Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

a.sort()
b.sort()
c.sort()

count = 0
for i in a:
  for j in range(bisect.bisect(b, i), len(b)):
    count += len(b) - bisect.bisect(c, b[j])
print(count)


Fixed submission:
import bisect

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

a.sort()
b.sort()
c.sort()

count = 0
for i in b:
  count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i))
print(count)

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

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

a.sort()
b.sort()
c.sort()

count = 0
for i in a:
  for j in range(bisect.bisect(b, i), len(b)):
    for k in range(bisect.bisect(c, b[j]), len(c)):
      count += 1
print(count)


Fixed submission:
import bisect

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

a.sort()
b.sort()
c.sort()

count = 0
for i in b:
  count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i))
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def func(i, j):
  il = len(str(i))
  jl = len(str(j))
  if il > jl:
    return il
  return jl

n = int(input())
min = len(str(10**10))
for i in range(1, n+1):
  if n % i == 0:
    if i > n/i:
      break
    fr = func(i, int(n/i))
    if min > fr:
      min = fr
print(min)


Fixed submission:
def func(i, j):
  il = len(str(i))
  jl = len(str(j))
  if il > jl:
    return il
  return jl

n = int(input())
min = len(str(n))
for i in range(1, n+1):
  if i**2 > n:
    break
  if n % i == 0:
    fr = func(i, int(n/i))
    if min > fr:
      min = fr
print(min)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, m = list(map(int, input().split()))
v = []
for i in range(m):
  tpl = tuple(map(int, input().split()))
  v.append(tpl)
  v.append((tpl[1], tpl[0]))

perms = list(itertools.permutations(v, n-1))
c = 0
for i in perms:
  if i[0][0] != 1:
    continue
  visited = []
  for j in range(len(i)-1):
    if i[j][1] != i[j+1][0]:
      break
    visited.append(i[j][0])
    if i[j+1][1] in visited:
      break
  else:
    c += 1
print(c)


Fixed submission:
import itertools

n, m = list(map(int, input().split()))
v = []
for i in range(m):
  tpl = tuple(map(int, input().split()))
  v.append(tpl)
  v.append((tpl[1], tpl[0]))

perms = list(itertools.permutations(range(1, n+1)))
c = 0
for i in perms:
  if i[0] != 1:
    continue
  for j in range(len(i)-1):
    if (i[j], i[j+1]) not in v:
      break
  else:
    c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def sigma(func, frm, to):
    result = 0
    for i in range(frm, to+1):
        result += func(i)
    #print(result)

def f(x):
    return x

K = int(input())

#print(sigma(f,1,K))

#print(gcd(sigma(f,1,K),sigma(f,1,K),sigma(f,1,K)))

#sigma(sigma(sigma(gcd(), 1, K)))

#print(gcd(sigma(gcd,1,K),sigma(f(K),1,K),sigma(f(K),1,K)))

x = 0

#print()

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x += gcd(a, b, c)
            """print("a:",end="")
            print(a)
            print("b:",end="")
            print(b)
            print("c:",end="")
            print(c)"""

print(x)

#print(gcd(27,18,9))

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def sigma(func, frm, to):
    result = 0
    for i in range(frm, to+1):
        result += func(i)
    #print(result)

def f(x):
    return x

K = int(input())

#print(sigma(f,1,K))

#print(gcd(sigma(f,1,K),sigma(f,1,K),sigma(f,1,K)))

#sigma(sigma(sigma(gcd(), 1, K)))

#print(gcd(sigma(gcd,1,K),sigma(f(K),1,K),sigma(f(K),1,K)))

x = 0

#print()

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x += gcd(a, b, c)
            """print("a:",end="")
            print(a)
            print("b:",end="")
            print(b)
            print("c:",end="")
            print(c)"""

print(x)

#print(gcd(27,18,9))
Buggy python submission (verdict: Runtime Error):
a =  float(raw_input())
c = float(raw_input())
print (2*c-a)

