Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

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

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

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

low = 200001

for i in range(m):

    f = xyc[i][0] - 1

    d = xyc[i][1] - 1

    if low >= dr[f]+wa[d]-xyc[i][2]:

        low = dr[f]+wa[d]-xyc[i][2]

dr.sort()

wa.sort()

if low >= (dr[0] + wa[0]):

    print((dr[0] + wa[0]))

else:

    print(low)

# optimized version of the same code:

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

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

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

low = min(al)+min(bl)

x = [0] * m

y = [0] * m

c = [0] * m

for i in range(m):

    x[i],y[i],c[i] = list(map(int, input().split()))

    x[i] -= 1

    y[i] -= 1

for i in range(m):

    low = min(low,al[x[i]]+bl[y[i]]-c[i])

print(low)

a, b, m = list(map(int, input().split()))
dr = list(map(int, input().split()))
wa = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(m)]
low = 200001
for i in range(m):
    f = xyc[i][0] - 1
    d = xyc[i][1] - 1
    if low >= dr[f] + wa[d] - xyc[i][2]:
        low = dr[f] + wa[d] - xyc[i][2]
dr.sort()
wa.sort()
if low >= (dr[0] + wa[0]):
    print((dr[0] + wa[0]))
else:
    print(low)

a, b, m = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
low = min(al) + min(bl)
x = [0] * m
y = [0] * m
c = [0] * m
for i in range(m):
    x[i], y[i], c[i] = list(map(int, input().split()))
    x[i] -= 1
    y[i] -= 1
for i in range(m):
    low = min(low, al[x[i]] + bl[y[i]] - c[i])
print(low)

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

-    if low >= dr[f] + wa[d] - xyc[i][2]:

-        low = dr[f] + wa[d] - xyc[i][2]

+    x[i], y[i], c[i] = list(map(int, input().split()))

+    low = min(low, al[x[i]] + bl[y[i]] - c[i])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

X=int(eval(input()))

a=[]

for i in range(-100,200):

  for j in range(-100,200):

    if i**5-j**5==X:

      a.append(str(i))

      a.append(str(j))

      break

print((' '.join(a[0:2])))

# optimized version of the same code:

X=int(eval(input()))

a=[]

for i in range(-100,200):

  for j in range(-100,200):

    if i**5-j**5==X:

      a.append(str(i))

      a.append(str(j))

      break

  else:

    continue

  break

print((' '.join(a[0:2])))

X = int(eval(input()))
a = []
for i in range(-100, 200):
    for j in range(-100, 200):
        if i**5 - j**5 == X:
            a.append(str(i))
            a.append(str(j))
            break
print((" ".join(a[0:2])))

X = int(eval(input()))
a = []
for i in range(-100, 200):
    for j in range(-100, 200):
        if i**5 - j**5 == X:
            a.append(str(i))
            a.append(str(j))
            break
    else:
        continue
    break
print((" ".join(a[0:2])))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

K, S = [int(i) for i in input().split()]

c = 0

for X in range(K + 1):

    for Y in range(K + 1):

        Z = S - X - Y

        if 0 <= Z <= K:

            c += 1

print(c)

# optimized version of the same code:

K, S = [int(i) for i in input().split()]

ans = 0

# X <= Y <= Zとしても一般性を失わない

for x in range(K + 1):

    for y in range(x, K + 1):

        z = S - x - y

        if z < y:

            break

        if z <= K:

            if x == y == z:

                ans += 1

            elif x == y or y == z or z == x:

                ans += 3

            else:

                ans += 6

print(ans)

+# X <= Y <= Zとしても一般性を失わない

+            elif x == y or y == z or z == x:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

menu = np.array([])

for i in range(N):

  a = np.array(input().split())

  menu = np.append(menu, a[1:])

menu = np.array(menu).astype(int).ravel()

count = 0

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

  if np.sum(menu == i) == N:

    count += 1

print(count)

# optimized version of the same code:

# coding: utf-8

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

ll = [0] * m

for i in range(n):

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

    for j in range(l[0]):

        ll[l[j+1] - 1] += 1

print((ll.count(max(ll)) if max(ll)==n else 0))

import numpy as np

N, M = list(map(int, input().split()))
menu = np.array([])
for i in range(N):
    a = np.array(input().split())
    menu = np.append(menu, a[1:])
menu = np.array(menu).astype(int).ravel()
count = 0
for i in range(1, M + 1):
    if np.sum(menu == i) == N:
        count += 1
print(count)

# coding: utf-8
n, m = list(map(int, input().split()))
ll = [0] * m
for i in range(n):
    l = list(map(int, input().split()))
    for j in range(l[0]):
        ll[l[j + 1] - 1] += 1
print((ll.count(max(ll)) if max(ll) == n else 0))

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

+print((ll.count(max(ll)) if max(ll) == n else 0))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

if r-l>672:

	p=0

else:

	p=2019

	for i in range(l, r):

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

			p=min(p, (((i%2019)*(j%2019))%2019))

			if not p:

				break

		if not p:

			break

print(p)

# optimized version of the same code:

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

if r-l>672:

	p=0

else:

	p=2019

	for i in range(l, r):

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

			p=min(p, (i*j%2019))

			if not p:

				break

		if not p:

			break

print(p)

l, r = list(map(int, input().split()))
if r - l > 672:
    p = 0
else:
    p = 2019
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            p = min(p, (((i % 2019) * (j % 2019)) % 2019))
            if not p:
                break
        if not p:
            break
print(p)

l, r = list(map(int, input().split()))
if r - l > 672:
    p = 0
else:
    p = 2019
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            p = min(p, (i * j % 2019))
            if not p:
                break
        if not p:
            break
print(p)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

price = 10**10

for k in range(10**5+1):

    re = 2*c*k + max(0,x-k)*a + max(0,y-k)*b

    price = min(re,price)

print(price)

# optimized version of the same code:

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

a1 = a*x + b*y

a2 = max(x,y) * 2*c

if y >= x:

    a3 = 2*c*x + (y-x)*b

else:

    a3 = 2*c*y + (x-y)*a

print((min(a1,a2,a3)))

a, b, c, x, y = list(map(int, input().split()))
price = 10**10
for k in range(10**5 + 1):
    re = 2 * c * k + max(0, x - k) * a + max(0, y - k) * b
    price = min(re, price)
print(price)

a, b, c, x, y = list(map(int, input().split()))
a1 = a * x + b * y
a2 = max(x, y) * 2 * c
if y >= x:
    a3 = 2 * c * x + (y - x) * b
else:
    a3 = 2 * c * y + (x - y) * a
print((min(a1, a2, a3)))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

N=int(eval(input()))

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

B=list(np.argsort(np.array(A)))

X=[[0,0],[0,0]]

for i in range(N):

    X[i%2][B[i]%2]+=1

print((X[0][1]))

# optimized version of the same code:

N=int(eval(input()))

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

AT=[(A[i],i) for i in range(N)]

AT.sort()

B=[AT[i][1] for i in range(N)]

X=[[0,0],[0,0]]

for i in range(N):

    X[i%2][B[i]%2]+=1

Y=[X[0][1],X[1][0]]

print((min(Y)))

import numpy as np

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = list(np.argsort(np.array(A)))
X = [[0, 0], [0, 0]]
for i in range(N):
    X[i % 2][B[i] % 2] += 1
print((X[0][1]))

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
AT = [(A[i], i) for i in range(N)]
AT.sort()
B = [AT[i][1] for i in range(N)]
X = [[0, 0], [0, 0]]
for i in range(N):
    X[i % 2][B[i] % 2] += 1
Y = [X[0][1], X[1][0]]
print((min(Y)))

-import numpy as np
-B = list(np.argsort(np.array(A)))
+AT = [(A[i], i) for i in range(N)]
+AT.sort()
+B = [AT[i][1] for i in range(N)]
-print((X[0][1]))
+Y = [X[0][1], X[1][0]]
+print((min(Y)))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import math

print((math.factorial(int(eval(input())))%(10**9+7)))

# optimized version of the same code:

ans=1

n=int(eval(input()))

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

    ans*=i

    ans=ans%(10**9+7)

print(ans)

import math

print((math.factorial(int(eval(input()))) % (10**9 + 7)))

ans = 1
n = int(eval(input()))
for i in range(1, n + 1):
    ans *= i
    ans = ans % (10**9 + 7)
print(ans)

-print((math.factorial(int(eval(input()))) % (10**9 + 7)))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

input = sys.stdin.readline

n = int(eval(input()))

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

cnt = 0

for b, a in ab:

    cnt += a

    if cnt > b:

        print('No')

        break

else:

    print('Yes')

# optimized version of the same code:

n = int(eval(input()))

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

ab = sorted(ab, key=lambda x: x[1])

t = 0

for a, b in ab:

    t += a

    if t > b:

        print('No')

        break

else:

    print('Yes')

import sys

input = sys.stdin.readline
n = int(eval(input()))
ab = sorted([list(map(int, input().split()))[::-1] for _ in range(n)])
cnt = 0
for b, a in ab:
    cnt += a
    if cnt > b:
        print("No")
        break
else:
    print("Yes")

