Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from re import *
n=int(input())
s=input()
l=["0","1","2","3","4","5","6","7","8","9"]
ans=0
for i in l:
    for j in l:
        for k in l:
            if match(".*{}.*{}.*{}".format(i,j,k),s):
                ans+=1
print(ans)

Fixed submission:
n = int(input())
s = input()

ans = 0

for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from re import *
n=int(input())
s=input()
l=["0","1","2","3","4","5","6","7","8","9"]
ans=0
for i in l:
    for j in l:
        for k in l:
            if match(".*{}.*{}.*{}".format(i,j,k),s):
                ans+=1
print(ans)

Fixed submission:
n = int(input())
s = input()

ans = 0

for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n=int(input())
s=input()
a=list(combinations(range(n),3))
b=set()
for i,j,k in a:
    b.add(s[i]+s[j]+s[k])
print(len(b))

Fixed submission:
n = int(input())
s = input()

ans = 0

for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
tmp=0
for i in range(n): 
    tmp+=a[i]
    if tmp*2==sum(a):
        print(0)
        sys.exit()
    if tmp*2>sum(a):
        l=i
        break
if abs(tmp*2-sum(a))>abs((tmp-a[l])*2-sum(a)):
    print(abs((tmp-a[l-1])*2-sum(a)))
else:
    print(abs(tmp*2-sum(a)))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=10**20
p=sum(a)
q=0
for i in range(n-1):
	q+=a[i]
	ans=min(ans,abs(p-q-q))
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
if (x+y)%3!=0:
    print(0)
    exit()
if x<y:
    y=x
    x,y=y,x
if 2y<x:
    print(0)
    exit()
mod=10**9+7
a=(2y-x)//3
b=(2x-y)//3
mx=10**6*2
k=[1]*(mx+1)
def inv(n):
    return pow(n,mod-2,mod)
for i in range(mx):
    k[i+1]=k[i]*(i+1)%mod
ans=(k[w+h]*inv(k[w])*inv(k[h]))%mod
print(ans)

Fixed submission:
x,y=map(int,input().split())
if (x+y)%3!=0:
    print(0)
    exit()
if x<y:
    x,y=y,x
if 2*y<x:
    print(0)
    exit()
mod=10**9+7
a=(2*y-x)//3
b=(2*x-y)//3
mx=10**6
k=[1]*(mx+1)
def inv(n):
    return pow(n,mod-2,mod)
for i in range(mx):
    k[i+1]=k[i]*(i+1)%mod
ans=(k[a+b]*inv(k[a])*inv(k[b]))%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())

for a in range(1,10):
    for b in range(1,10):
        if a*b==n:
            flag=True
if flag:
   print("Yes") 
else:
     print("No")

Fixed submission:
from sys import exit

N = int(input())

for i in range(1, 10):
    for j in range(1, 10):
        if N == i * j:
            print('Yes')
            exit()
print('No')

Buggy python submission (verdict: Runtime Error):
n=int(input())

for a in range(1,10):
    for b in range(1,10):
        if a*b==n:
            flag=True
print("Yes" if flag else "No")

Fixed submission:
from sys import exit

N = int(input())

for i in range(1, 10):
    for j in range(1, 10):
        if N == i * j:
            print('Yes')
            exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]+l[j]>l[k]:
                ans+=1
print(ans)

Fixed submission:
import bisect
n = int(input())
l = sorted(list(map(int,input().split())))

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += bisect.bisect_left(l,l[i] + l[j]) - (j + 1)


print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
print("No" if "L" in S[::2] or "R" in S[1::2] else "Yes")

Fixed submission:
import sys
s=input()
a=["R","U","D"]
b=["L","U","D"]
for i in range(len(s)):
    if i%2==0:
        if s[i] not in a:
            print("No")
            sys.exit()
    else:
        if s[i] not in b:
            print("No")
            sys.exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
for i in range(n):
    ans+=i
print(ans)

