Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
ans=0
for i in range(Q):
    q=input()
    if q[0]=='2':
        if ans%2==0:
            if q[2]=='1':
                S=q[4]+S
            else:
                S=S+q[4]
        else:
            if q[2]=='1':
                S=S+q[4]
            else:
                S=q[4]+S
    else:
        ans+=1
print(S if ans%2==0 else S[::-1])

Fixed submission:
from collections import deque
S=deque(input())
Q=int(input())
ans=0
for i in range(Q):
    q=input()
    if q[0]=='2':
        if ans%2==0:
            if q[2]=='1':
                S.appendleft(q[4])
            else:
                S.append(q[4])
        else:
            if q[2]=='1':
                S.append(q[4])
            else:
                S.appendleft(q[4])
    else:
        ans+=1
S="".join(S)
print(S if ans%2==0 else S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for i in range(Q):
    q=input()
    if q[0]=='2':
        if q[2]=='1':
            S=q[4]+S
        else:
            S=S+q[4]
    else:
        S=S[::-1]
print(S)

Fixed submission:
from collections import deque
S=deque(input())
Q=int(input())
ans=0
for i in range(Q):
    q=input()
    if q[0]=='2':
        if ans%2==0:
            if q[2]=='1':
                S.appendleft(q[4])
            else:
                S.append(q[4])
        else:
            if q[2]=='1':
                S.append(q[4])
            else:
                S.appendleft(q[4])
    else:
        ans+=1
S="".join(S)
print(S if ans%2==0 else S[::-1])
Buggy python submission (verdict: Runtime Error):
S,T=map(str,input().split())
A,B=map(int,input().split())
U=input()
if U==S:
    A-=1
else:
    B-=1
print(f"{A} {B}")

Fixed submission:
S,T=map(str,input().split())
A,B=map(int,input().split())
U=input()
if U==S:
    A-=1
else:
    B-=1
print(A, B)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=[int(i) for i in input().split()]
cnt=0
for r in range(N):
    if P[r]==min(P[0:r+1]):
        cnt+=1
    else:
        continue
print(cnt)

Fixed submission:
N=int(input())
P=[int(i) for i in input().split()]
min=2*(10**5)+1
cnt=0
for r in P:
    if min>=r:
        min=r
        cnt+=1
    else:
        continue
print(cnt)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
print(S.count('ABC'))

Fixed submission:
a,b = map(int,input().split())
sum=int(a)*500
if sum>=b:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N=input()
S=input()
print(S.count('ABC'))

Fixed submission:
a,b = map(int,input().split())
sum=int(a)*500
if sum>=b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import math
A,B=map(int,input().split())
print(A*B//(math.gcd(A,B)))

Fixed submission:
import fractions
A,B=map(int,input().split())
print(A*B//(fractions.gcd(A,B)))

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
import math
print(A*B//(math.gcd(A,B)))

Fixed submission:
import fractions
A,B=map(int,input().split())
print(A*B//(fractions.gcd(A,B)))
Buggy python submission (verdict: Runtime Error):
S=input()
for i in range(0,(len(S)),2):
    if S[i]=='R' or S[i]=='U' or S[i]=='D':
        for j in range (1,(len(S)),2):
            if S[j]=='L' or S[j]=='U' or S[j]=='D':
                mark=True
            else:
                mark=False
                break
    else:
        mark=False
        break
print('Yes' if mark==True else 'No')

Fixed submission:
S=input()
print('No' if 'L' in S[0::2] or 'R' in S[1::2] else 'Yes')
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q=map(int,input().split())
A=[int(input()) for i in range(Q)]
Z=[K for i in range(N)]
for i in A:
    for c in range(N):
        if c==i-1:
            continue
        else:
            Z[c]=Z[c]-1
for t in Z:
    if t<=0:
        print('No')
    else:
        print('Yes')

Fixed submission:
N,K,Q=map(int,input().split())
l=[0 for i in range(N)]
for t in range(Q):
    A=int(input())
    l[A-1]+=1
for i in range(N):
    if K-(Q-l[i])<=0:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
ans=sum(B)
for s in range(N-1):
        if A[s+1]==A[s]+1:
            ans+=C[A[s]-1]
print(ans)
    

Fixed submission:
N=int(input())
print(N**3)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        for t in range(T,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
    else:
        continue
print(int(cnt))    

Fixed submission:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))

Buggy python submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
for i in S.values():
    mul=1
    v=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))    

Fixed submission:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))

