Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])
p_list = []

hoge = input().split()

for i in range(N):
  p_list.append(int(hoge[i]))
  
big = 0
for i in range(N-K+1):
  _sum = sum(p_list[i:i+K])
  if _sum > big:
    big = _sum
    
ans = (float(big) / 2) + 0.5 * float(K) 
print(ans)

Fixed submission:
hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])

p_list = list(map(int,input().split()))
  
big = 0
s = [0] * (N+1)
for i in range(N):
  s[i+1] = s[i] + p_list[i]

res = 0
for i in range(N-K+1):
  val = s[K+i] - s[i]
  if res < val:
    res = val

ans = (float(res) / 2) + 0.5 * float(K) 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])
p_list = []

hoge = input().split()

for i in range(N):
  p_list.append(int(hoge[i]))
  
big = 0
max_idx = 0
for i in range(N-K+1):
  _sum = sum(p_list[i:i+K])
  if _sum > big:
    big = _sum
    max_idx = i
    
ans = 0
for j in range(K):
  num = p_list[max_idx+j]
  kitaichi = (float(num) / 2) + 0.5
  ans += kitaichi
print(ans)

Fixed submission:
hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])

p_list = list(map(int,input().split()))
  
big = 0
s = [0] * (N+1)
for i in range(N):
  s[i+1] = s[i] + p_list[i]

res = 0
for i in range(N-K+1):
  val = s[K+i] - s[i]
  if res < val:
    res = val

ans = (float(res) / 2) + 0.5 * float(K) 
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

if M != 0:
  A = []
  ACnum = []
  ACkazu = []
  for i in range(M):
    hoge = input().split()
    if hoge[1] == "AC" and hoge[0] not in ACkazu:
      ACnum.append(i)
      ACkazu.append(hoge[0])
      A.append(hoge)
    elif hoge[0] not in ACkazu:
      A.append(hoge)
  pena = 0
  _remove = []
  for i in ACnum:
    i = int(i)
    AC_num = A[i][0]
    for j in range(0,i):
      if A[j][0] == A[i][0]:
        pena += 1
        _remove.append(j)
    _remove.append(i)
  # popでケツから消していく
  for i in reversed(_remove):
    A.pop(i)
  pena += len(A)
  print(len(ACnum), end="")
  print(" ", end="")
  print(pena, end="")
else:
  print(0, end="")
  print(" ", end="")
  print(0, end="")

Fixed submission:
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

WA = [0] * 105000
AC = [False] * 105000

WAnum = 0
ACnum = 0

for i in range(M):
    hoge = input().split()
    if AC[int(hoge[0])]:
      continue
    if hoge[1] == "AC":
      AC[int(hoge[0])] = True;
      ACnum += 1
      WAnum += WA[int(hoge[0])]
    elif hoge[1] == "WA":
      WA[int(hoge[0])] += 1
      
print(ACnum, WAnum)
Buggy python submission (verdict: Runtime Error):
_N, _K, _Q = input().split()
N, K, Q = int(_N), int(_K), int(_Q)
A = []
for i in range(Q):
  A.append(int(input()))

if K > Q:
  for i in range(N):
    print("Yes")
else:
  hoge = Q - K + 1
  goods = sorted(set([i for i in A if A.count(i) >= hoge]))
  j = 0
  max_j = len(goods)
  for i in range(1,N+1):
    if i == goods[j]:
      print("Yes")
      if j + 1 == len(goods):
        for k in range(i,N):
          print("No")
        break
      else:
        j += 1
    else:
      print("No")

Fixed submission:
import numpy as np
_N, _K, _Q = input().split()
N, K, Q = int(_N), int(_K), int(_Q)
A = []
for i in range(Q):
  A.append(int(input()))

if K > Q:
  for i in range(N):
    print("Yes")
else:
  score = K * np.ones(N) - Q
  for i in A:
    score[i-1] += 1
  for i in score:
    if i > 0:
      print("Yes")
    else:
      print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = input().split()
A = []
for i in range(int(Q)):
  A.append(int(input()))

if int(K) > int(Q):
  for i in range(int(N)):
    print("Yes")
else:
  goods = list(set([i for i in A if A.count(i) >= int(Q) - int(K) + 1]))
  for i in range(1,int(N)+1):
    if i in goods:
      print("Yes")
    else:
      print("No")

Fixed submission:
import numpy as np
_N, _K, _Q = input().split()
N, K, Q = int(_N), int(_K), int(_Q)
A = []
for i in range(Q):
  A.append(int(input()))

