Problem: Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.

Submission attempts (in order):
MOD=10**9+7
def cmb(n,r):
    if n-r < r: r = n-r
    if r == 0: return 1
    denominator = 1                       
    numerator = 1                         
    for i in range(r):
        numerator *= n-i
        numerator %= Q
        denominator *= i+1
        denominator %= Q
    return numerator*pow(denominator, Q-2, Q)%Q


def main():
	S=int(input())
	ans=0
	for i in range(1,S//3+1):
		t=S-i*3
		ans+=cmb(t+i-1,i-1)
		ans%=MOD
	print(ans)

if __name__=="__main__":
	main()

S=int(input())

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1);

possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	possibles+=f(S-2*i-1)/f(S-3*i)/f(i-1)
n=10**9+7
print(possibles%n)

S=int(input())

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1); 



possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	left=S-3*i
	possibles+=(f(left+i-1)/f(i-1)/f(left))
n=10**9+7
print(possibles%n)

S=int(input())

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1);

possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	left=S-3*i
	possibles+=(f(left+i-1)/(f(i-1)*f(left)))
n=10**9+7
print(possibles%n)

S=int(input())

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1);

possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	possibles=f(S-2*i-1)/f(S-3*i)/f(i-1)
n=10**9+7
print(possibles%n)

S=int(input())

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1);

possibles=1
biggest_sub=S//3
for i in range(2,biggest_sub+1):
	left=S-3*i
	possibles+=(f(left+i-1)/f(i-1)/f(left))
n=10**9+7
print(possibles%n)

S=int(input())
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

possibles=1
biggest_sub=S//3
for i in range(2,biggest_sub+1):
	left=S-3*i
	possibles+=nCr(left+i-1,i-1)
print(possibles)

S=int(input())

def f(n):
	fact = 1
  
	for i in range(1,n+1): 
	    fact = fact * i
	 return fact

def nCr(n,r):
    
    return f(n) / f(r) / f(n-r)

possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	left=S-3*i
	possibles+=nCr(left+i-1,i-1)
n=10**9+7
print(possibles%n)

S=int(input())

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1);

possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	possibles=f(biggest_sub-3*i)/f(r)/f(biggest_sub-4*r)
n=10**9+7
print(possibles%n)

S=1729

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * f(n - 1);

possibles=0

n=10**9+7
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	possibles+=f(S-3*i+i-1)/f(i-1)/f(S-3*i)
	possibles%=n

n=10**9+7
print(possibles%n)

S=int(input())

def f(n): 
      
    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1);

possibles=0

n=10**9+7
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	possibles+=f(S-3*i+i-1)/f(i-1)/f(S-3*i)
	possibles%=n

n=10**9+7
print(possibles%n)

S=int(input())

def f(n):
	fact = 1
  
	for i in range(1,n+1): 
	    fact = fact * i
	return fact

def nCr(n,r):
    
    return f(n) / f(r) / f(n-r)

possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	left=S-3*i
	possibles+=nCr(left+i-1,i-1)
n=10**9+7
print(possibles%n)

S=int(input())
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

possibles=1
biggest_sub=S//3
for i in range(2,biggest_sub+1):
	left=S-3*i
	possibles+=nCr(left+i-1,i-1)
n=10**9+7
print(possibles%n)


 
 
const int mod = 1e9+7;
int fact[2020];
 
int power(int a, int b){
    int ans = 1;
    while(b){
        if (b&1){
            ans = (ans*a)%mod;
        }
        a = (a*a)%mod;
        b>>=1;
    }
    return ans;
}
 
int inv(int a){
    return power(a, mod-2);
}
 
int ncr(int n, int r){
    int denom = fact[r] * fact[n-r] %mod;
    denom = inv(denom);
    return (fact[n]*denom)%mod;
}
 
 
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
 
    int n;
    cin>>n;
 
    if(n==3){
        cout<<1<<endl;
        return 0;
    }
 
    fact[0] = 1;
    for (int i=1; i<=n; i++){
        fact[i] = (i*fact[i-1])%mod;
    }
 
    //n-1cr-1
    //n-1-2*icri-1
 
    int ans = 0;
    for (int i=1; (n-1-2*i)>0; i++){
        if (n-1-2*i<i-1) break;
        ans = (ans + ncr(n-1-2*i, i-1))%mod;
    }
    cout<<ans<<endl;
 
 
 
    return 0;
}

S=int(input())
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

possibles=0
biggest_sub=S//3
for i in range(1,biggest_sub+1):
	left=S-3*i
	possibles+=nCr(left+i-1,i-1)
n=10**9+7
print(possibles%n)

#import sys
#input = sys.stdin.readline
Q = 10**9+7
def cmb(n,r):
    if n-r < r: r = n-r
    if r == 0: return 1
    denominator = 1                       
    numerator = 1                         
    for i in range(r):
        numerator *= n-i
        numerator %= Q
        denominator *= i+1
        denominator %= Q
    return numerator*pow(denominator, Q-2, Q)%Q
 
def main():
    S = int( input())
    ans = 0
    for i in range(1, S//3+1):
        t = S - i*3
        ans += cmb(t+i-1,i-1)
        ans %= Q
    print(ans)
        
if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted