Buggy python submission (verdict: Time Limit Exceeded):
while True:
    try:
        n = int(raw_input())
        count = 0
        for a in range(1000,-1,-1):
            if 0 <= n - a <= 3000:
                for b in range(1000,-1,-1):
                    if 0 <= n - a - b <= 1000:
                        count += n-a-b+1
                    elif 1001 < n - a - b <= 2000:
                        count += (2000 - (n-a-b) + 1)
        print count
    except:
        break

Fixed submission:
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

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    try:
        n = int(raw_input())
        count = 0
        for a in range(1000,-1,-1):
             if 0 <= n - a <= 3000:
                for b in range(1000,-1,-1):
                    if n - a - b > 2000:
                        break
                    elif 0 <= n - a - b <= 1000:
                        count += n-a-b+1
                    elif 1001 < n - a - b <= 2000:
                        count += (2000 - (n-a-b) + 1)
        print count
    except:
        break

Fixed submission:
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

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    try:
        n = int(raw_input())
        count = 0
        for a in range(1000,-1,-1):
            na = n - a
            if 3000 < na:
                break
            elif 0 <= na <= 3000:
                for b in range(1000,-1,-1):
                    nab = n - a - b
                    if nab > 2000:
                        break
                    elif 0 <= nab <= 1000:
                        count += nab+1
                    elif 1001 < nab <= 2000:
                        count += (2000 - nab + 1)
        print count
    except:
        break

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
while True:

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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

Fixed submission:
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