Fixed submission:
n=int(input())
ans=n*(n-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import *
from bisect import *
s=input()
t=input()
n=len(s)
nn=len(t)
ss=[[]for i in range(26)]
tt=[[] for i in range(26)]
ans=0
k=0
for i in range(n):
    ss[ord(s[i])-97].append(i+1)
for i in t:
    j=ss[ord(i)-97]
    if len(j)==0:
        print(-1)
        exit()
    else:
        if j[-1]<ans:
            ans=j[0]
            k+=1
        else:
            ans=j[bisect(j,ans)]
print(k*n+ans)

Fixed submission:
from math import *
from bisect import *
s=input()
t=input()
n=len(s)
nn=len(t)
ss=[[]for i in range(26)]
tt=[[] for i in range(26)]
ans=0
k=0
for i in range(n):
    ss[ord(s[i])-97].append(i+1)
for i in t:
    j=ss[ord(i)-97]
    if len(j)==0:
        print(-1)
        exit()
    else:
        if j[-1]<=ans:
            ans=j[0]
            k+=1
        else:
            ans=j[bisect(j,ans)]
print(k*n+ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=[]
tt=0
for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    ans.append(s)
for i in range(n-1):
    for j in range(i+1,n):
        if ans[i]==ans[j]:
            tt+=1
print(tt)

Fixed submission:
from collections import Counter
n=int(input())
ans=[]
tt=0
for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    ans.append(s)
l=Counter(ans)
c=l.most_common()
for i,j in c:
    tt+=j*(j-1)//2
print(tt)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n=int(input())
h=deque((map(int,input().split())))
flag=True
while h:
    if h[0]<=h[1]-1:
        h.popleft()
        if len(h)==1:
            break
    else:
        flag=False
        break
print("Yes" if flag else "No")

Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
lis[0]-=1
for i in range(n-1):
  if lis[i] < lis[i+1]:
    lis[i+1] -= 1
  elif lis[i] > lis[i+1]:
    print("No")
    exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
b=[]
for i in range(m):
    b.append(int(input()))
a=set(b)
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
b=[]
for i in range(m):
    b.append(int(input()))
a=set(b)
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
dp=[0]*(n+1)
dp[0]=1
dp[1]=1
for i in range(2,n+1):
    if i-1 not in a and i-2 not in a:
        dp[i]=dp[i-1]+dp[i-2]
    elif i-1 in a and i-2 not in a:
        dp[i]=dp[i-2]
    elif i-1 not in a and i-2 in a:
        dp[i]=dp[i-1]
    elif i-1 in a and i-2 in a:
        dp[i]=0
print(dp[n]%1000000007)

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
b=[]
for i in range(m):
    b.append(int(input()))
a=set(b)
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
dp=[0]*(n+1)
dp[0]=1
dp[1]=1
for i in range(2,n+1):
    if i-1 not in a and i-2 not in a:
        dp[i]=dp[i-1]+dp[i-2]
    elif i-1 in a and i-2 not in a:
        dp[i]=dp[i-2]
    elif i-1 not in a and i-2 in a:
        dp[i]=dp[i-1]
    elif i-1 in a and i-2 in a:
        dp[i]=0
print(dp[n]%1000000007)

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
b=[]
for i in range(m):
    b.append(int(input()))
a=set(b)
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
ans=0
v=list(map(int,input().split()))
for i in range(min(n,k+1)):
    for j in range(min(n-i,k-i+1)):
        if j!=0
            tmp=v[:i]+v[-j:]
        else:
            tmp=v[:i]
        tmp.sort()
        t=sum(tmp)
        for d in range(min(k-i-j,len(tmp))):
            if tmp[d]<0:
                t-=tmp[d]
        if t>ans:
            ans=t
print(ans)
    

Fixed submission:
n,k=map(int,input().split())
ans=0
v=list(map(int,input().split()))
for i in range(min(n,k+1)):
    for j in range(min(n-i+1,k-i+1)):
        if j!=0:
            tmp=v[:i]+v[-j:]
        else:
            tmp=v[:i]
        tmp.sort()
        t=sum(tmp)
        for d in range(min(k-i-j,len(tmp))):
            if tmp[d]<0:
                t-=tmp[d]
        if t>ans:
            ans=t
print(ans)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if b-a<=k and c-b<=k and d-c<=k and e-d<=k c-a<=k and d-a<=k and e-a<=k and d-b<=k and e-b<=k and e-c<=k:
    print("Yay!")
else:
    print(":(")

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if b-a<=k and c-b<=k and d-c<=k and e-d<=k and c-a<=k and d-a<=k and e-a<=k and d-b<=k and e-b<=k and e-c<=k:
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
from decimal import Decimal
n=int(input())
ans=0
for in range(n):
    x,y=map(str,input().split())
    if y=="BTC":
        ans+=Decimal(380000*Decimal(x))
    else:
        ans+=Decimal(x)
print(ans)

Fixed submission:
from decimal import Decimal
n=int(input())
ans=0
for i in range(n):
    x,y=map(str,input().split())
    if y=="BTC":
        ans+=Decimal(380000*Decimal(x))
    else:
        ans+=Decimal(x)
print(ans)
Buggy python submission (verdict: Runtime Error):
def f(a):
    cnt=0
    st=set()
    cnt+=1
    st.add(a)
    while True:
        if n%2!=0:
            tmp=a/2
        else:
            tmp=3*a+1
        if tmp in st:
            break
        st.add(tmp)
        a=tmp
    return cnt
a=int(input())     
ans= f(s)
print(ans)

Fixed submission:
def f(s):
    cnt = 0
    st = set()

    cnt += 1
    st.add(s)

    while True:
        cnt += 1

        if s % 2 == 0:
            tmp = s / 2
        else:
            tmp = 3 * s + 1

        if tmp in st:
            break

        st.add(tmp)
        s = tmp
    return cnt


s = int(input())
ans = f(s)
print(ans)

Buggy python submission (verdict: Runtime Error):
def f(a):
    cnt=0
    st=set()
    while True:
        if n%2!=0:
            tmp=a/2
        else:
            tmp=3*a+1
        if tmp in st:
            break
        st.add(tmp)
        a=tmp
    return cnt
a=int(input())     
ans= f(s)
print(ans)

Fixed submission:
def f(s):
    cnt = 0
    st = set()

    cnt += 1
    st.add(s)

    while True:
        cnt += 1

        if s % 2 == 0:
            tmp = s / 2
        else:
            tmp = 3 * s + 1

        if tmp in st:
            break

        st.add(tmp)
        s = tmp
    return cnt


s = int(input())
ans = f(s)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float("inf")]*n
dp[0]=0
for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float("inf")]*n
dp[0]=0
for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a={"3","5","7"}
ans=0
for v in range(n+1):
    k=set(str(v))
    if k ==a:
        ans+=1