n = int(eval(input()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[1])
t = 0
for a, b in ab:
    t += a
    if t > b:
        print("No")
        break
else:
    print("Yes")

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

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

S, T = input().split()

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

U = eval(input())

if S == U:

    print((A - 1, B))

else:

    print((A, B - 1))

# optimized version of the same code:

S, T = input().split()

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

U = eval(input())

if S == U:

    A-=1

else:

    B-=1

print((A,B))

S, T = input().split()
A, B = list(map(int, input().split()))
U = eval(input())
if S == U:
    print((A - 1, B))
else:
    print((A, B - 1))

S, T = input().split()
A, B = list(map(int, input().split()))
U = eval(input())
if S == U:
    A -= 1
else:
    B -= 1
print((A, B))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from collections import Counter

N = int(eval(input()))

div = []

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

    while i != 1:

        for d in range(2,i+1):

            while i%d==0:

                i = i//d

                div.append(d)

C = Counter(div).most_common()

Ans = 1

for k,v in C:

    Ans = Ans*(v+1) % (10**9+7)

print(Ans)

# optimized version of the same code:

from collections import defaultdict

N = int(eval(input()))

F = [True]*(N+1)

F[0]=F[1]=False

P = []

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

    if F[i]==True:

        P.append(i)

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

            F[j]=False

dic = defaultdict(int)

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

    for p in P:

        while i%p==0:

            dic[p] += 1

            i = i//p

        if i==1:

            break

ans = 1

modulo = 10**9+7

for v in list(dic.values()):

    ans *= (v+1)

    ans %= modulo

print(ans)

from collections import Counter

N = int(eval(input()))
div = []
for i in range(2, N + 1):
    while i != 1:
        for d in range(2, i + 1):
            while i % d == 0:
                i = i // d
                div.append(d)
C = Counter(div).most_common()
Ans = 1
for k, v in C:
    Ans = Ans * (v + 1) % (10**9 + 7)
print(Ans)

from collections import defaultdict

N = int(eval(input()))
F = [True] * (N + 1)
F[0] = F[1] = False
P = []
for i in range(2, N + 1):
    if F[i] == True:
        P.append(i)
        for j in range(i * 2, N + 1, i):
            F[j] = False
dic = defaultdict(int)
for i in range(2, N + 1):
    for p in P:
        while i % p == 0:
            dic[p] += 1
            i = i // p
        if i == 1:
            break
ans = 1
modulo = 10**9 + 7
for v in list(dic.values()):
    ans *= v + 1
    ans %= modulo
print(ans)

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from collections import deque

from copy import deepcopy, copy

dy = [-1, 0, 0, 1]

dx = [0, -1, 1, 0]

N = 3

def g(i, j, a):

    t = a // (10 ** j) % 10

    return a - t * (10 ** j) + t * (10 ** i)

def MAIN():

    m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}

    MAP = "".join(input().replace(" ", "") for _ in range(N))

    start = 8 - MAP.find("0")

    MAP = int(MAP)

    goal = ('1', '2', '3', '4', '5', '6', '7', '8', '0')

    goal = 123456780

    dp = deque([(0, start, MAP)])

    LOG = {MAP}

    while dp:

        cnt, yx, M = dp.popleft()

        if M == goal:

            print(cnt)

            break

        cnt += 1

        for nyx in m[yx]:

            CM = g(yx, nyx, M)

            if not CM in LOG:

                dp.append((cnt, nyx, CM))

                LOG.add(CM)

MAIN()

# optimized version of the same code:

from collections import deque

from copy import deepcopy, copy

N = 3

def g(i, j, a):

    if i > j:

        i, j = j, i

    return a[:i] + a[j] + a[i + 1:j] + a[i] + a[j + 1:]

def MAIN():

    m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}

    MAP = "".join(input().replace(" ", "") for _ in range(N))

    start = MAP.find("0")

    goal = "123456780"

    dp = deque([(0, start, MAP)])

    LOG = {MAP}

    while dp:

        cnt, yx, M = dp.popleft()

        if M == goal:

            print(cnt)

            break

        cnt += 1

        for nyx in m[yx]:

            CM = g(yx, nyx, M)

            if not CM in LOG:

                dp.append((cnt, nyx, CM))

                LOG.add(CM)

MAIN()

from collections import deque
from copy import deepcopy, copy

N = 3

def g(i, j, a):
    if i > j:
        i, j = j, i
    return a[:i] + a[j] + a[i + 1 : j] + a[i] + a[j + 1 :]

def MAIN():
    m = {
        8: {7, 5},
        7: {8, 6, 4},
        6: {7, 3},
        5: {8, 4, 2},
        4: {7, 5, 3, 1},
        3: {6, 4, 0},
        2: {5, 1},
        1: {4, 2, 0},
        0: {3, 1},
    }
    MAP = "".join(input().replace(" ", "") for _ in range(N))
    start = MAP.find("0")
    goal = "123456780"
    dp = deque([(0, start, MAP)])
    LOG = {MAP}
    while dp:
        cnt, yx, M = dp.popleft()
        if M == goal:
            print(cnt)
            break
        cnt += 1
        for nyx in m[yx]:
            CM = g(yx, nyx, M)
            if not CM in LOG:
                dp.append((cnt, nyx, CM))
                LOG.add(CM)

MAIN()


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

# vim: fileencoding=utf-8

def main():

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

    c = 0

    for i in range(a, b + 1):

        s = str(i)

        r = "".join(reversed(list(s)))

        if s == r:

            c += 1

    print(c)

if __name__ == "__main__":

    main()

# optimized version of the same code:

# vim: fileencoding=utf-8

def main():

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

    c = 0

    for i in range(a, b + 1):

        #     s = str(i)

        #     r = "".join(reversed(list(s)))

        #     if s == r:

        #         c += 1

        if (i % 10) == (i // 10000 % 10) and (i // 10 % 10) == (i // 1000 % 10):

            c += 1

    print(c)

if __name__ == "__main__":

    main()

+        #     r = "".join(reversed(list(s)))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

A, B, C, X, Y = list(map(int, input().split()))

ans = float('inf')

for i in range(10 ** 5 + 1):

    ans = min(ans, A * max(X - i, 0) + B * max(Y - i, 0) + 2 * C * i)

print(ans)

# optimized version of the same code:

A, B, C, X, Y = list(map(int, input().split()))

# ans = float('inf')

# for i in range(10 ** 5 + 1):

#     ans = min(ans, A * max(X - i, 0) + B * max(Y - i, 0) + 2 * C * i)

# print(ans)

min_xy = min(X, Y)

max_xy = max(X, Y)

ans1 = 2 * C * min_xy + A * (X - min_xy) + B * (Y - min_xy)

ans2 = A * X + B * Y

ans3 = 2 * C * max_xy

print((min(ans1, ans2, ans3)))

A, B, C, X, Y = list(map(int, input().split()))
ans = float("inf")
for i in range(10**5 + 1):
    ans = min(ans, A * max(X - i, 0) + B * max(Y - i, 0) + 2 * C * i)
print(ans)

-    ans = min(ans, A * max(X - i, 0) + B * max(Y - i, 0) + 2 * C * i)

+#     ans = min(ans, A * max(X - i, 0) + B * max(Y - i, 0) + 2 * C * i)

+ans1 = 2 * C * min_xy + A * (X - min_xy) + B * (Y - min_xy)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

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

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)

def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)

from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

from heapq import heapify, heappop, heappush

import math

import random

import string

from copy import deepcopy

from itertools import combinations, permutations, product

from operator import mul, itemgetter

from functools import reduce

from bisect import bisect_left, bisect_right

import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7

#############

# Main Code #

#############

S = getN()

# 逆元事前処理ver

# nが小さい場合に

lim = 10 ** 5 + 1

fact = [1, 1]

factinv = [1, 1]

inv = [0, 1]

for i in range(2, lim + 1):

    fact.append((fact[-1] * i) % mod)

    inv.append((-inv[mod % i] * (mod // i)) % mod)

    # 累計

    factinv.append((factinv[-1] * inv[-1]) % mod)

def cmb(n, r):

    if (r < 0) or (n < r):

        return 0

    r = min(r, n - r)

    return fact[n] * factinv[r] * factinv[n - r] % mod

ans = 0

# 長さNの時最低でも3 * N使う

# 残りは分配する

for i in range(1, 2001):

    s = S - (3 * i)

    if s < 0:

        break

    # sをN個に分配する通りがいくつあるか

    # 重複組み合わせ

    # 仕切りの数はi - 1個

    ans += cmb(s + i - 1, i - 1)

print((ans % mod))

# optimized version of the same code:

def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

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

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)

def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)

from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

from heapq import heapify, heappop, heappush

import math

import random

import string

from copy import deepcopy

from itertools import combinations, permutations, product

from operator import mul, itemgetter

from functools import reduce

from bisect import bisect_left, bisect_right

import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7

#############

# Main Code #

#############

N = getN()

logk = N.bit_length()

# 漸化式にできるなら行列計算に落とし込める

# A[n] = A[n - 1] + A[n - 3]なので

# [a2, a1, a0] = [0, 0, 1]

# [[1, 1, 0], [0, 0, 1], [1, 0, 0]]のN乗をすれば

# [an+2, an+1, an] が出る

dp = [[[0, 0, 0] for i in range(3)] for i in range(logk)]

dp[0] = [

[1, 1, 0],

[0, 0, 1],

[1, 0, 0]

]

# 行列掛け算 O(n3)かかる

def array_cnt(ar1, ar2):

    h = len(ar1)

    w = len(ar2[0])

    row = ar1

    col = []

    for j in range(w):

        opt = []

        for i in range(len(ar2)):

            opt.append(ar2[i][j])

        col.append(opt)

    res = [[[0, 0] for i in range(w)] for i in range(h)]

    for i in range(h):

        for j in range(w):

            cnt = 0

            for x, y in zip(row[i], col[j]):

                cnt += x * y

            res[i][j] = cnt

            res[i][j] %= mod

    return res

for i in range(1, logk):

    dp[i] = array_cnt(dp[i - 1], dp[i - 1])

ans = [[0, 0, 1]]

for i in range(logk):

    if N & (1 << i):

        ans = array_cnt(ans, dp[i])

print((ans[0][2] % mod))

def getN():
    return int(eval(input()))

def getNM():
    return list(map(int, input().split()))

def getList():
    return list(map(int, input().split()))

def getArray(intn):
    return [int(eval(input())) for i in range(intn)]

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

def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)

def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
S = getN()
# 逆元事前処理ver
# nが小さい場合に
lim = 10**5 + 1
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, lim + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    # 累計
    factinv.append((factinv[-1] * inv[-1]) % mod)

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

ans = 0
# 長さNの時最低でも3 * N使う
# 残りは分配する
for i in range(1, 2001):
    s = S - (3 * i)
    if s < 0:
        break
    # sをN個に分配する通りがいくつあるか
    # 重複組み合わせ
    # 仕切りの数はi - 1個
    ans += cmb(s + i - 1, i - 1)
print((ans % mod))

def getN():
    return int(eval(input()))

def getNM():
    return list(map(int, input().split()))

def getList():
    return list(map(int, input().split()))

