Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [6,2,5,5,4,5,6,3,7,6] # B[i]がiを作るのに必要なマッチ棒の数

C = []
for a in A:
  C.append(B[a])
  
dp = [0] * (N+1)

dp[0] = 0
for i in range(1,len(dp)):
  for c in C:
    if i-c >= 0:
      dp[i] = max(dp[i-c] + 1, dp[i])

X = max(dp)
pos = N
ans = ""
#print(X)
for cnt in range(X):
  for i in range(9,0,-1):
    if i in A:
      if dp[pos] != dp[pos-B[i]] + 1:
        continue
      if cnt == X-1 and pos - B[i] != 0:
        continue
      pos = pos - B[i]
      ans = ans + str(i)
      break
      
print(ans)

Fixed submission:
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [6,2,5,5,4,5,6,3,7,6] # B[i]がiを作るのに必要なマッチ棒の数

# dp[i]: i本マッチ使って作れるMAX桁数。。
dp = [-1 for _ in range(N+10)]
dp[0] = 0
A.sort()
visited = [False for _ in range(N+10)]
h = []
heapq.heappush(h, (0,0))

while h:
  now_n, keta = heapq.heappop(h)
  if visited[now_n]:
    continue
  visited[now_n] = True
  for a in A:
    nxt_n = now_n + B[a]
    if nxt_n >= N + 10:
      continue
    dp[nxt_n] = max(dp[nxt_n], dp[now_n] + 1)
    heapq.heappush(h, (nxt_n, dp[now_n] + 1))
    
#print(dp)

A.sort(reverse=True)
# 上の桁から決めていく。dp[N]
ANS = []
zan = N
for i in range(dp[N],0,-1):
  bugf = True
  # sorted(a) 大きい方から試す
  for a in A:
    if dp[zan-B[a]] == dp[zan] - 1:
      ANS.append(str(a))
      zan = zan - B[a]
      bugf = False
      break
  if bugf:
    # Aが構成できない、と言うことなのでここは通らないはず
    print("bug...")
  
print("".join(ANS))
Buggy python submission (verdict: Runtime Error):
import heapq
N,K = map(int, input().split())

I = []
for _ in range(N):
  t,d = map(int, input().split())
  I.append((d,t))
  
I.sort(reverse=True)

# heap_can_delete
h_d = []
# heap_can_add
h_a = []

wk = 0
kind = 0
# 出現したことのあるネタ
ap = set()
for i in range(K):
  d,t = I[i]
  wk += d
  if t not in ap:
    ap.add(t)
    kind += 1
  else:
    heapq.heappush(h_d, (d,t))

for i in range(K,N):
  d,t = I[i]
  if t not in ap:
    ap.add(t)
    # maxをpopさせるために、価値を-1かけておく
    heapq.heappush(h_a, ((-1) * d, t))
  
ans = wk + kind ** 2
while len(h_d) > 0:
  d1,t1 = heapq.heappop(h_d)
  d2,t2 = heapq.heappop(h_a)
  d2 = (-1) * d2
  wk = wk - d1 + d2
  kind += 1
  ans = max(ans, wk + kind ** 2)
  
print(ans)
  
  

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

I = []
for _ in range(N):
  t,d = map(int, input().split())
  I.append((d,t))
  
I.sort(reverse=True)

# heap_can_delete
h_d = []
# heap_can_add
h_a = []

wk = 0
kind = 0
# 出現したことのあるネタ
ap = set()
for i in range(K):
  d,t = I[i]
  wk += d
  if t not in ap:
    ap.add(t)
    kind += 1
  else:
    heapq.heappush(h_d, (d,t))

for i in range(K,N):
  d,t = I[i]
  if t not in ap:
    ap.add(t)
    # maxをpopさせるために、価値を-1かけておく
    heapq.heappush(h_a, ((-1) * d, t))
  
ans = wk + kind ** 2
while len(h_d) > 0 and len(h_a) > 0:
  d1,t1 = heapq.heappop(h_d)
  d2,t2 = heapq.heappop(h_a)
  d2 = (-1) * d2
  wk = wk - d1 + d2
  kind += 1
  ans = max(ans, wk + kind ** 2)
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
S = []
for i in range(H):
  S.append(list(input()))

V = {}
for i in range(H):
  for j in range(W):
    V[str(i) + "_" + str(j)] = []
    
