def f(rest, k)
    if k == 1
        0 <= rest && rest <= 1000 ? 1 : 0
    else
        ([0, rest-1000*(k-1)].max..[1000, rest].min).map{|x| f(rest-x, k-1)}.inject(:+)
    end
end

module Memoizable
    def memoize(name)
        original = "__original_#{name}__"
        ([Class, Module].include?(self.class) ? self : self.class).class_eval {
            alias_method(original, name)
            private(original)
            cache = {}
            define_method(name){|*args|
                cache[args] ||= send(original, *args)
            }
        }
    end
end

include Memoizable
memoize :f

p f($_.to_i, 4) while gets