Fixed submission:
a =  float(raw_input())
c = float(raw_input())
print int(2*c-a)

Buggy python submission (verdict: Runtime Error):
import sys

a =  float(raw_input())
c = float(raw_input())
print 2*c-a


Fixed submission:
a =  float(raw_input())
c = float(raw_input())
print int(2*c-a)

Buggy python submission (verdict: Runtime Error):
a =  float(raw_input())
c = float(raw_input())
print 2*c-a


Fixed submission:
a =  float(raw_input())
c = float(raw_input())
print int(2*c-a)
Buggy python submission (verdict: Runtime Error):
a, v = list(map(long, input().split()))
b, w = list(map(long, input().split()))
t = long(input())

if a == b:
    print('NO')
    exit()
elif b > a:
    if v <= w:
        print('NO')
        exit()

    if b - a <= t * (v-w):
        print('YES')
    else:
        print('NO')
else:
    if w <= v:
        print('NO')
        exit()

    if a - b <= t * (w-v):
        print('YES')
    else:
        print('NO')


Fixed submission:
a, v = list(map(float, input().split()))
b, w = list(map(float, input().split()))
t = float(input())

if v <= w:
    print('NO')
    exit()

if abs(v-w)*t >= abs(a-b):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import math

x = int(input())

b = -100

while True:
    if x+b**5 > 0:
        if math.pow((x+b**5), 0.2).is_integer():
            print(int(math.pow((x+b**5), 0.2)), b)
            exit()
        
    b += 1

Fixed submission:
x = int(input())

for i in range(-1000,1000):
    for j in range(-1000,1000):
        if i ** 5 - j ** 5 == x:
            print(i,j)
            quit()

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

x = int(input())

b = -10000

while True:
    if x+b**5 > 0:
        if math.pow((x+b**5), 0.2).is_integer():
            print(int(math.pow((x+b**5), 0.2)), b)
            exit()
        
    b += 1

Fixed submission:
x = int(input())

for i in range(-1000,1000):
    for j in range(-1000,1000):
        if i ** 5 - j ** 5 == x:
            print(i,j)
            quit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i, value in enumerate(a):
    print(a.count(i+1))
print('0')

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0]*len(a)

for i, value in enumerate(a):
    b[value-1] += 1

for j in b:
    print(j) 

print('0')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i, value in enumerate(a):
    print(a.count(i+1))
print('0')


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0]*len(a)

for i, value in enumerate(a):
    b[value-1] += 1

for j in b:
    print(j) 

print('0')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i, value in enumerate(a):
    cnt = 0
    for j in range(i, len(a)):
        if a[j] == i+1:
            cnt += 1
    print(cnt)
print('0')


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0]*len(a)

for i, value in enumerate(a):
    b[value-1] += 1

for j in b:
    print(j) 

print('0')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i, num in enumerate(a):
#    print(i, num)
    cnt = 0
    for j in range(i, len(a)):
        if a[j] == i+1:
            cnt += 1
    print(cnt)
print('0')


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0]*len(a)

for i, value in enumerate(a):
    b[value-1] += 1

for j in b:
    print(j) 

print('0')
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))

n_prev = n

while True:
    n = abs(n - k)
    if n > n_prev:
        print(n_prev)
        exit()
    else:
        n_prev = n


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

print(min(n%k, abs(k- n%k)))
Buggy python submission (verdict: Runtime Error):
from collections import deque

S = str(input())
Q = int(input())

tmp = deque(S)
houkou = 1 #1:foward 2:reverse

for i in range(Q):
    inp = input().split()
    if inp[0] == '1':
        if houkou == 1:
            houkou = 2
        else:
            houkou = 1
    else:
        if houkou == 1 and inp[1] == '1':
            tmp.appendleft(inp[2])
        elif houkou == 1 and inp[1] == '2':
            tmp.append(inp[2])
        elif houkou == 2 and inp[1] == '1':
            tmp.append(inp[2])
        else:
            tmp.appendleft(inp[2])
    
    print(houkou, tmp)

