Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02641 (python)

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

if n == 0:
    print(x)
    exit()

P = [int(x) for x in input().split()]

before = x
after = x
while True:
    if before not in P:
        print(before)
        break
    elif after not in P:
        print(after)
        break
    before -= 1
    after += 1

Buggy submission (verdict: Runtime Error):
x, n = [int(x) for x in input().split()]

if n = 0:
    print(x)
    exit()

P = [int(x) for x in input().split()]

before = x
after = x
while True:
    if before not in P:
        print(before)
        break
    elif after not in P:
        print(after)
        break
    before -= 1
    after += 1
Problem p02658 (python)

Fixed submission:
import sys

n = input()
A = sorted([int(x) for x in input().split()], reverse=True)

if A[-1] == 0:
    print(0)
    sys.exit()

product = 1
for a in A:
    product *= a
    if product > 10**18:
        product = -1
        break

print(product)

Buggy submission (verdict: Runtime Error):
n = input()
A = [int(x) for x in input().split()]
product = 1
 
for a in A:
    product *= a
    if a = 0:
        break
 
print(product if product <= 10**18 else -1)

Buggy submission (verdict: Runtime Error):
n = input()
A = [int(x) for x in input().split()]
product = 1

for a in A:
    product *= a
    if a = 0:
        break

print(product if product <= 10**18 else -1)
Problem p02923 (python)

Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]

count = 0
provisional_max_count = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        count += 1
    else:
        provisional_max_count = max(count, provisional_max_count)
        count = 0
print(max(provisional_max_count, count))

Buggy submission (verdict: Runtime Error):
n = input()
height_list = [int(i) for i in input().split()]

count_list = []
for i in range(len(height_list)-1):
    count = 0
    for j in range(i, len(height_list)-1):
        if height_list[j] < height_list[j+1]:
            break
        count += 1
    count_list.append(count)
print(max(count_list))

Buggy submission (verdict: Runtime Error):
n = input()
height_list = [int(i) for i in input().split()]

count_list = []
for i in range(len(height_list)-1):
    count = 0
    for j in range(i, len(height_list)-1):
        if height_list[j] >= height_list[j+1]:
            count += 1
    count_list.append(count)
print(max(count_list))
Problem p03998 (python)

Fixed submission:
hands_a, hands_b, hands_c = (input() for i in range(3))

hands = {'a': hands_a, 'b': hands_b, 'c': hands_c}

turn = 'a'
while True:
    if len(hands[turn]) == 0:
        print(turn.upper())
        exit()
    next_turn = hands[turn][0]
    hands[turn] = hands[turn][1:]
    turn = next_turn

Buggy submission (verdict: Runtime Error):
hands_a, hands_b, hands_c = (list(input()) for i in range(3))

hands = {'a': hands_a, 'b': hands_b, 'c': hands_c}

turn = 'a'
while len(hands[turn]) > 0:
    turn = hands[turn].popleft()
print(turn.upper())

Buggy submission (verdict: Runtime Error):
hands_a, hands_b, hands_c = (list(input()) for i in range(3))

hands = {'a': hands_a, 'b': hands_b, 'c': hands_c}

turn = 'a'
while len(hands[turn]) > 0:
    turn = hands[turn].popleft
print(turn.upper())
Problem p02582 (python)

Fixed submission:
s=list(input())


c=[]
for i in range(3):
  cnt=0
  if s[i]=='R':
    
    
    while i<3:
      if s[i]=='R':
        cnt+=1
        i+=1
        
      else:
        break
        
  c.append(cnt)
    
print(max(c))

Buggy submission (verdict: Runtime Error):
s=list(input())


c=[]
for i in range(3):
  
  if s[i]=='R':
    cnt=0
    
    while i<3:
      if s[i]=='R':
        cnt+=1
        i+=1
        
      else:
        break
        
    c.append(cnt)
    
print(max(c))
Problem p02631 (python)

Fixed submission:
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()



n=ii()
a=lmi()
S=0
for i in a:
  S=S^i

