Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())

if (a+b+c) % 3 == 0:P
  print("Yes")
else:
  print("No")

Fixed submission:
a,b,c = map(int, input().split())

s = sum([a,b,c])
m = max(a,b,c)

if m == (s - m):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

print((a + b)*h//2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())

print((a + b)*h//2)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

L = 0
judge = False

for i in range(len(T), 0, -1):
    # print(i)
    for j in range(len(T)-i+1):
        print(S[j:])
        if T[j:j+i] in S[j:]:
            L = i
            # print(T[j:j+i])
            judge = True
            # print(i, j)
            break
    if judge:
        break

print(len(T)-L)


Fixed submission:
S = input()
T = input()

ls = len(S)
lt = len(T)
ans = lt

for i in range(ls-lt+1):
    cnt = 0
    for j in range(lt):
        if S[j+i] != T[j]:
            cnt += 1
    ans = min(ans, cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

base = int(1e9+7)
tot = 0

for i in range(N-1):
    for j in range(i+1, N):
        # print(i,j)
        tot += A[i]*A[j]
        tot %= base
print(tot)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

base = int(1e9+7)
tot = 0

s = 0
for a in A:
    tot += s*a
    s += a
    tot %= base

print(tot)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N = int(input())
A = list(map(int, input().split()))

inf = int(1e6+5)
C = [0]*inf

for a in A:
    C[a] += 1

pa = True
se = True
for i in range(2, inf):
    cnt = 0
    for j in range(i, inf, i):
        cnt += C[j]
    if cnt > 1:
        pa = False
    if cnt == N:
        se = False
        
if pa:
    print("pairwise coprime")
elif se:
    print("setwise coprime")
else:
    print("not coprime")


Fixed submission:
import math

N = int(input())
A = list(map(int, input().split()))

inf = int(1e6+5)
C = [0]*inf

for a in A:
    C[a] += 1

pa = True
se = True
for i in range(2, inf):
    cnt = 0
    for j in range(i, inf, i):
        cnt += C[j]
    if cnt > 1:
        pa = False
    if cnt == N:
        se = False
        
if pa:
    print("pairwise coprime")
elif se:
    print("setwise coprime")
else:
    print("not coprime")
Buggy python submission (verdict: Runtime Error):
import bisect

N = int(input())
L = list(map(int, input().split()))

cnt = 0
L = list(set(L))
L = sorted(L)


if N >= 3:
    for i in range(len(L)-2):
        for j in range(i+1, len(L)-1):
            ind = bisect.bisect_left(L, L[i]+L[j])
            cnt += max(0, ind-j)
    print(cnt)

else:
    print(0)


Fixed submission:
X, K, D = map(int, input().split())

if abs(K*D) > abs(X):
    A = X//D
    A %= 2
    if K % 2 == A:
        print(X%D)
    else:
        print(D-X%D)
else:
    print(abs(X)-abs(K*D))
Buggy python submission (verdict: Runtime Error):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]

v = 0
last = [-1 for _ in range(26)]

for d in range(D):
    last[t[d]-1] = d
    v += s[d][t[d]-1]
    for j in range(26):
        v -= c[j]*(d-last[j])
    print(v)


Fixed submission:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

max_c = 0
index_c = 0

for i, C in enumerate(c):
    if C > max_c:
        index_c = i
        max_c = C

for d in range(D):
    print(index_c+1)
Buggy python submission (verdict: Runtime Error):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]

v = 0
last = [0 for _ in range(26)]

for i in range(D):
    last[t[i]-1] = i+1
    v += s[i][t[i]-1]
    for j in range(26):
        v -= c[j]*(d-last[j])
    print(v)


Fixed submission:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]

v = 0
last = [-1 for _ in range(26)]

for d in range(D):
    last[t[d]-1] = d
    v += s[d][t[d]-1]
    for j in range(26):
        v -= c[j]*(d-last[j])
    print(v)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = map(int, input().split())

ans = 1

for a in A:
    ans *= a
if ans > pow(10, 18):
    ans = -1
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = 1

if 0 in A:
    ans = 0
else:
    for a in A:
        ans *= a
        if ans > pow(10, 18):
            ans = -1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=[]
judge={}
j=0 #A進み
while A[j] not in judge.keys() or judge[A[j]]!=2:
    ans.append(A[j])
    if A[j] not in judge.keys():
        judge[A[j]]=0
    judge[A[j]]+=1
    j=A[j]-1

