Harryxun/stf_run huggingface dataset:
import pandas as pd
height, width = map(int, input().split())
_s_list = [input() for i in range(height)]
s_list = [list(ss) for ss in _s_list]

df = pd.DataFrame(s_list)

ans_list = []
for _h in range(height):
    for _w in range(width):
        if _h <= 1:
            h_s = 0
        else:
            h_s = _h-1
        h_e = _h + 2
        
        if _w <= 1:
            w_s = 0
        else:
            w_s = _w - 1
        w_e = _w + 2
        
        df_bool = (df.iloc[h_s:h_e, w_s:w_e] == '#')
        
        if df.iloc[_h, _w] == '#':
            ans_list.append('#')
        else:
            ans_list.append(str(sum(df_bool.sum())))
        
ans_str = ''
for i in range(len(ans_list)):
    ans_str += ans_list[i]
    if (i+1) % width == 0:
        print(ans_str)
        ans_str = ''


### FIXED CODE ###

## グリッドに関する処理
# ABC075B_Minesweeper

## 考え方：
# A NG:pandasに入れて、df.ilocによる行×列のスライスでうまくやる -> pandasはimport不可
# B:np.arrayに入れて、うまいことやる  # PyPy3ではnumpyもimport不可。python3は、numpyはimport可。

## for test
# # 1
# height, width = 3, 5
# _s_list = ['.....', '.#.#.', '.....']

# # 2
# height, width = 3, 5
# _s_list = ['#####', '#####', '#####']

# 3
# height, width = 6, 6
# _s_list = ['#####.', '#.#.##', '####.#', '.#..#.', '#.##..', '#.#...']


## for submit
import numpy as np
height, width = map(int, input().split())
_s_list = [input() for i in range(height)]
s_list = [list(ss) for ss in _s_list]  # 列×行に1文字ずつ区切ってリストへ追加 -> 2次元配列化
s_arr  = np.array(s_list)
# print(s_list)  # debug
# print(s_arr)  # debug

ans_list = []
for _h in range(height):
    for _w in range(width):
        # 周囲1マスずつを取得
        if _h <= 1:
            h_s = 0
        else:
            h_s = _h-1
        # h_e = _h + 2  # 一応、範囲外アクセスしないように修正
        if _h == height-1:
            h_e = _h+1
        else:
            h_e = _h+2
        
        if _w <= 1:
            w_s = 0
        else:
            w_s = _w - 1
        # w_e = _w + 2  # 一応、範囲外アクセスしないように修正
        if _w == width-1:
            w_e = _w+1
        else:
            w_e = _w+2

        # print(s_arr[h_s:h_e, w_s:w_e])  # debug
        # # np.count_nonzero()を使うとTrueの数、すなわち、条件を満たす要素の個数が得られる。
        # print(np.count_nonzero(s_arr[h_s:h_e, w_s:w_e] == '#'))

#         # 周囲1マスずつから、#の数を数えるための前処理
#         df_bool = (df.iloc[h_s:h_e, w_s:w_e] == '#')
#         # PythonでTrueは1、Falseは0とみなされるため、bool値のオブジェクトに対してsum()メソッドを呼べば条件を満たす要素の数が得られる。
#         # print(str(sum(df_bool.sum())))
        
        # チェック対象の中心が#なら#, それ以外はcount_nonzeroした結果の数値を文字列として保存
        if s_arr[_h, _w] == '#':
            ans_list.append('#')
        else:
            ans_list.append(str(np.count_nonzero(s_arr[h_s:h_e, w_s:w_e] == '#')))
        
# 結果を出力 width行を1区切りとして1行ずつ出力
ans_str = ''
for i in range(len(ans_list)):
    ans_str += ans_list[i]
    if (i+1) % width == 0:
        print(ans_str)
        ans_str = ''
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
ans=sum(B)
for s in range(N-1):
        if A[s+1]==A[s]+1:
            ans+=C[A[s]-1]
print(ans)
    

### FIXED CODE ###

N=int(input())
print(N**3)
n = int(input())
arr = []
for i in range(n-1):
    arr.append([int(s) for s in input().split(" ")])

