Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-


def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0) * 2
            
        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0) * 2


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

pro = []
for i in range(n):
    name, time = list(input().split())
    pro.append(name)
    pro.append(int(time))

simu(pro, q)



### FIXED CODE ###

# -*- coding: utf-8 -*-


def simu(pro, q):
    end_time = 0

    while bool(pro):
        if pro[1] > q:
            end_time += q
            pro.append(pro[0])
            pro.append(pro[1] - q)
            pro.pop(0)
            pro.pop(0)

        elif pro[1] <= q:
            end_time += pro[1]
            print('{0} {1}'.format(pro[0], end_time))
            pro.pop(0)
            pro.pop(0)


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

pro = []
for i in range(n):
    name, time = list(input().split())
    pro.append(name)
    pro.append(int(time))

simu(pro, q)
n=int(input())
a=int(input())
b=int(input())
ans=[]
if n == 1:
    ans="Hello World"
else:
    ans=a+b
print(ans)

### FIXED CODE ###

n=int(input())
s = [int(input()) for i in range((n-1)*2)]
ans=[]
if n == 1:
    ans="Hello World"
else:
    ans=s[0]+s[1]
print(ans)
n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.sort()
y.sort()
if x[n-1] < y[0] and X < y[0] and y < x[n-1]:
    print('No War')
else:
    print('War')

### 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)
x.sort()
y.sort()
print('No War' if x[-1] < y[0] else 'War')
n, k = map(int,input().split())
x = list(map(int, input().split()))

ans = 999999999

for i in range(n - k + 1):
	if(x[i] <= 0 and x[i + k - 1] >= 0):
    	a = abs(x[i]) + (x[i + k - 1] - x[i])
    	b = abs(x[i + k - 1]) + (x[i + k - 1] - x[i])
    	ans = min(ans, a, b)

print(ans)


### FIXED CODE ###

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

ans = 999999999

for i in range(n - k + 1):
    a = abs(x[i]) + (x[i + k - 1] - x[i])
    b = abs(x[i + k - 1]) + (x[i + k - 1] - x[i])
    ans = min(ans, a, b)
    
print(ans)
print((int(input())-1)*(int(input())-1))

### FIXED CODE ###


a, b = [ int(v) for v in input().split() ]
print((a-1)*(b-1))
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

