Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import gcd

def lcm(n,m):
    return (n*m)//gcd(n,m)

def main():
    a,b,c,d=map(int,input().split())
    num=b-a+1
    moda1=(a-1)//c
    moda2=(a-1)//d
    moda3=(a-1)//(lcm(c,d))
    modat=moda1+moda2-moda3
    modb1=b//c
    modb2=b//d
    modb3=b//(lcm(c,d))
    modbt=modb1+modb2-modb3
    mod=modbt-modat
    return num-mod

print(main())

Fixed submission:
from fractions import gcd

def lcm(n,m):
    return (n*m)//gcd(n,m)

def main():
    a,b,c,d=map(int,input().split())
    num=b-a+1
    moda1=(a-1)//c
    moda2=(a-1)//d
    moda3=(a-1)//(lcm(c,d))
    modat=moda1+moda2-moda3
    modb1=b//c
    modb2=b//d
    modb3=b//(lcm(c,d))
    modbt=modb1+modb2-modb3
    mod=modbt-modat
    return num-mod

print(main())
Buggy python submission (verdict: Runtime Error):
def rec(n,me,stair):
    if me[n-1]!=0:
        return me[n-1]
    elif n in stair:
        return 0
    elif n==1:
        if n-1 in stair:
            me[n-1]=0
            return 0
        me[n-1]=1
        return 1
    elif n==2:
        test1=n-1 in stair
        test2=n-2 in stair
        if test1 and test2:
            me[n-1]=0
            return 0
        elif test1 or test2:
            me[n-1]=1
            return 1
        me[n-2]=2
        return 2
    else:
        ans=rec(n-2,me,stair)+rec(n-1,me,stair)
        me[n-1]=ans
        return ans

n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
memo=[0]*(n+1)
print(rec(n,memo,a)%1000000007)


Fixed submission:
n,m=map(int,input().split())
stair_m=[True]*(110000)
for i in range(m):
    a=int(input())
    stair_m[a]=False
dp=[0]*(110000)
dp[0]=1
for i in range(1,n+1):
    if stair_m[i]:
        dp[i]=dp[i-1]+dp[i-2]
    else:
        dp[i]=0
print(dp[n]%1000000007)

Buggy python submission (verdict: Runtime Error):
import pysnooper

@pysnooper.snoop()
def rec(n,me,stair):
    if me[n-1]!=0:
        return me[n-1]
    elif n in stair:
        return 0
    elif n==1:
        if n-1 in stair:
            me[n-1]=0
            return 0
        me[n-1]=1
        return 1
    elif n==2:
        test1=n-1 in stair
        test2=n-2 in stair
        if test1 and test2:
            me[n-1]=0
            return 0
        elif test1 or test2:
            me[n-1]=1
            return 1
        me[n-2]=2
        return 2
    else:
        ans=rec(n-2,me,stair)+rec(n-1,me,stair)
        me[n-1]=ans
        return ans

n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
memo=[0]*(n+1)
print(rec(n,memo,a)%1000000007)


Fixed submission:
n,m=map(int,input().split())
stair_m=[True]*(110000)
for i in range(m):
    a=int(input())
    stair_m[a]=False
dp=[0]*(110000)
dp[0]=1
for i in range(1,n+1):
    if stair_m[i]:
        dp[i]=dp[i-1]+dp[i-2]
    else:
        dp[i]=0
print(dp[n]%1000000007)

Buggy python submission (verdict: Runtime Error):
import pysnooper

@pysnooper.snoop()
def rec(n,me,stair):
    if me[n-1]!=0:
        return me[n-1]
    elif n in stair:
        return 0
    elif n==1:
        if n-1 in a:
            me[n-1]=0
            return 0
        me[n-1]=1
        return 1
    elif n==2:
        test1=n-1 in a
        test2=n-2 in a
        if test1 and test2:
            me[n-1]=0
            return 0
        elif test1 or test2:
            me[n-1]=1
            return 1
        me[n-2]=2
        return 2
    else:
        ans=rec(n-2,me,stair)+rec(n-1,me,stair)
        me[n-1]=ans
        return ans

n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
memo=[0]*(n+1)
print(rec(n,memo,a)%1000000007)


Fixed submission:
n,m=map(int,input().split())
stair_m=[True]*(110000)
for i in range(m):
    a=int(input())
    stair_m[a]=False
