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

Fixed submission:
N, M = map(int, raw_input().split())
#print N, M

state = [-1 for i in range(N)]
pena = [0 for i in range(N)]
WA = [0 for i in range(N)]

for i in range(M):
    s = raw_input().split()
    p = int(s[0])
    sc = s[1]
    #print p, sc
    p -= 1
    if (state[p] == 0):
        continue
    if sc == 'WA':
        pena[p] += 1
    else:
        state[p] = 0

ok = 0
pn = 0
for i in range(N):
    if state[i] == 0:
        ok += 1
        pn += pena[i]

print ok, pn

Buggy submission (verdict: Runtime Error):
cat atcorder_151_C.py
N, M = map(int, raw_input().split())
#print N, M

state = [-1 for i in range(N)]
pena = [0 for i in range(N)]
WA = [0 for i in range(N)]

for i in range(M):
    s = raw_input().split()
    p = int(s[0])
    sc = s[1]
    #print p, sc
    p -= 1
    if (state[p] == 0):
        continue
    if sc == 'WA':
        pena[p] += 1
    else:
        state[p] = 0

ok = 0
pn = 0
for i in range(N):
    if state[i] == 0:
        ok += 1
        pn += pena[i]

print ok, pn
Problem p02853 (python)

Fixed submission:
s = raw_input().split()
[X, Y] = s
o = [0,0]
o[0] = int(X)
o[1] = int(Y)
#print A, B

p = 0
for i in range(2):
    if o[i] == 1:
        p += 300000
    elif o[i] == 2:
        p += 200000
    elif o[i] == 3:
        p += 100000

if o[0] == 1 and o[1] == 1:
    p += 400000

print p

Buggy submission (verdict: Runtime Error):
N = int(input())
s = raw_input().split()
A = [0]*N

for i in range(N):
    A[i] = int(s[i])

#print N, A

h = 0
t = N-1
lh = 0
lt = 0

for i in range(N):
    if (lh > lt):
        lt += A[t]
        t -= 1
    else:
        lh += A[h]
        h += 1
    #print h, t, lh, lt, A[h+1:t-1]

print abs(lh-lt)
Problem p02865 (python)

Fixed submission:
s = raw_input().split()
[N] = s
N = int(N)

print ((N-1)/2)

Buggy submission (verdict: Runtime Error):
s = raw_input().split()
[N] = s
N = int(N)

print ((N-1)/2)
Problem p02899 (python)

Fixed submission:
N = int(input())
s = raw_input().split()
h = [0]*N

for i in range(N):
    h[i] = int(s[i])
    h[i] = (h[i], i+1)

#print h
h.sort()
#print h

for i in range(N-1):
    print h[i][1],

print h[N-1][1]

Buggy submission (verdict: Runtime Error):
$ cat atcorder_142_C.py
N = int(input())
s = raw_input().split()
h = [0]*N

for i in range(N):
    h[i] = int(s[i])
    h[i] = (h[i], i+1)

#print h
h.sort()
#print h

for i in range(N-1):
    print h[i][1],

print h[N-1][1]
Problem p02696 (python)

Fixed submission:
import math
a, b, n = list(map(int,input().split()))
if b > n:
    print(math.floor(a*n/b))
elif n < 2*b - 1:
    print(max(math.floor(a*n/b)-a,math.floor(a*(b-1)/b)))
else:
    print(a+math.floor((-1)*a/b))

Buggy submission (verdict: Runtime Error):
import math
a, b, n = list(map(int,input().split()))
if b > n:
    print(math.floor(a*n/b))
elif n < 2*b - 1:
    print(max(math.floor(a*n/b)-a,math.floor(a*(b-1)/b))
else:
    print(a+math.floor((-1)*a/b))
Problem p02702 (python)

Fixed submission:
s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
counting[0] += 1
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
#print(counting)
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)

Buggy submission (verdict: Runtime Error):
s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
counitng[0] += 1
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
#print(counting)
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)

Buggy submission (verdict: Runtime Error):
s = input()
s.reverse()
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = s[0]
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += counting[j]*(counting[j]-1)
print(sm)
Problem p02787 (python)

Fixed submission:
h, n= list(map(int,input().split()))
a = []
b = []
for i in range(n):
    a_in, b_in = list(map(int,input().split()))
    a.append(a_in)
    b.append(b_in)

if h == 1:
    print(min(b))
else:
    dp = [0]*h
    dp[0] = min(b)
    for i in range(2,h+1):
        c = [0]*n
        for j in range(n):
            if i > a[j]:
                c[j] = b[j] + dp[i-a[j]-1]
            else:
                c[j] = b[j]
        dp[i-1] = min(c)
    print(dp[h-1])