if K > Q:
  for i in range(N):
    print("Yes")
else:
  score = K * np.ones(N) - Q
  for i in A:
    score[i-1] += 1
  for i in score:
    if i > 0:
      print("Yes")
    else:
      print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K, Q = input().split()
A = []
for i in range(int(Q)):
  A.append(int(input()))

Answers = np.zeros(int(N))
ones = np.ones(int(N))
if int(K) > int(Q):
  for i in range(int(N)):
    print("Yes")
else:
  for i in A:
    ones[i-1] = 0
    Answers += ones
    ones[i-1] = 1
  for i in Answers:
    if i < int(K):
      print("Yes")
    else:
      print("No")

Fixed submission:
import numpy as np
_N, _K, _Q = input().split()
N, K, Q = int(_N), int(_K), int(_Q)
A = []
for i in range(Q):
  A.append(int(input()))

if K > Q:
  for i in range(N):
    print("Yes")
else:
  score = K * np.ones(N) - Q
  for i in A:
    score[i-1] += 1
  for i in score:
    if i > 0:
      print("Yes")
    else:
      print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
_N, _M = input().split()
N, M = int(_N), int(_M)
A = np.array(list(map(int,input().split())))

for i in range(M):
  hoge = A.argmax()
  A[hoge] = A[hoge]//2
print(sum(A))

Fixed submission:
import heapq
N,M = map(int,input().split())

A = list(map(int,input().split()))
H = []
for i in A:
  heapq.heappush(H, -int(i))
for i in range(M):
  a = heapq.heappop(H)
  heapq.heappush(H, -(-a//2))
print(-sum(H))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
_N, _M = input().split()
N, M = int(_N), int(_M)
A = np.array(list(map(int,input().split())))

for i in range(M):
  A[A.argmax()] = np.max(A)//2
print(sum(A))

Fixed submission:
import heapq
N,M = map(int,input().split())

A = list(map(int,input().split()))
H = []
for i in A:
  heapq.heappush(H, -int(i))
for i in range(M):
  a = heapq.heappop(H)
  heapq.heappush(H, -(-a//2))
print(-sum(H))

Buggy python submission (verdict: Time Limit Exceeded):
_N, _M = input().split()
N, M = int(_N), int(_M)
A = list(map(int,input().split()))

for i in range(M):
  hoge = max(A)
  A[A.index(hoge)] = hoge//2
print(sum(A))

Fixed submission:
import heapq
N,M = map(int,input().split())

A = list(map(int,input().split()))
H = []
for i in A:
  heapq.heappush(H, -int(i))
for i in range(M):
  a = heapq.heappop(H)
  heapq.heappush(H, -(-a//2))
print(-sum(H))

Buggy python submission (verdict: Time Limit Exceeded):
_N, _M = input().split()
N, M = int(_N), int(_M)
A = list(map(int,input().split()))

for i in range(M):
  A[A.index(max(A))] = max(A)//2
print(sum(A))

Fixed submission:
import heapq
N,M = map(int,input().split())

A = list(map(int,input().split()))
H = []
for i in A:
  heapq.heappush(H, -int(i))
for i in range(M):
  a = heapq.heappop(H)
  heapq.heappush(H, -(-a//2))
print(-sum(H))
Buggy python submission (verdict: Runtime Error):
N = int(input())
hoge = input().split()
v = []
for i in range(N):
  v.append(int(hoge[i]))

_v = sorted(v, reverse=True)

gu = _v.pop(N-1)
if N == 2:
  print((_v[0]+_v[1])/2)
else:
  for i in range(N-2,-1,-1):
    gu = (gu + _v.pop(i))/2
  print(gu)

Fixed submission:
N = int(input())
hoge = input().split()
v = []
for i in range(N):
  v.append(int(hoge[i]))

_v = sorted(v, reverse=True)

gu = _v.pop(N-1)
if N == 2:
  print((_v[0]+gu)/2)
else:
  for i in range(N-2,-1,-1):
    gu = (gu + _v.pop(i))/2
  print(gu)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N < 50000
print("No")

Fixed submission:
N = int(input())
hoge = input().split()
H = []
for i in range(N):
  H.append(int(hoge[i]))

piyo = True
dame = False
if N == 1:
  print("Yes")
else:
  for i in range(0,N-1):
    huga = H[i+1] - H[i]
    # print(huga)
    if huga < -1:
      dame = True
      break
    elif huga == -1:
      if piyo == True:
        H[i] = H[i] - 1
      piyo = True
    elif huga > 0:
      H[i+1] = H[i+1] - 1
      piyo = False
  # print(H)
  for i in range(0,N-1):
    huga = H[i+1] - H[i]
    # print(huga)
    if huga < 0:
      dame = True
      break
  if dame == True:
    print("No")
  else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(input())

max_itr = [i for i, v in enumerate(A) if v == max(A)]
max_number = max(A)
if len(max_itr) == 1:
  for i in range(N):
    if i != max_itr[0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)

Fixed submission:
import numpy as np
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(input())

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

Fixed submission:
import numpy as np
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(input())

max_itr = [i for i, v in enumerate(A) if v == max(A)]
max_number = max(A)
for i in range(N):
  if i not in max_itr:
    print(max_number)
  else:
    print(sorted(A)[-2])

Fixed submission:
import numpy as np
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)

Buggy python submission (verdict: Runtime Error):
N = int(input())
hoge = input().split()
A = []
for i in range(N):
  A.append(hoge[i])

max_itr = [i for i, v in enumerate(A) if v == max(A)]
max_number = max(A)
for i in range(N):
  if i not in max_itr:
    print(max_number)
  else:
    print(sorted(A)[-2])

Fixed submission:
import numpy as np
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)
Buggy python submission (verdict: Runtime Error):
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  erase_apple = 0
elif L+N >= 0:
  for i in range(N):
    if i + L == 0:
      erase_apple = i
      break
else:
  erase_apple = N-1

if erase_apple == N:
  erase_apple = N-1

apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))

Fixed submission:
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  erase_apple = 0
elif L+N >= 0:
  for i in range(N+1):
    if i + L == 0:
      erase_apple = i
      break
else:
  erase_apple = N-1

if erase_apple == N:
  erase_apple = N-1

apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))

Buggy python submission (verdict: Runtime Error):
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  print("a")
  erase_apple = 0
elif L+N-1 >= 0:
  for i in range(N):
    if i + L == 0:
      break
else:
  erase_apple = N-1

print(erase_apple)
apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))

