Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
lst=set()
for i in range(1,N+1):
    lst.add(i)
    if sum(lst)>=N:
        if sum(lst)==N:
            break
        else:
            lst.remove(sum(lst)-N)
for s in lst:
    print(s)


Fixed submission:
N=int(input())
lst=set()
num=0
for i in range(1,N+1):
    lst.add(i)
    num+=i
    if num>=N:
        if num==N:
            break
        else:
            lst.remove(num-N)
            break
for s in lst:
    print(s)
Buggy python submission (verdict: Runtime Error):
N,x=map(int,input().split())

lst=[0 for i in range(2*N-1)]
if x==1 or x==2*N-1:
    print("No")
else:
    nlst=set([i for i in range(1,2*N)])
    if x>=N:
        lst[N-1]=x
        lst[N]=x+1
        lst[N+1]=x-1
        lst[N-2]=x-2
        nlst.remove(x)
        nlst.remove(x+1)
        nlst.remove(x-1)
        nlst.remove(x-2)
    else:
        lst[N-1]=x
        lst[N]=x-1
        lst[N+1]=x+1
        lst[N-2]=x+2
        nlst.remove(x)
        nlst.remove(x-1)
        nlst.remove(x+1)
        nlst.remove(x+2)

    idxlst=set([i for i in range(2*N-1)])
    idxlst.remove(N-2)
    idxlst.remove(N-1)
    idxlst.remove(N)
    idxlst.remove(N+1)

    nlst=list(nlst)
    idxlst=list(idxlst)
    for n,i in zip(nlst,idxlst):
        lst[i]=n
    print(" ".join([str(i) for i in lst]))


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


if x==1 or x==2*N-1:
    print("No")
elif N==2:
    print("Yes")
    for i in range(1,4):
        print(i)
else:
    lst=[0 for i in range(2*N-1)]
    nlst=set([i for i in range(1,2*N)])
    if x>=N:
        lst[N-1]=x
        lst[N]=x+1
        lst[N+1]=x-1
        lst[N-2]=x-2
        nlst.remove(x)
        nlst.remove(x+1)
        nlst.remove(x-1)
        nlst.remove(x-2)
    else:
        lst[N-1]=x
        lst[N]=x-1
        lst[N+1]=x+1
        lst[N-2]=x+2
        nlst.remove(x)
        nlst.remove(x-1)
        nlst.remove(x+1)
        nlst.remove(x+2)

    idxlst=set([i for i in range(2*N-1)])
    idxlst.remove(N-2)
    idxlst.remove(N-1)
    idxlst.remove(N)
    idxlst.remove(N+1)

    nlst=list(nlst)
    idxlst=list(idxlst)
    for n,i in zip(nlst,idxlst):
        lst[i]=n
    print("Yes")
    for i in lst:
        print(i)
Buggy python submission (verdict: Runtime Error):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

N=int(input())
T=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
lst=[0 for i in range(N)]


lst[0]=T[0]
lst[N-1]=A[N-1]
if T[N-1]!=A[0]:
    print(0)
    exit()
for i in range(1,N):
    if T[i]>T[i-1]:
        if lst[i] and lst[i]!=T[i]:
            print(0)
            exit()
        lst[i]=T[i]

for i in range(N-2,-1,-1):
    if A[i]>A[i+1]:
        if lst[i] and lst[i]!=A[i]:
            print(0)
            exit()
        elif not lst[i] and T[i]<A[i]
        lst[i]=A[i]

count=1
for i in range(N):
    if not lst[i]:
        count=count*min(T[i],A[i])%mod
print(count)


Fixed submission:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

N=int(input())
T=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
lst=[0 for i in range(N)]


lst[0]=T[0]
lst[N-1]=A[N-1]
if T[N-1]!=A[0]:
    print(0)
    exit()
for i in range(1,N):
    if T[i]>T[i-1]:
        if lst[i] and lst[i]!=T[i]:
            print(0)
            exit()
        lst[i]=T[i]

for i in range(N-2,-1,-1):
    if A[i]>A[i+1]:
        if lst[i] and lst[i]!=A[i]:
            print(0)
            exit()
        elif not lst[i] and T[i]<A[i]:
            print(0)
            exit()
        lst[i]=A[i]

count=1
for i in range(N):
    if not lst[i]:
        count=count*min(T[i],A[i])%mod
print(count)
Buggy python submission (verdict: Runtime Error):
s=list(input())
K=int(input())
for i in range(len(s)-1):
    if s[i]!="a"
        a= ord("z")+1 - ord(s[i])
        if K>=a:
            s[i]="a"
            K-=a