Buggy submission (verdict: Runtime Error):
h, n= list(map(int,input().split()))
a = []
b = []
for i in range(n):
    a_in, b_in = list(map(int,input().split()))
    a.append(a_in)
    b.append(b_in)

def ibis(h,a,b,n):
    if h <= 0:
        return 0
    else:
        c = [0]*n
        for i in range(n):
            c[i] = b[i] + ibis(h-a[i],a,b,n)
        return(min(c))
 
print(ibis(h,a,b,n))
Problem p02911 (python)

Fixed submission:
n,k,q = map(int, input().split())
b = []
for i in range(n):
    b.append(0)
for i in range(q):
    a = int(input())
    b[a-1] += 1
for i in range(n):
    if b[i] > q - k:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
n,k,q = map(int, input().split())
b = []
for i in range(n):
    b.append(0)
for i in range(q):
    a = int(input())
    b[a] += 1
for i in range(n):
    if b[i] > q - k:
        print('Yes')
    else:
        print('No')
Problem p02917 (python)

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
a = b[0] + b[n-2]
if n > 2:
    for i in range(0,n-2):
        a = a + min(b[i],b[i+1])
print(a)

Buggy submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))
a = b[0] + b[n-1]
for i in range(0,n-1):
    a = a + min(b[i],b[i+1])
print(a)
Problem p02953 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
if n == 1:
    print('Yes')
else:
    i = 0
    f = 0
    while i < n-1:
        if h[i]-h[i+1] > 1:
            print('No')
            i = n 
        elif h[i]-h[i+1] == 1:
            f += 1
            if f == 2:
                print('No')
                i = n
            else:
                i += 1
        elif h[i] == h[i+1]:
            i += 1
        else:
            f = 0
            i += 1
    if i == n-1:
        print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
if n == 1:
    print('Yes')
else:
    i = 0
    f = 0
    while i < n-1:
        if h[i]-h[i+1] > 1:
            print('No')
            i = n 
        elif h[i]-h[i+1] == 1:
            f += 1
            if f == 2:
                print('No')
                i = n
            else:
                i += 1
        elif h[i] == h[i+1]:
            i += 1
        else:
            f = 0
            i += 1
if i == n-1:
    print('Yes')
Problem p02675 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int):
    mod = N % 10
    if mod in [2, 4, 5, 7, 9]:
        print("hon")
    elif mod in [0, 1, 6, 8]:
        print("pon")
    else:
        print("bon")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(K: int, S: str):
    if (len(S) <= K):
        print(S)
    else:
        print(S[0:K], "...", sep='')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()
Problem p02681 (python)

Fixed submission:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    if (S == T[:-1]):
        print(YES)
        return 0
    print(NO)
    return 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
cur = 0
i = 0
loop = 0
list = []

