Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
k = int(input())
a,b = map(int, input().sprit())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)

    


Fixed submission:
k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)

Buggy python submission (verdict: Runtime Error):
k = int(input())
a,b = map(int, input().sprit())
ans = False
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = True

if ans==True : print('OK')
else : print('NG')
    


Fixed submission:
k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)

Buggy python submission (verdict: Runtime Error):
k = int(input)
a,b = map(int, input().sprit())
ans = False
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = True

if ans==True : print('OK')
else : print('NG')
    


Fixed submission:
k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)

Buggy python submission (verdict: Runtime Error):
k = int(input)
a,b = map(int, input().sprit())
ans = False
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = True

if ans : print('OK')
else : print('NG')
    


Fixed submission:
k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)

Buggy python submission (verdict: Runtime Error):
k = int(input)
a,b = map(int, input().sprit())
ans = False
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = True

if ans : print('OK')
else print('NG')
    


Fixed submission:
k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)

Buggy python submission (verdict: Runtime Error):
k = int(input)
a,b = map(int, input().sprit())
ans = False
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = True
    break
    
if ans : print('OK')
else print('NG')
    

Fixed submission:
k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

if s[2]==s[3] ans s[4]==s[5] : print('Yes')
else : print('No')

Fixed submission:
s = input()

if s[2]==s[3] and s[4]==s[5] : print('Yes')
else : print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = n

i = 1

while i*i<=n :
  if n%i == 0 :
    d = n/i
    if ans > i*d-2 : ans = i*d-2
  i++
      
print(ans)

Fixed submission:
n = int(input())
ans = n
i = 1
while i*i<=n :
  if n%i == 0 :
    d = n//i
    if ans > i+d-2 : ans = i+d-2
  i+=1
print(int(ans))
Buggy python submission (verdict: Runtime Error):
s = input()

n = []*26

for e in s:
  n[e-'a']+=1
  
for i in n:
  if i>1:
    print("no")
    return
print("yes)

Fixed submission:
s = input()
n = [0]*26
for e in s:
  n[ord(e)-ord('a')]+=1
for i in n:
  if i>1:
    print("no")
    exit()
print("yes")
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret
memo=set()
n=input()
g=0
l=list(map(int,input().split()))
for i in l:
    g=gcd(i,g)
if g!=1:print('not coprime');exit()

for i in l:
    for p in primeFactor(i):
        if p in memo:print("setwise coprime");exit()
        memo.add(p)
print("pairwise coprime")

Fixed submission:
n,a=int(input()),list(map(int,input().split()))
g=0
from math import gcd
for i in a:g=gcd(i,g)
if g!=1:print("not coprime")
else:
    from collections import defaultdict
    memo=defaultdict(int)
    for i in a:
        for p in range(2,int(i**.5)+1):
            if i%p==0:
                while i%p==0:i//=p
                if memo[p]:
                    print("setwise coprime");exit()
                memo[p]+=1
        if i!=1:
            if memo[i]:print("setwise coprime");exit()
            memo[i]+=1
    print("pairwise coprime")
Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)

from collections import Counter as co

wk,wv= co(ys).most_common(1)[0]
hk,hv= co(ys).most_common(1)[0]
print(wv+kv-(hk,wk)in setobj)

Fixed submission:
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)
from collections import Counter as co
xs,ys=co(xs),co(ys)
xim,yim=xs.most_common(1)[0][1], ys.most_common(1)[0][1]
A=len([1 for u in xs.values() if u==xim])* len([1 for u in ys.values() if u==yim])
for a,b in setobj:
  if xs[a]==xim and ys[b]==yim:A-=1

print(xim+yim-1+int(A>0))

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)

from collections import Counter as co
ws=co(ys).most_common(2)
#key value
hs=co(xs)
ans=1
for i in range(1,h+1):
    preans=0 if i not in hs else hs[i]
    ans=max(ans,preans+max(ws[0][1]-int((i,ws[0][0]) in setobj), ws[1][1]-int((i,ws[1][0]) in setobj)))
print(ans)

Fixed submission:
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)
from collections import Counter as co
xs,ys=co(xs),co(ys)
xim,yim=xs.most_common(1)[0][1], ys.most_common(1)[0][1]
A=len([1 for u in xs.values() if u==xim])* len([1 for u in ys.values() if u==yim])
for a,b in setobj:
  if xs[a]==xim and ys[b]==yim:A-=1

