Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=sum(map(int,input().split()));
sl=sum(map(int,input().split()[:2]))
if sl>s/2:
  m='Left'
elif sl==s/2:
  m='Balanced'
else:
  m='Right'
print(m)

Fixed submission:
o=input().split();s=sum(map(int,o));sl=sum(map(int,o[:2]))
if sl>s/2:
  m='Left'
elif sl==s/2:
  m='Balanced'
else:
  m='Right'
print(m)
Buggy python submission (verdict: Runtime Error):
a,_,b=input();s=int(a)+int(b);print(s//2+int(bin(s)[-1]))

Fixed submission:
s=sum(map(int,input().split()));print(s//2+int(bin(s)[-1]))
Buggy python submission (verdict: Runtime Error):
def ds(n):
  return sum(map(int,str(n)))
print(n%ds(n)==0)

Fixed submission:
n=int(input())
def ds(n):
  return sum(map(int,str(n)))
print('Yes' if n%ds(n)==0 else 'No')
Buggy python submission (verdict: Runtime Error):
s=int(input())
print("YES" any([str(i)*3 in str(s) for i in range(10)]) else "NO")


Fixed submission:

s=int(input())
print("Yes" if any([str(i)*3 in str(s) for i in range(10)]) else "No" )
Buggy python submission (verdict: Time Limit Exceeded):

num=int(input())

def lucas(n):
    if n>1:
        return lucas(n-1)+lucas(n-2)
    elif n==1:
        return 1
    elif n==0:
        return 2

print(lucas(num))

Fixed submission:

num=int(input())

def lucas(n):
    lus = [2, 1]
    for idx in range(n+1):
        if idx > 1:
            lus.append(lus[-2]+lus[-1])
    return lus[-1]
            
print(lucas(num))
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
f=lambda i:a[i]
c=0
h=[]
while True:
  if f(c)==2:break
  if c in h:
    print(-1)
    exit()
  h.append(c)
  c=f(c)-1
print(len(h)+1)

Fixed submission:
n,*a=map(int,open(0).read().split())
f=lambda x,y:x[y]
i=1
c=0
for _ in range(n):
  i=f(a,i-1)
  c+=1
  if i==2:
    print(c)
    exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
import math;print(math.factorial(int(input()))%(7+1e9))

Fixed submission:
import math;print(math.factorial(int(input()))%int(7+1e9))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
d=1
for i in range(2,n+1):
  d*=i
print(int(d%int(7+1e9)))

Fixed submission:
import math;print(math.factorial(int(input()))%int(7+1e9))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
d=1
for i in range(2,n+1):
  d*=i
print(int(d%int(7+1e9)))

Fixed submission:
import math;print(math.factorial(int(input()))%int(7+1e9))
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
c=0
for x in range(k+1):
  if x>s:break
  for y in range(k+1):
    if x+y>s:break
    for z in range(k+1):
      if x+y+z==s: c+=1
      if x+y+z>s: break
print(c)


Fixed submission:
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for j in range(min(k,s-i)+1):
    if s-i-j<=k:c+=1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
c=0
for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z==s: c+=1
      if x+y+z>s: break
print(c)

Fixed submission:
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for j in range(min(k,s-i)+1):
    if s-i-j<=k:c+=1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,k=map(int,input().split())
p,n=10**9+7,h+w
x=k+k*(k+1)//2+k*(k-1)*(k+1)//3*h*w*pow(n*(n-1),p-2,p)
for i in range(n,n-k,-1):x=x*i%p
print(x)


Fixed submission:
h,w,k=map(int,input().split())
p,n=10**9+7,h+w
x=k+k*(k+1)//2+k*(k-1)*(k+1)//3*h*w*pow(n*(n-1),p-2,p)
for i in range(n,n-k,-1):x=x*i%p
print(x)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [tuple(map(int, input().split())) for i in range(n)]
t = set(a)
minans = 1000000000000
for i in range(n):
    for j in range(i + 1, n):
        r = t.copy()
        p = a[i][0] - a[j][0]
        q = a[i][1] - a[j][1]
        curans = 0
        while r:
            curans += 1
            m = r.pop()
            z = m.copy()
            while (m[0] + p, m[1] + q) in r:
                m = (m[0] + p, m[1] + q)
                r.remove(m)
            m = z.copy()
            while (m[0] - p, m[1] - q) in r:
                m = (m[0] - p, m[1] - q)
                r.remove(m)
        minans = min(minans, curans)
print(minans)


Fixed submission:
n = int(input())
a = [tuple(map(int, input().split())) for i in range(n)]
t = set(a)
assert len(t) == len(a)
minans = 1000000000000
for i in range(n):
    for j in range(i + 1, n):
        r = t.copy()
        p = a[i][0] - a[j][0]
        q = a[i][1] - a[j][1]
        curans = 0
        while r:
            curans += 1
            m = r.pop()
            z = m
            while (m[0] + p, m[1] + q) in r:
                m = (m[0] + p, m[1] + q)
                r.remove(m)
            m = z
            while (m[0] - p, m[1] - q) in r:
                m = (m[0] - p, m[1] - q)
                r.remove(m)
        minans = min(minans, curans)
if minans == 1000000000000:
    print(1)
else:
    print(minans)
Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(4)]
count = 0

for (i = 0; i <= a[0]; i++) :
  for (j = 0; j <= a[1]; j++) :
    for (k = 0; k <= a[2]; k++) :
      sum = 500*i + 100*j + 50*k
      if sum == a[3] :
        count += 1
print(count)

Fixed submission:
a = [int(input()) for i in range(4)]
count = 0

for i in range(a[0]+1) :
  for j in range(a[1]+1) :
    for k in range(a[2]+1) :
      sum = 500*i + 100*j + 50*k
      if sum == a[3] :
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(4)]
count = 0
y = a[3]
i = y / 500; if i > a[0] : i = a[0]; y -= i * 500
j = y / 100; if j > a[1] : j = a[1]; y -= j * 100
k = y /  50; if k > a[2] : k = a[2]; y -= k * 50
if (y == 0) :
  count += 1
  if i > 0 :
    while (i > 0 and j + 5 <= a[1]) :
      i -= 1
      j += 5
      tmp1 = j
      tmp2 = k
      count += 1
      while (tmp1 > 0 and tmp2 + 2 <= a[2]) :
        tmp1 -= 1
        tmp2 += 2
        count += 1
      tmp1 = j
      tmp2 = k
  elif i == 0 and j > 0:
    while (j > 0 and k + 2 <= a[2]) :
        j -= 1
        k += 2
        count += 1