if K:
    s[-1]=chr((K+ord(s[-1])-ord("a"))%(ord("z") - ord("a")+1)+ord("a"))
print("".join(s))


Fixed submission:
s=list(input())
K=int(input())
for i in range(len(s)-1):
    if s[i]!="a":
        a= ord("z")+1 - ord(s[i])
        if K>=a:
            s[i]="a"
            K-=a
if K:
    s[-1]=chr((K+ord(s[-1])-ord("a"))%(ord("z") - ord("a")+1)+ord("a"))
print("".join(s))
Buggy python submission (verdict: Runtime Error):
s=input()

for i in range(len(s)-2):
    if s[i]==s[i+1]:
        print(i + 1 ,i+1 + 1)
        exit()
    if s[i]==s[i+2]:
        print(i + 1,i+2 + 1)
        exit()

if s[i-2]==s[i -1 ]:
    print(i-2 +1 ,i-1)
    exit()

print(-1,-1)


Fixed submission:
s=input()

for i in range(len(s)-2):
    if s[i]==s[i+1]:
        print(i + 1 ,i+1 + 1)
        exit()
    if s[i]==s[i+2]:
        print(i + 1,i+2 + 1)
        exit()

if s[-2]==s[-1 ]:
    print(len(s)-1 ,len(s))
    exit()

print(-1,-1)
Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())

#.
y = y // 1000

#.
for i in range(n+1):
    for j in range(n+1):
        #.
        money = y - i*10 - j*50

        #.
        if money == n - i - j:
            print("{} {} {}".format(i, j, money))
            return 0


Fixed submission:
def solve(args):
    n, y = args

    #.
    for i in range(n+1):
        for j in range(0, n-i+1):
            #.
            k = n - i - j

            #.
            if i*10000 + j*5000 + k*1000 == y:
                return "{} {} {}".format(i, j, k)

    return "-1 -1 -1"

print(solve(map(int, input().split())))

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

#.
y /= 1000

#.
ans = 0

#.
for i in range(n+1):
    for j in range(n+1):
        #.
        money = y - i*10 - j*50

        #.
        if money == n - i - j:
            ans += 1

print(ans)

Fixed submission:
def solve(args):
    n, y = args

    #.
    for i in range(n+1):
        for j in range(0, n-i+1):
            #.
            k = n - i - j

            #.
            if i*10000 + j*5000 + k*1000 == y:
                return "{} {} {}".format(i, j, k)

    return "-1 -1 -1"

print(solve(map(int, input().split())))

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

#.
ans = 0

#.
for i in range(n+1):
    for j in range(n+1):
        #.
        money = y - i*10000 - j*5000

        #.
        if money % 1000 != 0:
            continue

        #.
        if money / 1000 <= n - i - j:
            ans++

print(ans)

Fixed submission:
def solve(args):
    n, y = args

    #.
    for i in range(n+1):
        for j in range(0, n-i+1):
            #.
            k = n - i - j

            #.
            if i*10000 + j*5000 + k*1000 == y:
                return "{} {} {}".format(i, j, k)

    return "-1 -1 -1"

print(solve(map(int, input().split())))
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)
ans1 = 0
ans2 = 0
for i in range(N):
  x = a[i]
  if i % 2 == 0:
    if x == '0':
      ans1 += 1
    else:
      ans2 += 1
  else:
    if x == '1':
      ans1 += 1
    else:
      ans2 += 1
ans = min(ans1,ans2)
print(ans)

Fixed submission:
S = input()
N = len(S)
ans1 = 0
ans2 = 0
for i in range(N):
  x = S[i]
  if i % 2 == 0:
    if x == '0':
      ans1 += 1
    else:
      ans2 += 1
  else:
    if x == '1':
      ans1 += 1
    else:
      ans2 += 1
ans = min(ans1,ans2)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(M-1):
  b.append(a[i+1]-a[i])
b.sort()
if M == 1:
  print(0)
else:
  x = a[M-1]-a[0]
  y = M-2
  for i in range(N-1):
    x -= b[y]
    y -= 1
  print(x)

Fixed submission:
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(M-1):
  b.append(a[i+1]-a[i])
b.sort()
if N >= M:
  print(0)
else:
  x = a[M-1]-a[0]
  y = M-2
  for i in range(N-1):
    x -= b[y]
    y -= 1
  print(x)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
a = []
for i in range(N):
    a.append(int(input()))
b = []
for i in range(N-K):
    b.append(a[i+K]-a[i])
print(min(b))

Fixed submission:
N,K = map(int,raw_input().split())
a = []
for i in range(N):
    a.append(int(raw_input()))
