Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
inf = input().split()
N = int(inf[0])
K = int(inf[1])
if K > (N-1)*(N-2)//2:
  print(-1)
else:
  if K==(N-1)*(N-2)//2:
    len(K)
    for i in range(2,N+1):
      print(1,i)
  else:
    ls = [i for i in range(1,N+1)]
    ls = list(combinations(ls,2))
    dic = {x:0 for x in ls}
    for i in range(2,N+1):
      dic[(1,i)] = 1
    m = (N-1)*(N-2)//2
    while m>K:
      for x in ls:
        if dic[x]==0:
          dic[x]=1
          m-=1
          break
    ans = [i for i in dic.keys() if dic[i]==1]
    print(len(ans))
    for x in ans:
      print(x[0], x[1])


Fixed submission:
from itertools import combinations
inf = input().split()
N = int(inf[0])
K = int(inf[1])
if K > (N-1)*(N-2)//2:
  print(-1)
else:
  if K==(N-1)*(N-2)//2:
    print(N-1)
    for i in range(2,N+1):
      print(1,i)
  else:
    ls = [i for i in range(1,N+1)]
    ls = list(combinations(ls,2))
    dic = {x:0 for x in ls}
    for i in range(2,N+1):
      dic[(1,i)] = 1
    m = (N-1)*(N-2)//2
    while m>K:
      for x in ls:
        if dic[x]==0:
          dic[x]=1
          m-=1
          break
    ans = [i for i in dic.keys() if dic[i]==1]
    print(len(ans))
    for x in ans:
      print(x[0], x[1])

Buggy python submission (verdict: Runtime Error):
from itertools import combinations
inf = input().split()
N = int(inf[0])
K = int(inf[1])
if K > (N-1)*(N-2)//2:
  print(-1)
else:
  if K==(N-1)*(N-2)//2:
    for i in range(2,N+1):
      print(1,i)
  else:
    ls = [i for i in range(1,N+1)]
    ls = list(combinations(ls,2))
    dic = {x:0 for x in ls}
    for i in range(2,N+1):
      dic[(1,i)] = 1
    m = (N-1)*(N-2)//2
    rem = []
    while m>K:
      for x in ls:
        if dic[x]==0:
          rem += [x]
          dic[x]=1
          m-=1
          continue
  ans = [i for i in dic.keys() if i not in rem]
  for x in ans:
    print(x[0], x[1])

Fixed submission:
from itertools import combinations
inf = input().split()
N = int(inf[0])
K = int(inf[1])
if K > (N-1)*(N-2)//2:
  print(-1)
else:
  if K==(N-1)*(N-2)//2:
    print(N-1)
    for i in range(2,N+1):
      print(1,i)
  else:
    ls = [i for i in range(1,N+1)]
    ls = list(combinations(ls,2))
    dic = {x:0 for x in ls}
    for i in range(2,N+1):
      dic[(1,i)] = 1
    m = (N-1)*(N-2)//2
    while m>K:
      for x in ls:
        if dic[x]==0:
          dic[x]=1
          m-=1
          break
    ans = [i for i in dic.keys() if dic[i]==1]
    print(len(ans))
    for x in ans:
      print(x[0], x[1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M,*L = map(int, open(0).read().split())
S = L[:N]
T = L[N:]
MOD = 10**9+7
dp = [[0]*(M+1) for i in range(N+1)]
for i in range(N+1):
  dp[i][0] = 1
for j in range(M+1):
  dp[0][j] = 1
for i in range(1,N+1):
  for j in range(1,M+1):
    if S[i-1]==T[j-1]:
      dp[i][j] += dp[i][j-1]+dp[i-1][j]
    else:
      dp[i][j] += dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]
    dp[i][j] %= MOD
print(dp[N][M])

Fixed submission:
N, M = map(int, input().split())
s = [int(c) for c in input().split()]
t = [int(c) for c in input().split()]
MOD = 10**9+7

dp = [[0]*(M+1) for i in range(N+1)]
dp_cum = [[0]*(M+1) for i in range(N+1)]

dp[0][0] = 1
for i in range(N+1):
  dp_cum[i][0] = 1
for j in range(M+1):
  dp_cum[0][j] = 1
  
for i in range(N):
  for j in range(M):
    if s[i]!=t[j]:
      dp[i+1][j+1] = 0
    else:
      dp[i+1][j+1] = dp_cum[i][j]
    dp_cum[i+1][j+1] = dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1]
    dp_cum[i+1][j+1] %= MOD