print(xim+yim-1+int(A>0))
Buggy python submission (verdict: Time Limit Exceeded):
# Binary Index Tree (2-dimension)
class BIT2:
    # H*W, 0-based
    def __init__(self, h, w):
        self.w,self.h=w,h
        self.data = [{}for i in range(h+1)]
    #O(logH*logW)
    #[0.i)x[0.j)
    def sum(self, i, j):
        s = 0
        i -= 1
        data = self.data
        while i >= 0:
            el = data[i]
            k = j - 1 
            while k >= 0:
                s += el.get(k, 0)
                k =( k & (k+1)) - 1

            i = (i&(i+1))-1
        return s

    # O(logH*logW)
    def add(self, i, j, x):
        w = self.w; h = self.h
        data = self.data
        while i < h:
            el = data[i]
            k = j
            while k < w:
                el[k] = el.get(k, 0) + x
                k|=(k+1)
            i|=(i+1)
    # [x0, x1) x [y0, y1)
    def range_sum(self, x0, x1, y0, y1):
        return self.sum(x1, y1) - self.sum(x1, y0) - self.sum(x0, y1) + self.sum(x0, y0)
ans=0
bit=BIT2(20,20)
for i in range(int(input())):
    a=input().split('.')
    if len(a)==1:
        cnt2,cnt5=9,9
        a=int(a[0])
        while a%2==0 and cnt2<18:
            cnt2+=1
            a//=2
        while a%5==0 and cnt5<18:
            cnt5+=1
            a//=5
    else:
        a=int(a[0])*10**9+int((a[1][::-1].zfill(9))[::-1])
        cnt2,cnt5=0,0
        for j in range(18):
            if a%2==0:
                a//=2
                cnt2+=1
            if a%5==0:
                a//=5
                cnt5+=1
    ans+=bit.range_sum(18-cnt2,19,18-cnt5,19)
    bit.add(cnt2,cnt5,1)
print(ans)

Fixed submission:
# Binary Index Tree (2-dimension)
class BIT2:
    # H*W, 0-based
    def __init__(self, h, w):
        self.w,self.h=w,h
        self.data = [{}for i in range(h+1)]
    #O(logH*logW)
    #[0.i)x[0.j)
    def sum(self, i, j):
        s = 0
        i -= 1
        data = self.data
        while i >= 0:
            el = data[i]
            k = j - 1 
            while k >= 0:
                s += el.get(k, 0)
                k =( k & (k+1)) - 1

            i = (i&(i+1))-1
        return s

    # O(logH*logW)
    def add(self, i, j, x):
        w = self.w; h = self.h
        data = self.data
        while i < h:
            el = data[i]
            k = j
            while k < w:
                el[k] = el.get(k, 0) + x
                k|=(k+1)
            i|=(i+1)
    # [x0, x1) x [y0, y1)
    def range_sum(self, x0, x1, y0, y1):
        return self.sum(x1, y1) - self.sum(x1, y0) - self.sum(x0, y1) + self.sum(x0, y0)
ans=0
bit=BIT2(20,20)
for i in range(int(input())):
    a=input().split('.')
    if len(a)==1:
        cnt2,cnt5=9,9
        a=int(a[0])
        while a%2==0 and cnt2<18:
            cnt2+=1
            a//=2
        while a%5==0 and cnt5<18:
            cnt5+=1
            a//=5
    else:
        a=int(a[0])*10**9+int((a[1][::-1].zfill(9))[::-1])
        cnt2,cnt5=0,0
        for j in range(18):
            if a%2==0:
                a//=2
                cnt2+=1
            if a%5==0:
                a//=5
                cnt5+=1
    ans+=bit.range_sum(18-cnt2,19,18-cnt5,19)
    bit.add(cnt2,cnt5,1)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