childNodeNums = [0 for i in range(n)]
childNodeStatus = [-1 for i in range(n)]
nodeLineColors = [[] for i in range(n - 1)]


def prepare(n, arr):
    s = [[] for i in range(n)]
    for ar in arr:
        s[ar[0] - 1].append(ar[1] - 1)
        s[ar[1] - 1].append(ar[0] - 1)
    return s


# x为记录入边的颜色
def dfs(currentNode, arr, x):
    childNodes = arr[currentNode]
    if len(childNodes) == 0:
        return

    childNodeNums[currentNode] = childNodeNums[currentNode] + len(arr[currentNode])
    childNodeStatus[currentNode] = 1

    kk = 0
    for i, childNodeIndex in enumerate(childNodes):
        if x == i:
            kk = kk + 1
        if childNodeStatus[childNodeIndex] == -1:
            kk = kk + 1
            nodeLineColors[currentNode].append(kk)
            dfs(childNodeIndex, arr, i)


data = prepare(n, arr)
dfs(0, data, -1)

print(max(childNodeNums))
for ar in nodeLineColors:
    for a in ar:
        print(a)


### FIXED CODE ###

from sys import setrecursionlimit


def genid(a, b):
    if b < a:
        a, b = b, a
    return a * 100000 + b


def paint(currentNode, usedColor, parentNode, edges, colors):
    color = 1
    for childNode in edges[currentNode]:
        if childNode == parentNode:
            continue
        if color == usedColor:
            color += 1
        colors[genid(currentNode, childNode)] = color
        paint(childNode, color, currentNode, edges, colors)
        color += 1


setrecursionlimit(100000)

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

edges = [[] for _ in range(N)]
for a, b in ab:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

colors = {}
paint(0, -1, -1, edges, colors)

print(max(len(e) for e in edges))
for a, b in ab:
    print(colors[genid(a - 1, b - 1)])
N,M = map(int,input().split())
K = []
sum = 0
if N==1:
  W=list(map(int,input().split()))
  W.pop(0)
  K+=W
  print(len(K))
for i in range(N):
  W=list(map(int,input().split()))
  W.pop(0)
  K+=W
for T in range(1,len(K)+1):
  B=K.count(T)
  if B == N:
    sum+=1
print(sum)


### FIXED CODE ###

N,M = map(int,input().split())
K = []
sum = 0
if N==1:
  W=list(map(int,input().split()))
  W.pop(0)
  K+=W
  print(len(K))
  exit()
for i in range(N):
  W=list(map(int,input().split()))
  W.pop(0)
  K+=W
for T in range(1,len(K)+1):
  B=K.count(T)
  if B == N:
    sum+=1
print(sum)
def a(s,i):
    if i = l-1:
        if eval(s)==7:
            print(s+"=7")
            exit()
        return
    a(s+"+"+N[i+1],i+1)
    a(s+"-"+N[i+1],i+1)

N = input()
l = len(N)

a(N[0],0)

### FIXED CODE ###

def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

s=input()
dfs(0,s[0],int(s[0]))
x, y, z = map(int, input().split())
print(f"{z} {x} {y}")

### FIXED CODE ###

x, y, z = map(int, input().split())
print("{} {} {}".format(z, x, y))
a,b,c = input().split()
a =int(a)
b = int(b)
c = int(c)
if a<B and b<c:
    print("Yes")
else:
    print("No")
    


### FIXED CODE ###

a,b,c = input().split()
a =int(a)
b = int(b)
c = int(c)
if a<b and b<c:
    print("Yes")
else:
    print("No")
N = int( input() )
A, B = list( map(lambda x: int(x), input().split(" ")) ), list( map(lambda x: int(x), input().split(" ")) )
#A = monsters. B = number of to be able to kill monsters.殺せる数

def kill_monsters(Ai, Bi):

    if Ai <= 0 or Bi <= 0:
        return (Ai, Bi)
    else:
        return kill_monsters(Ai-1, Bi-1)


def main(local_A, local_B, i, lim):
    local_A[i], local_B[i] = kill_monsters(local_A[i], local_B[i])

    if 0 < local_B[i]:
        local_A[i+1], local_B[i] = kill_monsters(local_A[i+1], local_B[i])

    if lim <= i:
        return [local_A, local_B]

    return main(local_A, local_B, i+1, lim)