dp=[0]*(110000)
dp[0]=1
for i in range(1,n+1):
    if stair_m[i]:
        dp[i]=dp[i-1]+dp[i-2]
    else:
        dp[i]=0
print(dp[n]%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
id=[0]*100010
for i in range(m):
    ll,rr=input().split()
    for j in range(int(ll),int(rr)+1):
        id[j]+=1

cnt=0
for i in range(1,n+1):
    if id[i]==m:
        cnt+=1
print(cnt)

Fixed submission:
n,m=map(int,input().split())
maxl,minr=0,n
for i in range(m):
    l,r=map(int,input().split())
    maxl=max(maxl,l)
    minr=min(minr,r)
print(max(0,minr-maxl+1))
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
cnt=0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            cnt+=1
        if j*g>n or i*r>n or s-bb>n:break
    if i*r>n:break
print(cnt)


Fixed submission:
r,g,b,n=map(int,input().split())
cnt=0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            cnt+=1
        if j*g>n or i*r>n or s-bb>n:break
    if i*r>n:break
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
cnt=0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            cnt+=1
        if j*g>n or i*r>n:break
    if i*r>n:break
print(cnt)

Fixed submission:
r,g,b,n=map(int,input().split())
cnt=0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            cnt+=1
        if j*g>n or i*r>n or s-bb>n:break
    if i*r>n:break
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
cnt=0
end=0
for i in range(0,3001):
    for j in range(0,3001):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            #print(i,j,bb)
            cnt+=1
        if j*g>n:break
    if i*r>n:break
print(cnt)

Fixed submission:
r,g,b,n=map(int,input().split())
cnt=0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            cnt+=1
        if j*g>n or i*r>n or s-bb>n:break
    if i*r>n:break
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache
setrecursionlimit(10**6)
input=stdin.readline

h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
d=[[False]*w for _ in range(h)]
dx=[1,-1,0,0]
dy=[0,0,1,-1]
q=deque()
nowi=[]
ans=0

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            nowi.append((i,j))
            d[i][j]=True
q.append(nowi)
#print(nowi)
while len(q):
    nowq=q.popleft()
    nextq=[]
    #print(nowq)
    for i in nowq:
        ny,nx=i
        for yx in range(4):
            if ny+dy[yx]<0 or ny+dy[yx]>=h:
                continue
            if nx+dx[yx]<0 or nx+dx[yx]>=w:
                continue
            if d[ny+dy[yx]][nx+dx[yx]]:
                continue
            nextq.append((ny+dy[yx],nx+dx[yx]))
            d[ny+dy[yx]][nx+dx[yx]]=True
    if len(nextq):
        q.append(nextq)
        ans+=1
    #print(nextq)
print(ans)

Fixed submission:
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache
setrecursionlimit(10**6)
input=stdin.readline

h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
d=[[False]*w for _ in range(h)]
dx=[1,-1,0,0]
dy=[0,0,1,-1]
q=deque()
nowi=[]
ans=0

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            nowi.append((i,j))
            d[i][j]=True
q.append(nowi)
#print(nowi)
while len(q):
    nowq=q.popleft()
    nextq=[]
    #print(nowq)
    for i in nowq:
        ny,nx=i
        for yx in range(4):
            if ny+dy[yx]<0 or ny+dy[yx]>=h:
                continue
            if nx+dx[yx]<0 or nx+dx[yx]>=w:
                continue
            if d[ny+dy[yx]][nx+dx[yx]]:
                continue
            nextq.append((ny+dy[yx],nx+dx[yx]))
            d[ny+dy[yx]][nx+dx[yx]]=True
    if len(nextq):
        q.append(nextq)
        ans+=1
    #print(nextq)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,t=map(int,input().split())
cnt=0
for i in range(1,t+0.5,a):
    cnt+=b
print(cnt)

Fixed submission:
a,b,t=map(int,input().split())
cnt=0
for i in range(a,t+1,a):
    cnt+=b
print(cnt)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
left=right=[0]*n
for i in range(1,n):
    left[i]=gcd(left[i-1],a[i-1])
for i in range(n-1)[::-1]:
    right[i]=gcd(right[i+1],a[i+1])
ans=[gcd(x[i],y[i]) for i in range(n)]
print(max(ans))

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))+[0]
left=[0]*(n+1)
right=[0]*(n+1)
for i in range(1,n):
    left[i]=gcd(left[i-1],a[i-1])
for i in range(n,0,-1):
    right[i-1]=gcd(right[i],a[i])
