Input:
n,m = list(map(int,input().split()))

cost = []

for i in range(n):

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

    cost.append([a,b])

cost.sort()

cnt = 0

price = 0

for i in range(n):

    if cnt + cost[i][1] <= m:

        price += cost[i][0] * cost[i][1]

        cnt += cost[i][1]

    else:

        price += (m-cnt)*cost[i][0]

        print(price)

        exit()

print(price)

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

drink = []

for i in range(n):

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

    drink.append((a,b))

drink.sort()

ans = 0

for i in range(n):

    if m == 0:

        break

    if m >= drink[i][1]:

        ans += drink[i][0] * drink[i][1]

        m -= drink[i][1]

    else:

        ans += m*drink[i][0]

        m = 0

print(ans)

n, m = list(map(int, input().split()))
cost = []
for i in range(n):
    a, b = list(map(int, input().split()))
    cost.append([a, b])
cost.sort()
cnt = 0
price = 0
for i in range(n):
    if cnt + cost[i][1] <= m:
        price += cost[i][0] * cost[i][1]
        cnt += cost[i][1]
    else:
        price += (m - cnt) * cost[i][0]
        print(price)
        exit()
print(price)

n, m = list(map(int, input().split()))
drink = []
for i in range(n):
    a, b = list(map(int, input().split()))
    drink.append((a, b))
drink.sort()
ans = 0
for i in range(n):
    if m == 0:
        break
    if m >= drink[i][1]:
        ans += drink[i][0] * drink[i][1]
        m -= drink[i][1]
    else:
        ans += m * drink[i][0]
        m = 0
print(ans)

-        price += cost[i][0] * cost[i][1]

+        ans += drink[i][0] * drink[i][1]

-        price += (m - cnt) * cost[i][0]


Input:
from collections import deque

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

g = [[] for i in range(n)]

for i in range(m):

  u, v = list(map(int, input().split()))

  u, v = u-1, v-1

  g[u].append(v)

# print(g)

s, t = list(map(int, input().split()))

s, t = s-1, t-1

visited = [[-1]*3 for j in range(n)]

l = 0

queue = deque([[s, l]])

visited[s][l] = 0