Buggy python submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
for i in S.values():
    mul=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))    

Fixed submission:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))

Buggy python submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
print(S.values())
for i in S.values():
    mul=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))    

Fixed submission:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for i in range(N)]
D=sorted(A)
num=max(D)
num2=D[-2]
for i in range(N):
    if A[i]==num:
        print(num2)
    else:
        print(num)

Fixed submission:
r=int(input())
print(3*(r**2))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[input() for i in range(N)]
for i in range(N):
    D=A[0:i]+A[i+1:]
    print(max(D))
    

Fixed submission:
N=int(input())
A=[int(input()) for i in range(N)]
D=sorted(A)
num=max(D)
num2=D[-2]
for i in range(N):
    if A[i]==num:
        print(num2)
    else:
        print(num)
Buggy python submission (verdict: Runtime Error):
import fraction
A,B,C,D=map(int,input().split())
L=C*D//(fraction.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Fixed submission:
import fractions
A,B,C,D=map(int,input().split())
L=C*D//(fractions.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D=map(int,input().split())
L=C*D//(math.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Fixed submission:
import fractions
A,B,C,D=map(int,input().split())
L=C*D//(fractions.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D=map(int,input().split())
L=A*B//(math.gcd(A,B))
print(int(B-A+1-(B//C-A//C)-(B//D-A//D)+(B//L-A//L)))

Fixed submission:
import fractions
A,B,C,D=map(int,input().split())
L=C*D//(fractions.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D=map(int,input().split())
cnt=0
for i in range(A,B+1):
    if i%C==0 or i%D==0:
        cnt+=1
    else:
        continue
print(B-A+1-cnt)

Fixed submission:
import fractions
A,B,C,D=map(int,input().split())
L=C*D//(fractions.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=[0 for i in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    for t in range(L-1,R):
        A[t]+=1
cnt=A.count(M)
print(cnt)

Fixed submission:
N,M=map(int,input().split())
l=[]
r=[]
for i in range(M):
    L,R=map(int,input().split())
    l.append(L)
    r.append(R)
big=min(r)
small=max(l)
print(big-small+1 if big-small>=0 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
A=[]
for t in range(Q):
    l,r=map(int,input().split())
    T=S[l-1:r]
    cnt=0
    for k in range(len(T)-1):
        if T[k:k+2]=='AC':
            cnt+=1
        else:
            continue
    A.append(cnt)
for s in A:
    print(s)

Fixed submission:
N,Q=map(int,input().split())
S=input()
t=[0]*(N+1)
for i in range(N):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
Z=''
A=[]
for i in range(Q):
    cnt=0
    l,r=map(int,input().split())
    Z=S[l-1:r]
    for t in range(len(Z)-1):
        if Z[t:t+2]=='AC':
            cnt+=1
        else:
            continue
    A.append(cnt)
for a in A:
    print(a)

Fixed submission:
N,Q=map(int,input().split())
S=input()
t=[0]*(N+1)
for i in range(N):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)

Fixed submission:
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=fractions.gcd(ans,A[i+1])
print(ans)

Fixed submission:
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=fractions.gcd(ans,A[i+1])
print(ans)

Fixed submission:
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=math.gcd(ans,A[i+1])
print(ans)

Fixed submission:
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
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')

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):
N,T=map(int,input().split())
ct=[list(map(int,input().split())) for a in range(N)]

ct=sorted(ct, key=lambda x:(x[0],x[1]))

print(ct[0])
for i in range(N):
    if ct[i][1]<=t:
        print(ct[i][0])
        break
else:
    print('TLE')

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())
ct=[list(map(int,input().split())) for a in range(N)]

ct=sorted(ct, key=lambda x:(x[0],x[1]))

for i in range(N):
    if ct[i][1]<=t:
        print(ct[i][0])
        break
else:
    print('TLE')

Fixed submission:
N,T=map(int,input().split())
ct=[list(map(int,input().split())) for a in range(N)]

ct=sorted(ct, key=lambda x:(x[0],x[1]))

for i in range(N):
    if ct[i][1]<=T:
        print(ct[i][0])
        break
else:
    print('TLE')
Buggy python submission (verdict: Runtime Error):
import math
N,X=map(int,input().split())
x=[int(i) for i in input().split()]
A=[]
for t in x:
    A.append(abs(t-X))
ans=A[0]
for s in A:
    ans=math.gcd(ans,s)
print(ans)

Fixed submission:
import fractions
N,X=map(int,input().split())
x=[int(i) for i in input().split()]
A=[]
for t in x:
    A.append(abs(t-X))
ans=A[0]
for s in A:
    ans=fractions.gcd(ans,s)
print(ans)
Buggy python submission (verdict: Runtime Error):
x1,y1,x2,y2=map(int,input().split())
print(x2-(y2-y1),y2-(x1-x2),x1-(y2-y1),y1-(x1-x2),end='')

Fixed submission:
K=int(input())
print(int((K/2)**2) if K%2==0 else int(K/2)*(int(K/2)+1))
Buggy python submission (verdict: Runtime Error):
D,N=map(int,input().split())
print((100**D)*N if N<100 else print((N+1)*(100+D))

Fixed submission:
A,B= map(int,input().split())
print(":(" if A>8 or B>8 else "Yay!")
Buggy python submission (verdict: Runtime Error):
D,N=map(int,input().split())
print((100**D)*N if N<100 else print((N+1)*(100**D))

Fixed submission:
D,N=map(int,input().split())
print(((100**D)*N) if N<100 else ((N+1)*(100**D)))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=b-a
summy=((n+1)*n)/2
print(int(summy-b))

Fixed submission:
N=int(input())
print('ABC' if N<=999 else'ABD')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
for i in range(0,N):
    a=S[0:i].count('E')
    b=S[i:N+1].count('W')
    ans=max(ans,a+b)
print(N-ans)

Fixed submission:
N=int(input())
S=input()
left=0
right=S[1:N].count('E')
ans=left+right
for i in range(1,N):
    if S[i-1]=='W':
        left+=1
    if S[i]=='E':
        right-=1
    ans=min(ans,left+right)
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
C=set()
for i in range(A,A+K):
    C.add(i)
for t in range(B-K-1,B+1):
    C.add(t)
for s in C:
    print(s)

Fixed submission:
S=input()
line=set(S)
if len(line)==3:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
for i in range(A,B+1):
    if i<A+K or i>B-K:
        print(i)
    else:
        continue


Fixed submission:
A,B,K=map(int,input().split())
ans=[]
for i in range(A,A+K):
    if A<=i<=B:
        ans.append(i)
    else:
        break
for t in range(B-K+1,B+1):
    if A<=t<=B: 
        ans.append(t)
    else:
        break
for z in sorted(set(ans)):
    print(z)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-') and len(S)==x+y+1:
    print('Yes')
else:
    print('No')

Fixed submission:
print(48-int(input()))
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-') and len(S)==(x+y+1):
    print('Yes')
else:
    print('No')

Fixed submission:
A,B=map(int,input().split())
S=input()
if S[:A].isdecimal() and S[A+1:].isdecimal() and S.count('-')==1 and len(S)==(A+B+1):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-') and len(S)==x+y+1:
    print('Yes')
else:
    print('No')

Fixed submission:
A,B=map(int,input().split())
S=input()
if S[:A].isdecimal() and S[A+1:].isdecimal() and S.count('-')==1 and len(S)==(A+B+1):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-':
    print('Yes')
else:
    print('No')

Fixed submission:
A,B=map(int,input().split())
S=input()
if S[:A].isdecimal() and S[A+1:].isdecimal() and S.count('-')==1 and len(S)==(A+B+1):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N=input()
print('Yes' if N[0]==N[1]==N[2] or N[1]==N[2]==M[3] else 'No')

Fixed submission:
N=input()
print('Yes' if N[0]==N[1]==N[2] or N[1]==N[2]==N[3] else 'No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
print(int(N**(1/2))**2)

Fixed submission:
C1=list(input())
C2=list(input())
if C1[0]==C2[2] and C1[1]==C2[1] and C1[2]==C2[0]:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
N=int(input())
for t in range(N//2):
    if t**2<=N:
        i=t**2
    else:
        break
print(i)

Fixed submission:
N=int(input())
print(int(N**(1/2))**2)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C=map(int,input().split())
ans="NO"
for i in range(1,10**10):
    if i%A==0:
        if i%B==C:
            ans='YES'
            break
    else:
        continue
print(ans)

Fixed submission:
A,B,C=map(int,input().split())
ans="NO"
for i in range(A):
    if (B*i+C)%A==0:
        ans='YES'
print(ans)
Buggy python submission (verdict: Runtime Error):
O=input()
E=input()
for i in range(len(O)*2):
    if i%2==0:
        print(O[i//2],end="")
    else:
        print(E[i//2],end="")

Fixed submission:
O=input()
E=input()
for i in range(len(O)*2-1 if len(O)!=len(E) else len(O)*2):
    if i%2==0:
        print(O[i//2],end="")
    else:
        print(E[i//2],end="")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
ans=1
for i in range(1,N+1):
    ans=ans*i
print(ans%((10**9)+7))

Fixed submission:
N=int(input())
ans=1
for i in range(1,N+1):
    ans=(ans*i)%((10**9)+7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
cnt=0
for i in range(K+1):
    for t in range(i,K+1):
        for s in range(t,K+1):
            if i+t+s==S:
                if i==t==s:
                    cnt+=1
                elif i==t or i==s or t==s:
                    cnt+=3
                else:
                    cnt+=6
            else:
                continue
print(cnt)

Fixed submission:
K,S=map(int,input().split())
cnt=0
for i in range(K+1):
    for t in range(K+1):
        s=S-i-t
        if 0<=s<=K:
            cnt+=1
        else:
            continue
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
cnt=0
for i in range(K+1):
    for t in range(K+1):
        for s in range(K+1):
            if i+t+s==S:
                cnt+=1
            else:
                continue
print(cnt)

Fixed submission:
K,S=map(int,input().split())
cnt=0
for i in range(K+1):
    for t in range(K+1):
        s=S-i-t
        if 0<=s<=K:
            cnt+=1
        else:
            continue
print(cnt)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n == 0:
	print(x)
	exit()
p = list(map(int, input().split()))
mind = abs(x - p[0])
pos = []
s = set(p)
p = []
for x1 in range(-100, 200):
	if x1 in s:
		continue
	else:
		p.append(x1)
for q in p:
	if abs(x - q) < mind:
		mind = abs(x - q)
		pos = [q]
	elif abs(x - q) == mind:
		pos.append(q)
pos.sort()
print(pos[0])

Fixed submission:
x, n = map(int, input().split())
if n == 0:
	print(x)
	exit()
p = list(map(int, input().split()))

s = set(p)
p = []
for x1 in range(-100, 200):
	if x1 in s:
		continue
	else:
		p.append(x1)
mind = abs(x - p[0])
pos = [p[0]]
for q in p:
	if abs(x - q) < mind:
		#print(q)
		mind = abs(x - q)
		pos = [q]
	elif abs(x - q) == mind:
		pos.append(q)
pos.sort()
print(pos[0])
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
n = int(input())
a = [int(x) for x in input().split()]

x = reduce(lambda x, y: x*y, a)

if x > 10**18:
    print("-1")
else:
    print(x)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]


ans = 1
a.sort()

for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print("0")
        exit(0)
    if ans > 10 ** 18:
        print("-1")
        exit(0)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
n = int(input())
a = [int(x) for x in input().split()]

x = reduce(lambda x, y: x*y, a)

if x > 10**18:
    print("-1")
else:
    print(x)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]


ans = 1
a.sort()

for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print("0")
        exit(0)
    if ans > 10 ** 18:
        print("-1")
        exit(0)

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = [int(x) for x in input().split()]

x = np.prod(a)

if x > 10**18:
    print("-1")
else:
    print(x)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]


ans = 1
a.sort()

for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print("0")
        exit(0)
    if ans > 10 ** 18:
        print("-1")
        exit(0)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 1
for i in range(n):
    ans = ans * a[i]

if ans > 10 ** 18:
    print("-1")
else:
    print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]


ans = 1
a.sort()

for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print("0")
        exit(0)
    if ans > 10 ** 18:
        print("-1")
        exit(0)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 1
for i in range(n):
    ans = ans * a[i]

if ans > 10 ** 18:
    print("-1")
else:
    print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]


ans = 1
a.sort()

for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print("0")
        exit(0)
    if ans > 10 ** 18:
        print("-1")
        exit(0)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = []
g = []
b = []

for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
    else:
        b.append(i)

sum = 0


for i in range(len(r)):
    for j in range(len(g)):
        for k in range(len(b)):
            index = [r[i],g[j],b[k]]
            index.sort()
            if index[1] - index[0] != index[2] - index[1]:
                sum += 1

print(sum)

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

r = 0
g = 0
b = 0

for i in range(n):
    if s[i] == "R":
        r += 1
        s[i] = 1
    elif s[i] == "G":
        g += 1
        s[i] = 2
    else:
        b += 1
        s[i] = 4

cnt = r*g*b

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i
        if k < n:
            if s[i] + s[j] + s[k] == 7:
                cnt -= 1

print(cnt)