b=[]
for i in a:
  a_=S^i
  b.append(a_)

print(' '.join(map(str,b)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()



n=ii()
a=lmi()
S=0
for i in a:
  S=S^i

b=[]
for i in a:
  a_=S^i
  b.append(a_)

  print(' '.join(map(str,b)))
Problem p02683 (python)

Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(10**8)

def dfs(i,a,value):
  global ans
  if i==n:
    if all(a[i]>=x for i in range(m)):
      ans=min(ans,value)


  else:
    dfs(i+1,a,value)
    dfs(i+1,a+np.array(pc[i][1:]),value+pc[i][0])


ans=float('inf')
n,m,x=map(int,input().split())
pc=[]
for i in range(n):
  s=list(map(int,input().split()))
  pc.append(s)

dfs(0,np.array([0]*(m)),0)
if ans==float('inf'):
  ans=-1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
nedan=[]
grade=[]
inf=12*10**6
for i in range(n):
  s=list(map(int,input().split())) 
  nedan.append(s.pop(0))
  grade.append(s)
#print(nedan)
#print(grade)

for i in range(2**n):
  shopping=[]
  total_grade=[]
  for j in range(n):
    if (( i >> j ) & 1):
      shopping.append(nedan[j])
      total_grade.append(grade[j])

  t=sum(shopping)
  #print(t)
  #print(shopping)
  #print(total_grade)
  sum_grade=[]
  for j in range(m):
    s=0
    for k in range(len(total_grade)):
        s+=total_grade[k][j]
    sum_grade.append(s)
    print(sum_grade)

  ans_t=[]
  if all(j>=x for j in sum_grade):
    ans_t.append(t)

print(ans_t)   
ans=min(ans_t)

if min(ans,inf)==ans:
  print(ans)

else:
  print(-1)
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
town=[0]*n
info=[1]
now=1
while town[now-1]==0:
    town[now-1]+=1
    now=a[now-1]
    info.append(now)
loop_list=list(info[info.index(now):-1])
loop_len=len(loop_list)
before_loop_list=list(info[:info.index(now)])
#print(town)
#print(info)
if k<len(before_loop_list):
    print(before_loop_list[k])
else:
    print(loop_list[((k-len(before_loop_list))%loop_len)])

Buggy submission (verdict: Runtime Error):
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n,k=mi()
a=lmi()

s=[]
s.append(1)

o=[-1]*(n+1)
o[1]=0
t=0
while a:
  p=a.pop(0)
  s.append(p)
  if o[p]!=-1:
    pp=t-o[p]
    ss=o[p]
    break
  o[p]=t
  t+=1
#print(ss,pp)
#print(s)
if k<ss:
  print(s[k-1])

else:
  ans=k%pp
  print(s[ss+ans+1])
Problem p02690 (python)

Fixed submission:
x=int(input())
for i in range(-120,120):
  for j in range(-120,120):
    if i**5-j**5==x:
      print(i,j)
      exit()

Buggy submission (verdict: Runtime Error):
x=int(input())
for i in range(-120,120):
  for j in range(-120.120):
    if i**5-j**5==x:
      print(i,j)
      break

Buggy submission (verdict: Runtime Error):
for i in range(-120,120):
  for j in range(-120,120):
    if i**5-j**5==x:
      print(i,j)
      break

Buggy submission (verdict: Runtime Error):
x=int(input())
for i in range(-120,120):
  for j in range(-120.120):
    if i**5-j**5==x:
      print(i,j)
      break
Problem p02706 (python)

Fixed submission:
n,m=map(int,input().split())
 
a=list(map(int,input().split()))
s=int(sum(a))
 
if (n-s)>= 0:
  print(n-s)
  
else:
  print(-1)

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

a=list(map(int,input().split()))
s=sum(a)

if n-a> 0:
  print(n-a)
  
else:
  print(-1)
Problem p02714 (python)

Fixed submission:

n=int(input())
s_=input()
r, g, b = s_.count("R"), s_.count("G"), s_.count("B")
rgb = r * g * b
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
s_=input()
s=Couter(s_)
rgb = s['R'] * s['G'] * s['B']
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)
Problem p02718 (python)

Fixed submission:
import math
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
t=math.ceil(s/4/m)
a.sort()

cnt=0
for i in a:
  if i>=t:
    cnt+=1

if cnt>=m:
  print('Yes')
  
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
t=math.floor(s/4/m)
a.sort()
for i in a:
  if i<t:
    u=i

  else:
    break
cnt=0
for i in a:
  if i>u:
    cnt+=1

if cnt>=m:
  print('Yes')
  
else:
  print('No')
Problem p02719 (python)

Fixed submission:
n,k=map(int,input().split())
s=n%k
print(min(s,abs(k-s)))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=n%k
print(min(s,abs(k-s))
Problem p02760 (python)

Fixed submission:
bingo=[]
for i in range(3):
  a=list(map(int,input().split()))
  bingo.append(a)
  
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    if b in bingo[j]:
      bingo[j][bingo[j].index(b)]=0
      
def hantei(l):
  for i in range(3):
    if all([l[i][j]==0 for j in range(3)]):
      return 'Yes'
    
    elif all([l[j][i]==0 for j in range(3)]):
      return 'Yes'
    
    elif l[0][0]==0 and l[1][1]==0 and l[2][2]==0:
      return 'Yes'
    
    elif l[0][2]==0 and l[1][1]==0 and l[2][0]==0:
      return 'Yes'
    
    else:
      continue
      
  return 'No'
    
#print(bingo)
print(hantei(bingo))

Buggy submission (verdict: Runtime Error):
bingo=[]
for i in range(3):
  a=list(map(int,input().split()))
  bingo.append(a)
  
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    if b in bingo[i]:
      bingo[i][bingo[i].index(b)]=0
      
def hantei(l):
  for i in range(3):
    if all([l[i][j]==0 for j in range(3)]):
      return 'Yes'
    
    elif all([l[j][i]==0 for j in range(3)]):
      return 'Yes'
    
    elif l[0][0]==0 and l[1][1]==0 and l[2][2]==0:
      return 'Yes'
    
    elif l[0][2]==0 and l[1][1]==0 and l[2][0]==0:
      return 'Yes'
    
    else:
      return 'No'
    
print(hantei(bingo))

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(3):
  aa=list(map(str,input().split()))
  a.append(aa)
  
n=int(input())
ln=[]
for i in range(n):
  lnn=input()
  ln.append(lnn)
  
visited=[[0]*3 for i in range(3)]

for i in range(3):
  for j in range(3):
    for k in range(n):
      if ln[k] in a[i][j]:
        visited[i][j]=1

for j in range(3):
  if all([visited[i][j] for i in range(3)])==1:
    print('Yes')
    exit()
    
for i in range(3):
  if all([visited[i][j] for j in range(3)])==1:
    print('Yes')
    exit()
    
if visited[0][0]==1 and visited[1][1]==1 and visited[2][2]==1:
  print('Yes')
  exis()
  
if visited[0][2]==1 and visited[1][1]==1 and visited[2][0]==1:
  print('Yes')
  exis()
  
print('No')
Problem p02789 (python)

Fixed submission:
n,m=map(int,input().split())
if n==m:
  print('Yes')
  
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n.m=map(int,input().split())
if n==m:
  print('Yes')
  
else:
  print('No')
Problem p02898 (python)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
cnt=0
for i in h:
  if i>=k:
    cnt+=1
    
print(cnt)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cnt=0
for i in h:
  if h<k:
    cnt+=1
    
print(cnt)
Problem p02909 (python)

Fixed submission:
s=input()
wether=['Sunny', 'Cloudy', 'Rainy','Sunny']
for i in range(len(wether)):
  if s==wether[i]:
    print(wether[i+1])
    break

Buggy submission (verdict: Runtime Error):
s=input()
wether=['Sunny', 'Cloudy', 'Rainy','Sunny']
for i in wether:
  if s==i:
    print(wether[i+1])
    break
Problem p02911 (python)

Fixed submission:
from collections import Counter
import numpy as np
n,k,q=map(int,input().split())
a=[]
for i in range(q):
  a_=int(input())
  a.append(a_)
 
 
listn_=[]
for i in range(n):
  listn_.append(k)
listn=np.array(listn_)
listn=listn-q
s=Counter(a)
for i in s.keys():
  listn[i-1]+=s[i]
 
#print(listn)
for i in listn:
  if i>0:
    print('Yes')
    
  else:
    print('No')

Buggy submission (verdict: Runtime Error):
from collections import Counter
import numpy as np
n,k,q=map(int,input().split())
a=[]
for i in range(q):
  a_=int(input())
  a.append(a_)


listn_=[]
for i in range(n):
  listn_.append(k)
listn=np.array(listn_)

s=Counter(a)
for i in s.keys():
  lists_=[-1*s[i]]*n
  lists_[i-1]=0
  lists=np.array(lists_)
  listn=listn+lists

#print(listn)
for i in listn:
  if i>0:
    print('Yes')
    
  else:
    print('No')
Problem p02917 (python)

Fixed submission:
N=int(input())
B=list(map(int,input().split()))
A=[]
B.insert(0,1000000)
B.append(1000000)
for i in range(1,N+1):
  a=min(B[i],B[i-1])
  A.append(a)
print(sum(A))

Buggy submission (verdict: Runtime Error):
N=int(input())
B=list(map(int,input().split()))

A=[0,]
for i in range(N+1):
  a=min(B[i],B[i-1])
  A.append(a)
  
print(sum(A))
Problem p02921 (python)

Fixed submission:
s=input()
t=input()
cnt=0
for i in range(len(s)):
  if s[i]==t[i]:
    cnt+=1
 
print(cnt)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
cnt=0
for i in rage(len(s)):
  if s[i]==t[i]:
    cnt+=1

print(cnt)
Problem p02983 (python)

Fixed submission:
L,R=map(int,input().split())
ans=float('inf')
for i in range(L,R):
  for j in range(L+1,R+1):
    s=(i*j)%2019
    
    if s==0:
      print(0)
      exit()
    else:
      ans=min(s,ans)
      
print(ans)

Buggy submission (verdict: Runtime Error):
L.R=map(int,input().split())
ans=float('inf')
for i in range(L,R+1):
  for j in range(L,R+1):
    s=(i*j)%2019
    if s==0:
      print(0)
      exit()
    else:
      ans=min(s,ans)
      
print(ans)
Problem p02993 (python)

Fixed submission:
s=input()
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    print('Bad')
    exit()
    
print('Good')

Buggy submission (verdict: Runtime Error):
s=input()
for i in range(len(s)):
  if s[i]==s[i+1]:
    print('Bad')
    exit()
    
print('Good')
Problem p03043 (python)

Fixed submission:
n,k = map(int, input().split())
 
ans = 0
for i in range(1,n+1):
  t = 0
  while i < k:
    i *= 2
    t += 1
  ans += 0.5**t
print(ans/n)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
for i in range(21):
  if k<=2**i:
    t=i
    break
   
#print(t)
if n>=k:
  ans=1/n*((1/2**t)*(2**(k-1)-1)+n-k+1)
else:
  ans=1/n*(1/2**t)*(2**(n)-1)
print('{:.13f}'.format(ans))
Problem p03086 (python)

Fixed submission:
ss=['A','G','C','T']
s=list(input())
ans=0
for i in range(len(s)):
  if s[i] in ss:
    j=i
    cnt=0
    while j<len(s):
      if s[j] in ss:
        cnt+=1
        j+=1
      else:
        break
      
    ans=max(ans,cnt)
      
print(ans)

Buggy submission (verdict: Runtime Error):
ss=['A','G','C','T']
s=list(input())
ans=0
for i in range(len(s)-1):
  if s[i] in ss:
    j=i
    cnt=0
    while s[j] in ss:
      j+=1
      cnt+=1
      
    ans=max(ans,cnt)
      
print(ans)
Problem p03251 (python)

Fixed submission:
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
 
x.sort(reverse=True)
y.sort()
 
 
flag=0
for i in range(X+1,Y+1):
  if x[0]<i and y[0]>=i:
    flag=1
    break
  
 
  else:
    flag=0
    
if flag==1:
  print('No War')
  
else:
  print('War')

Buggy submission (verdict: Runtime Error):
x=list(map(int,input().split()))
y=list(map(int,input().split()))
 
x.sort(reverse=True)
y.sort()
 
 
flag=0
for i in range(X+1,Y+1):
  if x[0]<=i and y[0]>i:
    flag=1
    break
  
 
  else:
    flag=0
    
if flag==1:
  print('No War')
  
else:
  print('War')

Buggy submission (verdict: Runtime Error):
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
 
x.sort(reverse=True)
y.sort()


flag=0
for i in range(X+1,Y+1):
  if x[0]<=i and y[0]>i:
    flag=1
    break
  

  else:
    flag=0
    
if flag=1:
  print('No War')
  
else:
  print('War')
Problem p03290 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})


