Problem p02761 (python)

Fixed submission:
import sys

n,m = map(int,input().split())
sc = []

if m == 0 and n == 1:
  print(0)
  sys.exit()
elif m == 0 and n != 1:
  print(10**n // 10)
  sys.exit()


for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if n == 1:
  tmp = 0
  for i in range(m):
    if sc[i][0] == 1 and sc[i][1] == 0:
      tmp += 1
    if tmp == m:
      print(0)
      sys.exit()

if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

ans = [-1 for _ in range(n)]
for i in range(m):
  if ans[sc[i][0]-1] == -1:
    ans[sc[i][0]-1] = sc[i][1]
  else:
    if ans[sc[i][0]-1] != sc[i][1]:
      print('-1')
      sys.exit()

res = ''
if ans[0] == -1:
  ans[0] = 1
for i in range(n):
  if ans[i] == -1:
    ans[i] = 0
  res = res + str(ans[i])

print(res)

Buggy submission (verdict: Runtime Error):
import sys

n,m = map(int,input().split())
sc = []

for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if n == 1:
  print(sc[0][1])
  sys.exit()
if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

ans = [-1 for _ in range(n)]
for i in range(m):
  if ans[sc[i][0]-1] == -1:
    ans[sc[i][0]-1] = sc[i][1]
  else:
    if ans[sc[i][0]-1] != sc[i][1]:
      print('-1')
      sys.exit()

res = ''
if ans[0] == 0:
  ans[0] = 1
for i in range(n):
  if ans[i] == -1:
    ans[i] = 0
  res = res + str(ans[i])

print(res)

Buggy submission (verdict: Runtime Error):
import sys

n,m = map(int,input().split())
sc = []

for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if n == 1:
  print(sc[0][1])
  sys.exit()
if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

num = 0
while len(sc) > num+1:
  if sc[num][0] == sc[num+1][0]:
    if sc[num][1] == sc[num+1][1]:
      del sc[num]
      num = 0
      continue
    else:
      print('-1')
      sys.exit()
  num += 1

ans = [0 for _ in range(n)]
for i in range(len(sc)):
  ans[sc[i][0]-1] = sc[i][1]
if ans[0] == 0:
  ans[0] = 1

res = ''
for i in range(len(ans)):
  res = res + str(ans[i])

print(res)

Buggy submission (verdict: Runtime Error):
import sys

n,m = map(int,input().split())
sc = []

for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if m == 1:
  print(sc[0][1])
  sys.exit()
if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

num = 0
while len(sc) > num+1:
  if sc[num][0] == sc[num+1][0]:
    if sc[num][1] == sc[num+1][1]:
      del sc[num]
      num = 0
      continue
    else:
      print('-1')
      sys.exit()
  num += 1

ans = [0 for _ in range(n)]
for i in range(len(sc)):
  ans[sc[i][0]-1] = sc[i][1]
if ans[0] == 0:
  ans[0] = 1

res = ''
for i in range(len(ans)):
  res = res + str(ans[i])

print(res)

Buggy submission (verdict: Runtime Error):
import sys

n,m = map(int,input().split())
sc = []

for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

num = 0
while len(sc) > num+1:
  if sc[num][0] == sc[num+1][0]:
    if sc[num][1] == sc[num+1][1]:
      del sc[num]
      num = 0
      continue
    else:
      print('-1')
      sys.exit()
  num += 1

ans = [0 for _ in range(n)]
for i in range(len(sc)):
  ans[sc[i][0]-1] = sc[i][1]
if ans[0] == 0:
  ans[0] = 1

res = ''
for i in range(len(ans)):
  res = res + str(ans[i])

print(res)

Buggy submission (verdict: Runtime Error):
import sys

n,m = map(int,input().split())
sc = []

for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

num = 0
while len(sc) > num+1:
  if sc[num][0] == sc[num+1][0]:
    if sc[num][1] == sc[num+1][1]:
      del sc[num]
      num = 0
      continue
    else:
      print('-1')
      sys.exit()
  num += 1

ans = [0 for _ in range(n)]
for i in range(len(sc)):
  ans[sc[i][0]-1] = sc[i][1]

res = ''
for i in range(len(ans)):
  res = res + str(ans[i])

print(res)