def getArray(intn):
    return [int(eval(input())) for i in range(intn)]

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

def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)

def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N = getN()
logk = N.bit_length()
# 漸化式にできるなら行列計算に落とし込める
# A[n] = A[n - 1] + A[n - 3]なので
# [a2, a1, a0] = [0, 0, 1]
# [[1, 1, 0], [0, 0, 1], [1, 0, 0]]のN乗をすれば
# [an+2, an+1, an] が出る
dp = [[[0, 0, 0] for i in range(3)] for i in range(logk)]
dp[0] = [[1, 1, 0], [0, 0, 1], [1, 0, 0]]
# 行列掛け算 O(n3)かかる
def array_cnt(ar1, ar2):
    h = len(ar1)
    w = len(ar2[0])
    row = ar1
    col = []
    for j in range(w):
        opt = []
        for i in range(len(ar2)):
            opt.append(ar2[i][j])
        col.append(opt)
    res = [[[0, 0] for i in range(w)] for i in range(h)]
    for i in range(h):
        for j in range(w):
            cnt = 0
            for x, y in zip(row[i], col[j]):
                cnt += x * y
            res[i][j] = cnt
            res[i][j] %= mod
    return res

for i in range(1, logk):
    dp[i] = array_cnt(dp[i - 1], dp[i - 1])
ans = [[0, 0, 1]]
for i in range(logk):
    if N & (1 << i):
        ans = array_cnt(ans, dp[i])
print((ans[0][2] % mod))

-# 逆元事前処理ver

-    inv.append((-inv[mod % i] * (mod // i)) % mod)

-    factinv.append((factinv[-1] * inv[-1]) % mod)

+# 漸化式にできるなら行列計算に落とし込める

+dp = [[[0, 0, 0] for i in range(3)] for i in range(logk)]

+# 行列掛け算 O(n3)かかる

+    res = [[[0, 0] for i in range(w)] for i in range(h)]

+            for x, y in zip(row[i], col[j]):

-    return fact[n] * factinv[r] * factinv[n - r] % mod

-# 長さNの時最低でも3 * N使う

-    # sをN個に分配する通りがいくつあるか

-    # 重複組み合わせ

-    # 仕切りの数はi - 1個

+    dp[i] = array_cnt(dp[i - 1], dp[i - 1])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

l=[0 for i in range(k+1)]

for i in range(m):

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

  l[a-1]+=1;l[s]-=1

ans=0

f=0

for j in range(k):

  l[j]+=f

  f=l[j]

print((len([1 for i in l if i==m])))

# optimized version of the same code:

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

table=[0]*(n+2)

for i in range(m):

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

    table[l]+=1

    table[r+1]-=1

from itertools import accumulate

from collections import Counter as co

var=co((accumulate(table)))

if m not in var:print((0))

else:print((var[m]))

k, m = list(map(int, input().split()))
l = [0 for i in range(k + 1)]
for i in range(m):
    a, s = list(map(int, input().split()))
    l[a - 1] += 1
    l[s] -= 1
ans = 0
f = 0
for j in range(k):
    l[j] += f
    f = l[j]
print((len([1 for i in l if i == m])))

n, m = list(map(int, input().split()))
table = [0] * (n + 2)
for i in range(m):
    l, r = list(map(int, input().split()))
    table[l] += 1
    table[r + 1] -= 1
from itertools import accumulate
from collections import Counter as co

var = co((accumulate(table)))
if m not in var:
    print((0))
else:
    print((var[m]))

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

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

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

count = 0

for i in range(N):

    for j in range(N):

        if j == i:

            continue

        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)]))

        if dist.is_integer():

            count += 1

print((count // 2))

# optimized version of the same code:

import sys

sys.setrecursionlimit(10 ** 6)

def calc_dist(x, y):

    dist = 0

    for xi, yi in zip(x, y):

        dist += (yi - xi) ** 2

    return dist ** (1/2)

def main():

    N, D = list(map(int, sys.stdin.readline().rstrip().split()))

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

    ans = 0

    for i in range(N):

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

            dist = calc_dist(X[i], X[j])

            if dist.is_integer():

                ans += 1

    print(ans)

if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(10**6)

def calc_dist(x, y):
    dist = 0
    for xi, yi in zip(x, y):
        dist += (yi - xi) ** 2
    return dist ** (1 / 2)

def main():
    N, D = list(map(int, sys.stdin.readline().rstrip().split()))
    X = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            dist = calc_dist(X[i], X[j])
            if dist.is_integer():
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

-        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)]))

+    N, D = list(map(int, sys.stdin.readline().rstrip().split()))

+    X = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]

+            dist = calc_dist(X[i], X[j])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def abc133_c():

    L, R = list(map(int, input().split()))

    # 区間の幅が673あれば、673の倍数と3の倍数が含まれて、2019の倍数が作れる

    if R - L > 673: return 0

    # それ以外は試す

    ans = 2019

    for i in range(L, R+1):

        for j in range(L, i):

            m = i * j % 2019

            ans = min(m, ans)

    return ans

print((abc133_c()))

# optimized version of the same code:

def abc133_c():

    L, R = list(map(int, input().split()))

    # 区間の幅が673あれば、673の倍数と3の倍数が含まれて、2019の倍数が作れる

    if R - L > 673: return 0

    # それ以外は試す

    ans = 2019

    for i in range(L, R+1):

        for j in range(L, i):

            m = i * j % 2019

            ans = min(m, ans)

            if ans == 1: return 1

    return ans

print((abc133_c()))

def abc133_c():
    L, R = list(map(int, input().split()))
    # 区間の幅が673あれば、673の倍数と3の倍数が含まれて、2019の倍数が作れる
    if R - L > 673:
        return 0
    # それ以外は試す
    ans = 2019
    for i in range(L, R + 1):
        for j in range(L, i):
            m = i * j % 2019
            ans = min(m, ans)
    return ans

print((abc133_c()))

def abc133_c():
    L, R = list(map(int, input().split()))
    # 区間の幅が673あれば、673の倍数と3の倍数が含まれて、2019の倍数が作れる
    if R - L > 673:
        return 0
    # それ以外は試す
    ans = 2019
    for i in range(L, R + 1):
        for j in range(L, i):
            m = i * j % 2019
            ans = min(m, ans)
            if ans == 1:
                return 1
    return ans

print((abc133_c()))

+            if ans == 1:
+                return 1


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

count = [[0 for _ in range(9)] for _ in range(9)]

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

    if str(i)[0] != "0" and str(i)[-1] != "0":

        count[int(str(i)[0]) - 1][int(str(i)[-1]) - 1] += 1

ans = 0

for i in range(0, 9):

    for k in range(0, 9):

        ans += count[i][k] * count[k][i]

print(ans)

# optimized version of the same code:

N = int(eval(input()))

nums = [0 for i in range(100)]

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

    i = str(i)

    nums[int(i[0] + i[-1])] += 1

ans = 0

for i in range(1, 10):

    for j in range(i, 10):

        i = str(i)

        j = str(j)

        if i != j:

            ans += nums[int(i + j)] * nums[int(j + i)] * 2

        else:

            n = nums[int(i + j)]

            ans += n * (n - 1)

            ans += n

print(ans)

-count = [[0 for _ in range(9)] for _ in range(9)]

-        ans += count[i][k] * count[k][i]

+            ans += nums[int(i + j)] * nums[int(j + i)] * 2


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

input = sys.stdin.readline

def main():

    X = int(eval(input()))

    for A in range(-200, 201):

        for B in range(-200, 201):

            if A ** 5 - B ** 5 == X:

                print((A, B))

                exit()

if __name__ == "__main__":

    main()

# optimized version of the same code:

import sys

input = sys.stdin.readline

def main():

    X = int(eval(input()))

    for A in range(-119, 120 + 1):

        for B in range(-119, 120 + 1):

            if A ** 5 - B ** 5 == X:

                print((A, B))

                exit()

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline

def main():
    X = int(eval(input()))
    for A in range(-200, 201):
        for B in range(-200, 201):
            if A**5 - B**5 == X:
                print((A, B))
                exit()

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline

def main():
    X = int(eval(input()))
    for A in range(-119, 120 + 1):
        for B in range(-119, 120 + 1):
            if A**5 - B**5 == X:
                print((A, B))
                exit()

if __name__ == "__main__":
    main()


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

import sys

def input(): return sys.stdin.readline().strip()

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

MOD = 10 ** 9 + 7

X,Y,Z,K=MAP()

A=sorted(LIST(), reverse=True)

B=sorted(LIST(), reverse=True)

C=sorted(LIST(), reverse=True)

ABC=[]

for i in range(X):

    for j in range(Y):

        if (i+1)*(j+1)>K:

            break

        for k in range(Z):

            if (i+1)*(j+1)*(k+1)>K:

                break

            ABC.append(A[i]+B[j]+C[k])

ABC.sort(reverse=True)

for i in range(K):

    print((ABC[i]))

# optimized version of the same code:

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

import sys

from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

MOD = 10 ** 9 + 7

X,Y,Z,K=MAP()

A=sorted(LIST(), reverse=True)

B=sorted(LIST(), reverse=True)

C=sorted(LIST(), reverse=True)

que=[]

heappush(que, (-(A[0]+B[0]+C[0]), 0, 0, 0))

S={(0,0,0)}

for i in range(K):

    ans=heappop(que)

    print((-ans[0]))

    a,b,c=ans[1:]

    if a+1<X and (a+1,b,c) not in S:

        heappush(que, (-(A[a+1]+B[b]+C[c]), a+1, b, c))

        S.add((a+1,b,c))

    if b+1<Y and (a,b+1,c) not in S:

        heappush(que, (-(A[a]+B[b+1]+C[c]), a, b+1, c))

        S.add((a,b+1,c))

    if c+1<Z and (a,b,c+1) not in S:

        heappush(que, (-(A[a]+B[b]+C[c+1]), a, b, c+1))

        S.add((a,b,c+1))

# -*- coding: utf-8 -*-
import sys

def input():
    return sys.stdin.readline().strip()

