Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N, K = map(int, input().split())
l = []
Ap = 0
An = 0
i = 0
for x in input().split():
    A = int(x)
    l.append(A)
    if i < K:
        Ap = Ap + A
    else:
        An = Ap - l.pop(0) + A
        if An > Ap:
            print("Yes")
        else:
            print("No")
        Ap = An
    i = i + 1


### FIXED CODE ###

N, K = map(int, input().split())
l = []
i = 0
for x in input().split():
    A = int(x)
    if K < N - i:
        l.insert(0, A)
    if i >= K:
        if l.pop() < A:
            print("Yes")
        else:
            print("No")
    i = i + 1
### BUGGY CODE ###

#B
N = int(input())
A = list(map(int,input().split()))
ans=1
for i in A:
    ans*=i
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

#B
N = int(input())
A = list(sorted(map(int,input().split())))
ans=1
if A[0]==0:
    print(0)
else:
    for i in A:
        ans*=i
        if ans > 10**18:
            ans =-1
            break
    print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[0]*W for _ in range(H)]

cnt = 0
for i in range(H):
    l = input()
    for j in range(W):
        grid[i][j] = l[j]
        if l[j] == '.':
            cnt += 1


# 動的計画法 dp[i][j]->grid[i][j]に行くための最短距離
dp = [[float('inf')]*W for _ in range(H)]


def dfs(i, j, dist):
    if 0 <= i < H and 0 <= j < W:
        if grid[i][j] != '#':
            if dp[i][j] < dist:
                return
            else:
                dp[i][j] = dist

                new_dist = dist+1
                dfs(i+1, j, new_dist)
                dfs(i-1, j, new_dist)
                dfs(i, j+1, new_dist)
                dfs(i, j-1, new_dist)


def solve():
    dfs(0, 0, 1)
    min_dist = dp[H-1][W-1]
    if min_dist == float('inf'):
        return -1
    else:
        return cnt - min_dist


print(solve())


### FIXED CODE ###


from collections import deque
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


H, W = map(int, input().split())
grid = [[0]*W for _ in range(H)]

cnt = 0
for i in range(H):
    l = input()
    for j in range(W):
        grid[i][j] = l[j]
        if l[j] == '.':
            cnt += 1


# 動的計画法 dp[i][j]->grid[i][j]に行くための最短距離
dp = [[float('inf')]*W for _ in range(H)]


def check_in(x, y):
    return 0 <= x < W and 0 <= y < H


def bfs():
    dx = [1, -1, 0, 0]
    dy = [0, 0, 1, -1]
    Q = deque([[0, 0]])
    dp[0][0] = 0

    while Q:
        s = Q.popleft()
        if s[0] == H-1 and s[1] == W-1:
            return
        else:
            s_x = s[1]
            s_y = s[0]
            for x, y in zip(dx, dy):
                n_x = s_x+x
                n_y = s_y+y

                if check_in(n_x, n_y):
                    if grid[n_y][n_x] != "#" and dp[n_y][n_x] == float('inf'):
                        Q.append([n_y, n_x])
                        dp[n_y][n_x] = dp[s_y][s_x]+1


def solve():
    bfs()
    min_dist = dp[H-1][W-1]
    if min_dist == float('inf'):
        return -1
    else:
        return cnt - min_dist-1


print(solve())
### BUGGY CODE ###

n = int(input())
line_a = list(map(int,input().split()))
total = sum(line_a)
q = int(input())
for i in range(q):
  b,c = map(int, input().split())
  for j in range(len(line_a)):
    if line_a[j] == b:
      line_a[j] = c
  print(sum(line_a))

### FIXED CODE ###

n = int(input())
line_a = list(map(int,input().split()))
total = sum(line_a)
q = int(input())
numbers = [0 for i in range(10**5+1)]
for i in line_a:
  numbers[i] += 1

for i in range(q):
  b,c = map(int, input().split())
  d = c - b
  stock = numbers[b]
  numbers[c] += numbers[b]
  numbers[b] = 0
  total += stock*d
  print(total)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
