Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys

sys.setrecursionlimit(10000000)

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


@lru_cache(maxsize=None)
def rec(i, reverse):
    if i == N - 1:
        return A[i] * reverse

    num_normal = rec(i + 1, 1) + (A[i] * reverse)
    num_reverse = rec(i + 1, -1) + (-1 * A[i] * reverse)

    return max(num_normal, num_reverse)


print(rec(0, 1))


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

minus_count = 0

for a in A:
    if a < 0:
        minus_count += 1

total = 0
min_num = 10 ** 9

for a in A:
    total += abs(a)
    min_num = min(min_num, abs(a))

if minus_count % 2 == 1:
    total -= 2 * min_num

print(total)

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


@lru_cache(maxsize=None)
def rec(i, reverse):
    if i == N - 1:
        return A[i] * reverse

    num_normal = rec(i + 1, +1) + (A[i] * reverse)
    num_reverse = rec(i + 1, -1) + (-A[i] * reverse)

    return max(num_normal, num_reverse)


print(rec(0, 1))


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

minus_count = 0

for a in A:
    if a < 0:
        minus_count += 1

total = 0
min_num = 10 ** 9

for a in A:
    total += abs(a)
    min_num = min(min_num, abs(a))

if minus_count % 2 == 1:
    total -= 2 * min_num

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

count = 0

while '01' in S or '10' in S:
    if '01' in S:
        count += S.count('01')
        S = S.replace('01', '')
    if '10' in S:
        count += S.count('10')
        S = S.replace('10', '')

print(count * 2)


Fixed submission:
S = input()

count_0 = S.count('0')
count_1 = S.count('1')

print(min(count_0, count_1) * 2)

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

#print('01' in S)
#print('10' in S)

count = 0

while '01' in S or '10' in S:
    #print(S)
    #print('01' in S or '10' in S)
    if '01' in S:
        count += S.count('01')
        S = S.replace('01', '')
    if '10' in S:
        count += S.count('10')
        S = S.replace('10', '')

print(count * 2)




Fixed submission:
S = input()

count_0 = S.count('0')
count_1 = S.count('1')

print(min(count_0, count_1) * 2)

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

#print('01' in S)
#print('10' in S)

count = 0

while '01' in S or '10' in S:
    #print(S)
    #print('01' in S or '10' in S)
    if '01' in S:
        S = S.replace('01', '', 1)
        count += 1
    if '10' in S:
        S = S.replace('10', '', 1)
        count += 1

print(count * 2)




Fixed submission:
S = input()

count_0 = S.count('0')
count_1 = S.count('1')

print(min(count_0, count_1) * 2)

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

#print('01' in S)
#print('10' in S)

count = 0

while '01' in S or '10' in S:
    #print(S)
    #print('01' in S or '10' in S)
    if '01' in S:
        S = S.replace('01', '', 1)
        count += 1
    if '10' in S:
        S = S.replace('10', '', 1)
        count += 1

print(count * 2)




Fixed submission:
S = input()

count_0 = S.count('0')
count_1 = S.count('1')

print(min(count_0, count_1) * 2)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]

h.sort()

min_h = 1000000000

for i in range(K - 1, N):
    min_h = min(min_h, h[i] - h[i - K + 1])

print(min_h)


Fixed submission:
D = int(input())

if D == 25:
    print('Christmas')
elif D == 24:
    print('Christmas Eve')
elif D == 23:
    print('Christmas Eve Eve')
else:
    print('Christmas Eve Eve Eve')
Buggy python submission (verdict: Runtime Error):
inn = input()
numS = 0
for c in inn:
    if c == 'R':
        numS += 1
if numR != 2:
    print(numR)
else:
    print(1 if inn[1] == 'S' else 2)

Fixed submission:
inn = input()
numR = 0
for c in inn:
    if c == 'R':
        numR += 1
if numR != 2:
    print(numR)
else:
    print(1 if inn[1] == 'S' else 2)