print( sum(A) - sum(main(A, B, 0, N-1)[0]) )

### FIXED CODE ###

N = int( input() )
A, B = list( map(lambda x: int(x), input().split(" ")) ), list( map(lambda x: int(x), input().split(" ")) )
#A = monsters. B = number of to be able to kill monsters.殺せる数

 
def kill_monsters(Ai, Bi):

    Ai -= Bi
    Bi = 0

    if Ai < 0:
        Bi += -1*Ai
        Ai = 0

    return (Ai, Bi)
 
def main(local_A, local_B, lim):
 
    for i in range(lim):
        local_A[i], local_B[i] = kill_monsters(local_A[i], local_B[i])
 
        if 0 < local_B[i]:
            local_A[i+1], local_B[i] = kill_monsters(local_A[i+1], local_B[i])
 
    return [local_A, local_B]

print( sum(A) - sum(main(A, B, N)[0]) )
n=int(input())
p=map(int,input().split())

c=0:
for i in range(1,n):
    if p[i-1]>p[i]:
        c=c+1

if c<=1:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

n=int(input())
p=list(map(int,input().split()))

c=0
d=0
for i in range(n):
    if p[i]==i+1:
        continue
    else:
        c=c+1
        if c>=3:
            break
        if d==0:
            d=i+1
            continue
        if d!=0:
            if d!=p[i]:
                c=3
                break

if c<=2:
    print("YES")
else:
    print("NO")
import numpy as np

x1,y1,x2,y2 = map(int,input().split())

x1y1 = np.array([x1,y1])
x2y2 = np.array([x2,y2])

vector = x1y1 - x2y2
rotation = np.array([[0,1],
                     [-1,0]])
rotated_vector = np.dot(rotation,vector)
x3y3 = x2y2 + rotated_vector
x4y4 = x3y3 + vector

print(*x3y3,*x4y4)

### FIXED CODE ###

import numpy as np
 
x1,y1,x2,y2 = map(int,input().split())
 
x1y1 = np.array([x1,y1])
x2y2 = np.array([x2,y2])
 
vector = x1y1 - x2y2
rotation = np.array([[0,1],
                     [-1,0]])
rotated_vector = np.dot(rotation,vector)
x3y3 = x2y2 + rotated_vector
x4y4 = x3y3 + vector
 
print(x3y3[0],x3y3[1],x4y4[0],x4y4[1])
a, b = map(int,input().split())
A = list(str(a)*b,), B = list(str(b)*a)
C = max(len(A),len(B))
for i in range(C)
  if A[i] > B[i]:
  　　　　print(str(B))
         break
  elif B[i] > A[i]:
         print(str(A))
         break

### FIXED CODE ###

A,B = map(int,input().split())
if A == B :
    print ("Yes")
else :
    print ("No")
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()

int N, M;
vector<int> x, y;

int input() {
    int a;
    cin>>a;
    return a;
}

bool check() {
    return max_element(all(x)) < min_element(all(y));
}

int main() {
    
    cin >> N >> M;
    x.pb(input());
    y.pb(input());
    for( int i=0; i < N; ++i)x.pb(input());
    for( int i=0; i < M; ++i)y.pb(input());

    if(check())cout << "No War" << endl;
    else cout << "War" <<endl;

    return 0;
}

### FIXED CODE ###

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)

def check2():
    return max(x) >= min(y)

if check2():
    print("War")
else:
    print("No War")
N = int(input())
K = int(input())

x = map(int, input().split())

ans = 0
for i in range(N);
    ans += 2*min(x, K-x)
    
print(ans)

### FIXED CODE ###

N = int(input())
K = int(input())

x = input().split()

ans = 0
for i in range(N):
    ans += 2*min(int(x[i]), K-int(x[i]))
    
print(ans)
N = int(input())
S1 = input()
S2 = input()

i = 1
if S1[0] == S2[0]:
    ans = 3
    state = 0
else:
    i+= 1
    ans = 6
    state = 1
