Problem p03027 (python)

Fixed submission:
from collections import *
mod=10**6+3
fac=[0 for i in range(mod)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
fac[0]=0
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    if d>0:
        D=pow(d,mod-2,mod)
        a=(x-d%mod)*D%mod
        b=(a+n)%mod
        if a<b and a+n<mod:
            if a>0:
                value=fac[b]*pow(fac[a],mod-2,mod)*pow(d,n,mod)
            else:
                value=fac[b]*pow(d,n,mod)
            print(value%mod)
        else:
            print(0)
    else:
        print(pow(x,n,mod))

Buggy submission (verdict: Runtime Error):
from collections import *
mod=10**6+3
fac=[0 for i in range(mod)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
fac[0]=0
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a=(x-d%mod)*D%mod
    b=a+n
    if a<b:
        if a>0:
            value=fac[b]*pow(fac[a],mod-2,mod)*pow(d,n,mod)
        else:
            value=fac[b]*pow(d,n,mod)
        print(value%mod)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from collections import *
mod=10**6+3
fac=[0 for i in range(mod-1)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a,b=x*D%mod,(x+(n-1)*d)*D%mod
    if d>5:
        if a>=0 and a<b and b<mod-1:
            if a>0:
                value=fac[b]*pow(fac[a-1],mod-2,mod)*pow(d,n,mod)
            elif a==0:
                value=fac[b]*pow(d,n,mod)
            print(value%mod)
        else:
            print(0)
    else:
        print(unko)

Buggy submission (verdict: Runtime Error):
from collections import *
mod=10**6+3
fac=[0 for i in range(mod-1)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a,b=x*D%mod,(x+(n-1)*d)*D%mod
    if a>=0 and a<b and b-1<mod:
        if a>0:
            value=fac[b]*pow(fac[a-1],mod-2,mod)*pow(d,n,mod)
        elif a==0:
            value=fac[b]*pow(d,n,mod)

        print(value%mod)

    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from collections import *
mod=10**6+3
fac=[0 for i in range(mod-1)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a,b=x*D%mod,(x+(n-1)*d)*D%mod
    if a>0 and a<b and b-1<mod:
        value=fac[b]*pow(fac[a-1],mod-2,mod)*pow(d,n,mod)
        print(value%mod)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from collections import *
mod=10**6+3
fac=[0 for i in range(mod-1)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a,b=x*D%mod,(x+(n-1)*d)*D%mod
    if a>0 and a<b and b<mod:
        value=fac[b]*pow(fac[a-1],mod-2,mod)*pow(d,n,mod)
        print(value%mod)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from collections import *
mod=10**6+3
fac=[0 for i in range(mod-1)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a,b=x*D%mod,(x+(n-1)*d)*D%mod
    print(a,b)
    if a>0 and a<b and b<mod:
        value=fac[b]*pow(fac[a-1],mod-2,mod)*pow(d,n,mod)
        print(value%mod)
    else:
        print(0)