print(count)


Fixed submission:
a = [int(input()) for i in range(4)]
count = 0

for i in range(a[0]+1) :
  for j in range(a[1]+1) :
    for k in range(a[2]+1) :
      sum = 500*i + 100*j + 50*k
      if sum == a[3] :
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(4)]
count = 0
y = a[3]
i = y / 500; if i > a[0] : i = a[0]; y -= i * 500
j = y / 100; if j > a[1] : j = a[1]; y -= j * 100
k = y /  50; if k > a[2] : k = a[2]; y -= k * 50
if (y == 0) :
  count += 1
  while (i > 0 && j + 5 < a[1]) :
    i -= 1
    j += 5
    tmp1 = j
    tmp2 = k
    count += 1
    while (tmp1 > 0 && tmp2 + 2 < a[2]) :
      tmp1 -= 1
      tmp2 += 2
      count += 1
    tmp1 = j
    tmp2 = k

print(count)


Fixed submission:
a = [int(input()) for i in range(4)]
count = 0

for i in range(a[0]+1) :
  for j in range(a[1]+1) :
    for k in range(a[2]+1) :
      sum = 500*i + 100*j + 50*k
      if sum == a[3] :
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(4)]
count = 0
for i in range(a[0], -1, -1) :
  y = a[3]
  if (y > 500*i):
    y -= i*500
    if y == 0:
      count += 1
      continue
    for j in range(a[1], -1, -1) :
      if (y > j*100) :
        y -= j*100
        if y == 0:
          count += 1
          continue
      for k in range(a[2], -1, -1) :
        if (y > k*50) :
          y -= k*50
          if y == 0:
      count += 1
      continue
print(count)

Fixed submission:
a = [int(input()) for i in range(4)]
count = 0