st=ans.index(A[j])
ans=ans[st:]
if st<K:
    K-=st
    l=len(ans)
    #print(ans)
    print(ans[K%l-1])
else:
    print(ans[st])

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=[]
judge={}
j=0 #A進み
while A[j] not in judge.keys() or judge[A[j]]!=2:
    ans.append(A[j])
    if A[j] not in judge.keys():
        judge[A[j]]=0
    judge[A[j]]+=1
    j=A[j]-1

st=ans.index(A[j])

if st<K:
    ans=ans[st:]
    K-=st
    l=len(ans)
    #print(ans)
    print(ans[K%l-1])
else:
    print(ans[K-1])

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=[]
judge={}
j=0 #A進み
while judge[A[j]]!=2:
    ans.append(A[j])
    if A[j] not in judge.keys():
        judge[A[j]]=0
    judge[A[j]]+=1
    j=A[j]-1
ans.append(A[j])

st=ans.index(A[j])
ans=ans[st:-1]
K-=st
l=len(ans)
#print(ans)
print(ans[K%l-1])

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=[]
judge={}
j=0 #A進み
while A[j] not in judge.keys() or judge[A[j]]!=2:
    ans.append(A[j])
    if A[j] not in judge.keys():
        judge[A[j]]=0
    judge[A[j]]+=1
    j=A[j]-1

st=ans.index(A[j])

if st<K:
    ans=ans[st:]
    K-=st
    l=len(ans)
    #print(ans)
    print(ans[K%l-1])
else:
    print(ans[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,N=map(int,input().split())

answer=0

for i in range(1,N+1):
    f=int(A*i/B)-A*int(i/B)
    if f>answer:
        answer=f
    if f<answer:
        break
    #print(f)
print(answer)
        

Fixed submission:
import math
A,B,N=map(int,input().split())

def f(x):
    return int(A*x/B)-A*int(x/B)

print(f(min(N,B-1)))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,N=map(int,input().split())

answer=0

for i in range(1,N+1):
    f=int(A*i/B)-A*int(i/B)
    if f>answer:
        answer=f
    #print(f)
print(answer)
        

Fixed submission:
import math
A,B,N=map(int,input().split())

def f(x):
    return int(A*x/B)-A*int(x/B)

print(f(min(N,B-1)))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

li=list(range(N+1))
count=0

#print(li)
for i in range(M,N+2):
    small=(i*(i-1))//2
    large=small+li[-i]*i
    count+=large-small+1

print(count%(pow(10,9)+7))

Fixed submission:
S=input()

N=len(S)
count=0
tot=[0]*2019
S=S[::-1]
base=0
#print(S)
for i,s in enumerate(S):
    base+=int(s)*pow(10,i,2019)
    base%=2019
    #tot[base]+=1
    #print(base)
    if base==0:
        count+=1
    count+=tot[base]
    #print(tot[base],i,base)
    tot[base]+=1
#print(tot)    

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()

N=len(S)
count=0

for i in range(N-3):
    for j in range(i+4,N+1):
        #print(S[i:j])
        if int(S[i:j])%2019==0:
            count+=1
print(count)

Fixed submission:
S=input()

N=len(S)
count=0
tot=[0]*2019
S=S[::-1]
base=0
#print(S)
for i,s in enumerate(S):
    base+=int(s)*pow(10,i,2019)
    base%=2019
    #tot[base]+=1
    #print(base)
    if base==0:
        count+=1
    count+=tot[base]
    #print(tot[base],i,base)
    tot[base]+=1
#print(tot)    

print(count)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))

homework=0

for a in A:
    homework+=a

if N>hemework:
    print(N-homework)
else:
    print(-1)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))

homework=0

for a in A:
    homework+=a

if N>=homework:
    print(N-homework)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

dict={}
dict[max(A)+1]=0
dict[1]=0
for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1
        if a+1 not in dict.keys():
            dict[a+1]=0

print(dict[1])
for a in A:
    print(dict[a+1])
    dict[a+1]=0


Fixed submission:
N=int(input())
A=list(map(int,input().split()))

dict={}

for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1
dict[N]=0

for i in range(1,N+1):
    if i in dict.keys():
        print(dict[i])
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

dict={}
dict[max(A)+1]=0
for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1
        if a+1 not in dict.keys():
            dict[a+1]=0