def list2d(a, b, c):
    return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
    return int(-(-x // y))

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST():
    return list(map(int, input().split()))

def Yes():
    print("Yes")

def No():
    print("No")

def YES():
    print("YES")

def NO():
    print("NO")

sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
X, Y, Z, K = MAP()
A = sorted(LIST(), reverse=True)
B = sorted(LIST(), reverse=True)
C = sorted(LIST(), reverse=True)
ABC = []
for i in range(X):
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[k])
ABC.sort(reverse=True)
for i in range(K):
    print((ABC[i]))

# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop

def input():
    return sys.stdin.readline().strip()

def list2d(a, b, c):
    return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
    return int(-(-x // y))

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST():
    return list(map(int, input().split()))

def Yes():
    print("Yes")

def No():
    print("No")

def YES():
    print("YES")

def NO():
    print("NO")

sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
X, Y, Z, K = MAP()
A = sorted(LIST(), reverse=True)
B = sorted(LIST(), reverse=True)
C = sorted(LIST(), reverse=True)
que = []
heappush(que, (-(A[0] + B[0] + C[0]), 0, 0, 0))
S = {(0, 0, 0)}
for i in range(K):
    ans = heappop(que)
    print((-ans[0]))
    a, b, c = ans[1:]
    if a + 1 < X and (a + 1, b, c) not in S:
        heappush(que, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
        S.add((a + 1, b, c))
    if b + 1 < Y and (a, b + 1, c) not in S:
        heappush(que, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
        S.add((a, b + 1, c))
    if c + 1 < Z and (a, b, c + 1) not in S:
        heappush(que, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
        S.add((a, b, c + 1))

-            ABC.append(A[i] + B[j] + C[k])

+    if a + 1 < X and (a + 1, b, c) not in S:

+    if b + 1 < Y and (a, b + 1, c) not in S:

+    if c + 1 < Z and (a, b, c + 1) not in S:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**6)

INF = 10 ** 9 + 1  # sys.maxsize # float("inf")

MOD = 10 ** 9 + 7

def floor_sum(n, m, a, b):

    ret = 0

    if a >= m:

        ret += (n - 1) * n * (a // m) // 2

        a %= m

    if b >= m:

        ret += n * (b // m)

        b %= m

    y_max = (a * n + b) // m

    x_max = y_max * m - b

    if y_max == 0:

        return ret

    ret += (n - (x_max + a - 1) // a) * y_max

    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)

    return ret

def debug(*x):

    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):

    pass

def main():

    # parse input

    T = int(input())

    for _t in range(T):

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

        print(floor_sum(N, M, A, B))

# tests

T1 = """

5

4 10 6 3

6 5 4 3

1 1 0 0

31415 92653 58979 32384

1000000000 1000000000 999999999 999999999

"""

TEST_T1 = """

>>> as_input(T1)

>>> main()

3

13

0

314095480

499999999500000000

"""

def _test():

    import doctest

    doctest.testmod()

    g = globals()

    for k in sorted(g):

        if k.startswith("TEST_"):

            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):

    "use in test, use given string as input file"

    import io

    f = io.StringIO(s.strip())

    g = globals()

    g["input"] = lambda: bytes(f.readline(), "ascii")

    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline

read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":

    print("testing")

    _test()

    sys.exit()

main()

# optimized version of the same code:

#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**6)

INF = 10 ** 9 + 1  # sys.maxsize # float("inf")

MOD = 10 ** 9 + 7

def floor_sum_1(n, m, a, b):

    ret = 0

    if a >= m:

        ret += (n - 1) * n * (a // m) // 2

        a %= m

    if b >= m:

        ret += n * (b // m)

        b %= m

    y_max = (a * n + b) // m

    x_max = y_max * m - b

    if y_max == 0:

        return ret

    ret += (n - (x_max + a - 1) // a) * y_max

    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)

    return ret

def floor_sum(n, m, a, b):

    ret = 0

    while True:

        if a >= m:

            ret += (n - 1) * n * (a // m) // 2

            a %= m

        if b >= m:

            ret += n * (b // m)

            b %= m

        y_max = (a * n + b) // m

        x_max = y_max * m - b

        if y_max == 0:

            return ret

        ret += (n - (x_max + a - 1) // a) * y_max

        n = y_max

        m, a, b = a, m, (a - x_max % a) % a

def debug(*x):

    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):

    pass

def main():

    # parse input

    T = int(input())

    for _t in range(T):

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

        print(floor_sum(N, M, A, B))

# tests

T1 = """

5

4 10 6 3

6 5 4 3

1 1 0 0

31415 92653 58979 32384

1000000000 1000000000 999999999 999999999

"""

TEST_T1 = """

>>> as_input(T1)

>>> main()

3

13

0

314095480

499999999500000000

"""

def _test():

    import doctest

    doctest.testmod()

    g = globals()

    for k in sorted(g):

        if k.startswith("TEST_"):

            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):

    "use in test, use given string as input file"

    import io

    f = io.StringIO(s.strip())

    g = globals()

    g["input"] = lambda: bytes(f.readline(), "ascii")

    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline

read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":

    print("testing")

    _test()

    sys.exit()

main()

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10**6)
INF = 10**9 + 1  # sys.maxsize # float("inf")
MOD = 10**9 + 7

def floor_sum(n, m, a, b):
    ret = 0
    if a >= m:
        ret += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ret += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return ret
    ret += (n - (x_max + a - 1) // a) * y_max
    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ret

def debug(*x):
    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):
    pass

def main():
    # parse input
    T = int(input())
    for _t in range(T):
        N, M, A, B = map(int, input().split())
        print(floor_sum(N, M, A, B))

# tests
T1 = """
5
4 10 6 3
6 5 4 3
1 1 0 0
31415 92653 58979 32384
1000000000 1000000000 999999999 999999999
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
3
13
0
314095480
499999999500000000
"""

def _test():
    import doctest

    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):
    "use in test, use given string as input file"
    import io

    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()
main()

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10**6)
INF = 10**9 + 1  # sys.maxsize # float("inf")
MOD = 10**9 + 7

def floor_sum_1(n, m, a, b):
    ret = 0
    if a >= m:
        ret += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ret += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return ret
    ret += (n - (x_max + a - 1) // a) * y_max
    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ret

def floor_sum(n, m, a, b):
    ret = 0
    while True:
        if a >= m:
            ret += (n - 1) * n * (a // m) // 2
            a %= m
        if b >= m:
            ret += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        x_max = y_max * m - b
        if y_max == 0:
            return ret
        ret += (n - (x_max + a - 1) // a) * y_max
        n = y_max
        m, a, b = a, m, (a - x_max % a) % a

def debug(*x):
    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):
    pass

def main():
    # parse input
    T = int(input())
    for _t in range(T):
        N, M, A, B = map(int, input().split())
        print(floor_sum(N, M, A, B))

# tests
T1 = """
5
4 10 6 3
6 5 4 3
1 1 0 0
31415 92653 58979 32384
1000000000 1000000000 999999999 999999999
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
3
13
0
314095480
499999999500000000
"""

def _test():
    import doctest

    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):
    "use in test, use given string as input file"
    import io

    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()
main()

+        m, a, b = a, m, (a - x_max % a) % a


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

n = int(eval(input()))

value = np.array(tuple(map(int, input().split())))

cost = np.array(tuple(map(int, input().split())))

xy = value - cost

ans = 0

for i in range(n):

    if xy[i] < 0:

        continue

    else:

        ans += xy[i]

print(ans)

# optimized version of the same code:

n = int(eval(input()))

value = tuple(map(int, input().split()))

cost = tuple(map(int, input().split()))

# iこめまでのxーyの最大値

inf = -100

dp = [inf] * (n+1)

dp[1] = max(0, value[0]-cost[0])

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

    dp[i] = max(dp[i-1], dp[i-1]+value[i-1]-cost[i-1])

print((dp[n]))

n = int(eval(input()))
value = tuple(map(int, input().split()))
cost = tuple(map(int, input().split()))
# iこめまでのxーyの最大値
inf = -100
dp = [inf] * (n + 1)
dp[1] = max(0, value[0] - cost[0])
for i in range(2, n + 1):
    dp[i] = max(dp[i - 1], dp[i - 1] + value[i - 1] - cost[i - 1])
print((dp[n]))

-value = np.array(tuple(map(int, input().split())))

-cost = np.array(tuple(map(int, input().split())))

+value = tuple(map(int, input().split()))

+cost = tuple(map(int, input().split()))

+# iこめまでのxーyの最大値


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import math

N = int(eval(input()))

ans = 10**12

for i in range(1,10**6+1):

  j = math.ceil(N/(i+1))

  if (1+i)*j == N:

    ans = min(i+j-1,ans)

  if i == 10**6 and ans == 10**12:

    ans = N-1

    break

print(ans)

# optimized version of the same code:

N = int(eval(input()))

ans = 10**12

for i in range(1,10**6+1):

  j = N//i

  if i*j == N:

    ans = min(i+j-2,ans)

  if i == 10**6 and ans == 10**12:

    ans = N-1

    break

print(ans)

import math

N = int(eval(input()))
ans = 10**12
for i in range(1, 10**6 + 1):
    j = math.ceil(N / (i + 1))
    if (1 + i) * j == N:
        ans = min(i + j - 1, ans)
    if i == 10**6 and ans == 10**12:
        ans = N - 1
        break
print(ans)

N = int(eval(input()))
ans = 10**12
for i in range(1, 10**6 + 1):
    j = N // i
    if i * j == N:
        ans = min(i + j - 2, ans)
    if i == 10**6 and ans == 10**12:
        ans = N - 1
        break
print(ans)

-import math
-    j = math.ceil(N / (i + 1))
-    if (1 + i) * j == N:
-        ans = min(i + j - 1, ans)
+    j = N // i
+    if i * j == N:
+        ans = min(i + j - 2, ans)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

N = int(eval(input()))

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

value=np.sort(value)[::-1]

#print(N,value)

a = np.sum(value[::2])

b = np.sum(value[1::2])

print((a-b))

# optimized version of the same code:

n = int(eval(input()))

a = sorted(list(map(int, input().split())), reverse=True)

print((sum(a[::2]) - sum(a[1::2])))

import numpy as np

N = int(eval(input()))
value = list(map(int, input().split()))
value = np.sort(value)[::-1]
# print(N,value)
a = np.sum(value[::2])
b = np.sum(value[1::2])
print((a - b))

-value = list(map(int, input().split()))

+a = sorted(list(map(int, input().split())), reverse=True)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

mod = 998244353

N = int(eval(input()))

X = []

for _ in range(N):

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

    X.append((x, x + d))

X = sorted(X, key = lambda x: x[0])

L = [(0, -(10**9+1), 10**9+1)]

P = [-1] * (N+1)

for i, (x, y) in enumerate(X):

    while L[-1][2] <= y:

        if L[-1][2] > x and P[i+1] < 0:

            P[i+1] = L[-1][0]

        L.pop()

    if P[i+1] < 0:

        P[i+1] = L[-1][0]

    L.append((i+1, x, y))

C = [[] for _ in range(N+1)]

for i, p in enumerate(P):

    if p >= 0:

        C[p].append(i)

Y = [1] * (N+1)

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

    s = 1

    for j in C[i]:

        s = s * (Y[j] + 1) % mod

    Y[i] = s

print((Y[0]))

# optimized version of the same code:

import sys

input = sys.stdin.readline

mod = 998244353

N = int(eval(input()))

X = []

for _ in range(N):

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

    X.append((x, x + d))

X = sorted(X, key = lambda x: x[0])

L = [(0, -(10**9+1), 10**9+1)]

P = [-1] * (N+1)

for i, (x, y) in enumerate(X):

    while L[-1][2] <= y:

        if L[-1][2] > x and P[i+1] < 0:

            P[i+1] = L[-1][0]

        L.pop()

    if P[i+1] < 0:

        P[i+1] = L[-1][0]

    L.append((i+1, x, y))

C = [[] for _ in range(N+1)]

for i, p in enumerate(P):

    if p >= 0:

        C[p].append(i)

Y = [1] * (N+1)

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

    s = 1

    for j in C[i]:

        s = s * (Y[j] + 1) % mod

    Y[i] = s

print((Y[0]))

import sys

input = sys.stdin.readline
mod = 998244353
N = int(eval(input()))
X = []
for _ in range(N):
    x, d = list(map(int, input().split()))
    X.append((x, x + d))
X = sorted(X, key=lambda x: x[0])
L = [(0, -(10**9 + 1), 10**9 + 1)]
P = [-1] * (N + 1)
for i, (x, y) in enumerate(X):
    while L[-1][2] <= y:
        if L[-1][2] > x and P[i + 1] < 0:
            P[i + 1] = L[-1][0]
        L.pop()
    if P[i + 1] < 0:
        P[i + 1] = L[-1][0]
    L.append((i + 1, x, y))
C = [[] for _ in range(N + 1)]
for i, p in enumerate(P):
    if p >= 0:
        C[p].append(i)
Y = [1] * (N + 1)
for i in range(N + 1)[::-1]:
    s = 1
    for j in C[i]:
        s = s * (Y[j] + 1) % mod
    Y[i] = s
print((Y[0]))

+import sys
+
+input = sys.stdin.readline


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

print((sum(si != ti for si, ti in zip(eval(input()), eval(input())))))

# optimized version of the same code:

print((sum(a!=b for a,b in zip(*open(0)))))

-print((sum(si != ti for si, ti in zip(eval(input()), eval(input())))))

+print((sum(a != b for a, b in zip(*open(0)))))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

l=[a+i-1 for i in range(1,n+1)]

import numpy as np

b=min(np.abs(l))

if b==0:

  l.remove(0)

elif b in l:

  l.remove(b)

elif -b in l:

  l.remove(-b)

print((sum(l)))

# optimized version of the same code:

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

apples=[a+i for i in range(n)]

eat=min(apples,key=lambda x:abs(x))

res=sum(apples)-eat

print(res)

n, a = list(map(int, input().split()))
l = [a + i - 1 for i in range(1, n + 1)]
import numpy as np

b = min(np.abs(l))
if b == 0:
    l.remove(0)
elif b in l:
    l.remove(b)
elif -b in l:
    l.remove(-b)
print((sum(l)))

n, a = list(map(int, input().split()))
apples = [a + i for i in range(n)]
eat = min(apples, key=lambda x: abs(x))
res = sum(apples) - eat
print(res)

-l = [a + i - 1 for i in range(1, n + 1)]

+eat = min(apples, key=lambda x: abs(x))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n = int(eval(input()))

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

p = 10000000

for i in range(100):

    pi = 0

    for j in range(n):

        pi += (x[j] - (i + 1))**2

    if pi < p:

        p = pi

    # else:

    #     break

        # p[i] += (x[j]-(i+1))**2

print(p)

# optimized version of the same code:

n = int(eval(input()))

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

p = 10000000

for i in range(100):

    pi = 0

    for j in range(n):

        pi += (x[j] - (i + 1))**2

    if pi < p:

        p = pi

    else:

        break

        # p[i] += (x[j]-(i+1))**2

print(p)

n = int(eval(input()))
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1)) ** 2
    if pi < p:
        p = pi
    # else:
    #     break
    # p[i] += (x[j]-(i+1))**2
print(p)

n = int(eval(input()))
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1)) ** 2
    if pi < p:
        p = pi
    else:
        break
        # p[i] += (x[j]-(i+1))**2
print(p)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from scipy.sparse.csgraph import floyd_warshall

import numpy as np

import sys

input = sys.stdin.readline

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

AB = []

edge = np.zeros((N, N), dtype=int)

for _ in range(M):

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

    a -= 1

    b -= 1

    AB.append((a, b))

    edge[a][b] = 1

    edge[b][a] = 1

ans = 0

for i in range(M):

    graph = np.copy(edge)

    a, b = AB[i]

    graph[a][b] = 0

    graph[b][a] = 0

    fw = floyd_warshall(graph)

    if fw.max() > 10000:

        ans += 1

print(ans)

# optimized version of the same code:

import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

class UF_tree:

    def __init__(self, n):

        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数

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

    def find(self, x):  # xの根となる要素番号を返す

        if self.root[x] < 0:

            return x

        else:

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

            return self.root[x]

    def isSame(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

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

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

            self.root[x] = y

        else:

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

            self.root[y] = x

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

                self.rank[x] += 1

    def getNodeLen(self, x):

        return -self.root[self.find(x)]

if __name__ == "__main__":

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

    AB = tuple(tuple(map(int, input().split())) for _ in range(M))

    ans = 0

    for i in range(M):

        uf = UF_tree(N)

        for j, (a, b) in enumerate(AB):

            if i == j:

                continue

            uf.unite(a, b)

        a, b = AB[i]

        if not uf.isSame(a, b):

            ans += 1

    print(ans)

import sys

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

class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数
        self.rank = [0] * (n + 1)

    def find(self, x):  # xの根となる要素番号を返す
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def isSame(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
        elif self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def getNodeLen(self, x):
        return -self.root[self.find(x)]

if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    AB = tuple(tuple(map(int, input().split())) for _ in range(M))
    ans = 0
    for i in range(M):
        uf = UF_tree(N)
        for j, (a, b) in enumerate(AB):
            if i == j:
                continue
            uf.unite(a, b)
        a, b = AB[i]
        if not uf.isSame(a, b):
            ans += 1
    print(ans)

-from scipy.sparse.csgraph import floyd_warshall

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

+        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数

+    def find(self, x):  # xの根となる要素番号を返す

+            self.root[x] = self.find(self.root[x])

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

+        elif self.rank[x] < self.rank[y]:

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

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

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

+        return -self.root[self.find(x)]

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

+    AB = tuple(tuple(map(int, input().split())) for _ in range(M))

+        for j, (a, b) in enumerate(AB):


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N=int(eval(input()))

a = []

for i in range(N):

    a.append(int(eval(input())))

# a=[0]*N

# for i in range(N):

#   a[i]=int(input())

count=0

#loopの定義→同じインデックスを使用したらloop判定

#in の処理を爆速で実行するためにsetを使用する

#loop=[]

loop=set()

tmp=1

while True:

  tmp=a[tmp-1]

  count+=1

  if tmp==2:

    print(count)

    exit()

  if tmp-1 in loop:

    print((-1))

    exit()

  #loop.append(tmp-1)

  loop.add(tmp-1)

# optimized version of the same code:

N=int(eval(input()))

#複数行の入力を高速化

#a=[0]*N

#for i in range(N):

#  a[i]=int(input())

import sys

a=[int(i) for i in sys.stdin]

count=0

#loopの定義→同じインデックスを使用したらloop判定

#in の処理を爆速で実行するためにsetを使用する

#loop=[]

loop=set()

tmp=1

while True:

  tmp=a[tmp-1]

  count+=1

  if tmp==2:

    print(count)

    exit()

  if tmp-1 in loop:

    print((-1))

    exit()

  #loop.append(tmp-1)

  loop.add(tmp-1)

N = int(eval(input()))
a = []
for i in range(N):
    a.append(int(eval(input())))
# a=[0]*N
# for i in range(N):
#   a[i]=int(input())
count = 0
# loopの定義→同じインデックスを使用したらloop判定
# in の処理を爆速で実行するためにsetを使用する
# loop=[]
loop = set()
tmp = 1
while True:
    tmp = a[tmp - 1]
    count += 1
    if tmp == 2:
        print(count)
        exit()
    if tmp - 1 in loop:
        print((-1))
        exit()
    # loop.append(tmp-1)
    loop.add(tmp - 1)

N = int(eval(input()))
# 複数行の入力を高速化
# a=[0]*N
# for i in range(N):
#  a[i]=int(input())
import sys

a = [int(i) for i in sys.stdin]
count = 0
# loopの定義→同じインデックスを使用したらloop判定
# in の処理を爆速で実行するためにsetを使用する
# loop=[]
loop = set()
tmp = 1
while True:
    tmp = a[tmp - 1]
    count += 1
    if tmp == 2:
        print(count)
        exit()
    if tmp - 1 in loop:
        print((-1))
        exit()
    # loop.append(tmp-1)
    loop.add(tmp - 1)

-a = []
-for i in range(N):
-    a.append(int(eval(input())))
+# 複数行の入力を高速化
-#   a[i]=int(input())
+#  a[i]=int(input())
+import sys
+
+a = [int(i) for i in sys.stdin]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

n = int(eval(input()))

balls = np.array(list(map(int, input().split())))

time = 0

while np.all(balls % 2 == 0) and np.all(balls > 0):

    time += 1

    balls = balls / 2

print(time)

# optimized version of the same code:

import math

n = eval(input())

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

ans = float("inf")

for i in a:

    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)

print((round(ans)))

-balls = np.array(list(map(int, input().split())))

-while np.all(balls % 2 == 0) and np.all(balls > 0):

+    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

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

# construct map

import numpy as np

dists = np.ones((n + 1, n + 1)) * float('inf')

for _ in range(m):

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

    dists[a, b] = dists[b, a] = c

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

    dists[i, i] = 0

from itertools import product, permutations

for i, j in product(list(range(1, 1 + n)), repeat=2):

    dists[j] = np.minimum(dists[j], dists[i] + dists[j, i])

ans = float('inf')

for path in permutations(rs):

    val = sum(dists[i, j] for i, j in zip(path, path[1:]))

    val = int(val)

    if val < ans:

        ans = val

print(ans)

# optimized version of the same code:

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

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

# construct map

import numpy as np

dists = np.ones((n + 1, n + 1)) * float('inf')

for _ in range(m):

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

    dists[a, b] = dists[b, a] = c

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

    dists[i, i] = 0

from itertools import permutations

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

    dists = np.minimum(dists, dists[i: i + 1] + dists[:, i: i + 1])

ans = float('inf')

for path in permutations(rs):

    val = sum(dists[i, j] for i, j in zip(path, path[1:]))

    val = int(val)

    if val < ans:

        ans = val

print(ans)

n, m, r = list(map(int, input().split()))
rs = list(map(int, input().split()))
# construct map
import numpy as np

dists = np.ones((n + 1, n + 1)) * float("inf")
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    dists[a, b] = dists[b, a] = c
for i in range(1, n + 1):
    dists[i, i] = 0
from itertools import product, permutations

for i, j in product(list(range(1, 1 + n)), repeat=2):
    dists[j] = np.minimum(dists[j], dists[i] + dists[j, i])
ans = float("inf")
for path in permutations(rs):
    val = sum(dists[i, j] for i, j in zip(path, path[1:]))
    val = int(val)
    if val < ans:
        ans = val
print(ans)

n, m, r = list(map(int, input().split()))
rs = list(map(int, input().split()))
# construct map
import numpy as np

dists = np.ones((n + 1, n + 1)) * float("inf")
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    dists[a, b] = dists[b, a] = c
for i in range(1, n + 1):
    dists[i, i] = 0
from itertools import permutations

for i in range(1, 1 + n):
    dists = np.minimum(dists, dists[i : i + 1] + dists[:, i : i + 1])
ans = float("inf")
for path in permutations(rs):
    val = sum(dists[i, j] for i, j in zip(path, path[1:]))
    val = int(val)
    if val < ans:
        ans = val
print(ans)

-from itertools import product, permutations

-for i, j in product(list(range(1, 1 + n)), repeat=2):

-    dists[j] = np.minimum(dists[j], dists[i] + dists[j, i])

+    dists = np.minimum(dists, dists[i : i + 1] + dists[:, i : i + 1])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def solve():

    N = int(eval(input()))

    numss = [[0]*(10) for _ in range(10)]

    for x in range(1, 10):

        for y in range(1, 10):

            num = 0

            for d in range(1, 5):

                for i in range(10**d):

                    j = x*10**(d+1) + i*10 + y

                    if 1 <= j <= N:

                        num += 1

                    else:

                        break

            j = x*10 + y

            if 1 <= j <= N:

                num += 1

            if x == y:

                j = x

                if 1 <= j <= N:

                    num += 1

            numss[x][y] = num

    ans = 0

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

        ss = str(A)

        ans += numss[int(ss[-1])][int(ss[0])]

    print(ans)

solve()

# optimized version of the same code:

def solve():

    strN = eval(input())

    N = int(strN)

    maxD = len(strN)

    numss = [[0]*(10) for _ in range(10)]

    for x in range(1, 10):

        for y in range(1, 10):

            num = 0

            for d in range(1, maxD-2):

                num += 10**d

            if maxD-2 > 0:

                if x < int(strN[0]):

                    num += 10**(maxD-2)

                elif x == int(strN[0]):

                    num += int(strN[1:-1]) + 1

                    if y > int(strN[-1]):

                        num -= 1

            j = x*10 + y

            if 1 <= j <= N:

                num += 1

            if x == y:

                j = x

                if 1 <= j <= N:

                    num += 1

            numss[x][y] = num

    ans = 0

    for i in range(1, 10):

        for j in range(1, 10):

            ans += numss[i][j]*numss[j][i]

    print(ans)

solve()

def solve():
    N = int(eval(input()))
    numss = [[0] * (10) for _ in range(10)]
    for x in range(1, 10):
        for y in range(1, 10):
            num = 0
            for d in range(1, 5):
                for i in range(10**d):
                    j = x * 10 ** (d + 1) + i * 10 + y
                    if 1 <= j <= N:
                        num += 1
                    else:
                        break
            j = x * 10 + y
            if 1 <= j <= N:
                num += 1
            if x == y:
                j = x
                if 1 <= j <= N:
                    num += 1
            numss[x][y] = num
    ans = 0
    for A in range(1, N + 1):
        ss = str(A)
        ans += numss[int(ss[-1])][int(ss[0])]
    print(ans)

solve()

def solve():
    strN = eval(input())
    N = int(strN)
    maxD = len(strN)
    numss = [[0] * (10) for _ in range(10)]
    for x in range(1, 10):
        for y in range(1, 10):
            num = 0
            for d in range(1, maxD - 2):
                num += 10**d
            if maxD - 2 > 0:
                if x < int(strN[0]):
                    num += 10 ** (maxD - 2)
                elif x == int(strN[0]):
                    num += int(strN[1:-1]) + 1
                    if y > int(strN[-1]):
                        num -= 1
            j = x * 10 + y
            if 1 <= j <= N:
                num += 1
            if x == y:
                j = x
                if 1 <= j <= N:
                    num += 1
            numss[x][y] = num
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += numss[i][j] * numss[j][i]
    print(ans)

solve()

+            for d in range(1, maxD - 2):

+                elif x == int(strN[0]):

+                    if y > int(strN[-1]):

-        ans += numss[int(ss[-1])][int(ss[0])]

+            ans += numss[i][j] * numss[j][i]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

from collections import deque

def inpl(): return list(map(int, input().split()))

S = eval(input())

A = set("ATCG")

ans = 0

mode = 0

for i, s in enumerate(S):

    if s in A:

        if mode == 0:

            mode = 1

            start = i

    else:

        if mode == 1:

            ans = max(i - start, ans)

            mode = 0

if mode == 1:

    ans = max(len(S) - start, ans)

print(ans)

# optimized version of the same code:

def inpl(): return list(map(int, input().split()))

S = eval(input())

C = set("ACGT")

tmp = 0

ans = 0

for s in S:

    if s in C:

        tmp += 1

    else:

        ans = max(ans, tmp)

        tmp = 0

ans = max(ans, tmp)

print(ans)

-# -*- coding: utf-8 -*-
-from collections import deque
-A = set("ATCG")
+C = set("ACGT")
+tmp = 0
-mode = 0
-for i, s in enumerate(S):
-    if s in A:
-        if mode == 0:
-            mode = 1
-            start = i
+for s in S:
+    if s in C:
+        tmp += 1
-        if mode == 1:
-            ans = max(i - start, ans)
-            mode = 0
-if mode == 1:
-    ans = max(len(S) - start, ans)
+        ans = max(ans, tmp)
+        tmp = 0
+ans = max(ans, tmp)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

import numba

from numba import njit, b1, i4, i8, f8

@njit((i8, i8[:]), cache=True)

def main(N,A):

  Amax = np.max(A)

  lis = np.zeros(Amax+1, np.int64)

  for i in range(N):

    lis[A[i]] += 1

  setwise = False

  for t in range(2,Amax+1):

    cnt = np.sum(lis[t:Amax+1:t])

    if cnt==N:

      return 'not'

    if 2<=cnt<N:

      setwise=True

  if setwise==True:

    return 'setwise'

  return 'pairwise'

N = int(eval(input()))

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

print((main(N,A)+' coprime'))

# optimized version of the same code:

def sieve(n):

  is_prime = [True for _ in range(n+1)]

  is_prime[0] = False

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

    if is_prime[i-1]:

      j = 2 * i

      while j <= n:

        is_prime[j-1] = False

        j += i

  table = [i for i in range(1, n+1) if is_prime[i-1]]

  return table

N = int(eval(input()))

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

Amax = max(A)

lis = [0]*(Amax+1)

for i in range(N):

  lis[A[i]] += 1

table = sieve(Amax)

setwise = False

for t in table:

  cnt = sum(lis[t:Amax+1:t])

  if cnt==N:

    print('not coprime')

    break

  if 2<=cnt<N:

    setwise=True

else:

  if setwise==True:

    print('setwise coprime')

  else:

    print('pairwise coprime')

import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8, i8[:]), cache=True)
def main(N, A):
    Amax = np.max(A)
    lis = np.zeros(Amax + 1, np.int64)
    for i in range(N):
        lis[A[i]] += 1
    setwise = False
    for t in range(2, Amax + 1):
        cnt = np.sum(lis[t : Amax + 1 : t])
        if cnt == N:
            return "not"
        if 2 <= cnt < N:
            setwise = True
    if setwise == True:
        return "setwise"
    return "pairwise"

N = int(eval(input()))
A = np.array(list(map(int, input().split())))
print((main(N, A) + " coprime"))

def sieve(n):
    is_prime = [True for _ in range(n + 1)]
    is_prime[0] = False
    for i in range(2, n + 1):
        if is_prime[i - 1]:
            j = 2 * i
            while j <= n:
                is_prime[j - 1] = False
                j += i
    table = [i for i in range(1, n + 1) if is_prime[i - 1]]
    return table

N = int(eval(input()))
A = list(map(int, input().split()))
Amax = max(A)
lis = [0] * (Amax + 1)
for i in range(N):
    lis[A[i]] += 1
table = sieve(Amax)
setwise = False
for t in table:
    cnt = sum(lis[t : Amax + 1 : t])
    if cnt == N:
        print("not coprime")
        break
    if 2 <= cnt < N:
        setwise = True
else:
    if setwise == True:
        print("setwise coprime")
    else:
        print("pairwise coprime")

-        cnt = np.sum(lis[t : Amax + 1 : t])

+    is_prime = [True for _ in range(n + 1)]

+                is_prime[j - 1] = False

+    table = [i for i in range(1, n + 1) if is_prime[i - 1]]

-A = np.array(list(map(int, input().split())))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

ans = 0

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

    if len(str(i)) % 2 == 1:

        ans += 1

print(ans)

# optimized version of the same code:

N = int(eval(input()))

print((len(list([x for x in range(1, N + 1) if len(str(x)) % 2 == 1]))))

+print((len(list([x for x in range(1, N + 1) if len(str(x)) % 2 == 1]))))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

S = eval(input())

k = int(eval(input()))

A = set()

for l in range(k+1):

	for i in range(len(S)-l):

			A.add(S[i:i+l+1])

A = sorted(list(A))

print((A[k-1]))

# optimized version of the same code:

S = eval(input())

l = len(S)

d = set()

K = int(eval(input()))

for i in range(5):

    for j in range(l-i):

        d.add(S[j:j+i+1])

D = sorted(list(d))

print((D[K-1]))

S = eval(input())
k = int(eval(input()))
A = set()
for l in range(k + 1):
    for i in range(len(S) - l):
        A.add(S[i : i + l + 1])
A = sorted(list(A))
print((A[k - 1]))

S = eval(input())
l = len(S)
d = set()
K = int(eval(input()))
for i in range(5):
    for j in range(l - i):
        d.add(S[j : j + i + 1])
D = sorted(list(d))
print((D[K - 1]))

-k = int(eval(input()))
-A = set()
-for l in range(k + 1):
-    for i in range(len(S) - l):
-        A.add(S[i : i + l + 1])
-A = sorted(list(A))
-print((A[k - 1]))
+l = len(S)
+d = set()
+K = int(eval(input()))
+for i in range(5):
+    for j in range(l - i):
+        d.add(S[j : j + i + 1])
+D = sorted(list(d))
+print((D[K - 1]))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

input = sys.stdin.readline

from collections import *

K = int(eval(input()))

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

for i in range(A, B+1):

    if i%K==0:

        print('OK')

        exit()

print('NG')

# optimized version of the same code:

K = int(eval(input()))

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

if (A-1)//K!=B//K:

    print('OK')

else:

    print('NG')

import sys

input = sys.stdin.readline
from collections import *

K = int(eval(input()))
A, B = list(map(int, input().split()))
for i in range(A, B + 1):
    if i % K == 0:
        print("OK")
        exit()
print("NG")

K = int(eval(input()))
A, B = list(map(int, input().split()))
if (A - 1) // K != B // K:
    print("OK")
else:
    print("NG")

-import sys
-input = sys.stdin.readline
-from collections import *
-for i in range(A, B + 1):
-    if i % K == 0:
-        print("OK")
-        exit()
-print("NG")
+if (A - 1) // K != B // K:
+    print("OK")
+else:
+    print("NG")


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

# coding: utf-8

import numpy as np

n = int(eval(input()))

dp = np.zeros((n+10, 3))

def cmax(a,b):

    if a>b:

        return a

    else:

        return b

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

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

    # a

    dp[i][0] = cmax(dp[i-1][1]+a, dp[i-1][2]+a)

    # b

    dp[i][1] = cmax(dp[i-1][0]+b, dp[i-1][2]+b)

    # c

    dp[i][2] = cmax(dp[i-1][0]+c, dp[i-1][1]+c)

print((int(max(dp[i,:]))))

# optimized version of the same code:

# coding: utf-8

# Your code here!

N = int(eval(input()))

dp = [[0]*3 for _ in range(N+1)]

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

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

    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a

    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b

    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c

print((max(dp[N])))

# coding: utf-8
import numpy as np

n = int(eval(input()))
dp = np.zeros((n + 10, 3))

def cmax(a, b):
    if a > b:
        return a
    else:
        return b

for i in range(1, n + 1):
    a, b, c = list(map(int, input().split()))
    # a
    dp[i][0] = cmax(dp[i - 1][1] + a, dp[i - 1][2] + a)
    # b
    dp[i][1] = cmax(dp[i - 1][0] + b, dp[i - 1][2] + b)
    # c
    dp[i][2] = cmax(dp[i - 1][0] + c, dp[i - 1][1] + c)
print((int(max(dp[i, :]))))

# coding: utf-8
# Your code here!
N = int(eval(input()))
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(1, N + 1):
    a, b, c = list(map(int, input().split()))
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c
print((max(dp[N])))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

N = int(eval(input()))

Vlist = np.array(list(map(int,input().split())))

Clist = np.array(list(map(int,input().split())))

Dlist = Vlist-Clist

sum_ = 0

for d in Dlist:

    if d >= 0:

        sum_ += d

print(sum_)

# optimized version of the same code:

# 入力

N = int(eval(input()))

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

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

ans = 0

for i in range(N):

    Z = Vlist[i] - Clist[i]

    if Z > 0:

        ans += Z

print(ans)

import numpy as np

N = int(eval(input()))
Vlist = np.array(list(map(int, input().split())))
Clist = np.array(list(map(int, input().split())))
Dlist = Vlist - Clist
sum_ = 0
for d in Dlist:
    if d >= 0:
        sum_ += d
print(sum_)

-Vlist = np.array(list(map(int, input().split())))

-Clist = np.array(list(map(int, input().split())))

+Vlist = list(map(int, input().split()))

+Clist = list(map(int, input().split()))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

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

Q=[0]

def ex(A):

  return (1+A)/2.0

for i in range(N):

  Q.append(ex(P[i]))

Q=np.array(Q)

R=Q.cumsum()

ans=0

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

  S=R[i]-R[i-K]

  if ans<S:

    ans=S

print(ans)

# optimized version of the same code:

#ika tako

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

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

tot = sum(ppp[:k])#まず、先頭K個の合計を求める

ans = tot#仮の答としておく

for i in range(k, n):#for文で0-indexでk+1番目から最後までチェック

    tot += ppp[i] - ppp[i - k]#新しくi番目を足して、一番古いものを引く

    ans = max(ans, tot)#新しい答が大きいなら更新する

print(((ans + k) / 2))#K個分のサイコロの期待値を出力する

import numpy as np

N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = [0]

def ex(A):
    return (1 + A) / 2.0

for i in range(N):
    Q.append(ex(P[i]))
Q = np.array(Q)
R = Q.cumsum()
ans = 0
for i in range(K, N + 1):
    S = R[i] - R[i - K]
    if ans < S:
        ans = S
print(ans)

# ika tako
n, k = list(map(int, input().split()))
ppp = list(map(int, input().split()))
tot = sum(ppp[:k])  # まず、先頭K個の合計を求める
ans = tot  # 仮の答としておく
for i in range(k, n):  # for文で0-indexでk+1番目から最後までチェック
    tot += ppp[i] - ppp[i - k]  # 新しくi番目を足して、一番古いものを引く
    ans = max(ans, tot)  # 新しい答が大きいなら更新する
print(((ans + k) / 2))  # K個分のサイコロの期待値を出力する

+for i in range(k, n):  # for文で0-indexでk+1番目から最後までチェック

+    tot += ppp[i] - ppp[i - k]  # 新しくi番目を足して、一番古いものを引く

+    ans = max(ans, tot)  # 新しい答が大きいなら更新する

+print(((ans + k) / 2))  # K個分のサイコロの期待値を出力する


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n, ma, mb = list(map(int, input().split()))

U = 400

dp = [[[float("inf")]*(U+1) for _ in range(U+1)] for i in range(n+1)]

dp[0][0][0] = 0

for i in range(n):

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

  for j in range(U+1):

    for k in range(U+1):

      if j<a or k<b:

        dp[i+1][j][k] = dp[i][j][k]

      else:

        dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a][k-b]+c)