output = ''.join(list(tmp))
if houkou == 2:
    output = output[::-1]

print(output)


Fixed submission:
from collections import deque

S = str(input())
Q = int(input())

tmp = deque(S)
houkou = 1 #1:foward 2:reverse

for i in range(Q):
    inp = input().split()
    if inp[0] == '1':
        if houkou == 1:
            houkou = 2
        else:
            houkou = 1
    else:
        if houkou == 1 and inp[1] == '1':
            tmp.appendleft(inp[2])
        elif houkou == 1 and inp[1] == '2':
            tmp.append(inp[2])
        elif houkou == 2 and inp[1] == '1':
            tmp.append(inp[2])
        else:
            tmp.appendleft(inp[2])
    
#    print(houkou, tmp)

output = ''.join(list(tmp))
if houkou == 2:
    output = output[::-1]

print(output)
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))

s = [0]*m
c = [0]*m

for k in range(m):
    s[k], c[k] = list(map(int, input().split()))

for l in range(m):
    if n == 1:
        if s[l] != 1:
            print(-1)
            exit()
    elif n == 2:
        if s[l] == 3 or (s[l] == 1 and c[l] == 0):
            print(-1)
            exit()
    elif n == 3:
        if s[l] == 1 and c[l] == 0:
            print(-1)
            exit()

if n == 1:
    kaishi = 0
    owari = 10
elif n == 2:
    kaishi = 10
    owari = 100
elif n == 3:
    kaishi = 100
    owari = 1000