print(dict[1])
for a in A:
    print(dict[a+1])
    dict[a+1]=0


Fixed submission:
N=int(input())
A=list(map(int,input().split()))

dict={}

for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1
dict[N]=0

for i in range(1,N+1):
    if i in dict.keys():
        print(dict[i])
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

dict={}
dict[max(A)+1]=0
for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1
        if a+1 in dict.keys():
            dict[a+1]=0

print(dict[1])
for a in A:
    print(dict[a+1])
    dict[a+1]=0


Fixed submission:
N=int(input())
A=list(map(int,input().split()))

dict={}

for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1
dict[N]=0

for i in range(1,N+1):
    if i in dict.keys():
        print(dict[i])
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

dict={}
dict[max(A)+1]=0
for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1

print(dict[1])
for a in A:
    print(dict[a+1])
    dict[a+1]=0


Fixed submission:
N=int(input())
A=list(map(int,input().split()))

dict={}

for a in A:
    if a in dict.keys():
        dict[a]+=1
    else:
        dict[a]=1
dict[N]=0

for i in range(1,N+1):
    if i in dict.keys():
        print(dict[i])
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K=int(input())

sum=0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            base=math.gcd(i,j)
            sum+=math.gcd(base,k)

print(sum)

Fixed submission:
import math
K=int(input())

sum=K

for i in range(1,K):
    sum+=i
    for j in range(i+1,K+1):
        for k in range(j,K+1):
            if j==k:
                base=math.gcd(i,j)
                sum+=math.gcd(base,k)*6
            else:
                base=math.gcd(i,j)
                sum+=math.gcd(base,k)*6
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())
answer=0
count=0
i=1

while count<K:
    if i<=9:
        count+=1
        if count==K:
            answer=i
            break
    else:
        S=str(i)
        judge=True
        for j in range(1,len(S)):
            if abs(int(S[j-1])-int(S[j]))<=1:
                pass
            else:
                judge=False
        if judge==True:
            count+=1
            if count==K:
                answer=i
                break
    i+=1
print(answer)

Fixed submission:
from queue import Queue 
K=int(input())

q=Queue()

for i in range(1,min(9,K)+1):
    q.put(i)

for k in range(K):
    a=q.get()
    #print(a)
    if k!=K-1:
        b=a%10
        for j in range(max(0,b-1),min(9,b+1)+1):
            q.put(int(str(a)+str(j)))
    else:
        print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y=map(int,input().split())

X-=1
Y-=1

dist=[0]*(N+1)