for i in range(a[0]+1) :
  for j in range(a[1]+1) :
    for k in range(a[2]+1) :
      sum = 500*i + 100*j + 50*k
      if sum == a[3] :
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
if a[0]%2==0 || a[1]%2==0 :
  print("Even")
else:
  print("Odd")	

Fixed submission:
a = list(map(int,input().split()))
if (a[0]%2==0) or (a[1]%2==0) :
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
if a[0]%2==0 || a[1]%2==0 :
  print("Even")
else:
  print("Odd")	

Fixed submission:
a = list(map(int,input().split()))
if (a[0]%2==0) or (a[1]%2==0) :
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
time = list(map(int, input().split()))

time = time.sort()

print(time[0] + time[1])

Fixed submission:
data = list(map(int, input().split()))
time = sorted(data)
answer = time[0] + time[1]
print(answer)
Buggy python submission (verdict: Runtime Error):
X,Y = input().split()
if int(X, 16) = int(Y, 16):
    print('=')
elif int(X, 16) > int(Y, 16):
    print('>')
else:
    print('<')

Fixed submission:
X, Y = input().split()
if int(X, 16) > int(Y, 16):
    print('>')
elif int(X, 16) < int(Y, 16):
    print('<')
else:
    print('=')
Buggy python submission (verdict: Runtime Error):
r,g,b = input().split()
if (g*10+b)%4==0:
    print('YES')
else:
    print('No')
    


Fixed submission:
r,g,b=map(int,input().split())
X = r * 100 + g * 10 + b
if X % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r,g,b = input().split()
if int((g*10+b)%4==0):
    print('YES')
else:
    print('No')
    


Fixed submission:
r,g,b=map(int,input().split())
X = r * 100 + g * 10 + b
if X % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r,g b = input().split()
if int((g*10+b)%4==0):
    print('YES')
else:
    print('No')
    


Fixed submission:
r,g,b=map(int,input().split())
X = r * 100 + g * 10 + b
if X % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r,g b = input().split()
if (g*10+b)%4==0:
    print('YES')
else:
    print('No')
    


Fixed submission:
r,g,b=map(int,input().split())
X = r * 100 + g * 10 + b
if X % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r,g b = input().split()
if (g*10+b)%4%==0:
    print('YES')
else:
    print('No')
    


Fixed submission:
r,g,b=map(int,input().split())
X = r * 100 + g * 10 + b
if X % 4 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
s=input()
n=s[::2].count("0")+s[1::2].count("1")
print(min(n,lens(s)-n))

Fixed submission:
s=input()
n=s[::2].count("0")+s[1::2].count("1")
print(min(n,len(s)-n))
Buggy python submission (verdict: Runtime Error):
S=int(input())
m=0
count=0
for s in S:
    if s in "A":count+=1
    elif s in "C":count+=1
    elif s in "G":count+=1
    elif s in "T":count+=1
    else:count=0
    m=max(m,count)
print(m)

Fixed submission:
S=input()
m=0
count=0
for s in S:
    if s in "A":count+=1
    elif s in "C":count+=1
    elif s in "G":count+=1
    elif s in "T":count+=1
    else:count=0
    m=max(m,count)
print(m)
Buggy python submission (verdict: Runtime Error):
S=int(input())
l=[]
while(S not in l):
    l.append(S)
    if S%2==0:S//=2
    else:S=3*S+1
print(len(s)+1)

Fixed submission:
S=int(input())
l=[]
while(S not in l):
    l.append(S)
    if S%2==0:S//=2
    else:S=3*S+1
