Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
e=[[]for _ in range(n)]
for x,y in[map(int,input().split())for _ in[0]*(n-1)]:e[x-1].append(y-1);e[y-1].append(x-1)
def b(r,v):return sum((r!=i)and(a[v]>a[i])and(not(b(v,i)))for i in e[v])
print(*[i+1for i in range(n)if b(n,i)])

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
a=list(map(int,input().split()))
edge=[[]for _ in range(n)]
for x,y in[list(map(int,input().split()))for _ in range(n-1)]:
  edge[x-1].append(y-1)
  edge[y-1].append(x-1)
def bfs(r,v):
  for i in edge[v]:
    if(r!=i)and(a[v]>a[i])and(not(bfs(v,i))):return True
  return False
print(*[i+1 for i in range(n)if bfs(-1,i)])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
a=list(map(int,input().split()))+[10**10]
edge=[[]for _ in range(n)]
for x,y in[list(map(int,input().split()))for _ in range(n-1)]:
  edge[x-1].append(y-1)
  edge[y-1].append(x-1)
def bfs(r,v):
  return (a[r]<=a[v])|sum(not(bfs(v,i))for i in edge[v] if i!=r)
ans=[]
for i in range(n):
  if bfs(n,i):ans.append(i+1)
print(*ans)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
a=list(map(int,input().split()))
edge=[[]for _ in range(n)]
for x,y in[list(map(int,input().split()))for _ in range(n-1)]:
  edge[x-1].append(y-1)
  edge[y-1].append(x-1)
def bfs(r,v):
  for i in edge[v]:
    if(r!=i)and(a[v]>a[i])and(not(bfs(v,i))):return True
  return False
print(*[i+1 for i in range(n)if bfs(-1,i)])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
a=list(map(int,input().split()))+[10**10]
edge=[[]for _ in range(n)]
for x,y in[list(map(int,input().split()))for _ in range(n-1)]:
  edge[x-1].append(y-1)
  edge[y-1].append(x-1)
def bfs(r,v):
  return (a[r]<=a[v])|sum(not(bfs(v,i))for i in edge[v] if i!=r)
ans=[]
for i in range(n):
  if bfs(n,i):ans.append(i+1)
print(*ans)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
a=list(map(int,input().split()))
edge=[[]for _ in range(n)]
for x,y in[list(map(int,input().split()))for _ in range(n-1)]:
  edge[x-1].append(y-1)
  edge[y-1].append(x-1)
def bfs(r,v):
  for i in edge[v]:
    if(r!=i)and(a[v]>a[i])and(not(bfs(v,i))):return True
  return False
print(*[i+1 for i in range(n)if bfs(-1,i)])
Buggy python submission (verdict: Runtime Error):
n=int(input())
edge=[[]for _ in range(n)]
for i in range(n-1):edge[int(input())-1].append(i+1)
def dfs(v):
  d=[-1]+sorted([dfs(i)for i in edge[v]])
  l=len(d)
  return max(l-i+j for i,j in enumerate(d))
print(dfs(0))

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n=int(input())
a=[int(input())for _ in range(n-1)]
def dfs(v):
  d=[dfs(i)for i in t[v]]
  d.sort()
  l=len(d)
  ans=0
  for i,j in enumerate(d):
    ans=max(ans,l-i+j)
  return ans
t=[[]for _ in range(n+1)]
for i in range(n-1):
  t[a[i]-1].append(i+1)
print(dfs(0))
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
if x=0:print(abs(y)+(y<0))
elif y=0:print(abs(x)+(x>0))
elif 0<x<y or x<y<0:print(abs(y-x))
elif 0<y<x or y<x<0:print(2+abs(x-y))
else:print(abs(abs(x)-abs(y))+1)

Fixed submission:
x,y=map(int,input().split())
if x==0:print(abs(y)+(y<0))
elif y==0:print(abs(x)+(x>0))
elif 0<x<y or x<y<0:print(abs(y-x))
elif 0<y<x or y<x<0:print(2+abs(x-y))
else:print(abs(abs(x)-abs(y))+1)
Buggy python submission (verdict: Runtime Error):
I,O,R,J,L,S,Z=map(int,input().split())
ans=O
m=min(I,J,L):
I-=m
J-=m
L-=m
ans+=m*3
ans+=I//2*2
ans+=J//2*2
ans+=L//2*2
print(ans)