for i in range(N):
    for j in range(N):
        dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
    print(dist[d]//2)
    
    

Fixed submission:
N,X,Y=map(int,input().split())

X-=1
Y-=1

dist=[0]*(N+1)


for i in range(N):
    for j in range(i+1,N):
        dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
    print(dist[d])

Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y=map(int,input().split())

X-=1
Y-=1

dist={}

for k in range(N):
    dist[k]=0

for i in range(N):
    for j in range(N):
        dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
    print(dist[d]//2)
    
    

Fixed submission:
N,X,Y=map(int,input().split())

X-=1
Y-=1

dist=[0]*(N+1)


for i in range(N):
    for j in range(i+1,N):
        dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
    print(dist[d])

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue

N,X,Y=map(int,input().split())

inf=1001001001
answer=[0]*(N-1)

for j in range(N):
    v=[inf]*N
    q=Queue()
    q.put(j)
    #print(q)
    v[j]=0
    while not q.empty():
        i=q.get()
        if i-1>=0 and v[i-1]==inf:
            v[i-1]=v[i]+1
            q.put(i-1)
            #print(i-1)
        if i+1<N and v[i+1]==inf:
            v[i+1]=v[i]+1
            q.put(i+1)
            #print(i+1)
        if i==X-1 and v[Y-1]==inf:
            v[Y-1]=v[i]+1
            q.put(Y-1)

        if i==Y-1 and v[X-1]==inf:
            v[X-1]=v[i]+1
            q.put(X-1)
        #print(v)
    #print(v)
    for k in v:
        if k>0:
            answer[k-1]+=1
for a in answer:
    print(a//2)




Fixed submission:
N,X,Y=map(int,input().split())

X-=1
Y-=1

dist=[0]*(N+1)


for i in range(N):
    for j in range(i+1,N):
        dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
    print(dist[d])
Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
answer=p[:X]+q[:Y]
sum=0
answer=sorted(answer,reverse=True)
i=0

while answer[-i-1]<r[i]:
    answer[-i-1]=r[i]
    i+=1

for a in answer:
    sum+=a

print(sum)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
answer=p[:X]+q[:Y]
sum=0
answer=sorted(answer)
i=0

while i<=min(X+Y-1,C-1) and answer[i]<r[i]:
    answer[i]=r[i]
    i+=1

for a in answer:
    sum+=a

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))


dict_A={}
B=list(set(A))
sum=0


for b in B:
    a=A.count(b)
    dict_A[b]=a-1
    sum+=a*(a-1)//2

for a in A:
    print(sum-dict_A[a])

        

Fixed submission:
N=int(input())
A=list(map(int,input().split()))


dict_A={}
B=list(set(A))
sum=0


for a in A:
    if a not in dict_A.keys():
        dict_A[a]=1
    else:
        dict_A[a]+=1
for b in B:
    sum+=dict_A[b]*(dict_A[b]-1)//2

for a in A:
    print(sum-dict_A[a]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

dict_B={}
dict_A={}
B=list(set(A))
sum=0
C=0

for b in B:
    a=A.count(b)
    dict_A[b]=(a-1)*(a-2)//2
    dict_B[b]=a*(a-1)//2
    sum+=a*(a-1)//2

for a in A:
    print(sum-dict_B[a]+dict_A[a])

        

Fixed submission:
N=int(input())
A=list(map(int,input().split()))


dict_A={}
B=list(set(A))
sum=0


for a in A:
    if a not in dict_A.keys():
        dict_A[a]=1
    else:
        dict_A[a]+=1
for b in B:
    sum+=dict_A[b]*(dict_A[b]-1)//2

for a in A:
    print(sum-dict_A[a]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

dict_A={}
B=list(set(A))
C=0

for a in A:
    if a not in dict_A.keys():
        dict_A[a]=1
    else:
        dict_A[a]+=1

for n in range(N):
    C=0
    for i in dict_A.keys():
        if A[n]==i:
            C+=(dict_A[i]-1)*(dict_A[i]-2)//2
        else:
            C+=dict_A[i]*(dict_A[i]-1)//2
    print(C)
#print(dict_A)
#print(B)
        
        

Fixed submission:
N=int(input())
A=list(map(int,input().split()))


dict_A={}
B=list(set(A))
sum=0


for a in A:
    if a not in dict_A.keys():
        dict_A[a]=1
    else:
        dict_A[a]+=1
for b in B:
    sum+=dict_A[b]*(dict_A[b]-1)//2

for a in A:
    print(sum-dict_A[a]+1)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]

dp=[[0]*H]*W
#print(s)
answer=[]



for h in range(H):
    for w in range(W):
        #print(s[h][w],dp[h][w])
        if s[h][w]==".":
            if h!=0 and w==0:
                dp[h][w]=dp[h-1][w]
            elif h==0 and w!=0:
                dp[h][w]=dp[h][w-1]
            elif h==0 and w==0:
                pass
            else:
                dp[h][w]=min(dp[h-1][w],dp[h][w-1])
        else:
            if s[h][w]=="#":
                if h!=0 and w==0:
                    dp[h][w]=dp[h-1][w]+1
                elif h==0 and w!=0:
                    dp[h][w]=dp[h][w-1]+1
                elif h==0 and w==0:
                    dp[h][w]=1
                else:
                    dp[h][w]=min(dp[h-1][w],dp[h][w-1])+1
        #print(s[h][w],dp[h][w])
#print(dp)
print(dp[H-1][W-1])


Fixed submission:
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]

dp=[]
blacks=[]
whites=[]
black=0
white=0
#DP=[]
#print(s)

for h in range(H):
    dp.append([0]*W)
    #DP.append([0]*W)
    for w in range(W):
        #print(s[h][w],dp[h][w])
        if s[h][w]==".":
            if h!=0 and w==0:
                dp[h][w]=dp[h-1][w]
                #DP[h][w]=DP[h-1][w]+1
            elif h==0 and w!=0:
                dp[h][w]=dp[h][w-1]
                #DP[h][w]=DP[h][w-1]+1
            elif h==0 and w==0:
                dp[h][w]=0
                #DP[h][w]=1
            else:
                dp[h][w]=min(dp[h-1][w],dp[h][w-1])
                #DP[h][w]=min(DP[h-1][w],DP[h][w-1])+1
        else:
            if h!=0 and w==0:
                if s[h-1][w]=="#":
                    dp[h][w]=dp[h-1][w]
                else:
                    dp[h][w]=dp[h-1][w]+1
                #DP[h][w]=DP[h-1][w]
            elif h==0 and w!=0:
                if s[h][w-1]=="#":
                    dp[h][w]=dp[h][w-1]
                else:
                    dp[h][w]=dp[h][w-1]+1
                #DP[h][w]=DP[h][w-1]
            elif h==0 and w==0:
                dp[0][0]=1
                #DP[0][0]=0
            else:
                if s[h-1][w]=="." and s[h][w-1]=="#":
                    dp[h][w]=min(dp[h-1][w]+1,dp[h][w-1])
                elif s[h-1][w]=="#" and s[h][w-1]==".":
                    dp[h][w]=min(dp[h-1][w],dp[h][w-1]+1)
                elif s[h-1][w]=="#" and s[h][w-1]=="#":
                    dp[h][w]=min(dp[h-1][w],dp[h][w-1])
                elif s[h-1][w]=="." and s[h][w-1]==".":
                    dp[h][w]=min(dp[h-1][w]+1,dp[h][w-1]+1)
        #print(dp)
                
print(dp[H-1][W-1])
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
q=[input().split() for _ in range(Q)]

for i in range(Q):
    if q[i][0]=="1":
        S=S[::-1]
    else:
        if q[i][1]=="1":
            S=q[i][2]+S
        elif q[i][1]=="2":
            S=S+q[i][2]
print(S)

Fixed submission:
S=input()
Q=int(input())
q=[input().split() for _ in range(Q)]

count=0
f=""
b=""

for i in range(Q):
    if q[i][0]=="1":
        count+=1
    else:
        if q[i][1]=="1":
            if count%2==0:
                f=q[i][2]+f
            else:
                b+=q[i][2]
        elif q[i][1]=="2":
            if count%2==1:
                f=q[i][2]+f
            else:
                b+=q[i][2]

if count%2==1:
    S=f+S+b
    print(S[::-1])
else:
    print(f+S+b)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(M)]