print(len(l)+1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=""
while n!=0:
    x=str(n%2)+x
    s=-(n//2)
print(0 if x=="" else x)

Fixed submission:
n=int(input())
x=""
while n!=0:
    x=str(n%2)+x
    n=-(n//2)
print(0 if x=="" else x)
Buggy python submission (verdict: Runtime Error):
n=input()
print("No" if n%sum(map(int,n)) else "Yes")

Fixed submission:
n=input()
print("No" if int(n)%sum(map(int,n)) else "Yes")
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
for i in range(b-a+1):
    s.append(a+i)
    if i<k or i>b-a+1-k:print(a+i)

Fixed submission:
a,b,k=map(int,input().split())
r=range(a,b+1)
for i in sorted(set(r[:k])|set(r[-k:])):print(i)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=[int(input()) for _ in range(4)]
print(min(a,b)+min(c.d))

Fixed submission:
a,b,c,d=[int(input()) for _ in range(4)]
print(min(a,b)+min(c,d))
Buggy python submission (verdict: Runtime Error):
print("Odd" if (int(input()).replace(" ","*"))%2 else "Even")

Fixed submission:
print("Odd" if eval(input().replace(" ","*"))%2 else "Even")

Buggy python submission (verdict: Runtime Error):
print("Odd" if int(input()).replace(" ","*")%2 else "Even")

Fixed submission:
print("Odd" if eval(input().replace(" ","*"))%2 else "Even")
Buggy python submission (verdict: Runtime Error):
input()
A=list(map(int,input().split()))
while all(a%2==0 for a in A):
    A=[a/2 for a in A]
    ans+=1
print(ans)

Fixed submission:
input()
A=list(map(int,input().split()))
ans=0
while all(a%2==0 for a in A):
    A=[a/2 for a in A]
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
print("<" if x<y else "=" if x==y else ">")

Fixed submission:
x,y=input().split()
print("<" if x<y else "=" if x==y else ">")
Buggy python submission (verdict: Runtime Error):
X,t=map(int,input().split())
print("0" if x-t<0 else x-t)

Fixed submission:
x,t=map(int,input().split())
print("0" if x-t<0 else x-t)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split()
print("Impossible" if a*b*(a+b)%3 else "Possible")

Fixed submission:
a,b=map(int,input().split())
print("Impossible" if a*b*(a+b)%3 else "Possible")
Buggy python submission (verdict: Runtime Error):
print("NO" if int(input())[::2]%4 else "YES")

Fixed submission:
print("NO" if int(input()[::2])%4 else "YES")
Buggy python submission (verdict: Runtime Error):
x=int(input())
print("ABC" x<1200 else "ARC")

Fixed submission:
x=int(input())
print("ABC" if x<1200 else "ARC")
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
print([x+y+z for z in range(k+1) for y in range(k+1) for x in range(k+1)].count(s))

Fixed submission:
k,s=map(int,input().split())
print(len([1 for z in range(k+1) for y in range(k+1) if 0<=s-y-z<=k]))

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
print(sum([h+i+j==s for j in range(k+1) for i in range(k+1) for h in range(k+1)]))

Fixed submission:
k,s=map(int,input().split())
print(len([1 for z in range(k+1) for y in range(k+1) if 0<=s-y-z<=k]))
Buggy python submission (verdict: Runtime Error):
S=int(input())
l=[]
while(S not in l):
    l.append(S)
    if S%2==0:S/=2
    else:S=3*S+1
print(len(l)+1)

Fixed submission:
S={c:list(input()) for c in "abc"}
s="a"
while S[s]:s=S[s].pop(0)
print(s.upper())
Buggy python submission (verdict: Runtime Error):
import datetime

input_time = input()
old_date = datetime.datetime.strptime(input_time, '%Y/%m/%d')
new_date = old_date + datetime.timedelta(years=1)
print(new_date)


Fixed submission:
import datetime
import sys

input_date = sys.stdin.read(10)
old_date = datetime.datetime.strptime(input_date, '%Y/%m/%d')
new_date = old_date.replace(old_date.year + 1)
out_date = "{0:%Y/%m/%d}".format(new_date)
print(out_date)
Buggy python submission (verdict: Runtime Error):
L=list(map(int,input().split))
L.sort()
print(L[0]+L[1])

Fixed submission:
L= list(map(int, input().split()))
L.sort()
print(L[0]+L[1])
Buggy python submission (verdict: Runtime Error):
N= int(input())
L= list(map(int,input().split()))

v=[]
for i in range(N):
  v.append(abs(sum(L[:(i+1)]-L[(i+1):])))

ans=min(v)

print(ans)


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

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1])-sum(L[i+1:])))

ans=min(v)

print(ans)

Buggy python submission (verdict: Runtime Error):
N= int(input())
L= list(map(int,input().split()))

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:(i+1)]-L[(i+1):])))

ans=min(v)

print(ans)


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

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1])-sum(L[i+1:])))