print(ans)

Fixed submission:
N = int(input())
def dfs(s): 
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    # s 自体が七五三数なら +1 
    for c in '753':
        ret += dfs(s + c)
    return ret
print(dfs('0'))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a={"3","5","7"}
ans=0
for v in range(n+1):
    k=set(list(str(v)))
    if k ==a:
        ans+=1
print(ans)

Fixed submission:
N = int(input())
def dfs(s): 
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    # s 自体が七五三数なら +1 
    for c in '753':
        ret += dfs(s + c)
    return ret
print(dfs('0'))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[[]*i for i in range(n)]
tmp=[]
for i in range(m):
    p,y=map(int,input().split())
    p-=1
    a[p].append([y,i])
for k in range(n):
    if len(a[k])>0:
        a[k].sort()
        for j in a[k]:
            u=str(k+1).zfill(6)
            d=str(a[k].index(j)+1).zfill(6)
            ans=u+d
            tmp.append([ans,j[1]])
tmp.sort(key=lambda x:x[1])
for b in tmp:
    print(b[0])

Fixed submission:
n, m = map(int, input().split())
cnt = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    cnt[p].append((y, i))
buf = [None] * m
for p, l in enumerate(cnt):
    if not l:
        continue
    l.sort()
    for j, (y, i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p, j + 1)
print('\n'.join(buf))
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import sys
input=sys.stdin.readline
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n,m=map(int,input().split())
s=input()
t=input()
if s[0]!=t[0]:
    print(-1)
    exit()