N,K = [int(x) for x in input().split()]
edge = [[int(x) for x in input().split()]for _ in range(N-1)]
mod = 10**9+7
def dfs(n,fr):
    color = 0
    if(fr==-1):
        color = K-1
    else:
        color = K-2
    if(K<len(edges[n])):
        return 0
    else:
        case_num = 1
        for e in edges[n]:
            if(e==fr):continue
            case_num*=color
            color-=1
            case_num%=mod

        for e in edges[n]:
            if(e==fr):continue
            case_num*=dfs(e,n)
            case_num%=mod
        return case_num

edges = [[] for _ in range(N)]
for s,d in edge:
    s-=1
    d-=1
    edges[s].append(d)
    edges[d].append(s)
ans = K*dfs(0,-1)
print(ans%mod)


### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
mod = 10**9+7
def dfs():
    stack = deque([[-1,0]])
    visited = set()
    case_num=1
    while stack:
        fr,n = stack.pop()
        if(n in visited):continue
        visited.add(n)
        color = 0
        if(fr==-1):
            color = K-1
        else:
            color = K-2
        if(K<len(edges[n])):
            return 0
        else:
            for e in edges[n]:
                if(e==fr):continue
                case_num*=color
                color-=1
                stack.append([n,e])
                case_num%=mod
    return case_num%mod

if(__name__=='__main__'):
    N,K = [int(x) for x in input().split()]
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        s,d = [int(x) for x in input().split()]
        edges[s-1].append(d-1)
        edges[d-1].append(s-1)
    ans = K*dfs()
    print(ans%mod)
### BUGGY CODE ###

N = int(input())

A = [[0]*N for i in range(N)]

for i in range(N):
    A[i] = list(map(int,input().split()))
B = [[A[i][j] for j in range(i+1,N)] for i in range(N-1)]
#print(A)
#print(B)

det = 0

for i in range(N-1):
    for j in range(i+1,N):
        for k in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                det = -1
                break
            elif i != k and j != k and A[i][j] == A[i][k] + A[k][j]:
                B[i][j-(i+1)] = 0
                #print(i,j,k,B)
        
        if det == -1:
            break

    if det == -1:
        break

if det == 0:
    ans = 0
    for i in range(N-1):
        for j in range(i+1,N):
            ans += B[i][j-(i+1)]
else:
    ans = -1

print(ans)


### FIXED CODE ###

N = int(input())

A = [[0]*N for i in range(N)]

for i in range(N):
    A[i] = list(map(int,input().split()))
B = [[A[i][j] for j in range(i+1,N)] for i in range(N-1)]
#print(A)
#print(B)

det = 0

for i in range(N-1):
    for j in range(i+1,N):
        for k in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                det = -1
                break
            elif i != k and j != k and A[i][j] == A[i][k] + A[k][j]:
                B[i][j-(i+1)] = 0
                #print(i,j,k,B)
        
        if det == -1:
            break

    if det == -1:
        break

if det == 0:
    ans = 0
    for i in range(N-1):
        for j in range(i+1,N):
            ans += B[i][j-(i+1)]
else:
    ans = -1

print(ans)
### BUGGY CODE ###

# coding: utf-8
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = lr()
dp = [[min(i, N-1-i)] * N for i in range(N)]
people = [[True] * N for i in range(N)]
for j in range(N):
    x = min(j, N-1-j)
    for i in range(N):
        dp[i][j] = min(dp[i][j], x)

answer = 0
for p in P:
    p -= 1
    i = p // N
    j = p % N
    answer += dp[i][j]
    dp[i][j] -= 1
    people[i][j] = False
    def bfs(sy, sx):
        que = deque([(sy, sx)])
        popleft = que.popleft; append = que.append
        while que:
            y, x = popleft()
            cur = dp[y][x]
            if cur == -1 and not people[y][x]:
                people[y][x] = True
            for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):
                ny = y + dy
                nx = x + dx
                if 0 <= ny < N and 0 <= nx < N:
                    if dp[ny][nx] > cur + 1:
                        dp[ny][nx] = cur + 1
                        if not people[ny][nx]:
                            dp[ny][nx] = cur
                        append((ny, nx))
                    elif dp[ny][nx] > cur and (not people[ny][nx]):
                        # 人がいない時
                        dp[ny][nx] = cur
                        append((ny, nx))
    bfs(i, j)

print(answer)


### FIXED CODE ###