while (i <= K):
  i = i+1
  cur = A[cur-1]
  if(loop == 0):
    if (cur in list):
      loop = len(list) - list.index(cur)
      if (K > 100):
        K= K - ((K // loop) - 1)*loop
    list.append(cur)

print(cur)

Buggy submission (verdict: Runtime Error):
import sys
 
 
def solve(A: int, B: int, C: int, K: int):
    if (K <= A):
        print(K)
    else:
        if (K <= (A+B)):
            print(A)
        else:
            print(A-(K-A-B))
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    if (K <= A):
        print(K)
    else:
        if (K <= (A+B)):
            print(A)
        else:
            print(A-(K-A-B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()
Problem p03493 (python)

Fixed submission:
l = input()

b = 0

for i in l[0], l[1], l[2]:
  if (int(i) == 1):
    b = b+1

print(b)

Buggy submission (verdict: Runtime Error):
import sys

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

loop = 1

while (1):
  for i in l:
    if (i % (2 ** (loop + 1)) != 0):
      print(loop )
      sys.exit(0)
  loop = loop + 1

Buggy submission (verdict: Runtime Error):
import sys

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

loop = 1

while (1):
  for i in l:
    if (i % (2 ** loop) != 0):
      print(loop - 1)
      sys.exit(0)
  loop = loop + 1
Problem p02675 (python)

Fixed submission:
import re

N = input()

if re.match(r'[2,4,5,7,9]', N[-1]):
	print('hon')
elif re.match(r'[0,1,6,8]', N[-1]):
	print('pon')
else:
	print('bon')

Buggy submission (verdict: Runtime Error):
imporet re

N = input()

if re.match(r'[2,4,5,7,9]', N[-1]):
	print('hon')
elif re.match(r'[0,1,6,8]', N[-1]):
	print('pon')
else:
	print('bon')
Problem p02718 (python)

Fixed submission:
N, M = map(int, input().split())
votes = [int(i) for i in input().split()]
count = [1 for vote in votes if vote >= sum(votes) * 1 / (4 * M)]
if sum(count) >= M:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
votes = [int(i) for i in input().split()]
count = [1 for vote in votes if vote >= sum(votes) * 1 / (4 * M)]
if count >= M:
  print('Yes')
else:
  print('No')
Problem p02917 (python)

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
s=0
if n==2:
  print(b[0]*2)
else:
  if(b[0]<b[1]):
  	s = b[0]*2+b[-1]
  else:
  	s = b[0]+b[1]+b[-1]
  for i in range(1,n-2):
  	s+=min(b[i],b[i+1])
    
  print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))
s=0
if n==1:
  print(b[0]*2)
else:
  s = min(b[0],b[1])*2+b[-1]
  for i in range(1,n-1):
  	s+=min(b[i],b[i+1])
    
  print(s)
Problem p02783 (python)

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

q, mod = divmod(list[0], list[1])
if mod == 0 :
  print(q)
else :
  print(int(q+1))

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

a_total = 0
count = 0
for i in range(0,h):
  a_total += a
  count += 1
  if h <= a_total:
    print(count)
    break
Problem p02801 (python)

Fixed submission:
c = str(input())

List = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

c_index = List.index(c)
ans = List[c_index+1]
print(ans)

Buggy submission (verdict: Runtime Error):
c = str(input())

List = ['a','b','c','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

c_index = List.index(c)
ans = List[c_index+1]
print(ans)
Problem p02812 (python)

Fixed submission:
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if j != n-2 :
        if s[j+2] == 'C' :
          count += 1

print(count)

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

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if s[j+2] == 'C' :
        count += 1

print(count)

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

A_index = [i for i, x in enumerate(s) if x == 'A']
print(A_index)

count = 0
for j in A_index :
  print(j)
  if j != n-1 :
    if s[j+1] == 'B' :
      if s[j+2] == 'C' :
        count += 1

print(count)

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

A_index = [i for i, x in enumerate(s) if x == 'A']
print(A_index)

count = 0
for j in A_index :
  print(j)
  if j != n-2 :
    if s[j+1] == 'B' :
      if s[j+2] == 'C' :
        count += 1

print(count)

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

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in range(A_index[0], n-1) :
  if s[j+1] == 'B' :
    if s[j+2] == 'C' :
      count += 1

print(count)

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

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if s[j+1] == 'B' :
    if s[j+2] == 'C' :
      count += 1

print(count)
Problem p02830 (python)

Fixed submission:
n = list(input().split())
s, t = list(input().split())

ans = []
for i in range(0, int(n[0])):
  ans.append(s[i])
  ans.append(t[i])
  
print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
n = list(input().split())
s, t = list(input().split())

ans = []
for i in range(0, int(len(n)+1)):
  ans.append(s[i])
  ans.append(t[i])
  
print(''.join(map(str,ans)))
Problem p02678 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
room_adjacent = [[] for _ in range(n)]
for _ in range(m):
  room1, room2 = map(int, input().split())
  room_adjacent[room1-1].append(room2)
  room_adjacent[room2-1].append(room1)

room_labels = [1]+[0]*(n-1)
old_room = 1
path_queue = deque((old_room, room) for room in room_adjacent[old_room-1])
while path_queue:
  old_room, new_room = path_queue.pop()
  if room_labels[new_room-1] == 0:
    room_labels[new_room-1] = old_room
    for another_room in room_adjacent[new_room-1]:
      path_queue.appendleft((new_room, another_room))
  
if 0 in room_labels:
  print("No")
else:
  print("Yes")
  [print(value) for value in room_labels[1:]]

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
room_adjacent = [[] for _ in range(n)]
for _ in range(m):
  room1, room2 = map(int, input().split())
  room_adjacent[room1-1].append(room2)
  room_adjacent[room2-1].append(room1)

def label_rooms(old_room):
  for room in room_adjacent[old_room-1]:
    if room_labels[room-1] == 0: room_labels[room-1] = old_room
  for room in room_adjacent[old_room-1]:
    if room_labels[room-1] == old_room: label_rooms(room)

room_labels = [1]+[0]*(n-1)
label_rooms(1)
if 0 in room_labels:
  print("No")
else:
  print("Yes")
  [print(value) for value in room_labels[1:]]
Problem p02691 (python)

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

dict_diffs1 = dict()
dict_diffs2 = dict()
for i in range(1, n+1):
  dict_diffs1[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
  dict_diffs2[i-a[i-1]] = dict_diffs2.get(i-a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
  total += dict_diffs2.get(j+a[j-1], 0)
total = total//2
print(total)

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

dict_diffs = dict()
for i in range(1, n+1):
  dict_diffs[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
print(total)
Problem p02717 (python)

Fixed submission:
a, b, c = map(int, input().split())
print(c, a, b)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split)
print(c, a, b)
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
top_red = p[-x:]
top_green = q[-y:]
final = top_red+top_green+r
final.sort()
print(sum(final[-(x+y):]))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
red = p[-x:]
green = q[-y:]
ri, gi = 0, 0
for blank in r:
  if (red[ri]>green[gi] and gi<y) or (ri>=x and gi<y):
    if blank>green[gi]:
      green[gi] = blank
      gi += 1
  elif ri<x:
    if blank>red[ri]:
      red[ri] = blank
      ri += 1
print(sum(red)+sum(green))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
red = p[-x:]
green = q[-y:]
ri, gi = 0, 0
for blank in r:
  if (red[ri]>green[gi] and gi<y) or (ri>=x and gi<y):
    if blank>green[gi]:
      green[gi] = blank
      gi += 1
  elif ri<x:
    if blank>red[ri]:
      red[ri] = r[bi]
      ri += 1
print(sum(red)+sum(green))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
red = p[-x:]
green = q[-y:]
ri, gi = 0, 0
for blank in r:
  if (red[ri]>green[gi] and gi<y) or ri>=x:
    if blank>green[gi]:
      green[gi] = blank
      gi += 1
  elif ri<x:
    if blank>red[ri]:
      red[ri] = r[bi]
      ri += 1
print(sum(red)+sum(green))
Problem p02761 (python)

Fixed submission:
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return [str(-1)]
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return [str(-1)]
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int("".join(assign_digits(ans))))

Buggy submission (verdict: Runtime Error):
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return -1
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return -1
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int("".join(assign_digits(ans))))

Buggy submission (verdict: Runtime Error):
# if assignment already exists for a digit, check it is consistent.
# no leading zeroes (except for the number zero)
# given constraints are ok, fill other digits with zeros (and potentially 1 for lead)

def assign_digits(ans):
  for _ in range(M):
    new_s = s.pop()
    new_c = c.pop()
    if flags_assigned[new_s-1] == 1:
      if new_c != int(ans[new_s-1]): return -1
    else:
      flags_assigned[new_s-1] = 1
      ans[new_s-1]=str(new_c)
  if ans[0] == "0" and len(ans)>1: return -1
  return ans

N, M = map(int, input().split())
s = list()
c = list()
for _ in range(M):
  row = list(map(int, input().split()))
  s.append(row[0])
  c.append(row[1])

if N==1:
  ans = [str(0)]
elif N==2:
  ans = [str(1), str(0)]
elif N==3:
  ans = [str(1), str(0), str(0)]
flags_assigned = [0]*N

print(int(assign_digits(ans)))
Problem p02786 (python)

Fixed submission:
"""
if a monster is not attacked, it doesn't do anything, so we can
deal with each living monster as a separate problem that takes
a certain number of moves to kill it and all of its offspring.
when x is not 1,
num(x) = 2*num(floor(x/2))+1
(because it took one move to kill it, and there will be two offspring)
and when x is 2 or 3,
num(x) = 3
so we can do some recursion, or memoization, or tabulation
"""

from math import floor


def get_num_attacks(H):
  if H>3:
    return 2*get_num_attacks(floor(H/2))+1
  if H==2 or H==3:
    return 3
  if H==1:
    return 1


if __name__ == "__main__":
  H = int(input())
  print(get_num_attacks(H))

Buggy submission (verdict: Runtime Error):
"""
if a monster is not attacked, it doesn't do anything, so we can
deal with each living monster as a separate problem that takes
a certain number of moves to kill it and all of its offspring.
when x is not 1,
num(x) = 2*num(floor(x/2))+1
(because it took one move to kill it, and there will be two offspring)
and when x is 2 or 3,
num(x) = 3
so we can do some recursion, or memoization, or tabulation
"""

from math import floor


def get_num_attacks(H):
  if H>3:
    return 2*get_num_attacks(floor(H/2))+1
  if H==2 or H==3:
    return 3
  if H==1
    return 1


if __name__ == "__main__":
  H = int(input())
  print(get_num_attacks(H))