Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the…
- User
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions. Input
Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.
The number of datasets does not exceed 50.
Output
For each data set, output the number of combinations of a, b, c, and d on one line.
Example
Input
2 3 35
Output
10 20 8436
Assistant
pythonimport sys from math import comb def compute_combinations(n): total = 0 for k in range(0, 5): sign = (-1) ** k c4k = comb(4, k) remaining = n - k * 1001 if remaining < 0: continue m = remaining + 3 if m < 3: term = 0 else: term = c4k * (m * (m - 1) * (m - 2) // 6) total += sign * term return total for line in sys.stdin: line = line.strip() if not line: continue n = int(line) print(compute_combinations(n))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.