def nHk(n, k):
    f = math.factorial
    return int(f(n + k - 1) // f(k) // f(n - 1))

N, K = map(int, input().split())
MOD = 10 ** 9 + 7

for i in range(1, K + 1):
#    print('i: ' + str(i))
    # 青玉をi個のグループに並べる並べ方
    blue = 1
#    if i == 1:
#        blue = 1
#    else:
#        blue = nCr(K - 1, i - 1)
#    print('blue: ' + str(blue))
    # 青い玉に合わせた赤い玉の並べ方
#    if (N - K) < (i - 1):
#        red = 0
#        print('red0: ' + str(red))
    if i == 1:
        red = (N - K) + 1
#        print('red1: ' + str(red))
    else:
        red = nCr(K - 1, i - 1) * nHk(i + 1, N - K - (i - 1))
#        print('nCr: ' + str(nCr(K - 1, i - 1)))
#        print('nHk: ' + str(nHk(i + 1, N - K - (i - 1))))
#        print('red2: ' + str(red))

    # 解は青の並べ方と赤の並べ方の組み合わせ
    ans = blue * red % MOD
    print(ans)
#    print('ans: ' + str(ans))


### FIXED CODE ###

from operator import mul
from functools import reduce

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

N, K = map(int, input().split())
MOD = 10 ** 9 + 7

for i in range(1, K + 1):
    if i > N - K + 1:
        ans = 0
    else:
        ans = nCr(K - 1, i - 1) * nCr(N - K + 1, i) % MOD
    print(ans)
def main():
    N = int(input())
    if (N / (N % 9)) % 1 == 0:
        print("Yes")
    else:
        print("No")
    return 0
main()


### FIXED CODE ###

def main():
    def dig_sum(x):
        return sum(list(map(int, [i for i in str(x)])))
    N = int(input())
    if (N / dig_sum(N)) % 1 == 0:
        print("Yes")
    else:
        print("No")
    return 0
main()
a, b = map(int, input().split(' '))
sum = 0
for i in range(1,2):
	if a < b:
      sum += b
      b -= 1
    else:
      sum += a
      a -= 1
print(sum)

### FIXED CODE ###

A,B = map(int, input().split())
sum = 0
for i in range(2):
  if A < B:
    sum += B
    B -= 1
  else:
    sum += A
    A -= 1
print(sum)
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
s,c = [list(i) for i in zip(*l)]
z = ['a'] * n
for i in range(m):
    if z[s[i]-1] == 'a':
        z[s[i]-1] = str(c[i])
    elif z[s[i]-1] == str(c[i]):
        pass
    else:
        print('-1')
        exit(0)
if n == 1:
    if z[0] == 'a':
        print(0)
    else:
        print(z[0])
else:
    if z[0] == '0':
        print(-1)
    else:
        if z[0] == 'a':
            z[0] = '1'
        for i in range(1,n):
            if z[i] == 'a':
                z[i] = '0'
        print(''.join(z))

### FIXED CODE ###

n,m = map(int,input().split())
if m != 0:
    l = [list(map(int,input().split())) for i in range(m)]
    s,c = [list(i) for i in zip(*l)]
z = ['a'] * n
for i in range(m):
    if z[s[i]-1] == 'a':
        z[s[i]-1] = str(c[i])
    elif z[s[i]-1] == str(c[i]):
        pass
    else:
        print('-1')
        exit(0)
if n == 1:
    if z[0] == 'a':
        print(0)
    else:
        print(z[0])
else:
    if z[0] == '0':
        print(-1)
    else:
        if z[0] == 'a':
            z[0] = '1'
        for i in range(1,n):
            if z[i] == 'a':
                z[i] = '0'
        print(''.join(z))
weather = input()

elif weather in ["RRR"]:
    print("3")
elif weather in ["SRR","RRS"]:
    print("2")
elif weather in ["SSR","SRS","RSS","RSR"]:
    print("1")
else:
    print("0")

### FIXED CODE ###

weather = input()

if weather in ["RRR"]:
    print("3")
elif weather in ["SRR","RRS"]:
    print("2")
elif weather in ["SSR","SRS","RSS","RSR"]:
    print("1")
else:
    print("0")
m1,d1 =map(int,input().split())
m2,d2 =map(int,input().split())
if m1 == m2 :
    return 0 :
else :
    return 1:


### FIXED CODE ###

m1,d1 =map(int,input().split())
m2,d2 =map(int,input().split())
if m1 == m2 :
    print (0)
else :
    print (1)
Ordinary Beauty

### FIXED CODE ###

n, m, d = map(int, input().split())

if d != 0:
    r = 2 * (n - d) / n**2 * (m - 1)
else:
    r = (m - 1) / n
print(r)
N,W=map(int,input().split())
dp = [0]*(capacity + 1)

def solve_knapsack(capacity):
    # basic checks
 
    
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit

    for i in range(0, N):
        weights,profits = map(int,input().split())
        for c in range(capacity, weights-1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]: dp[c] = tmp
 
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]
  
def main():
 
    res = solve_knapsack(W)
 
    print(res)
if __name__ == "__main__":
	main()

### FIXED CODE ###

def main():
  n, w = [int(e) for e in input().split()]
  t = [-1 for i in range(w + 1)]
  t[w] = 0
  for _ in range(n):
    nw, nv = [int(e) for e in input().split()]
    for i in range(nw, w + 1):
      if t[i] == -1:
        continue
      if t[i - nw] < t[i] + nv:
        t[i - nw] = t[i] + nv
  print(max(t))
main()
import sys
input = sys.stdin.readline


x = int(input())

prime = [True] * (1000000)
prime[2] = True

def e_prime(x):
	i = 2
	flag = False
	while True:
		if prime[i]:
			if(flag==True):
				return i
			else:
				for j in range(i**2,len(prime),i):
					prime[j]=False
		i+=1
		if(i==x):flag=True

print(e_prime(x))

### FIXED CODE ###

import sys
input = sys.stdin.readline


x = int(input())

prime = [True] * (100004)
prime[2] = True

def e_prime(x):
	i = 2
	flag = False
	while True:
		if(i==x):flag=True
		if prime[i]:
			if(flag==True):
				return i
			else:
				for j in range(i**2,len(prime),i):
					prime[j]=False
		i+=1

print(e_prime(x))
(a, b) = list(map(int, input().split()))

if a == b:
  print("Yes")
rlse:
  print("No")

### FIXED CODE ###

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

if a == b:
  print("Yes")
else:
  print("No")
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input()-1)]

### FIXED CODE ###

print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())-1])
n=int(input())
a=list(map(int,input().split()))
sum=0
for i in a:
  x=i**2
  sum+=x