ans=[gcd(right[i],left[i]) for i in range(n)]
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
for i in range(n-1):
    if a[i]<0:
        a[i]=a[i]*(-1)
        a[i+1]=a[i+1]*(-1)
    b=max(b,sum(a))
print(sum(a))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in a:
    if i<0:
        cnt+=1
s=0
for i in range(n):
    s+=abs(a[i])
if cnt%2==1:
    c=10**10
    for i in range(n):
        num=abs(a[i])
        if num<c:
            c=num
    s=s-(c*2)
print(s)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
r=S.count(".")
a=r
for i in range(n):
  if s[i]=="#":r+=1
  else:r-=1
  a=min(a,r)
print(a)


Fixed submission:
n=int(input())
s=input()
r=s.count(".")
a=r
for i in range(n):
  if s[i]=="#":r+=1
  else:r-=1
  a=min(a,r)
print(a)
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
m=max(a,b)
ans=[]
for i in range(1,m):
  if a%i==0 and b%i==0:
    ans.append(i)
ans.reverse()
print(ans[k-1])

Fixed submission:
a,b,k=map(int,input().split())
inte=[];mini=min(a,b);j=1
for i in range(1,mini+1):
  if a%i==0 and b%i==0:
    inte.append(i)
inte.sort(reverse=True)
print(inte[k-1])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

s=input().rstrip()
t="keyence"
i,j=0,0
while len(s)>i:
    if s[i]==t[j]:
        j+=1
    i+=1
print("YES"if j==7 else "NO")

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

s=input().rstrip()
n=len(s)
t="keyence"
for i in range(n):
    for j in range(i,n):
        if s[:i]+s[j:]==t:
            print("YES")
            exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
n,h,w=map(int,input().split())
cnt=0
for i in range(n):
  a,b=map(int,input().split)
  if h<=a and w<=b:
    cnt+=1
print(cnt)

Fixed submission:
n,h,w=map(int,input().split())
cnt=0
for i in range(n):
  a,b=map(int,input().split())
  if h<=a and w<=b:
    cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
a=list(map(int,input().split()))
m=10**10
for i in a:
    dis=abs(i-x)
    if m>dis:
        m=dis
while True:
    j=1
    for i in a:
        num=abs(i-x)
        if num%m!=0:
            j=0
    if j:
        break
    else:
        m-=1
print(m)

Fixed submission:
from fractions import gcd
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=abs(a[0]-x)
for i in range(1,n):
    ans=gcd(ans,abs(a[i]-x))
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
c=[]
for i in range(len(s)):
    for j in range(min(len(s)-i,k)):
        t=s[i:i+j+1]
        if t not in cnt:
            c.append(t)
print(sorted(c)[k-1])

Fixed submission:
s=input()
k=int(input())
cnt=[]
for i in range(len(s)):
    for j in range(min(len(s)-i,k)):
        t=s[i:i+j+1]
        if t not in cnt:
            cnt.append(t)
print(sorted(cnt)[k-1])
Buggy python submission (verdict: Runtime Error):
s=list(map(int,input().split()))
a=max(s)*3-sum(s)
if a%2==1
    a+=3