#(ng,ok]type
#if k==0:print(max(l));exit()
#(ng,ok]type
ok,ng=10**9+1,-1
def enough(x):
    return sum( (i//x) for i in l if i>x)<=k
# [ok,ng)type->eraseng,ok=ok,ng
eps=10**(-3)
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if enough(mid):ok=mid
    else:ng=mid
print(ok)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
#(ng,ok]type
#if k==0:print(max(l));exit()
#(ng,ok]type
ok,ng=10**9+1,0
def enough(x):
    return sum( (i//x) for i in l if i>x)<=k
# [ok,ng)type->eraseng,ok=ok,ng
eps=10**(-3)
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if enough(mid):ok=mid
    else:ng=mid
print(ok)
Buggy python submission (verdict: Runtime Error):
import numba
@numba.njit('(i8,)', cache=True)
def m(n):
    return sum(m*((n//m)**2+n//m-m**2) for m in range(1,int(n**.5)+1))

print(m(int(input())))

Fixed submission:
n=int(input())
from math import sqrt,floor
x=floor(sqrt(n))
print(sum(m*(n//m+m)*(n//m+1-m) for m in range(1,floor(sqrt(n))+1))  -x*(x+1)*(2*x+1)//6)

Buggy python submission (verdict: Runtime Error):

N = int(input())
print(sum(i*(N//i)*(N//i + 1) // 2 for i in range(1,N+1) )


Fixed submission:
n=int(input())
from math import sqrt,floor
x=floor(sqrt(n))
print(sum(m*(n//m+m)*(n//m+1-m) for m in range(1,floor(sqrt(n))+1))  -x*(x+1)*(2*x+1)//6)
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
s=len(input())
mod=10**9+7
fact=[1]*(2*10**6+4+1)
inv=[1]*(2*10**6+4+1)
for i in range(2,2*10**6+4+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(2*10**6+4,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
print((pow(26,k+s,mod)-sum(25**(k+s-i)*comb(k+s,i) for i in range(s))%mod)%mod)

Fixed submission:
k=int(input())
s=len(input())
mod=10**9+7
fact=[1]*(k+s+1)
inv=[1]*(k+s+1)
for i in range(2,k+s+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(k+s,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
ans=pow(26,k+s,mod)
for i in range(s):
    ans=(ans-pow(25,k+s-i,mod)*comb(k+s,i)%mod)%mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

a,s,d,f=map(int,input().split())
dp=[[0]*(f+1) for i in range(d+1)]
dp[a][s]=1
mod=998244353

for x in range(a,d+1):
    for y in range(s,f+1):
        if x==a and y==s:continue
        dp[x][y]=(dp[x-1][y]*y+dp[x][y-1]*x-dp[x-1][y-1]*(x-1)*(y-1))%mod
        
print(dp[d][f])


Fixed submission:

a,s,d,f=map(int,input().split())
dp=[[0]*(f+1) for i in range(d+1)]
dp[a][s]=1
mod=998244353

for x in range(a,d+1):
    for y in range(s,f+1):
        if x==a and y==s:continue
        dp[x][y]=(dp[x-1][y]*y+dp[x][y-1]*x-dp[x-1][y-1]*(x-1)*(y-1))%mod
        
print(dp[d][f])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
from collections import Counter as co
l=co(map(int,input().split()))
ans=set()
for k in l:
    if l[k]>=2:ans.add(k)
    for j in range(2*k,10**6+1,k):
        if j in l:
            ans.add(j)
        
        
print(len(l)-len(ans))

Fixed submission:
n=int(input())
from collections import Counter as co
l=co(list(map(int,input().split())))
ans=len(l)
ng=set()
for k in l:
    if l[k]>=2:ng.add(k)
    for i in range(2*k,10**6+1,k):

        if i in l:
            ng.add(i)
            
            

print(ans-len(ng))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
from itertools import accumulate
def update(a):
    ret=[0]*len(a)
    for i,x in enumerate(a):
        ret[max(i-x,0)]+=1
        r=min(n-1,i+x)
        if r==n-1:continue
        ret[r+1]-=1
    return list(accumulate(ret))
for i in range(min(50,k)):
    l=update(l)
print(*l)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
from itertools import accumulate
def update(a):
    ret=[0]*len(a)
    for i,x in enumerate(a):
        ret[max(i-x,0)]+=1
        r=min(n-1,i+x)
        if r==n-1:continue
        ret[r+1]-=1
    return list(accumulate(ret))
for i in range(min(50,k)):
    l=update(l)
print(*l)
Buggy python submission (verdict: Time Limit Exceeded):
ans=1
n=int(input())
lim=10**18
for i in list(map(int,input().split())):
    ans*=i
print(ans if ans<=lim else -1)


Fixed submission:
ans=1
n=int(input())
lim=10**18
l=list(map(int,input().split()))
if 0 in set(l):print(0);exit()
for i in l:
    ans*=i
    if ans>lim:print(-1);exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod1,mod2=10**9+7,998244353
mod=mod2
n,s=map(int,input().split())
dp=[0]*(s+1)
dp[0]=1
for a in map(int,input().split()):
    for i in range(s,a-1,-1):
        dp[i]=(dp[i]*2%mod+dp[i-a])%mod
    for i in range(min(s,a-1),-1,-1):
        dp[i]=2*dp[i]%mod
        
print(dp[-1])


Fixed submission:
n,s=map(int,input().split())
dp=[0]*(s+1)
dp[0]=1
ne=[0]*(s+1)
mod=998244353
for i in list(map(int,input().split())):

    for k in range(0,s+1):
        if k+i<=s:
            ne[k+i]=(ne[k+i]+dp[k])%mod
        ne[k]=(ne[k]+2*dp[k])%mod
        dp[k]=0
    dp,ne=ne,dp
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
mod1,mod2=10**9+7,998244353
mod=mod2
n,s=map(int,input().split())
dp=[0]*(s+1)
dp[0]=1
for a in map(int,input().split()):
    for i in range(s,a-1,-1):
        dp[i]=(dp[i]*2%mod+dp[i-a])%mod
    for i in range(a-1,-1,-1):
        dp[i]=2*dp[i]%mod
        
print(dp[-1])


Fixed submission:
n,s=map(int,input().split())
dp=[0]*(s+1)
dp[0]=1
ne=[0]*(s+1)
mod=998244353
for i in list(map(int,input().split())):

    for k in range(0,s+1):
        if k+i<=s:
            ne[k+i]=(ne[k+i]+dp[k])%mod
        ne[k]=(ne[k]+2*dp[k])%mod
        dp[k]=0
    dp,ne=ne,dp
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
table=[-1]*n
edges=[[] for i in range(n)]
costs=[n]*n
for i in range(m):
    a,s=map(int,input().split())
    edges[a-1].append(s-1);edges[s-1].append(a-1)
def dfs(now,pre,cost):
    if costs[now]>cost:
        costs[now]=cost
        table[now]=pre+1
        for i in edges[now]:
            dfs(i,now,cost+1)
dfs(0,0,0)
if -1 not in table[1:]:
    print("Yes")
    for i in range(1,n):
        print(table[i])
else:print("No")

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

n,m=map(int,input().split())
edges=[[] for i in range(n)]
table=[-1]*n
for i in range(m):
    a,s=map(int,input().split())
    edges[a-1].append(s-1);edges[s-1].append(a-1)
l=[0]
print()
from collections import deque as que
q=que([(-1,0)])
p=que()
flag=1
ok=0
while flag:
    flag=0
    while len(q):
        flag=1
        pre,now=q.pop()
        if table[now]==-1:
            ok+=1
            table[now]=pre+1
            for i in edges[now]:
                if table[i]==-1:
                    p.append((now,i))
    p,q=q,p






if ok==n:
    print("Yes")
    for i in range(1,n):
        print(table[i])
else:print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
table=[-1]*n
edges=[[] for i in range(n)]
costs=[n]*n
for i in range(m):
    a,s=map(int,input().split())
    edges[a-1].append(s-1);edges[s-1].append(a-1)
def dfs(now,pre,cost):
    if costs[now]>cost:
        costs[now]=cost
        table[now]=pre+1
        for i in edges[now]:
            dfs(i,now,cost+1)
dfs(0,0,0)
if -1 not in table[1:]:
    print("Yes")
    for i in range(1,n):
        print(table[i])
else:print("No")

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

n,m=map(int,input().split())
edges=[[] for i in range(n)]
table=[-1]*n
for i in range(m):
    a,s=map(int,input().split())
    edges[a-1].append(s-1);edges[s-1].append(a-1)
l=[0]
print()
from collections import deque as que
q=que([(-1,0)])
p=que()
flag=1
ok=0
while flag:
    flag=0
    while len(q):
        flag=1
        pre,now=q.pop()
        if table[now]==-1:
            ok+=1
            table[now]=pre+1
            for i in edges[now]:
                if table[i]==-1:
                    p.append((now,i))
    p,q=q,p






if ok==n:
    print("Yes")
    for i in range(1,n):
        print(table[i])
else:print("No")
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.buffer.readline
mod=10**9+7
n=int(input())
d={}
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if x<0:x*=-1;y*=-1
        if x==0 and y<0:y=-y
        d[(x,y)]=1 if (x,y)not in d else d[(x,y)]+=1
ans=1
for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)-1 + pow(2,ng,mod)-1 +1)%mod
    ans%=mod
    d[(a,s)]=0
print((ans+z-1)%mod)

Fixed submission:
mod=10**9+7
n=int(input())
from collections import defaultdict
d=defaultdict(int)#各点の方向ベクトルを管理
z=0#原点にいる際は例外処理したいので別途数える
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f#非本質な定数倍を削除
        if x<0:x*=-1;y*=-1#偏角は|theta|<=pi/2で十分
        if x==0 and y<0:y=-y
        d[(x,y)]+=1
ans=1
for (a,s) in d:
    if d[(a,s)]==0:continue#すでに数えた
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)-1 + pow(2,ng,mod)-1 +1)%mod
    #(a,s)を一本以上使う,ngを((a,s)と直交するもの)を一本以上使う,どちらも使わない
    ans%=mod
    d[(a,s)]=0
print((ans+z-1)%mod)#原点はそれ1つのみでしか使えない　+　1つも使わない例を除外

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.buffer.readline
mod=10**9+7
n=int(input())
d={}
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if x<0:x*=-1;y*=-1
        if x==0 and y<0:y=-y
        d[(x,y)]+=1 if (x,y)in d else d[(x,y)]=1
ans=1
for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)-1 + pow(2,ng,mod)-1 +1)%mod
    ans%=mod
    d[(a,s)]=0
print((ans+z-1)%mod)

Fixed submission:
mod=10**9+7
n=int(input())
from collections import defaultdict
d=defaultdict(int)#各点の方向ベクトルを管理
z=0#原点にいる際は例外処理したいので別途数える
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f#非本質な定数倍を削除
        if x<0:x*=-1;y*=-1#偏角は|theta|<=pi/2で十分
        if x==0 and y<0:y=-y
        d[(x,y)]+=1
ans=1
for (a,s) in d:
    if d[(a,s)]==0:continue#すでに数えた
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)-1 + pow(2,ng,mod)-1 +1)%mod
    #(a,s)を一本以上使う,ngを((a,s)と直交するもの)を一本以上使う,どちらも使わない
    ans%=mod
    d[(a,s)]=0
print((ans+z-1)%mod)#原点はそれ1つのみでしか使えない　+　1つも使わない例を除外
Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
mod=998244353
if m==1:print(0 if k!=n-1 else 1);exit()
fact=[1]*(n-1+1)
inv=[1]*(n-1+1)
for i in range(2,n-1+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n-1,1,-1):
    inv[i-1]=inv[i]*i%mod
ans=0
po=pow(m-1,n-1,mod)*m%mod
ue=fact[n-1]
iii=pow(m-1,mod-2,mod)%mod
for i in range(k+1):
    ans+=ue*inv[n-1-i]%mod*inv[i]%mod*po%mod
    po*=iii
print(ans%mod)


Fixed submission:
s,d=[input(),input()]
print("Yes") if s==d[:-1] else print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c,k-map(inat,input().split())
ans=0
ans+=min(k,a)
k-=min(k,a)
k-=min(k,b)
ans-=min(k,c)
print(ans)

Fixed submission:
a,b,c,k=map(int,input().split())
if k<=a:print(k)
elif k<=a+b:print(a)
else:print(2*a-k+b)
Buggy python submission (verdict: Time Limit Exceeded):
def f():
    n,k=map(int,input().split())
    l=list(map(int,input().split()))
    now=1

    for i in range(k.bit_length()):
        if k and k%2:now=l[now-1]
        l=[l[l[i]-1]for i in range(n)]
        k//=2
    print(now)
if __name__ == "__main__":
    f()

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=set()
now=0
l=[]
while now not in ok and k:
    l.append(now)
    ok.add(now)
    now=a[now]-1
    k-=1
if k==0:print(now+1);exit()
length=len(ok)-(h:=l.index(now))
l=l[h:]

k=(k)%length

print(l[k]+1)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=set()
now=0
l=[]
while now not in ok and k:
    l.append(now)
    ok.add(now)
    now=a[now]-1
    k-=1
length=len(ok)-(h:=l.index(now))
l=l[h:]
print(l,h,length)
k=(k)%length

print(l[k]+1)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=set()
now=0
l=[]
while now not in ok and k:
    l.append(now)
    ok.add(now)
    now=a[now]-1
    k-=1
if k==0:print(now+1);exit()
length=len(ok)-(h:=l.index(now))
l=l[h:]

k=(k)%length

print(l[k]+1)