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 math import sys for line in sys.stdin: line = line.strip() if not line: continue n = int(line) if n < 0 or n > 4000: print(0) continue total = 0 for k in range(0, 5): sign = (-1) ** k c4k = math.comb(4, k) m = n - k * 1001 if m < 0: continue m_total = m + 3 if m_total < 3: comb_val = 0 else: comb_val = math.comb(m_total, 3) total += sign * c4k * comb_val print(total)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.