a.sort()
b = []
for i in range(N-K+1):
    b.append(a[i+K-1]-a[i])
print(min(b))

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
a = []
for i in range(N):
    a.append(int(input()))
b = []
for i in range(N-K):
    b.append(a[i+K]-a[i])
print min(b)

Fixed submission:
N,K = map(int,raw_input().split())
a = []
for i in range(N):
    a.append(int(raw_input()))
a.sort()
b = []
for i in range(N-K+1):
    b.append(a[i+K-1]-a[i])
print(min(b))
Buggy python submission (verdict: Runtime Error):
H,W = map(int,raw_input().split())
count = 0
c = []
d = 0
e = []
for i in range(H):
  count += 1
  a = raw_input().split()
  b = []
  for j in range(W):
    b.append(int(a[j]))
  for k in range(W-1):
    if b[k]%2 == 1:
      d += 1
      f = [count,k+1,count,k+2]
      e.append(f)
      b[k] -= 1
      b[k+1] += 1
  c.append(b[W-1])
count = 0
for i in range(H-1):
  count += 1
  if c[i]%2 == 1:
    d += 1
    f = [count,k+1,count,k+2]
    e.append(f)
print d
for i in range(d):
  x = e[i]
  print x[0],x[1],x[2],x[3]

Fixed submission:
H,W = map(int,raw_input().split())
count = 0
c = []
d = 0
e = []
for i in range(H):
  count += 1
  a = raw_input().split()
  b = []
  for j in range(W):
    b.append(int(a[j]))
  for k in range(W-1):
    if b[k]%2 == 1:
      d += 1
      f = [count,k+1,count,k+2]
      e.append(f)
      b[k] -= 1
      b[k+1] += 1
  c.append(b[W-1])
count = 0
for i in range(H-1):
  count += 1
  if c[i]%2 == 1:
    d += 1
    f = [count,W,count+1,W]
    e.append(f)
    c[i] -= 1
    c[i+1] +=1
print d
for i in range(d):
  x = e[i]
  print x[0],x[1],x[2],x[3]
Buggy python submission (verdict: Runtime Error):
a = raw_input().split()
b = a[2:-1]
if a[0] == "A" and b.count("C") == 1:
  a.del("A")
  a.del("C")
  if a.islower() == True:
     print "AC"
else:
  print "WA"

Fixed submission:
a = list(raw_input())
b = a[2:-1]
if a[0] == "A" and b.count("C") == 1:
  c = b.index("C")
  a.pop(0)
  a.pop(c+1)
  d = ""
  for i in range(len(a)):
     d += a[i] 
  if d.islower():
     print "AC"
  else:
     print "WA"
else:
  print "WA"
Buggy python submission (verdict: Runtime Error):
n = int(input())

MOD = 10**9 + 7

ans = pow(10, n, MOD)-pow(9, n, MOD) - pow(9, n, MOD) + pow(8, n, MOD)

#負の処理
ans (ans+MOD)%MOD

print(ans)

Fixed submission:
n = int(input())

MOD = 10**9 + 7

ans = pow(10, n, MOD)-pow(9, n, MOD) - pow(9, n, MOD) + pow(8, n, MOD)

#負の処理
ans = (ans+MOD)%MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = sorted(list(int, input().split()))

ans = 0
for i in range(k):
    ans += p[i]

print(ans)

Fixed submission:
n, k = map(int, input().split())
p = sorted(list(map(int, input().split())))