d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
sys.setrecursionlimit(10**6)

def dfs(i,sum,count,nokori):
  global ans
  if i==g:
    if sum<g:
      use=max(nokori)
      n=min(pc[n-1][1],-(-(g-sum)//100*use)
      count+=n
      sum+=n*100*use

    if sum>=g:
      ans=min(ans,count)

  else:
    dfs(i+1,sum,count,nokori)
    dfs(i+1,sum+pc[i][0]*100*(i+1)+pc[i][1],count+pc[i][0],nokori-(i+1))

d,g=map(int,input().split())
pc=[list(map(int,input().split())) for i in range(d)]
ans=float('inf')

dfs(0,0,0,set(range(1,d+1))

print(ans)
Problem p03436 (python)

Fixed submission:
from collections import deque

h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
visited=[[float('inf')]*w for i in range(h)]
def bfs():
  que =deque()
  visited[0][0]=0
  que.append([0,0])
  while que:
    p=que.popleft()
    if p[1]==w-1 and p[0]==h-1:
      break
    for dx,dy in ([0,1],[0,-1],[1,0],[-1,0]):
      ny=p[1]+dy
      nx=p[0]+dx
      if nx>=0 and ny>=0 and nx<h and ny<w and visited[nx][ny]==float('inf') and l[nx][ny]!='#':
        visited[nx][ny]=visited[p[0]][p[1]]+1
        que.append([nx,ny])

  return visited[h-1][w-1]


suml=0
for i in range(h):
  suml+=l[i].count('#')
  
if bfs()==float('inf'):
  print(-1)
else:
  print(h*w-suml-bfs()-1)

Buggy submission (verdict: Runtime Error):
from collections import deque

h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
visited=[[0]*w for i in range(h)]
def bfs():
  que =deque()
  visited[0][0]=0
  que.append([0,0])
  while que:
    p=que.popleft()
    if p[1]==w-1 and p[0]==h-1:
      break
    for dx,dy in ([0,1],[0,-1],[1,0],[-1,0]):
      ny=p[1]+dy
      nx=p[0]+dx
      if nx>=0 and ny>=0 and nx<w and ny<h and visited[nx][ny]==0 and l[nx][ny]!='#':
        visited[nx][ny]=visited[p[0]][p[1]]+1
        que.append([nx,ny])

  return visited[h-1][w-1]


suml=0
for i in range(h):
  suml+=l[i].count('#')
print(h*w-suml-bfs()-1)
Problem p02556 (python)

Fixed submission:
N = int(input())

Xmax = -2*10**9
Ymax = -2*10**9
Xmin = 2*10**9
Ymin = 2*10**9


for i in range(N):
    x, y = map(int, input().split())
    if (x + y >= Xmax):
        Xmax = x + y
    if (x + y <= Xmin):
        Xmin = x + y
    if (x - y >= Ymax):
        Ymax = x - y
    if (x - y <= Ymin):
        Ymin = x - y

print(max(Xmax - Xmin, Ymax - Ymin))

Buggy submission (verdict: Runtime Error):
N = int(input())

Xmax = -2*10**9
Ymax = -2*10**9
Xmin = 2*10**9
Ymin = 2*10**9


for i in range(N):
    x, y = map(int, input().split())
    if (x + y >= Xmax):
        Xmax = x + y
    if (x + y =< Xmin):
        Xmin = x + y
    if (x - y >= Ymax):
        Ymax = x - y
    if (x - y =< Ymin):
        Ymin = x - y

print(max(Xmax - Xmin, Ymax - Ymin))
Problem p02612 (python)

Fixed submission:
n = int(input())
i = 0
m = n
while (m > 0):
    m = m - 1000
    i = i + 1

print(i*1000 - n)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]
AC = 0
WA = 0
TLE = 0
RE = 0
for t in s:
    if (t == 'AC'):
        AC += 1
    elif (t == 'WA'):
        WA += 1
    elif (t == 'TLE'):
        TLE += 1
    else:
        RE += 1

print('AC x ', AC)
print('WA x ', WA)
print('TLE x ', TLE)
print('RE x ', RE)
Problem p02582 (python)

Fixed submission:
s = input()
R_list = s.split('S')

ans = 0

for s in R_list:
  if ans < len(s):
    ans = len(s)
    
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = [int(x)-1 for x in input().split()]
c = [int(x) for x in input().split()]
each_point = []

for i in range(n):
  now = i
  check = []
  max_point = c[p[now]]
  point = 0
  for j in range(k):
    if now in check:
      l = len(check)
      lastpoint = point * int(k/l)
      for e in range(k%l):
        now = p[now]
        lastpoint += c[now]
      each_point.append(lastpoint)
      for e in range(l):
        lastpoint -= c[now]
        now = p.index(now)
      break
    check.append(now)    
    now = p[now]
    point += c[now]
    if max_point < point:
      max_point = point
  
  each_point.append(max_point)
  
print(max(each_point))
Problem p02681 (python)

Fixed submission:
s = input()
t = input()

if(len(s)+1 == len(t)) and (s == t[0:len(t)-1]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n,k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
 
l = [1]
now = 1
next = a[0]
notloop = 0
dupl = -1
 
for i in range(n):
  now = next
  next = a[now-1]
  
  if now in l:
    dupl = now
    break
  else:
    l.append(now)
    
if(dupl == -1):
  print(now)
  
else:
  notloop = l.index(dupl)
  length = len(l)-notloop
  print(l[(k-notloop)%length+notloop])
Problem p02683 (python)

Fixed submission:
def check(pair,m,x):
  sum = 0
  
  for i in range(1,m+1):
    p= 0
    for e in pair:
      p += e[i]
    if(p < x):
      return -1
    
  for e in pair:
    sum += e[0]
  return sum
      
n,m,x = (int(x) for x in input().split())
a = []
for i in range(n):
  a.append(tuple([int(x) for x in input().split()]))
  
min = -1
  
for i in range(2 ** n):
  pair = []
  for j in range(n):
    if((i >> j) & 1):
      pair.append(a[j])
  sum = check(pair,m,x)
  
  if min == -1:
    min = sum
  elif sum != -1 and min > sum:
    min = sum
    
print(min)

Buggy submission (verdict: Runtime Error):
def check(pair,m,x):
  sum = 0
  
  for i in range(1,m):
    p = 0
    for e in pair:
      p += e[i]
    
    if(p < x):
      return -1
    
  for e in pair:
    sum += e[0]
  return sum
      
n,m,x = (int(x) for x in input().split())
a = []
for i in range(n):
  a.append(tuple([int(x) for x in input().split()]))
  
list = [] 
  
for i in range(2 ** n):
  pair = []
  for j in range(n):
    if((i >> j) & 1):
      pair.append(a[j])
      
  sum = check(pair,m,x)
  if(sum != -1):
    list.append(sum)
print(min(list))