while queue:

  x, l = queue.popleft()

  if [x, l] == [t, 0]:

    print((visited[x][l]//3))

    exit()

  for x_ in g[x]:

    new_x, new_l = x_, (l+1)%3

    if visited[new_x][new_l] == -1:

      visited[new_x][new_l] = visited[x][l]+1

      queue.append([new_x, new_l])

print((visited[t][0]))

import sys

input = sys.stdin.buffer.readline

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

g = [[] for _ in range(3*n)]

for i in range(m):

    u, v = list(map(int, input().split()))

    u, v = u-1, v-1

    g[u].append(v+n)

    g[u+n].append(v+2*n)

    g[u+2*n].append(v)

s, t = list(map(int, input().split()))

s, t = s-1, t-1

from collections import deque

q = deque()

visit = [-1]*(3*n)

q.append(s)

visit[s] = 0

while q:

    u = q.popleft()

    for v in g[u]:

        if visit[v] == -1:

            visit[v] = visit[u]+1

            q.append(v)

if visit[t] == -1:

    print((-1))

else:

    print((visit[t]//3))

from collections import deque

n, m = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(m):
    u, v = list(map(int, input().split()))
    u, v = u - 1, v - 1
    g[u].append(v)
# print(g)
s, t = list(map(int, input().split()))
s, t = s - 1, t - 1
visited = [[-1] * 3 for j in range(n)]
l = 0
queue = deque([[s, l]])
visited[s][l] = 0
while queue:
    x, l = queue.popleft()
    if [x, l] == [t, 0]:
        print((visited[x][l] // 3))
        exit()
    for x_ in g[x]:
        new_x, new_l = x_, (l + 1) % 3
        if visited[new_x][new_l] == -1:
            visited[new_x][new_l] = visited[x][l] + 1
            queue.append([new_x, new_l])
print((visited[t][0]))

import sys

input = sys.stdin.buffer.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(3 * n)]
for i in range(m):
    u, v = list(map(int, input().split()))
    u, v = u - 1, v - 1
    g[u].append(v + n)
    g[u + n].append(v + 2 * n)
    g[u + 2 * n].append(v)
s, t = list(map(int, input().split()))
s, t = s - 1, t - 1
from collections import deque

q = deque()
visit = [-1] * (3 * n)
q.append(s)
visit[s] = 0
while q:
    u = q.popleft()
    for v in g[u]:
        if visit[v] == -1:
            visit[v] = visit[u] + 1
            q.append(v)
if visit[t] == -1:
    print((-1))
else:
    print((visit[t] // 3))

-        if visited[new_x][new_l] == -1:

-            visited[new_x][new_l] = visited[x][l] + 1

-            queue.append([new_x, new_l])


Input:
n=eval(input())

k=int(eval(input()))

counter=0

nex=0

for i in range(len(n)):

  if n[i]=='1':

    counter+=1

  else:

    nex=n[i]

    break

if nex==0:

  nex='1'

if k>counter:

  print(nex)

else:

  print((1))

import sys

s=eval(input())

k=int(eval(input()))

for i in range(min(len(s),k)):

  if s[i]!='1':

    print((s[i]))

    sys.exit()

print((1))

n = eval(input())
k = int(eval(input()))
counter = 0
nex = 0
for i in range(len(n)):
    if n[i] == "1":
        counter += 1
    else:
        nex = n[i]
        break
if nex == 0:
    nex = "1"
if k > counter:
    print(nex)
else:
    print((1))

import sys

s = eval(input())
k = int(eval(input()))
for i in range(min(len(s), k)):
    if s[i] != "1":
        print((s[i]))
        sys.exit()
print((1))

-n = eval(input())
+import sys
+
+s = eval(input())
-counter = 0
-nex = 0
-for i in range(len(n)):
-    if n[i] == "1":
-        counter += 1
-    else:
-        nex = n[i]
-        break
-if nex == 0:
-    nex = "1"
-if k > counter:
-    print(nex)
-else:
-    print((1))
+for i in range(min(len(s), k)):
+    if s[i] != "1":
+        print((s[i]))
+        sys.exit()
+print((1))


Input:
N = int(eval(input()))

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

if N == 1:

    print((0))

    quit()

start = 0

moves = []

for i in range(N-1):

    moves.append(i - start)

    if H[i] < H[i+1]:

        start = i + 1

if H[N-2] >= H[N-1]:

    moves.append(i - start + 1)

print((max(moves)))

N = int(eval(input()))

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

if N == 1:

    print((0))

    quit()

count = 0

moves = []

for h0, h1 in zip(H,H[1:]):

    if h0 >= h1:

        count += 1

    else:

        moves.append(count)

        count = 0

print((max(moves + [count])))

N = int(eval(input()))
H = list(map(int, input().split()))
if N == 1:
    print((0))
    quit()
start = 0
moves = []
for i in range(N - 1):
    moves.append(i - start)
    if H[i] < H[i + 1]:
        start = i + 1
if H[N - 2] >= H[N - 1]:
    moves.append(i - start + 1)
print((max(moves)))

N = int(eval(input()))
H = list(map(int, input().split()))
if N == 1:
    print((0))
    quit()
count = 0
moves = []
for h0, h1 in zip(H, H[1:]):
    if h0 >= h1:
        count += 1
    else:
        moves.append(count)
        count = 0
print((max(moves + [count])))

-start = 0
+count = 0
-for i in range(N - 1):
-    moves.append(i - start)
-    if H[i] < H[i + 1]:
-        start = i + 1
-if H[N - 2] >= H[N - 1]:
-    moves.append(i - start + 1)
-print((max(moves)))
+for h0, h1 in zip(H, H[1:]):
+    if h0 >= h1:
+        count += 1
+    else:
+        moves.append(count)
+        count = 0
+print((max(moves + [count])))


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

div, rem = divmod(N, K)

mods = [div + (0 < i <= rem) for i in range(K)]

total = mods[0] ** 3

if not K & 1:

    total += mods[K >> 1] ** 3

print(total)

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

div, rem = divmod(N, K)

total = div ** 3

if not K & 1:

    total += (div + (0 < K <= (rem << 1))) ** 3

print(total)

N, K = list(map(int, input().split()))
div, rem = divmod(N, K)
total = div**3
if not K & 1:
    total += (div + (0 < K <= (rem << 1))) ** 3
print(total)

-mods = [div + (0 < i <= rem) for i in range(K)]


Input:
import sys

L=["A","B","AB","O"]

b={}

for e in L:

    b[e]=0

for s in sys.stdin:

    i = s[s.index(',')+1:-1]

    b[i]+=1

for e in L:

    print(b[e])

import sys

b=[s.split(',')[1][:-1] for s in sys.stdin]

for e in ["A","B","AB","O"]:

    print(b.count(e))

import sys

L = ["A", "B", "AB", "O"]
b = {}
for e in L:
    b[e] = 0
for s in sys.stdin:
    i = s[s.index(",") + 1 : -1]
    b[i] += 1
for e in L:
    print(b[e])

import sys

b = [s.split(",")[1][:-1] for s in sys.stdin]
for e in ["A", "B", "AB", "O"]:
    print(b.count(e))

+b = [s.split(",")[1][:-1] for s in sys.stdin]


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

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

s=sum(a)

candidates=set()

for i in range(1,int(s**0.5)+1):

  if s%i==0:

    candidates.add(i)

    candidates.add(s//i)

ans=0

for cdd in candidates:

  div_cdd=[0]*n

  for i in range(n):

    div_cdd[i]=a[i]%cdd

  div_cdd=sorted(div_cdd)

  pstv,ngtv=0,-sum(div_cdd)

  # calc need

  if pstv==-ngtv:

    ans=max(ans,cdd)

    continue

  for i in range(n):

    pstv+=cdd-div_cdd[-1-i]

    ngtv+=div_cdd[-1-i]

    if pstv==-ngtv: break

  ans=max(ans,cdd) if pstv<=k else ans

print(ans)

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

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

s=sum(a)

candidates=set()

for i in range(1,int(s**0.5)+1):

  if s%i==0:

    candidates.add(i)

    candidates.add(s//i)

ans=0

for cdd in candidates:

  div_cdd=[0]*n

  for i in range(n):

    div_cdd[i]=a[i]%cdd

  div_cdd=sorted(div_cdd)

  # calc need

  idx=n-sum(div_cdd)//cdd

  need=0

  for i in range(idx):

    need+=div_cdd[i]

  ans=max(ans,cdd) if need<=k else ans

print(ans)

n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
s = sum(a)
candidates = set()
for i in range(1, int(s**0.5) + 1):
    if s % i == 0:
        candidates.add(i)
        candidates.add(s // i)
ans = 0
for cdd in candidates:
    div_cdd = [0] * n
    for i in range(n):
        div_cdd[i] = a[i] % cdd
    div_cdd = sorted(div_cdd)
    pstv, ngtv = 0, -sum(div_cdd)
    # calc need
    if pstv == -ngtv:
        ans = max(ans, cdd)
        continue
    for i in range(n):
        pstv += cdd - div_cdd[-1 - i]
        ngtv += div_cdd[-1 - i]
        if pstv == -ngtv:
            break
    ans = max(ans, cdd) if pstv <= k else ans
print(ans)

n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
s = sum(a)
candidates = set()
for i in range(1, int(s**0.5) + 1):
    if s % i == 0:
        candidates.add(i)
        candidates.add(s // i)
ans = 0
for cdd in candidates:
    div_cdd = [0] * n
    for i in range(n):
        div_cdd[i] = a[i] % cdd
    div_cdd = sorted(div_cdd)
    # calc need
    idx = n - sum(div_cdd) // cdd
    need = 0
    for i in range(idx):
        need += div_cdd[i]
    ans = max(ans, cdd) if need <= k else ans
print(ans)

-    ans = max(ans, cdd) if pstv <= k else ans

+    ans = max(ans, cdd) if need <= k else ans


Input:
N = int(eval(input()))

M = 10**9 + 7

if N < 3:

    print((0))

elif N < 6:

    print((1))

else:

    dp = [0] * (N + 1)

    dp[3] = 1

    dp[4] = 1

    dp[5] = 1

    for i in range(6, N + 1):

        dp[i] = sum(dp[3:i - 3 + 1]) + 1

        dp[i] %= M

    print((dp[-1] % M))


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

p=0.0

for i in range(1,n+1):

    m=0

#    print(k,i,m,i*2**m)

    while k>i*2**m:

#        print(k,i,m,i*2**m)

        m=m+1

#    print(m)

    p=p+(0.5)**m/n

print(p)

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

ret=0

for i in range(1,n+1):

    now=i

    tmp=1/n

    while now<k:

        now*=2

        tmp/=2

    ret+=tmp

print(ret)

n, k = list(map(int, input().split()))
p = 0.0
for i in range(1, n + 1):
    m = 0
    #    print(k,i,m,i*2**m)
    while k > i * 2**m:
        #        print(k,i,m,i*2**m)
        m = m + 1
    #    print(m)
    p = p + (0.5) ** m / n
print(p)

n, k = list(map(int, input().split()))
ret = 0
for i in range(1, n + 1):
    now = i
    tmp = 1 / n
    while now < k:
        now *= 2
        tmp /= 2
    ret += tmp
print(ret)

-p = 0.0
+ret = 0
-    m = 0
-    #    print(k,i,m,i*2**m)
-    while k > i * 2**m:
-        #        print(k,i,m,i*2**m)
-        m = m + 1
-    #    print(m)
-    p = p + (0.5) ** m / n
-print(p)
+    now = i
+    tmp = 1 / n
+    while now < k:
+        now *= 2
+        tmp /= 2
+    ret += tmp
+print(ret)


Input:
a = eval(input(''))

print((a**3))

-a = eval(input(""))
-print((a**3))
+y = eval(input())
+print((y * y * y))


Input:
from numpy import*

k,A,F=[int64(t.split())for t in open(0)]

l=-1

r=10**12

while~l+r:

 m=l+r>>1

 if sum(A-minimum(sort(A),m//sort(F)[::-1]))>k[1]:l=m

 else:r=m

print(r)

(_,k),*t=[list(map(int,t.split()))for t in open(0)]

A,F=list(map(sorted,t))

o=10**12

g=-1

while~g+o:

 m,l=o+g>>1,k

 for a,f in zip(A,F[::-1]):l-=max(0,a-m//f)

 if l<0:g=m

 else:o=m

print(o)

from numpy import *

k, A, F = [int64(t.split()) for t in open(0)]
l = -1
r = 10**12
while ~l + r:
    m = l + r >> 1
    if sum(A - minimum(sort(A), m // sort(F)[::-1])) > k[1]:
        l = m
    else:
        r = m
print(r)

(_, k), *t = [list(map(int, t.split())) for t in open(0)]
A, F = list(map(sorted, t))
o = 10**12
g = -1
while ~g + o:
    m, l = o + g >> 1, k
    for a, f in zip(A, F[::-1]):
        l -= max(0, a - m // f)
    if l < 0:
        g = m
    else:
        o = m
print(o)

-k, A, F = [int64(t.split()) for t in open(0)]

-    if sum(A - minimum(sort(A), m // sort(F)[::-1])) > k[1]:

+(_, k), *t = [list(map(int, t.split())) for t in open(0)]


Input:
from sys import setrecursionlimit

#setrecursionlimit(10**5)

class UnionFind:

    def __init__(self, n):

        # 親要素のノード番号を格納

        # par[x]=xの時そのノードは根

        self.par = [i for i in range(n + 1)]

        # rank

        self.rank = [0] * (n + 1)

        self.size = [1] * (n + 1)

    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 check(self, x, y):

        # x,yが同じ集合に属するかどうか調べる

        return self.find(x) == self.find(y)

    def union(self, x, y):

        # 根を探す

        x = self.find(x)

        y = self.find(y)

        if x == y:return -1

        # rankの小さいものを大きいほうにくっつける

        if self.rank[x] < self.rank[y]:

            self.par[x] = y

            temp = self.size[x]

            self.size[y] += temp

            temp1 = self.size[y]

        else:

            self.par[y] = x

            temp = self.size[y]

            self.size[x] += temp

            temp1 = self.size[x]

            if self.rank[x] == self.rank[y]:

                self.rank[x] += 1

        return (temp, temp1)

    def count_group(self):

        return len({self.find(x) for x in range(1, n + 1)})

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

ab = [list(map(int,input().split())) for i in range(m)]

uf = UnionFind(n)

inc = [n * (n - 1) // 2] * m

for i in range(m - 1):

    a, b = ab[- i - 1]

    rec = uf.union(a, b)

    if rec == -1:

        inc[-i-2] = inc[-i-1]

        continue

    temp = rec[1] - rec[0]

    inc[-i-2] = max(inc[-i-1] - temp * rec[0], 0)

    #print(uf.size,inc,rec,temp)

print(*inc, sep = '\n')

from sys import setrecursionlimit

#setrecursionlimit(10**5)

class UnionFind:

    def __init__(self, n):

        # 親要素のノード番号を格納

        # par[x]=xの時そのノードは根

        self.par = [i for i in range(n + 1)]

        # rank

        self.rank = [0] * (n + 1)

        self.size = [1] * (n + 1)

    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 check(self, x, y):

        # x,yが同じ集合に属するかどうか調べる

        return self.find(x) == self.find(y)

    def union(self, x, y):

        # 根を探す

        x = self.find(x)

        y = self.find(y)

        if x == y:return

        # rankの小さいものを大きいほうにくっつける

        if self.rank[x] < self.rank[y]:

            self.par[x] = y

            self.size[y] += self.size[x]

        else:

            self.par[y] = x

            self.size[x] += self.size[y]

            if self.rank[x] == self.rank[y]:

                self.rank[x] += 1

    def count_group(self, n):

        return len({self.find(x) for x in range(1, n + 1)})

def com_2(n):

    if n == 1:return 0

    return n * (n - 1) // 2

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

ab = [list(map(int,input().split())) for i in range(m)]

ab = ab[::-1]

uf = UnionFind(n)

rec = [n * (n - 1) // 2] * m

for i in range(m - 1):

    a, b = ab[i]

    if uf.check(a, b):

        rec[i + 1] = rec[i]

        continue

    a_size = uf.size[uf.find(a)]

    b_size = uf.size[uf.find(b)]

    temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size)

    rec[i + 1] = rec[i] + temp

    uf.union(a, b)

rec = rec[::-1]

print(*rec, sep='\n')

from sys import setrecursionlimit

# setrecursionlimit(10**5)
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    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 check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)

    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return -1
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            temp = self.size[x]
            self.size[y] += temp
            temp1 = self.size[y]
        else:
            self.par[y] = x
            temp = self.size[y]
            self.size[x] += temp
            temp1 = self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return (temp, temp1)

    def count_group(self):
        return len({self.find(x) for x in range(1, n + 1)})

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
uf = UnionFind(n)
inc = [n * (n - 1) // 2] * m
for i in range(m - 1):
    a, b = ab[-i - 1]
    rec = uf.union(a, b)
    if rec == -1:
        inc[-i - 2] = inc[-i - 1]
        continue
    temp = rec[1] - rec[0]
    inc[-i - 2] = max(inc[-i - 1] - temp * rec[0], 0)
    # print(uf.size,inc,rec,temp)
print(*inc, sep="\n")

from sys import setrecursionlimit

# setrecursionlimit(10**5)
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    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 check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)

    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def count_group(self, n):
        return len({self.find(x) for x in range(1, n + 1)})

def com_2(n):
    if n == 1:
        return 0
    return n * (n - 1) // 2

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
ab = ab[::-1]
uf = UnionFind(n)
rec = [n * (n - 1) // 2] * m
for i in range(m - 1):
    a, b = ab[i]
    if uf.check(a, b):
        rec[i + 1] = rec[i]
        continue
    a_size = uf.size[uf.find(a)]
    b_size = uf.size[uf.find(b)]
    temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size)
    rec[i + 1] = rec[i] + temp
    uf.union(a, b)
rec = rec[::-1]
print(*rec, sep="\n")

+            self.size[y] += self.size[x]

+            self.size[x] += self.size[y]

+    temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size)


Input:
s = input().rstrip()

removed = 0

cnt_s = cnt_t = 0

for c in s:

    if c == 'S':

        cnt_s += 1

    else:

        cnt_t += 1

    if cnt_t > cnt_s:

        removed += cnt_s

        cnt_s = cnt_t = 0

#     print(cnt_s,cnt_t)

removed += min(cnt_s,cnt_t)

print((len(s) - removed*2))

s = input().rstrip()

n = len(s)

removed = 0

cnt_s = cnt_t = 0

for i in range(n):

    if s[i] == 'S':

        cnt_s += 1

    else:

        cnt_t += 1

    if i == n-1:

        removed += min(cnt_s,cnt_t)

    elif cnt_t > cnt_s:

        removed += cnt_s

        cnt_s = cnt_t = 0

#     print(cnt_s,cnt_t)

print((len(s) - removed*2))

s = input().rstrip()
removed = 0
cnt_s = cnt_t = 0
for c in s:
    if c == "S":
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
removed += min(cnt_s, cnt_t)
print((len(s) - removed * 2))

s = input().rstrip()
n = len(s)
removed = 0
cnt_s = cnt_t = 0
for i in range(n):
    if s[i] == "S":
        cnt_s += 1
    else:
        cnt_t += 1
    if i == n - 1:
        removed += min(cnt_s, cnt_t)
    elif cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
print((len(s) - removed * 2))

+n = len(s)
-for c in s:
-    if c == "S":
+for i in range(n):
+    if s[i] == "S":
-    if cnt_t > cnt_s:
+    if i == n - 1:
+        removed += min(cnt_s, cnt_t)
+    elif cnt_t > cnt_s:
-removed += min(cnt_s, cnt_t)


Input:
N = int(eval(input()))

A = list(map(int, input().split()))

B = [0]*N

for i in range(N-1, -1, -1):

  count = 0

  for j in range(i, N, i+1):

    count += B[j]

    if count%2 == A[i]:

      B[i] = 0

    else:

      B[i] = 1

sum = sum(B)

if sum == 0:

  print((0))

else:

  print(sum)

  ans = []

  for i in range(N):

    if B[i] == 1:

      ans.append(i+1)

  print((*ans))

N = int(eval(input()))
A = list(map(int, input().split()))
B = [0] * N
for i in range(N - 1, -1, -1):
    count = 0
    for j in range(i, N, i + 1):
        count += B[j]
        if count % 2 == A[i]:
            B[i] = 0
        else:
            B[i] = 1
sum = sum(B)
if sum == 0:
    print((0))
else:
    print(sum)
    ans = []
    for i in range(N):
        if B[i] == 1:
            ans.append(i + 1)
    print((*ans))


Input:
import sys

sys.setrecursionlimit(10**7)

def I(): return int(sys.stdin.readline().rstrip())

def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

def S(): return sys.stdin.readline().rstrip()

def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり

def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

W,H,x,y = MI()

if 2*x == W and 2*y == H:

    print((H*W/2,1))

else:

    print((H*W/2,0))

import sys

def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))

W,H,x,y = MI()

# 長方形の中心

if 2*x == W and 2*y == H:

    print((H*W/2,1))

else:

    print((H*W/2,0))

import sys

sys.setrecursionlimit(10**7)

def I():
    return int(sys.stdin.readline().rstrip())

def MI():
    return list(map(int, sys.stdin.readline().rstrip().split()))

def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり

def LI2():
    return list(map(int, sys.stdin.readline().rstrip()))  # 空白なし

def S():
    return sys.stdin.readline().rstrip()

def LS():
    return list(sys.stdin.readline().rstrip().split())  # 空白あり

def LS2():
    return list(sys.stdin.readline().rstrip())  # 空白なし

W, H, x, y = MI()
if 2 * x == W and 2 * y == H:
    print((H * W / 2, 1))
else:
    print((H * W / 2, 0))

import sys

def MI():
    return list(map(int, sys.stdin.readline().rstrip().split()))

W, H, x, y = MI()
# 長方形の中心
if 2 * x == W and 2 * y == H:
    print((H * W / 2, 1))
else:
    print((H * W / 2, 0))

-    return int(sys.stdin.readline().rstrip())

-    return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり

-    return list(map(int, sys.stdin.readline().rstrip()))  # 空白なし

-    return sys.stdin.readline().rstrip()

-    return list(sys.stdin.readline().rstrip().split())  # 空白あり

-    return list(sys.stdin.readline().rstrip())  # 空白なし


Input:
# Union find

# かっつぱさんの解説と公式のスライドみた

# https://www.youtube.com/watch?time_continue=916&v=zxor0DdwoXA&feature=emb_logo

# https://www.slideshare.net/chokudai/union-find-49066733

import sys

sys.setrecursionlimit(10 ** 9)

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

AB = [list(map(int, input().split())) for _ in range(m)]

root = [-1]*n

def find(x):

    if root[x] < 0:

        return x

    else:

        root[x] = find(root[x])

        return root[x]

def unite(x, y):

    gx = find(x)

    gy = find(y)

    if gx == gy:

        return

    if root[gx] > root[gy]:

        gx, gy = gy, gx

    root[gx] += root[gy]

    root[gy] = gx

def size(x):

    x = find(x)

    return -root[x]

for a, b in AB:

    a -= 1

    b -= 1

    unite(a, b)

ans = 0

for i in range(n):

    ans = max(ans, size(i))

print(ans)

import sys

sys.setrecursionlimit(10**9)

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

AB = [list(map(int, input().split())) for _ in range(m)]

root = [-1] * n

def find(x):

    if root[x] < 0:

        return x

    else:

        return find(root[x])

def unity(x, y):

    gx = find(x)

    gy = find(y)

    if gx == gy:

        return

    if root[gx] > root[gy]:

        gx, gy = gy, gx

    root[gx] += root[gy]

    root[gy] = gx

for a, b in AB:

    a -= 1

    b -= 1

    unity(a, b)

print((-min(root)))

# Union find
# かっつぱさんの解説と公式のスライドみた
# https://www.youtube.com/watch?time_continue=916&v=zxor0DdwoXA&feature=emb_logo
# https://www.slideshare.net/chokudai/union-find-49066733
import sys

sys.setrecursionlimit(10**9)
n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
root = [-1] * n

def find(x):
    if root[x] < 0:
        return x
    else:
        root[x] = find(root[x])
        return root[x]

def unite(x, y):
    gx = find(x)
    gy = find(y)
    if gx == gy:
        return
    if root[gx] > root[gy]:
        gx, gy = gy, gx
    root[gx] += root[gy]
    root[gy] = gx

def size(x):
    x = find(x)
    return -root[x]

for a, b in AB:
    a -= 1
    b -= 1
    unite(a, b)
ans = 0
for i in range(n):
    ans = max(ans, size(i))
print(ans)

-# かっつぱさんの解説と公式のスライドみた


Input:
A, B, N = list(map(int, input().split()))

alpha = A // B

beta = A % B

q = min(N, B - 1)

ans = alpha * q + (beta*q//B)

print(ans)

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

x = min(N, B-1)

print((A*x//B - A*(x//B)))

A, B, N = list(map(int, input().split()))
alpha = A // B
beta = A % B
q = min(N, B - 1)
ans = alpha * q + (beta * q // B)
print(ans)

A, B, N = list(map(int, input().split()))
x = min(N, B - 1)
print((A * x // B - A * (x // B)))

-alpha = A // B
-beta = A % B
-q = min(N, B - 1)
-ans = alpha * q + (beta * q // B)
-print(ans)
+x = min(N, B - 1)
+print((A * x // B - A * (x // B)))


Input: n=int(eval(input()));a=sorted(int(x)-i for i,x in enumerate(input().split()));print((sum(abs(i-a[n//2])for i in a)))

_,a=open(0);a=sorted(int(x)-i for i,x in enumerate(a.split()));print((sum(abs(i-a[len(a)//2])for i in a)))

n = int(eval(input()))
a = sorted(int(x) - i for i, x in enumerate(input().split()))
print((sum(abs(i - a[n // 2]) for i in a)))

_, a = open(0)
a = sorted(int(x) - i for i, x in enumerate(a.split()))
print((sum(abs(i - a[len(a) // 2]) for i in a)))

-a = sorted(int(x) - i for i, x in enumerate(input().split()))

-print((sum(abs(i - a[n // 2]) for i in a)))

+a = sorted(int(x) - i for i, x in enumerate(a.split()))

+print((sum(abs(i - a[len(a) // 2]) for i in a)))


Input:
temp=input().split()

W=int(temp[0])

H=int(temp[1])

x=int(temp[2])

y=int(temp[3])

S=W*H/2

if W/2==x and H/2==y:

  w=int(1)

else:

  w=int(0)

print((S, w))

W, H, x, y=list(map(int, input().split()))

S=W*H/2

output='0'

if x==W/2 and y==H/2:

  output='1'

print((' '.join([str(S), output])))

temp = input().split()
W = int(temp[0])
H = int(temp[1])
x = int(temp[2])
y = int(temp[3])
S = W * H / 2
if W / 2 == x and H / 2 == y:
    w = int(1)
else:
    w = int(0)
print((S, w))

W, H, x, y = list(map(int, input().split()))
S = W * H / 2
output = "0"
if x == W / 2 and y == H / 2:
    output = "1"
print((" ".join([str(S), output])))

+W, H, x, y = list(map(int, input().split()))


Input:
import sys

import collections

# input処理を高速化する

input = sys.stdin.readline

def chmax(a, b):

    """ 最大値を返す関数 """

    if a >= b:

        return a

    else:

        return b

def main():

    # 入力

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

    # 隣接関係は隣接リストで管理する

    lst_edge = [[] for _ in range(N)]

    # 各頂点の入力辺の本数

    deg = [0] * N

    for _ in range(M):

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

        # 最初のindexをゼロにする

        lst_edge[x-1].append(y-1)

        deg[y-1] += 1

    # 入力辺を持たない頂点をqueueに入れる

    que = collections.deque()

    for v in range(N):

        if deg[v] == 0:

            que.append(v)

    # 各頂点の最初に入力辺を持たなかった点からの距離

    dp = [0] * N

    while len(que) > 0:

        v = que.popleft()

        lst_nv = lst_edge[v]

        for nv in lst_nv:

            # エッジ(v, nv)をグラフから削除する

            deg[nv] -= 1

            if deg[nv] == 0:

                # エッジがなくなったことで、入力辺がなくなったらqueueに入れる

                que.append(nv)

                # 最初に入力辺を持たなかった点からの距離

                dp[nv] = chmax(dp[nv], dp[v] + 1)

    print((max(dp)))

main()

import sys

import collections

# input処理を高速化する

input = sys.stdin.readline

def chmax(a, b):

    """ 最大値を返す関数 """

    if a >= b:

        return a

    return b

def main():

    # 入力

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

    # 隣接関係は隣接リストで管理する

    lst_edge = [[] for _ in range(N)]

    # 各頂点の入力辺の本数

    deg = [0] * N

    for _ in range(M):

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

        # 最初のindexをゼロにする

        lst_edge[x-1].append(y-1)

        deg[y-1] += 1

    # 入力辺を持たない頂点をqueueに入れる

    que = collections.deque()

    for v in range(N):

        if deg[v] == 0:

            que.append(v)

    # 各頂点の最初に入力辺を持たなかった点からの距離

    dp = [0] * N

    while que:

        v = que.popleft()

        lst_nv = lst_edge[v]

        for nv in lst_nv:

            # エッジ(v, nv)をグラフから削除する

            deg[nv] -= 1

            if deg[nv] == 0:

                # エッジがなくなったことで、入力辺がなくなったらqueueに入れる

                que.append(nv)

                # 最初に入力辺を持たなかった点からの距離

                dp[nv] = chmax(dp[nv], dp[v] + 1)

    print((max(dp)))

main()

import sys
import collections

# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    """最大値を返す関数"""
    if a >= b:
        return a
    else:
        return b

def main():
    # 入力
    N, M = list(map(int, input().split()))
    # 隣接関係は隣接リストで管理する
    lst_edge = [[] for _ in range(N)]
    # 各頂点の入力辺の本数
    deg = [0] * N
    for _ in range(M):
        x, y = list(map(int, input().split()))
        # 最初のindexをゼロにする
        lst_edge[x - 1].append(y - 1)
        deg[y - 1] += 1
    # 入力辺を持たない頂点をqueueに入れる
    que = collections.deque()
    for v in range(N):
        if deg[v] == 0:
            que.append(v)
    # 各頂点の最初に入力辺を持たなかった点からの距離
    dp = [0] * N
    while len(que) > 0:
        v = que.popleft()
        lst_nv = lst_edge[v]
        for nv in lst_nv:
            # エッジ(v, nv)をグラフから削除する
            deg[nv] -= 1
            if deg[nv] == 0:
                # エッジがなくなったことで、入力辺がなくなったらqueueに入れる
                que.append(nv)
                # 最初に入力辺を持たなかった点からの距離
                dp[nv] = chmax(dp[nv], dp[v] + 1)
    print((max(dp)))

main()

import sys
import collections

# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    """最大値を返す関数"""
    if a >= b:
        return a
    return b

def main():
    # 入力
    N, M = list(map(int, input().split()))
    # 隣接関係は隣接リストで管理する
    lst_edge = [[] for _ in range(N)]
    # 各頂点の入力辺の本数
    deg = [0] * N
    for _ in range(M):
        x, y = list(map(int, input().split()))
        # 最初のindexをゼロにする
        lst_edge[x - 1].append(y - 1)
        deg[y - 1] += 1
    # 入力辺を持たない頂点をqueueに入れる
    que = collections.deque()
    for v in range(N):
        if deg[v] == 0:
            que.append(v)
    # 各頂点の最初に入力辺を持たなかった点からの距離
    dp = [0] * N
    while que:
        v = que.popleft()
        lst_nv = lst_edge[v]
        for nv in lst_nv:
            # エッジ(v, nv)をグラフから削除する
            deg[nv] -= 1
            if deg[nv] == 0:
                # エッジがなくなったことで、入力辺がなくなったらqueueに入れる
                que.append(nv)
                # 最初に入力辺を持たなかった点からの距離
                dp[nv] = chmax(dp[nv], dp[v] + 1)
    print((max(dp)))

main()

-    else:
-        return b
+    return b
-    while len(que) > 0:
+    while que:


Input:
w, h, x, y = list(map(int, input().split()))

area = w * h / 2

if 2 * x == w and 2 * y == h:

    print((area, 1))

else:

    print((area, 0))

import sys

input = sys.stdin.readline

ri = lambda: int(eval(input()))

rs = lambda: input().rstrip()

ril = lambda: list(map(int, input().split()))

rsl = lambda: input().rstrip().split()

ris = lambda n: [ri() for _ in range(n)]

rss = lambda n: [rs() for _ in range(n)]

rils = lambda n: [ril() for _ in range(n)]

rsls = lambda n: [rsl() for _ in range(n)]

w, h, x, y = ril()

s = w * h / 2

if w == 2 * x and h == 2 * y:

    print((s, 1))

else:

    print((s, 0))

-w, h, x, y = list(map(int, input().split()))

+ril = lambda: list(map(int, input().split()))

+ris = lambda n: [ri() for _ in range(n)]

+rss = lambda n: [rs() for _ in range(n)]

+rils = lambda n: [ril() for _ in range(n)]

+rsls = lambda n: [rsl() for _ in range(n)]


Input:
import sys

import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

def main():

    N = int(eval(input()))

    A = [int(eval(input())) for _ in range(N)]

    if N == 2:

        print((abs(A[0] - A[1])))

        return

    A.sort()

    q = collections.deque(A)

    ans = 0

    i = 0

    c = [q.popleft(), q.pop()]

    ans += abs(c[0] - c[1])

    while q:

        if len(q) >= 2:

            a = q.popleft()

            b = q.pop()

            al = abs(a - c[0])

            ar = abs(a - c[1])

            bl = abs(b - c[0])

            br = abs(b - c[1])

            ma = max([al, ar, bl, br])

            ans += ma

            if ma == al:

                c[0] = a

                q.append(b)

            elif ma == ar:

                c[1] = a

                q.append(b)

            elif ma == bl:

                c[0] = b

                q.appendleft(a)

            else:

                c[1] = b

                q.appendleft(a)

        else:

            a = q.pop()

            ans += max(abs(c[0] - a), abs(c[1] - a))

    print(ans)

if __name__ == '__main__':

    main()

import sys

import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

def main():

    N = int(eval(input()))

    A = [int(eval(input())) for _ in range(N)]

    A.sort()

    if N % 2 == 0:

        ans = sum(A[N // 2:]) * 2 - A[N // 2] - sum(A[:N // 2]) * 2 + A[N // 2 - 1]

    else:

        ans = sum(A[N // 2:]) * 2 - A[N // 2] - A[N // 2 + 1] - sum(A[:N // 2]) * 2

        ans = max(ans, sum(A[N // 2 + 1:]) * 2 - sum(A[:N // 2 + 1]) * 2 + A[N // 2] + A[N // 2 - 1])

    print(ans)

if __name__ == '__main__':

    main()

import sys
import collections

sys.setrecursionlimit(10**8)
input = sys.stdin.readline

def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    if N == 2:
        print((abs(A[0] - A[1])))
        return
    A.sort()
    q = collections.deque(A)
    ans = 0
    i = 0
    c = [q.popleft(), q.pop()]
    ans += abs(c[0] - c[1])
    while q:
        if len(q) >= 2:
            a = q.popleft()
            b = q.pop()
            al = abs(a - c[0])
            ar = abs(a - c[1])
            bl = abs(b - c[0])
            br = abs(b - c[1])
            ma = max([al, ar, bl, br])
            ans += ma
            if ma == al:
                c[0] = a
                q.append(b)
            elif ma == ar:
                c[1] = a
                q.append(b)
            elif ma == bl:
                c[0] = b
                q.appendleft(a)
            else:
                c[1] = b
                q.appendleft(a)
        else:
            a = q.pop()
            ans += max(abs(c[0] - a), abs(c[1] - a))
    print(ans)

if __name__ == "__main__":
    main()

import sys
import collections

sys.setrecursionlimit(10**8)
input = sys.stdin.readline

def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    A.sort()
    if N % 2 == 0:
        ans = sum(A[N // 2 :]) * 2 - A[N // 2] - sum(A[: N // 2]) * 2 + A[N // 2 - 1]
    else:
        ans = sum(A[N // 2 :]) * 2 - A[N // 2] - A[N // 2 + 1] - sum(A[: N // 2]) * 2
        ans = max(
            ans,
            sum(A[N // 2 + 1 :]) * 2
            - sum(A[: N // 2 + 1]) * 2
            + A[N // 2]
            + A[N // 2 - 1],
        )
    print(ans)

if __name__ == "__main__":
    main()


Input:
import sys

input=sys.stdin.readline

from bisect import bisect_left

class SegmentTree():

    def __init__(self,size,func,default):

        self.leaf=2**(size-1).bit_length()

        self.data=[default]*(2*self.leaf-1)

        self.f=func; self.d=default

    def rangeupdate(self,l,r,x):

        l+=self.leaf-1; r+=self.leaf-1

        while l<r:

            if not l&1:

                self.data[l]=self.f(self.data[l],x)

                l+=1

            if not r&1:

                r-=1

                self.data[r]=self.f(self.data[r],x)

            l>>=1; r>>=1

    def getvalue(self,i):

        k=i+self.leaf-1

        ret=self.d

        while k>=0:

            ret=self.f(ret,self.data[k])

            k=(k-1)>>1

        return ret

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

seg=SegmentTree(q,min,float('inf'))

STX=[list(map(int,input().split())) for _ in range(n)]

D=[int(eval(input())) for _ in range(q)]

for s,t,x in STX:

    seg.rangeupdate(bisect_left(D,s-x),bisect_left(D,t-x),x)

for i in range(q):

    print((-1 if seg.getvalue(i)==float('inf') else seg.getvalue(i)))

import sys

input=sys.stdin.readline

from bisect import bisect_left

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

STX=[tuple(map(int,input().split())) for _ in range(n)]

STX.sort(key=lambda x: x[2])

D=[int(input()) for _ in range(q)]

Ans=[-1]*q; Jump=[-1]*q

for s,t,x in STX:

    l=bisect_left(D,s-x)

    r=bisect_left(D,t-x)

    while l<r:

        s=Jump[l]

        if s==-1:

            Ans[l]=x

            Jump[l]=r

            l+=1

        else:

            l=s

print(*Ans,sep='\n')

import sys

input = sys.stdin.readline
from bisect import bisect_left

class SegmentTree:
    def __init__(self, size, func, default):
        self.leaf = 2 ** (size - 1).bit_length()
        self.data = [default] * (2 * self.leaf - 1)
        self.f = func
        self.d = default

    def rangeupdate(self, l, r, x):
        l += self.leaf - 1
        r += self.leaf - 1
        while l < r:
            if not l & 1:
                self.data[l] = self.f(self.data[l], x)
                l += 1
            if not r & 1:
                r -= 1
                self.data[r] = self.f(self.data[r], x)
            l >>= 1
            r >>= 1

    def getvalue(self, i):
        k = i + self.leaf - 1
        ret = self.d
        while k >= 0:
            ret = self.f(ret, self.data[k])
            k = (k - 1) >> 1
        return ret

n, q = list(map(int, input().split()))
seg = SegmentTree(q, min, float("inf"))
STX = [list(map(int, input().split())) for _ in range(n)]
D = [int(eval(input())) for _ in range(q)]
for s, t, x in STX:
    seg.rangeupdate(bisect_left(D, s - x), bisect_left(D, t - x), x)
for i in range(q):
    print((-1 if seg.getvalue(i) == float("inf") else seg.getvalue(i)))

import sys

input = sys.stdin.readline
from bisect import bisect_left

n, q = map(int, input().split())
STX = [tuple(map(int, input().split())) for _ in range(n)]
STX.sort(key=lambda x: x[2])
D = [int(input()) for _ in range(q)]
Ans = [-1] * q
Jump = [-1] * q
for s, t, x in STX:
    l = bisect_left(D, s - x)
    r = bisect_left(D, t - x)
    while l < r:
        s = Jump[l]
        if s == -1:
            Ans[l] = x
            Jump[l] = r
            l += 1
        else:
            l = s
print(*Ans, sep="\n")

-    def __init__(self, size, func, default):

-        self.leaf = 2 ** (size - 1).bit_length()

-        self.data = [default] * (2 * self.leaf - 1)

-                self.data[l] = self.f(self.data[l], x)

-                self.data[r] = self.f(self.data[r], x)

-            ret = self.f(ret, self.data[k])

-seg = SegmentTree(q, min, float("inf"))

-STX = [list(map(int, input().split())) for _ in range(n)]

-D = [int(eval(input())) for _ in range(q)]

+STX = [tuple(map(int, input().split())) for _ in range(n)]

-    seg.rangeupdate(bisect_left(D, s - x), bisect_left(D, t - x), x)

-    print((-1 if seg.getvalue(i) == float("inf") else seg.getvalue(i)))


Input:
n = int(input())

ls = list(map(int, input().split()))

menber = list(range(1, n+1))

dict1 = dict(zip(ls, menber))

dict1 = sorted(dict1.items(), key=lambda x: x[0])

for i in range(len(dict1)):

    print(dict1[i][1], end=' ')

n = int(eval(input()))

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

ans = [0]*n

for i, item in enumerate(a):

    ans[item-1] = i+1

print((*ans))

n = int(input())
ls = list(map(int, input().split()))
menber = list(range(1, n + 1))
dict1 = dict(zip(ls, menber))
dict1 = sorted(dict1.items(), key=lambda x: x[0])
for i in range(len(dict1)):
    print(dict1[i][1], end=" ")

n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * n
for i, item in enumerate(a):
    ans[item - 1] = i + 1
print((*ans))

-dict1 = sorted(dict1.items(), key=lambda x: x[0])


Input:
N,*A=list(map(int,open(0)));p=f=0

for a,b in zip(A,A[1:]):d,m=divmod(a-f,2);f=min(m,b);p+=d+f

print((p+(A[-1]-f)//2))

N,*A=list(map(int,open(0)));p=f=0

for a in A:d,m=divmod(a+f,2);p+=d;f=m&(a>0)

print(p)

N, *A = list(map(int, open(0)))
p = f = 0
for a, b in zip(A, A[1:]):
    d, m = divmod(a - f, 2)
    f = min(m, b)
    p += d + f
print((p + (A[-1] - f) // 2))

N, *A = list(map(int, open(0)))
p = f = 0
for a in A:
    d, m = divmod(a + f, 2)
    p += d
    f = m & (a > 0)
print(p)

-for a, b in zip(A, A[1:]):
-    d, m = divmod(a - f, 2)
-    f = min(m, b)
-    p += d + f
-print((p + (A[-1] - f) // 2))
+for a in A:
+    d, m = divmod(a + f, 2)
+    p += d
+    f = m & (a > 0)
+print(p)


Input:
n = int(eval(input()))

d = [0] * n

present = [[] for i in range(n)]

for i in range(n - 1):

    u, v = list(map(int, input().split()))

    u -= 1

    v -= 1

    if u > v:

        u, v = v, u

    d[v] += 1

    present[u].append(v)

ans = 0

cur = 0

for v in range(n):

    cur += (n - v) * d[v]

for l in range(n):

    ans += (l + 1) * (l + 2) // 2

    ans -= cur

    for v in present[l]:

        cur -= (n - v)

print(ans)

import sys

def read():

    return sys.stdin.readline()

def main():

    n = int(read())

    d = [0] * n

    present = [[] for i in range(n)]

    for i in range(n - 1):

        u, v = sorted([int(x) - 1 for x in read().split()])

        d[v] += 1

        present[u].append(v)

    ans, cur = 0, 0

    for v in range(n):

        cur += (n - v) * d[v]

    for L in range(n):

        ans += (L + 1) * (L + 2) // 2 - cur

        for v in present[L]:

            cur -= (n - v)

    print(ans)

if __name__ == '__main__':

    main()

n = int(eval(input()))
d = [0] * n
present = [[] for i in range(n)]
for i in range(n - 1):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    if u > v:
        u, v = v, u
    d[v] += 1
    present[u].append(v)
ans = 0
cur = 0
for v in range(n):
    cur += (n - v) * d[v]
for l in range(n):
    ans += (l + 1) * (l + 2) // 2
    ans -= cur
    for v in present[l]:
        cur -= n - v
print(ans)

import sys

def read():
    return sys.stdin.readline()

def main():
    n = int(read())
    d = [0] * n
    present = [[] for i in range(n)]
    for i in range(n - 1):
        u, v = sorted([int(x) - 1 for x in read().split()])
        d[v] += 1
        present[u].append(v)
    ans, cur = 0, 0
    for v in range(n):
        cur += (n - v) * d[v]
    for L in range(n):
        ans += (L + 1) * (L + 2) // 2 - cur
        for v in present[L]:
            cur -= n - v
    print(ans)

if __name__ == "__main__":
    main()

-    u, v = list(map(int, input().split()))

+        u, v = sorted([int(x) - 1 for x in read().split()])


Input:
def main():

    N = int(eval(input()))

    sp_lst = [0 for _ in range(N)]

    for i in range(N):

        S, P = input().split()

        sp_lst[i] = [i + 1, S, int(P)]

    sp_lst.sort(key=lambda x: x[2], reverse=True)

    sp_lst.sort(key=lambda x: x[1])

    for i, _, _ in sp_lst:

        print(i)

if __name__ == "__main__":

    main()

def main():

    N = int(eval(input()))

    s_dict = dict()

    for i in range(1, N + 1):

        S, P = input().split()

        if S in s_dict:

            s_dict[S].append((i, int(P)))

        else:

            s_dict[S] = [(i, int(P))]

    s_dict_keys = sorted(list(s_dict.keys()))

    for key in s_dict_keys:

        s_dict[key].sort(key=lambda x: x[1], reverse=True)

        for i, _ in s_dict[key]:

            print(i)

if __name__ == "__main__":

    main()

-    sp_lst.sort(key=lambda x: x[2], reverse=True)

+            s_dict[S].append((i, int(P)))

+    s_dict_keys = sorted(list(s_dict.keys()))

+        s_dict[key].sort(key=lambda x: x[1], reverse=True)


Input:
h,*c=open(0)

h,w,k=list(map(int,h.split()))

print((sum(k==sum(y>>w+z//w&y>>z%w&1and'.'>c[z//w][z%w]for z in range(h*w))for y in range(1<<h+w))))

h,*c=open(0)

h,w,k=list(map(int,h.split()))

print((sum(k==sum(y>>w+z//w&y>>z%w&('.'>c[z//w][z%w])for z in range(h*w))for y in range(1<<h+w))))

h, *c = open(0)
h, w, k = list(map(int, h.split()))
print(
    (
        sum(
            k
            == sum(
                y >> w + z // w & y >> z % w & 1 and "." > c[z // w][z % w]
                for z in range(h * w)
            )
            for y in range(1 << h + w)
        )
    )
)

h, *c = open(0)
h, w, k = list(map(int, h.split()))
print(
    (
        sum(
            k
            == sum(
                y >> w + z // w & y >> z % w & ("." > c[z // w][z % w])
                for z in range(h * w)
            )
            for y in range(1 << h + w)
        )
    )
)


Input:
def solve(string):

    *nkrsp, t = string.split()

    *t, = list(map(int, t.replace("r", "2").replace("s", "0").replace("p", "1")))

    n, k, *rsp = list(map(int, nkrsp))

    ans = 0

    for s in range(k):

        u = t[s::k]

        i = 0

        while i < len(u):

            c = 1

            while i < len(u) - 1 and u[i] == u[i + 1]:

                i += 1

                c += 1

            ans += (c + 1) // 2 * rsp[u[i]]

            i += 1

    return str(ans)

if __name__ == '__main__':

    import sys

    print((solve(sys.stdin.read().strip())))

def solve(string):

    *nkrsp, t = string.split()

    n, k, *rsp = list(map(int, nkrsp))

    table = {k: v for k, v in zip("spr", rsp)}

    ans = 0

    for s in range(k):

        u = t[s::k]

        i = 0

        while i < len(u):

            c = 1

            while i < len(u) - 1 and u[i] == u[i + 1]:

                i += 1

                c += 1

            ans += (c + 1) // 2 * table[u[i]]

            i += 1

    return str(ans)

if __name__ == '__main__':

    import sys

    print((solve(sys.stdin.read().strip())))

def solve(string):
    *nkrsp, t = string.split()
    (*t,) = list(map(int, t.replace("r", "2").replace("s", "0").replace("p", "1")))
    n, k, *rsp = list(map(int, nkrsp))
    ans = 0
    for s in range(k):
        u = t[s::k]
        i = 0
        while i < len(u):
            c = 1
            while i < len(u) - 1 and u[i] == u[i + 1]:
                i += 1
                c += 1
            ans += (c + 1) // 2 * rsp[u[i]]
            i += 1
    return str(ans)

if __name__ == "__main__":
    import sys

    print((solve(sys.stdin.read().strip())))

def solve(string):
    *nkrsp, t = string.split()
    n, k, *rsp = list(map(int, nkrsp))
    table = {k: v for k, v in zip("spr", rsp)}
    ans = 0
    for s in range(k):
        u = t[s::k]
        i = 0
        while i < len(u):
            c = 1
            while i < len(u) - 1 and u[i] == u[i + 1]:
                i += 1
                c += 1
            ans += (c + 1) // 2 * table[u[i]]
            i += 1
    return str(ans)

if __name__ == "__main__":
    import sys

    print((solve(sys.stdin.read().strip())))

+    table = {k: v for k, v in zip("spr", rsp)}


Input:
n = int(eval(input()))

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

dp = [1e9]*n

dp[0] = 0

for i in range(1, n):

  dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]))

  if i > 1:

    dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]))

print((dp[n-1]))

n = int(eval(input()))

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

dp = [1e9 for _ in range(n)]

#dp[i]...コストの最小

dp[0] = 0

dp[1] = abs(a[1] - a[0])

for i in range(n-2):

  dp[i+2] = min(dp[i+1] + abs(a[i+2] - a[i+1]), dp[i] + abs(a[i+2] - a[i]))

print((dp[n-1]))

n = int(eval(input()))
a = list(map(int, input().split()))
dp = [1e9] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]))
print((dp[n - 1]))

n = int(eval(input()))
a = list(map(int, input().split()))
dp = [1e9 for _ in range(n)]
# dp[i]...コストの最小
dp[0] = 0
dp[1] = abs(a[1] - a[0])
for i in range(n - 2):
    dp[i + 2] = min(dp[i + 1] + abs(a[i + 2] - a[i + 1]), dp[i] + abs(a[i + 2] - a[i]))
print((dp[n - 1]))


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

h,w = list(map(int, input().split()))

inf = 10**6

field = []

d = []

res = 0

for _ in range(h):

    line = list(eval(input()))

    field.append(line)

    d.append([inf]*w)

    for s in line:

        if s==".":

            res += 1

d[0][0] = 0

diff = [

    [1,0]

    ,[0,1]

    ,[-1,0]

    ,[0,-1]

]

flag = True

while flag:

    flag = False

    for hi in range(h):

        for wi in range(w):

            if d[hi][wi]<inf:

                for (dh,dw) in diff:

                    if h>hi+dh>=0 and w>wi+dw>=0 and field[hi+dh][wi+dw]=="." and d[hi+dh][wi+dw]>d[hi][wi]+1:

                        d[hi+dh][wi+dw] = d[hi][wi]+1

                        flag = True

if d[h-1][w-1]<inf:

    print((res-d[h-1][w-1]-1))

else:

    print((-1))

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

from queue import Queue

h,w = list(map(int, input().split()))

d = []

for _ in range(h):

    d.append(eval(input()))

cost = [[0]*w for _ in range(h)]

q = Queue()

q.put((0,0))

while not q.empty():

    hi,wi = q.get()

    if hi==h-1 and wi==w-1:

        break

    for dh,dw in [[0,1],[1,0],[0,-1],[-1,0]]:

        if h>dh+hi>=0 and w>dw+wi>=0 and d[dh+hi][dw+wi]==".":

            if cost[dh+hi][dw+wi]==0 or cost[dh+hi][dw+wi]>cost[hi][wi]+1:

                cost[dh+hi][dw+wi] = cost[hi][wi]+1

                q.put((dh+hi, dw+wi))

if cost[h-1][w-1]==0:

    print((-1))

    exit()

res = 0

for hi in range(h):

    for wi in range(w):

        if (hi==0 and wi==0) or (hi==h-1 and wi==-1):

            continue

        if d[hi][wi]==".":

            res += 1

print((res - cost[h-1][w-1]))

# -*- coding: utf-8 -*-
h, w = list(map(int, input().split()))
inf = 10**6
field = []
d = []
res = 0
for _ in range(h):
    line = list(eval(input()))
    field.append(line)
    d.append([inf] * w)
    for s in line:
        if s == ".":
            res += 1
d[0][0] = 0
diff = [[1, 0], [0, 1], [-1, 0], [0, -1]]
flag = True
while flag:
    flag = False
    for hi in range(h):
        for wi in range(w):
            if d[hi][wi] < inf:
                for (dh, dw) in diff:
                    if (
                        h > hi + dh >= 0
                        and w > wi + dw >= 0
                        and field[hi + dh][wi + dw] == "."
                        and d[hi + dh][wi + dw] > d[hi][wi] + 1
                    ):
                        d[hi + dh][wi + dw] = d[hi][wi] + 1
                        flag = True
if d[h - 1][w - 1] < inf:
    print((res - d[h - 1][w - 1] - 1))
else:
    print((-1))

# -*- coding: utf-8 -*-
from queue import Queue

h, w = list(map(int, input().split()))
d = []
for _ in range(h):
    d.append(eval(input()))
cost = [[0] * w for _ in range(h)]
q = Queue()
q.put((0, 0))
while not q.empty():
    hi, wi = q.get()
    if hi == h - 1 and wi == w - 1:
        break
    for dh, dw in [[0, 1], [1, 0], [0, -1], [-1, 0]]:
        if h > dh + hi >= 0 and w > dw + wi >= 0 and d[dh + hi][dw + wi] == ".":
            if cost[dh + hi][dw + wi] == 0 or cost[dh + hi][dw + wi] > cost[hi][wi] + 1:
                cost[dh + hi][dw + wi] = cost[hi][wi] + 1
                q.put((dh + hi, dw + wi))
if cost[h - 1][w - 1] == 0:
    print((-1))
    exit()
res = 0
for hi in range(h):
    for wi in range(w):
        if (hi == 0 and wi == 0) or (hi == h - 1 and wi == -1):
            continue
        if d[hi][wi] == ".":
            res += 1
print((res - cost[h - 1][w - 1]))

+        if h > dh + hi >= 0 and w > dw + wi >= 0 and d[dh + hi][dw + wi] == ".":

+            if cost[dh + hi][dw + wi] == 0 or cost[dh + hi][dw + wi] > cost[hi][wi] + 1:

+                cost[dh + hi][dw + wi] = cost[hi][wi] + 1

+                q.put((dh + hi, dw + wi))

-                        and w > wi + dw >= 0

-                        and field[hi + dh][wi + dw] == "."

-                        and d[hi + dh][wi + dw] > d[hi][wi] + 1

-                        d[hi + dh][wi + dw] = d[hi][wi] + 1


Input:
def main():

    n = int(eval(input()))

    ab = [] # type:[[int]]

    for i in range(n):

        ab.append([int(x) for x in input().split()])

    a, b = max(ab, key=lambda x: x[0])

    print((a + b))

if __name__ == "__main__":

    main()

def main():

    n = int(eval(input()))

    max_a, max_b = 0, 0 # type:int

    for _ in range(n):

        a, b = input().split()

        a = int(a)

        if max_a < a:

            max_a = a

            max_b = int(b)

    print((max_a + max_b))

if __name__ == "__main__":

    main()

-        ab.append([int(x) for x in input().split()])


Input:
for _ in[0]*int(eval(input())):

 X,z=eval(input()),[]

 for y in eval(input()):

  s=i=0

  for k in z:

   t=X.find(y,s)+1

   if t<1:break

   z[i]=min(t,k)

   s=k;i+=1

  else:

   t=X.find(y,s)+1

   if t:z+=[t]

 print((len(z)))

for _ in[0]*int(eval(input())):

 X,z=eval(input()),[]

 for y in eval(input()):

  s=i=0

  for k in z:

   t=X.find(y,s)+1

   if not t:break

   if t<k:z[i]=t

   s=k;i+=1

  else:

   t=X.find(y,s)+1

   if t:z+=[t]

 print((len(z)))

for _ in [0] * int(eval(input())):
    X, z = eval(input()), []
    for y in eval(input()):
        s = i = 0
        for k in z:
            t = X.find(y, s) + 1
            if t < 1:
                break
            z[i] = min(t, k)
            s = k
            i += 1
        else:
            t = X.find(y, s) + 1
            if t:
                z += [t]
    print((len(z)))

for _ in [0] * int(eval(input())):
    X, z = eval(input()), []
    for y in eval(input()):
        s = i = 0
        for k in z:
            t = X.find(y, s) + 1
            if not t:
                break
            if t < k:
                z[i] = t
            s = k
            i += 1
        else:
            t = X.find(y, s) + 1
            if t:
                z += [t]
    print((len(z)))

-            if t < 1:
+            if not t:
-            z[i] = min(t, k)
+            if t < k:
+                z[i] = t


Input:
# ABC084D - 2017-like Number

import sys

input = sys.stdin.readline

from bisect import bisect_left, bisect_right

def get_primes(n):

    # return a list of primes <= n

    n += 1  # include n itself

    sieve = [1] * n

    for i in range(3, int(n ** 0.5) + 1, 2):

        if sieve[i]:

            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)

    return [2] + [i for i in range(3, n, 2) if sieve[i]]

def main():

    Q = int(input())

    A = tuple(tuple(map(int, input().split())) for _ in range(Q))

    _, R = zip(*A)

    lim = max(R)

    P = get_primes(lim)

    S = set(P)

    selected_P = [p for p in P if (p + 1) // 2 in S]

    ans = []

    for l, r in A:

        x = bisect_right(selected_P, r) - bisect_left(selected_P, l)

        ans += [x]

    print(*ans, sep="\n")

if __name__ == "__main__":

    main()

# ABC084D - 2017-like Number

import sys

input = sys.stdin.readline

from bisect import bisect_left, bisect_right

def get_primes(n: int) -> list:

    # return a list of primes <= n

    n += 1  # include n itself

    sieve = [1] * n

    for i in range(3, int(n ** 0.5) + 1, 2):

        if sieve[i]:

            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)

    return [2] + [i for i in range(3, n, 2) if sieve[i]]

def main():

    Q = int(input())

    A = tuple(tuple(map(int, input().split())) for _ in range(Q))

    P = get_primes(10 ** 5)

    S = set(P)

    selected_P = [p for p in P if (p + 1) // 2 in S]

    ans = []

    bsr, bsl = bisect_right, bisect_left

    for l, r in A:

        x = bsr(selected_P, r) - bsl(selected_P, l)

        ans += [x]

    print(*ans, sep="\n")

if __name__ == "__main__":

    main()

# ABC084D - 2017-like Number
import sys

input = sys.stdin.readline
from bisect import bisect_left, bisect_right

def get_primes(n):
    # return a list of primes <= n
    n += 1  # include n itself
    sieve = [1] * n
    for i in range(3, int(n**0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]

def main():
    Q = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(Q))
    _, R = zip(*A)
    lim = max(R)
    P = get_primes(lim)
    S = set(P)
    selected_P = [p for p in P if (p + 1) // 2 in S]
    ans = []
    for l, r in A:
        x = bisect_right(selected_P, r) - bisect_left(selected_P, l)
        ans += [x]
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

# ABC084D - 2017-like Number
import sys

input = sys.stdin.readline
from bisect import bisect_left, bisect_right

def get_primes(n: int) -> list:
    # return a list of primes <= n
    n += 1  # include n itself
    sieve = [1] * n
    for i in range(3, int(n**0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]

def main():
    Q = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(Q))
    P = get_primes(10**5)
    S = set(P)
    selected_P = [p for p in P if (p + 1) // 2 in S]
    ans = []
    bsr, bsl = bisect_right, bisect_left
    for l, r in A:
        x = bsr(selected_P, r) - bsl(selected_P, l)
        ans += [x]
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

+    bsr, bsl = bisect_right, bisect_left

-        x = bisect_right(selected_P, r) - bisect_left(selected_P, l)

+        x = bsr(selected_P, r) - bsl(selected_P, l)


Input:
N, A, B = [int(x) for x in input().strip().split()]

p = N // (A + B) * A

q = N % (A + B)

if q > A:

    q = A

print((p + q))

"""

    Author: _YL_

"""

# b:blue, r:red

n, b, r = list(map(int, input().split()))

if b == 0:

    print("0")

elif r == 0:

    print(n)

else:

    remainder = n % (b+r)

    if remainder > b:

        remainder = b

    print((n//(b+r)*b+remainder))

"""
    Author: _YL_
"""
# b:blue, r:red
n, b, r = list(map(int, input().split()))
if b == 0:
    print("0")
elif r == 0:
    print(n)
else:
    remainder = n % (b + r)
    if remainder > b:
        remainder = b
    print((n // (b + r) * b + remainder))

-N, A, B = [int(x) for x in input().strip().split()]

+n, b, r = list(map(int, input().split()))

+    print((n // (b + r) * b + remainder))


Input:
H, W = list(map(int, input().split()))

s = [list(eval(input())) for i in range(H)]

dh = [-1, 0, 0, 1]

dw = [0, -1, 1, 0]

cnt = 0

for h in range(H):

  for w in range(W):

    # Check only black cell

    if s[h][w] == '.':

      continue

    for k in range(4):

      nh = h + dh[k]

      nw = w + dw[k]

      if nh < 0 or nw < 0 or H <= nh or W <= nw:

        continue

      # ok

      if s[nh][nw] == '#':

        break

    # failed

    else:

      cnt += 1

if cnt == 0:

  print('Yes')

else:

  print('No')

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

s = [list(eval(input())) for i in range(H)]

dh = [-1, 0, 0, 1]

dw = [0, -1, 1, 0]

cnt = 0

for h in range(H):

  for w in range(W):

    # Check only black cell

    if s[h][w] == '.':

      continue

    for k in range(4):

      nh = h + dh[k]

      nw = w + dw[k]

      if nh < 0 or nw < 0 or H <= nh or W <= nw:

        continue

      # ok

      if s[nh][nw] == '#':

        break

    # failed

    else:

      print('No')

      break

  else:

    continue

  break

else:

  print('Yes')

H, W = list(map(int, input().split()))
s = [list(eval(input())) for i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0
for h in range(H):
    for w in range(W):
        # Check only black cell
        if s[h][w] == ".":
            continue
        for k in range(4):
            nh = h + dh[k]
            nw = w + dw[k]
            if nh < 0 or nw < 0 or H <= nh or W <= nw:
                continue
            # ok
            if s[nh][nw] == "#":
                break
        # failed
        else:
            cnt += 1
if cnt == 0:
    print("Yes")
else:
    print("No")

H, W = list(map(int, input().split()))
s = [list(eval(input())) for i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0
for h in range(H):
    for w in range(W):
        # Check only black cell
        if s[h][w] == ".":
            continue
        for k in range(4):
            nh = h + dh[k]
            nw = w + dw[k]
            if nh < 0 or nw < 0 or H <= nh or W <= nw:
                continue
            # ok
            if s[nh][nw] == "#":
                break
        # failed
        else:
            print("No")
            break
    else:
        continue
    break
else:
    print("Yes")

-            cnt += 1
-if cnt == 0:
+            print("No")
+            break
+    else:
+        continue
+    break
+else:
-else:
-    print("No")


Input:
s = eval(input())

s = sorted(s)

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

ans = 'None'

for chr_alpha in ascii_lowercase:

  if chr_alpha not in s:

    ans = chr_alpha

    break

print(ans)

def main():

    s = eval(input())

    s = sorted(s)

    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

    ans = 'None'

    for chr_alpha in ascii_lowercase:

        if chr_alpha not in s:

            ans = chr_alpha

            break

    print(ans)

if __name__ == "__main__":

    main()

def main():
    s = eval(input())
    s = sorted(s)
    ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"
    ans = "None"
    for chr_alpha in ascii_lowercase:
        if chr_alpha not in s:
            ans = chr_alpha
            break
    print(ans)

if __name__ == "__main__":
    main()

+    ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"


Input:
n,m=[int(i) for i in input().split()]

ans=(n-m)*100

ans=(ans+1900*m)*2**m

print(ans)

n, m = [int(i) for i in input().split()]
ans = (n - m) * 100
ans = (ans + 1900 * m) * 2**m
print(ans)

-n, m = [int(i) for i in input().split()]


Input:
# 計算量 O(NC) = O(3 * 10 ** 6)

import sys

input = sys.stdin.readline

import numpy as np

N, C = list(map(int, input().split()))

# 入力

lst = [[0] * (10 ** 5 + 10) for _ in range(C + 1)]

lst_max = [[1] * (10 ** 5 + 10) for _ in range(C + 1)]

# lst = [[0] * (10) for _ in range(C + 1)]

# lst_max = [[1] * (10) for _ in range(C + 1)]

for _ in range(N):

    s, t, c = list(map(int, input().split()))

    lst[c][s] += 1

    lst[c][t + 1] -= 1

lst = np.array(lst)

np.cumsum(lst, axis = 1, out = lst)

np.minimum(lst, lst_max, out = lst)

np.cumsum(lst, axis = 0, out = lst)

print((np.max(lst[-1])))

# 計算量 O(NC) = O(3 * 10 ** 6)

import sys

input = sys.stdin.readline

import numpy as np

N, C = list(map(int, input().split()))

# 入力

lst = [[0] * (10 ** 5 + 10) for _ in range(C + 1)]

# lst_max = [[1] * (10 ** 5 + 10) for _ in range(C + 1)]

# lst = [[0] * (10) for _ in range(C + 1)]

# lst_max = [[1] * (10) for _ in range(C + 1)]

for _ in range(N):

    s, t, c = list(map(int, input().split()))

    lst[c][s] += 1

    lst[c][t + 1] -= 1

lst = np.array(lst)

np.cumsum(lst, axis = 1, out = lst)

np.minimum(lst, 1, out = lst)

np.cumsum(lst, axis = 0, out = lst)

print((np.max(lst[-1])))

# 計算量 O(NC) = O(3 * 10 ** 6)
import sys

input = sys.stdin.readline
import numpy as np

N, C = list(map(int, input().split()))
# 入力
lst = [[0] * (10**5 + 10) for _ in range(C + 1)]
lst_max = [[1] * (10**5 + 10) for _ in range(C + 1)]
# lst = [[0] * (10) for _ in range(C + 1)]
# lst_max = [[1] * (10) for _ in range(C + 1)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    lst[c][s] += 1
    lst[c][t + 1] -= 1
lst = np.array(lst)
np.cumsum(lst, axis=1, out=lst)
np.minimum(lst, lst_max, out=lst)
np.cumsum(lst, axis=0, out=lst)
print((np.max(lst[-1])))

# 計算量 O(NC) = O(3 * 10 ** 6)
import sys

input = sys.stdin.readline
import numpy as np

N, C = list(map(int, input().split()))
# 入力
lst = [[0] * (10**5 + 10) for _ in range(C + 1)]
# lst_max = [[1] * (10 ** 5 + 10) for _ in range(C + 1)]
# lst = [[0] * (10) for _ in range(C + 1)]
# lst_max = [[1] * (10) for _ in range(C + 1)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    lst[c][s] += 1
    lst[c][t + 1] -= 1
lst = np.array(lst)
np.cumsum(lst, axis=1, out=lst)
np.minimum(lst, 1, out=lst)
np.cumsum(lst, axis=0, out=lst)
print((np.max(lst[-1])))


Input:
n = int(input())

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

b = [0]*n

for i in range(n):

    b[a[i]-1] = i+1

for i in range(n):

    print(b[i],end=" ")

n = int(eval(input()))

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

b = [0]*n

for i in range(n):

    b[a[i]-1] = i+1

print((*b))

n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n):
    b[a[i] - 1] = i + 1
for i in range(n):
    print(b[i], end=" ")

n = int(eval(input()))
a = list(map(int, input().split()))
b = [0] * n
for i in range(n):
    b[a[i] - 1] = i + 1
print((*b))

-n = int(input())
+n = int(eval(input()))
-for i in range(n):
-    print(b[i], end=" ")
+print((*b))


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

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

bit=[0]*(2*n+1)

def add(t,x):

    while t<=n:

        bit[t]+=x

        t+=t&(-t)

def que(t):

    res=0

    while t:

        res+=bit[t]

        t-=t&(-t)

    return res

for i in range(n):

    add(i+1,a[i])

for _ in range(q):

    i,p,x=list(map(int, input().split()))

    if i:

        ans=que(x)-que(p)

        print(ans)

    else:

        add(p+1,x)

import sys

input=sys.stdin.readline

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

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

bit=[0]*(n+1)

def add(t,x):

    while t<=n:

        bit[t]+=x

        t+=t&(-t)

def que(t):

    res=0

    while t:

        res+=bit[t]

        t-=t&(-t)

    return res

for i in range(n):

    add(i+1,a[i])

for _ in range(q):

    i,p,x=list(map(int, input().split()))

    if i:

        ans=que(x)-que(p)

        print(ans)

    else:

        add(p+1,x)

n, q = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
bit = [0] * (2 * n + 1)

def add(t, x):
    while t <= n:
        bit[t] += x
        t += t & (-t)

def que(t):
    res = 0
    while t:
        res += bit[t]
        t -= t & (-t)
    return res

for i in range(n):
    add(i + 1, a[i])
for _ in range(q):
    i, p, x = list(map(int, input().split()))
    if i:
        ans = que(x) - que(p)
        print(ans)
    else:
        add(p + 1, x)

import sys

input = sys.stdin.readline
n, q = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
bit = [0] * (n + 1)

def add(t, x):
    while t <= n:
        bit[t] += x
        t += t & (-t)

def que(t):
    res = 0
    while t:
        res += bit[t]
        t -= t & (-t)
    return res

for i in range(n):
    add(i + 1, a[i])
for _ in range(q):
    i, p, x = list(map(int, input().split()))
    if i:
        ans = que(x) - que(p)
        print(ans)
    else:
        add(p + 1, x)

+import sys
+
+input = sys.stdin.readline
-bit = [0] * (2 * n + 1)
+bit = [0] * (n + 1)


Input:
d, n = list(map(int, input().split()))

for i in range(1, 100000000):

    if i % (100 ** d) == 0 and i % (100 * 100 ** d) != 0:

        n -= 1

    if n == 0:

        print(i)

        exit()

# Problem B - Ringo's Favorite Numbers

# input

D, N = list(map(int, input().split()))

# initialization

ans = 0

tmp = 100**D

# count

i = 1

while i<=N:

    if i==100:

        ans = tmp * (i + 1)

        break

    ans = tmp * i

    i += 1

# output

print(ans)

# Problem B - Ringo's Favorite Numbers
# input
D, N = list(map(int, input().split()))
# initialization
ans = 0
tmp = 100**D
# count
i = 1
while i <= N:
    if i == 100:
        ans = tmp * (i + 1)
        break
    ans = tmp * i
    i += 1
# output
print(ans)


Input:
import math

n=int(eval(input()))

c=[]

s=[]

f=[]

for i in range(n-1):

    C,S,F=list(map(int,input().split()))

    c.append(C)

    s.append(S)

    f.append(F)

for j in range(n-1):

    t=s[j]

    for i in range(j,n-1):

        if t<=s[i]:

            t=s[i]+c[i]

        else:

            k=t-s[i]

            t=s[i]+math.ceil(k/f[i])*f[i]+c[i]

    print( t)

print((0))

import math

n=int(eval(input()))

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

for j in range(n-1):

    now=0

    for i in range(j,n-1):

        if csf[i][1]>=now:

            now=csf[i][1]+csf[i][0]

        else:

            now=csf[i][1]-((csf[i][1]-now)//csf[i][2])*csf[i][2]+csf[i][0]

    print(now)

print((0))

import math

n = int(eval(input()))
c = []
s = []
f = []
for i in range(n - 1):
    C, S, F = list(map(int, input().split()))
    c.append(C)
    s.append(S)
    f.append(F)
for j in range(n - 1):
    t = s[j]
    for i in range(j, n - 1):
        if t <= s[i]:
            t = s[i] + c[i]
        else:
            k = t - s[i]
            t = s[i] + math.ceil(k / f[i]) * f[i] + c[i]
    print(t)
print((0))

import math

n = int(eval(input()))
csf = [list(map(int, input().split())) for i in range(n - 1)]
for j in range(n - 1):
    now = 0
    for i in range(j, n - 1):
        if csf[i][1] >= now:
            now = csf[i][1] + csf[i][0]
        else:
            now = csf[i][1] - ((csf[i][1] - now) // csf[i][2]) * csf[i][2] + csf[i][0]
    print(now)
print((0))

-    C, S, F = list(map(int, input().split()))

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

-            t = s[i] + math.ceil(k / f[i]) * f[i] + c[i]


Input:
import bisect

n = int(eval(input()))

l = sorted(list(map(int, input().split())))

s = 0

for i in range(0,n-2):

  a = l[i]

  for j in range(i+1,n-1):

    b = l[j]

    s += bisect.bisect_left(l,a+b,j+1)-j-1

print(s)

import bisect

n = int(eval(input()))

l = sorted(list(map(int, input().split())))

s = 0

for i in range(0,n-2):

  a = l[i]

  for j in range(i+1,n-1):

    b = l[j]

    s += bisect.bisect_left(l,a+b)-j-1

print(s)

import bisect

n = int(eval(input()))
l = sorted(list(map(int, input().split())))
s = 0
for i in range(0, n - 2):
    a = l[i]
    for j in range(i + 1, n - 1):
        b = l[j]
        s += bisect.bisect_left(l, a + b, j + 1) - j - 1
print(s)

import bisect

n = int(eval(input()))
l = sorted(list(map(int, input().split())))
s = 0
for i in range(0, n - 2):
    a = l[i]
    for j in range(i + 1, n - 1):
        b = l[j]
        s += bisect.bisect_left(l, a + b) - j - 1
print(s)

-        s += bisect.bisect_left(l, a + b, j + 1) - j - 1

+        s += bisect.bisect_left(l, a + b) - j - 1


Input:
N = int(eval(input()))

S = eval(input())

t = [S[0]]

p = S[0]

r = 1

for i in range(1, N):

  if S[i] == p:

    r += 1

    if r < 4:

      t.append(S[i])

  else:

    r = 1

    t.append(S[i])

T = ''.join(t)

result = 0

for i in range(10):

  a = T.find(str(i))

  if a == -1:

    continue

  for j in range(10):

    b = T.find(str(j), a + 1)

    if b == -1:

      continue

    for k in range(10):

      if T.find(str(k), b + 1) != -1:

        result += 1

print(result)

N = int(eval(input()))

S = eval(input())

result = 0

for i in range(10):

  a = S.find(str(i))

  if a == -1:

    continue

  for j in range(10):

    b = S.find(str(j), a + 1)

    if b == -1:

      continue

    for k in range(10):

      if S.find(str(k), b + 1) != -1:

        result += 1

print(result)

N = int(eval(input()))
S = eval(input())
t = [S[0]]
p = S[0]
r = 1
for i in range(1, N):
    if S[i] == p:
        r += 1
        if r < 4:
            t.append(S[i])
    else:
        r = 1
        t.append(S[i])
T = "".join(t)
result = 0
for i in range(10):
    a = T.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = T.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            if T.find(str(k), b + 1) != -1:
                result += 1
print(result)


Input:
from collections import defaultdict

from heapq import heappop, heappush

N = int(eval(input()))

class Graph(object):

    def __init__(self):

        self.graph = defaultdict(list)

    def __len__(self):

        return len(self.graph)

    def add_edge(self, src, dst, weight=1):

        self.graph[src].append((dst, weight))

    def get_nodes(self):

        return list(self.graph.keys())

class Dijkstra(object):

    def __init__(self, graph, start):

        g = graph.graph

        self.dist = defaultdict(lambda: float('inf'))

        self.dist[start] = 0

        self.prev = defaultdict(lambda: None)

        Q = []

        heappush(Q, (self.dist[start], start))

        while Q:

            dist_u, u = heappop(Q)

            if self.dist[u] < dist_u:

                continue

            for v, weight in g[u]:

                alt = dist_u + weight

                if self.dist[v] > alt:

                    self.dist[v] = alt

                    self.prev[v] = u

                    heappush(Q, (alt, v))

    def shortest_distance(self, goal):

        return self.dist[goal]

    def shortest_path(self, goal):

        path = []

        node = goal

        while node is not None:

            path.append(node)

            node = self.prev[node]

        return path[::-1]

g = Graph()

for _ in range(N - 1):

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

    g.add_edge(a - 1, b - 1)

    g.add_edge(b - 1, a - 1)

d1 = Dijkstra(g, 0)

d2 = Dijkstra(g, N - 1)

c1, c2 = 0, 0

for i in range(N):

    if d1.shortest_distance(i) <= d2.shortest_distance(i):

        c1 += 1

    else:

        c2 += 1

if c1 > c2:

    print('Fennec')

else:

    print('Snuke')

import sys

from collections import defaultdict

from heapq import heappop, heappush

input = sys.stdin.readline

N = int(eval(input()))

class Graph(object):

    def __init__(self):

        self.graph = defaultdict(list)

    def __len__(self):

        return len(self.graph)

    def add_edge(self, src, dst, weight=1):

        self.graph[src].append((dst, weight))

    def get_nodes(self):

        return list(self.graph.keys())

class Dijkstra(object):

    def __init__(self, graph, start):

        g = graph.graph

        self.dist = defaultdict(lambda: float('inf'))

        self.dist[start] = 0

        self.prev = defaultdict(lambda: None)

        Q = []

        heappush(Q, (self.dist[start], start))

        while Q:

            dist_u, u = heappop(Q)

            if self.dist[u] < dist_u:

                continue

            for v, weight in g[u]:

                alt = dist_u + weight

                if self.dist[v] > alt:

                    self.dist[v] = alt

                    self.prev[v] = u

                    heappush(Q, (alt, v))

    def shortest_distance(self, goal):

        return self.dist[goal]

g = Graph()

for _ in range(N - 1):

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

    g.add_edge(a - 1, b - 1)

    g.add_edge(b - 1, a - 1)

d1 = Dijkstra(g, 0)

d2 = Dijkstra(g, N - 1)

cnt1, cnt2 = 0, 0

for i in range(1, N - 1):

    x = d1.shortest_distance(i)

    y = d2.shortest_distance(i)

    if x <= y:

        cnt1 += 1

    else:

        cnt2 += 1

if cnt1 > cnt2:

    print('Fennec')

else:

    print('Snuke')

from collections import defaultdict
from heapq import heappop, heappush

N = int(eval(input()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return list(self.graph.keys())

class Dijkstra(object):
    def __init__(self, graph, start):
        g = graph.graph
        self.dist = defaultdict(lambda: float("inf"))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)
        Q = []
        heappush(Q, (self.dist[start], start))
        while Q:
            dist_u, u = heappop(Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

g = Graph()
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    g.add_edge(a - 1, b - 1)
    g.add_edge(b - 1, a - 1)
d1 = Dijkstra(g, 0)
d2 = Dijkstra(g, N - 1)
c1, c2 = 0, 0
for i in range(N):
    if d1.shortest_distance(i) <= d2.shortest_distance(i):
        c1 += 1
    else:
        c2 += 1
if c1 > c2:
    print("Fennec")
else:
    print("Snuke")

import sys
from collections import defaultdict
from heapq import heappop, heappush

input = sys.stdin.readline
N = int(eval(input()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return list(self.graph.keys())

class Dijkstra(object):
    def __init__(self, graph, start):
        g = graph.graph
        self.dist = defaultdict(lambda: float("inf"))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)
        Q = []
        heappush(Q, (self.dist[start], start))
        while Q:
            dist_u, u = heappop(Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

g = Graph()
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    g.add_edge(a - 1, b - 1)
    g.add_edge(b - 1, a - 1)
d1 = Dijkstra(g, 0)
d2 = Dijkstra(g, N - 1)
cnt1, cnt2 = 0, 0
for i in range(1, N - 1):
    x = d1.shortest_distance(i)
    y = d2.shortest_distance(i)
    if x <= y:
        cnt1 += 1
    else:
        cnt2 += 1
if cnt1 > cnt2:
    print("Fennec")
else:
    print("Snuke")

-    if d1.shortest_distance(i) <= d2.shortest_distance(i):


Input:
import sys

readline = sys.stdin.readline

from operator import itemgetter

def main():

    N = int(readline())

    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]

    AB.sort(key=itemgetter(1))

    t = 0

    for a, b in AB:

        t += a

        if t > b:

            print('No')

            return

    print('Yes')

if __name__ == '__main__':

    main()

import sys

readline = sys.stdin.readline

from operator import itemgetter

def main():

    N = int(readline())

    AB = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]

    AB.sort(key=itemgetter(1))

    t = 0

    for a, b in AB:

        t += a

        if t > b:

            print('No')

            return

    print('Yes')

if __name__ == '__main__':

    main()

import sys

readline = sys.stdin.readline
from operator import itemgetter

def main():
    N = int(readline())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print("No")
            return
    print("Yes")

if __name__ == "__main__":
    main()

import sys

readline = sys.stdin.readline
from operator import itemgetter

def main():
    N = int(readline())
    AB = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print("No")
            return
    print("Yes")

if __name__ == "__main__":
    main()

-    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]

+    AB = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]


Input:
n = int(eval(input()))

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

y = list(map(int, input().split()))

p = 0

q = 0

p1 = 0

p2 = 0

p3 = 0

max = 0

import math

for i, j in zip(x, y):

    p1 += abs(i - j)

    p += abs((i - j) ** 2)

    p2 = math.sqrt(p)

    q += abs((i - j) ** 3)

    p3 = math.pow(q, 1.0/3.0)

    if abs(i - j) > max:

        max = abs(i - j)

print(p1)

print(p2)

print(p3)

print(max)

import math

n = int(eval(input()))

x = [float(x) for x in input().split()]

y = [float(y) for y in input().split()]

d = 0

for i in range(n):

    d += abs(x[i] - y[i])

print(d)

d = 0

for i in range(n):

    d += abs((x[i] - y[i])**2)

d = math.sqrt(d)

print(d)

d = 0

for i in range(n):

    d += abs((x[i] - y[i])**3)

d = math.pow(d, 1.0/3.0)

print(d)

d = 0

for i in range(n):

    if d <= abs(x[i] - y[i]):

        d = abs(x[i] - y[i])

print(d)

n = int(eval(input()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
p = 0
q = 0
p1 = 0
p2 = 0
p3 = 0
max = 0
import math

for i, j in zip(x, y):
    p1 += abs(i - j)
    p += abs((i - j) ** 2)
    p2 = math.sqrt(p)
    q += abs((i - j) ** 3)
    p3 = math.pow(q, 1.0 / 3.0)
    if abs(i - j) > max:
        max = abs(i - j)
print(p1)
print(p2)
print(p3)
print(max)

import math

n = int(eval(input()))
x = [float(x) for x in input().split()]
y = [float(y) for y in input().split()]
d = 0
for i in range(n):
    d += abs(x[i] - y[i])
print(d)
d = 0
for i in range(n):
    d += abs((x[i] - y[i]) ** 2)
d = math.sqrt(d)
print(d)
d = 0
for i in range(n):
    d += abs((x[i] - y[i]) ** 3)
d = math.pow(d, 1.0 / 3.0)
print(d)
d = 0
for i in range(n):
    if d <= abs(x[i] - y[i]):
        d = abs(x[i] - y[i])
print(d)

+x = [float(x) for x in input().split()]

+y = [float(y) for y in input().split()]


Input:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read

input = sys.stdin.buffer.readline

def inputS(): return input().rstrip().decode()

readlines = sys.stdin.buffer.readlines

from functools import reduce

def gcd(a, b):

  while b:

    a, b = b, a%b

  return a

def lcm(a, b):

  return a*b // gcd(a, b)

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

A = list(map(int, input().split()))

# 2で割ったものに置き換え a -> a'

Ad = [a//2 for a in A]

# 各要素について、2で割り切れる回数が等しいかチェック

div2 = None

for a in Ad:

  cnt = 0

  while a%2 == 0:

    a //= 2

    cnt += 1

  if div2 is None:

    div2 = cnt

  elif div2 != cnt:

    print((0))

    exit()

# LCM

_lcm = reduce(lcm, Ad)

if _lcm > M:

  print((0))

  exit()

print(((M//_lcm + 1) // 2))   # 切り上げ

import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read

input = sys.stdin.buffer.readline

def inputS(): return input().rstrip().decode()

readlines = sys.stdin.buffer.readlines

from functools import reduce

def gcd(a, b):

  while b:

    a, b = b, a%b

  return a

def lcm(a, b):

  return a*b // gcd(a, b)

def div2cnt(a):

  cnt = 0

  while a%2 == 0:

    a //= 2

    cnt += 1

  return cnt

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

A = list(map(int, input().split()))

# 2で割ったものに置き換え a -> a'

Ad = [a//2 for a in A]

# 各要素について、2で割り切れる回数が等しいかチェック

div2 = div2cnt(Ad[0])

for a in Ad:

  if div2cnt(a) != div2:

    print((0))

    exit()

# LCM

_lcm = reduce(lcm, Ad)

if _lcm > M:

  print((0))

  exit()

print(((M//_lcm + 1) // 2))   # 切り上げ

import sys

sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline

def inputS():
    return input().rstrip().decode()

readlines = sys.stdin.buffer.readlines
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
# 2で割ったものに置き換え a -> a'
Ad = [a // 2 for a in A]
# 各要素について、2で割り切れる回数が等しいかチェック
div2 = None
for a in Ad:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1
    if div2 is None:
        div2 = cnt
    elif div2 != cnt:
        print((0))
        exit()
# LCM
_lcm = reduce(lcm, Ad)
if _lcm > M:
    print((0))
    exit()
print(((M // _lcm + 1) // 2))  # 切り上げ

import sys

sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline

def inputS():
    return input().rstrip().decode()

readlines = sys.stdin.buffer.readlines
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def div2cnt(a):
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1
    return cnt

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
# 2で割ったものに置き換え a -> a'
Ad = [a // 2 for a in A]
# 各要素について、2で割り切れる回数が等しいかチェック
div2 = div2cnt(Ad[0])
for a in Ad:
    if div2cnt(a) != div2:
        print((0))
        exit()
# LCM
_lcm = reduce(lcm, Ad)
if _lcm > M:
    print((0))
    exit()
print(((M // _lcm + 1) // 2))  # 切り上げ

+def div2cnt(a):
+    cnt = 0
+    while a % 2 == 0:
+        a //= 2
+        cnt += 1
+    return cnt
+
+
-div2 = None
+div2 = div2cnt(Ad[0])
-    cnt = 0
-    while a % 2 == 0:
-        a //= 2
-        cnt += 1
-    if div2 is None:
-        div2 = cnt
-    elif div2 != cnt:
+    if div2cnt(a) != div2:


Input:
import sys

import itertools

# import numpy as np

import time

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

class UnionFind(object):

    def __init__(self, n = 1):

        self.link = [i for i in range(n)]

        self.size = [1 for _ in range(n)]

    def find(self, x):

        if self.link[x] == x:

            return x

        # re-connect union find to make the height of tree lower

        # you can use while, but recursion makes it easier to reconnect

        self.link[x] = self.find(self.link[x])

        return self.link[x]

    def is_same(self, x, y):

        return self.find(x) == self.find(y)

    def unite(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.size[x] < self.size[y]:

            x, y = y, x

        self.link[y] = x

        self.size[x] += self.size[y]

    def get_size(self, x):

        x = self.find(x)

        return self.size[x]

# from union_find import *

# n, m = map(int, readline().split())

# u = UnionFind(n)

# a = [0 for _ in range(m)]

# b = [0 for _ in range(m)]

# for i in range(m):

#     a[i], b[i] = map(lambda x: int(x) - 1, readline().split())

# ans = [None for _ in range(m)]

# ans[-1] = n * (n - 1) // 2

# for i in range(m - 1, 0, -1):

#     x = a[i]

#     y = b[i]

#     if u.is_same(x, y):

#         ans[i - 1] = ans[i]

#     else:

#         ans[i - 1] = ans[i] - (u.get_size(x) * u.get_size(y))

#     u.unite(x, y)

# for a in ans:

#     print(a)

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

A, B = [None] * M, [None] * M

for i in range(M):

    A[i], B[i] = list(map(int, input().split()))

uf = UnionFind(N)

ans = [None] * M

ans[M - 1] = N * (N - 1) // 2

for i in range(M - 1, 0, -1):

    x, y = A[i] - 1, B[i] - 1

    if uf.is_same(x, y):

        ans[i - 1] = ans[i]

    else:

        ans[i - 1] = ans[i] - (uf.get_size(x) * uf.get_size(y))

    uf.unite(x, y)

for a in ans:

    print(a)

import sys

import itertools

# import numpy as np

import time

import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

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

class UnionFind(object):

    def __init__(self, n = 1):

        self.link = [i for i in range(n)]

        self.size = [1 for _ in range(n)]

    def find(self, x):

        if self.link[x] == x:

            return x

        # re-connect union find to make the height of tree lower

        # you can use while, but recursion makes it easier to reconnect

        self.link[x] = self.find(self.link[x])

        return self.link[x]

    def is_same(self, x, y):

        return self.find(x) == self.find(y)

    def unite(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.size[x] < self.size[y]:

            x, y = y, x

        self.link[y] = x

        self.size[x] += self.size[y]

    def get_size(self, x):

        x = self.find(x)

        return self.size[x]

es = [0] * M

for i in range(M):

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

    es[i] = (a - 1, b - 1)

u = UnionFind(N)

ans = []

pair = N * (N - 1) // 2

ans.append(pair)

for i in range(M - 1, -1, -1):

    a, b = es[i]

    if u.is_same(a, b):

        ans.append(pair)

        continue

    pair -= (u.get_size(a) * u.get_size(b))

    u.unite(a ,b)

    if pair < 0:

        pair = 0

    ans.append(pair)

for i in list(reversed(ans))[1:]:

    print(i)

import sys
import itertools

# import numpy as np
import time

sys.setrecursionlimit(10**7)
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

class UnionFind(object):
    def __init__(self, n=1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x
        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

# from union_find import *
# n, m = map(int, readline().split())
# u = UnionFind(n)
# a = [0 for _ in range(m)]
# b = [0 for _ in range(m)]
# for i in range(m):
#     a[i], b[i] = map(lambda x: int(x) - 1, readline().split())
# ans = [None for _ in range(m)]
# ans[-1] = n * (n - 1) // 2
# for i in range(m - 1, 0, -1):
#     x = a[i]
#     y = b[i]
#     if u.is_same(x, y):
#         ans[i - 1] = ans[i]
#     else:
#         ans[i - 1] = ans[i] - (u.get_size(x) * u.get_size(y))
#     u.unite(x, y)
# for a in ans:
#     print(a)
N, M = list(map(int, input().split()))
A, B = [None] * M, [None] * M
for i in range(M):
    A[i], B[i] = list(map(int, input().split()))
uf = UnionFind(N)
ans = [None] * M
ans[M - 1] = N * (N - 1) // 2
for i in range(M - 1, 0, -1):
    x, y = A[i] - 1, B[i] - 1
    if uf.is_same(x, y):
        ans[i - 1] = ans[i]
    else:
        ans[i - 1] = ans[i] - (uf.get_size(x) * uf.get_size(y))
    uf.unite(x, y)
for a in ans:
    print(a)

import sys
import itertools

# import numpy as np
import time
import math

sys.setrecursionlimit(10**7)
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, input().split()))

class UnionFind(object):
    def __init__(self, n=1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x
        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

es = [0] * M
for i in range(M):
    a, b = list(map(int, input().split()))
    es[i] = (a - 1, b - 1)
u = UnionFind(N)
ans = []
pair = N * (N - 1) // 2
ans.append(pair)
for i in range(M - 1, -1, -1):
    a, b = es[i]
    if u.is_same(a, b):
        ans.append(pair)
        continue
    pair -= u.get_size(a) * u.get_size(b)
    u.unite(a, b)
    if pair < 0:
        pair = 0
    ans.append(pair)
for i in list(reversed(ans))[1:]:
    print(i)

-#     a[i], b[i] = map(lambda x: int(x) - 1, readline().split())

-#         ans[i - 1] = ans[i] - (u.get_size(x) * u.get_size(y))

-    A[i], B[i] = list(map(int, input().split()))

-        ans[i - 1] = ans[i] - (uf.get_size(x) * uf.get_size(y))

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

+    pair -= u.get_size(a) * u.get_size(b)