for i in range(H):
  for j in range(W):
    
    for dy,dx in [(-1,0), (1,0), (0,-1), (0,1)]:
      y,x = i+dy, j+dx
      if y < 0 or H <= y or x < 0 or W <= x:
        continue
      if S[i][j] == S[y][x]:
        continue
      V[str(i) + "_" + str(j)].append([y,x])
      
ans = 0
visited = [[False for i in range(W)] for j in range(H)]
willsearch = [[False for i in range(W)] for j in range(H)]
Q = deque()
#print(V)
def dfs(y,x):
  wc, bc = 0, 0
  Q.append([y,x])
  while len(Q) > 0:
    b,a = Q.pop()
    #print("pop;", b, a, Q)
    visited[b][a] = True
    if S[b][a] == '.':
      wc += 1
    else:
      bc += 1
    for q,p in V[str(b) + "_" + str(a)]:
      #print("yeah:", q,p)
      if visited[q][p] or willsearch[q][p]:
        continue
      Q.append([q,p])
      willsearch[q][p] = True
    #print(b,a,"|",Q)
  #print(y,x,wc,bc)
  return wc*bc

for i in range(H):
  for j in range(W):
    ans += dfs(i,j)
    
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
S = []
for i in range(H):
  S.append(list(input()))

V = {}
for i in range(H):
  for j in range(W):
    V[str(i) + "_" + str(j)] = []
    
for i in range(H):
  for j in range(W):
    
    for dy,dx in [(-1,0), (1,0), (0,-1), (0,1)]:
      y,x = i+dy, j+dx
      if y < 0 or H <= y or x < 0 or W <= x:
        continue
      if S[i][j] == S[y][x]:
        continue
      V[str(i) + "_" + str(j)].append([y,x])
      
ans = 0
visited = [[False for i in range(W)] for j in range(H)]
willsearch = [[False for i in range(W)] for j in range(H)]
Q = deque()
#print(V)
def dfs(y,x):
  wc, bc = 0, 0
  Q.append([y,x])
  while len(Q) > 0:
    b,a = Q.pop()
    #print("pop;", b, a, Q)
    visited[b][a] = True
    if S[b][a] == '.':
      wc += 1
    else:
      bc += 1
    for q,p in V[str(b) + "_" + str(a)]:
      #print("yeah:", q,p)
      if visited[q][p] or willsearch[q][p]:
        continue
      Q.append([q,p])
      willsearch[q][p] = True
    #print(b,a,"|",Q)
  #print(y,x,wc,bc)
  return wc*bc

for i in range(H):
  for j in range(W):
    ans += dfs(i,j)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A = list(map(int, input().split()))

P = [1e9]*N
P[0] = 0

for i in range(1,N):
  for j in range(1,min(K+1,i+1)):
    P[i] = min(P[i], abs(A[i]-A[i-j])+P[i-j])
  
print(P[N-1])


Fixed submission:
N,K = map(int, input().split())
A = list(map(int, input().split()))

P = [1e9]*N
P[0] = 0

for i in range(1,N):
  for j in range(1,min(K+1,i+1)):
    P[i] = min(P[i], abs(A[i]-A[i-j])+P[i-j])
  
