Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())
t1 = x * (2/(a*(b**2)))
t2 = a/(2 * b - x * (2/(a**2)))
if t1 < (a/b):
  print(90.-math.degrees(math.atan(t1)))
else:
  print(90.-math.degrees(math.atan(t2)))


Fixed submission:
import math

a, b, x = map(int, input().split())
t1 = x * (2/(a*(b**2)))
if t1 < (a/b):
  print(90.-math.degrees(math.atan(t1)))
else:
  tmp = 2 * b - x * (2/(a**2))
  if tmp < 0.000001:
    print(0.)
  else:
    t2 = a/(2 * b - x * (2/(a**2)))
    print(90.-math.degrees(math.atan(t2)))
Buggy python submission (verdict: Time Limit Exceeded):
def isok(A_, F_, N_, K_, x):
  _K_ = 0
  for i in range(N_):
    a_ = A_[i]-x//F_[i]
    if a_ > 0:
      _K_ += a_
  if _K_ > K_:
  	return False
  else:
    return True

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse = True)
ok = 10**12
ng = 0
while abs(ok-ng)>1:
  mid_x = (ok+ng)//2
  if isok(A, F, N, K, mid_x):
    ok = mid_x
  else:
    ng = mid_x
if isok(A, F, N, K, ng):
  print(ng)
else:
  print(ok)

Fixed submission:
def isok(A_, F_, N_, K_, x):
  _K_ = 0
  for i in range(N_):
    a_ = A_[i]-x//F_[i]
    if a_ > 0:
      _K_ += a_
  if _K_ > K_:
  	return False
  else:
    return True

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse = True)
ok = 10**12
ng = 0
while abs(ok-ng)>1:
  mid_x = (ok+ng)//2
  if isok(A, F, N, K, mid_x):
    ok = mid_x
  else:
    ng = mid_x
if isok(A, F, N, K, ng):
  print(ng)
else:
  print(ok)
Buggy python submission (verdict: Runtime Error):
H, W, A, B = map(int, input().split())
ans = [[0]*W for _ in range(H)]
X = [0]*W
fail = False
if H == 1 and B == 0:
  print("1"*A+"0"*(W-A))
elif W == 1 and A == 0:
  for _ in range(B):
    print(1)
  for _ in range(H-B):
    print(0)
else:
  for i in range(H):
    s = 0
    while X[s] >= B:
      s += 1
    c = 0
    while s < W and c < A:
      ans[i][s] = 1
      X[s] += 1
      s += 1
      c += 1
    if c < A:
      fail = True
      break
  print("\n".join(["".join([str(x) for x in a]) for a in ans]) if not fail else "No")

Fixed submission:
H, W, A, B = map(int, input().split())
for _ in range(B):
  print("0"*A+"1"*(W-A))
for _ in range(H-B):
  print("1"*A+"0"*(W-A))
Buggy python submission (verdict: Runtime Error):
S = input()
if S == "Sunny":
  print("Cloudy")
elif S == "Cloudy"
	print("Rainy")
else:
  print("Sunny")

Fixed submission:
S = input()
if S == "Sunny":
  print("Cloudy")
elif S == "Cloudy":
	print("Rainy")
else:
  print("Sunny")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

for m in range(M):
  x = A.pop() // 2
  A.insert(bisect.bisect_left(A, x),x)
print(sum(A))



Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(lambda x:[-int(x),int(x)], input().split()))
heapq.heapify(A)

for m in range(M):
  x = heapq.heappop(A)
  x[1] //= 2
  x[0] = -x[1]
  heapq.heappush(A, x)
ans = 0
for a in A:
  ans += a[1]
print(ans)

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

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

for i in range(m):
  x = a.pop()//2
  a.insert(bisect.bisect_left(a, x),x)
print(sum(a))


Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(lambda x:[-int(x),int(x)], input().split()))
heapq.heapify(A)

for m in range(M):
  x = heapq.heappop(A)
  x[1] //= 2
  x[0] = -x[1]
  heapq.heappush(A, x)
ans = 0
for a in A:
  ans += a[1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
d = {}

def solve(N, M, A, cur, remain):
  if cur == N:
    return 0
  else:
    if not (cur, remain) in d:
      a = A[cur]
      tmp = 10**10
      for i in range(remain+1):
        tmp = min(tmp, solve(N, M, A, cur+1, remain-i)+a)
        if a / 2 < 0.5:
          break
        a //= 2
      d[(cur, remain)] = tmp
    return d[(cur, remain)]
n, m = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, m, a, 0, m))



Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(lambda x:[-int(x),int(x)], input().split()))
heapq.heapify(A)