print(dp_cum[-1][-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
MOD = 10**9+7
N, M = map(int, input().split())
s = np.array(input().split(), dtype=np.int32)
t = np.array(input().split(), dtype=np.int32)

dp = np.zeros((N+1,M+1), dtype=np.int64)
dp[0] = 1

for i in range(N):
  same = (s[i]==t)
  dp[i+1,1:][same] = dp[i,:-1][same]
  dp[i+1] = (dp[i+1].cumsum()+dp[i])%MOD

print(dp[-1,-1])

Fixed submission:
N, M = map(int, input().split())
s = [int(c) for c in input().split()]
t = [int(c) for c in input().split()]
MOD = 10**9+7

dp = [[0]*(M+1) for i in range(N+1)]
dp_cum = [[0]*(M+1) for i in range(N+1)]

dp[0][0] = 1
for i in range(N+1):
  dp_cum[i][0] = 1
for j in range(M+1):
  dp_cum[0][j] = 1
  
for i in range(N):
  for j in range(M):
    if s[i]!=t[j]:
      dp[i+1][j+1] = 0
    else:
      dp[i+1][j+1] = dp_cum[i][j]
    dp_cum[i+1][j+1] = dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1]
    dp_cum[i+1][j+1] %= MOD

print(dp_cum[-1][-1])
Buggy python submission (verdict: Runtime Error):
import fractions
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
dic = {}
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    size = fractions.gcd(vec[0],vec[1])
    vec[0] = vec[0]//size
    vec[1] = vec[1]//size
    vec = tuple(vec)
    if vec not in dic.keys():
      dic[vec] = set([j])
    else:
      dic[vec].add(j)
m = 1
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)


Fixed submission:
line = input().split()
N = int(line[0])
K = int(line[1])

if K==1:
  ans = 0
else:
  ans = N-K

print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
source = map(int, input().split())
source = list(source)
score = sum(souce)
for i in range(1, len(source)):
  value = sum(souce[:i])-sum(souce[i:])
  value = abs(value)
  if score > value:
    score = value
print(score)

Fixed submission:
n = input()
line = map(int, input().split())
line = list(line)
m = abs(sum(line))
for i in range(1, len(line)):
  score = abs(sum(line[:i]) - sum(line[i:]))
  if m > score:
    m = score
print(m)
Buggy python submission (verdict: Runtime Error):
inf = input().split()
N = int(inf[0])
M = int(inf[1])
ls = []
for i in range(M):
  a = int(input())
  ls += [a]
step = [0 for i in range(N)]
if 1 not in ls:
  step[0] = 1
if 2 not in ls:
  step[1] = 1 + step[0]
for j in range(2, N):
  if j not in ls:
    step[j] = step[j-1]+step[j-2]
  else:
    step[j] = 0
ans = step[N-1]%(10^9+7)
print(ans)

Fixed submission:
line = input().split()
N = int(line[0])
M = int(line[1])
broken = []
count = 0
step = []
def check(value):
  if count < M:
    return broken[count]==value
  else:
    return False
for i in range(M):
  a = int(input())
  broken += [a]
if check(1):
  step+=[0]
  count += 1
else:
  step +=[1]
if check(2):
  step += [0]
  count += 1
else:
  step += [1+step[0]]
for j in range(2, N):
  if check(j+1):
    step += [0]
    count += 1
  else:
    step += [step[j-2]+step[j-1]]
ans = step[N-1]%(10**9+7)
print(ans)
Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
N, *L = map(int, open('0').read().split())
dic = [[] for i in range(N)]
ans = [-1]*N
cnt = [0]*N
hq = []
for a,b in zip(*[iter(L[:2*(N-1)])]*2):
  a -= 1
  b -= 1
  dic[a] += [b]
  dic[b] += [a]
  cnt[a] += 1
  cnt[b] += 1
C = L[2*(N-1):]
C.sort()
for i in range(N):
  heappush(hq,(cnt[i],i))
arg = 0
m = sum(C)-C[-1]
while True:
  c, i = heappop(hq)
  if ans[i]!=-1:
    continue
  ans[i] = C[arg]
  arg += 1
  if arg==N:
    break
  for v in dic[i]:
    cnt[v] -= 1
    heappush(hq,(cnt[v],v))
print(m)
print(*ans)