print((sum(a)**2)-sum)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
aa=0
for i in a:
  x=i**2
  aa+=x
print(((sum(a)**2)-aa)//2)
import sympy

n = int(input())
cnt = 0
for i in range(1, n):
    # print('i:', i)
    cnt += sympy.divisor_count(n - i)
print(cnt)

### FIXED CODE ###

n = int(input())
cnt = 0
for i in range(1, n):
    cnt += (n - 1) // i
print(cnt)
import numpy as np
N =int(input())

X = np.array([int(i) for i in input().split()])

co_min = min(X)
co_max = max(X)

Y =np.ones(co_max-co_min)

for i in range(len(Y)):
    start = co_min + i
    Y[i] = sum((X-start)**2)
    
ans = int(min(Y))

print(ans)

### FIXED CODE ###

import numpy as np
N =int(input())

X = np.array([int(i) for i in input().split()])

co_min = min(X)
co_max = max(X)

Y =np.ones(co_max-co_min)

for i in range(len(Y)):
    start = co_min + i
    Y[i] = sum((X-start)**2)
if co_min != co_max:    
    ans = int(min(Y))
elif co_min == co_max:
    ans =0
print(ans)
N = int(input())
X_bin = input()

X_int = int(X_bin, 2)  # bin => int
dp = {1: 1}
bin_cnt = {}

import sys
sys.setrecursionlimit(10**5)


def calc_bin_cnt(next_int):
    if next_int in bin_cnt.keys():
        cnt = bin_cnt[next_int]
    else:
        next_bin = format(next_int, 'b')
        # popcount
        cnt = 0
        for i in next_bin:
            if i == '1':
                cnt += 1
        bin_cnt[next_int] = cnt
    return cnt


def calc_ans(next_int):
    key = next_int
    if key in dp.keys():
        ans = dp[key]
    else:
        '''
        next_bin = format(next_int, 'b')
        # popcount
        cnt = 0
        for i in next_bin:
            if i == '1':
                cnt += 1
        '''
        cnt = calc_bin_cnt(next_int)
        bin_cnt[next_int] = cnt
        next_int = next_int % cnt
        if next_int > 0:
            ans = calc_ans(next_int) + 1
        else:
            ans = 1
        dp[key] = ans
    return ans


for i in range(N):
    if X_bin[i] == '1':
        print(calc_ans(X_int - (2**(N-i-1))))
    else:
        print(calc_ans(X_int + (2**(N-i-1))))


### FIXED CODE ###

N = int(input())
X_bin = input()
#N = 10**5
#X_bin = '1' * N

X_int = int(X_bin, 2)  # bin => int


def calc_bin_cnt(next_int):
    if next_int == 0:
        return 0
    next_bin = bin(next_int)[2:]
    # popcount
    cnt = 0
    for i in next_bin:
        if i == '1':
            cnt += 1
    return cnt


def calc_ans(next_int, cnt=None):
    if next_cnt == 0:
        return 0
    if next_int == 0:
        return 1
    if cnt is None:
        cnt = calc_bin_cnt(next_int)
    next_int = next_int % cnt
    if next_int > 0:
        ans = calc_ans(next_int) + 1
    else:
        ans = 1
    return ans


X_cnt = calc_bin_cnt(X_int)
f_p = X_int % (X_cnt+1)
if X_cnt-1 == 0:
    f_m = 0
else:
    f_m = X_int % (X_cnt-1)
for i in range(N):
    if X_bin[i] == '1':
        next_cnt = X_cnt - 1
        if next_cnt == 0:
            next_int = 0
        else:
            next_int = f_m - pow(2, (N-i-1), next_cnt)  # マイナスでも正しく求まる？
    else:
        next_cnt = X_cnt + 1
        next_int = f_p + pow(2, (N-i-1), next_cnt)
    print(calc_ans(next_int, next_cnt))
    #calc_ans(next_cnt, next_cnt)
import statistics
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=np.array(list(map(int,input().split())))

    B=np.array([i for i in range(1,N+1)])

    A=A-B
    val=0
    for i in A:
        val += abs(i - statistics.median(A))
    print(int(val))
resolve()

### FIXED CODE ###

# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
import numpy as np
#import statistics
#import sys
#sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=np.array(list(map(int,input().split())))

    for i in range(N):
        A[i]-=i+1

    B=abs(A-np.median(A))
    print(int(sum(B)))
resolve()
from itertools import math
N = int(input())
P = tuple(map(int(input().split())))
Q = tuple(map(int(input().split()))
# Find all possible and allow the length
perm = permutations((range(1,N+1)),N)
print(abs(perm.index(P)-perm.index(Q)))


### FIXED CODE ###

from itertools import permutations
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
# Find all possible
perm = list(permutations(range(1,N+1),N))
print(abs(perm.index(P)- perm.index(Q)))
s={'SAT':1,'FRI':2,'THU':3,'WED':4,'TUE':5,'MON':6,'SUN':7}
print({}.format(s[input()]))

### FIXED CODE ###

s={'SAT':1,'FRI':2,'THU':3,'WED':4,'TUE':5,'MON':6,'SUN':7}
print('{}'.format(s[input()]))
S = input()
K = int(input())

buf=''
cnt = 1
total = 0
cnts = []


for s in S:
    if s == buf:
        cnt += 1       
    else:
        cnts.append(cnt)
        total += int(cnt/2)
        cnt = 1        
    buf = s
cnts.append(cnt)    
total += int(cnt/2)

if len(set(list(S)))==1:
    print(int(len(S*K)/2))

elif S[0]==S[-1] :#and cnts[1] % 2 != 0:
    print(int(total*K - (int(cnts[1]/2)+int(cnts[-1]/2)-((cnts[1]+cnts[-1])/2))*(K-1)))
else:
    print(total*K)

### FIXED CODE ###

from itertools import groupby
S = input()
K = int(input())
a = [len(tuple(s)) for _, s in groupby(S)]
ans = 0
 
if S[0] == S[-1] and K > 1:
    if len(a) == 1:
        ans = a[0]*K // 2
    else:
        ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
        ans += sum(n // 2 for n in a[1:-1]) * K
else:
    ans = sum(n // 2 for n in a) * K
print(ans)
#coding:utf-8

def main():
    h, n = map(int, input().split())
    ab = []
    for _ in range(n):
        ab.append(list(map(int, input().split())))
    
    inf = 1000000
    # indexがモンスターに与えたダメージで、中身がトキのダメージ
    damages = [inf for _ in range(100000)]
    damages[0] = 0
    for i in range(h):
        if damages[i] == inf:
            continue
        for j in range(n):
            new_damage = ab[j][0]
            if damages[i + new_damage] > damages[i] + ab[j][1]:
                damages[i + new_damage] = damages[i] + ab[j][1]
    
    k = h
    while damages[k] == inf:
        k += 1
    print(damages[k])
main()

### FIXED CODE ###

#coding:utf-8

def main():
    h, n = map(int, input().split())
    ab = []
    for _ in range(n):
        ab.append(list(map(int, input().split())))
    
    inf = 100000000000
    # indexがモンスターに与えたダメージで、中身がトキのダメージ
    damages = [0] + [inf] * h
    for i in range(1, h + 1):
        for j in range(n):
            damage_monster = ab[j][0]
            damage_toki = ab[j][1]
            
            damages[i] = min(damages[max(0, i - damage_monster)] + damage_toki, damages[i])


    print(min(damages[h:]))
main()
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
N = int(input())
H = list(map(int,input().split()))
cnt = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        ans = cnt
        cnt = 0

if ans <= cnt:
    ans = cnt
print(ans)


### FIXED CODE ###

from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
N = int(input())
H = list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        if ans <= cnt:
            ans = cnt
        cnt = 0

if ans <= cnt:
    ans = cnt
print(ans)
import itertools
N = int(input())

ans = [0]*(10**4)
for i1 in range(1, 1000):
    i2 = i1+1
    i3 = i1+2
    L = list(itertools.combinations_with_replacement((i1, i2, i3), 3))
    for i in L:
        i = list(i)
        x = i[0]
        y = i[1]
        z = i[2]
        n = (x**2)+(y**2)+(z**2)+(x*y)+(y*z)+(z*x)
        if n > 10**4:
            break
        if len(list(set(i))) == 1:
            ans[n] += 1
        if len(list(set(i))) == 2:
            ans[n] += 3
        if len(list(set(i))) == 3:
            ans[n] += 6
        
for k in range(1, N+1):
    print(ans[k])

### FIXED CODE ###

n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
    for j in range(1,105):
        for k in range(1,105):
            v = i*i+j*j+k*k+i*j+j*k+k*i
            if v<10050:
                ans[v]+=1
for i in range(n):
    print(ans[i+1])
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0] * (N+1)
mark_A = 0
for i,a in enumerate(A, 1):
    tmp =  sum_A[i-1] + a
    if tmp <= K:
        sum_A[i] = tmp
        mark_A = i
    else:
        break

sum_B = [0] * (M+1)
mark_B = 0
for j,b in enumerate(B, 1):
    tmp = sum_B[j-1] + b
    if tmp <= K:
        sum_B[j] = tmp
        mark_B = j
    else:
        break
        
import numpy as np

C = np.tile(sum_A[:mark_A+1], (mark_B+1,1)) + np.array(sum_B[:mark_B+1]).reshape(-1, 1)
print(max(np.where(C <= K)[0] + np.where(C <= K)[1]))

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = len(sum_B) - 1

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        j -= 1
        
    ans = max(ans, i+j)
    
print(ans)
cond = map(int, raw_input().split())
a = cond[0]
b = cond[1]

print (a*b) (a*2 + b*2)

### FIXED CODE ###

cond = map(int, raw_input().split())
a = cond[0]
b = cond[1]

print (a*b),
print (a*2 + b*2)
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 CODE ###

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])
n,a,b=map(int,input())
print(max(a*n,b))

### FIXED CODE ###

n,a,b=map(int,input().split())
print(min(a*n,b))
N,M = map(int,input().split())
 
a = [int(input()) for i in range(M)]
 
wa = (10**9) + 7
 
def Fib(n):
    if n==0:
        return 0 #F0
    elif n==1:
        return 1 #F1
    elif n==2:
        return 1
    else:
        fibo_minus1 = 1 #Fn-1
        fibo_minus2 = 0 #Fn-2
        for i in range(2,n):
            fibo = fibo_minus1 + fibo_minus2 #Fn = Fn-1 + Fn-2
            fibo_minus2 = fibo_minus1 # Fn-2の値を更新
            fibo_minus1 = fibo # Fn-1の値を更新
        return fibo
 
 
 
 
 
ans = 1
 
 
 
if M!= 1:
    length = a[0]
    ans *= Fib(length+1)
 
    for i in range(0,M-1):
        length = a[i+1]-a[i]-1
        # print(length)
        if length == 0:
            ans *= 0
        else:
            ans *= Fib(length+1)
        # print(ans)
 
 
    
if M==1:
    length = a[0]
    ans *= Fib(length+1)
 
 
 
 
length = N-a[-1]
 
 
ans *= Fib(length+1)
 
print(ans%wa)

### FIXED CODE ###

N,M = map(int,input().split())

a = [int(input()) for i in range(M)]

wa = (10**9) + 7

#dpを使う

dp = [0]*(N+1)
dp[0]=1
now_a = 0
if len(a)==0:
    now_a = -1
if len(a)!=0:
    a.reverse()
    now_a = a.pop()

for i in range(1,N+1):
    # print(now_a)
    if i==1:
        dp[i]=dp[i-1]
    else:
        dp[i]=dp[i-1] + dp[i-2]
    if i == now_a:
        dp[i]=0
        if len(a)!=0:
            now_a = a.pop()
        else:
            now_a = -1

# print(dp)

print(dp[N]%wa)
import math
h = int(input())
i = int(math.ceil(h/2))
print(int("1"*(i+1), 2))

### FIXED CODE ###

import math
h = int(input())
c = 0
while h > 1:
    h /= 2
    c += 1
if h == 1:
    print(int("1"*(c+1),2))
else:
    print(int("1"*c,2))
h,n= map(int, input().split())
a = sum(list(map(int,input().split())))
print("Yes" if h-a <=0 else "No")

### FIXED CODE ###

h, a = map(int, input().split())
print(h//a if h % a == 0 else h//a +1)
import numpy as np

lst=[]
while 1:
    try:
        lst.append(list(map(int, input().split())))
    except EOFError:
        break
for a in lst:
    A = np.array([[a[0],a[1]],
                  [a[3],a[4]]])
    b = np.array([a[2],a[5]])
    x = np.linalg.solve(A, b)
    print(x)


### FIXED CODE ###

while 1:
    try:
        a,b,c,d,e,f = map(float, input().split())  
        y=(c*d-a*f)/(b*d-a*e)
        x=(c-b*y)/a
        print("{0:.3f} {1:.3f}".format(x,y))
    except:
        break
,a,b=map(int, input().split())

x=int(n/(a+b))
if x*(a+b)+a <= n:
	print(a*(x+1))
else:
	print(n-b*x)

### FIXED CODE ###

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

x=int(n/(a+b))
if x*(a+b)+a <= n:
	print(a*(x+1))
else:
	print(n-b*x)