print(P[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
ITEM = []
vmax, wmax = 0,0
for _ in range(N):
  w,v = map(int, input().split())
  ITEM.append((v,w))
  vmax = max(vmax,v)
  wmax = max(wmax,w)

INF = 10**18
    
def solve2():
  #dp[i][w] i個目までを選んで、重さW以下で実現できる最大の価値
  # TLEしたらiを消す。
  dp = [0] * (wmax*N+1)
  dp[0] = 0
  for i in range(1,N+1):
    v1,w1 = ITEM[i-1]
    # dp[i]消すなら、wは大きい方から探索する
    for w in range(wmax*i,-1,-1):
      if w-w1>=0:
        dp[w] = max(dp[w], dp[w-w1]+v1)
  ret = max(dp[:W+1])
  
  #for d in dp:
    #print(dp[0:20])
  return ret

ans = solve2()
  
print(ans)

Fixed submission:
N, W = map(int, input().split())
ITEM = []
vmax, wmax = 0,0
for _ in range(N):
  w,v = map(int, input().split())
  ITEM.append((v,w))
  vmax = max(vmax,v)
  wmax = max(wmax,w)

INF = 10**18
    
def solve2():
  #dp[i][w] i個目までを選んで、重さW以下で実現できる最大の価値
  # TLEしたらiを消す。
  dp = [0] * (wmax*N+1)
  dp[0] = 0
  for i in range(1,N+1):
    v1,w1 = ITEM[i-1]
    # dp[i]消すなら、wは大きい方から探索する
    for w in range(wmax*i,-1,-1):
      if w-w1>=0:
        dp[w] = max(dp[w], dp[w-w1]+v1)
  ret = max(dp[:W+1])
  
  #for d in dp:
    #print(dp[0:20])
  return ret

ans = solve2()
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())

if N == 1:
  print(P)
  exit(0)
  
ans = 1
i = 2
while i ** N <= P:
  if P % i**N == 0:
    ans *= i
    P = P // i**N
    continue
  i += 1
  
print(ans)

Fixed submission:
from math import floor
N, P = map(int, input().split())

if N == 1:
  print(P)
  exit(0)
  
ans = 1
#i = floor(pow(P,1/N))
#print(i)
i = 2

def prime_table(n):
  list = [True for _ in range(n + 1)]
  i = 2
  while i * i <= n:
    if list[i]:
      j = i + i
      while j <= n:
        list[j] = False
        j += i
    i += 1

  table = [i for i in range(n + 1) if list[i] and i >= 2]
  return table

T = prime_table(floor(pow(P,1/N)))

for i in range(len(T)):
  if T[i] ** N > P:
    break
  while P % T[i]**N == 0:
    ans *= T[i]
    P = P // T[i]**N
  
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
S = sum(A,B,C)
print(max(S+9*A, S+9*B, S+9*C))

Fixed submission:
A, B, C = map(int, input().split())
S = A+B+C
print(max(S+9*A, S+9*B, S+9*C))
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N % 2 == 0:
  print((N // 2) ** 2)
else:
  print((N // 2) * (N // 2 + 1)


Fixed submission:
N = int(input())

if N % 2 == 0:
  print((N // 2) ** 2)
else:
  print((N // 2) * (N // 2 + 1))
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

print((A-1)*(B-1))

Fixed submission:
A,B = map(int, input().split())

print((A-1)*(B-1))
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split() )

N_LR = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l, r = map(int, input().split() )
  N_LR[l][r] += 1

S_LR = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
  for j in range(1,N+1):
    S_LR[i][j] = S_LR[i-1][j] + N_LR[i][j]

for i in range(Q):
  x,y = map(int, input().split() )
  ans = 0
  for j in range(x, y+1):
    ans += S_LR[y][j] - S_LR[x-1][j]  
  print(ans)

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

N_LR = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l, r = map(int, input().split() )
  N_LR[l][r] += 1

#S_LR = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
  for j in range(1,N+1):
    N_LR[i][j] += N_LR[i-1][j] + N_LR[i][j-1] - N_LR[i-1][j-1]

for i in range(Q):
  x,y = map(int, input().split() )
  ans = N_LR[y][y] - N_LR[x-1][y] - N_LR[y][x-1] + N_LR[x-1][x-1]
  print(ans)
Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())

if A <= 8 and B <= 8:
    print("Yay!")
else:
    print(":(")

Fixed submission:
A,B = map(int,input().split())	

if A <= 8 and B <= 8:
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))

ans = 0
for i in range(n):
  j = 0
  sum = 0
  xorsum = 0
  while i + j < n:
    sum = sum + li[i+j]
    xorsum = xorsum ^ li[i+j]
    if sum == xorsum:
      ans = ans + 1
    else:
      break
    j = j + 1

print(ans)

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

ans = 0
w_xor,w_sum = A[0],A[0]
l,r = 0,0

while l < N and r < N:
  #print(l,r,w_xor, w_sum)

  if w_xor == w_sum:
    if r < N-1:
    #print(l,r)
      r += 1
      w_xor = w_xor ^ A[r]
      w_sum = w_sum + A[r]
      continue
    else:
      ans += 1+r-l
  else:
    # l,r-1、までがマッチしてたということなので1小さい
    ans += r-l
  w_xor = w_xor ^ A[l] 
  w_sum = w_sum - A[l]
  l += 1
  
print(ans)

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

ans = 0
for i in range(n):
  j = 0
  sum = 0
  xorsum = 0
  while i + j < n:
    sum = sum + li[i+j]
    xorsum = xorsum ^ li[i+j]
    if sum == xorsum:
      ans = ans + 1
    j = j + 1

print(ans)

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

ans = 0
w_xor,w_sum = A[0],A[0]
l,r = 0,0

while l < N and r < N:
  #print(l,r,w_xor, w_sum)

  if w_xor == w_sum:
    if r < N-1:
    #print(l,r)
      r += 1
      w_xor = w_xor ^ A[r]
      w_sum = w_sum + A[r]
      continue
    else:
      ans += 1+r-l
  else:
    # l,r-1、までがマッチしてたということなので1小さい
    ans += r-l
  w_xor = w_xor ^ A[l] 
  w_sum = w_sum - A[l]
  l += 1
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
P = list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
uf = UnionFind(N)
for _ in range(M):
  x,y = map(int, input().split())
  uf.union(x-1,y-1)
  
ans = 0
for lis in uf.all_group_members().values():
  s = set(lis)
  for a in s:
    if P[a]-1 in s:
      ans += 1
      
print(ans)

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
uf = UnionFind(N+1)
for _ in range(M):
  x,y = map(int, input().split())
  uf.union(x,y)
  
ans = 0
for i in range(N):
  if uf.same(i+1, P[i]):
    ans += 1
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 整数の入力
import sys
n = int(input())
li = list(map(int, input().split()))

count = 0
table = {}

for i in range(len(li)) :
  sum = 0
  if i in table.keys() :
    count += table[i]
    continue

  match_i = list()

  for j in range(len(li)-i) :
    sum = sum + li[i+j]
    if sum == 0:
      count = count + 1
      for k in match_i:
        table[k] = table[k] + 1
      table[i+j+1] = 0
      match_i.append(i+j+1)

print(count)
#print(table)

Fixed submission:
def tri(n):
  return n * (n+1) // 2

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

SA = [0] * (N+1)
for i in range(N):
  SA[i+1] = SA[i] + A[i]
  
SA.sort()

ans = 0
cnt = 0

for i in range(N+1):
  if i == 0:
    now = SA[i]
    continue
  
  if now == SA[i]:
    cnt += 1
    continue
  elif cnt > 0:
    ans += tri(cnt)
    cnt = 0
  else:
    pass
  now = SA[i]

if cnt > 0:
    ans += tri(cnt)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 整数の入力
import sys
n = int(input())
li = list(map(int, input().split()))

count = 0

for i in range(len(li)) :
  for j in range(len(li)) :
    if sum(li[i:i+j+1]) == 0:
      count = count + 1
    if i + j >= len(li) - 1:
      break

print(count)


Fixed submission:
def tri(n):
  return n * (n+1) // 2

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

SA = [0] * (N+1)
for i in range(N):
  SA[i+1] = SA[i] + A[i]
  
SA.sort()

ans = 0
cnt = 0

for i in range(N+1):
  if i == 0:
    now = SA[i]
    continue
  
  if now == SA[i]:
    cnt += 1
    continue
  elif cnt > 0:
    ans += tri(cnt)
    cnt = 0
  else:
    pass
  now = SA[i]

if cnt > 0:
    ans += tri(cnt)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 整数の入力
import sys
n = int(input())
li = list(map(int, input().split()))

count = 0

for i in range(len(li)) :
  sum = 0
  for j in range(len(li)) :
    sum = sum + li[i+j]
    if sum == 0:
      count = count + 1
    if i + j >= len(li) - 1:
      break

print(count)


Fixed submission:
def tri(n):
  return n * (n+1) // 2

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

SA = [0] * (N+1)
for i in range(N):
  SA[i+1] = SA[i] + A[i]
  
SA.sort()

ans = 0
cnt = 0

for i in range(N+1):
  if i == 0:
    now = SA[i]
    continue
  
  if now == SA[i]:
    cnt += 1
    continue
  elif cnt > 0:
    ans += tri(cnt)
    cnt = 0
  else:
    pass
  now = SA[i]

if cnt > 0:
    ans += tri(cnt)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.readline

def chr2ord(c):
  return ord(c) - ord('a')

N = int(input())
S = []
for i in range(N):
  wk = list(input())
  S.append(wk)

ANS = 0
# A=0として、0<=B<Nをためす。
# こたえはN倍。
for b in range(N):
  cnt = 0
  B = [['X' for _ in range(N)] for _ in range(N)]
  for i in range(N):
    for j in range(N):
      B[i][j] = S[i][(j+b)%N]
  #print(B)
  for i in range(N):
    for j in range(N):
      if B[i][j] == B[j][i]:
        cnt += 1
  
  if cnt == N*N:
    ANS += N
print(ANS)

Fixed submission:
#import sys
#input = sys.stdin.readline

def chr2ord(c):
  return ord(c) - ord('a')

N = int(input())
S = []
for i in range(N):
  wk = list(input())
  S.append(wk)

ANS = 0
# A=0として、0<=B<Nをためす。
# こたえはN倍。
for b in range(N):
  cnt = 0
  B = [['X' for _ in range(N)] for _ in range(N)]
  for i in range(N):
    for j in range(N):
      B[i][j] = S[i][(j+b)%N]
  #print(B)
  for i in range(N):
    for j in range(N):
      if B[i][j] == B[j][i]:
        cnt += 1
  
  if cnt == N*N:
    ANS += N
print(ANS)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
# 文字列の入力
if a+b>=c:
  print "Yes"
else:
  print "No"

Fixed submission:
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
# 文字列の入力
if a+b>=c:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
Arr = list(map(int, input().split()))

Arr.sort(reverse=True)

i = 0
ans = 0
for a in arr:
  if i%2 == 0:
    ans += a
  else:
    ans -= a

print(ans)

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

Arr.sort(reverse=True)

i = 0
ans = 0
for a in Arr:
  if i%2 == 0:
    ans += a
  else:
    ans -= a
  i += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
sys.setrecursionlimit(300000)

N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  l,r,d = map(int, input().split())
  l,r = l-1,r-1
  E[l].append((r,d))
  E[r].append((l,-d)) 
  
#for e in E:
#  print(e)
  
# dfs
visited = [False] * N

INF = 10**16
A = [ INF ] * N

def dfs(now, prev, num):
  visited[now] = True
  if A[now] == INF:
    A[now] = num
  else:
    pass
  for nxt, dis in E[now]:
    if nxt == prev:
      continue
    if A[nxt] < INF and A[nxt] != num + dis:
      # ある点において2通りのnum設定の仕方がある
      print("No")
      exit(0)
    if visited[nxt]:
      continue
    dfs(nxt, now, num + dis)
  return 

for i in range(N):
  if visited[i]:
    continue
  dfs(i,-1,0)
  
print("Yes")

Fixed submission:
from collections import deque
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  l,r,d = map(int, input().split())
  l,r = l-1,r-1
  E[l].append((r,d))
  E[r].append((l,-d)) 
  
#for e in E:
#  print(e)
  
# bfs
Q = deque()
visited = [False] * N
willSearch = [False] * N
INF = 10**16
A = [ INF ] * N

for i in range(N):
  if visited[i]:
    continue
  Q.append((i,-1,0))
  while Q:
    now, prev, num = Q.popleft()
    visited[now] = True
    if A[now] == INF:
      A[now] = num
    elif A[now] != num:
      # ある点において2通りのnum設定の仕方がある
      #print(now,prev,num,A[inxt])
      print("No")
      exit(0)
    for nxt, dis in E[now]:
      if nxt == prev:
        continue
      if A[nxt] < INF and A[nxt] != num + dis:
        # ある点において2通りのnum設定の仕方がある
        #print(now,prev,num, nxt,dis, A[nxt])
        print("No")
        exit(0)
      if visited[nxt] or willSearch[nxt]:
        continue
      Q.append((nxt, now, num + dis))
      willSearch[nxt] = True
    
print("Yes")
Buggy python submission (verdict: Runtime Error):
S = input()

S[3] = '8'
print(S)

Fixed submission:
S = input()
 
print(S[0:3] + '8' + S[4:])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  h,p = list(map(int, input().split()))
  A.append([h+p,h,p])
  
A.sort()

# N人積んだ時の最小の高さH
dp = [-1 for i in range(N+1)]
dp[0] = 0

for i in range(N):
  _,h,p = A[i]
  for j in range(N, 0, -1):
    ## まだj-1人積んだことがない
    if dp[j-1] < 0:
      continue
    ## 高すぎてつめない
    if dp[j-1] > h:
      continue
    if dp[j] < 0:
      dp[j] = dp[j-1] + p
    else:
      dp[j] = min(dp[j], dp[j-1] + p)
    
for i in range(N+1):
  if dp[i] < 0:
    print(i-1)
    exit(0)

print(N)


Fixed submission:
N = int(input())
A = []
for i in range(N):
  h,p = list(map(int, input().split()))
  A.append([h+p,h,p])
  
A.sort()

# N人積んだ時の最小の高さH
dp = [-1 for i in range(N+1)]
dp[0] = 0

for i in range(N):
  _,h,p = A[i]
  for j in range(N, 0, -1):
    ## まだj-1人積んだことがない
    if dp[j-1] < 0:
      continue
    ## 高すぎてつめない
    if dp[j-1] > h:
      continue
    if dp[j] < 0:
      dp[j] = dp[j-1] + p
    else:
      dp[j] = min(dp[j], dp[j-1] + p)
    
for i in range(N+1):
  if dp[i] < 0:
    print(i-1)
    exit(0)

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

if a < b:
  print("<")
elif a > b:
  print(">")
else:
  print("=")

Fixed submission:
a, b = input().split()

if a < b:
  print("<")
elif a > b:
  print(">")
else:
  print("=")
Buggy python submission (verdict: Runtime Error):
from math import floor, sqrt

print(floor(sqrt(int(input())) ** 2)

Fixed submission:
from math import floor, sqrt

print(floor(sqrt(int(input()))) ** 2)
Buggy python submission (verdict: Time Limit Exceeded):
"""
ABC076_D AtCoderExpress
まず区間に注目してEditorialみたいなグラフを思い描くことがきつかった。
そのうえで、区間Limitをバグなく実装するのが結構ポイント。
あとはVVあたりがバグってないかをPrintしながら見ていく形。
"""
N = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))
TMAX = sum(T)

TS = [0] * (N+1)
for i in range(N):
  TS[i+1] = TS[i] + T[i]
T_Left = TS[:N]
T_Right = TS[1:]
#print(T_Left,T_Right,V)

## これで下記がちゃんとつくれた。
# Tleft[i] <= t <= Tright[i] の間、 V[i]以下でなければいけない

# VV[tt] tt/2秒時の速度。両端がゼロ、という条件から初期値を生成する。
VV = [min(i*0.5, (TMAX*2-i) * 0.5) for i in range(TMAX*2+1)]
#print(VV)

# 区間iについて
for i in range(N):
  for tt in range(TMAX*2+1):
    VV[tt] = min(VV[tt], V[i] + max(0, (T_Left[i]*2 - tt) * 0.5, (tt-T_Right[i]*2) * 0.5))
#print(VV)
# 面積は両端がゼロであることから、速度合計を２で割る（0.5秒ごとだから）で出る。
# v-tグラフの面積を台形の面積で考えればよい。
print(sum(VV)/2)

Fixed submission:
"""
ABC076_D AtCoderExpress
まず区間に注目してEditorialみたいなグラフを思い描くことがきつかった。
そのうえで、区間Limitをバグなく実装するのが結構ポイント。
あとはVVあたりがバグってないかをPrintしながら見ていく形。
"""
N = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))
TMAX = sum(T)

TS = [0] * (N+1)
for i in range(N):
  TS[i+1] = TS[i] + T[i]
T_Left = TS[:N]
T_Right = TS[1:]
#print(T_Left,T_Right,V)

## これで下記がちゃんとつくれた。
# Tleft[i] <= t <= Tright[i] の間、 V[i]以下でなければいけない

# VV[tt] tt/2秒時の速度。両端がゼロ、という条件から初期値を生成する。
VV = [min(i*0.5, (TMAX*2-i) * 0.5) for i in range(TMAX*2+1)]
#print(VV)

# 区間iについて
for i in range(N):
  for tt in range(TMAX*2+1):
    VV[tt] = min(VV[tt], V[i] + max(0, (T_Left[i]*2 - tt) * 0.5, (tt-T_Right[i]*2) * 0.5))
#print(VV)
# 面積は両端がゼロであることから、速度合計を２で割る（0.5秒ごとだから）で出る。
# v-tグラフの面積を台形の面積で考えればよい。
print(sum(VV)/2)