Fixed submission:
from heapq import heappush, heappop
N, *L = map(int, open(0).read().split())
dic = [[] for i in range(N)]
ans = [-1]*N
cnt = [0]*N
hq = []
for a,b in zip(*[iter(L[:2*(N-1)])]*2):
  a -= 1
  b -= 1
  dic[a] += [b]
  dic[b] += [a]
  cnt[a] += 1
  cnt[b] += 1
C = L[2*(N-1):]
C.sort()
for i in range(N):
  heappush(hq,(cnt[i],i))
arg = 0
m = 0
while True:
  c, i = heappop(hq)
  if ans[i]!=-1:
    continue
  m += C[arg]*cnt[i]
  ans[i] = C[arg]
  arg += 1
  if arg==N:
    break
  for v in dic[i]:
    cnt[v] -= 1
    heappush(hq,(cnt[v],v))
print(m)
print(*ans)

Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
N, *L = map(int, open('0').read().split())
dic = [[] for i in range(N)]
ans = [-1]*N
cnt = [0]*N
hq = []
for a,b in zip(*[iter(L[:2*(N-1)])]*2):
  a -= 1
  b -= 1
  dic[a] += [b]
  dic[b] += [a]
  cnt[a] += 1
  cnt[b] += 1
C = L[2*(N-1):]
C.sort()
for i in range(N):
  heappush(hq,(cnt[i],i))
arg = 0
m = 0
while True:
  c, i = heappop(hq)
  if ans[i]!=-1:
    continue
  m += C[arg]*cnt[i]
  ans[i] = C[arg]
  arg += 1
  if arg==N:
    break
  for v in dic[i]:
    cnt[v] -= 1
    heappush(hq,(cnt[v],v))
print(m)
print(*ans)

Fixed submission:
from heapq import heappush, heappop
N, *L = map(int, open(0).read().split())
dic = [[] for i in range(N)]
ans = [-1]*N
cnt = [0]*N
hq = []
for a,b in zip(*[iter(L[:2*(N-1)])]*2):
  a -= 1
  b -= 1
  dic[a] += [b]
  dic[b] += [a]
  cnt[a] += 1
  cnt[b] += 1
C = L[2*(N-1):]
C.sort()
for i in range(N):
  heappush(hq,(cnt[i],i))
arg = 0
m = 0
while True:
  c, i = heappop(hq)
  if ans[i]!=-1:
    continue
  m += C[arg]*cnt[i]
  ans[i] = C[arg]
  arg += 1
  if arg==N:
    break
  for v in dic[i]:
    cnt[v] -= 1
    heappush(hq,(cnt[v],v))
print(m)
print(*ans)
Buggy python submission (verdict: Runtime Error):
inf = input().split()
N = int(inf[0])
K = int(inf[1])
line = [int(v) for v in input().split()]

ans = 0
if K<N:
  for k in range(K+1):
    for i in range(k+1):
      item = line[:i]+line[N-k+i:]
      item.sort()
      count = 0
      while count<K-k and item:
        if item[0]>0:
          break
        item = item[1:]
        count += 1
      s = sum(item)
      if s>ans:
        ans = s
else:
  line.sort()
  count = 0
  while line[0]<0 and count<K:
    line = line[1:]
    count+=1
  s = sum(line)
  if s>ans:
    ans = s

print(ans)

Fixed submission:
inf = input().split()
N = int(inf[0])
K = int(inf[1])
line = [int(v) for v in input().split()]

ans = 0
if K<N:
  for k in range(K+1):
    for i in range(k+1):
      item = line[:i]+line[N-k+i:]
      item.sort()
      count = 0
      while count<K-k and item:
        if item[0]>0:
          break
        item = item[1:]
        count += 1
      s = sum(item)
      if s>ans:
        ans = s
else:
  line = [i for i in line if i>0]
  ans = sum(line)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
inf = input().split()
N = int(inf[0])
M = int(inf[1])
ls = []
m = 0
for i in range(M):
  inf = input().split()
  L = int(inf[0])-1
  R = int(inf[1])-1
  x = max(L,R)
  if x > m:
    m = x
  ls += [(L,R)]

ans = [True]*(m+1)

for s in ls:
  ans[:s[0]] = [False]*len(ans[:s[0]])
  ans[s[1]+1:] = [False]*len(ans[s[1]+1:])

print(sum(ans))

Fixed submission:
inf = input().split()
N = int(inf[0])
M = int(inf[1])
ls = []
m = 0
pair = [0,N]
for i in range(M):
  inf = input().split()
  L = int(inf[0])
  R = int(inf[1])
  pair[0] = max(pair[0], L)
  pair[1] = min(pair[1], R)
  if pair[0]>pair[1]:
    print(0)
    break
