Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
dp = [-1]*(N+100010)
dp[0] = 0
dp[1] = abs(A[1] - A[0])


def rec(i):
  if dp[i] != -1:
    return dp[i]
  dp[i] = min(rec(i-1) + abs(A[i-1] - A[i]), rec(i-2) + abs(A[i-2] - A[i]))
  return dp[i]

print(rec(N-1))


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

def solve():
  dp = [0]*N
  dp[1] = abs(A[1] - A[0])
  for i in range(2,N):
    dp[i] = min((dp[i-1] + abs(A[i] - A[i-1])), (dp[i-2] + abs(A[i] - A[i-2])))
  return dp

dp = solve()
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
dp = [-1]*(N+2)
dp[0] = 0
dp[1] = abs(A[1] - A[0])


def rec(i):
  if dp[i] != -1:
    return dp[i]
  dp[i] = min(rec(i-1) + abs(A[i-1] - A[i]), rec(i-2) + abs(A[i-2] - A[i]))
  return dp[i]

print(rec(N-1))

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

def solve():
  dp = [0]*N
  dp[1] = abs(A[1] - A[0])
  for i in range(2,N):
    dp[i] = min((dp[i-1] + abs(A[i] - A[i-1])), (dp[i-2] + abs(A[i] - A[i-2])))
  return dp

dp = solve()
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
dp = [-1]*N
dp[0] = 0
dp[1] = abs(A[1] - A[0])


def rec(i):
  if dp[i] != -1:
    return dp[i]
  dp[i] = min(rec(i-1) + abs(A[i-1] - A[i]), rec(i-2) + abs(A[i-2] - A[i]))
  return dp[i]

print(rec(N-1))

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

def solve():
  dp = [0]*N
  dp[1] = abs(A[1] - A[0])
  for i in range(2,N):
    dp[i] = min((dp[i-1] + abs(A[i] - A[i-1])), (dp[i-2] + abs(A[i] - A[i-2])))
  return dp

dp = solve()
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(200000)

from heapq import *
f_inf = float('inf')

def dijkstra(start,node,edge):
    #始点sから各頂点への距離
    #node:頂点数
    #d:各頂点へのコスト(存在しないときはinf)
    d = [0] * node
    d[start] = 0
    #q:キュー(スタートからのコスト,頂点)
    #スタートをキューに入れる
    q = [(0,start)]
    while(len(q) != 0):
    #キューの先頭を取得
      ci, i = heappop(q)
    #キューの先頭から繋がっている頂点を探索
      for j in edge[i]:
        nc = ci + 1
        d[j] = nc
        heappush(q, (nc, j))
    return max(d)
#入力
N,M = (int(x) for x in input().split())
#エッジ
E = [[] for _ in [0]*N]

for i in range(M):
  a,b = (int(x) for x in input().split())
  E[a-1].append(b-1)

ans = 0
for i in range(N):
  ans = max(ans, dijkstra(i,N,E))


#出力
print(ans)


Fixed submission:
import sys
from heapq import *
sys.setrecursionlimit(200000)

def rec(i):
  if dp[i] != 0:
    return dp[i]
  res = 0
  for j in E[i]:
    res = max(rec(j) + 1, res)
  dp[i] = res
  return dp[i]


#入力
N,M = (int(x) for x in input().split())
#エッジ
E = [[] for _ in [0]*N]
dp = [0]*N

for i in range(M):
  a,b = (int(x) for x in input().split())
  E[a-1].append(b-1)

ans = 0
for i in range(N):
  ans = max(ans, rec(i))

#出力
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
f_inf = float('inf')

def dijkstra(start,node,edge):
    #始点sから各頂点への距離
    #node:頂点数
    #d:各頂点へのコスト(存在しないときはinf)
    d = [0] * node
    d[start] = 0
    #q:キュー(スタートからのコスト,頂点)
    #スタートをキューに入れる
    q = [(0,start)]
    while(len(q) != 0):
    #キューの先頭を取得
      ci, i = heappop(q)
    #キューの先頭から繋がっている頂点を探索
      for j in edge[i]:
        nc = ci + 1
        d[j] = nc
        heappush(q, (nc, j))
    return max(d)
#入力
N,M = (int(x) for x in input().split())
#エッジ
E = [[] for _ in [0]*N]

for i in range(M):
  a,b = (int(x) for x in input().split())
  E[a-1].append(b-1)