for m in range(M):
  x = heapq.heappop(A)
  x[1] //= 2
  x[0] = -x[1]
  heapq.heappush(A, x)
ans = 0
for a in A:
  ans += a[1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

def solve(N, M, A, cur, remain):
  if cur == N:
    return 0
  else:
    a = A[cur]
    tmp = 10**10
    for i in range(remain+1):
      tmp = min(tmp, solve(N, M, A, cur+1, remain-i)+a//(2**i))
    return tmp
n, m = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, m, a, 0, m))



Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(lambda x:[-int(x),int(x)], input().split()))
heapq.heapify(A)

for m in range(M):
  x = heapq.heappop(A)
  x[1] //= 2
  x[0] = -x[1]
  heapq.heappush(A, x)
ans = 0
for a in A:
  ans += a[1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import bisect

S = list(input())
T = list(input())

pos_S = {}
for i, s in enumerate(S):
  if s in pos_S:
    pos_S[s].append(i)
  else:
    pos_S[s] = deque([i])
x = 0
start = 0
for t in T:
  if t in pos_S:
    poss = pos_S[t]
    pos = bisect.bisect_left(poss, start)
    if pos >= len(poss):
      x += 1
      start = poss[0]+1
    else:
      start = poss[pos]+1
  else:
    x = -1
    break
if x == -1:
  print(-1)
else:
  print(x*len(S)+start)



Fixed submission:
from collections import deque
import bisect

S = list(input())
T = list(input())

pos_S = {}
for i, s in enumerate(S):
  if s in pos_S:
    pos_S[s].append(i)
  else:
    pos_S[s] = deque([i])
x = 0
start = 0
for t in T:
  if t in pos_S:
    poss = pos_S[t]
    pos = bisect.bisect_left(poss, start)
    if pos >= len(poss):
      x += 1
      start = poss[0]+1
    else:
      start = poss[pos]+1
  else:
    x = -1
    break
if x == -1:
  print(-1)
else:
  print(x*len(S)+start)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

def solve(n, h, cur, l):
  if cur > n:
    return True
  else:
    if l < h[cur]:
      return solve(n, h, cur+1, h[cur]-1) or solve(n, h, cur+1, h[cur])
    elif l == h[cur]:
      return solve(n, h, cur+1, h[cur])
    else:
      return False

N = int(input())
H = [-1]+list(map(int, input().split()))+[(10**9)+1]
print("Yes" if solve(N, H, 1, -1) else "No")



Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def solve(n, h, cur, l):
  if cur > n:
    return True
  else:
    if l < h[cur]:
      return solve(n, h, cur+1, h[cur]-1)
    elif l == h[cur]:
      return solve(n, h, cur+1, h[cur])
    else:
      return False

N = int(input())
H = [-1]+list(map(int, input().split()))+[(10**9)+1]
print("Yes" if solve(N, H, 1, -1) else "No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

def solve(n, h, cur, l):
  if cur > n:
    return True
  else:
    if l < h[cur]:
      return solve(n, h, cur+1, h[cur]-1) or solve(n, h, cur+1, h[cur])
    elif l == h[cur]:
      return solve(n, h, cur+1, h[cur])
    else:
      return False

N = int(input())
H = [-1]+list(map(int, input().split()))+[(10**9)+1]
print("Yes" if solve(N, H, 1, -1) else "No")



Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def solve(n, h, cur, l):
  if cur > n:
    return True
  else:
    if l < h[cur]:
      return solve(n, h, cur+1, h[cur]-1)
    elif l == h[cur]:
      return solve(n, h, cur+1, h[cur])
    else:
      return False

N = int(input())
H = [-1]+list(map(int, input().split()))+[(10**9)+1]
print("Yes" if solve(N, H, 1, -1) else "No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
S = int(input())
a = S//2 #x1*y2
isOk = False
while a > 0 and not isOk:
  b = S - a #x2*y1
  x1 = int(math.sqrt(a))
  y2 = -1
  while x1 >= 1:
    y2 = a//x1
    if x1*y2 == a:
      break
    x1 -= 1
  x2 = int(math.sqrt(b))
  y1 = -1
  while x2 >= 1:
    y1 = b // x2
    if x2*y1 == b:
      break
    x2 -= 1
  if y2 > 0 and y1 > 0 and max(x1, x2, y1, y2) <=10**9:
    m = min(x1, x2, y1, y2)
    if m == x1 and x1+x2 <= 10**9:
      ans = [0, y1, x2+x1, y2, x1, 0]
      isOk = True
    elif m == x2 and x1+x2 <= 10**9:
      ans = [x1+x2, y1, 0, y2, x2, 0]
      isOk = True
    elif m == y1 and y1+y2 <= 10**9:
      ans = [x1, 0, x2, y1+y2, 0, y1]
      isOk = True
    elif m == y2 and y1+y2 <= 10**9:
      ans = [x1, y1+y2, x2, 0, 0, y2]
      isOk = True
    if isOk:
      print(" ".join([str(a) for a in ans]))
  a -= 1
if not isOk:
  a = 0
  b = S - a
  x2 = int(math.sqrt(b))
  y1 = -1
  while x2 >= 1:
    y1 = b // x2
    if x2*y1 == b:
      break
    x2 -= 1
  if y1 > 0 and min(x2, y1) <= 10**9:
    print(" ".join([str(a) for a in [0, y1, x2, 0, 0, 0 ]]))

Fixed submission:
import math
S = int(input())
v = 10**9
x3 = (v-S%v)%v
y3 = (S+x3)//v
print("0 0 %d 1 %d %d"%(10**9, x3, y3))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
S = sum(A)/2
x1 = S - sum([a for a in A[1:N:2]])
ans = "%d"%(x1*2)
x = x1
for a in A[:-1]:
  x = a-x
  ans += " %d"%(x*2)
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)/2
x1 = S - sum([a for a in A[1:N:2]])
ans = "%d"%(x1*2)
x = x1
for a in A[:-1]:
  x = a-x
  ans += " %d"%(x*2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
S = sum(A)/2
x1 = S - sum([A[i] for i in range(1, N, 2)])
ans = "%d"%(x1*2)
x = x1
for i in range(N-1):
  x = A[i]-x
  ans += " %d"%(x*2)
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)/2
x1 = S - sum([a for a in A[1:N:2]])
ans = "%d"%(x1*2)
x = x1
for a in A[:-1]:
  x = a-x
  ans += " %d"%(x*2)
print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
memo = {}
def steps(n):
  if not(n in memo):
    if n == 0:
      memo[n] = 1
    elif n == 1:
      memo[n] = 1
    else:
      memo[n] = (steps(n-1)+steps(n-2))%MOD
  return memo[n]

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
nowstep = 0
ans = 1
for a in A:
  if nowstep == a:
    ans = 0
    break
  ans = (ans * steps(a-1-nowstep))%MOD
  nowstep = a+1
ans = (ans * steps(N-nowstep))%MOD
print(ans)



Fixed submission:
import sys
sys.setrecursionlimit(10**6)

MOD = 10**9+7
memo = {}
def steps(n):
  if not(n in memo):
    if n == 0:
      memo[n] = 1
    elif n == 1:
      memo[n] = 1
    else:
      memo[n] = (steps(n-1)+steps(n-2))%MOD
  return memo[n]

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
nowstep = 0
ans = 1
for a in A:
  if nowstep == a:
    ans = 0
    break
  ans = (ans * steps(a-1-nowstep))%MOD
  nowstep = a+1
ans = (ans * steps(N-nowstep))%MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
X = [[-10**2 for __ in range(W)] for _ in range(H)]
Y = [[-10**2 for __ in range(W)] for _ in range(H)]
last_ys = [-1] * W
for y in range(H):
  last_x = -1
  for x in range(W):
    if S[y][x] == "#":
      for t in range(last_x+1,x):
        X[y][t] = x-1-last_x
      for t in range(last_ys[x]+1,y):
        Y[t][x] = y-1-last_ys[x]
      last_x = x
      last_ys[x] = y
  for t in range(last_x+1,W):
    X[y][t] = W-1-last_x
for x in range(W):
  for t in range(last_ys[x]+1,H):
    Y[t][x] = H-1-last_ys[x]
ans = 0
for y in range(H):
  for x in range(W):
    ans = max(ans, Y[y][x]+X[y][x])
print(ans-1)


Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
X = [[-10**2 for __ in range(W)] for _ in range(H)]
Y = [[-10**2 for __ in range(W)] for _ in range(H)]
last_ys = [-1] * W
for y in range(H):
  last_x = -1
  for x in range(W):
    if S[y][x] == "#":
      for t in range(last_x+1,x):
        X[y][t] = x-1-last_x
      for t in range(last_ys[x]+1,y):
        Y[t][x] = y-1-last_ys[x]
      last_x = x
      last_ys[x] = y
  for t in range(last_x+1,W):
    X[y][t] = W-1-last_x
for x in range(W):
  for t in range(last_ys[x]+1,H):
    Y[t][x] = H-1-last_ys[x]
ans = 0
for y in range(H):
  for x in range(W):
    ans = max(ans, Y[y][x]+X[y][x])
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
X = [[-10**2 for __ in range(W)] for _ in range(H)]
Y = [[-10**2 for __ in range(W)] for _ in range(H)]
for y in range(H):
  last_x = -1
  for x in range(W):
    if S[y][x] == "#":
      for t in range(last_x+1,x):
        X[y][t] = x-1-last_x
      last_x = x
  for t in range(last_x+1,W):
    X[y][t] = W-1-last_x
for x in range(W):
  last_y = -1
  for y in range(H):
    if S[y][x] == "#":
      for t in range(last_y+1,y):
        Y[t][x] = y-1-last_y
      last_y = y
  for t in range(last_y+1,H):
    Y[t][x] = H-1-last_y
ans = 0
for y in range(H):
  for x in range(W):
    ans = max(ans, Y[y][x]+X[y][x])
print(ans-1)


Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
X = [[-10**2 for __ in range(W)] for _ in range(H)]
Y = [[-10**2 for __ in range(W)] for _ in range(H)]
last_ys = [-1] * W
for y in range(H):
  last_x = -1
  for x in range(W):
    if S[y][x] == "#":
      for t in range(last_x+1,x):
        X[y][t] = x-1-last_x
      for t in range(last_ys[x]+1,y):
        Y[t][x] = y-1-last_ys[x]
      last_x = x
      last_ys[x] = y
  for t in range(last_x+1,W):
    X[y][t] = W-1-last_x
for x in range(W):
  for t in range(last_ys[x]+1,H):
    Y[t][x] = H-1-last_ys[x]
ans = 0
for y in range(H):
  for x in range(W):
    ans = max(ans, Y[y][x]+X[y][x])
print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
BCidxs = []
i = 0
while i < N:
  if "".join(S[i:i+2]) == "BC":
    BCidxs.append(i)
  i += 1
ans = 0
L = len(BCidxs)
i = 0
while i < L:
  idx = BCidxs[i]
  if "".join(S[idx-1:idx+2]) == "ABC":
    ans += 1
    S[idx-1] = "B"
    S[idx] = "C"
    S[idx+1] = "A"
    BCidxs[i] -= 1
  else:
    i += 1
print(ans)

Fixed submission:
S = input()
N = len(S)
ans = 0
cnt = 0
i = 0
while i < N:
  if S[i] == "A":
    cnt += 1
    i += 1
  elif "".join(S[i:i+2]) == "BC":
    ans += cnt
    i += 2
  else:
    cnt = 0
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
Aidxs = []
i = 0
while i < N:
  if S[i] == "A":
    Aidxs.append(i)
  i += 1
ans = 0
L = len(Aidxs)
i = 0
while i < L:
  idx = Aidxs[i]
  if "".join(S[idx:idx+3]) == "ABC":
    ans += 1
    S[idx] = "B"
    S[idx+1] = "C"
    S[idx+2] = "A"
    Aidxs[i] += 2
    i = max(0, i-2)
  else:
    i += 1
print(ans)

Fixed submission:
S = input()
N = len(S)
ans = 0
cnt = 0
i = 0
while i < N:
  if S[i] == "A":
    cnt += 1
    i += 1
  elif "".join(S[i:i+2]) == "BC":
    ans += cnt
    i += 2
  else:
    cnt = 0
    i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
dp = {}

def dfs(N, K, k, have, q):
  if k == K:
    return sum(have)
  else:
    if not ((k, tuple(q)) in dp):
      a = [sum(have)]
      if len(q) > 0:
        tmp_q = copy.copy(q)
        tmp_have = copy.copy(have)
        v = tmp_q.popleft()
        tmp_have.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
        tmp_q = copy.copy(q)
        tmp_have = copy.copy(have)
        v = tmp_q.pop()
        tmp_have.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
      if len(have) > 0:
        tmp_q = copy.copy(q)
        tmp_have = sorted(copy.copy(have))
        v = tmp_have.pop(0)
        tmp_q.appendleft(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
        tmp_q = copy.copy(q)
        tmp_have = sorted(copy.copy(have))
        v = tmp_have.pop(0)
        tmp_q.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
      dp[(k, tuple(q))] = max(a)
    return dp[(k, tuple(q))]


N, K = map(int, input().split())
V = deque(list(map(int, input().split())))
print(dfs(N, K, 0, [], V))




Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
M = min(N, K)
ans = 0
for p in range(M+1):
  for q in range(M-p+1):
    left = []
    right = []
    if p > 0:
      left = V[:p]
    if q > 0:
      right = V[-q:]
    have = sorted((left+right).copy())
    if len(have) > 0:
      for i in range(min(len(have),K-p-q+1)):
        if have[i] > 0:
          break
      ans = max(sum(have[i:]),ans)
print(ans)

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

dp = {}

def dfs(N, K, k, have, q):
  if k == K:
    return sum(have)
  else:
    if not ((k, tuple(q)) in dp):
      a = [sum(have)]
      if len(q) > 0:
        tmp_q = q.copy()
        tmp_have = have.copy()
        v = tmp_q.popleft()
        tmp_have.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
        tmp_q = q.copy()
        tmp_have = have.copy()
        v = tmp_q.pop()
        tmp_have.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
      if len(have) > 0:
        tmp_q = q.copy()
        tmp_have = sorted(have.copy())
        v = tmp_have.pop(0)
        tmp_q.appendleft(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
        tmp_q = q.copy()
        tmp_have = sorted(have.copy())
        v = tmp_have.pop(0)
        tmp_q.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
      dp[(k, tuple(q))] = max(a)
    return dp[(k, tuple(q))]


N, K = map(int, input().split())
V = deque(list(map(int, input().split())))
print(dfs(N, K, 0, [], V))



Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
M = min(N, K)
ans = 0
for p in range(M+1):
  for q in range(M-p+1):
    left = []
    right = []
    if p > 0:
      left = V[:p]
    if q > 0:
      right = V[-q:]
    have = sorted((left+right).copy())
    if len(have) > 0:
      for i in range(min(len(have),K-p-q+1)):
        if have[i] > 0:
          break
      ans = max(sum(have[i:]),ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
import copy

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

ansA = 0
for i in range(N-2):
  if A[i] < 0:
    A[i+1] *= -1
  ansA += abs(A[i])
if A[-3] == 0:
  ansA += abs(A[-1])+abs(A[-2])
else:
  ansA += abs(A[-1]+A[-2])
ansB = 0
for i in reversed(range(2, N)):
  if X[i] < 0:
    X[i-1] *= -1
  ansB += abs(X[i])
if X[2] == 0:
  ansB += abs(X[0])+abs(X[1])
else:
  ansB += abs(X[0]+X[1])
print(max(ansA, ansB))



Fixed submission:
from collections import deque

N = int(input())
A = list(map(int, input().split()))
minAbs = 10**10
countMinus = 0
S = 0
for a in A:
  countMinus += (1 if a < 0 else 0)
  S += abs(a)
  minAbs = min(minAbs, abs(a))
print(S-2*(0 if countMinus % 2 == 0 else minAbs))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)

def dfs(N, B, A, seq, nums):
  if len(A) == N:
    ok = True
    for a, b in zip(A, B):
      if a != b:
        ok = False
        break
    return seq if ok else None
  else:
    for n in nums.keys():
      if nums[n] > 0:
        tmpA = A.copy()
        tmpSeq = seq.copy()
        tmpNums = nums.copy()
        tmpA.insert(n-1,n)
        tmpSeq.append(n)
        tmpNums[n] -= 1
        ans = dfs(N, B, tmpA, tmpSeq, tmpNums)
        if ans:
          return ans

N = int(input())
B = list(map(int, input().split()))
ok = True
nums = {b:0 for b in B}
for i, b in enumerate(B):
  if i+1<b:
    ok = False
    break
  nums[b] += 1
if ok:
  for n in dfs(N,B,[],[],nums):
    print(n)
else:
  print(-1)



Fixed submission:
import sys
sys.setrecursionlimit(10**5)

N = int(input())
B = list(map(int, input().split()))
ans = []
while len(B) > 0:
  ok = False
  for i in reversed(range(len(B))):
    if B[i] == i+1:
      ok = True
      ans.append(B.pop(i))
      break
  if not ok:
    break
if len(B) > 0:
  print(-1)
else:
  for a in reversed(ans):
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in range(1, min(i+1,K+1)):
      if i-j < 0:
        break
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)
    



Fixed submission:
import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in reversed(range(1, min(i+1,K+1))):
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in range(1, K+1):
      if i-j < 0:
        break
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)
    



Fixed submission:
import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in reversed(range(1, min(i+1,K+1))):
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in range(1, K+1):
      if i - j < 0:
        continue
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)
    



Fixed submission:
import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in reversed(range(1, min(i+1,K+1))):
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)