ans = 0
for i in range(k):
    ans += p[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [list(map(int, input().split())) for _ in range(q)]
dic = Counter(a)

for i in range(q):
    (b, c) = l[i] 
    num = dic[b]
    dic[b] = 0
    if dic[c] == 0:
        dic[c] = num
    else:
        dic[c] += num
    ans = 0
    for i, j in dic.items():
        ans += i*j
    print(ans)

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [list(map(int, input().split())) for _ in range(q)]
dic = Counter(a)
S = sum(a)
for i in range(q):
    (b, c) = l[i] 
    num = dic[b]
    S -= b*num
    dic[b] = 0
    if dic[c] == 0:
        dic[c] = num
    else:
        dic[c] += num
    S += c*num
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
    (b, c) = l[i] 
    dic = Counter(a)
    for i in range(dic[b]):
        a.remove(b)
        a.append(c)
    print(sum(a))

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [list(map(int, input().split())) for _ in range(q)]
dic = Counter(a)
S = sum(a)
for i in range(q):
    (b, c) = l[i] 
    num = dic[b]
    S -= b*num
    dic[b] = 0
    if dic[c] == 0:
        dic[c] = num
    else:
        dic[c] += num
    S += c*num
    print(S)
Buggy python submission (verdict: Runtime Error):
from collections import deque

n, m = map(int, input().split())
u = [[] for _ in range(n)] 

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    u[a].append(b)
    u[b].append(a)

q = deque([0])
ans = [-1] * n
count = 0

while len(q):
    p = q.popleft()
    for x in u[p]:
        if ans[x] == -1:
            ans[x] = p+1
            q.append(x)
    print(q)

ans[0] = 'Yes'

for i in range(n):
    print(ans[i])

Fixed submission:
from collections import deque

n, m = map(int, input().split())
u = [[] for _ in range(n)] 

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    u[a].append(b)
    u[b].append(a)

q = deque([0])
ans = [-1] * n
count = 0

while len(q):
    p = q.popleft()
    for x in u[p]:
        if ans[x] == -1:
            ans[x] = p+1
            q.append(x)

ans[0] = 'Yes'

for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

s = 1
place = [s]
first = set(place)

for i in range(n):
    s = a[s-1]
    if s in first:
        loops = place.index(s)
        loope = len(place)
        ans = loops + (k-loope) % (loope-loops)
        print(place(ans))
        break
    else:
        place.append(s)
        first.add(s)
else:
    print(s)

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

s = 1
place = [s]
first = set(place)

for i in range(1, k+1):
    s = a[s-1]
    if s in first:
        loops = place.index(s)
        loope = len(place)
        ans = loops + (k-loope) % (loope-loops)
        print(place[ans])
        exit()
    else:
        place.append(s)
        first.add(s)

print(s)
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor

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


ans = - 10 ** 9

for i in range(1, n+1):
    m = floor(a*i/b) - a*floor(i/b)
    ans = max(ans, m)
    
print(ans)

Fixed submission:
from math import floor

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

if a == 1 or b == 1:
    print(0)
elif n < b:
    print(floor(a*n/b))
else:
    print(floor(a*(b-1)/b))
Buggy python submission (verdict: Runtime Error):
s, w = map(int, input().split())

if s =< w:
    print('unsafe')
else:
    print('safe')

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

if s <= w:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
s = str(input())
s_count = Counter(list(s))

ans = 1
count = 0

for i, j in s_count.items():
    count += 1
    ans *= j

if count < 3:
    ans = 0
    

for i in range(n):
    k = 1

    while i + 2 * k < n:
        l = [s[i], s[i+k], s[i+2*k]]
        if l.count('R') == 1 and l.count('G') == 1 and l.count('B') == 1:
            ans -= 1
        
        k += 1
    
print(ans)

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

count = [0] * 3

for i in range(n):
    if s[i] == 'R':
        count[0] += 1
    if s[i] == 'G':
        count[1] += 1
    if s[i] == 'B':
        count[2] += 1

ans = count[0] * count[1] * count[2]

for i in range(n):
    k = 1
    while i + 2 * k < n:
        l = []
        l.append(s[i])
        l.append(s[i+k])
        l.append(s[i+2*k])
        if l.count('R') == 1 and l.count('G') == 1 and l.count('B') == 1:
            ans -= 1
        
        k += 1

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

n, x, y = map(int, input().split())
x -= 1
y -= 1

ans = [0] * (n+1)
INF = 10 ** 10

for i in range(n):
    distance = [INF] * n
    q = deque([])
    distance[i] = 0
    q.append(i)
    while len(q) > 0:
        v = q.popleft()
        if v - 1 >= 0:
            if distance[v-1] == INF:
                q.append(v-1) 
                distance[v-1] = distance[v] + 1
        if v + 1 < n:
            if distance[v+1] == INF:
                q.append(v+1)
                d = distance[v] + 1
                distance[v+1] = distance[v] + 1
        if v == x:
            if distance[y] == INF:
                q.append(y)
                distance[y] = distance[v] + 1
        if v == y:
            if distance[x] == INF:
                q.append(x)
                distance[x] = distance[v] + 1
    for i in range(n):
        ans[distance[i]] += 1

for i in range(1, n):
    ans[i] //= 2
    print(ans[i])

Fixed submission:
from collections import deque

n, x, y = map(int, input().split())
x -= 1
y -= 1

ans = [0] * (n+1)
INF = 10 ** 10

for i in range(n):
    distance = [INF] * n
    q = deque([])
    distance[i] = 0
    q.append(i)
    while len(q) > 0:
        v = q.popleft()
        if v - 1 >= 0:
            if distance[v-1] == INF:
                q.append(v-1) 
                distance[v-1] = distance[v] + 1
        if v + 1 < n:
            if distance[v+1] == INF:
                q.append(v+1)
                d = distance[v] + 1
                distance[v+1] = distance[v] + 1
        if v == x:
            if distance[y] == INF:
                q.append(y)
                distance[y] = distance[v] + 1
        if v == y:
            if distance[x] == INF:
                q.append(x)
                distance[x] = distance[v] + 1
    for i in range(n):
        ans[distance[i]] += 1

for i in range(1, n):
    ans[i] //= 2
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
import math

def P(n, r):
    if n == 1 or 0:
        return 0
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    return P(n, r)//math.factorial(r)

n, m = map(int, input().split())

print(C(n, 2) + C(m, 2))

Fixed submission:
import math

def P(n, r):
    if n < r:
        return 0
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    return P(n, r)//math.factorial(r)

n, m = map(int, input().split())

print(C(n, 2) + C(m, 2))

Buggy python submission (verdict: Runtime Error):
import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    if n == 1:
        return 0
    return P(n, r)//math.factorial(r)

n, m = map(int, input().split())

print(C(n, 2) + C(m, 2))

Fixed submission:
import math

def P(n, r):
    if n < r:
        return 0
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    return P(n, r)//math.factorial(r)

n, m = map(int, input().split())

print(C(n, 2) + C(m, 2))
Buggy python submission (verdict: Runtime Error):
import math

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

k = a + b + 2 * math.sqrt(a * b)) / c - 1