for num in range (kaishi, owari):
    seigo = 1
    for i in range(m):
        if s[i] == 3:
            if num%10 == c[i]:
                continue
            else:
                seigo = 0
        if s[i] == 2:
            if (num//100) == 0 and (num%100)//10 == 0:
                seigo = 0 
            elif (num%100)//10 == c[i]:
                continue
            else:
                seigo = 0
        if s[i] == 1:
            elif (num%10) == c[i]:
                continue
            else:
                seigo = 0

    if seigo == 1:
        print(num)
        exit()
        
print(-1)





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

s = [0]*(m+1)
c = [0]*(m+1)

for k in range(m):
    s[k], c[k] = list(map(int, input().split()))

for l in range(m):
    if n == 1:
        if s[l] != 1:
            print(-1)
            exit()
    elif n == 2:
        if s[l] == 3 or (s[l] == 1 and c[l] == 0):
            print(-1)
            exit()
    elif n == 3:
        if s[l] == 1 and c[l] == 0:
            print(-1)
            exit()

if n == 1:
    for num in range(0, 10):
        seigo = 1
        for i in range(m):
            if num != c[i]:
                seigo = 0
        if seigo == 1:
            print(num)
            exit()
    print(-1)
    exit()
elif n == 2:
    for num in range(10, 100):
        seigo = 1
        for i in range(m):
            if s[i] == 1:
                if num//10 != c[i]:
                    seigo = 0
            if s[i] == 2:
                if num%10 != c[i]:
                    seigo = 0
        if seigo == 1:
            print(num)
            exit()
    print(-1)
    exit()
else:
    for num in range(100, 1000):
        seigo = 1
        for i in range(m):
            if s[i] == 1:
                if num//100 != c[i]:
                    seigo = 0
            elif s[i] == 2:
                if (num-100*(num//100))//10 != c[i]:
                    seigo = 0
            elif s[i] == 3:
                if num%10 != c[i]:
                    seigo = 0
        if seigo == 1:
            print(num)
            exit()
    print(-1)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = []
c = []
l = [list(map(int, input().split())) for i in range(q)]
for i in range(len(l)):
    b.append(l[i][0])
    c.append(l[i][1])
for i in range(q):
    if b[i] in a:
        for j in range(len(a)):
            if a[j] == b[i]:
                a[j] = c[i]
        print(sum(a))
    else:
        print(sum(a)) 
        

Fixed submission:
import collections
 
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for i in range(Q)]
 
sum_ = sum(A)

# 要素の出現回数をカウント
counter = dict(collections.Counter(A))
# print(counter)
 
for i in range(Q):
    b, c = BC[i]
    if not b in counter:
        counter[b] = 0
    if not c in counter:
        counter[c] = 0
    cnt = counter[b]
    sum_ += (c-b)*cnt
    print(sum_)
    counter[b] -= cnt
    counter[c] += cnt
Buggy python submission (verdict: Runtime Error):
k = []
for i in range(1,101):
    k.append(int(i))
x,n = map(int,input().split())
try:
    p = list(map(int,input().split()))
except EOFError:
    pass

if n == 0:
    print(x)
else:
    for i in range(0,len(p)):
        if p[i] != x:
            k.remove(p[i])
    l = k.index(x)
    if abs(k[l]-k[l-1]) < abs(k[l]-k[l+1]) or x < k[l+1]:
        print(k[l-1])
    else:
        print(k[l+1])


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

P.sort()
ans = 10000000
for i in range(-101, 102):
  if not i in P:
    ans = min(ans, abs(i-X))

if not X-ans in P:
  print(X-ans)
else:
  print(X+ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(input().split())
ans = int(a[0])
tmp = 0
for  i in range(1,n):
    if '0' in a:
        ans = 0
        break
    ans = ans * int(a[i])

check = 10**18
if ans <= check:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
check = 10**18

a = sorted(a)
ans = a[0]
tmp = 0


for i in range(n-1,0,-1):
    ans = ans * a[i]
    if ans > check:
        tmp  = 1
        break
    elif a[0] == 0:
        tmp = 2
        break

if tmp == 1:
    print('-1')
elif tmp == 0:
    print(ans)
elif tmp == 2:
    print('0')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(input().split())
check = 10**18
ans = int(a[0])
tmp = 0
for  i in range(1,n):
    if '0' in a:
        ans = 0
        break
    ans = ans * int(a[i])
    if ans > check:
        tmp = 1
        break

if tmp == 0:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
check = 10**18

a = sorted(a)
ans = a[0]
tmp = 0


for i in range(n-1,0,-1):
    ans = ans * a[i]
    if ans > check:
        tmp  = 1
        break
    elif a[0] == 0:
        tmp = 2
        break

if tmp == 1:
    print('-1')
elif tmp == 0:
    print(ans)
elif tmp == 2:
    print('0')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
check = 10**18
ans = a[0]

for  i in range(1,n):
    ans = ans * a[i]
if ans <= check:
    print(ans)
else:
    print('-1')


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
check = 10**18

a = sorted(a)
ans = a[0]
tmp = 0


for i in range(n-1,0,-1):
    ans = ans * a[i]
    if ans > check:
        tmp  = 1
        break
    elif a[0] == 0:
        tmp = 2
        break

if tmp == 1:
    print('-1')
elif tmp == 0:
    print(ans)
elif tmp == 2:
    print('0')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
check = 10**18
ans = a[0]

for  i in range(1,n):
    ans = ans * a[i]
if ans <= check:
    print(ans)
else:
    print('-1')

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
check = 10**18

a = sorted(a)
ans = a[0]
tmp = 0


for i in range(n-1,0,-1):
    ans = ans * a[i]
    if ans > check:
        tmp  = 1
        break
    elif a[0] == 0:
        tmp = 2
        break

if tmp == 1:
    print('-1')
elif tmp == 0:
    print(ans)
elif tmp == 2:
    print('0')
Buggy python submission (verdict: Runtime Error):
n, l = map(int, input().split())

apples = [l+i for i in range(n)] #りんごの味
ans = sum(apples) - apples[apples.index(min(apples, key=abs))] #りんごの味の合計ーりんごの味の絶対値の最小
print(ans)


Fixed submission:
s = input()
ans = 0
for i in range(3):
    if s[i] == s[i + 1]:
        ans = 1
        break

print('Good' if ans == 0 else 'Bad')
Buggy python submission (verdict: Runtime Error):
N = input()
L = map(int,raw_input().split())
if max(L) >= (sum(L)-max(L)):
  print "No"
else:
  print "Yes"

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
if 2 * max(l) < sum(l):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input(),split()))

if max(l) < sum(l)-max(l):
    print('Yes')
else:
    print('No')

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
if 2 * max(l) < sum(l):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input(),split())