# coding: utf-8
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def main():
    N = ir()
    P = lr()
    P = [((p-1)//N, (p-1)%N) for p in P]
    dp = [[min(i, N-1-i, j, N-1-j) for j in range(N)] for i in range(N)]
    people = [[True] * N for i in range(N)]

    answer = 0
    for i, j in P:
        answer += dp[i][j]
        people[i][j] = False
        que = deque([(i, j, dp[i][j])])
        popleft = que.popleft; append = que.append
        while que:
            y, x, cur = popleft()
            cur += people[y][x]
            if x > 0:
                if dp[y][x-1] > cur:
                    dp[y][x-1] = cur
                    append((y, x-1, cur))
            if x < N-1:
                if dp[y][x+1] > cur:
                    dp[y][x+1] = cur
                    append((y, x+1, cur))
            if y > 0:
                if dp[y-1][x] > cur:
                    dp[y-1][x] = cur
                    append((y-1, x, cur))
            if y < N-1:
                if dp[y+1][x] > cur:
                    dp[y+1][x] = cur
                    append((y+1, x, cur))

    print(answer)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

S = input()
cnt = 0
len_s = len(S)
i = 2
while i <= len_s-1:
  if S[i-2:i+1] == 'ABC':
    S = S[:i-2] + 'BCA' + S[i+1:]
    cnt += 1
    i = max(0, i-3)
  else:
    i += 1
print(cnt)

### FIXED CODE ###

S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt += 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        cnt += a_cnt
        idx += 2
      else:
        break
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
F = list(map(int,input().split()))
F.sort(reverse=True)

sa = sum(A)
if K >= sa:
    print(0)
    exit()

def isok(b):
    k = 0
    for a,f in zip(A,F):
        if a > b//f:
            k += a-(b//f)
            if k > K:
                return False
    return True

ok = 10**12+1
ng = 0

while ok-ng > 1:
    m = (ok+ng)//2
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
F = list(map(int,input().split()))
F.sort(reverse=True)

sa = sum(A)
if K >= sa:
    print(0)
    exit()

def isok(b):
    k = 0
    for a,f in zip(A,F):
        if a > b//f:
            k += a-(b//f)
            if k > K:
                return False
    return True

ok = 10**12+1
ng = 0

while ok-ng > 1:
    m = (ok+ng)//2
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)
### BUGGY CODE ###

N,K=map(int,input().split())
mod=1000000007
path=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  path[a].append(b)
  path[b].append(a)
#print(path)
  
abc=[0 for i in range(N)] #0ならまだ塗ってない

abc[0]=1
cnt=0
ans=K%mod
nx=[]
for i in range(len(path[0])):
  child=path[0][i]
  if abc[child]==0:
    ans=ans*(K-1-cnt)
    ans=ans%mod
    cnt=cnt+1
    abc[child]=1
    nx.append(child)
while len(nx)>0:
  a=nx.pop(0)
  cnt=0
  for i in range(len(path[a])):
    child=path[a][i]
    if abc[child]==0:
      ans=ans*(K-2-cnt)
      ans=ans%mod
      cnt=cnt+1
      abc[child]=1
      nx.append(child)
      
print(ans%mod)
      
      
    

### FIXED CODE ###

N,K=map(int,input().split())
mod=1000000007
path=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  path[a].append(b)
  path[b].append(a)
#print(path)
  
abc=[False for i in range(N)] #0ならまだ塗ってない

abc[0]=True
cnt=0
ans=K%mod
nx=[]
for i in range(len(path[0])):
  child=path[0][i]
  if abc[child]:
    continue
  ans=ans*(K-1-cnt)
  ans=ans%mod
  cnt=cnt+1
  abc[child]=True
  nx.append(child)
while len(nx)>0:
  a=nx.pop()
  cnt=0
  for i in range(len(path[a])):
    child=path[a][i]
    if abc[child]:
      continue
    ans=ans*(K-2-cnt)
    ans=ans%mod
    cnt=cnt+1
    abc[child]=True
    nx.append(child)
      
print(ans%mod)
### BUGGY CODE ###


H,W = input().split()
H = int(H)
W = int(W)
S = []

for i in range(H):

    sp = input()
    S.append(sp)

maxi = 0
now = 0

for i in range(H):

    for j in range(W):

        if ( S[i][j] != "#"):

            now = 1

            for k in range(j):
                k = j - 1 - k

                if (S[i][k] == "."):
                    now += 1

                else:
                    break

            for k in range(W - 1 - j):
                k = j + 1 + k

                if (S[i][k] == "."):
                    now += 1

                else:
                    break

            for k in range(i):
                k = i - 1 - k

                if (S[k][j] == "."):
                    now += 1

                else:
                    break

            for k in range(H - 1 - i):
                k = i + k + 1

                if (S[k][j] == "."):
                    now += 1

                else:
                    break


            if (maxi < now):
                maxi = now
            

print (maxi)


### FIXED CODE ###


H,W = map(int,input().split())

S = []

for i in range(H):

    s = input()
    S.append(list(s))

yoko = []

for i in range(H):

    num = 0
    now = []

    for j in range(W):

        if S[i][j] == ".":
            num += 1

        else:
            now += ([num] * num)
            num = 0
            now.append(0)

    now += [num] * num
    yoko.append(now)

#print (yoko)

tate = []

for j in range(W):

    num = 0
    now = []

    for i in range(H):

        if S[i][j] == ".":
            num += 1

        else:
            now += ([num]*num)
            num = 0
            now.append(0)

    now += [num] * num
    tate.append(now)

ans = 0

for i in range(H):

    for j in range(W):

        ans = max(ans , yoko[i][j] + tate[j][i] - 1)

print (ans)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
l = []

for i in range(n-k+1):
    a = sum(p[i:i+k])
    l.append(a)

print((max(l) + k)/2)

### FIXED CODE ###

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

a= sum(p[0:k])
ans = a

for i in range(n-k):
    a -= p[i]
    a += p[i+k]
    ans = max(ans,a)

print((ans+k)/2)
### BUGGY CODE ###


def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[0 for i in range(n)]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1][b-1]=b-1
        r[b-1][a-1]=a-1
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if not visited[i]:
                queue.append(i)
                visited[i]=True
                d[i]=now
    #print(d)
    if flg:
        print("Yes")
        for i in range(1,n):
            print(d[i]+1)
    else:
        print("No")


if __name__ == "__main__":
     main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

    print("Yes")
    for i in range(1,n):
        print(d[i]+1)


if __name__ == "__main__":
     main()
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = {}
dp[0] = 0

for i in range(1, N):
    min_cost = float("inf")
    for j in range(K):
        if i - j - 1 < 0:
            break
        else:
            min_cost = min(min_cost, abs(h[i - j - 1]-h[i]) + dp[i - j - 1])
    
    dp[i] = min_cost

print(dp[N - 1])

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))