Fixed submission:
I,O,R,J,L,S,Z=map(int,input().split())
a=(I//2+J//2+L//2)*2
b=0
if I*J*L!=0:b=(2*((I-1)//2+(J-1)//2+(L-1)//2)+3)
print(max(a,b)+O)
Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split());a=list(map(int,input().split()));ans=0
for i in range(n-1):
  while sum(a[i:i+1+1])>x:
    if a[i+1]==0:a[i]-=1
    else:a[i+1]-=1
    ans+=1
print(ans)

Fixed submission:
n,x=map(int,input().split());a=list(map(int,input().split()));ans=0
for i in range(n-1):
  m=a[i]+a[i+1]
  if a[i]>=x:a[i+1]=0;a[i]=x
  else:a[i+1]=min(x-a[i],a[i+1])
  ans+=m-a[i]-a[i+1]
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input());print(int(round(int(input()))*2)+1if n!=1else"1")

Fixed submission:
n,c=int(input()),0
for j in range(n+1):
  if c<n:c+=j+1
  else:break	
for i in range(j,0,-1):
  if i<=n:print(i);n-=i
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split());c=0
for i in range(h):
  a=input().split(".")
  c+=len(a)
print("Possible"if h+w-1==ans else"Impossible")

Fixed submission:
h,w=map(int,input().split());c=0
for i in range(h):
  a=input()
  b=[]
  for j in range(w):b.append(a[j])
  c+=b.count("#")
print("Possible"if h+w-1==c else"Impossible")
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input()).split())
if sum(a)/2==max(a):print("YES")
else:print("NO")

Fixed submission:
a=list(map(int,input().split()))
if sum(a)/2==max(a):print("Yes")
else:print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input());a,b=1,1
for i in range(n):
  c,d=map(int,input().split())
  cc,dd=c,d
  while a>c or b>d:c+=cc;d+=dd
  a,b=c,d
print(a+b)