mod  = 10**9 + 7
while N > i:
    if S1[i] != S2[i] and state == 0:
        ans *= 2
        i+=2
        state = 1
    elif S1[i] != S2[i] and state == 1:
        ans *= 3
        i+=2
    elif S1[i] == S2[i] and state == 0:
        ans *= 2
        i+= 1
    elif S1[i] == S2[i] and state == 1:
        ans *= 1
        i+=1
        state = 0

    ans %= mod
print(ans)
~


### FIXED CODE ###

N = int(input())
S1 = input()
S2 = input()

i = 1
if S1[0] == S2[0]:
    ans = 3
    state = 0
else:
    i+= 1
    ans = 6
    state = 1
mod  = 10**9 + 7
while N > i:
    if S1[i] != S2[i] and state == 0:
        ans *= 2
        i+=2
        state = 1
    elif S1[i] != S2[i] and state == 1:
        ans *= 3
        i+=2
    elif S1[i] == S2[i] and state == 0:
        ans *= 2
        i+= 1
    elif S1[i] == S2[i] and state == 1:
        ans *= 1
        i+=1
        state = 0

    ans %= mod
print(ans)
import sys
n,k=map(int,input().split())
for i in range(length.n):
  if k**i<=n and n<k**(i+1):
    print(i+1)
    sys.exit()
  

### FIXED CODE ###

import sys
n,k=map(int,input().split())
for i in range(n):
  if k**i<=n and n<k**(i+1):
    print(i+1)
    sys.exit()
import collections

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 1
N = 10 ** 5 + 1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
n, m = map(int, input().split())
A = list(map(int, input().split()))
ans_list = [0] * (n + 1)
for i in range(1, n + 1):
  A[i - 1] %= m
  ans_list[i] = (ans_list[i - 1] + A[i - 1]) % m
ans_list.pop(ans_list[0])
ans_list = dict(collections.Counter(ans_list))
  
#print(A)
#print(ans_list)
count = ans_list[0]
#print(count)
for v in ans_list.values():
  #print(v)
  if v != 1:
    count +=  v * (v - 1) / 2
    
print(int(count))   
    
    


### FIXED CODE ###

import collections
    
n, m = map(int, input().split())
A = list(map(int, input().split()))
ans_list = [0] * (n + 1)
for i in range(1, n + 1):
  A[i - 1] %= m
  ans_list[i] = (ans_list[i - 1] + A[i - 1]) % m
ans_list.pop(ans_list[0])
ans_list = dict(collections.Counter(ans_list))
  
#print(A)
#print(ans_list)
count = 0
if 0 in ans_list:
  count = ans_list[0]
#print(count)
for v in ans_list.values():
  #print(v)
  if v != 1:
    count +=  v * (v - 1) / 2
    
print(int(count))
from scipy.sparse import csr_matrix, csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
data = []
row = []
column = []
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n - 1)
    if c != W - 1 and maze[n + 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n + 1)
    if r and maze[n - W] == ".":
        data.append(1)
        row.append(n)
        column.append(n - W)
    if r != H - 1 and maze[n + W] == ".":
        data.append(1)
        row.append(n)
        column.append(n + W)
dist = csgraph.shortest_path(csr_matrix((data, (row, column)), dtype="i8", shape=(H * W, H * W)), directed=False)
print(int(dist[dist < 401].max()))

### FIXED CODE ###

import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(array, directed=False)
print(int(dist[dist < 401].max()))
x1, y1, x2, y2 = map(int, input().split())
dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4

### FIXED CODE ###

x1, y1, x2, y2 = map(int, input().split())
dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4)
n,c=map(int,input().split())
x=[0]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    x.append(a)
    v.append(b)

x1=[x[i+1]-x[i] for i in range(len(x)-1)]
x2=[c-x[-1]]+x1[:0:-1]
h=[0]
for i,j in zip(x2,reversed(v)):
    h.append(h[-1]+j+-i)
t=[0]
for i,j in zip(x1,v):
    t.append(t[-1]+j-i)
hi=h.index(max(h[0:-1]))
ti=t.index(max(t[0:-1]))
tm=max(t[0:-1])
hm=max(h[0:-ti])
h2=[h[i]-c+x[-i] for i in range(1,len(h))]
t2=[t[i]-x[i] for i in range(1,len(h))]
print(h,t)
print(h2,t2)