h += [float("inf")] * (K)
dp = [float("inf")] * (N+K)
dp[0] = 0
for i in range(N):
    for j in range(K):
        dp[i+j+1] = min(dp[i+j+1], dp[i]+abs(h[i] - h[i+j+1]))


print(dp[N-1])
### BUGGY CODE ###

n = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(n[1])]

passcard = []
for c in range(l[0][1] - l[0][0]+1):
    passcard.append(l[0][0]+c)

for tt in range(n[1]):
    t = n[1] - tt -1
    for i in range(len(passcard)):
        if not(l[t][0] <= passcard[i] <= l[t][1]):
            passcard[i] = 0
        else:
            passcard[i] = passcard[i]

    passcard = [i for i in passcard if i!=0]
            
print(len(passcard))

### FIXED CODE ###

n = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(n[1])]
minp = l[0][0]
maxp = l[0][1]
for t in range(n[1]):
    minp = max(minp,l[t][0])
    maxp = min(maxp,l[t][1])
print(max(0,maxp-minp+1))
### BUGGY CODE ###

def dfs(count,last,distance):
    if (count == r):
        if (ans[0] > distance ):ans[0] = distance
        return
    for i in range(r):
        if seen[i]:continue
        seen[i] = True
        if last == -1:dfs(count+1,i,0)
        else:dfs(count+1,i,distance+dp[R[last]-1][R[i]-1])
        seen[i] = False

