Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
tBeA = 0
tBeNA = 0
tNBeA = 0
for i in range(N):
    flag = False
    if a[i][0] == "B":
        if a[i][-1] == "A":
            tBeA += 1
        else:
            tBeNA += 1
    else:
        if a[i][-1] == "A":
            tNBeA += 1

    for j in range(len(a[i])):
        # print(a[i][j])
        if a[i][j] == "B" and flag:
            cnt += 1
        flag = False

        if a[i][j] == "A":
            flag = True

print(
    cnt + min(tBeNA, tNBeA) if tBeA == 0 else cnt + min(tBeNA, tNBeA) + tBeA if tNBeA + tBeNA > 0 else cnt + min(tBeNA,
                                                                                                                 tNBeA) + tBeA - 1)


Fixed submission:
N = int(input())
a = [str(input()) for i in range(N)]
cnt = 0
tBeA = 0
tBeNA = 0
tNBeA = 0
for i in range(N):
    flag = False
    if a[i][0] == "B":
        if a[i][-1] == "A":
            tBeA += 1
        else:
            tBeNA += 1
    else:
        if a[i][-1] == "A":
            tNBeA += 1

    for j in range(len(a[i])):
        # print(a[i][j])
        if a[i][j] == "B" and flag:
            cnt += 1
        flag = False

        if a[i][j] == "A":
            flag = True

print(
    cnt + min(tBeNA, tNBeA) if tBeA == 0 else cnt + min(tBeNA, tNBeA) + tBeA if tNBeA + tBeNA > 0 else cnt + min(tBeNA,
                                                                                                                 tNBeA) + tBeA - 1)
Buggy python submission (verdict: Runtime Error):
S = input()

cnt = 0
a = []
for i in S:
    if i == 'A' or i == 'T' or i == 'G' or i == 'C':
        cnt += 1
    else:
        a.append(cnt)
        cnt = 0
print(max(a))

Fixed submission:
S = input()

cnt = 0
a = []
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C':
        cnt += 1
        if i == len(S) - 1:
            a.append(cnt)
    else:
        lenflag = False
        a.append(cnt)
        cnt = 0
print(max(a))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
a = []
an = [0] * (N + 1)
for i in range(Q):
    a.append(list(map(int, input().split())))

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        an[i] = 1
# print(an)
for i in range(Q):
    print(an[a[i][0] - 1:a[i][1] - 1].count(1))

Fixed submission:
N, Q = map(int, input().split())
S = input()
a = []
an = [0] * (N + 1)
for i in range(Q):
    a.append(list(map(int, input().split())))

for i in range(len(S) - 1):
    an[i + 1] = an[i]
    if S[i:i + 2] == "AC":
        an[i + 1] += 1