Fixed submission:
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  erase_apple = 0
elif L+N >= 0:
  for i in range(N+1):
    if i + L == 0:
      erase_apple = i
      break
else:
  erase_apple = N-1

if erase_apple == N:
  erase_apple = N-1

apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))

Buggy python submission (verdict: Runtime Error):
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  erase_apple = 0
elif L+N >= 0:
  for i in range(N):
    if i + L == 0:
      erase_apple = i
      break
else:
  erase_apple = N-1
  
apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))

Fixed submission:
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  erase_apple = 0
elif L+N >= 0:
  for i in range(N+1):
    if i + L == 0:
      erase_apple = i
      break
else:
  erase_apple = N-1

if erase_apple == N:
  erase_apple = N-1

apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())

s = []
l = [[0] * W for i in range(H)]
r = [[0] * W for i in range(H)]
u = [[0] * W for i in range(H)]
d= [[0] * W for i in range(H)]
  
for i in range(H):
    tmp =list(input())
    s.append(tmp)

for y in range(H):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif x == 0:
      l[y][x] = 1
    else:
      l[y][x] = l[y][x-1] + 1

for y in range(H):
  for x in range(W-1, -1, -1):
    if s[y][x] == "#":
      continue
    elif x == W - 1:
      r[y][x] = 1
    else:
      r[y][x] = r[y][x+1] + 1
      
for y in range(H):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif y == 0:
      u[y][x] = 1
    else:
      u[y][x] = u[y-1][x] + 1
      
for y in range(H-1, -1, -1):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif y == H - 1:
      d[y][x] = 1
    else:
      d[y][x] = d[y+1][x] + 1

ans = 0
for x in range(H):
  for y in range(W):
    if ans < l[x][y] + r[x][y] + u[x][y] + d[x][y] - 3:
      ans = l[x][y] + r[x][y] + u[x][y] + d[x][y] - 3
      
print(ans)

Fixed submission:
H,W = map(int,input().split())

s = []
l = [[0] * W for i in range(H)]
r = [[0] * W for i in range(H)]
u = [[0] * W for i in range(H)]
d= [[0] * W for i in range(H)]
  
for i in range(H):
    tmp =list(input())
    s.append(tmp)

for y in range(H):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif x == 0:
      l[y][x] = 1
    else:
      l[y][x] = l[y][x-1] + 1

for y in range(H):
  for x in range(W-1, -1, -1):
    if s[y][x] == "#":
      continue
    elif x == W - 1:
      r[y][x] = 1
    else:
      r[y][x] = r[y][x+1] + 1
      