#print(ti,hi)
print(max(max(t), max(h), hm+max(t2[0:-ti]),tm+max(h2[:-hi])))

### FIXED CODE ###

n,c=map(int, input().split())
a=[[0,0]]+[list(map(int, input().split())) for i in range(n)]+[[c,0]]
m=[0]
h=[0]
mb=[0]
hb=[0]
for i in range(n+1):
    m.append(m[-1]-a[i+1][0]+a[i][0]+a[i+1][1])
    mb.append(m[-2]-a[i+1][0]+a[i][0]+a[i+1][1]-a[i+1][0])
    h.append(h[-1]-a[-i-1][0]+a[-i-2][0]+a[-i-2][1])
    hb.append(h[-2]-a[-i-1][0]+a[-i-2][0]+a[-i-2][1]-c+a[-i-2][0])

mm=[0]
for i in range(n):
    mm.append(max(mm[-1],m[i+1]))
hm=[0]
for i in range(n):
    hm.append(max(hm[-1],h[i+1]))
    
ans=max(hm[-1],mm[-1])
for i in range(1,n):
    ans=max(hb[i]+mm[-i-1], mb[i]+hm[-i-1],ans)
print(ans)
if __name__ == '__main__':
    from collections import Counter
    from mist.special import comb

    N,A,B = [int(i) for i in input().split()]
    V = [int(i) for i in input().split()]

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))
    
    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))


### FIXED CODE ###

def comb(n, k):
    return factorial(n) // (factorial(k) * factorial(n-k))
  
if __name__ == '__main__':
    from collections import Counter
    from math import factorial

    N,A,B = [int(i) for i in input().split()]
    V = [int(i) for i in input().split()]

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))

    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))
x,n = list(map(int,input().split()))


if n <= 0:
    print(x)
else:
    p = list(map(int,input().split()))
    q = p
    q.sort()
    p2 = [x for x in range(1,q[-1]+n)]

    p_p2_diff = set(p)^set(p2)
    p_p2_diff_list = list(p_p2_diff)

    min_list = []
    for i in range(len(p_p2_diff_list)):
        val = abs(x - p_p2_diff_list[i])
        min_list.append(val)

    print(p_p2_diff_list[min_list.index(min(min_list))])


### FIXED CODE ###


x,n = list(map(int,input().split()))


if n <= 0:
    print(x)
else:
    p = list(map(int,input().split()))
    p.sort()
    p2 = [x for x in range(-200,200)]

    p_p2_diff = set(p)^set(p2)
    p_p2_diff_list = list(p_p2_diff)

    min_list = []
    for i in p_p2_diff_list:
        val = abs(x - i)
        min_list.append(val)

    print(p_p2_diff_list[min_list.index(min(min_list))])
a, b, n = map(int, input().split())
print(math.floor(a * min((b - 1), n) / b))

### FIXED CODE ###

import math
a, b, n = map(int, input().split())
print(math.floor(a * min((b - 1), n) / b))
class UnionFind:
    def __init__(self, length):
        self.par = [-1 for _ in range(length)]

    def root(self,x):
        if (self.par[x] < 0 ):
             return x
        else:
            #change connection
            root = self.root(self.par[x])
            self.par[x] = root
            return root
            
            
    
    def unite(self,x,y):
        root_x = self.root(x)
        root_y = self.root(y)
        if (root_x==root_y):
            return 
        else:
            self.par[root_y] += self.par[root_x]
            self.par[root_x] = root_y
        
    def same(self,x,y):
        root_x = self.root(x)
        root_y = self.root(y)
        return root_x == root_y 
    
    def size(self,x):
        return -self.par[self.root(x)]

"""
uf = UnionFind(5)
uf.unite(3,4)
uf.unite(1,2)
uf.unite(1,4)
print(uf.size_dict)
"""


N,M = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(M)]
score= N*(N-1)//2
outputs = [score]
uf = UnionFind(N+3)
for edge in edges[::-1]:
    if not uf.same(*edge):
        score -= uf.size(edge[0]) * uf.size(edge[1])
        uf.unite(*edge)
    outputs.append(score)
