Problem:


４つの整数の和 II

4,000 以下の正の整数 n を入力し、0 〜 1000 の範囲の整数 a, b, c, d の組で

a + b + c + d = n

を満たすものの組み合わせ数を出力するプログラムを作成して下さい。

Input

複数のデータセットが与えられます。各データセットに n が１行に与えられます。入力の最後まで処理して下さい。

データセットの数は 50 を超えません。

Output

各データセットごとに、a, b, c, d の組み合わせの個数を１行に出力して下さい。

Sample Input

2
3
35

Output for the Sample Input

10
20
8436



Sample input:
2
3
35


Sample output:
10
20
8436

Submission status: Accepted

Solution code:
import sys

a = range(1,1001) + range(1001,0,-1)
for s in sys.stdin:
    n = int(s)
    r = 0
    for i in range(min(2000,n),-1,-1):
        if n - i <= 2000:
            r += a[i] * a[n - i]
    print r

Submission status: Accepted

Solution code:
f = lambda x: x+1 if x<=1000 else 2001-x
while 1:
    try:
        n = input(); p = min(n, 2000); ans = 0;
        for i in xrange(n-p,p+1):
            ans += f(i)*f(n-i);
        print ans
    except EOFError:
        break

Submission status: Accepted

Solution code:
def N(n):
    return (n+1)*(n+2)*(n+3)/6

while True:
    try:
        n = int(raw_input())
        if n > 2000:
            n = 4000 - n
        if n < 1001:
            print N(n)
        else:
            print N(n) - (N(2*(n-1000)) - (n-1000) - 1)/2
    except:
        break

Submission status: Accepted

Solution code:
def N(n):
    return (n+1)*(n+2)*(n+3)/6

while True:
    try:
        n = int(raw_input())
        if n > 2000:
            n = 4000 - n
        if n < 1001:
            print N(n)
        else:
            m = n - 1000
            print N(n) - (N(2*m) - m - 1)/2
    except:
        break

Submission status: Accepted

Solution code:
import sys
def N(n):
    return (n+1)*(n+2)*(n+3)/6
for n in sys.stdin:
        n = int(n)
        if n > 2000:
            n = 4000 - n
        if n < 1001:
            print N(n)
        else:
            m = n - 1000
            print N(n) - (N(2*m) - m - 1)/2

Submission status: Accepted

Solution code:
import sys
def N(n):
    return (n+1)*(n+2)*(n+3)/6
for n in sys.stdin:
    n = int(n)
    if n > 2000:
        n = 4000 - n
    if n < 1001:
        print N(n)
    else:
        m = n - 1000
        print N(n) - (N(2*m) - m - 1)/2

Submission status: Accepted

Solution code:
dp = [[0] * 4001 for _ in range(4)]
for i in range(1001):
    dp[0][i] = 1
for i in range(1, 4):
    for j in range((i + 1) * 1000 + 1):
        dp[i][j] += sum(dp[i - 1][max(0, j - 1000): j + 1])

while 1:
    try:
        print dp[3][input()]
    except:
        break

Submission status: Accepted

Solution code:
s = list(range(1,1001)) + list(range(1001,0,-1))
while True:
    try:
        n = int(input())
    except:
        break

    ans = 0
    for i in range(min(n+1,2001)):
        if 0 <= n-i <= 2000:
            ans += s[i] * s[n-i]
    print(ans)

Submission status: Accepted

Solution code:
while True:
    try:
        n = int(input())
        if n > 2000:
            n = 4000 - n

        ans = (n+1)*(n+2)*(n+3)/6
        if n >= 1001:
            n = n - 1001
            ans = ans - 2*(n+1)*(n+2)*(n+3)/3

        print(int(ans))

    except EOFError:
        break

Submission status: Accepted

Solution code:
A = [0 for i in range(2001)]
        
for i in range(1001) :
    for j in range(1001) :
        A[i + j] += 1

while True :
    try :
        n = int(input())
                
        cnt = 0
        
        if(n > 4000) :
            print(0)
            
        elif(n > 2000) :
            for i in range(n - 2000, 2001) :
                cnt += A[i] * A[n - i]
            print(cnt)
                
        else :
            for i in range(n + 1) :
                cnt += A[i] * A[n - i]
            print(cnt)
       
    except :
        break

Submission status: Accepted

Solution code:
import sys

n_list = []
while True:
    try:
        n_list.append(int(input()))
    except:
        break
for n in n_list:
    sum_list = list(range(1, 1001)) + list(range(1001, 0, -1))
    ans = 0
    for i in range(min(n+1, 2001)):
        if 0<= (n-i) <= 2000:
            ans += sum_list[i]*sum_list[n-i]
    print(ans)

Submission status: Accepted

Solution code:
import sys
for n in sys.stdin:print(sum(max(0,min(i,2002-i))*max(0,min(int(n)-i+2,2000-int(n)+i))for i in range(int(n)+2)))