if k < 0:
    print("Yes")
else:
    print("No")

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

if c - a - b > 0 and (c - a - b) ** 2  > 4 * a * b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

n, m = map(int, input().split())

num = [''] * n

if m == 0:
    for i in range(n):
        num[i] = '0'
    if n != 1:
        num[0] = '1'
    print(''.join(num))
    exit()

sc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))

last = sc[0][0]
num[last-1] = str(sc[i][1])
number = True

if last != 1:
    num[0] = '1'

for i in range(m):
    if sc[i][0] == 1 and sc[i][1] == 0:
        number = False
    if sc[i][0] == last and num[last-1] != '':
        if num[last-1] != sc[i][1]:
            number = False
    last = sc[i][0]
    num[last-1] = str(sc[i][1])

for i in range(n):
    if num[i] == '':
        num[i] = '0'
        
if number:
    print(''.join(num))
else:
    print(-1)


Fixed submission:
from operator import itemgetter

n, m = map(int, input().split())

num = [''] * n

if m == 0:
    for i in range(n):
        num[i] = '0'
    if n != 1:
        num[0] = '1'
    print(''.join(num))
    exit()

sc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))

last = sc[0][0]
num[last-1] = str(sc[0][1])
number = True

if last != 1:
    num[0] = '1'

for i in range(m):
    if n != 1 and sc[i][0] == 1 and sc[i][1] == 0:
        number = False
    if sc[i][0] == last and num[last-1] != '':
        if num[last-1] != str(sc[i][1]):
            number = False
    last = sc[i][0]
    num[last-1] = str(sc[i][1])

for i in range(n):
    if num[i] == '':
        num[i] = '0'

if number:
    print(''.join(num))
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

n, m = map(int, input().split())

num = [''] * n

if m == 0:
    for i in range(n):
        num[i] = '0'
    if n != 1:
        num[0] = '1'
    print(''.join(num))

sc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))

last = sc[0][0]
num[last-1] = str(sc[0][1])
number = True

if last != 1:
    num[0] = '1'

for i in range(m):
    if n != 1 and sc[i][0] == 1 and sc[i][1] == 0:
        number = False
    if sc[i][0] == last and num[last-1] != '':
        if num[last-1] != str(sc[i][1]):
            number = False
    last = sc[i][0]
    num[last-1] = str(sc[i][1])

for i in range(n):
    if num[i] == '':
        num[i] = '0'

if number:
    print(''.join(num))
else:
    print(-1)

Fixed submission:
from operator import itemgetter

n, m = map(int, input().split())

num = [''] * n

if m == 0:
    for i in range(n):
        num[i] = '0'
    if n != 1:
        num[0] = '1'
    print(''.join(num))
    exit()

sc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))

last = sc[0][0]
num[last-1] = str(sc[0][1])
number = True

if last != 1:
    num[0] = '1'

for i in range(m):
    if n != 1 and sc[i][0] == 1 and sc[i][1] == 0:
        number = False
    if sc[i][0] == last and num[last-1] != '':
        if num[last-1] != str(sc[i][1]):
            number = False
    last = sc[i][0]
    num[last-1] = str(sc[i][1])

for i in range(n):
    if num[i] == '':
        num[i] = '0'

if number:
    print(''.join(num))
else:
    print(-1)