Problem p02555 (python)

Fixed submission:
#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()

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

Buggy submission (verdict: Runtime Error):
#define int long long
 
 
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;
}

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

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

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

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

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

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

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

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

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

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

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

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

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