ans = 0
for i in range(N):
  ans = max(ans, dijkstra(i,N,E))


#出力
print(ans)

Fixed submission:
import sys
from heapq import *
sys.setrecursionlimit(200000)

def rec(i):
  if dp[i] != 0:
    return dp[i]
  res = 0
  for j in E[i]:
    res = max(rec(j) + 1, res)
  dp[i] = res
  return dp[i]


#入力
N,M = (int(x) for x in input().split())
#エッジ
E = [[] for _ in [0]*N]
dp = [0]*N

for i in range(M):
  a,b = (int(x) for x in input().split())
  E[a-1].append(b-1)

ans = 0
for i in range(N):
  ans = max(ans, rec(i))

#出力
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = (int(x) for x in input().split())
ans = []
i = 1

while(m//i >= n):
  if(m%i == 0):
    ans.append(i)
  i += 1
  
print(ans[-1])

Fixed submission:
import heapq
n,m = (int(x) for x in input().split())
a1 = []
a2 = []
for i in range(1, int(m**0.5)+1):
  if(m%i == 0):
    a1.append(i)
    a2.append(m//i)
    
a1.extend(a2[::-1])
i = 0

while(i <= len(a1)):
  if(a1[i] >= n):
    print(m//a1[i])
    break
  i += 1
Buggy python submission (verdict: Time Limit Exceeded):
n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))
sum = [0]*(n+1)

for i in range(1,n+1):
  sum[i] = sum[i-1] + a[i-1]

cnt = 0
for i in range(n):
  for j in range(i+1, n+1):
    if((sum[j] - sum[i])%m == 0):
      cnt += 1
      
print(cnt)
    
    

Fixed submission:
from collections import Counter
n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))
s = [0]*(n+1)
for i in range(1,n+1):
  s[i] = (s[i-1] + a[i-1])%m

cl = Counter(s).values()
ans = sum(i*(i-1)//2 for i in cl)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
size = len(S)
mod = 10**9+7

dp = [[0]*4 for _ in range(size + 10)]
dp[0][0] = 1

for i in range(size):
  cn = dp[i][0]
  a = dp[i][1]
  b = dp[i][2]
  c = dp[i][3]
  if(S[i] == 'A'):
    dp[i+1][0] += cn
    dp[i+1][1] += (a+cn)
    dp[i+1][2] += b
    dp[i+1][3] += c
  elif(S[i] == 'B'):
    dp[i+1][0] += cn
    dp[i+1][1] += a
    dp[i+1][2] += (b+a)
    dp[i+1][3] += c
  elif(S[i] == 'C'):
    dp[i+1][0] += cn
    dp[i+1][1] += a
    dp[i+1][2] += b
    dp[i+1][3] += (c+b)
  else:
    dp[i+1][0] += (3*cn)
    dp[i+1][1] += (3*a+cn)
    dp[i+1][2] += (3*b+a)
    dp[i+1][3] += (3*c+b)
  #for j in range(3):
    #dp[i+1][j] = (dp[i+1][j])

print(dp[size][3]%mod)

    
    

Fixed submission:
S = input()
size = len(S)
mod = 10**9+7

dp = [[0]*4 for _ in range(size + 10)]
dp[0][0] = 1

for i in range(size):
  cn = dp[i][0]%mod
  a = dp[i][1]%mod
  b = dp[i][2]%mod
  c = dp[i][3]%mod
  if(S[i] == 'A'):
    dp[i+1][0] += cn
    dp[i+1][1] += (a+cn)
    dp[i+1][2] += b
    dp[i+1][3] += c
  elif(S[i] == 'B'):
    dp[i+1][0] += cn
    dp[i+1][1] += a
    dp[i+1][2] += (b+a)
    dp[i+1][3] += c
  elif(S[i] == 'C'):
    dp[i+1][0] += cn
    dp[i+1][1] += a
    dp[i+1][2] += b
    dp[i+1][3] += (c+b)
  else:
    dp[i+1][0] += (3*cn)
    dp[i+1][1] += (3*a+cn)
    dp[i+1][2] += (3*b+a)
    dp[i+1][3] += (3*c+b)

print(dp[size][3]%mod)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          self.par[x] = self.find(self.par[x])
          return self.par[i]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

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

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)



Fixed submission:
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          self.par[i] = self.root(self.par[i])
          return self.par[i]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

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

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          return self.root(self.par[i])

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

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

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)



Fixed submission:
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          self.par[i] = self.root(self.par[i])
          return self.par[i]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

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

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