n,m,r = map(int,input().split())
R = list(map(int,input().split()))
dp = [[ 0 if i == j else float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    dp[x-1][y-1] = z
    dp[y-1][x-1] = z
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dp[i][j] > dp[i][k] + dp[k][j]:
                dp[i][j] = dp[i][k] + dp[k][j]
ans = [float("Inf")]
seen = [False]*r
dfs(0,-1,0)
print(*ans)

### FIXED CODE ###

def dfs(count,last,distance):
    if (count == r):
        if (ans[0] > distance ):ans[0] = distance
        return
    for i in range(r):
        if seen[i]:continue
        seen[i] = True
        if last == -1:dfs(count+1,i,0)
        else:dfs(count+1,i,distance+dp[R[last]-1][R[i]-1])
        seen[i] = False

n,m,r = map(int,input().split())
R = list(map(int,input().split()))
dp = [[ 0 if i == j else float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    dp[x-1][y-1] = z
    dp[y-1][x-1] = z
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dp[i][j] > dp[i][k] + dp[k][j]:
                dp[i][j] = dp[i][k] + dp[k][j]
ans = [float("Inf")]
seen = [False]*r
dfs(0,-1,0)
print(*ans)
### BUGGY CODE ###

A, B, K = map(int, input().split())
for num in range(A, B + 1):
    if num < A + K or num > B - K:
        print(num)


### FIXED CODE ###

a, b, k = map(int, input().split())

x = b - a
if x < 2 * k:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(a, a + k):
        print(i)

    for i in range(b - k + 1, b + 1):
        print(i)
### BUGGY CODE ###

n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)

cnt = 0
for v in lst:
    flag = False
    first_key = v[0]
    for i in range(len(s)):
        if s[i] == first_key:
            second_key = v[1]
            for j in range(i + 1, len(s)):
                if s[j] == second_key:
                    third_key = v[2]
                    for k in range(j + 1, len(s)):
                        if s[k] == third_key:
                            flag = True
    if flag:
        cnt += 1

print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)

cnt = 0
for v in lst:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)
### BUGGY CODE ###

import math
n=int(input())
for i in range(1,n+1):
  max = int(math.sqrt(i))
  result = 0
  for x in range(1,max+1):
    max = int(math.sqrt(i - x * x))
    for y in range(1,max+1):
      if i - x * x - y * y - x * y < 1:
        continue
      max = int(math.sqrt(i - x * x - y * y - x * y))
      for z in range(1,max+1):
        if x * x + y * y + z * z + x * y + y * z + x * z == i:
          result += 1
          break
  print(result)

### FIXED CODE ###

nn=int(input())
nc = [0] * (nn + 1)
for x in range(1, 100):
  for y in range(1, 100):
    for z in range(1, 100):
      a = x * x + y * y + z * z + x * y + x * z + y * z
      if a > nn:
        break
      nc[a] += 1
for i in range(1, nn + 1):
  print(nc[i])
### BUGGY CODE ###

(N,M) = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    (A[i], B[i]) = map(int,input().split())
    A[i] -= 1
    B[i] -= 1

parent = [-1]*N
depth = [0] * N

def boss(n):
    d = 0
    while parent[n] >= 0:
        n = parent[n]
        d += 1
    return n,d

P = [1]*N
S = (N*(N-1))//2

ans = [0] * M
ans[M-1] = S

#print(A)
#print(B)

for i in range(M-1):
#    print(parent)
    j = M-1-i
    bA, dA = boss(A[j])
    bB, dB = boss(B[j])
#    print(A[j],B[j],bA,bB)
    if bA != bB:
        if depth[bA] < depth[bB]:
            (bA, bB) = (bB, bA)
        parent[bB] = bA
        S -= P[bA]*P[bB]
        P[bA] = P[bA] + P[bB]
        P[bB] = 0
    ans[j-1] = S

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

### FIXED CODE ###

(N,M) = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    (A[i], B[i]) = map(int,input().split())
    A[i] -= 1
    B[i] -= 1

parent = [-1]*N
depth = [0] * N

def boss(n):
    d = 0
    while parent[n] >= 0:
        n = parent[n]
        d += 1
    return n,d

P = [1]*N
S = (N*(N-1))//2

ans = [0] * M
ans[M-1] = S

#print(A)
#print(B)

for i in range(M-1):
#    print(parent)
    j = M-1-i
    bA, dA = boss(A[j])
    bB, dB = boss(B[j])
#    print(A[j],B[j],bA,bB)
    if bA != bB:
        if depth[bA] < depth[bB]:
            (bA, bB) = (bB, bA)
        parent[bB] = bA
        S -= P[bA]*P[bB]
        P[bA] = P[bA] + P[bB]
        P[bB] = 0
        depth[bA] = max(depth[bA],depth[bB]+1)
    ans[j-1] = S

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