else:
  print(pair[1]-pair[0]+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

dic = [[] for i in range(N)]
for i in range(N-1):
  inf = input().split()
  u = int(inf[0])
  v = int(inf[1])
  w = int(inf[2])
  dic[u-1] +=[(v-1, w)]
  dic[v-1] +=[(u-1, w)]

dist = [-1]*N
stack = []
stack.append(0)
dist[0] = 0

while stack:
  label = stack.pop(-1)
  for i, c in dic[label]:
    if dist[i] == -1:
      dist[i] = dist[label]+c
      stack += [i]

ls = [0]
print(0)
for i in range(1,N):
  j = i-1
  for j in range(i):
    if (dist[j]+dist[i])%2==1:
      print((ls[j]+1)%2)
      ls += [(ls[j]+1)%2]
      break
  else:
    print(ls[i-1])
    ls += [ls[i-1]]



Fixed submission:
N = int(input())

dic = [[] for i in range(N)]
for i in range(N-1):
  inf = input().split()
  u = int(inf[0])
  v = int(inf[1])
  w = int(inf[2])
  dic[u-1] +=[(v-1, w)]
  dic[v-1] +=[(u-1, w)]

dist = [-1]*N
stack = []
stack.append(0)
dist[0] = 0

while stack:
  label = stack.pop(-1)
  for i, c in dic[label]:
    if dist[i] == -1:
      dist[i] = dist[label]+c
      stack += [i]

ls = [0]
print(0)
for i in range(1,N):
  if dist[i]%2==0:
    print(0)
  else:
    print(1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

dic = [[] for i in range(N)]
for i in range(N-1):
  inf = input().split()
  u = int(inf[0])
  v = int(inf[1])
  w = int(inf[2])
  dic[u-1] +=[(v-1, w)]
  dic[v-1] +=[(u-1, w)]

dist = [-1]*N
stack = []
stack.append(0)
dist[0] = 0

while stack:
  label = stack.pop(-1)
  for i, c in dic[label]:
    if dist[i] == -1:
      dist[i] = dist[label]+c
      stack += [i]

ls = [0]
print(0)
for i in range(1,N):
  j = i-1
  for j in range(i):
    if (dist[j]+dist[i])%2==1:
      print((ls[j]+1)%2)
      ls += [(ls[j]+1)%2]
      break
  else:
    print(ls[i-1])
    ls += [ls[i-1]]



Fixed submission:
N = int(input())

dic = [[] for i in range(N)]
for i in range(N-1):
  inf = input().split()
  u = int(inf[0])
  v = int(inf[1])
  w = int(inf[2])
  dic[u-1] +=[(v-1, w)]
  dic[v-1] +=[(u-1, w)]

dist = [-1]*N
stack = []
stack.append(0)
dist[0] = 0

while stack:
  label = stack.pop(-1)
  for i, c in dic[label]:
    if dist[i] == -1:
      dist[i] = dist[label]+c
      stack += [i]

ls = [0]
print(0)
for i in range(1,N):
  if dist[i]%2==0:
    print(0)
  else:
    print(1)
Buggy python submission (verdict: Runtime Error):
N,*L = open('0').read().split()

ans = 0
a = 0
b = 0
for s in L:
  for j in range(len(s)-1):
    if s[j]=='A' and s[j+1]=='B':
      ans += 1
  if s[-1]=='A':
    a += 1
  if s[0]=='B':
    b += 1
ans += min(a,b)
print(ans)
  

Fixed submission:
N,*L = open(0).read().split()

ans = 0
a = 0
b = 0
c = 0
for s in L:
  for j in range(len(s)-1):
    if s[j]=='A' and s[j+1]=='B':
      ans += 1
  if s[-1]=='A' and s[0]=='B':
    c += 1
  elif s[-1]=='A':
    a += 1
  elif s[0]=='B':
    b += 1
if c!=0:
  if a+b>0:
    ans += c+min(a,b)
  else:
    ans += c-1
else:
  ans += min(a,b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
INF = 10**9
sheet = []
score = [[INF]*W for i in range(H)]
step = [(-1,0),(1,0),(0,-1),(0,1)]
stuck = []
ans = -1

for i in range(H):
  line = input()
  for j in range(W):
    if line[j]=='#':
      stuck += [(i,j,0)]
      score[i][j] = 0
      
while stuck:
  y, x, m = stuck.pop()
  for s in step:
    dx, dy = s
    if x+dx<0 or x+dx>W-1 or y+dy<0 or y+dy>H-1:
      continue
    if score[y+dy][x+dx]>m+1:
      score[y+dy][x+dx]=m+1
      stuck += [(y+dy, x+dx, m+1)]
      
for i in range(H):
  ans = max(ans, *score[i])
  
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
INF = 10**9
sheet = []
log = [[True]*W for i in range(H)]
step = [(-1,0),(1,0),(0,-1),(0,1)]
stuck = deque()
ans = 0

for i in range(H):
  line = input()
  for j in range(W):
    if line[j]=='#':
      stuck += [(i,j,0)]
      log[i][j] = False
      
while stuck:
  y, x, m = stuck.popleft()
  for s in step:
    dx, dy = s
    if x+dx<0 or x+dx>W-1 or y+dy<0 or y+dy>H-1:
      continue
    if log[y+dy][x+dx]:
      log[y+dy][x+dx]=False
      stuck += [(y+dy, x+dx, m+1)]
      if ans<m+1:
        ans = m+1
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
from collections import deque

N = int(input())

line = [int(a) for a in input().split()]
line = deque(line)

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)


Fixed submission:
from fractions import gcd
from collections import deque

N = int(input())
A = [int(a) for a in input().split()]
L = deque([0])
R = deque([0])

for i in range(N):
  L.append(gcd(L[i],A[i]))
for i in range(N)[::-1]:
  R.appendleft(gcd(R[0],A[i]))

ans = []
for i in range(N):
  ans += [gcd(L[i], R[i+1])]
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
from collections import deque

N = int(input())

line = [int(a) for a in input().split()]
line = deque(line)

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)

Fixed submission:
from fractions import gcd
from collections import deque

N = int(input())
A = [int(a) for a in input().split()]
L = deque([0])
R = deque([0])

for i in range(N):
  L.append(gcd(L[i],A[i]))
for i in range(N)[::-1]:
  R.appendleft(gcd(R[0],A[i]))

ans = []
for i in range(N):
  ans += [gcd(L[i], R[i+1])]
print(max(ans))

Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
from collections import deque

N = int(input())

line = [int(a) for a in input().split()]
line = deque(line)

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)