ans = float("inf")

for i in range(1, 1+U//max(ma, mb)):

  na, nb = i*ma, i*mb

  ans = min(ans, dp[-1][na][nb])

if ans == float("inf"):

  print((-1))

else:

  print(ans)

# optimized version of the same code:

import numpy as np

n, ma, mb = list(map(int, input().split()))

U = 400

dp = np.full((U+1, U+1), float("inf"))

dp[0, 0] = 0

for i in range(n):

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

  np.minimum(dp[a:, b:], dp[:-a, :-b]+c, out=dp[a:, b:])

ans = float("inf")

for i in range(1, 1+U//max(ma, mb)):

  na, nb = i*ma, i*mb

  ans = min(ans, dp[na, nb])

if ans == float("inf"):

  print((-1))

else:

  print((int(ans)))

n, ma, mb = list(map(int, input().split()))
U = 400
dp = [[[float("inf")] * (U + 1) for _ in range(U + 1)] for i in range(n + 1)]
dp[0][0][0] = 0
for i in range(n):
    a, b, c = list(map(int, input().split()))
    for j in range(U + 1):
        for k in range(U + 1):
            if j < a or k < b:
                dp[i + 1][j][k] = dp[i][j][k]
            else:
                dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - a][k - b] + c)
ans = float("inf")
for i in range(1, 1 + U // max(ma, mb)):
    na, nb = i * ma, i * mb
    ans = min(ans, dp[-1][na][nb])
if ans == float("inf"):
    print((-1))
else:
    print(ans)

import numpy as np

n, ma, mb = list(map(int, input().split()))
U = 400
dp = np.full((U + 1, U + 1), float("inf"))
dp[0, 0] = 0
for i in range(n):
    a, b, c = list(map(int, input().split()))
    np.minimum(dp[a:, b:], dp[:-a, :-b] + c, out=dp[a:, b:])
ans = float("inf")
for i in range(1, 1 + U // max(ma, mb)):
    na, nb = i * ma, i * mb
    ans = min(ans, dp[na, nb])
if ans == float("inf"):
    print((-1))
else:
    print((int(ans)))

-dp = [[[float("inf")] * (U + 1) for _ in range(U + 1)] for i in range(n + 1)]

+dp = np.full((U + 1, U + 1), float("inf"))

+    np.minimum(dp[a:, b:], dp[:-a, :-b] + c, out=dp[a:, b:])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n,*x=list(map(int,open(0).read().split()))

import numpy as np

xar=np.array(x)

ans=float("inf")

for p in range(0,101):

    tmp=sum((xar-p)**2)

    ans=min(ans,tmp)

print((int(ans)))

# optimized version of the same code:

n,*x=list(map(int,open(0).read().split()))

ans=float("inf")

for p in range(0,101):

  s=0

  for xi in x:

    s+=(xi-p)**2

  ans=min(ans,s)

print((int(ans)))

n, *x = list(map(int, open(0).read().split()))
import numpy as np

xar = np.array(x)
ans = float("inf")
for p in range(0, 101):
    tmp = sum((xar - p) ** 2)
    ans = min(ans, tmp)
print((int(ans)))

n, *x = list(map(int, open(0).read().split()))
ans = float("inf")
for p in range(0, 101):
    s = 0
    for xi in x:
        s += (xi - p) ** 2
    ans = min(ans, s)
print((int(ans)))

-import numpy as np
-xar = np.array(x)
-    tmp = sum((xar - p) ** 2)
-    ans = min(ans, tmp)
+    s = 0
+    for xi in x:
+        s += (xi - p) ** 2
+    ans = min(ans, s)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

items = []

for _ in range(N):

    items.append(tuple(map(int, input().split())))

v_max = sum([i[1] for i in items])

INF = 10**12

dp = np.array([[INF for j in range(v_max+1)] for _ in range(N+1)])

dp[0, 0] = 0

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

    w, v = items[i-1]

    dp[i, :v] = dp[i-1, :v]

    dp[i, v:] = np.minimum(dp[i-1, :-v] + w, dp[i-1, v:])

ans = 0

for v in range(v_max, -1, -1):

    if dp[N][v] <= W:

        ans = v

        break

print(ans)

# optimized version of the same code:

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

items = []

INF = 10**12

for _ in range(N):

    items.append(tuple(map(int, input().split())))

MAX_V = sum([v for _, v in items])

dp = [[INF for j in range(MAX_V+1)] for i in range(N+1)]

dp[0][0] = 0

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

    w, v = items[i-1]

    for j in range(MAX_V+1):

        if j - v >= 0:

            dp[i][j] = min(dp[i-1][j-v] + w, dp[i-1][j])

        else:

            dp[i][j] = dp[i-1][j]

for v in range(MAX_V, -1, -1):

    if dp[N][v] <= W:

        break

print(v)

import numpy as np

N, W = list(map(int, input().split()))
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
v_max = sum([i[1] for i in items])
INF = 10**12
dp = np.array([[INF for j in range(v_max + 1)] for _ in range(N + 1)])
dp[0, 0] = 0
for i in range(1, N + 1):
    w, v = items[i - 1]
    dp[i, :v] = dp[i - 1, :v]
    dp[i, v:] = np.minimum(dp[i - 1, :-v] + w, dp[i - 1, v:])
ans = 0
for v in range(v_max, -1, -1):
    if dp[N][v] <= W:
        ans = v
        break
print(ans)

N, W = list(map(int, input().split()))
items = []
INF = 10**12
for _ in range(N):
    items.append(tuple(map(int, input().split())))
MAX_V = sum([v for _, v in items])
dp = [[INF for j in range(MAX_V + 1)] for i in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
    w, v = items[i - 1]
    for j in range(MAX_V + 1):
        if j - v >= 0:
            dp[i][j] = min(dp[i - 1][j - v] + w, dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]
for v in range(MAX_V, -1, -1):
    if dp[N][v] <= W:
        break
print(v)

-dp = np.array([[INF for j in range(v_max + 1)] for _ in range(N + 1)])

+dp = [[INF for j in range(MAX_V + 1)] for i in range(N + 1)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

N = int(readline())

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

graph = [[] for _ in range(N+1)] #隣接リスト

for a,b in AB:

    graph[a].append(b)

    graph[b].append(a)

#親のノードに子を入れてくdfs

stack = [1]

parent = [0]*(N+1)

order = []

while stack:

    x = stack.pop()

    order.append(x)

    for i in graph[x]:

        if i == parent[x]:

            continue

        parent[i] = x

        stack.append(i)

#各子の色を決めていく。

color = [-1]*(N+1)

for x in order:

    ng = color[x]

    c = 1

    for y in graph[x]:

        if parent[x] == y:

            continue

        if c == ng:

            c += 1

        color[y] = c

        c += 1

ans = []

for a,b in AB:

    if parent[a] == b: #子の頂点の色を入れる

        ans.append(color[a])

    else:

        ans.append(color[b])

print((max(ans)))

for i in ans:

    print(i)

# optimized version of the same code:

import sys

from collections import deque

readline = sys.stdin.buffer.readline

def even(n): return 1 if n%2==0 else 0

n = int(readline())

g = [[] for _ in range(n)] #隣接リスト

ab = []

for i in range(n-1):

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

    a,b = a-1,b-1

    ab.append((a,b))

    g[a].append(b)

    g[b].append(a)

root = 0

parent = [0]*n

deq = deque([root])

order = [root]

color = [-1]*n

deq = deque([root])

while deq:

    fr = deq.pop()

    ng = color[fr]

    c = 0

    for go in g[fr]:

        if go == parent[fr]:

            continue

        if c == ng:

            c += 1

        parent[go] = fr

        color[go] = c

        c += 1

        deq.append(go)

        order.append(go)

rank = [0]*n

for i,j in enumerate(order):

    rank[j] = i

print((max(color)+1))

for a,b in ab:

    if rank[a] < rank[b]:

        print((color[b]+1))

    else:

        print((color[a]+1))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
AB = [list(map(int, readline().split())) for i in range(N - 1)]
graph = [[] for _ in range(N + 1)]  # 隣接リスト
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
# 親のノードに子を入れてくdfs
stack = [1]
parent = [0] * (N + 1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in graph[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)
# 各子の色を決めていく。
color = [-1] * (N + 1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if parent[x] == y:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1
ans = []
for a, b in AB:
    if parent[a] == b:  # 子の頂点の色を入れる
        ans.append(color[a])
    else:
        ans.append(color[b])
print((max(ans)))
for i in ans:
    print(i)

import sys
from collections import deque

readline = sys.stdin.buffer.readline

def even(n):
    return 1 if n % 2 == 0 else 0

n = int(readline())
g = [[] for _ in range(n)]  # 隣接リスト
ab = []
for i in range(n - 1):
    a, b = list(map(int, readline().split()))
    a, b = a - 1, b - 1
    ab.append((a, b))
    g[a].append(b)
    g[b].append(a)
root = 0
parent = [0] * n
deq = deque([root])
order = [root]
color = [-1] * n
deq = deque([root])
while deq:
    fr = deq.pop()
    ng = color[fr]
    c = 0
    for go in g[fr]:
        if go == parent[fr]:
            continue
        if c == ng:
            c += 1
        parent[go] = fr
        color[go] = c
        c += 1
        deq.append(go)
        order.append(go)
rank = [0] * n
for i, j in enumerate(order):
    rank[j] = i
print((max(color) + 1))
for a, b in ab:
    if rank[a] < rank[b]:
        print((color[b] + 1))
    else:
        print((color[a] + 1))

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

-graph = [[] for _ in range(N + 1)]  # 隣接リスト

-# 親のノードに子を入れてくdfs

-# 各子の色を決めていく。

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from copy import deepcopy

from scipy.sparse.csgraph import floyd_warshall

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

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

cnt=0

for i in range(m):

  ll=deepcopy(l)

  del ll[i]

  d=[[float('inf')]*n for i in range(n)]

  for i in range(n):

    d[i][i]=0

  for a,b in ll:

    a-=1

    b-=1

    d[a][b]=1

    d[b][a]=1

  s=floyd_warshall(d)

  for i in s:

    if float('inf') in i:

      cnt+=1

      break

print(cnt)

# optimized version of the same code:

from collections import deque

from copy import deepcopy

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

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

def BFS(m):

  t_l=deepcopy(l)

  del t_l[m]

  tree=[[] for j in range(n)]

  for a,b in t_l:

    a-=1

    b-=1

    tree[a].append(b)

    tree[b].append(a)

  dist=[-1 for i in range(n)]

  dist[0]=0

  que=deque()

  que.append(0)

  while que:

    x=que.popleft()

    for i in tree[x]:

      if dist[i]==-1:

        que.append(i)

        dist[i]=dist[x]+1

  return dist

ans=0

for i in range(m):

  d=BFS(i)

  if -1 in d:

    ans+=1

print(ans)

from copy import deepcopy
from scipy.sparse.csgraph import floyd_warshall

n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
cnt = 0
for i in range(m):
    ll = deepcopy(l)
    del ll[i]
    d = [[float("inf")] * n for i in range(n)]
    for i in range(n):
        d[i][i] = 0
    for a, b in ll:
        a -= 1
        b -= 1
        d[a][b] = 1
        d[b][a] = 1
    s = floyd_warshall(d)
    for i in s:
        if float("inf") in i:
            cnt += 1
            break
print(cnt)

from collections import deque
from copy import deepcopy

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

def BFS(m):
    t_l = deepcopy(l)
    del t_l[m]
    tree = [[] for j in range(n)]
    for a, b in t_l:
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)
    dist = [-1 for i in range(n)]
    dist[0] = 0
    que = deque()
    que.append(0)
    while que:
        x = que.popleft()
        for i in tree[x]:
            if dist[i] == -1:
                que.append(i)
                dist[i] = dist[x] + 1
    return dist

ans = 0
for i in range(m):
    d = BFS(i)
    if -1 in d:
        ans += 1
print(ans)

-from scipy.sparse.csgraph import floyd_warshall

-    d = [[float("inf")] * n for i in range(n)]