for i in range(M):
    print(int(outputs[M-i-1]))



### FIXED CODE ###

class UnionFind:
    def __init__(self, length):
        self.par = [-1 for _ in range(length)]
        self.rank = [0 for _ in range(length)]
 
    def root(self,x):
        if (self.par[x] < 0 ):
             return x
        else:
            #change connection
            root = self.root(self.par[x])
            self.par[x] = root
            return root
    
    def unite(self,x,y):
        root_x = self.root(x)
        root_y = self.root(y)
        if (root_x==root_y):
            return 
        else:
            if self.rank[root_x] < self.rank[root_y]:
                self.par[root_y] += self.par[root_x]
                self.par[root_x] = root_y

            else:
                self.par[root_x] += self.par[root_y]
                self.par[root_y] = root_x
                if self.rank[root_x] == self.rank[root_y]:
                    self.rank[root_x]+=1
        
    def same(self,x,y):
        root_x = self.root(x)
        root_y = self.root(y)
        return root_x == root_y 
    
    def size(self,x):
        return -self.par[self.root(x)]

"""
uf = UnionFind(5)
uf.unite(3,4)
uf.unite(1,2)

uf.unite(1,4)
print(uf.size_dict)
"""
def solve(edges,N,M):
 
    score= N*(N-1)//2
    outputs = [score]
    uf = UnionFind(N)
    for edge in edges[::-1]:
        if not uf.same(*edge):
            score -= uf.size(edge[0]) * uf.size(edge[1])
            uf.unite(*edge)
        outputs.append(score)
    for i in range(M):
        print(int(outputs[M-i-1]))

def get_input():
    N,M = map(int, input().split())
    edges = [tuple(map(lambda x:  int(x)-1, input().split())) for _ in range(M)]
    return N,M,edges

N,M,edges = get_input()
# = 10**6
#M=10**5
#import numpy as np
#edges = [(np.random.randint(N),np.random.randint(N)) for i in range(M)]
solve(edges,N,M)
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

if N == 1 and m == 1:
  print(0)
else:
  n = 0
  for i in range(N-1):
    n += 1+i
  m = (M * (M-1)) / 2
  print(int(n + m))

### FIXED CODE ###

hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

if N == 1 and M == 1:
  print(0)
else:
  n = 0
  if N != 0:
    for i in range(N-1):
      n += 1+i
  else:
    n = 0
  if M != 0:
    m = (M * (M-1)) / 2
  else:
    m = 0
  print(int(n + m))
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    s = [sc[i][0] for i in range(M)]
    c = [sc[i][1] for i in range(M)]
    ans = "-1"
    if N == 1:
        for i in range(10):
            if ans != "-1":
                break
            strnum = str(i)
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
            if j == M-1:
                ans = i
                break
    elif N == 2:
        for i in range(10,100):
            if ans != "-1":
                break
            strnum = str(i)
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
            if j == M-1:
                ans = i
                break
    else:
        for i in range(100,1000):
            if ans != "-1":
                break
            strnum = list(str(i))
            for j in range(M):
                if strnum[s[j]-1] != str(c[j]):
                    break
                if j == M-1:
                    ans = i
                    break
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    if M == 0:
        if N != 1:
            print(10**(N-1))
        else:
            print(0)
    else:
        ans = "-1"
        flag = False
        for i in range(10**N):
            if flag:
                break
            tmp = str(i)
            if len(tmp) < N:
                continue
            for j in range(M):
                if tmp[sc[j][0]-1] != str(sc[j][1]):
                    break
                if j == M-1:
                    ans = i
                    flag = True
        print(ans)

if __name__ == '__main__':
    main()
a,b,c=input().split()
if a+b=c:
    print(“Yes”)
if else b+c=a:
    print(“Yes”)
if else a+c=b:
    print(“Yes”)
else:
    print(“No”)


### FIXED CODE ###

a,b,c=map(int,input().split())
if a+b==c:
    print("Yes")
elif b+c==a:
    print("Yes")
elif a+c==b:
    print("Yes")
else:
    print("No")