answer=[]

if N==1:
    for j in range(10):
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
else:
    for j in range(10**(N-1),10**N):
        a=0
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
if len(answer)>=1:
    print(min(answer))
    #print(answer)
else:
    print(-1)


Fixed submission:
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(M)]

answer=[]

if N==1:
    for j in range(10):
        a=0
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
else:
    for j in range(10**(N-1),10**N):
        a=0
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
if len(answer)>=1:
    print(min(answer))
    #print(answer)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,a,b=map(int,input().split())

count=0
mod=1000000007

def C(n,a):
    x=1
    y=1
    for i in range(a):
        x*=n-i
        y*=i+1
    return x*pow(y,mod-2,mod)%mod

count+=pow(2,n,mod)
#print(count)
count-=1
count-=C(n,a)
#print(count)
count-=C(n,b)

print(max(0,(count)%mod))

Fixed submission:
import math
n,a,b=map(int,input().split())

count=0
mod=1000000007

def C(n,a):
    x=1
    y=1
    for i in range(a):
        x*=n-i
        y*=i+1
        x%=mod
        y%=mod
    return x*pow(y,mod-2,mod)%mod

count+=pow(2,n,mod)
#print(count)
count-=1
count-=C(n,a)
#print(count)
count-=C(n,b)

print(max(0,(count)%mod))

Buggy python submission (verdict: Runtime Error):
import math
n,a,b=map(int,input().split())

count=0
mod=10**9+7

def C(n,a):
    x=1
    y=1
    for i in range(a):
        x*=n-i
        y*=i+1
    return x/y

count+=pow(2,n,mod)
#print(count)
count-=1
count-=C(n,a)
#print(count)
count-=C(n,b)

print(int(count%mod))

Fixed submission:
import math
n,a,b=map(int,input().split())

count=0
mod=1000000007

def C(n,a):
    x=1
    y=1
    for i in range(a):
        x*=n-i
        y*=i+1
        x%=mod
        y%=mod
    return x*pow(y,mod-2,mod)%mod

count+=pow(2,n,mod)
#print(count)
count-=1
count-=C(n,a)
#print(count)
count-=C(n,b)

print(max(0,(count)%mod))