print(a//2)

Fixed submission:
s=list(map(int,input().split()))
a=max(s)*3-sum(s)
if a%2==1:
    a+=3
print(a//2)
Buggy python submission (verdict: Runtime Error):
n=int(input())
m=a=r=c=h=0
ls
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif a[0]=='A':
        a+=1
    elif a[0]=='R':
        r+=1
    elif a[0]=='C':
        c+=1
    elif a[0]=='H':
        h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Fixed submission:
n=int(input())
m=a=r=c=h=0
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif s[0]=='A':
        a+=1
    elif s[0]=='R':
        r+=1
    elif s[0]=='C':
        c+=1
    elif s[0]=='H':
        h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[]
for i in range(n):
    a=int(input())
    if a in s:
        for j in range(len(s)):
            if s[j]==a:
                s.pop(j)
                break
    else:
        s.append(a)
    #print(s)
print(len(s))

Fixed submission:
from collections import Counter
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
index,cnt=zip(*Counter(a).most_common())
ans=0
for i in range(len(index)):
    if cnt[i]%2==1:
        ans+=1
print(ans)
#print(index,cnt)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
n=int(input())
s=1
for i in range(n):
    t=int(input())
    s=lcm(a,t)
print(s)

Fixed submission:
from fractions import gcd
a=1
for _ in[0]*int(input()):
    t=int(input())
    a*=t//gcd(a,t)
print(a)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
n=int(input())
s=1
for i in range(n):
    t=int(input())
    s=lcm(a,t)

Fixed submission:
from fractions import gcd
a=1
for _ in[0]*int(input()):
    t=int(input())
    a*=t//gcd(a,t)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    if i%2==1:
        b=[a[i]]+b
    else:
        b+=[a[i]]
if n%2==0:
    print(*b)
else:
    print(*b[::-1])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=a[1::2][::-1]+a[::2]
if n%2==0:
    print(*b)
else:
    print(*b[::-1])

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

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=a[1::2][::-1]+a[::2]
if n%2==0:
    print(*b)
else:
    print(*b[::-1])

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

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=a[1::2][::-1]+a[::2]
if n%2==0:
    print(*b)
else:
    print(*b[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    b.append(a[i])
    b=b[::-1]
print(*b)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=a[1::2][::-1]+a[::2]
if n%2==0:
    print(*b)
else:
    print(*b[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin,setrecursionlimit
import sys
from math import factorial
setrecursionlimit(10**6)
input=stdin.readline

a,b=map(int,input().split())
if abs(a-b)>1:
    print(0)
else:
    ans=factorial(a)*factorial(b)
    print(ans if abs(a-b)==1 else ans*2)


Fixed submission:
from sys import stdin,setrecursionlimit
import sys
from math import factorial
setrecursionlimit(10**6)
input=stdin.readline

a,b=map(int,input().split())
if abs(a-b)>1:
    print(0)
else:
    mod=10**9+7
    fact=[0]*(max(a,b)+1)
    fact[0],fact[1]=1,1
    for i in range(2,max(a,b)+1):
        fact[i]=(i*fact[i-1])%mod
    ans=(fact[a]*fact[b])%mod
    print(ans if abs(a-b)==1 else (ans*2)%mod)
Buggy python submission (verdict: Runtime Error):
import sys
n=int(input())
s=[]
for i in range(n):
  s.append(int(input()))
s.sort()
sm=sum(s)
if sm%10!=0:
  print(sm)
  sys.exit()
while 1:
  a=s.pop(0)
  t=sum(s)
  if t%10!=0:
    print(t)
    sys.exit()

Fixed submission:
n=int(input())
s=[];ans=0
for i in range(n):
  a=int(input())
  if a%10!=0:
    s.append(a)
  ans+=a
s.sort()
if ans%10==0:
  if s:
    ans-=s[0]
  else:
    ans=0
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

n,m=map(int,input().split())
g=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]

for i in g:
    a,b=i[0],i[1]
    dis=10**10
    ind=1
    for j in range(m):
        x,y=c[j][0],c[j][1]
        now=abs(a-x)+abs(b-y)
        if now<dis:
            dis=now
            ind=j+1
    print(ind)import sys
input=sys.stdin.readline

n,m=map(int,input().split())
g=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]

for i in g:
    a,b=i[0],i[1]
    dis=10**10
    ind=1
    for j in range(m):
        x,y=c[j][0],c[j][1]
        now=abs(a-x)+abs(b-y)
        if now<dis:
            dis=now
            ind=j+1
    print(ind)

Fixed submission:
import sys
input=sys.stdin.readline

n,m=map(int,input().split())
g=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]

for i in g:
    a,b=i[0],i[1]
    dis=10**10
    ind=1
    for j in range(m):
        x,y=c[j][0],c[j][1]
        now=abs(a-x)+abs(b-y)
        if now<dis:
            dis=now
            ind=j+1
    print(ind)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

input=sys.stdin.readline

n,m=map(int,input().split())
G=[[False]*n for _ in range(n)]
used=[False]*n

def dfs(now,depth):
    if used[now]:
        return 0
    if n==depth:
        return 1
    used[now]=True
    ans=0
    for i in range(n):
        if G[now][i]:
            ans+=dfs(i,depth+1)
    used[now]=False
    return ans

for _ in range(n):
    a,b=map(int,input().split())
    G[a-1][b-1]=True
    G[b-1][a-1]=True

print(dfs(0,1))

Fixed submission:
def dfs(n,depth):
    if used[n]:
        return 0
    if depth==N:
        return 1
    used[n]=1
    ans=0
    for i in range(N):
        if connect[n][i]:
            ans+=dfs(i,depth+1)
    used[n]=0
    return ans

N,M=map(int,input().split())
used=[0]*N
connect=[[0 for i in range(N)]for j in range(N)]
a=[];b=[]

for i in range(M):
    x,y=map(int,input().split())
    a.append(x-1)
    b.append(y-1)

for i in range(M):
    connect[a[i]][b[i]]=connect[b[i]][a[i]]=1

print(dfs(0,1))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a.sort()
dp = [0 for i in range(a[-1])]
p = [0 for i in range(a[-1])]
for i in range(n):
    p[a[i]-1] = 1
ans = 1
for i in range(2,a[-1]+1):
    if dp[i-1] == 1:
        continue
    u = 0
    k = 1
    while i*k <= a[-1]:
        dp[i*k-1] = 1
        if p[i*k-1] == 1:
            u += 1
        k += 1
    if u == n:
        ans = -1
    elif u > 1:
        ans = min(ans,0)
elif ans == 1:
    print('pairwise coprime')
elif ans == 0:
    print('setwise coprime')
elif a[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort()
dp = [0 for i in range(a[-1])]
p = [0 for i in range(a[-1])]
for i in range(n):
    p[a[i]-1] += 1
ans = 1
for i in range(2,a[-1]+1):
    if dp[i-1] == 1:
        continue
    u = 0
    k = 1
    while i*k <= a[-1]:
        dp[i*k-1] = 1
        if p[i*k-1] != 0:
            u += p[i*k-1]
        k += 1
    if u == n:
        ans = -1
    elif u > 1:
        ans = min(ans,0)
if ans == 1:
    print('pairwise coprime')
elif ans == 0:
    print('setwise coprime')
elif a[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')
Buggy python submission (verdict: Time Limit Exceeded):
h,w,m = map(int,input().split())
p = [[0 for i in range(w)]for i in range(h)]
hlist = [0 for i in range(h)]
wlist = [0 for i in range(w)]
for i in range(m):
    a,b = map(int,input().split())
    hlist[a-1] += 1
    wlist[b-1] += 1
    p[a-1][b-1] = 1
q = 0
for i in range(h):
    q = max(q,hlist[i])
s = []
for i in range(h):
    if hlist[i] == q:
        s.append(i)
r = 0
for i in range(w):
    r = max(r,wlist[i])
t = []
for i in range(w):
    if wlist[i] == r:
        t.append(i)
ans = 0
for i in range(len(s)):
    for j in range(len(t)):
        if p[s[i]][t[j]] == 1:
            pass
        else:
            ans = q+r
            break
if ans == 0:
    print(q+r-1)
else:
    print(ans)

Fixed submission:
h,w,m = map(int,input().split())
p = []
hlist = [0 for i in range(h)]
wlist = [0 for i in range(w)]
for i in range(m):
    a,b = map(int,input().split())
    hlist[a-1] += 1
    wlist[b-1] += 1
    p.append([a-1,b-1])
q = 0
for i in range(h):
    q = max(q,hlist[i])
s = []
for i in range(h):
    if hlist[i] == q:
        s.append(i)
r = 0
for i in range(w):
    r = max(r,wlist[i])
t = []
for i in range(w):
    if wlist[i] == r:
        t.append(i)
z = 0
for i in range(m):
    if hlist[p[i][0]] == q and wlist[p[i][1]] == r:
        z += 1
if z == len(s)*len(t):
    print(q+r-1)
else:
    print(q+r)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = list(map(int,input().split()))
import copy
a = copy.deepcopy(p)
for i in range(n):
    a[i] = [-a[i],0,i]
import heapq as hp
hp.heapify(a)
for i in range(k):
    s = hp.heappop(a)
    u = [s[0]/2,s[1]+1,s[2]]
    hp.heappush(a, u)
ans = 0
for i in range(n):
    ans = max(-(-p[a[i][2]]//(a[i][1]+1)),ans)
print(ans)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
def test(d,m,u):
    global ans
    p = 0
    for i in range(n):
        if m < a[i]:
            p += a[i]//m
    if u-d <= 1:
        ans = max(ans,m)
        pass
    elif p > k:
        ans = max(ans,m)
        d = m
        m = -(-(m+u)//2)
        test(d,m,u)
    else:
        u = m
        m = -(-(m+d)//2)
        test(d,m,u)
d = 0
m = 1
u = 10**9+7
test(d,m,u)
print(ans)