ans=min(v)

print(ans)

Buggy python submission (verdict: Runtime Error):
N= int(input())
L= list(map(int,input().split()))

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1]-L[i+1:])))

ans=min(v)

print(ans)


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

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1])-sum(L[i+1:])))

ans=min(v)

print(ans)

Buggy python submission (verdict: Runtime Error):
N= int(input())
L= list(map(int,input().split()))

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1]-L[i+1:])))

ans=min(v)

print(v)


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

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1])-sum(L[i+1:])))

ans=min(v)

print(ans)

Buggy python submission (verdict: Runtime Error):
N= int(input())
L= list(map(int,input().split()))

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i]-L[i+1:])))

ans=min(v)

print(v)

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

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1])-sum(L[i+1:])))

ans=min(v)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
MOD = 10**6+3
q = int(input())

fact = [1]*(MOD+1)
for i in range(1, MOD+1):
    fact[i] = fact[i-1]*i%MOD
finv = [pow(f, MOD-2, MOD) for f in fact]

for _ in range(q):
    x, d, n = map(int, input().split())
    if d == 0:
        ans = pow(x, n, MOD)
    else:
        x_div = x*pow(d, MOD-2, MOD)%MOD
        if x_div+n-1 > MOD:
            ans = 0
        else:

            if x_div+n-1 >= MOD:
                ans = 0
            else:
                ans = fact[x_div+n-1]*finv[x_div-1]%MOD*pow(d, n, MOD)%MOD
    print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
MOD = 10**6+3
q = int(input())

fact = [1]*(MOD+1)
for i in range(1, MOD+1):
    fact[i] = fact[i-1]*i%MOD

for _ in range(q):
    x, d, n = map(int, input().split())
    if d == 0:
        ans = pow(x, n, MOD)
    else:
        x_div = x*pow(d, MOD-2, MOD)%MOD
        if x_div+n-1 > MOD:
            ans = 0
        else:

            if x_div+n-1 >= MOD:
                ans = 0
            else:
                f = fact[x_div+n-1]
                fi = pow(fact[x_div-1], MOD-2, MOD)
                ans = f*fi%MOD*pow(d, n, MOD)%MOD
    print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(list, input().split())
h, w = map(list, input().split())

print((H-h)*(W-w))


Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())

print((H-h)*(W-w))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

def get(n):
    if n%4 == 0:
        return x
    elif n%4 == 1:
        return 1
    elif n%4 == 2:
        return x+1
    else:
        return 0

print(get(b)^get(a-1))


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

def count_bin(n, d):
    if n < 0:
        return 0
    div = (n+1)//2**(d+1)
    res = div*(2**d)
    remain = (n+1) - div*(2**(d+1))
    res += remain - 2**d if remain > 2**d else 0
    return res

ans = 0
for d in range(50):
    n_bin = count_bin(b, d) - count_bin(a-1, d)
    if n_bin%2 > 0:
        ans += 2**d
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ans = [n*(n-1)//2]
remains = set(range(1, n+1))
sets = []
for i in range(m-1):
    a, b = ab[-(i+1)]
    if a in remains and b in remains:
        sets.append(set([a, b]))
        remains.remove(a)
        remains.remove(b)
        ans.append(ans[i] - 1)
    elif a not in remains and b in remains:
        for i_set in range(len(sets)):
            if a in sets[i_set]:
                size_a = len(sets[i_set])
                sets[i_set].add(b)
                remains.remove(b)
                ans.append(ans[i] - size_a)
                break
    elif a in remains and b not in remains:
        for i_set in range(len(sets)):
            if b in sets[i_set]:
                size_b = len(sets[i_set])
                sets[i_set].add(a)
                remains.remove(a)
                ans.append(ans[i] - size_b)
                break
    else:
        i_set_a, i_set_b = None, None
        for i_set in range(len(sets)):
            if a in sets[i_set]:
                i_set_a = i_set
                size_a = len(sets[i_set])
            if b in sets[i_set]:
                i_set_b = i_set
                size_b = len(sets[i_set])
            if i_set_a is not None and i_set_b is not None:
                break
        if i_set_a == i_set_b:
            ans.append(ans[i])
        else:
            sets[i_set_a] = sets[i_set_a].union(sets[i_set_b])
            sets.pop(i_set_b)
            ans.append(ans[i] - size_a*size_b)
    # print(sets, remains)

for a in ans[::-1]:
    print(a)


Fixed submission:
import sys
sys.setrecursionlimit(100000)

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)][::-1]