k=lcm(n,m)
ans=[""for i in range(k)]
ans[0]=s[0]
for i in range(1,n):
    ans[i*(k//n)]=s[i]
for i in range(1,m):
    if not ans[i*(k//m)]:
        ans[i*(k//m)]=t[i]
    else:
        if ans[i*(k//m)]!=t[i]:
            print(-1)
            exit()
print(k)

Fixed submission:
from math import gcd
N,M = map(int, input().split())
S = input()
T = input()
G = gcd(N,M)
for i in range (G):
  if S[N//G * i] != T[M//G * i]:
    print(-1)
    exit()
print(N//G * M//G * G)

Buggy python submission (verdict: Runtime Error):
import fractions
import sys
input=sys.stdin.readline()
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n,m=map(int,input().split())
s=input()
t=input()
if s[0]!=t[0]:
    print(-1)
    exit()
k=lcm(n,m)
ans=[""for i in range(k)]
ans[0]=s[0]
for i in range(1,n):
    ans[i*(k//n)]=s[i]
for i in range(1,m):
    if not ans[i*(k//m)]:
        ans[i*(k//m)]=t[i]
    else:
        if ans[i*(k//m)]!=t[i]:
            print(-1)
            exit()
print(k)

Fixed submission:
from math import gcd
N,M = map(int, input().split())
S = input()
T = input()
G = gcd(N,M)
for i in range (G):
  if S[N//G * i] != T[M//G * i]:
    print(-1)
    exit()
print(N//G * M//G * G)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n,m=map(int,input().split())
s=input()
t=input()
if s[0]!=t[0]:
    print(-1)
    exit()
k=lcm(n,m)
ans=[""for i in range(k)]
ans[0]=s[0]
for i in range(1,n):
    ans[i*(k//n)]=s[i]
for i in range(1,m):
    if not ans[i*(k//m)]:
        ans[i*(k//m)]=t[i]
    else:
        if ans[i*(k//m)]!=t[i]:
            print(-1)
            exit()
print(k)

Fixed submission:
from math import gcd
N,M = map(int, input().split())
S = input()
T = input()
G = gcd(N,M)
for i in range (G):
  if S[N//G * i] != T[M//G * i]:
    print(-1)
    exit()
print(N//G * M//G * G)
Buggy python submission (verdict: Runtime Error):
n,T=map(int,input().split())
data=[input().split() for i in range(n)]
lc=[]
for row in data:
    if int(row[1]) <=T:
        lc.append(int(row[0]))

if not lc:
    print("TLE")
else:
    a=sorted(lc)
    print(a[0])

Fixed submission:
n=int(input())
if n==1:
    print("Hello World")
else:
    a=int(input())
    b=int(input())
    print(a+b)

Buggy python submission (verdict: Runtime Error):
n,T=map(int,input().split())
data=[input().split() for i in range(n)]
lc=[]
for row in data:
    if int(row[1]) <=T:
        lc.append(row[0])
if  len(lc)==0:
    print("TLE")
else:
    print(min(lc))

Fixed submission:
n=int(input())
if n==1:
    print("Hello World")
else:
    a=int(input())
    b=int(input())
    print(a+b)
Buggy python submission (verdict: Runtime Error):
from copy import *
n,m=map(int,input().split())
t=int(m/n)
while True:
    if m%t==0:
        if t*n<=m:
            print(t)
            exit()
        else:
            t-=1
    else:
        t-=1

Fixed submission:
n=int(input())
z=[]
aa=[]
for i in range(n):
     z.append(list(map(int,input().split())))
for cx in range(101):
    for cy in range(101):
        ans=set()
        for i in range(n):
            x,y,h=z[i][0],z[i][1],z[i][2]
            if h!=0:
                tmp=h+abs(x-cx)+abs(y-cy)
                ans.add(tmp)
        if len(ans)==1:
            ans=list(ans)
            aa.append((ans[0],cx,cy))

for a,cx,cy in aa:
    flg=True
    for i in range(n):
        x,y,h=z[i][0],z[i][1],z[i][2]
        if h!=max(a-abs(x-cx)-abs(y-cy),0):
                flg=False
    if flg:
        print(cx,cy,a)
        exit()

Buggy python submission (verdict: Runtime Error):
n=int(input())
z=[]
for i in range(n):
     z.append(list(map(int,input().split())))
for cx in range(101):
    for cy in range(101):
        ans=set()
        for i in range(n):
            x,y,h=z[i][0],z[i][1],z[i][2]
            if h!=0:
                tmp=h+abs(x-cx)+abs(y-cy)
                ans.add(tmp)
        if len(ans)==1:
            for i in range(n):
                x,y,h=z[i][0],z[i][1],z[i][2]
                if h==0:
                    if ans[0]-abs(x-cx)-abs(y-cy)>=0:
                        break
            print(cx,cy,*ans)
            exit()

Fixed submission:
n=int(input())
z=[]
aa=[]
for i in range(n):
     z.append(list(map(int,input().split())))
for cx in range(101):
    for cy in range(101):
        ans=set()
        for i in range(n):
            x,y,h=z[i][0],z[i][1],z[i][2]
            if h!=0:
                tmp=h+abs(x-cx)+abs(y-cy)
                ans.add(tmp)
        if len(ans)==1:
            ans=list(ans)
            aa.append((ans[0],cx,cy))

for a,cx,cy in aa:
    flg=True
    for i in range(n):
        x,y,h=z[i][0],z[i][1],z[i][2]
        if h!=max(a-abs(x-cx)-abs(y-cy),0):
                flg=False
    if flg:
        print(cx,cy,a)
        exit()
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
ans=[]
a=[list(map(int,input().split())) for i in range(h)]
flg=True
for i in range(h):
    if flg:
        for j in range(w):
            if a[i][j]%2==1:
                if j<w-1:
                    a[i][j+1]+=1
                    ans.append((i+1,j+1,i+1,j+2))
                if j==w-1:
                    if i<h-1:
                        a[i+1][j]+=1
                        ans.append(print(i+1,j+1,i+2,j+1))
        flg=False
    else:
        flg=True
        for j in range(w-1,-1,-1):
            if a[i][j]%2==1:
                if j>0:
                    a[i][j-1]+=1
                    ans.append((i+1,j+1,i+1,j))
                if j==0:
                    if i<h-1:
                        a[i+1][j]+=1
                        ans.append((i+1,j+1,i+2,j+1))
print(len(ans))
for i in ans:
    print(*i)

Fixed submission:
h,w=map(int,input().split())
ans=[]
a=[list(map(int,input().split())) for i in range(h)]
flg=True
for i in range(h):
    if flg:
        for j in range(w):
            if a[i][j]%2==1:
                if j<w-1:
                    a[i][j+1]+=1
                    ans.append((i+1,j+1,i+1,j+2))
                if j==w-1:
                    if i<h-1:
                        a[i+1][j]+=1
                        ans.append((i+1,j+1,i+2,j+1))
        flg=False
    else:
        flg=True
        for j in range(w-1,-1,-1):
            if a[i][j]%2==1:
                if j>0:
                    a[i][j-1]+=1
                    ans.append((i+1,j+1,i+1,j))
                if j==0:
                    if i<h-1:
                        a[i+1][j]+=1
                        ans.append((i+1,j+1,i+2,j+1))
print(len(ans))
for i in ans:
    print(*i)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
n,k=map(int,input().split())
if k%2==1:
    l=[i for i in range(k,n+1,k)]
    ans=len(list(product(l,repeat=3)))
if k%2==0:
    l=[i for i in range(k//2,n+1,k)]
    ll=[i for i in range(k,n+1,k)]
    ans=len(list(product(l,repeat=3)))+len(list(product(ll,repeat=3)))
print(ans)

Fixed submission:
from itertools import product
n,k=map(int,input().split())
if k%2==1:
    l=[i for i in range(k,n+1,k)]
    ans=len(l)**3
if k%2==0:
    l=[i for i in range(k//2,n+1,k)]
    ll=[i for i in range(k,n+1,k)]
    ans=len(l)**3+len(ll)**3
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n=int(input())
a=list(map(int,input().split()))

b=lcm_list(a)-1
ans=0
for i in a:
    tmp=b%i
    ans+=tmp
print(ans)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
x=1
for t in a:
    x=lcm(x,t)
x-=1
ans=0
for t in a:
    ans+=x%t
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n=int(input())
a=list(map(int,input().split()))

b=lcm_list(a)-1
ans=0
for i in a:
    tmp=b%i
    ans+=tmp
print(ans)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
x=1
for t in a:
    x=lcm(x,t)
x-=1
ans=0
for t in a:
    ans+=x%t
print(ans)