Fixed submission:
from fractions import gcd
from collections import deque

N = int(input())
A = [int(a) for a in input().split()]
L = deque([0])
R = deque([0])

for i in range(N):
  L.append(gcd(L[i],A[i]))
for i in range(N)[::-1]:
  R.appendleft(gcd(R[0],A[i]))

ans = []
for i in range(N):
  ans += [gcd(L[i], R[i+1])]
print(max(ans))
Buggy python submission (verdict: Runtime Error):
inf = input().split()
X = int(inf[0])
Y = int(inf[1])
Z = int(inf[2])
K = int(inf[3])

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ab = []
for a in A:
  for b in B:
    ab +=[a+b]
ab.sort(reverse=True)
C.sort(reverse=True)
state = [ab[0]+i for i in C]
count  = 0
while count<K:
  x = max(state)
  print(x)
  count += 1
  i = state.index(x)
  j = ab.index(x-C[i])
  if j<X*Y-1:
    state[i] = ab[j+1]+C[i]
  else:
    state[i]=-1

Fixed submission:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
ls = [A,B,C,D,E]
X = min((A,B,C,D,E))
s=N//X
if N%X==0:
  s-=1
print(s+5)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
t= [0]*(N+1)
for i in range(N):
  t[i+1] = t[i] +(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1]-t[l-1])


Fixed submission:
dic={}
dic['A'] = 'T'
dic['C'] = 'G'
dic['G'] = 'C'
dic['T'] = 'A'
b = input()
print(dic[b])
Buggy python submission (verdict: Time Limit Exceeded):
inf = input().split()
N = int(inf[0])
Q = int(inf[1])
S = input()
ans = []
for i in range(Q):
  inf = input().split()
  l = int(inf[0])-1
  r = int(inf[1])
  ans += [(S[l:r].count('AC'))]
for a in ans:
  print(a)
  

Fixed submission:
N, Q = map(int, input().split())
S = input()
t= [0]*(N+1)
for i in range(N):
  t[i+1] = t[i] +(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1]-t[l-1])
