Problem p02761 (python)

Fixed submission:
n,m = list(map(int, input().split()))
x = []
ans = [0]*n
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)

if (n == 1) and (m == 0):
  print(0)
elif m == 0:
  ans[0] = 1
  for i in range(len(ans)):
    answ += ans[i]*(10**(n-1-i))
    
  print(answ)
elif has_duplicates(s):
  print(-1)
elif (n == 1) and (c.count(0) == 1):
  print(0)
else:
  for i,j in x:
    ans[i-1] = j
    
  if (ans[0] == 0) and (s.count(1) == 0):
    ans[0] = 1
    
  for i in range(len(ans)):
    answ += ans[i]*(10**(n-1-i))

  if ans[0] == 0:
    print(-1)
  else:
    print(answ)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
x = []
ans = [0]*m
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)
  
if m == 0:
  print(-1)
#sに重複があれば－１を出力
elif has_duplicates(s):
  print(-1)
else:
  for i,j in x:
    ans[i-1] = j
    
  if (ans[0] == 0) and (s.count(1) == 0):
    ans[0] = 1
    
  for i in range(len(ans)):
    answ += ans[i]*(10**(m-1-i))

  if ans[0] == 0:
    print(-1)
  else:
    print(answ)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
x = []
ans = [0]*m
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)
  
#sに重複があれば－１を出力
if m == 0:
  print(-1)
elif has_duplicates(s):
  print(-1)
else:
  for i,j in x:
    ans[i-1] = j
    
  for i in range(len(ans)):
    answ += ans[i]*(10**(m-1-i))

  if ans[0] == 0:
    print(-1)
  else:
    print(answ)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
x = []
ans = [0]*m
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)
  
#sに重複があれば－１を出力
if m == 0:
  print(-1)
elif has_duplicates(s):
  print(-1)
else:
  for i,j in x:
    ans[i-1] = j
    
  for i in range(len(ans)):
    answ += ans[i]*(10**(m-1-i))

    if ans[0] != 0:
      print(answ)
    else:
      print(-1)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
x = []
ans = [0]*m
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)
  
#sに重複があれば－１を出力
if has_duplicates(s):
  print(-1)
else:
  for i,j in x:
    ans[i-1] = j
    
  if ans.count(0) == m:
    print(-1)
  else:
    for i in range(len(ans)):
      answ += ans[i]*(10**(m-1-i))
    
    if len(str(answ)) == n:
    	print(answ)
    else:
      print(-1)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
x = []
ans = [0]*m
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)
  
#sに重複があれば－１を出力
if has_duplicates(s):
  print(-1)
else:
  for i,j in x:
    ans[i-1] = j
    
  if ans.count(0) == m:
    print(-1)
  else:
    for i in range(len(ans)):
      answ += ans[i]*(10**(m-1-i))
    
    print(answ)