Fixed submission:
n=int(input());a,b=map(int,input().split())
for i in range(n-1):
  c,d=map(int,input().split())
  m=max((a-1)//c,(b-1)//d)+1
  a,b=c*m,d*m
print(a+b)
Buggy python submission (verdict: Runtime Error):
x=input();a=0
for i in range(len(x)):
  if x[l-i-1]=="T":a+=1
  else:a=max(0,a-1)
print(a*2)

Fixed submission:
x=input();a,l=0,len(x)
for i in range(l):
  if x[l-i-1]=="T":a+=1
  else:a=max(0,a-1)
print(a*2)
Buggy python submission (verdict: Runtime Error):
n=int(input());a=list(map(int,input().split()));ans=0
for i in range(n):
  if i+1=a[a[i]-1]:ans+=1
print(ans)

Fixed submission:
n=int(input());a=list(map(int,input().split()));ans=0
for i in range(n):
  if i+1==a[a[i]-1]:ans+=1
print(ans//2)
Buggy python submission (verdict: Runtime Error):
t="abcdefghijklmnopqrstuvwxyz"
s=input()
k=int(input())
a=[t.index(i)for i in s]
ans=""
for i in a:
  if i==0:
    ans+="a"
    continue
  j=i
  if k>=26-i:
    k-=26-i
    j=0
  ans+=t[j]
j+=k
j%=26
ans=ans[:-1]+t[j]
print(ans)

Fixed submission:
s=input()
k=int(input())
t="abcdefghijklmnopqrstuvwxyz"
a=[t.index(i)for i in s]
i=0
while k:
  if i==len(s)-1:a[i]+=k;a[i]%=26;k=0
  if a[i]==0 or 26-a[i]>k:i+=1
  else:a[i]+=1;a[i]%=26;k-=1
print("".join([t[i]for i in a]))
Buggy python submission (verdict: Runtime Error):
a=list(int,input().split());a.sort();s=a[0]*a[1]
if (a[2]*s)%2==0:print(0)
else:print(s)

Fixed submission:
a=list(map(int,input().split()));a.sort();s=a[0]*a[1]
if (a[2]*s)%2==0:print(0)
else:print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a.copy()
ans=sum(a)
for k in range(n):
  d=0
  for i in range(n):
    b[i]=min(b[i],a[i-k])
    d+=b[i]
  ans=min(d+x*k,ans)
print(ans)

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a.copy()
ans=sum(a)
for k in range(n):
  for i in range(n):b[i]=min(b[i],a[i-k])
  ans=min(sum(b)+x*k,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
ans=0
for i in a:
  b.append(i)
  ans+=i
for k in range(1,n):
  d=0
  for i in range(n):
    b[i]=min(b[i],a[i-k])
    d+=b[i]
  ans=min(d+x*k,ans)
print(ans)

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a.copy()
ans=sum(a)
for k in range(n):
  for i in range(n):b[i]=min(b[i],a[i-k])
  ans=min(sum(b)+x*k,ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
s,ans=input(),0;a=[s[i]for i in range(len(s))];a.sort()
for i in a:
  if a.count(i)%2!=0:ans=1
if ans=0:print("Yes")
else:print("No")

Fixed submission:
s,ans=input(),0;a=[s[i]for i in range(len(s))];a.sort()
for i in a:
  if a.count(i)%2!=0:ans=1
if ans==0:print("Yes")
else:print("No")
Buggy python submission (verdict: Runtime Error):
a,b=int(input()),list(map(int,input().split()));b.sort();c=(b[0]+b[-1])//2;if (b[0]+b[-1])%2==1 and c+1 in b:c+=1
d=[(b[i]-c)**2 for i in range(a)];print(sum(d))

Fixed submission:
a,b=int(input()),list(map(int,input().split()))
ans=-1
for i in range(-100,100+1):
  c=0
  for j in range(a):c+=(b[j]-i)**2
  if ans==-1:ans=c
  elif ans>c:ans=c
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b=int(input()),list(map(int,input().split()));b.sort();c=(b[0]+b[-1])//2;if (b[0]+b[-1])%2==1 and c+1 in b:c+=1;d=[(b[i]-c)**2 for i in range(a)];print(sum(d))

Fixed submission:
a,b=int(input()),list(map(int,input().split()))
ans=-1
for i in range(-100,100+1):
  c=0
  for j in range(a):c+=(b[j]-i)**2
  if ans==-1:ans=c
  elif ans>c:ans=c
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
l=len(s)
for i in range(1,l)
  if s[i-1]==s[i]:print(i,i+1);exit()
for i in range(2,l)
  if s[i-2]==s[i]:print(i-1,i+1);exit()
print(-1,-1)

Fixed submission:
s=input()
l=len(s)
for i in range(1,l):
  if s[i-1]==s[i]:print(i,i+1);exit()
for i in range(2,l):
  if s[i-2]==s[i]:print(i-1,i+1);exit()
print(-1,-1)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a*b=0:print("Zero")
elif 0<a:print("Positive")
else:
  if -a%2==0:print("Positive")
  else:print("Negative")

Fixed submission:
a,b=map(int,input().split())
if a*b<=0:print("Zero")
elif 0<a:print("Positive")
else:
  if (b-a)%2==1:print("Positive")
  else:print("Negative")
Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
a=list(map(int, input().split()))
for i in range(n-1):
  if a[i]+a[i+1]>=L:
    print("Possible")
    for j in range(i):print(j+1)
    for j in range(n-1,i,-1):print(i)
    exit()
print("Impossible")

Fixed submission:
n,l=map(int,input().split())
a=list(map(int, input().split()))
for i in range(n-1):
  if a[i]+a[i+1]>=l:
    print("Possible")
    for j in range(i):print(j+1)
    for j in range(n-1,i,-1):print(j)
    exit()
print("Impossible")
Buggy python submission (verdict: Runtime Error):
h,w,a,b=map(int,input().split())m=10**9+7;f=[1]
for i in range(h+w):f+=[f[-1]*(i+1)%m]
def comb(a,b,m):return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m
x=0
for i in range(b,w):x+=comb(h-a+i-1,i,m)*comb(a+w-i-2,a-1,m)%m
print(x%m)

Fixed submission:
h,w,a,b=map(int,input().split());m=10**9+7;f=[1]
for i in range(h+w):f+=[f[-1]*(i+1)%m]
def comb(a,b,m):return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m
x=0
for i in range(b,w):x+=comb(h-a+i-1,i,m)*comb(a+w-i-2,a-1,m)%m
print(x%m)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
g=[[],]*n
for i in range(m):
	u,v=map(int,input().split())
	u-=1
	v-=1
	g[u].append(v)
	g[v].append(u)

vis=[False]*n
def dfs(u):
	if vis[u]:
		return
	vis[u]=True
	for v in g[u]:
		dfs(v)

cnt=0
for i in range(n):
	if not vis[i]:
		cnt+=1
		dfs(i)
print(cnt-1)

Fixed submission:
n,m=map(int,input().split())
g=[[] for i in range(n)]
for i in range(m):
	u,v=map(int,input().split())
	u-=1
	v-=1
	g[u].append(v)
	g[v].append(u)

vis=[False]*n
stk=[]

cnt=0
tt=0
for i in range(n):
	if not vis[i]:
		cnt+=1
		stk.append(i)
	while len(stk)!=0:
		u=stk[-1]
		stk.pop()
		if vis[u]:
			continue
		vis[u]=True
		for v in g[u]:
			tt+=1
			if not vis[v]:
				stk.append(v)
print(cnt-1)
Buggy python submission (verdict: Runtime Error):
M=10**9+7
n=int(input())
c=list(int(input()) for i in range(n))
dp=[0]*n
rec=[0]*n
dp[0]=1
rec[c[0]]=1
for i in range(1,n):
	if c[i]==c[i-1]:
		dp[i]=dp[i-1]
		continue
	dp[i]=(dp[i-1]+rec[c[i]])%M
	rec[c[i]]=dp[i]
print(dp[-1])

Fixed submission:
n=int(input())
c=list(int(input()) for i in range(n))
dp=[0]*n
rec=[0]*(2*10**5+1)
dp[0]=1
rec[c[0]]=1
for i in range(1,n):
	if c[i]==c[i-1]:
		dp[i]=dp[i-1]
		continue
	dp[i]=(dp[i-1]+rec[c[i]])%(10**9+7)
	rec[c[i]]=dp[i]
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
x1,y1,x2,y2=map(int,input().split())
fx=1
fy=1
if x1>x2:
	x1,x2=x2,x1
	fx=-1
if y1>y2:
	y1,y2=y2,y1
	fy=-1

n=int(input())
p=[]
for i in range(n):
	x,y=map(int,input().split())
	if x1<=x<=x2 and y1<=y<=y2:
		p.append((fx*x,fy*y))
p=[y for x,y in sorted(p)]

from bisect import bisect_left as bl

b=[]

for y in p:
	pos=bl(b,y)
	if len(b)<=pos:
		b.append(y)
	else:
		b[pos]=y
	
from math import pi

l=len(b)

if l==min(x2-x1,y2-y1)+1:
	print(100*(x2-x1+y2-y1)+(5*pi-20)*(l-1)+(10*pi-20))
else:
	print(100*(x2-x1+y2-y1)+(5*pi-20)*l);


Fixed submission:
q,h,s,d=map(int,input().split())

h=min(h,q+q)
s=min(s,h+h)
d=min(d,s+s)

n=int(input())

print(n//2*d+n%2*s)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import functools
import numpy as np
import operator



# a, b = map(float, input().split())

# b = int(b * 100)
# a = int(a)

# print(int(a * b / 100))

n = int(input())
v = [int(i) for i in input().split()]
ans = functools.reduce(operator.mul, v)
 
if ans > 1e18:
    print(-1)
else:
    print(ans)

Fixed submission:
import math
import itertools
import functools
import numpy as np



# a, b = map(float, input().split())

# b = int(b * 100)
# a = int(a)

# print(int(a * b / 100))

n = int(input())
v = [int(i) for i in input().split()]
v.sort()

if v[0] == 0:
  print(0)
  exit(0)
ans = 1
for l in v:
    ans *= l
    if ans > 1e18:
      print(-1)
      exit(0)
 
if ans > 1e18:
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = [int(i) for i in input().split()]
ans = 1
for l in v:
    ans *= l;

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

Fixed submission:
import math
import itertools
import functools
import numpy as np



# a, b = map(float, input().split())

# b = int(b * 100)
# a = int(a)

# print(int(a * b / 100))

n = int(input())
v = [int(i) for i in input().split()]
v.sort()

if v[0] == 0:
  print(0)
  exit(0)
ans = 1
for l in v:
    ans *= l
    if ans > 1e18:
      print(-1)
      exit(0)
 
if ans > 1e18:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n < 3:
  print(0)
  exit()
l = map(int,input().split())
l.sort()
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i] + l[j] > l[k] and l[i] != l[j] and l[j] != l[k]:
        c += 1
print(c)

Fixed submission:
n = int(input())
if n < 3:
  print(0)
  exit()
l = map(int,input().split())
l = sorted(l)
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i] + l[j] > l[k] and l[i] != l[j] and l[j] != l[k]:
        c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
na = []
c = 0
for booka in a:
  c += booka
  na.append(c)
nb = []
d = 0
for bookb in b:
  d += bookb
  nb.append(d)
maxa = 0
for i in range(n):
  for j in range(maxa-i,m):
    if na[i] + nb[j] <= k:
      maxa = max(maxa,i+j+2)
print(maxa)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
na,nb = [0],[0]
for i in range(n):
  na.append(na[i]+a[i])
for j in range(m):
  nb.append(nb[j]+b[j])
ans = 0
l = m
for i in range(n+1):
  if na[i] > k:
    break
  while nb[l] > k - na[i]:
    l -= 1
  ans = max(ans,i+l)
print(ans)
Buggy python submission (verdict: Runtime Error):
import decimal
a,b = map(decimal,input().split())
print(int(a*b))


Fixed submission:
a,b = input().split()
na = int(a)
nb100 = (int(b[0])*100+int(b[2:]))
ans = na*nb100
print(ans//100)

Buggy python submission (verdict: Runtime Error):
a,b = map(decimal,input().split())
print(int(a*b))

Fixed submission:
a,b = input().split()
na = int(a)
nb100 = (int(b[0])*100+int(b[2:]))
ans = na*nb100
print(ans//100)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
abl = [list(map(int,input().split())) for nesya in range(n)]
al = []
bl = []
for ab in abl:
  bisect.insort_left(al,ab[0])
  bisect.insort_left(bl,ab[1])
if n%2 == 1:
  z = (n+1)//2-1
  print(bl[z]-al[z]+1)
else:
  x = n//2
  ax2 = al[x-1]+al[x]
  bx2 = bl[x-1]+bl[x]
  print(bx2-ax2+1)

Fixed submission:
from statistics import median

n = int(input())
abl = [list(map(int,input().split())) for nesya in range(n)]
al = []
bl = []
for ab in abl:
  al.append(ab[0])
  bl.append(ab[1])
if n%2 == 1:
  print(median(bl)-median(al)+1)
else:
  print(int(median(bl)*2-median(al)*2+1))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
abl = [list(map(int,input().split())) for nesya in range(n)]
al = []
bl = []
for ab in abl:
  al.append(ab[0])
  bl.append(ab[1])
  al.sort()
  bl.sort()
if n%2 == 1:
  z = (n+1)//2-1
  print(bl[z]-al[z]+1)
else:
  x = n//2
  ax2 = al[x-1]+al[x]
  bx2 = bl[x-1]+bl[x]
  print(bx2-ax2+1)

Fixed submission:
from statistics import median

n = int(input())
abl = [list(map(int,input().split())) for nesya in range(n)]
al = []
bl = []
for ab in abl:
  al.append(ab[0])
  bl.append(ab[1])
if n%2 == 1:
  print(median(bl)-median(al)+1)
else:
  print(int(median(bl)*2-median(al)*2+1))
Buggy python submission (verdict: Runtime Error):
n,m,x = map(int,input().split())
c_list = [list(map(int,input().split())) 
          for nesya in range(n)]
arugo = [0]*m
hoge = 0
for c in c_list:
  arugo[0] += c[1]
  arugo[1] += c[2]
  arugo[2] += c[3]
  hoge += c[0]
if arugo[0] < 10 or arugo[1] < 10 or arugo[2] < 10:
  print(-1)
else:
  print(hoge)

Fixed submission:
def bit_set(num:int,n:int):
  if num & (1<<n):
    return True
  return False

n,m,x = map(int,input().split())
ca_list = [list(map(int,input().split())) 
           for nesya in range(n)]
c = -1
for i in range(2**n):
  skill = [0]*m
  cost = 0
  for k in range(n):
    if bit_set(i,k) == True:
      ca =  ca_list[k]
      cost += ca[0]
      a = ca[1:]
      skill = [j+l for (j,l) in zip(skill, a)]
  if all((hoge >= x) for hoge in skill):
    if c == -1:
      c = cost
    else:
      c = min(c,cost)
print(c)

Buggy python submission (verdict: Runtime Error):
n,m,x = map(int,input().split())
c_list = [list(map(int,input().split())) 
          for nesya in range(n)]
arugo = [0]*m
hoge = 0
while c in c_list:
  arugo[0] += c[1]
  arugo[1] += c[2]
  arugo[2] += c[3]
  hoge += c[0]
if arugo[0] < 10 or arugo[1] < 10 or arugo[2] < 10:
  print(-1)
else:
  print(hoge)

Fixed submission:
def bit_set(num:int,n:int):
  if num & (1<<n):
    return True
  return False

n,m,x = map(int,input().split())
ca_list = [list(map(int,input().split())) 
           for nesya in range(n)]
c = -1
for i in range(2**n):
  skill = [0]*m
  cost = 0
  for k in range(n):
    if bit_set(i,k) == True:
      ca =  ca_list[k]
      cost += ca[0]
      a = ca[1:]
      skill = [j+l for (j,l) in zip(skill, a)]
  if all((hoge >= x) for hoge in skill):
    if c == -1:
      c = cost
    else:
      c = min(c,cost)
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a = 0
t = 1
d = 0
hoge_list = []
while a < k:
  hoge_list.append(t)
  t = a_list[t-1]
  a += 1
  if t in hoge_list:
    b = hoge_list.index(t)
    d += 1
    break
if d == 0:
  print(t)
else:
  e = (k-b)%(a-b)
  print(hoge_list[b+e])

Fixed submission:
n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a = 0
t = 1
d = 0
hoge_list = []
hoge_set = set()
while a < k:
  hoge_list.append(t)
  hoge_set.add(t)
  t = a_list[t-1]
  a += 1
  if t in hoge_set:
    b = hoge_list.index(t)
    d += 1
    break
if d == 0:
  print(t)
else:
  e = (k-b)%(a-b)
  print(hoge_list[b+e])
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
h = list(map(int,input().split()))
x = [list(map(int,input().split())) for nesya in range(m)]
k = [1]*n
for route in x:
  h1 = route[0]-1
  h2 = route[1]-1
  if h[h1] < h[h2]:
    k[h1] = 0
  elif h[h1] > h[h2]
    k[h2] = 0
print(sum(k))

Fixed submission:
n,m = map(int,input().split())
h = list(map(int,input().split()))
x = [list(map(int,input().split())) for nesya in range(m)]
k = [1]*n
for route in x:
  h1 = route[0]-1
  h2 = route[1]-1
  if h[h1] < h[h2]:
    k[h1] = 0
  elif h[h1] > h[h2]:
    k[h2] = 0
  else:
    k[h1] = 0
    k[h2] = 0
print(sum(k))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
h = list(map(int,input().split()))
x = [list(map(int,input().split())) for nesya in range(m)]
s = list(range(1,n+1))
for hoge in x:
  if h[hoge[0]-1] > h[hoge[1]-1]:
    try:
      s.remove(hoge[1])
    except ValueError:
      pass
  elif h[hoge[0]-1] < h[hoge[1]-1]:
    try:
      s.remove(hoge[0])
    except ValueError:
      pass
  else:
    try:
      s.remove(hoge[0])
    except ValueError:
      pass
    try:
      s.remove(hoge[1])
    except ValueError:
      pass
print(len(s))


Fixed submission:
n,m = map(int,input().split())
h = list(map(int,input().split()))
x = [list(map(int,input().split())) for nesya in range(m)]
k = [1]*n
for route in x:
  h1 = route[0]-1
  h2 = route[1]-1
  if h[h1] < h[h2]:
    k[h1] = 0
  elif h[h1] > h[h2]:
    k[h2] = 0
  else:
    k[h1] = 0
    k[h2] = 0
print(sum(k))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
plus = []
minus = []
for i in range(n):
  plus.append(a[i]+i+1)
  minus.append(i+1-a[i])
c = 0
for i in range(n-1):
  for j in range(i,n):
    if plus[i] == minus[j]:
      c += 1
print(c)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
plus = dict()
minus = dict()
for i in range(n):
  num = i+1
  p = a[i] + num
  m = num - a[i]
  if p in plus:
    plus[p] += 1
  else:
    plus[p] = 1
  if (m) in minus:
    minus[m] += 1
  else:
    minus[m] = 1
c = 0
for v in plus.keys():
  if v in minus:
    c += plus[v] * minus[v]
print(c)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = input()
a_list = s.split()
dic =  Counter(a_list)
k = 1
while k <= n:
  print(dic[str(k)])
  k += 1

Fixed submission:
import math
a = int(input())
b = 2*a*math.pi
print(b)

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = a*pi()
print(b)

Fixed submission:
import math
a = int(input())
b = 2*a*math.pi
print(b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
a_list = s.split()
k = 1
while k <= n:
  a = a_list.count(str(k))
  print(a)
  k += 1

Fixed submission:
from collections import Counter
n = int(input())
s = input()
a_list = s.split()
dic =  Counter(a_list)
k = 1
while k <= n:
  print(dic[str(k)])
  k += 1
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = a//100
c = a//10 - b*10
d = a%10
if b != 7 and c != 7 and d != 7:
  print(No)
else:
  print(Yes)

Fixed submission:
a = int(input())
b = a//100
c = a//10 - b*10
d = a%10
if b != 7 and c != 7 and d != 7:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
a = list(range(1,k+1))
ans = 0
for x in a:
  for y in a:
    for z in a:
      ans += math.gcd(math.gcd(x,y),z)
print(ans)

Fixed submission:
import math
k = int(input())
ans = 0
for x in range(1,k+1):
  for y in range(1,k+1):
    hoge = math.gcd(x,y)
    for z in range(1,k+1):
      ans += math.gcd(hoge,z)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
m = int(input())
q_list = [list(input().split()) 
          for nesya in range(m)]
n = 0
for q in q_list:
  if q[0] == '1':
    n += 1
  else:
    f = n + int(q[1])
    if f%2 == 1:
      s = q[2] + s
    else:
      s = s + q[2]
if n%2 == 1:
  s = s[::-1]
print(s)

Fixed submission:
from collections import deque
#入力
s = input()
m = int(input())
q_list = [list(input().split()) 
          for nesya in range(m)]
d = deque(s)
n = 0
for q in q_list:
  if q[0] == '1':
    n += 1
  else:
    if (n%2 == 0 and q[1] == '1') or (n%2 == 1 and q[1] == '2'):
      d.appendleft(q[2])
    else:
      d.append(q[2])
ans = ''.join(d)
if n%2 == 0:
  print(ans)
else:
  print(ans[::-1])