import math

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

mul_c = b // c - int(math.ceil((a - 1) / c)) + 1
mul_d = b // d - int(math.ceil((a - 1) / d)) + 1

gcd_c_d = gcd(c, d)
lcm_c_d = gcd_c_d * (c / gcd_c_d) * (d / gcd_c_d)
mul_c_d = b // lcm_c_d - int(math.ceil((a - 1)) / lcm_c_d)) + 1

print(b - a + 1 - (mul_c + mul_d - mul_c_d))


Fixed submission:
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

import math

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

mul_c = b // c - (a - 1) // c
mul_d = b // d - (a - 1) // d

gcd_c_d = gcd(c, d)
lcm_c_d = gcd_c_d * (c // gcd_c_d) * (d // gcd_c_d)
mul_c_d = b // lcm_c_d - (a - 1) // lcm_c_d

print(b - a + 1 - (mul_c + mul_d - mul_c_d))
Buggy python submission (verdict: Runtime Error):
b = int(input())
print("A" if b == "T" else "T" if b == "A" else "C" if b == "G" else "G")

Fixed submission:
b = input()
print("A" if b == "T" else "T" if b == "A" else "C" if b == "G" else "G")
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = map(int, input().split())
print("Yes" if max(l) > sum(l) - max(l) else "No")

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

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [int(input()) for _ in range(n)]
print("Yes" if max(l) > sum(l) - max(l) else "No")

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
print("Yes" if max(l) < sum(l) - max(l) else "No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = [int(input()) for _ in range(n)]
print(p.sum() - max(p) // 2)

Fixed submission:
n = int(input())
p = [int(input()) for _ in range(n)]
print(sum(p) - max(p) // 2)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input())
print("Yes" if abs(c - a) <= d or (abs(c - b) <= d and abs(a - b) <= d) else "No")

Fixed submission:
a, b, c, d = map(int, input().split())
print("Yes" if abs(c - a) <= d or (abs(c - b) <= d and abs(a - b) <= d) else "No")
Buggy python submission (verdict: Runtime Error):
c = [input().split() for i in range(3)]
print(c[0][0] + c[1][1] + c[2][2])

Fixed submission:
c = [input() for i in range(3)]
print(c[0][0] + c[1][1] + c[2][2])
Buggy python submission (verdict: Runtime Error):
import sys

s = sorted(input())
t = sorted(input())[::-1]
for i in range(len(s)):
    if s[i] < t[i]:
        print("Yes")
        sys.exit()
    elif s[i] > t[i]:
        print("No")
        sys.exit()
if len(t) > len(s):
    print("Yes")
else:
    print("No")

Fixed submission:
import sys

s = sorted(input())
t = sorted(input())[::-1]
print("Yes" if s < t else "No")
Buggy python submission (verdict: Runtime Error):
x = input()
fx = sum(map(int, input()))
print("Yes" if int(x) % fx == 0 else "No")

Fixed submission:
x = input()
fx = sum(map(int, x))
print("Yes" if int(x) % fx == 0 else "No")
Buggy python submission (verdict: Runtime Error):
c = [input() for i in range(2)]
print("YES" if c[0] == c[1][::-1]) else "NO")

Fixed submission:
c = [input() for i in range(2)]
print("YES" if c[0] == c[1][::-1] else "NO")
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input())
print(max(a*b, c*d))

Fixed submission:
a, b, c, d = map(int, input().split())
print(max(a*b, c*d))
Buggy python submission (verdict: Runtime Error):
c = int(input())
if c in 'aiueo':
    print('vowel')
else:
    print('consonant')

Fixed submission:
c = input()
if c in 'aiueo':
    print('vowel')
else:
    print('consonant')
Buggy python submission (verdict: Runtime Error):
l = sorted(list(map, input().split()))
print("Yes" if l[0] + l[1] == l[2] else "No")

Fixed submission:
l = sorted(map(int, input().split()))
print("Yes" if l[0] + l[1] == l[2] else "No")
Buggy python submission (verdict: Runtime Error):
lst = map(int, input().split())
print("YES" if lst.count(5) == 2 and lst.count(7) == 1 else "NO")

Fixed submission:
lst = list(map(int, input().split()))
print("YES" if lst.count(5) == 2 and lst.count(7) == 1 else "NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(sum(list(range(N))[1:]))


Fixed submission:
N = int(input())
print((N-1)*(N)//2)
Buggy python submission (verdict: Runtime Error):
l = map(int, raw_input().split())
A, B, X = l[0], l[1], l[2]

if A <= X and A + B >= X:
    print('YES')
else:
    print('NO')

Fixed submission:
l = list(map(int, input().split()))
A, B, X = l[0], l[1], l[2]

if A <= X and A + B >= X:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
X = list(map(int, input().split()))

for i in range(N):
    print(int(np.median(X[:i]+X[i+1:])))

Fixed submission:
import numpy as np
N = int(input())
X = list(map(int, input().split()))

X_sort = sorted(X)
small, big = X_sort[N//2-1], X_sort[N//2]

for x in X:
    if x >= big:
        print(small)
    else:
        print(big)
Buggy python submission (verdict: Runtime Error):
n,m=map(int, input().split())
a=list(map(int, input().split()))

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a)
for _ in range(m):
    heappush(hq, -(heappop(hq)*(-1))//(-2))
print(-sum(hq))

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

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a_val)
for _ in range(m):
    heappush(hq, -(heappop(hq)//(-2)))
print(-sum(hq))

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

for _ in range(m):
    a[a.index(max(a))] //=2
print(sum(a))

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

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a_val)
for _ in range(m):
    heappush(hq, -(heappop(hq)//(-2)))
print(-sum(hq))

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

while(m>0):
    a[a.index(max(a))] //=2
    m-=1
print(sum(a))

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

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a_val)
for _ in range(m):
    heappush(hq, -(heappop(hq)//(-2)))
print(-sum(hq))

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

while(m>0):
    max_index=a.index(max(a))
    a[max_index] = a[max_index]//2
    m-=1
print(sum(a))

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

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a_val)
for _ in range(m):
    heappush(hq, -(heappop(hq)//(-2)))
print(-sum(hq))

Buggy python submission (verdict: Runtime Error):
n,m=map(int, input().split())
a=list(map(int, input().split()), reverse=True)

while(m>0):
    max_index=a.index(max(a))
    a[max_index] = a[max_index]//2
    m-=1
print(sum(a))

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

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a_val)
for _ in range(m):
    heappush(hq, -(heappop(hq)//(-2)))
print(-sum(hq))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
a=sorted(map(int, input().split()), reverse=True)

while(m>0):
    a[0]=a[0]//2
    m-=1
    a=sorted(a,reverse=True)
print(sum(a))

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

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a_val)
for _ in range(m):
    heappush(hq, -(heappop(hq)//(-2)))
print(-sum(hq))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s_list=[]
for i in range(N):
    s_list.append(sorted(list(input())))
set_list=list(map(list, set(map(tuple, s_list))))

import math

count=0
for element in set_list:
    many = s_list.count(element)
    if many>1:
        count+=math.factorial(many) // (math.factorial(many - 2) * math.factorial(2))

print(count)

Fixed submission:
N = int(input())
s_list=[]
s_dict={}
count=0

for i in range(N):
    s = "".join(sorted(input()))
    if s not in s_dict:
        s_dict[s]=0
    else:
        s_dict[s]+=1
        count+=s_dict[s]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# 実行時間超過

N = int(input())
s_list=[]

for i in range(N):
    s_list.append(sorted(list(input())))

count=0
for i in range(N):
    for j in range(i+1,N):
        if s_list[i]==s_list[j]:
            count+=1
print(count)

Fixed submission:
N = int(input())
s_list=[]
s_dict={}
count=0

for i in range(N):
    s = "".join(sorted(input()))
    if s not in s_dict:
        s_dict[s]=0
    else:
        s_dict[s]+=1
        count+=s_dict[s]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s_list=[]

for _ in range(N):
    s_list.append(input())
    
count=0
for i in range(N):
    for j in range(i+1,N):
        s1=list(s_list[i])
        s2=list(s_list[j])
        if sorted(s1)==sorted(s2):
            count+=1
print(count)

Fixed submission:
N = int(input())
s_list=[]
s_dict={}
count=0

for i in range(N):
    s = "".join(sorted(input()))
    if s not in s_dict:
        s_dict[s]=0
    else:
        s_dict[s]+=1
        count+=s_dict[s]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s_list=[]

for _ in range(N):
    s_list.append(input())
    
count=0
for i in range(N):
    for j in range(i+1,N):
        s1=[]
        s2=[]
        for k in range(10):
            s1.append(s_list[i][k])
            s2.append(s_list[j][k])
        if sorted(s1)==sorted(s2):
            count+=1
print(count)

Fixed submission:
N = int(input())
s_list=[]
s_dict={}
count=0

for i in range(N):
    s = "".join(sorted(input()))
    if s not in s_dict:
        s_dict[s]=0
    else:
        s_dict[s]+=1
        count+=s_dict[s]
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
n = list(map(int, input().split()))

for i in range(N)[::-1]:
    for j in range(i)[::-1]:
        if n[i]-n[j]<-1:
            print("No")
            exit()
print("Yes")

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
f=1
h[0]-=1
for i in range(1,n):
    if h[i]-h[i-1]>=1:h[i]+=-1
    elif h[i]-h[i-1]==0:h[i]+=0
    else:
        f=0
        print("No")
        break
if f==1:print("Yes")

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

for i in range(N)[::-1]:
    value = n[i]
    for k in range(i):
        if n[k]-n[i] >1:
            print("No")
            exit()
print("Yes")

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
f=1
h[0]-=1
for i in range(1,n):
    if h[i]-h[i-1]>=1:h[i]+=-1
    elif h[i]-h[i-1]==0:h[i]+=0
    else:
        f=0
        print("No")
        break
if f==1:print("Yes")

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

n_sorted = sorted(n)

for i in range(N)[::-1]:
    value = n_sorted[i]
    j = n.index(value)
    for k in range(j+1, N):
        if n[k]-value< -1:
            print("No")
            exit()
print("Yes")

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
f=1
h[0]-=1
for i in range(1,n):
    if h[i]-h[i-1]>=1:h[i]+=-1
    elif h[i]-h[i-1]==0:h[i]+=0
    else:
        f=0
        print("No")
        break
if f==1:print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
num = input()
for _ in range(N+1):
    n = list(map(int, num.split()))

for i in range(N):
    for j in range(i, N):
        if n[i]-n[j]>1:
            print("No")
            exit()
print("Yes")

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
f=1
h[0]-=1
for i in range(1,n):
    if h[i]-h[i-1]>=1:h[i]+=-1
    elif h[i]-h[i-1]==0:h[i]+=0
    else:
        f=0
        print("No")
        break
if f==1:print("Yes")
Buggy python submission (verdict: Runtime Error):
n,x=map(int, input().split())
L=list(map(int, input().split()))

i=0
D=0
while(i<=n and D<=x):
    D+=L[i]
    i+=1
print(i)

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

count=1
D=0
for move in L :
    D = D + move
    if D<=x:
        count+=1
    else:
        break
print(count)

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

i=0
D=0
while(i<=n+1 and D<=x):
    D+=L[i]
    i+=1
print(i)

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

count=1
D=0
for move in L :
    D = D + move
    if D<=x:
        count+=1
    else:
        break
print(count)
Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce

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

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

gcd_box=[]

for i in range(1,n-1):
    L_gcd=gcd_list(a[:i])
    R_gcd=gcd_list(a[i+1:])
    gcd_box.append(fractions.gcd(L_gcd,R_gcd))
    
print(max(gcd_box))

Fixed submission:
from fractions import gcd

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

L = [0]*(n+1)
R = [0]*(n+1)

for i in range(1,n+1):
    L[i] = gcd(L[i-1],a[i-1])
for i in range(0,n)[::-1]:
    R[i] = gcd(R[i+1],a[i])
    
gcd_ans=[]
for i in range(n):
    gcd_ans.append(gcd(L[i],R[i+1]))
        
print(max(gcd_ans))

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

# 書き換える必要ある？
# 2 36 72　などの場合,2を36にしたら最大公約数は大きくなる
# ならば、１つを除いた全ての数の組み合わせにおける最大公約数の最大値が答えでは？

import itertools
import fractions
from functools import reduce

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

all_pairs=list(itertools.combinations(a,n-1))
gcd_box=[]
for lis in all_pairs:
    gcd_box.append(gcd_list(lis))
print(max(gcd_box))


Fixed submission:
from fractions import gcd

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

L = [0]*(n+1)
R = [0]*(n+1)

for i in range(1,n+1):
    L[i] = gcd(L[i-1],a[i-1])
for i in range(0,n)[::-1]:
    R[i] = gcd(R[i+1],a[i])
    
gcd_ans=[]
for i in range(n):
    gcd_ans.append(gcd(L[i],R[i+1]))
        
print(max(gcd_ans))