Buggy python submission (verdict: Runtime Error):
inn = input()
numS = 0
for c in inn:
    if c == 'R':
        numS += 1
if numR != 2:
    print(numR)
else:
    print(1 if inn[1] == 'S' else 2);

Fixed submission:
inn = input()
numR = 0
for c in inn:
    if c == 'R':
        numR += 1
if numR != 2:
    print(numR)
else:
    print(1 if inn[1] == 'S' else 2)
Buggy python submission (verdict: Runtime Error):
import sys
import sympy

ans = 0
for i in range(1, int(input())+1):
    ans += 1 if i%2==1 and len(sympy.divisors(i)) == 8 else 0
print(ans)

Fixed submission:
import sys

def div(n):
    count = 0
    for i in range(1, n+1):
        count += 1 if n%i==0 else 0
    return count

ans = 0
for i in range(1, int(input())+1):
    ans += 1 if i%2==1 and div(i) == 8 else 0
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
print(a*b)

Fixed submission:
a,b = map(int,input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans=1
for e in a:
  ans *= e
if(ans > 10**18):
  print("-1")
else:
  print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans=1
for e in a:
  ans *= e
  if(ans > 10**18) :
    ans = -1
    break
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N=int(input())
C=list(input())

qw=deque(list())
qr=deque(list())

ans=0
for i in range(N//2):
    if C[i]=='W':
        qw.append(i)
    if C[-(i+1)]=='R':
        qr.append(-(i+1))
    if len(qw)>0 and len(qr)>0:
        ans+=1
        l=qw.popleft()
        r=qr.popleft()
        C[l],C[r]=C[r],C[l]

if len(qw)>0:
    l=qw.popleft()
    if C[l+1]=='R':
        C[l+1]='W'
        ans+=1
elif len(qr)>0:
    r=qr.popleft()
    if C[r-1]=='W':
        C[r-1]='R'
        ans+=1

if (C[N//2-1]==C[N//2]==C[N//2+1]) or (C[N//2]=='R' and C[N//2-1]=='R' and C[N//2+1]=='W') or (C[N//2]=='W' and C[N//2-1]=='R' and C[N//2+1]=='R'):
    print(ans)
else:
    print(ans+1)



Fixed submission:
N=int(input())
C=list(input())

white=[0]*(N+1)
red=[0]*(N+1)

for i in range(N):
    if C[i]=="W":
        white[i+1]=white[i]+1
        red[i+1]=red[i]
    else:
        white[i+1]=white[i]
        red[i+1]=red[i]+1

if white[-1]==N or red[-1]==N:
    print(0)
    exit()

ans=float("inf")
for i in range(1,N):
    wcnt=white[i]
    rcnt=red[-1]-red[i]
    m=max(wcnt,rcnt)
    ans=min(m,ans)

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

point=1
for i in range(K):
    point*=A[i]

point_=point
for i in range(K,N):
    point_*=A[i]
    point_//=A[i-K]
    if point_>point:
        print('Yes')
    else:
        print('No')
    point=point_

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

for i in range(K,N):
    if A[i]>A[i-K]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=map(int,input().split())
border=10**18

ans=1
for a in A:
    ans*=a

if ans>border:
    print(-1)
else:
    print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
border=10**18

ans=1
for a in A:
    ans*=a
    if ans>border:
        print(-1)
        exit()
    elif ans==0:
        print(0)
        exit()

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

ans=0
for i in range(N):
    if A[i]>N-2: continue
    for j in range(i+A[i]+1,N):
        s=A[i]+A[j]
        if s==j-i:
            ans+=1
print(ans)

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

Aii=[0]*(N)
Ajj=[0]*(N)

for i in range(N):
    x=A[i]+i+1
    y=i+1-A[i]
    if 1<x<N: Aii[x]+=1
    if 1<y<N: Ajj[y]+=1

ans=0
for i in range(N):
    ans+=Aii[i]*Ajj[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

R,G,B=[],[],[]
for i,s in enumerate(S):
    if s=='R': R.append(i+1)
    elif s=='G': G.append(i+1)
    else: B.append(i+1)

ans=0
for r in R:
    for g in G:
        for b in B:
            i=min(r,g,b)
            k=max(r,g,b)
            j=r+g+b-(i+k)
            if j-i!=k-j: ans+=1
print(ans)

Fixed submission:
N=int(input())
S=input()

r,g,b=0,0,0
for s in S:
    if s=='R': r+=1
    elif s=='G': g+=1
    else: b+=1


ng=0
for i in range(N):
    for j in range(i+1,N):
        k=j+(j-i)
        if k>=N: continue
        if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
            ng+=1

ans=r*g*b
print(ans-ng)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]==S[j]: continue
        for k in range(j+1,N):
            if (j-i!=k-j) and (S[i]!=S[k]) and (S[j]!=S[k]):
                ans+=1
print(ans)

Fixed submission:
N=int(input())
S=input()

r,g,b=0,0,0
for s in S:
    if s=='R': r+=1
    elif s=='G': g+=1
    else: b+=1


ng=0
for i in range(N):
    for j in range(i+1,N):
        k=j+(j-i)
        if k>=N: continue
        if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
            ng+=1

ans=r*g*b
print(ans-ng)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if (j-i!=k-j) and (S[i]!=S[j]) and (S[j]!=S[k]) and (S[i]!=S[k]):
                ans+=1
print(ans)

Fixed submission:
N=int(input())
S=input()

r,g,b=0,0,0
for s in S:
    if s=='R': r+=1
    elif s=='G': g+=1
    else: b+=1


ng=0
for i in range(N):
    for j in range(i+1,N):
        k=j+(j-i)
        if k>=N: continue
        if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
            ng+=1

ans=r*g*b
print(ans-ng)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
A=list(map(int,input().split()))

A_=Counter(A)
D=[0]*N
S=0
for k,v in A_.items():
    if v<2:
        continue
    a=v*(v-1)//2
    D[k]=a
    S+=a

for a in A:
    x=A_[a]
    y=x*(x-1)//2
    S-=y
    z=(x-1)*(x-2)//2
    print(S+z)
    S+=y



Fixed submission:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
A__=list(set(A))
A_=Counter(A)
S=0
for a in A__:
    k=a
    v=A_[a]
    if v<2:
        continue
    a=v*(v-1)//2
    S+=a

for a in A:
    x=A_[a]
    y=x*(x-1)//2
    S-=y
    z=(x-1)*(x-2)//2
    print(S+z)
    S+=y
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[input() for _ in range(N)]
S_=list(set(S))

ans=0
ans_s=[]
for s in S_:
    x=S.count(s)
    if ans<x:
        ans=x
        ans_s=[s]
    elif ans==x:
        ans_s.append(s)

ans_s.sort()

for a in ans_s:
    print(a)

Fixed submission:
N=int(input())
S=[input() for _ in range(N)]
S_=list(set(S))

ans_d={s:0 for s in S_}
for s in S:
    ans_d[s]+=1

M=max(set(ans_d.values()))
for k,v in sorted(ans_d.items()):
    if v==M:
        print(k)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,K=map(int,input().split())
P=list(map(int,input().split()))

cnt=0
ans=0
q=deque([])
for i in range(N):
    q.append(P[i]*(P[i]+1)//2/P[i])
    if len(q)==K:
        if sum(q)>ans:
            ans=sum(q)
        q.popleft()
print(ans)

Fixed submission:
from collections import deque
N,K=map(int,input().split())
P=list(map(int,input().split()))

cnt=0
ans=0
buf=0
buf_2=0
q=deque([])
cnt=0
for i in range(N):
    cnt+=1
    buf=P[i]*(P[i]+1)//2/P[i]
    q.append(buf)
    buf_2+=buf
    if cnt>=K:
        if ans<buf_2:
            ans=buf_2
        buf_2-=q.popleft()
    # if len(q)==K:
    #     if sum(q)>ans:
    #         ans=sum(q)
    #     q.popleft()
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
x=math.gcd(a,b)
print(int((a*b)/x))

Fixed submission:
a,b=map(int,input().split())
def gcd(x,y):
    while y!=0:
        x,y=y,x%y
    return x
print(int((a*b)/gcd(a,b)))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
x=0
b_brick=0
for i in range(N):
    try:
        x+=A[x:].index(i+1)
        b_brick+=1
    except:
        break
if b_brick<=0:
    print(-1)
else:
    print(N-b_brick)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
x=1
for a in A:
    if a==x:
        x+=1
    else:
        pass
if x==1:
    print(-1)
else:
    print(N-x+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read=sys.stdin.buffer.readline

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

L.sort()

def binary_tree(data,l_index,value):
    left=l_index
    right=N-2
    while left<=right:
        mid=(left+right)//2
        if data[mid]>=value and data[mid-1]<value:
            return mid-1
        elif data[mid]<value:
            left=mid+1
        else:
            right=mid-1
    if data[-1]<value:
        return N-1
    return -1

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        x=binary_tree(L,j+1,L[i]+L[j])
        if x!=-1:
            ans+=(x-j)

print(ans)

Fixed submission:
import sys
from bisect import bisect_left

read=sys.stdin.buffer.readline

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

L.sort()

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans+=bisect_left(L,L[i]+L[j])-(j+1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())

# 素数だったら1を返す
def prime_number(n):
    for x in range(2,n):
        if n%x==0:
            return 0
    return 1

ans=0
m=min(a,b)//2+2
for i in range(1,m):
    if a%i==0 and b%i==0:
        ans+=prime_number(i)

print(ans)


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

A,B=map(int,read().split())

def factorization(n):
    arr=set([1])
    temp=n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.add(i)
    if temp!=1:
        arr.add(temp)
    if arr==[]:
        arr.add(n)
    return arr


print(len(factorization(A)&factorization(B)))
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q=map(int,input().split())
A=[int(input()) for _ in range(Q)]
if K>Q:
    for n in range(N):
        print("Yes")
else:
    N_dic={n+1:K for n in range(N)}
    for a in A:
        for k,v in N_dic.items():
            if a!=k:
                N_dic[k]=v-1
    for v in N_dic.values():
        if v>0:
            print("Yes")
        else:
            print("No")

Fixed submission:
N,K,Q=map(int,input().split())
# A=[int(input()) for _ in range(Q)]
point=[0]*N
for i in range(Q):
    point[int(input())-1]+=1
for i in range(N):
    ans=K-(Q-point[i])
    if ans>0:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q=map(int,input().split())
A=[int(input()) for _ in range(Q)]
Point=[K for _ in range(N)]
len_Point=len(Point)
for a in A:
    for i in range(len_Point):
        if i!=a-1:
            Point[i]=Point[i]-1
for p in Point:
    if p<=0:
        print("No")
    else:
        print("Yes")

Fixed submission:
N,K,Q=map(int,input().split())
# A=[int(input()) for _ in range(Q)]
point=[0]*N
for i in range(Q):
    point[int(input())-1]+=1
for i in range(N):
    ans=K-(Q-point[i])
    if ans>0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
b=list(map(int,input().split()))
if N==1:
    a=[b[0]]*2
elif N==2:
    minb=min(b[0],b[1])
    a=[minb]*2
    a.append(b[-1])    
elif N>2:
    minb=min(b[0],b[1])
    a=[minb]*2
    for i in range(1,N-2):
        minb=min(b[i],b[i+1])
        a.append(minb)
    a.append(b[-1])
print(sum(a))

Fixed submission:
N=int(input())
b=list(map(int,input().split()))
a=b[0]
for i in range(0,N-2):
    a+=min(b[i],b[i+1])
print(a+b[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
lst=[N%1]
for i in range(2,N+1):
    lst.append((i-1)%i)
print(sum(lst))

Fixed submission:
N=int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
d={i:[] for i in range(1,N+1)}

ans=[0]*N
for i in range(1,N):
    a,b=map(int,input().split())
    d[a].append(b)

def f(n,x):
    if d[n]==[]:
        return 0
    for m in d[n]:
        ans[m-1]+=x
        f(m,x)

for i in range(Q):
    p,x=map(int,input().split())
    ans[p-1]+=x
    hoge=f(p,x)

for a in ans:
    print(a,end=' ')

Fixed submission:
N,Q=map(int,input().split())
d=[[] for _ in range(N+1)]

ans=[0]*(N+1)
for i in range(1,N):
    a,b=map(int,input().split())
    d[a].append(b)
    d[b].append(a)

for i in range(Q):
    p,x=map(int,input().split())
    ans[p]+=x

from collections import deque
flag=[0]*(N+1)
q=deque([1])
while q:
    k=q.popleft()
    flag[k]=1
    for v in d[k]:
        if flag[v]==1:
            continue
        ans[v]+=ans[k]
        q.appendleft(v)

print(*ans[1:])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
read_=sys.stdin.buffer.readline

N=int(read_())
S=[Counter(list(input())) for _ in range(N)]

ans=0

for i in range(N-1):
    for j in range(i+1,N):
        if S[i]==S[j]:
            ans+=1
print(ans)

Fixed submission:
N=int(input())
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)

Buggy python submission (verdict: Runtime Error):
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)

Fixed submission:
N=int(input())
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
s=[sorted(list(input())) for _ in range(N)]
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i]==s[j]:
            ans+=1
print(ans)

Fixed submission:
N=int(input())
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
s=[collections.Counter(input()) for _ in range(N)]
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i]==s[j]:
            ans+=1
print(ans)

Fixed submission:
N=int(input())
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
ans=0
N=int(input())
s_lst=[input() for _ in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        si=collections.Counter(s_lst[i])
        sj=collections.Counter(s_lst[j])
        if si==sj:
            ans+=1
print(ans)

Fixed submission:
N=int(input())
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

A_set=set(A)
A_lst=list(A_set)

# すべてが0のとき
if sum(A_set)==0 and len(A_set)==1:
    print('Yes')
    exit()

# x…2N/3,0…N/3
if len(A_set)==2 and A_set.count(0)==1 t and A_set.count(sum(A_set)//2)==2 and len(A)%3==0:
    print('Yes')
    exit()

# x^y^z==0
if len(A_set)==3 and A_lst[0]^A_lst[1]^A_lst[2]==0 and len(A)%3==0:
    print('Yes')
    exit()

# それ以外
print('No')

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

A_set=set(A)
A_lst=list(A_set)

# すべてが0のとき
if sum(A_set)==0 and len(A_set)==1:
    print('Yes')
    exit()

# x…2N/3,0…N/3
if len(A_set)==2 and A_lst.count(0)==1 and len(A)%3==0:
    cnt=0
    for i in range(N):
        if A[i]==0:
            cnt+=1
    if cnt==N//3:
        print('Yes')
    else:
        print('No')
    exit()

# x^y^z==0
if len(A_set)==3 and A_lst[0]^A_lst[1]^A_lst[2]==0 and len(A)%3==0:
    cnt_x,cnt_y,cnt_z=0,0,0
    x,y,z=A_lst[0],A_lst[1],A_lst[2]
    for i in range(N):
        if A[i]==x:
            cnt_x+=1
            continue
        if A[i]==y:
            cnt_y+=1
            continue
        if A[i]==z:
            cnt_z+=1
    if cnt_x==cnt_y==cnt_z:
        print('Yes')
    else:
        print('No')
    exit()

# それ以外
print('No')

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

A_set=set(A)
A_lst=list(A_set)

# すべてが0のとき
if sum(A_set)==0:
    print('Yes')
    exit()

# x…2N/3,0…N/3
if 0 in A_set and A_set.count(sum(A_set)//2)==2 and len(A)%3==0:
    print('Yes')
    exit()

# x^y^z==0
if A_lst[0]^A_lst[1]^A_lst[2]==0 and len(A)%3==0:
    print('Yes')
    exit()

# それ以外
print('No')

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

A_set=set(A)
A_lst=list(A_set)

# すべてが0のとき
if sum(A_set)==0 and len(A_set)==1:
    print('Yes')
    exit()

# x…2N/3,0…N/3
if len(A_set)==2 and A_lst.count(0)==1 and len(A)%3==0:
    cnt=0
    for i in range(N):
        if A[i]==0:
            cnt+=1
    if cnt==N//3:
        print('Yes')
    else:
        print('No')
    exit()

# x^y^z==0
if len(A_set)==3 and A_lst[0]^A_lst[1]^A_lst[2]==0 and len(A)%3==0:
    cnt_x,cnt_y,cnt_z=0,0,0
    x,y,z=A_lst[0],A_lst[1],A_lst[2]
    for i in range(N):
        if A[i]==x:
            cnt_x+=1
            continue
        if A[i]==y:
            cnt_y+=1
            continue
        if A[i]==z:
            cnt_z+=1
    if cnt_x==cnt_y==cnt_z:
        print('Yes')
    else:
        print('No')
    exit()

# それ以外
print('No')
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())

def func(x,y,z):
    if (x-y)%z==0:
        return (x-y)//z
    else:
        return (x-y)//z+1
def gid(x,y):
    ans=x%y
    x=y
    y=ans
    while True:
        ans=x%y
        if ans==0:
            return y
            break
        x=y
        y=ans
cd=[c,d]
cd.sort()
cd2=cd[1]*cd[0]//(gid(cd[1],cd[0]))
_c=func(b,a,c)
_d=func(b,a,d)
_cd2=func(b,a,cd2)
print((b-a+1)-(_c+_d-_cd2))


Fixed submission:
import fractions
a,b,c,d=map(int,input().split())
lcm=c*d//fractions.gcd(c,d)
print(b-a+1-((b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//lcm-(a-1)//lcm)))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
cd=[c,d]
cd.sort()
l=b-a+1

def func(n,m):
    if m%n!=0:
        return m//n+1
    else:
        return m//n

def func2(x,y):
    ans=x%y
    x=y
    y=ans
    while True:
        ans=x%y
        if ans==0:
            return y
        x=y
        y=ans
cd2=cd[1]*cd[0]//(func2(cd[1],cd[0]))
print(l-(func(c,l)+func(d,l)-func(cd2,l)))


Fixed submission:
import fractions
a,b,c,d=map(int,input().split())
lcm=c*d//fractions.gcd(c,d)
print(b-a+1-((b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//lcm-(a-1)//lcm)))
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))
d,cnt=0,0
for i in range(1,N+2):
    if d<=X:
        d=d+L[i-1]
        cnt+=1
print(cnt)


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

N,X=map(int,read().split())
L=list(map(int,read().split()))

ans=1
res=0
for l in L:
    res+=l
    if res<=X:
        ans+=1
    else:
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))
d,cnt=0,0
for i in range(1,N+2):
    if d>X:
        break
    d=d+L[i-1]
    cnt+=1
print(cnt)

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

N,X=map(int,read().split())
L=list(map(int,read().split()))

ans=1
res=0
for l in L:
    res+=l
    if res<=X:
        ans+=1
    else:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
dp=[0]*(n+2)
dp[0]=1
for i in range(n):
    if i in a:
        continue
    dp[i+1]+=dp[i]
    dp[i+2]+=dp[i]
print(dp[n]%1000000007)

Fixed submission:
n,m=map(int,input().split())
a=set(int(input()) for _ in range(m))
dp=[0]*(n+2)
dp[0]=1
for i in range(n):
    if i in a:
        continue
    dp[i+1]+=dp[i]
    dp[i+2]+=dp[i]
print(dp[n]%1000000007)