Submission status: Accepted

Solution code:
dp = [[0 for j in range(4001)] for i in range(4)]
for j in range(4001):
  if j <= 1000:
    dp[0][j] = 1
for i in range(1,4):
  for j in range(4001):
    for k in range(0, min(1000, j) + 1):
      dp[i][j] += dp[i - 1][j - k]

while True:
  try:
    n = int(input())
  except:
    break
  print(dp[3][n])

Submission status: Accepted

Solution code:
dp=[0]*4001
for i in range(4001):
    if i<1000:
        dp[i]=i+1
    elif i>2000:
        dp[i]=0
    elif i>=1000:
        dp[i]=2001-i
while 1:
    try:
        ans=0
        n=int(input())
        for i in range(n+1):
            ans+=dp[i]*dp[n-i]
        print(ans)
    except:break

Submission status: Accepted

Solution code:
import sys
  
n = [[0]*4001, [0]*4001, [0]*4001, [0]*4001]
n[0][:1001] = [1]*1001

for i in range(1, 4):
    for j in range(1000*(i+1)+1):
        x = max(0,j-1000*(i+1))
        y = min(j+1,1001)
        for k in range(x,y):
            n[i][j] += n[i-1][j-k]

for i in sys.stdin:
    print(n[3][int(i)])

Submission status: Accepted

Solution code:
import sys
dp = list(range(1, 1002))+list(range(1000,0,-1))

for n in map(int, sys.stdin):
    n = min(n, 4000-n)
    print(sum(dp[i]*dp[j] for i, j in zip(range(n+1), range(n, -1, -1))))

Submission status: Runtime Error

Solution code:
import sys

n=1001
a=range(1,n)
a+=[n]+a[::-1]

for n in map(int,sys.stdin):
  x=0
  for i in range(max(0,n-2000),n+1):
    x+=a[i]*a[n-i]
  print x

Submission status: Runtime Error

Solution code:
n=1001
a=range(1,n)
a+=[n]+a[::-1]
for n in map(int,sys.stdin):
  x=0
  for i in range(max(0,n-2000),min(n,2000)+1):
    x+=a[i]*a[n-i]
  print x

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

for s in sys.stdin:
    n = int(s)

    T = [0] * 2001
    for a in range(1001):
        for b in range(1001):
            T[a+b] += 1

    sum_n_num = 0
    for a_b_sum in range(0, n+1):
        c_d_sum = n - a_b_sum
        sum_n_num += T[a_b_sum] * T[c_d_sum]

    print(sum_n_num)

Submission status: Runtime Error

Solution code:
for s in sys.stdin:
    n = int(s)

    T = [0] * 2001
    for a in range(1001):
        for b in range(1001):
            T[a+b] += 1

    sum_n_num = 0
    for a_b_sum in range(0, n+1):
        c_d_sum = n - a_b_sum
        if a_b_sum <= 2000 and c_d_sum <= 2000:
            sum_n_num += T[a_b_sum] * T[c_d_sum]

    print(sum_n_num)

Submission status: Runtime Error

Solution code:
two_dict = {}
for i in range(2001):
  two_dict[i] = min(i, 2000 - i) + 1 

while True:
  try:
    n = int(input())
    ans = 0
    for i in range(n + 1):
      ans += two_dict[i] * two_dict[n - i]
    print(ans)

  except EOFError:
    break

Submission status: Runtime Error

Solution code:
import sys,math
f=lambda x:math.factorial(x)
[print(i) for i in [int(f(int(l[:-1])+3)/f(3)/f(int(l[:-1]))) for l in sys.stdin]]

Submission status: Runtime Error

Solution code:
# coding: utf-8

def nCr(n, r):
    ret = 1
    for i in xrange(r):
        ret *= (n-i)
        ret /= (i+1)
    return ret

A = []
while True:
    sA = raw_input()
    if not sA:
        break
    A.append( int(sA) )

for i in xrange( len(A) ):
    print nCr( A[i]+3, 3 )

Submission status: Runtime Error

Solution code:
# coding: utf-8

def nCr(n, r):
    ret = 1
    for i in xrange(r):
        ret *= (n-i)
        ret /= (i+1)
    return ret

A = []
for i in xrange(50):
    sA = raw_input()
    if not sA:
        break
    A.append( int(sA) )

for i in xrange( len(A) ):
    print nCr( A[i]+3, 3 )

Submission status: Runtime Error

Solution code:
while True:

Submission status: Runtime Error

Solution code:
import sys
def N(n):
    return (n+1)*(n+2)*(n+3)/6
for n in sys.stdin:
        n = int(raw_input())
        if n > 2000:
            n = 4000 - n
        if n < 1001:
            print N(n)
        else:
            m = n - 1000
            print N(n) - (N(2*m) - m - 1)/2