Problem p02761 (python)

Fixed submission:
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
 
if m == 0:
  if n == 1:
    print(0)
  elif n == 2:
    print(10)
  else:
    print(100)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  if len(l_1) > 0:
    pv = l_1[0]
    for j in range(len(l_1)):
      if not pv  == l_1[j]:
        nocounter += 1
      if l_1[j] == 0 and n > 1:
        nocounter += 1
  if len(l_2) > 0:
    pv = l_2[0]
    for j in range(len(l_2)):
      if not pv  == l_2[j]:
        nocounter += 1
  if len(l_3) > 0:
    pv = l_3[0]
    for j in range(len(l_3)):
      if not pv  == l_3[j]:
        nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_1[0])
    elif n == 2 and len(l_2)*len(l_1) > 0:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) > 0:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0 and len(l_2) == 0:
      print(100 + l_3[0])
    elif len(l_1) == 0 and len(l_3) == 0:
      print(100 + 10*l_2[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0 and len(l_3) == 0:
      print(100*l_1[0])
    elif len(l_2) == 0 :
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])

Buggy submission (verdict: Runtime Error):
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
 
if m == 0:
  if n == 1:
    print(0)
  elif n == 2:
    print(10)
  else:
    print(100)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  if len(l_1) > 0:
    pv = l_1[0]
    for j in range(len(l_1)):
      if not pv  == l_1[j]:
        nocounter += 1
      if l_1[j] == 0:
        nocounter += 1
  if len(l_2) > 0:
    pv = l_2[0]
    for j in range(len(l_2)):
      if not pv  == l_2[j]:
        nocounter += 1
  if len(l_3) > 0:
    pv = l_3[0]
    for j in range(len(l_3)):
      if not pv  == l_3[j]:
        nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_3[0])
    elif n == 2 and len(l_2)*len(l_1) == 1:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) == 1:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0 and len(l_2) == 0:
      print(100 + l_3[0])
    elif len(l_1) == 0 and len(l_3) == 0:
      print(100 + l_2[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0 and len(l_3) == 0:
      print(100*l_1[0])
    elif len(l_2) == 0 :
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])

Buggy submission (verdict: Runtime Error):
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
answer = 100  
 
if m == 0:
  if n == 1:
    print(0)
  elif n == 2:
    print(10)
  else:
    print(100)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  if len(l_1) > 0:
    pv = l_1[0]
    for j in range(len(l_1)):
      if not pv  == l_1[j]:
        nocounter += 1
      if l_1[j] == 0:
        nocounter += 1
  if len(l_2) > 0:
    pv = l_2[0]
    for j in range(len(l_2)):
      if not pv  == l_2[j]:
        nocounter += 1
  if len(l_3) > 0:
    pv = l_3[0]
    for j in range(len(l_3)):
      if not pv  == l_3[j]:
        nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_3[0])
    elif n == 2 and len(l_2)*lemn(l_1) == 1:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) == 1:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0 and len(l_2) == 0:
      print(100 + l_3[0])
    elif len(l_1) == 0 and len(l_3) == 0:
      print(100 + l_2[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0 and len(l_3) == 0:
      print(100*l_1[0])
    elif len(l_2) == 0 :
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])

Buggy submission (verdict: Runtime Error):
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
answer = 100  
 
if m == 0:
  print(0)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  if len(l_1) > 0:
    pv = l_1[0]
    for j in range(len(l_1)):
      if not pv  == l_1[j]:
        nocounter += 1
      if l_1[j] == 0:
        nocounter += 1
  if len(l_2) > 0:
    pv = l_2[0]
    for j in range(len(l_2)):
      if not pv  == l_2[j]:
        nocounter += 1
  if len(l_3) > 0:
    pv = l_3[0]
    for j in range(len(l_3)):
      if not pv  == l_3[j]:
        nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_3[0])
    elif n == 2 and len(l_2)*lemn(l_1) == 1:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) == 1:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0 and len(l_2) == 0:
      print(100 + l_3[0])
    elif len(l_1) == 0 and len(l_3) == 0:
      print(100 + l_2[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0 and len(l_3) == 0:
      print(100*l_1[0])
    elif len(l_2) == 0 :
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])

Buggy submission (verdict: Runtime Error):
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
answer = 100  
 
if m == 0:
  print(0)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  if len(l_1) > 0:
    pv = l_1[0]
    for j in range(len(l_1)):
      if not pv  == l_1[j]:
        nocounter += 1
      if l_1[j] == 0:
        nocounter += 1
  if len(l_2) > 0:
    pv = l_2[0]
    for j in range(len(l_2)):
      if not pv  == l_2[j]:
        nocounter += 1
  if len(l_3) > 0:
    pv = l_3[0]
    for j in range(len(l_3)):
      if not pv  == l_3[j]:
        nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_3[0])
    elif n == 2 and len(l_2)*lemn(l_1) == 1:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) == 1:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0:
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])

Buggy submission (verdict: Runtime Error):
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
answer = 100  
 
if m == 0:
  print(0)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  pv = l_1[0]
  for j in range(len(l_1)):
    if not pv  == l_1[j]:
      nocounter += 1
    if l_1[j] == 0:
      nocounter += 1
  pv = l_2[0]
  for j in range(len(l_2)):
    if not pv  == l_2[j]:
      nocounter += 1
  pv = l_3[0]
  for j in range(len(l_3)):
    if not pv  == l_3[j]:
      nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_3[0])
    elif n == 2 and len(l_2)*lemn(l_1) == 1:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) == 1:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0:
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])

Buggy submission (verdict: Runtime Error):
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
answer = 100  

if m == 0:
  print(0)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  pv = l_1[0]
  for j in range(len(l_1)):
    if not pv  == l_1[j]:
      nocounter += 1
    if l_1[j] == 0:
      nocounter += 1
  pv = l_2[0]
  for j in range(len(l_2)):
    if not pv  == l_2[j]:
      nocounter += 1
  pv = l_3[0]
  for j in range(len(l_3)):
    if not pv  == l_3[j]:
      nocounter += 1
  if nocoutner > 0:
    print(-1)
  else:
    if n == 1:
      print(l_3[0])
    elif n == 2 && len(l_2)*lemn(l_1) == 1:
      print(10*l_1[0] + l_2[0])
    elif n == 2 && len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 && len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) == 1:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0:
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])