Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
ans = 0
for n in range(a, b+1):
    ans = ans ^ n
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
a, b = map(int, input().split())
a-=1
ans = [a,1,a+1,0][a%4]^[b,1,b+1,0][b%4]
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
btc = 380000.0
y=0
for i in range(int(input())):
    x, u = input().split()
    x = int(x)
    if u = "BTC":
         y = y + x * btc
    else:
        y = x
print(y)


Fixed submission:
# -*- coding: utf-8 -*-
btc = 380000.0
y = 0.0
for i in range(int(input())):
    x, u = input().split()
    x = float(x)
    if u == "BTC":
         y += x * btc
    else:
        y += x

print(y)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
btc = 380000.0
y=0
for i in range(int(input())):
    x, u = input().split()
    if u = "BTC":
         y = y + x * btc
    else:
        y = x
print(y)


Fixed submission:
# -*- coding: utf-8 -*-
btc = 380000.0
y = 0.0
for i in range(int(input())):
    x, u = input().split()
    x = float(x)
    if u == "BTC":
         y += x * btc
    else:
        y += x

print(y)
Buggy python submission (verdict: Runtime Error):
a,b,c =input().split(",")
mylist = [int(a),int(b),int(c)]
mylist.sort()
print(sum(mylist[0:2]))

Fixed submission:
a,b,c =input().split(" ")
mylist = [int(a),int(b),int(c)]
mylist.sort()
print(sum(mylist[0:2]))
Buggy python submission (verdict: Runtime Error):
a,b = input().split(" ")
if int(b)%int(a)==0:
  print(int(a)+int(b)
else:
  print(int(b)-int(a))

Fixed submission:
a,b = input().split(" ")
print(int(a)+int(b)) if int(b)%int(a)==0 else print(int(b)-int(a))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
r = []
for i,c in zip(range(1, N + 1), range(N)):
    r.append(A.index(i)  + 1)
print(" ".join(map(str, r)))

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A = np.argsort(A)
for a in A:
    print(str(a + 1) + " " , end="")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
r = []
for i,c in zip(range(1, N + 1), range(N)):
    r.append(A.index(i)  + 1)
print(" ".join(map(str, r)))

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A = np.argsort(A)
for a in A:
    print(str(a + 1) + " " , end="")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
li = np.array([range(1, N)])
print("{:.0f}".format(np.sum(li)))

Fixed submission:
N = int(input())
print((1 + (N - 1)) * (N - 1) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
li = range(1, N)
print(sum(li))

Fixed submission:
N = int(input())
print((1 + (N - 1)) * (N - 1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import itertools

N = int(input())
V = list(map(int, input().split()))
l = list(itertools.permutations(V))
r = list()
for lo in l:
    d = deque(lo)
    while(len(d) != 1):
        d.append((d.pop() + d.pop()) / 2)
    r.append(d)
print(max(r).pop())


Fixed submission:
N = int(input())
V = list(map(int, input().split()))
V.sort()
a = V[0]
for i in range(1, N):
    a = (a + V[i])/2
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = list()
for i in range(N):
    A.append(int(input()))

for j in range(len(A)):
    Ai = copy.copy(A)
    del Ai[j]
    print(max(Ai))

Fixed submission:
import copy
N = int(input())
A = list()
for i in range(N):
    A.append(int(input()))
s = sorted(A)[::-1]
m1 = s[0]
m2 = s[1]

for j in A:
    if j == m1:
        print(m2)
    else:
        print(m1)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
x = sorted(X)
i = 0
diff = []
while i + 1 < len(x):
    diff.append(x[i] - x[i + 1])
    i += 1
d = sorted(diff)[:N - 1]
i = 0
sum = 0
for _ in x:
    if i + 1 < len(x):
        if x[i] - x[i + 1] in d:
            d.remove(x[i] - x[i + 1])
        else:
            sum = sum + abs(x[i] - x[i + 1])
    i += 1
print(sum)

Fixed submission:
#!/usr/bin/python
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
x = sorted(X)
i = 0
diff = []
while i + 1 < len(x):
    diff.append(x[i] - x[i + 1])
    i += 1
d = sorted(diff)[N - 1:]
print(abs(sum((d))))
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
p = 1
for i in range(1, N + 1):
    p *= i
print(p % (10** 9 + 7))

Fixed submission:

N = int(input())
p = 1
for i in range(1, N + 1):
    p = p * i % (10** 9 + 7)
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = list(map(int, input().split()))
count = 0
for x in range(0, K + 1):
    for y in range(0, K + 1):
        for z in range(0, K + 1):
            if x + y + z == S:
                count+=1
print(count)

Fixed submission:
K, S = list(map(int, input().split()))
count = 0
for x in range(0, K + 1):
    for y in range(0, K + 1):
        z = S - x - y
        if 0 <= z <= K:
            count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
n=int(input())
k =int(input()) 
count=0
for i in range(n):
  x=int(input())
  if x>=k:
    count=count+1
print(count)

Fixed submission:
n,k = [int(x) for x in input().split()]
cnt=0
list  = input().split()
for num in list:
    if int(num)>=k: cnt=cnt+1
print(cnt)

Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()] 
count=0
for i in range(n):
  x=int(input())
  if x>=k:
    count=count+1
print(count)

Fixed submission:
n,k = [int(x) for x in input().split()]
cnt=0
list  = input().split()
for num in list:
    if int(num)>=k: cnt=cnt+1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
#N人の参加者 全員がＫポイント持っている 
#Q回の正解
#Aは誰が正解したか
N,K,Q=map(int,input().split())
Ans=[]
for _ in range(Q):
    hoge=int(input())
    Ans.append(hoge-1)
# print(Ans) 
person=N*[K]
# print(person)

#問題
for i in range(Q):
    #人
    for j in range(N):
        if Ans[i]==j:
            pass
        else:
            person[j]-=1
    # print(person)
# print(person)

for i in range(N):
    if person[i]>0:
        print("Yes")
    else:
        print("No")

Fixed submission:
#N人の参加者 全員がＫポイント持っている 
#Q回の正解
#Aは誰が正解したか
N,K,Q=map(int,input().split())
Ans=[]
for _ in range(Q):
    hoge=int(input())
    Ans.append(hoge-1)
# print(Ans) 
person=N*[K-Q]
# print(person)

#問題
for i in range(Q):
    person[Ans[i]]+=1
    # #人
    # for j in range(N):
    #     if Ans[i]==j:
    #         pass
    #     else:
    #         person[j]-=1
    # print(person)
# print(person)

for i in range(N):
    if person[i]>0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N,M=map(int,input().split())
# N,M=3,3
A = list(map(int,input().split()))
#dymmy
# A.append(-1)
# A=[2,13,8]
# print(np.argmax(A))

# print(N,M,A)
# Val = sorted(A,reverse=True)
# print("割引前",Val)

#Ｍ枚の商品券を持っているため
for i in range(M):
    A[np.argmax(A)]= A[np.argmax(A)]//2
    # if Val[0] < Val[1]:
        # Val = sorted(Val,reverse=True)

# print("計算後",Val)
print(sum(A))

Fixed submission:
import numpy as np

N,M=map(int,input().split())
# N,M=4,4
A = list(map(int,input().split()))
#dymmy
A.append(-1)
# A=[1,9,3,5]
# print(np.argmax(A))

# print(N,M,A)
Val = sorted(A,reverse=True)
# print("割引前",Val)

#Ｍ枚の商品券を持っているため
hoge =Val[0]

if N==1:
    print(Val[0]//(2**M))
    exit(0)
if M==1:
    Val[0]//=2
    print(sum(Val)+1)
    exit(0)
# for i in range(M):
#     # A[np.argmax(A)]= A[np.argmax(A)]//2
#     Val[0]//=2
#     for i in range(1,M):
#         if Val[0]<Val[i]:
#             Val[0],Val[i] = Val[i],Val[0]
#             break
#         else:
#             pass
i=0
while i<M:
    # A[np.argmax(A)]= A[np.argmax(A)]//2
    i+=1
    Val[0]//=2
    if i>=M:
        break
    for j in range(1,M):
        if i<M and Val[0]<Val[j]:
            Val[j]//=2
            i+=1
        else:
            Val = sorted(Val,reverse=True)
            break
    

# print(Val)
print(sum(Val)+1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
# N,M=3,3
A = list(map(int,input().split()))
A.append(-1)
# A=[2,13,8]

# print(N,M,A)
Val = sorted(A,reverse=True)
# print("割引前",Val)

#Ｍ枚の商品券を持っているため
for i in range(M):
    Val[0]= Val[0]//2
    if Val[0] < Val[1]:
        Val = sorted(Val,reverse=True)

# print("計算後",Val)
print(sum(Val)+1)

Fixed submission:
import numpy as np

N,M=map(int,input().split())
# N,M=4,4
A = list(map(int,input().split()))
#dymmy
A.append(-1)
# A=[1,9,3,5]
# print(np.argmax(A))

# print(N,M,A)
Val = sorted(A,reverse=True)
# print("割引前",Val)

#Ｍ枚の商品券を持っているため
hoge =Val[0]

if N==1:
    print(Val[0]//(2**M))
    exit(0)
if M==1:
    Val[0]//=2
    print(sum(Val)+1)
    exit(0)
# for i in range(M):
#     # A[np.argmax(A)]= A[np.argmax(A)]//2
#     Val[0]//=2
#     for i in range(1,M):
#         if Val[0]<Val[i]:
#             Val[0],Val[i] = Val[i],Val[0]
#             break
#         else:
#             pass
i=0
while i<M:
    # A[np.argmax(A)]= A[np.argmax(A)]//2
    i+=1
    Val[0]//=2
    if i>=M:
        break
    for j in range(1,M):
        if i<M and Val[0]<Val[j]:
            Val[j]//=2
            i+=1
        else:
            Val = sorted(Val,reverse=True)
            break
    

# print(Val)
print(sum(Val)+1)
Buggy python submission (verdict: Runtime Error):

#入力受け取り
n = int(input())
tourList = []
for i in range(n):
    array = list(map(int, input().strip().split()))
    tourList.append(array)

#DebugPrint
currentTime = 0
currentX = 0
currentY = 0

for i in range(len(tourList)) :
    Time = tourList[i][0]
    X = tourList[i][1]
    Y = tourList[i][2]

    Time = Time - currentTime
    X = X - currentX
    Y = Y - currentY
    flag=False
    Z=0 #往復調整用

    if( (Time-abs(X+Y))%2==0 ):
        flag=True

    # while (X+Y+Z) <= Time :
    #     if X+Y+Z == Time:
    #         flag=True
    #         break
    #     else:
    #         Z+=2
    
    #継続判定
    if flag == False:
        print("No")
        exit()
    
    currentTime = Time
    currentX = X
    currentY = Y

print("Yes")

    #最初の点がまず実現可能か


Fixed submission:
#https://atcoder.jp/contests/abc086/tasks/abc086_a
#
a,b = map(int,input().split())
if ((a*b)% 2) == 0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):

#入力受け取り
n = int(input())
tourList = []
for i in range(n):
    array = list(map(int, input().strip().split()))
    tourList.append(array)

#DebugPrint

currentTime = 0
currentX = 0
currentY = 0

loop=0

for i in range(len(tourList)) :
    Time = tourList[i][0]
    X = tourList[i][1]
    Y = tourList[i][2]

    Time = Time - currentTime
    X = X - currentX
    Y = Y - currentY
    flag=False
    Z=0 #往復調整用    
    while (X+Y+Z) <= Time :
        if X+Y+Z == Time:
            flag=True
            break
        else:
            Z+=2
    
    #継続判定
    if flag == False:
        print("No")
        exit()
    
    currentTime = Time
    currentX = X
    currentY = Y

print("Yes")

    #最初の点がまず実現可能か


Fixed submission:

#入力受け取り
n = int(input())
tourList = []
for i in range(n):
    array = list(map(int, input().strip().split()))
    tourList.append(array)

#DebugPrint
currentTime = 0
currentX = 0
currentY = 0

for i in range(len(tourList)) :
    Time = tourList[i][0]
    X = tourList[i][1]
    Y = tourList[i][2]

    Time = Time - currentTime
    X = X - currentX
    Y = Y - currentY
    flag=False

    NUM = abs(X)+abs(Y)
    if( (Time-NUM)%2==0 and NUM <= Time):
        flag=True

    # while (X+Y+Z) <= Time :
    #     if X+Y+Z == Time:
    #         flag=True
    #         break
    #     else:
    #         Z+=2
    
    #継続判定
    if flag == False:
        print("No")
        exit()
    
    currentTime = Time
    currentX = X
    currentY = Y

print("Yes")

    #最初の点がまず実現可能か
Buggy python submission (verdict: Runtime Error):
n = int(input())
loop = 0
array = []
moti = []

while loop < n :
    array.append(int(input()))
    loop += 1

for i in array:
    if moti.count( array[i] )==0:
        moti.append(array[i])

print(len(moti))

Fixed submission:
n = int(input())
loop = 0
array = []
moti = []

while loop < n :
    array.append(int(input()))
    loop += 1

for i in range(len(array)):
    if moti.count( array[i] )==0:
        moti.append(array[i])

print(len(moti))
Buggy python submission (verdict: Runtime Error):
loop = int(input())
kokuban=[int(x) for x in input().split()]
print(kokuban)

flag=False
result =0

while(flag==False) :
    for index,obj in enumerate(kokuban) :
        print(int(obj))
        if int(obj)%2 == 0:
            kokuban[index]= int(obj)//2
        else:
            flag=True
    if flag==False :
        result +=1

print(result)


Fixed submission:
num = input()
print(num.count("1"))
Buggy python submission (verdict: Runtime Error):
import math
from sympy import sieve
N=int(input())

num = math.factorial(N)
primeNum=[]

for i in range(2,1000):
  flag=False  
  for j in range(2,i):
    if i%j==0:
      flag=True
      break
  if flag==False:
    primeNum.append(i)
    

# primeNum = [i for i in sieve.primerange(1,1000)]
# print(primeNum)
resulNum=[0]*len(primeNum)
result=1

j=0
flag=False
for i in primeNum:
  while num % i == 0 :
    num = num // i
    resulNum[j]+=1
    flag=True
  
  if flag==True:
    result*=(resulNum[j]+1)
    result %= 10**9+7
  j+=1
  flag=False

print(result)



Fixed submission:
import math
# from sympy import sieve
N=int(input())

num = math.factorial(N)
primeNum=[]

for i in range(2,1000):
  flag=False  
  for j in range(2,i):
    if i%j==0:
      flag=True
      break
  if flag==False:
    primeNum.append(i)
    

# primeNum = [i for i in sieve.primerange(1,1000)]
# print(primeNum)
resulNum=[0]*len(primeNum)
result=1

j=0
flag=False
for i in primeNum:
  while num % i == 0 :
    num = num // i
    resulNum[j]+=1
    flag=True
  
  if flag==True:
    result*=(resulNum[j]+1)
    result %= 10**9+7
  j+=1
  flag=False

print(result)

Buggy python submission (verdict: Runtime Error):
import math
from sympy import sieve
N=int(input())

num = math.factorial(N)
primeNum = [i for i in sieve.primerange(1,10000000)]
# print(primeNum)
resulNum=[0]*len(primeNum)
result=1

j=0
for i in primeNum:
  while num % i == 0 :
    num = num // i
    resulNum[j]+=1
  j+=1

for i in resulNum:
  if i>0:
    result*=(i+1)
    result %= 10**9+7

print(result)



Fixed submission:
import math
# from sympy import sieve
N=int(input())

num = math.factorial(N)
primeNum=[]

for i in range(2,1000):
  flag=False  
  for j in range(2,i):
    if i%j==0:
      flag=True
      break
  if flag==False:
    primeNum.append(i)
    

# primeNum = [i for i in sieve.primerange(1,1000)]
# print(primeNum)
resulNum=[0]*len(primeNum)
result=1

j=0
flag=False
for i in primeNum:
  while num % i == 0 :
    num = num // i
    resulNum[j]+=1
    flag=True
  
  if flag==True:
    result*=(resulNum[j]+1)
    result %= 10**9+7
  j+=1
  flag=False

print(result)
Buggy python submission (verdict: Runtime Error):
a,b,x= map(int,input().split())
result=0
num = a
for _ in range(a,b+1,x):
    if num <= b and num % x == 0 :
        # print("num",num)
        result+=1
    num+=x
# while a <= b:
#     if a % x == 0:
#         result+=1
#     a+=x
print(result)


Fixed submission:
A,B,C=input().split()
print("A"+B[0]+"C")
Buggy python submission (verdict: Time Limit Exceeded):
N,x= map(int,input().split())
array = list(map(int,input().split()))
result=0
for i in range(0,N-1):
    #i と i+1 が閾値以下じゃなかったら 
    while array[i] + array[i+1] > x:
        if array[i+1]!=0:
            array[i+1]-=1
        else:
            array[i]-=1
        result+=1
print(result)

Fixed submission:
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0
#TLE pattern
# for i in range(0,N-1):
#     #i と i+1 が閾値以下じゃなかったら 
#     while array[i] + array[i+1] > x:
#         if array[i+1]!=0:
#             array[i+1]-=1
#         else:
#             array[i]-=1
#         result+=1
# print(result)

for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        # if array[i+1] - (array[i] + array[i+1] - x) >= 0:
        #     array[i+1]=array[i+1] - (array[i] + array[i+1] - x)
        if (array[i]+array[i+1])-x <= array[i+1]:
            array[i+1]= array[i+1] - (array[i]+array[i+1]-x)
        else:
            # array[i]=array[i] - (array[i]+array[i+1]) - x - array[i+1]
            array[i]= array[i]-(array[i]-x)
            array[i+1]=0

# print(array2)
# print(array)
print(sum(array2)-sum(array))
Buggy python submission (verdict: Runtime Error):
w=input()

for i in range(len(w)):
    if w.count(w[i])%2==0:
        pass
    else:
        break
else:
    print("Yes")
    exit(1)
print("No")

Fixed submission:
w=input()

for i in range(len(w)):
    if w.count(w[i])%2==0:
        pass
    else:
        break
else:
    print("Yes")
    exit(0)
print("No")

Buggy python submission (verdict: Runtime Error):
w=input()

for i in range(len(w)):
    if w.count(w[i])%2==0:
        pass
    else:
        break
else:
    print("Yes")
    exit(1)
print("No")

Fixed submission:
w=input()

for i in range(len(w)):
    if w.count(w[i])%2==0:
        pass
    else:
        break
else:
    print("Yes")
    exit(0)
print("No")
Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())

li=[]
cnt=0
for i in range(l, r+1):
  li.append(i%2019)
  if i%2019==0:
    li.sort()
    print((li[0]*li[1])%2019)
    break
else:
  ans=2019
  for index, i in enumerate(li):
    for j in li[index+1:]:
      ans = min(ans, (i*j)%2019)
  print(ans)

Fixed submission:
l, r = map(int, input().split())

li=[]
cnt=0
for i in range(l, r+1):
  li.append(i%2019)
  if i%2019==0:
    print(0)
    break
else:
  ans=2019
  for index, i in enumerate(li):
    for j in li[index+1:]:
      ans = min(ans, (i*j)%2019)
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
card=[0 for _ in range(n)]
for i in range(m):
    l, r = map(lambda x: int(x)-1, input().split())
    for i in range(l,r+1):
        card[i]+=1
print(card.count(m))


Fixed submission:
n, m = map(int, input().split())
card=[0 for _ in range(n)]
l, r = map(int, input().split())
l-=1
for i in range(m-1):
    li, ri = map(int, input().split())
    li-=1
    if li>r or ri<l:
        l=r
        break
    elif li>=l and ri<=r:
        l=li; r=ri
    elif li<=l and ri>=r:
        pass
    elif li<=r and ri>=r:
        l=li
    elif ri>=l and li<=l:
        r=ri
    else:
        pass
print(r-l)
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int, input().split()))
prv=a[0]
for ai in a[1:]:
  prv=math.gcd(ai,prv)
print(prv)




Fixed submission:
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a


n=int(input())
a=list(map(int, input().split()))
prv=a[0]
for ai in a[1:]:
  prv=gcd(ai,prv)
print(prv)
Buggy python submission (verdict: Runtime Error):
import math
n,X=map(int, input().split())
x=list(map(int, input().split()))
ans=abs(x[0]-X)
for xi in x[1:]:
    ans=math.gcd(ans, abs(xi-X))
print(ans)

Fixed submission:
from fractions import gcd
n,X=map(int, input().split())
x=list(map(int, input().split()))
ans=abs(x[0]-X)
for xi in x[1:]:
    ans=gcd(ans, abs(xi-X))
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k= map(int, input().split())
cnt=[0]*n
for i in range(1,n+1):
    cnt[i%k]+=1
ans=0
for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k==0:
        ans+=cnt[a]*cnt[b]*cnt[c]
print(ans)

Fixed submission:
n, k= map(int, input().split())
cnt=[0]*k
for i in range(1,n+1):
    cnt[i%k]+=1
ans=0
for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k==0:
        ans+=cnt[a]*cnt[b]*cnt[c]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int, input().split())
x=list(map(int, input().split()))
zi=0
for xi in x:
    if xi>=0:
        break
    zi+=1

xm=[0]
if x[zi]==0:
    xp=[]
else:
    xp=[0]

xm.extend(reversed(x[:zi]))
xp.extend(x[zi:])

ans=float('inf')
for i in range(k):
    if i<len(xm) and k-i<len(xp):
        ans=min(xm[i]*2*(-1) + xp[k-i], ans)
    if i<len(xp) and k-i<len(xm):
        ans=min(xp[i]*2 + xm[k-i]*(-1), ans)
if len(x)==1 and x[0]==0:
    ans=0
print(ans)

Fixed submission:
n,k=map(int, input().split())
x=list(map(int, input().split()))
zi=0
for xi in x:
    if xi>=0:
        break
    zi+=1

xm=[0]
if zi<len(x) and x[zi]==0:
    xp=[]
else:
    xp=[0]

xm.extend(reversed(x[:zi]))
xp.extend(x[zi:])

ans=float('inf')
for i in range(k):
    if i<len(xm) and k-i<len(xp):
        ans=min(xm[i]*2*(-1) + xp[k-i], ans)
    if i<len(xp) and k-i<len(xm):
        ans=min(xp[i]*2 + xm[k-i]*(-1), ans)
if len(x)==1 and x[0]==0:
    ans=0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,C=map(int, input().split())
D=[list(map(int, input().split())) for _ in range(C)]
c=[list(map(int, input().split())) for _ in range(N)]

cost=[[0 for _ in range(C) ] for _ in range(3)]
for i in range(N):
    for j in range(N):
        for k in range(C):
            cost[(i+j)%3][k]+= D[c[i][j]-1][k]
#print(cost)

ans=1000*500*500
for i in range(C):
    for j in filter(lambda x:x!=i,range(C)):
        for k in filter(lambda x:x!=i and x!=j, range(C)):
            #print(cost[0][i]+cost[1][j]+cost[2][k])
            ans=min(cost[0][i]+cost[1][j]+cost[2][k], ans)
print(ans)


Fixed submission:
N,C=map(int, input().split())
D=[list(map(int, input().split())) for _ in range(C)]
clr=[[0 for _ in range(C) ] for _ in range(3)]
cost=[[0 for _ in range(C) ] for _ in range(3)]

for i in range(N):
    ci=list(map(int, input().split()))
    for j, cij in enumerate(ci):
        clr[(i+j)%3][cij-1]+=1 

for i in range(3):
    for j in range(C):
        for k in range(C):
            cost[i][k]+=(D[j][k])*clr[i][j]

ans=1000*500*500
for i in range(C):
    for j in filter(lambda x:x!=i,range(C)):
        for k in filter(lambda x:x!=i and x!=j, range(C)):
            #print(cost[0][i]+cost[1][j]+cost[2][k])
            ans=min(cost[0][i]+cost[1][j]+cost[2][k], ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
a= list(map(int, input().split()))

cnt=0
for i, ai in enumerate(a):
    tmp=0
    for aj in a[i:]:
        if tmp^aj==tmp+aj:
            tmp^=aj            
            cnt+=1
        else:
            break
print(cnt)




Fixed submission:
n= int(input())
a= list(map(int, input().split()))

cnt=0
tail=0
sec=0
for head in range(n):
    while(tail<n and sec^a[tail]==sec+a[tail]):
        sec^=a[tail]
        tail+=1
    cnt+=(tail-head)
    sec^=a[head]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

s=input()
K=int(input())

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for i in range(26):
    for j in d[chr(ord('a')+i)]:
        for k in range(len(s[j:])):
            sub.add(s[j:j+k+1])
#            print(s[j:j+k+1])
#    print(len(sub), k)    
    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break


Fixed submission:
from collections import defaultdict

s=input()
K=int(input())

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for i in range(26):
    for j in d[chr(ord('a')+i)]:
        for k in range(min(K,len(s[j:]))):
            sub.add(s[j:j+k+1])
#            print(s[j:j+k+1])
#    print(len(sub), k)    
    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break