Buggy python submission (verdict: Runtime Error):
N,*B = map(int, open('0').read().split())
ans = [0]*N
for i in range(N):
  for j in range(len(B)-1,-1,-1):
    if B[j]==j+1:
      ans[N-1-i] = j+1
      B = B[:j]+B[j+1:]
      break
print('\n'.join(map(str,ans)))

Fixed submission:
N,*B = map(int, open(0).read().split())
ans = [0]*N
for i in range(N):
  for j in range(len(B)-1,-1,-1):
    if B[j]==j+1:
      ans[N-1-i] = j+1
      B = B[:j]+B[j+1:]
      break
if B==[]:
  print('\n'.join(map(str,ans)))
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
MOD = 10**9+7
P2 = [1]
for i in range(N):
  P2 += [(P2[-1]*2)%MOD]
pre = [-1]*(N+1)
p = -1
end = 0
ans = 1
for i in range(N):
  c = int(input())
  if pre[c]!=-1:
    if p==c:
      continue
    ans += P2[pre[c]]
    end += 1
    pre[c] = end
  else:
    pre[c] = end
  p = c
print(ans%MOD)

Fixed submission:
from collections import defaultdict
N = int(input())
MOD = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
dic = defaultdict(int)
p = -1
for i in range(N):
  c = int(input())
  if c==p:
    dp[i+1] = dp[i]
    continue
  dic[c] += dp[i]
  dp[i+1] = dic[c]%MOD
  p = c
#  print(dp)

print(dp[-1]%MOD)

Buggy python submission (verdict: Runtime Error):
N = int(input())
MOD = 10**9+7
P2 = [1]
for i in range(N):
  P2 += [(P2[-1]*2)%MOD]
pre = [-1]*N
p = -1
end = 0
ans = 1
for i in range(N):
  c = int(input())
  if pre[c]!=-1:
    if p==c:
      continue
    ans += P2[pre[c]]
    end += 1
    pre[c] = end
  else:
    pre[c] = end
  p = c
print(ans)

Fixed submission:
from collections import defaultdict
N = int(input())
MOD = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
dic = defaultdict(int)
p = -1
for i in range(N):
  c = int(input())
  if c==p:
    dp[i+1] = dp[i]
    continue
  dic[c] += dp[i]
  dp[i+1] = dic[c]%MOD
  p = c
#  print(dp)

print(dp[-1]%MOD)
Buggy python submission (verdict: Runtime Error):
def cmb(n,r):
  r = min(r, n-r)
  if r==0: return 1
  if r<0: return 0
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1,r+1))
  return over//under

class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.size = [1]*n
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      self.size[y] += self.size[x]
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
      self.size[x] += self.size[y]
    else:
      self.par[y] = x
      self.size[x] += self.size[y]
      self.rank[x] += 1
      
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
  def count(self, x):
    return self.size[x]

N, M = map(int, input().split())
bridge = []
u = UnionFind(N)
m = cmb(N,2)
ans = [m]

for i in range(M):
  A, B = map(int, input().split())
  bridge += [(A,B)]
  
for i in range(M-1,0,-1):
  a, b = bridge[i]
  if u.same(a-1,b-1):
    ans += [m]
    continue
  pa = u.find(a-1)
  pb = u.find(b-1)
  m -= u.count(pa)*u.count(pb)
  ans += [m]
  u.unit(a-1,b-1)

for i in range(M-1,-1,-1):
  print(ans[i])
  

Fixed submission:
from functools import reduce
from operator import mul

def cmb(n,r):
  r = min(r, n-r)
  if r==0: return 1
  if r<0: return 0
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1,r+1))
  return over//under

class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.dic = {i:1 for i in range(n)}
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      self.dic[y] += self.dic.pop(x)
      
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
      self.dic[x] += self.dic.pop(y)
    else:
      self.par[y] = x
      self.dic[x] += self.dic.pop(y)
      self.rank[x] += 1
  def same(self, x, y):
    return self.find(x)==self.find(y)


N, M = map(int, input().split())
bridge = []
u = UnionFind(N)
m = cmb(N,2)
ans = [m]

for i in range(M):
  A, B = map(int, input().split())
  bridge += [(A,B)]
  
for i in range(M-1,0,-1):
  a, b = bridge[i]
  if u.same(a-1,b-1):
    ans += [m]
    continue
  pa = u.find(a-1)
  pb = u.find(b-1)
  m -= u.dic[pa]*u.dic[pb]
  ans += [m]
  u.unit(a-1,b-1)

for i in range(M-1,-1,-1):
  print(ans[i])