for y in range(H):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif y == 0:
      u[y][x] = 1
    else:
      u[y][x] = u[y-1][x] + 1
      
for y in range(H-1, -1, -1):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif y == H - 1:
      d[y][x] = 1
    else:
      d[y][x] = d[y+1][x] + 1

ans = 0
for x in range(H):
  for y in range(W):
    if ans < l[x][y] + r[x][y] + u[x][y] + d[x][y] - 3:
      ans = l[x][y] + r[x][y] + u[x][y] + d[x][y] - 3
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
hoge = input().split()
n = int(hoge[0])
m = int(hoge[1])

l = []
r = []

for i in range(m):
  hoge = input().split()
  l.append(hoge[0])
  r.append(hoge[1])

ok_card = []
for i in range(m):
  for j in range(int(r[i]) - int(l[i])+1):
    ok_card.append(int(l[i])+j)

big_a = list(set(ok_card))
super_card = []
for i in range(len(big_a)):
  if ok_card.count(big_a[i]) >= m:
    super_card.append(big_a[i])

print(len(super_card))

Fixed submission:
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

mi = 0
ma = N

for j in range(M):
    i = input().split(" ")
    l = int(i[0])
    r = int(i[1])
    if l >= mi:
        mi = l
    if r <= ma:
        ma = r
r = ma - mi + 1
if r > 0:
    print(r)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
hoge = input().split()
n = int(hoge[0])
k = int(hoge[1])
s = hoge[2]
new_s = s[:k-1] + s[k-1].lower() + s[k:]
print(new_s)

Fixed submission:
hoge = input().split()
s = input()
n = int(hoge[0])
k = int(hoge[1])
new_s = s[:k-1] + s[k-1].lower() + s[k:]
print(new_s)
Buggy python submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if 0 < a and a <= 12:
  result = "MMYY"
  if 0 < b and b <= 12:
    result = "AMBIGUOUS"
if 0 < b and b <= 12:
  result = "YYMM"
  if 0 < a and a <= 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Fixed submission:
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])
result = None

if 0 < a and a <= 12:
  result = "MMYY"
  if 0 < b and b <= 12:
    result = "AMBIGUOUS"
if 0 < b and b <= 12:
  result = "YYMM"
  if 0 < a and a <= 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Buggy python submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if 0 < a and a < 12:
  result = "YYMM"
  if 0 < b and b < 12:
    result = "AMBIGUOUS"
if 0 < b and b < 12:
  result = "MMYY"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Fixed submission:
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])
result = None

if 0 < a and a <= 12:
  result = "MMYY"
  if 0 < b and b <= 12:
    result = "AMBIGUOUS"
if 0 < b and b <= 12:
  result = "YYMM"
  if 0 < a and a <= 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Buggy python submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if 0 < a and a < 12:
  result = "YYMM"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if 0 < b and b < 12:
  result = "MMYY"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Fixed submission:
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])
result = None

if 0 < a and a <= 12:
  result = "MMYY"
  if 0 < b and b <= 12:
    result = "AMBIGUOUS"
if 0 < b and b <= 12:
  result = "YYMM"
  if 0 < a and a <= 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Buggy python submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if a == 0 or b == 0:
  result = "NA"

if 0 < a and a < 12:
  result = "YYMM"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if 0 < b and b < 12:
  result = "MMYY"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"

print(result)

Fixed submission:
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])
result = None

if 0 < a and a <= 12:
  result = "MMYY"
  if 0 < b and b <= 12:
    result = "AMBIGUOUS"
if 0 < b and b <= 12:
  result = "YYMM"
  if 0 < a and a <= 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = list(map(int, input().split()))
# minus minus
if b <= 0 and d <= 0:
    ans = a*c
# minus plus
if b <= 0 and c >= 0:
    ans = b*c
# plus minus
elif 0 <= a and d <= 0:
    ans = a*d
# plus plus
if a >= 0 and c >= 0:
    ans = b*d
print(ans)



Fixed submission:
a, b, c, d = list(map(int, input().split()))
# minus minus
if b <= 0 and d <= 0:
    print(a*c)
else:
    ans = max(a*c, a*d, b*c, b*d)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = tuple(map(lambda x: int(x)-1, input().split()))