par, sizes = [-1]*(n+1), [1]*(n+1)
def find(i):
    if par[i] < 0:
        return i
    else:
        par[i] = find(par[i])
        return par[i]

ans = [n*(n-1)//2]
for i in range(m-1):
    a, b = ab[i]
    pa, pb = find(a), find(b)

    if pa != pb:
        ans.append(ans[i] - sizes[pa]*sizes[pb])
        par[pa] = pb
        sizes[pb] += sizes[pa]
    else:
        ans.append(ans[i])
    # print(par, sizes)

for ans_ in ans[::-1]:
    print(ans_)
Buggy python submission (verdict: Runtime Error):
import bisect
inf = 10**18
a, b, q = map(int, input().split())
s = [-inf] + [int(input()) for _ in range(a)] + [inf]
t = [-inf] + [int(input()) for _ in range(a)] + [inf]

for _ in range(q):
    x = int(input())
    i = bisect.bisect_right(s, x)
    j = bisect.bisect_right(t, x)
    ans = inf
    for s_x in [s[i-1], s[i]]:
        for t_x in [t[j-1], t[j]]:
            ans0 = abs(s_x - x) + abs(t_x - s_x)
            ans1 = abs(t_x - x) + abs(s_x - t_x)
            ans = min(ans, ans0, ans1)
    print(ans)

Fixed submission:
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [(int(input()), i) for i in range(q)]
x = sorted(x)

def check(x, s0, s1, t0, t1):
    ans = float('inf')
    for x1, x2 in [(s0, t0), (s0, t1), (s1, t0), (s1, t1),
                   (t0, s0), (t0, s1), (t1, s0), (t1, s1)]:
        ans = min(ans, abs(x-x1)+abs(x1-x2))
    return ans

s0, t0 = -float('inf'), -float('inf')
s1, t1 = s[0], t[0]
i_s, i_t = 0, 0
answers = []
for x_i, i in x:
    while s1 < x_i and i_s < a-1:
        s0 = s1
        i_s += 1
        s1 = s[i_s]
    while t1 < x_i and i_t < b-1:
        t0 = t1
        i_t += 1
        t1 = t[i_t]
    ans = check(x_i, s0, s1, t0, t1)
    answers.append((i, ans))

for _, ans in sorted(answers):
    print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
inf = 10**18
a, b, q = map(int, input().split())
s = [-inf] + [int(input()) for _ in range(a)] + [inf]
t = [-inf] + [int(input()) for _ in range(a)] + [inf]

for _ in range(q):
    x = int(input())
    i = bisect.bisect_right(s, x)
    j = bisect.bisect_right(t, x)
    ans = inf
    for s_x in [s[i-1], s[i]]:
        for t_x in [t[i-1], t[i]]:
            ans0 = abs(s_x - x) + abs(t_x - s_x)
            ans1 = abs(t_x - x) + abs(s_x - t_x)
            ans = min(ans, ans0, ans1)
    print(ans)


Fixed submission:
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [(int(input()), i) for i in range(q)]
x = sorted(x)

def check(x, s0, s1, t0, t1):
    ans = float('inf')
    for x1, x2 in [(s0, t0), (s0, t1), (s1, t0), (s1, t1),
                   (t0, s0), (t0, s1), (t1, s0), (t1, s1)]:
        ans = min(ans, abs(x-x1)+abs(x1-x2))
    return ans

s0, t0 = -float('inf'), -float('inf')
s1, t1 = s[0], t[0]
i_s, i_t = 0, 0
answers = []
for x_i, i in x:
    while s1 < x_i and i_s < a-1:
        s0 = s1
        i_s += 1
        s1 = s[i_s]
    while t1 < x_i and i_t < b-1:
        t0 = t1
        i_t += 1
        t1 = t[i_t]
    ans = check(x_i, s0, s1, t0, t1)
    answers.append((i, ans))

for _, ans in sorted(answers):
    print(ans)