if max(l) < sum(l)-max(l):
    print('Yes')
else:
    print('No')

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
if 2 * max(l) < sum(l):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for _ in range(Q)]

ans = sum(A)

for i in range(Q):
    A = [BC[i][1] if x==BC[i][0] else x for x in A]
    print(sum(A))

Fixed submission:
import collections

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for _ in range(Q)]

ans = sum(A)
d = collections.defaultdict(int)

for key in A:
    d[key] += 1

for i in range(Q):
    b,c = BC[i][0],BC[i][1]
    ans += d[b]*(c-b)
    d[c] += d[b]
    d[b] = 0
    print(ans)

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

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for _ in range(Q)]

ans = sum(A)

for i in range(Q):
    counter = collections.Counter(A)
    if BC[i][0] in counter:
        ans += counter[BC[i][0]]*(BC[i][1]-BC[i][0])
        print(ans)
        A = [BC[i][1] if x==BC[i][0] else x for x in A]
    else:
        print(ans)

Fixed submission:
import collections

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for _ in range(Q)]

ans = sum(A)
d = collections.defaultdict(int)

for key in A:
    d[key] += 1

for i in range(Q):
    b,c = BC[i][0],BC[i][1]
    ans += d[b]*(c-b)
    d[c] += d[b]
    d[b] = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

for i in range(1,N+1):
    print(Counter(A)[i])


Fixed submission:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))

d = defaultdict(int)

for i in A:
    d[i] += 1

for i in range(1,N+1):
    print(d[i])
Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C = map(int,input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
l = p[:X] + q[:Y]
l.sort()
for i in range(C):
    if r[i] > l[i]:
        l[i] = r[i]
print(sum(l))

Fixed submission:
X,Y,A,B,C = map(int,input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
l = p[:X] + q[:Y]
l.sort()
for i in range(min(C,X+Y)):
    if r[i] > l[i]:
        l[i] = r[i]
print(sum(l))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = input()
N = int(input())
Q = [list(input().split()) for _ in range(N)]

d = deque(S)

for q in Q:
    if q[0] == "1":
        d.reverse()
    elif q[0] == "2":
        if q[1] == "1":
            d.appendleft(q[2])
        else:
            d.append(q[2])
            
print("".join(d))

Fixed submission:
from collections import deque

S = input()
N = int(input())
Q = [list(input().split()) for _ in range(N)]

d = deque(S)

cnt = 0 
for q in Q:
    if q[0] == "1":
        cnt+=1
        #d.reverse()
    elif q[0] == "2":
        if (cnt%2==0 and q[1] == "1") or (cnt%2!=0 and q[1] == "2"):
            d.appendleft(q[2])
        else:
            d.append(q[2])
            
if cnt%2 != 0:
    d.reverse()
print("".join(d))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = [input() for _ in range(N)]

num = 0
for i in l:
   num = max(num,l.count(i)) 
ans = []
for i in l:
    if num == l.count(i):
        ans.append(i)

l= list(set(ans))
l.sort()
for i in l:
    print(i)


Fixed submission:
N = int(input())
l = [input() for _ in range(N)]

ans = []
l.sort()
num = 1
max_num = 0

for i in range(1,N):
    if l[i] == l[i-1]:
        num += 1
    else:
        if num > max_num:
            max_num = num
            ans = [l[i-1]]
        elif num == max_num:
            ans.append(l[i-1])
        num = 1
if num > max_num:
        max_num = num
        ans = [l[i]]
elif num == max_num:
    ans.append(l[i])

for i in ans:
    print(i)