C = tuple(map(int, input().split()))
from collections import deque
ans = -2*10**9
for idx, root in enumerate(P):
    scores = [C[root]]
    p = P[root]
    while True:
        scores.append(scores[-1] + C[p])
        p = P[p]
        if p == root:
            break

    sc = scores[-1]
    if sc <= 0:
        if k < len(scores):
            ans = max(ans, max(scores[:k]))
        else:
            ans = max(ans, max(scores))
    else:
        kk, r = divmod(k, len(scores))
        if r == 0:
            ans = max(ans, kk*sc, (kk-1)*sc + max(scores))
        else:
            ans = max(ans, kk*sc + max(scores[:r]))
print(ans)


Fixed submission:
n, k = map(int, input().split())
P = tuple(map(lambda x: int(x)-1, input().split()))
C = tuple(map(int, input().split()))
CC = [[] for _ in range(n)]
for idx, p in enumerate(P):
    CC[idx].append(C[p])
    pp = P[p]
    for _ in range(n):
        CC[idx].append(C[pp])
        pp = P[pp]
        if pp == p:
            break
        
from itertools import accumulate
ans = -2*(10**9)
for cc in CC:
    cca = list(accumulate(cc))
    if cca[-1] <= 0:
        # 1周分のうちの最大値
        if k < len(cc):
            ans = max(ans, max(cca[:k]))
        else:
            ans = max(ans, max(cca))
    else:
        # kk周したほうが良い
        kk, r = divmod(k, len(cc))
        if r == 0:
            ans = max(ans, kk*cca[-1], (kk-1)*cca[-1]+max(cca))
        else:
            ans = max(ans, kk*cca[-1] + max(cca[:r]))
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
P = tuple(map(lambda x: int(x)-1, input().split()))
C = tuple(map(int, input().split()))
CC = [[] for _ in range(n)]
p = P[0]

for idx, p in enumerate(P):
    CC[idx].append(C[p])
    pp = P[p]
    for i in range(n):
        if pp == p:
            break
        CC[idx].append(C[pp])
        pp = P[pp]
        

from itertools import accumulate
ans = -50**15
for cc in CC:
    cca = list(accumulate(cc))
    sc = sum(cc)
    if sc <= 0:
        # 1周分のmax
        ans = max(ans, max(cca))
    else:
        kk, r = divmod(k, len(cc))
        ans = max(ans, kk * sc + max(cca[:r]))
print(ans)

Fixed submission:
n, k = map(int, input().split())
P = tuple(map(lambda x: int(x)-1, input().split()))
C = tuple(map(int, input().split()))
CC = [[] for _ in range(n)]
for idx, p in enumerate(P):
    CC[idx].append(C[p])
    pp = P[p]
    for _ in range(n):
        CC[idx].append(C[pp])
        pp = P[pp]
        if pp == p:
            break
        
from itertools import accumulate
ans = -2*(10**9)
for cc in CC:
    cca = list(accumulate(cc))
    if cca[-1] <= 0:
        # 1周分のうちの最大値
        if k < len(cc):
            ans = max(ans, max(cca[:k]))
        else:
            ans = max(ans, max(cca))
    else:
        # kk周したほうが良い
        kk, r = divmod(k, len(cc))
        if r == 0:
            ans = max(ans, kk*cca[-1], (kk-1)*cca[-1]+max(cca))
        else:
            ans = max(ans, kk*cca[-1] + max(cca[:r]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
if k%2==0 or k%5==0:
    print('-1')
else:
    from itertools import accumulate
    ac = list(accumulate([7*pow(10, i, k)%k for i in range(999983)]))
    for idx, a in enumerate(ac):
        if a%k == 0:
            print(idx+1)
            break
    else:
        print('-1')

Fixed submission:
k = int(input())

if k%2==0 or k%5==0:
    print('-1')
else:
    from itertools import accumulate
    ac = list(accumulate([7*pow(10, i, k)%k for i in range(999983)]))
    for idx, a in enumerate(ac):
        if a%k == 0:
            print(idx+1)
            break
    else:
        print('-1')
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = tuple(map(int, input().split()))

pa = 1
for i in range(k):
    pa *= A[i]

for kk in range(k, n):
    ppa = pa*A[kk]//A[kk-k]
    if ppa > pa:
        print('Yes')
    else:
        print('No')
    pa = ppa



Fixed submission:
from decimal import Decimal
n, k = map(int, input().split())
A = tuple(map(int, input().split()))

pa = Decimal(1)
#for i in range(k):
#    pa *= A[i]

for kk in range(k, n):
    ppa = pa*A[kk]/A[kk-k]
    if ppa > pa:
        print('Yes')
    else:
        print('No')
    pa = ppa