for i in range(Q):
    print(an[a[i][1] - 1] - an[a[i][0] - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import copy
S=input()
sx=list(str(S))
s=list(map(int,sx))
#print(s)
cnt=0
while(1):
    t=copy.deepcopy(s) 
    for i in range(len(s)-1):
        if s[i]+s[i+1]==1:
            s.pop(i+1)
            s.pop(i)
            cnt+=2
            break
    if s==t:
        break
print(cnt)

Fixed submission:
s=input()
a=s.count('0')
b=s.count('1')
print(min(a,b)*2)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
d = []

h.sort()
# print(h)
tmp = 10 ** 10

for i in range(n - 1):
    d.append(h[i + 1] - h[i])
# print(d)
for i in range(n):
    if i + k - 1 >= len(h):
        break
    sub = sum(d[i:i + k - 1])
    # print(sub)
    tmp = min(tmp, sub)

print(tmp)


Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
d = []

h.sort()
# print(h)
tmp = 10 ** 10

for i in range(n):
    if i + k - 1 >= len(h):
        break
    tmp = min(tmp, h[i + k - 1] - h[i])

print(tmp)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
d = []

h.sort()
# print(h)
tmp = 10 ** 10

for i in range(n - 1):
    d.append(h[i + 1] - h[i])
# print(d)
for i in range(n):
    if i + k - 1 >= len(h):
        break
    sub = sum(d[i:i + k - 1])
    # print(sub)
    tmp = min(tmp, sub)

print(tmp)


Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
d = []

h.sort()
# print(h)
tmp = 10 ** 10

for i in range(n):
    if i + k - 1 >= len(h):
        break
    tmp = min(tmp, h[i + k - 1] - h[i])

print(tmp)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
C=A+B
if N == 1:
    print('Hello World')
if N == 2:
    print(C)

Fixed submission:
N=int(input())
if N == 1:
    print("Hello World")
if N == 2:
    A=int(input())
    B=int(input())
if N == 2:
    print(A+B)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
C=A+B
if N==1:
    print("Hello World")
if N==2:
    print(C)

Fixed submission:
N=int(input())
if N == 1:
    print("Hello World")
if N == 2:
    A=int(input())
    B=int(input())
if N == 2:
    print(A+B)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
if N==1:
    print("Hello World")
else:
    print(A+B)

Fixed submission:
N=int(input())
if N == 1:
    print("Hello World")
if N == 2:
    A=int(input())
    B=int(input())
if N == 2:
    print(A+B)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=int(input())
B=int(input())
if N==1:
    print("Hello World")
else:
    print(A+B)

Fixed submission:
N=int(input())
if N == 1:
    print("Hello World")
if N == 2:
    A=int(input())
    B=int(input())
if N == 2:
    print(A+B)
Buggy python submission (verdict: Runtime Error):
D,N=map(int,input().split())
S=0
if D==0:
    if N=100:
        S=1
    print(N+S)
elif D==1:
    print(100*N)
else:
    print(10000*N)

Fixed submission:
D,N=map(int,input().split())
S=0
if N==100:
    S=1
print(100**D*(N+S))
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=list(input())
ans=0
for i in range(N-1):
    a=set(S[:i+1])
    b=set(S[i+1:])
    ans=max(ans,len(a&b))
print(ans)

Fixed submission:
A,B=map(int,input().split())
C=[]
C.append(A+B)
C.append(A-B)
C.append(A*B)
print(max(C))
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=list(input())
for i in range(N-1):
    a=set(S[:i+1])
    b=set(S[i+1:])
    ans=max(ans,len(a&b))
print(ans)

Fixed submission:
N=int(input())
S=list(input())
ans=0
for i in range(N-1):
    a=set(S[:i+1])
    b=set(S[i+1:])
    ans=max(ans,len(a&b))
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
s = [input() for i in range(N)]
M=int(input())
t = [input() for i in range(M)]
tmp=[0]
for i in range(N):
    point=0
    point+=s.count(s[i])
    point-=t.count(s[i])
    tmp.append(point)
print(max(tmp))

Fixed submission:
A,B,C=map(int,input().split())
print('Yes'if A+B>=C else "No")
Buggy python submission (verdict: Runtime Error):
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Fixed submission:
a=['']*3
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Buggy python submission (verdict: Runtime Error):
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Fixed submission:
a=['']*3
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Buggy python submission (verdict: Runtime Error):
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)

Fixed submission:
a=['']*3
for i in range(3):
    a[i]=input()
b=[]
b.append(a[0][0])
b.append(a[1][1])
b.append(a[2][2])
ans=''.join(b)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
N=int(input())
x=[int(i) for i in input().split()]
cnt=0
while(1):
    for i in range(N):
        if x[i]%2 != 0:
            print(cnt)
            sys.exit()
    tmp=[i//2 for i in x]
    x=tmp
    cnt+=1

Fixed submission:
print(input().count("1"))
Buggy python submission (verdict: Runtime Error):
N=(input())
print("Yes"if int(N)%(int(N[0])+int(N[1]))==0 else"No")

Fixed submission:
N,A,B=map(int,input().split())
print(B if N*A>B else N*A )
Buggy python submission (verdict: Runtime Error):
N=(input())
print("Yes"if int(N)%(int(N[0])+int(N[1]))==0 else"No")

Fixed submission:
N=(input())
sum=0
for i in range(len(N)):
    sum+=int(N[i])

print("Yes"if int(N)%sum==0 else"No")

Buggy python submission (verdict: Runtime Error):
N=(input())
print("Yes"if int(N)%(int(N[0])+int(N[1]))==0 else"No")

Fixed submission:
N=(input())
sum=0
for i in range(len(N)):
    sum+=int(N[i])

print("Yes"if int(N)%sum==0 else"No")
Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
a = [int(input()) for _ in range(n)]
b = collections.Counter(a)

cnt = 0
for v in b.values():
    if v % 2 == 1:
        cnt += 1

print(cnt)


Fixed submission:
a=input()
print('Yes'if "9"in a else 'No')
Buggy python submission (verdict: Runtime Error):
s=list(input())
while(1):
    if len(s)==1:
        print(s)
        break
    s.pop(-1)
    if s[:t]==s[t:]:
        print(len(s))
        break
    t=int(len(s)/2)

Fixed submission:
s=list(input())
while(1):
    t=int(len(s)/2)
    if len(s)==1:
        print(s)
        break
    s.pop(-1)
    if s[:t]==s[t:]:
        print(len(s))
        break
Buggy python submission (verdict: Runtime Error):
import math

n, m = map(int, input().split())
w = 10 ** 9 + 7
if n + 1 == m or m + 1 == n:
    print(math.factorial(min(n, m)) ** 2 * max(n, m) % w)
elif n == m:
    print(2 * math.factorial(n) ** 2 % w)
else:
    print(0)


Fixed submission:
x,a,b=map(int,input().split())
if b<=a:
    print("delicious")
elif b-a<=x:
    print("safe")
else:
    print("dangerous")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
tmp=list()
for i in range(N+1):
    cnt+=1
    if a[b-1]==2:
        break
    if a[b-1] in tmp:
        print(-1)
        sys.exit(0)
    else:
        tmp.append(a[b-1])
        b=a[b-1]
print(cnt)

Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
ok=False
for i in range(N+1):
    cnt+=1
    if a[b-1]==2:
        ok=True
        break
    b=a[b-1]
print(cnt if ok else -1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
tmp=list()
while(1):
    cnt+=1
    if a[b-1]==2:
        break
    if a[b-1] in tmp:
        print(-1)
        sys.exit(0)
    else:
        tmp.append(a[b-1])
        b=a[b-1]
print(cnt)

Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
ok=False
for i in range(N+1):
    cnt+=1
    if a[b-1]==2:
        ok=True
        break
    b=a[b-1]
print(cnt if ok else -1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(100000)


def k(x):
    if x < 2:
        return 1
    return x * k(x - 1)


n, m = map(int, input().split())
w = 10 ** 9 + 7
if n + 1 == m or m + 1 == n:
    print(k(n) * k(m) % w)
elif n == m:
    print(2 * k(n) ** 2 % w)
else:
    print(0)


Fixed submission:
import math

n, m = map(int, input().split())
w = 10 ** 9 + 7
if n + 1 == m or m + 1 == n:
    print(math.factorial(min(n, m)) ** 2 * max(n, m) % w)
elif n == m:
    print(2 * math.factorial(n) ** 2 % w)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
a = int(math.sqrt(n))

for i in range(a, n + 1):
    if n % i == 0:
        print(len(str(i)))
        exit()



Fixed submission:
import math

n = int(input())
a = int(math.sqrt(n))

for i in range(a + 1, 0, -1):
    if n % i == 0:
        # print(n // i, i)
        print(max(len(str(i)), len(str(n // i))))
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
a = int(math.sqrt(n))

for i in range(a, n + 1):
    if n % i == 0:
        print(len(str(i)))
        exit()



Fixed submission:
import math

n = int(input())
a = int(math.sqrt(n))

for i in range(a + 1, 0, -1):
    if n % i == 0:
        # print(n // i, i)
        print(max(len(str(i)), len(str(n // i))))
        exit()
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a = []
for i in range(n):
    a.append(input())
b = []
for i in range(m):
    b.append(input())

ok=False
cf=[]
for i in range(n-m+1):
    for j in range(n-m+1):
        for l in range(m):
            cf.append(a[i+l][j:j+m])
            #print(cf)
    if cf==b:
        ok=True
    cf=[]
print("Yes"if ok else "No")

Fixed submission:
a,b=map(int,input().split())
J=0
if (a==1 and b!=1):
    J=1
elif (b==1 and a!=1):
    J=2
elif a<b:
    J=2
elif a>b:
    J=1
print("Alice" if J==1 else "Bob" if J==2 else "Draw")
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for l in range(k+1):
    for m in range(k+1):
        for n in range(k+1):
            if l+m+n==s and l<=k and m<=k and n<=k:
                cnt+=1
                #print(l,m,n)
print(cnt)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for l in range(k+1):
    for m in range(k+1):
        #2つが定まるともう一つの値は一意に定まる
        if 0<=s-l-m and s-l-m<=k:
            cnt+=1
            #print(l,m,n)
print(cnt)
Buggy python submission (verdict: Runtime Error):
a=list(input())
b=list(input())
c=list(input())
read=a[0]
a.pop(0)

while(1):
    if read=='a':
        if len(a)==0:
            break
        read=a[0]
        f='A'
        a.pop(0)
        
    elif read=='b':
        if len(b)==0:
            break
        read=b[0]
        f='B'
        b.pop(0)
        
    elif read=='c':
        if len(c)==0:
            break
        read=c[0]
        f='C'
        c.pop(0)
        
print(f)

Fixed submission:
a=list(input())
b=list(input())
c=list(input())
read=a[0]

while(1):
    if read=='a':
        try:
            read=a.pop(0)
        except:
            f='A'
            break
    if read=='b':
        try:
            read=b.pop(0)
        except:
            f='B'
            break
    if read=='c':
        try:
            read=c.pop(0)
        except:
            f='C'
            break
print(f)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
if n%2==0:
  s_1=s[0:n/2]
  s_2=s[n/2:n]
  if s_1==s_2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Fixed submission:
n=int(input())
s=input()
if n%2==0:
    k=int(n/2)
    s_1=s[0:k]
    s_2=s[k:n]
    if s_1==s_2:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
if n%2==0:
  s_1=s[0:n/2]
  s_2=s[n/2:n]
  if s_1==s_2:
    print("Yes")
else:
  print("No")


Fixed submission:
n=int(input())
s=input()
if n%2==0:
    k=int(n/2)
    s_1=s[0:k]
    s_2=s[k:n]
    if s_1==s_2:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def  makabe((float)num, (float)ko):
  ky=(num+ko)/2
  return ky



n=int(input())
g=list(map(float,input().split()))
g.sort()
ty=(g[0]+g[1])/2
for h in range(2,n):
  ty= makabe(ty,g[h])
  
print(ty)

Fixed submission:
def  makabe(nam, co):
  ky=(nam+co)/2.0
  return ky



n=int(input())
g=list(map(int,input().split()))
g.sort()
ty=(g[0]+g[1])/2.0
for h in range(2,n):
  ty= makabe(ty,g[h])
  
print(ty)
Buggy python submission (verdict: Runtime Error):
n, d=int(input().split())
cnt=1
while True:
  if (2*d+1)*cnt>=n:
    print(cnt)
    break
  
  cnt+=1
  
  

Fixed submission:
n, d=input().split()
ni=int(n)
di=int(d)
cnt=1
while True:
  if (2*di+1)*cnt>=ni:
    print(cnt)
    break
  
  cnt+=1
Buggy python submission (verdict: Runtime Error):
n=int(input())
w=list(map(int, input().split()))
a[n]={}
for t in range(n):
  s1=sum(w[0:t+1])
  s2=sum(w[t+1:n])
  a[t]=abs(s1-s2)

print(min(a))

Fixed submission:
n=int(input())
w=list(map(int, input().split()))
a=[]
for t in range(n):
    s1=sum(w[0:t+1])
    s2=sum(w[t+1:n])
    a.append(abs(s1-s2))
 
print(min(a))
Buggy python submission (verdict: Runtime Error):
x, y, z=list(map(int, input().split(/)))
if y>=5:
  print("TBD")
else:
  print("Heisei")

Fixed submission:
x, y, z=list(map(int, input().split("/")))
if y>=5:
  print("TBD")
else:
  print("Heisei")
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(len(s)):
  if s[i]=="1":
    s[i]="9"
  elif s[i]=="9":
    s[i]="1"

print(s)

Fixed submission:
s=input()
t=s.replace("9","2")
u=t.replace("1","3")
v=u.replace("2","1")
w=v.replace("3","9")

print(w)
Buggy python submission (verdict: Runtime Error):
x=list(map(int,input().split()))
a=x[0]
b=x[1]
if a<=b:
  print(a)
else:
  priint(a-1)

Fixed submission:
x=list(map(int,input().split()))
a=x[0]
b=x[1]
if a<=b:
  print(a)
else:
  print(a-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
req = [0] * n
req[-1] = a[-1]
for i in range(2, n+1):
    req[-i] = req[-(i-1)] + a[-i]
l = [0] * (n + 1)
l[0] = 1
for i in range(1, n+1):
    M = (l[i-1] - a[i-1]) * 2
    l[i] = min(M, req[i-1])
if l[-1] < a[-1]:
    print(-1)
else:
    print(sum(l))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
if n == 0:
    if a[0] == 1:
        print(1)
    else:
        print(-1)
else:
    req = [0] * n
    req[-1] = a[-1]
    for i in range(2, n+1):
        req[-i] = req[-(i-1)] + a[-i]
    l = [0] * (n + 1)
    l[0] = 1
    for i in range(1, n+1):
        M = (l[i-1] - a[i-1]) * 2
        l[i] = min(M, req[i-1])
    if l[-1] < a[-1]:
        print(-1)
    else:
        print(sum(l))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, m, x = map(int, input().split())
L = list(list(map(int, input().split())) for _ in range(n))
ans = float('inf')
p = []
for i in range(1, n + 1):
    for j in itertools.permutations(L, i):
        p.append(list(j))

for k in p:
    s = [0] * (m + 1)
    for l in range(len(k)):
        for t in range(m + 1):
            s[t] += k[l][t]
            
    sum_price = 0
    for i in range(1, m + 1):
        if s[i] < x:
            sum_price = float('inf')
            break
        sum_price = s[0]
    if sum_price < ans:
        ans = sum_price

if ans == float('inf'):
    print('-1')
else:
    print(ans)


Fixed submission:
def solve(L):
    cost = 0
    s = [0] * m
    for k in range(n):
        if L[k] == 1:
            cost += A[k][0]
            for l in range(1, m+1):
                s[l-1] += A[k][l]
    if all(s[i] >= x for i in range(m)):
        return cost
    else:
        return float('inf')

n, m, x = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
ans = float('inf')
for i in range(2 ** n):
    L = [0] * n
    for j in range(n):
        if ((i >> j) & 1) != 0:
            L[j] = 1
    ans = min(ans, solve(L))
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, m, x = map(int, input().split())
L = list(list(map(int, input().split())) for _ in range(n))
ans = float('inf')
p = []
for i in range(1, n + 1):
    for j in itertools.permutations(L, i):
        p.append(list(j))

for k in p:
    s = [0] * (m + 1)
    for l in range(len(k)):
        for t in range(m + 1):
            s[t] += k[l][t]
            
    sum_price = 0
    for i in range(1, m + 1):
        if s[i] < x:
            sum_price = float('inf')
            break
        sum_price = s[0]
    if sum_price < ans:
        ans = sum_price

if ans == float('inf'):
    print('-1')
else:
    print(ans)


Fixed submission:
def solve(L):
    cost = 0
    s = [0] * m
    for k in range(n):
        if L[k] == 1:
            cost += A[k][0]
            for l in range(1, m+1):
                s[l-1] += A[k][l]
    if all(s[i] >= x for i in range(m)):
        return cost
    else:
        return float('inf')

n, m, x = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
ans = float('inf')
for i in range(2 ** n):
    L = [0] * n
    for j in range(n):
        if ((i >> j) & 1) != 0:
            L[j] = 1
    ans = min(ans, solve(L))
if ans == float('inf'):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

k, n = map(int, input().split())
a = list(map(int, input().split()))

ans = float('inf')
roots = list(itertools.permutations(a))

for i in range(n):
    sum_d = 0
    root = list(roots[i])
    for j in range(1, n):
        sum_d += min(abs(root[j] - root[j - 1]), abs(k - root[j] + root[j - 1]))
    if sum_d < ans:
        ans = sum_d
print(ans)


Fixed submission:
k, n = map(int, input().split())
a = list(map(int, input().split()))
d_list = [] * n
for i in range(1, n):
    d_list.append(a[i] - a[i - 1])
d_list.append(k - a[n - 1] + a[0])
ans = sum(d_list) - max(d_list)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int,input().split())
d = {}
for i in range(1, n+1):
    for j in range(i+1, n+1):
        l = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        d[l] = 1 if l not in d else d[l] + 1
for i in range(1, n):
    if i in d:
        print(d[i])
    else:
        print(0)


Fixed submission:
n, x, y = map(int,input().split())
li = [0] * (n - 1)
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        k = min(j - i, abs(i - x) + abs(j - y) + 1)
        li[k - 1] += 1
for i in li:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
cnt = 0
for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        cnt += 1
    else:
        if query[1] == '1':
            if cnt % 2:
                s = s + query[2]
            else:
                s = query[2] + s
        else:
            if cnt % 2:
                s = query[2] + s
            else:
                s = s + query[2]
if cnt % 2:
    s = s[::-1]
print(s)


Fixed submission:
s = str(input())
q = int(input())
cnt = 0
L = []
R = []
for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        cnt += 1
    else:
        if query[1] == '1':
            if cnt % 2:
                R.append(query[2])
            else:
                L.append(query[2])
        else:
            if cnt % 2:
                L.append(query[2])
            else:
                R.append(query[2])
s = (''.join(L[::-1]) + s + ''.join(R))
if cnt % 2:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        s = s[::-1]
    else:
        if query[1] == '1':
            s = query[2] + s
        else:
            s = s + query[2]
print(s)


Fixed submission:
s = str(input())
q = int(input())
cnt = 0
L = []
R = []
for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        cnt += 1
    else:
        if query[1] == '1':
            if cnt % 2:
                R.append(query[2])
            else:
                L.append(query[2])
        else:
            if cnt % 2:
                L.append(query[2])
            else:
                R.append(query[2])
s = (''.join(L[::-1]) + s + ''.join(R))
if cnt % 2:
    s = s[::-1]
print(s)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
N = [None] * n
for s, c in L:
    if N[s - 1] is None:
        N[s - 1] = c
    elif N[s - 1] == c:
        continue
    else:
        print(-1)
        exit()
for i in range(n):
    if N[i] is None:
        N[i] = 0
if N[0] == 0:
    print(-1)
else:
    print(*N, sep='')


Fixed submission:
n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(m)]
N = [None] * n
for s, c in L:
    if N[s - 1] is None:
        N[s - 1] = c
    elif N[s - 1] == c:
        continue
    else:
        print(-1)
        exit()

if n == 1:
    if N[0] is None:
        N[0] = 0
    print(*N)
    exit()
elif N[0] == 0:
    print(-1)
    exit()

for i in range(n):
    if i == 0 and N[0] is None:
        N[0] = 1
    elif N[i] is None:
        N[i] = 0
print(*N, sep='')