Input:
from collections import defaultdict, deque

N, M, *L = list(map(int, open(0).read().split()))

dic = defaultdict(list)

par =  [0]*N

cnt = [0]*(N+1)

for a,b in zip(*[iter(L)]*2):

  dic[a] += [b]

  cnt[b] += 1

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

  if cnt[i]==0:

    q = deque([i])

    par[i-1] = '0'

    break

while q:

  m = q.popleft()

  for c in dic[m]:

    cnt[c] -= 1

    if cnt[c]==0:

      par[c-1] = str(m)

      q += [c]

ans = '\n'.join(par)

print(ans)

from collections import defaultdict, deque

def main():

  N, M, *L = list(map(int, open(0).read().split()))

  dic = defaultdict(list)

  par =  [0]*N

  cnt = [0]*(N+1)

  for a,b in zip(*[iter(L)]*2):

    dic[a] += [b]

    cnt[b] += 1

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

    if cnt[i]==0:

      q = deque([i])

      par[i-1] = '0'

      break

  while q:

    m = q.popleft()

    for c in dic[m]:

      cnt[c] -= 1

      if cnt[c]==0:

        par[c-1] = str(m)

        q += [c]

  ans = '\n'.join(par)

  print(ans)

if __name__== '__main__':

  main()

from collections import defaultdict, deque

N, M, *L = list(map(int, open(0).read().split()))
dic = defaultdict(list)
par = [0] * N
cnt = [0] * (N + 1)
for a, b in zip(*[iter(L)] * 2):
    dic[a] += [b]
    cnt[b] += 1
for i in range(1, N + 1):
    if cnt[i] == 0:
        q = deque([i])
        par[i - 1] = "0"
        break
while q:
    m = q.popleft()
    for c in dic[m]:
        cnt[c] -= 1
        if cnt[c] == 0:
            par[c - 1] = str(m)
            q += [c]
ans = "\n".join(par)
print(ans)

from collections import defaultdict, deque

def main():
    N, M, *L = list(map(int, open(0).read().split()))
    dic = defaultdict(list)
    par = [0] * N
    cnt = [0] * (N + 1)
    for a, b in zip(*[iter(L)] * 2):
        dic[a] += [b]
        cnt[b] += 1
    for i in range(1, N + 1):
        if cnt[i] == 0:
            q = deque([i])
            par[i - 1] = "0"
            break
    while q:
        m = q.popleft()
        for c in dic[m]:
            cnt[c] -= 1
            if cnt[c] == 0:
                par[c - 1] = str(m)
                q += [c]
    ans = "\n".join(par)
    print(ans)

if __name__ == "__main__":
    main()

-N, M, *L = list(map(int, open(0).read().split()))

+    N, M, *L = list(map(int, open(0).read().split()))


Input:
def main():

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

    # マイナスの場合は leader であり、同時にサイズ(*-1)を保持する

    uf = [-1] * (n+1)

    def uf_leader(a):

        if uf[a]<0:

            return a

        uf[a] = uf_leader(uf[a])

        return uf[a]

    def uf_unite(a, b):

        ua, ub = uf_leader(a), uf_leader(b)

        if ua==ub:

            return False

        if uf[ua] > uf[ub]:

            a, b = b, a

        uf[ua] += uf[ub]

        uf[ub] = ua

        return True

    def uf_leaders():

        return set([uf_leader(v) for v in range(1,n+1)])

    # print(uf[1:])

    for _ in range(m):

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

        uf_unite(a, b)

        # print(uf[1:])

    # print(uf_leaders())

    ans = len(uf_leaders())-1

    print(ans)

main()

def main():

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

    # マイナスの場合は leader であり、同時にサイズ(*-1)を保持する

    uf = [-1] * (n+1)

    def uf_leader(a):

        if uf[a]<0:

            return a

        uf[a] = uf_leader(uf[a])

        return uf[a]

    def uf_unite(a, b):

        ua, ub = uf_leader(a), uf_leader(b)

        if ua==ub:

            return False

        if uf[ua] > uf[ub]:

            ua, ub = ub, ua

        uf[ua] += uf[ub]

        uf[ub] = ua

        return True

    def uf_leaders():

        return set([uf_leader(v) for v in range(1,n+1)])

    # print(uf[1:])

    for _ in range(m):

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

        uf_unite(a, b)

        # print(uf[1:])

    # print(uf_leaders())

    ans = len(uf_leaders())-1

    print(ans)

main()

def main():
    n, m = list(map(int, input().split()))
    # マイナスの場合は leader であり、同時にサイズ(*-1)を保持する
    uf = [-1] * (n + 1)

    def uf_leader(a):
        if uf[a] < 0:
            return a
        uf[a] = uf_leader(uf[a])
        return uf[a]

    def uf_unite(a, b):
        ua, ub = uf_leader(a), uf_leader(b)
        if ua == ub:
            return False
        if uf[ua] > uf[ub]:
            a, b = b, a
        uf[ua] += uf[ub]
        uf[ub] = ua
        return True

    def uf_leaders():
        return set([uf_leader(v) for v in range(1, n + 1)])

    # print(uf[1:])
    for _ in range(m):
        a, b = list(map(int, input().split()))
        uf_unite(a, b)
        # print(uf[1:])
    # print(uf_leaders())
    ans = len(uf_leaders()) - 1
    print(ans)

main()

def main():
    n, m = list(map(int, input().split()))
    # マイナスの場合は leader であり、同時にサイズ(*-1)を保持する
    uf = [-1] * (n + 1)

    def uf_leader(a):
        if uf[a] < 0:
            return a
        uf[a] = uf_leader(uf[a])
        return uf[a]

    def uf_unite(a, b):
        ua, ub = uf_leader(a), uf_leader(b)
        if ua == ub:
            return False
        if uf[ua] > uf[ub]:
            ua, ub = ub, ua
        uf[ua] += uf[ub]
        uf[ub] = ua
        return True

    def uf_leaders():
        return set([uf_leader(v) for v in range(1, n + 1)])

    # print(uf[1:])
    for _ in range(m):
        a, b = list(map(int, input().split()))
        uf_unite(a, b)
        # print(uf[1:])
    # print(uf_leaders())
    ans = len(uf_leaders()) - 1
    print(ans)

main()

-            a, b = b, a
+            ua, ub = ub, ua


Input:
from numba import njit

from math import gcd

K = int(eval(input()))

@njit

def solve():

    ans = 0

    for a in range(1, K + 1):

        for b in range(1, K + 1):

            for c in range(1, K + 1):

                ans += gcd(gcd(a, b), c)

    return ans

print((solve()))

from math import gcd

K = int(eval(input()))

ans = 0

for a in range(1, K + 1):

    for b in range(1, K + 1):

        for c in range(1, K + 1):

            ans += gcd(gcd(a, b), c)

print(ans)

-                ans += gcd(gcd(a, b), c)


Input:
import sys

import numba

import numpy as np

S = sys.stdin.buffer.readline().decode('utf-8').rstrip()

S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

@numba.njit(numba.i8(numba.typeof(S)), cache=True)

def solve(S):

	M = 2019

	t = 1

	ans = 0

	c = np.zeros(M, dtype=np.int64)

	c[0] = 1

	r = 0

	for d in S:

		r = (d * t + r) % M

		ans += c[r]

		c[r] += 1

		t = t * 10 % M

	return ans

print((solve(S)))

import sys

import numpy as np

def solve(S):

	M = 2019

	t = 1

	ans = 0

	c = np.zeros(M, dtype=np.int64)

	c[0] = 1

	r = 0

	for d in S:

		r = (d * t + r) % M

		ans += c[r]

		c[r] += 1

		t = t * 10 % M

	return ans

def cc_export():

	from numba.pycc import CC

	cc = CC('my_module')

	cc.export('solve', 'i8(i4[:])')(solve)

	cc.compile()

if __name__ == '__main__':

	import sys

	if sys.argv[-1] == 'ONLINE_JUDGE':

		cc_export()

		exit(0)

	from my_module import solve

	S = sys.stdin.buffer.readline().decode('utf-8').rstrip()

	S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

	print((solve(S)))

import sys
import numba
import numpy as np

S = sys.stdin.buffer.readline().decode("utf-8").rstrip()
S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

@numba.njit(numba.i8(numba.typeof(S)), cache=True)
def solve(S):
    M = 2019
    t = 1
    ans = 0
    c = np.zeros(M, dtype=np.int64)
    c[0] = 1
    r = 0
    for d in S:
        r = (d * t + r) % M
        ans += c[r]
        c[r] += 1
        t = t * 10 % M
    return ans

print((solve(S)))

import sys
import numpy as np

def solve(S):
    M = 2019
    t = 1
    ans = 0
    c = np.zeros(M, dtype=np.int64)
    c[0] = 1
    r = 0
    for d in S:
        r = (d * t + r) % M
        ans += c[r]
        c[r] += 1
        t = t * 10 % M
    return ans

def cc_export():
    from numba.pycc import CC

    cc = CC("my_module")
    cc.export("solve", "i8(i4[:])")(solve)
    cc.compile()

if __name__ == "__main__":
    import sys

    if sys.argv[-1] == "ONLINE_JUDGE":
        cc_export()
        exit(0)
    from my_module import solve

    S = sys.stdin.buffer.readline().decode("utf-8").rstrip()
    S = np.array([int(d) for d in S[::-1]], dtype=np.int32)
    print((solve(S)))

-S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

+    cc.export("solve", "i8(i4[:])")(solve)

+    S = sys.stdin.buffer.readline().decode("utf-8").rstrip()

+    S = np.array([int(d) for d in S[::-1]], dtype=np.int32)


Input:
class Dice:

    def __init__(self):

        # 初期値がない場合

        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定

        self.t = 1

        self.s = 2

        self.e = 3

        self.w = 4

        self.n = 5

        self.b = 6

        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):

        # 初期値が指定される場合

        self.t = t

        self.s = s

        self.e = e

        self.w = w

        self.n = n

        self.b = b

        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):

        if way == 0:

            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s

        elif way == 1:

            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n

        elif way == 2:

            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e

        elif way == 3:

            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w

def main():

    import random

    n = int(eval(input()))

    diceList = [[0 for _ in range(6)] for _ in range(n)]

    for i in range(n):

        diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5] = list(map(int, input().split()))

    flag = 0

    # 2つ目以降のさいころが、以前のさいころと一致しているか確認していく。

    for i in range(1, n):

        if flag == 1:

            break

        else:

            dice_a = Dice(diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5])

            for j in range(i):

                dice_b = Dice(diceList[j][0],diceList[j][1],diceList[j][2],diceList[j][3],diceList[j][4],diceList[j][5])

                for _ in range(100):

                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (dice_b.t, dice_b.s, dice_b.e, dice_b.w, dice_b.n, dice_b.b):

                        flag = 1

                        break

                    else:

                        seed = random.randint(0, 3)

                        dice_a.rot(seed)

    if flag == 0:

        print("Yes")

    else:

        print("No")

if __name__ == '__main__':

    main()

def main():

    n = int(eval(input()))

    dices=[]

    same = 0

    for _ in range(n):

        dices.append(list(map(int, input().split())))

    for i in range(n-1):

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

            same += check_dice(dices[i], dices[j])

        if same >= 1:

            print('No')

            break

    if same == 0:

        print('Yes')

def check_dice(f, s):

    yes = 0

    for _ in range(4):

        s[0],s[2],s[5],s[3] = s[2],s[5],s[3],s[0]

        for _ in range(4):

            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]

            if f == s:

                yes = 1

    for _ in range(4):

        s[0],s[1],s[5],s[4] = s[1],s[5],s[4],s[0]

        for _ in range(4):

            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]

            if f == s:

                yes = 1

    return yes

if __name__ == '__main__':

    main()

class Dice:
    def __init__(self):
        # 初期値がない場合
        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        # 初期値が指定される場合
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = (
                self.n,
                self.t,
                self.e,
                self.w,
                self.b,
                self.s,
            )
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = (
                self.s,
                self.b,
                self.e,
                self.w,
                self.t,
                self.n,
            )
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = (
                self.w,
                self.s,
                self.t,
                self.b,
                self.n,
                self.e,
            )
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = (
                self.e,
                self.s,
                self.b,
                self.t,
                self.n,
                self.w,
            )

def main():
    import random

    n = int(eval(input()))
    diceList = [[0 for _ in range(6)] for _ in range(n)]
    for i in range(n):
        (
            diceList[i][0],
            diceList[i][1],
            diceList[i][2],
            diceList[i][3],
            diceList[i][4],
            diceList[i][5],
        ) = list(map(int, input().split()))
    flag = 0
    # 2つ目以降のさいころが、以前のさいころと一致しているか確認していく。
    for i in range(1, n):
        if flag == 1:
            break
        else:
            dice_a = Dice(
                diceList[i][0],
                diceList[i][1],
                diceList[i][2],
                diceList[i][3],
                diceList[i][4],
                diceList[i][5],
            )
            for j in range(i):
                dice_b = Dice(
                    diceList[j][0],
                    diceList[j][1],
                    diceList[j][2],
                    diceList[j][3],
                    diceList[j][4],
                    diceList[j][5],
                )
                for _ in range(100):
                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (
                        dice_b.t,
                        dice_b.s,
                        dice_b.e,
                        dice_b.w,
                        dice_b.n,
                        dice_b.b,
                    ):
                        flag = 1
                        break
                    else:
                        seed = random.randint(0, 3)
                        dice_a.rot(seed)
    if flag == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    dices = []
    same = 0
    for _ in range(n):
        dices.append(list(map(int, input().split())))
    for i in range(n - 1):
        for j in range(i + 1, n):
            same += check_dice(dices[i], dices[j])
        if same >= 1:
            print("No")
            break
    if same == 0:
        print("Yes")

def check_dice(f, s):
    yes = 0
    for _ in range(4):
        s[0], s[2], s[5], s[3] = s[2], s[5], s[3], s[0]
        for _ in range(4):
            s[1], s[2], s[4], s[3] = s[2], s[4], s[3], s[1]
            if f == s:
                yes = 1
    for _ in range(4):
        s[0], s[1], s[5], s[4] = s[1], s[5], s[4], s[0]
        for _ in range(4):
            s[1], s[2], s[4], s[3] = s[2], s[4], s[3], s[1]
            if f == s:
                yes = 1
    return yes

if __name__ == "__main__":
    main()

-        # 初期値がない場合

-        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定

-    def __init__(self, t, s, e, w, n, b):

-        # 初期値が指定される場合

-            self.t, self.s, self.e, self.w, self.n, self.b = (

+        dices.append(list(map(int, input().split())))

+            same += check_dice(dices[i], dices[j])

-    diceList = [[0 for _ in range(6)] for _ in range(n)]

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

-    # 2つ目以降のさいころが、以前のさいころと一致しているか確認していく。

-                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (

-                        seed = random.randint(0, 3)

-                        dice_a.rot(seed)


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

total_val = 0

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

    i_str = str(i)

    digits = list(i_str)

    sum_digit = sum([int(digit) for digit in digits])

    if sum_digit >= a and sum_digit <= b:

        total_val += i

print(total_val)

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

canditates = [i for i in range(1, n+1)

              if a <= sum(list(map(int, list(str(i))))) <= b]

print((sum(canditates)))

n, a, b = list(map(int, input().split()))
total_val = 0
for i in range(1, n + 1):
    i_str = str(i)
    digits = list(i_str)
    sum_digit = sum([int(digit) for digit in digits])
    if sum_digit >= a and sum_digit <= b:
        total_val += i
print(total_val)

n, a, b = list(map(int, input().split()))
canditates = [i for i in range(1, n + 1) if a <= sum(list(map(int, list(str(i))))) <= b]
print((sum(canditates)))

-    sum_digit = sum([int(digit) for digit in digits])

-    if sum_digit >= a and sum_digit <= b:

+canditates = [i for i in range(1, n + 1) if a <= sum(list(map(int, list(str(i))))) <= b]


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

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

sum_a = sum(a)

MOD = 998244353

dp = [[0] * (sum_a + 1) for i in range(n + 1)]

dp[0][0] = 1

for i in range(n):

    for j in range(sum_a + 1):

        # 選ぶとき

        if j - a[i] >= 0:

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

        # 選ばないとき

        dp[i + 1][j] += dp[i][j] * 2

        dp[i + 1][j] %= MOD

dq = [[0] * (sum_a + 1) for i in range(n + 1)]

dq[0][0] = 1

for i in range(n):

    for j in range(sum_a + 1):

        # 選ぶとき

        if j - a[i] >= 0:

            dq[i + 1][j] += dq[i][j - a[i]]

        # 選ばないとき

        dq[i + 1][j] += dq[i][j]

        dq[i + 1][j] %= MOD

ans = 0

for j in range(sum_a + 1):

    if sum_a <= j * 2:

        ans += dp[-1][j] * 3

        ans %= MOD

if sum_a % 2 == 0:

    ans -= dq[-1][sum_a // 2] * 3

print(((3 ** n - ans) % MOD))

n = int(eval(input()))

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

sum_a = sum(a)

MOD = 998244353

dp = [0] * (sum_a + 1)

dp[0] = 1

for i in range(n):

    for j in range(sum_a + 1)[::-1]:

        # 選ばないとき

        dp[j] += dp[j]

        if j - a[i] >= 0:

            dp[j] += dp[j - a[i]]

        dp[j] %= MOD

dq = [0] * (sum_a + 1)

dq[0] = 1

for i in range(n):

    for j in range(sum_a + 1)[::-1]:

        # 選ぶとき

        if j - a[i] >= 0:

            dq[j] += dq[j - a[i]]

            dq[j] %= MOD

        else:

            break

ans = 0

for j in range(sum_a + 1):

    if sum_a <= j * 2:

        ans += dp[j] * 3

        ans %= MOD

if sum_a % 2 == 0:

    ans -= dq[sum_a // 2] * 3

print(((3 ** n - ans) % MOD))

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
sum_a = sum(a)
MOD = 998244353
dp = [[0] * (sum_a + 1) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
    for j in range(sum_a + 1):
        # 選ぶとき
        if j - a[i] >= 0:
            dp[i + 1][j] += dp[i][j - a[i]]
        # 選ばないとき
        dp[i + 1][j] += dp[i][j] * 2
        dp[i + 1][j] %= MOD
dq = [[0] * (sum_a + 1) for i in range(n + 1)]
dq[0][0] = 1
for i in range(n):
    for j in range(sum_a + 1):
        # 選ぶとき
        if j - a[i] >= 0:
            dq[i + 1][j] += dq[i][j - a[i]]
        # 選ばないとき
        dq[i + 1][j] += dq[i][j]
        dq[i + 1][j] %= MOD
ans = 0
for j in range(sum_a + 1):
    if sum_a <= j * 2:
        ans += dp[-1][j] * 3
        ans %= MOD
if sum_a % 2 == 0:
    ans -= dq[-1][sum_a // 2] * 3
print(((3**n - ans) % MOD))

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
sum_a = sum(a)
MOD = 998244353
dp = [0] * (sum_a + 1)
dp[0] = 1
for i in range(n):
    for j in range(sum_a + 1)[::-1]:
        # 選ばないとき
        dp[j] += dp[j]
        if j - a[i] >= 0:
            dp[j] += dp[j - a[i]]
        dp[j] %= MOD
dq = [0] * (sum_a + 1)
dq[0] = 1
for i in range(n):
    for j in range(sum_a + 1)[::-1]:
        # 選ぶとき
        if j - a[i] >= 0:
            dq[j] += dq[j - a[i]]
            dq[j] %= MOD
        else:
            break
ans = 0
for j in range(sum_a + 1):
    if sum_a <= j * 2:
        ans += dp[j] * 3
        ans %= MOD
if sum_a % 2 == 0:
    ans -= dq[sum_a // 2] * 3
print(((3**n - ans) % MOD))

-dp = [[0] * (sum_a + 1) for i in range(n + 1)]

+        # 選ばないとき

-        # 選ばないとき

-dq = [[0] * (sum_a + 1) for i in range(n + 1)]

-        # 選ぶとき

-        # 選ばないとき


Input:
import re

print(("YES" if re.match("^(eraser?|dream(er)?)+$",eval(input())) else "NO"))

s = input().replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ").replace(" ", "")

if s:

    print("NO")

else:

    print("YES")

import re

print(("YES" if re.match("^(eraser?|dream(er)?)+$", eval(input())) else "NO"))

s = (
    input()
    .replace("eraser", " ")
    .replace("erase", " ")
    .replace("dreamer", " ")
    .replace("dream", " ")
    .replace(" ", "")
)
if s:
    print("NO")
else:
    print("YES")

-print(("YES" if re.match("^(eraser?|dream(er)?)+$", eval(input())) else "NO"))


Input:
n = eval(input())

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

b = []

for i in range(1, n):

    if a[i] - a[i-1] != 0:

        b.append(a[i] - a[i-1])

dont_mind = True

c = 1

i = 1

while i < len(b):

    prev = b[i-1]

    t = prev * b[i]

    if t >= 0:

        i += 1

        continue

    if t < 0:

        c += 1

        i += 2

        continue

    i += 1

print(c)

# coding: utf-8

# AGC 013 a

# Here your code !

n = eval(input())

if n <= 2:

    print(1)

    exit()

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

c = 1

status = "n"

i = 1

while i < n:

    if status == "n":

        if a[i-1] < a[i]:

            status = "i"

        elif a[i-1] > a[i]:

            status = "d"

        i += 1

    elif status == "i":

        if a[i-1] <= a[i]:

            i += 1

        elif a[i-1] > a[i]:

            status = "n"

            c += 1

            i += 1

    elif status == "d":

        if a[i-1] < a[i]:

            status = "n"

            c += 1

            i += 1

        elif a[i-1] >= a[i]:

            i += 1

print(c)

n = eval(input())
a = list(map(int, input().split()))
b = []
for i in range(1, n):
    if a[i] - a[i - 1] != 0:
        b.append(a[i] - a[i - 1])
dont_mind = True
c = 1
i = 1
while i < len(b):
    prev = b[i - 1]
    t = prev * b[i]
    if t >= 0:
        i += 1
        continue
    if t < 0:
        c += 1
        i += 2
        continue
    i += 1
print(c)

# coding: utf-8
# AGC 013 a
# Here your code !
n = eval(input())
if n <= 2:
    print(1)
    exit()
a = list(map(int, input().split()))
c = 1
status = "n"
i = 1
while i < n:
    if status == "n":
        if a[i - 1] < a[i]:
            status = "i"
        elif a[i - 1] > a[i]:
            status = "d"
        i += 1
    elif status == "i":
        if a[i - 1] <= a[i]:
            i += 1
        elif a[i - 1] > a[i]:
            status = "n"
            c += 1
            i += 1
    elif status == "d":
        if a[i - 1] < a[i]:
            status = "n"
            c += 1
            i += 1
        elif a[i - 1] >= a[i]:
            i += 1
print(c)

+# coding: utf-8
+# AGC 013 a
+# Here your code !
+if n <= 2:
+    print(1)
+    exit()
-b = []
-for i in range(1, n):
-    if a[i] - a[i - 1] != 0:
-        b.append(a[i] - a[i - 1])
-dont_mind = True
+status = "n"
-while i < len(b):
-    prev = b[i - 1]
-    t = prev * b[i]
-    if t >= 0:
+while i < n:
+    if status == "n":
+        if a[i - 1] < a[i]:
+            status = "i"
+        elif a[i - 1] > a[i]:
+            status = "d"
-        continue
-    if t < 0:
-        c += 1
-        i += 2
-        continue
-    i += 1
+    elif status == "i":
+        if a[i - 1] <= a[i]:
+            i += 1
+        elif a[i - 1] > a[i]:
+            status = "n"
+            c += 1
+            i += 1
+    elif status == "d":
+        if a[i - 1] < a[i]:
+            status = "n"
+            c += 1
+            i += 1
+        elif a[i - 1] >= a[i]:
+            i += 1


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

start = 100 ** d

counter = 0

while True:

    if start % (100 ** d) == 0 and start % (100 ** (d + 1)) != 0:

        counter += 1

    if counter == n:

        print(start)

        break

    start += 1

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

start = 100 ** d

counter = 0

while True:

    if start % (100 ** d) == 0 and start % (100 ** (d + 1)) != 0:

        counter += 1

    if counter == n:

        print(start)

        break

    start += 100 ** d

d, n = list(map(int, input().split()))
start = 100**d
counter = 0
while True:
    if start % (100**d) == 0 and start % (100 ** (d + 1)) != 0:
        counter += 1
    if counter == n:
        print(start)
        break
    start += 100**d


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

A = int(eval(input()))

B = int(eval(input()))

print(((X - A) % B))

X, A, B = [int(eval(input())) for _ in range(3)]

print(((X-A) % B))

X, A, B = [int(eval(input())) for _ in range(3)]
print(((X - A) % B))

+X, A, B = [int(eval(input())) for _ in range(3)]


Input:
from operator import mul

from functools import reduce

MOD = 10**9 + 7

def cmb(n, r):

    if n < r:

        return 0

    r = min(n-r, r)

    if r == 0:

        return 1

    numer = reduce(mul, list(range(n, n-r, -1)))

    denom = reduce(mul, list(range(1, r+1)))

    return numer // denom % MOD

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

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

    print((cmb(K-1, i-1) * cmb(N-K+1, i) % MOD))

from operator import mul

from functools import reduce

MOD = 10 ** 9 + 7

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

def cmb(n, r):

    if n < r:

        return 0

    r = min(r, n-r)

    if r == 0:

        return 1

    nume = reduce(mul, list(range(n, n-r, -1)))

    deno = reduce(mul, list(range(1, r+1)))

    return nume // deno % MOD

# 赤いボールの間と両端（N-K+1）の中からi個を選ぶ

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

    print((cmb((N-K+1), i) * cmb((K-1), i-1) % MOD))

from operator import mul
from functools import reduce

MOD = 10**9 + 7

def cmb(n, r):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    numer = reduce(mul, list(range(n, n - r, -1)))
    denom = reduce(mul, list(range(1, r + 1)))
    return numer // denom % MOD

N, K = list(map(int, input().split()))
for i in range(1, K + 1):
    print((cmb(K - 1, i - 1) * cmb(N - K + 1, i) % MOD))

from operator import mul
from functools import reduce

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

def cmb(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    if r == 0:
        return 1
    nume = reduce(mul, list(range(n, n - r, -1)))
    deno = reduce(mul, list(range(1, r + 1)))
    return nume // deno % MOD

# 赤いボールの間と両端（N-K+1）の中からi個を選ぶ
for i in range(1, K + 1):
    print((cmb((N - K + 1), i) * cmb((K - 1), i - 1) % MOD))

-    numer = reduce(mul, list(range(n, n - r, -1)))

-    denom = reduce(mul, list(range(1, r + 1)))

+    nume = reduce(mul, list(range(n, n - r, -1)))

+    deno = reduce(mul, list(range(1, r + 1)))

+# 赤いボールの間と両端（N-K+1）の中からi個を選ぶ


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

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

n = N

while True:

    s = str(n)

    S = set(list(s))

    for c in S:

        if c in D:

            break

    else:

        break

    n += 1

print(n)

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

D=set(input().split())

def check(x):

    for c in str(x):

        if c in D: return False

    return True

ans = N

while not check(ans): ans += 1

print(ans)

N, K = list(map(int, input().split()))
D = list(map(str, list(map(int, input().split()))))
n = N
while True:
    s = str(n)
    S = set(list(s))
    for c in S:
        if c in D:
            break
    else:
        break
    n += 1
print(n)

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

def check(x):
    for c in str(x):
        if c in D:
            return False
    return True

ans = N
while not check(ans):
    ans += 1
print(ans)

-D = list(map(str, list(map(int, input().split()))))


Input:
# C - Average Length

N = int(eval(input()))

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

def calcDist(Y):

    dist = 0

    for i in range(1, len(Y)):

        dist += pow(pow(P[Y[i]][0] - P[Y[i-1]][0], 2) + pow(P[Y[i]][1] - P[Y[i-1]][1], 2), 0.5)

    return dist

def dfs(X):

    global ans

    if len(X)==N:

        ans.append(calcDist(X))

        return

    for i in range(N):

        if i not in X:

            X.append(i)

            dfs(X)

            X.pop()

ans = []

X = []

dfs(X)

print((sum(ans)/len(ans)))

# C - Average Length

import itertools

N = int(eval(input()))

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

def calcDist(Y):

    dist = 0

    for i in range(1, len(Y)):

        dist += pow(pow(P[Y[i]][0] - P[Y[i-1]][0], 2) + pow(P[Y[i]][1] - P[Y[i-1]][1], 2), 0.5)

    return dist

def dfs(X):

    global ans

    if len(X)==N:

        ans.append(calcDist(X))

        return

    for i in range(N):

        if i not in X:

            X.append(i)

            dfs(X)

            X.pop()

ans = []

X = []

#dfs(X)

for X in itertools.permutations(list(range(N)),N):

    ans.append(calcDist(X))

print((sum(ans)/len(ans)))

# C - Average Length
N = int(eval(input()))
P = [tuple(map(int, input().split())) for _ in range(N)]

def calcDist(Y):
    dist = 0
    for i in range(1, len(Y)):
        dist += pow(
            pow(P[Y[i]][0] - P[Y[i - 1]][0], 2) + pow(P[Y[i]][1] - P[Y[i - 1]][1], 2),
            0.5,
        )
    return dist

def dfs(X):
    global ans
    if len(X) == N:
        ans.append(calcDist(X))
        return
    for i in range(N):
        if i not in X:
            X.append(i)
            dfs(X)
            X.pop()

ans = []
X = []
dfs(X)
print((sum(ans) / len(ans)))

# C - Average Length
import itertools

N = int(eval(input()))
P = [tuple(map(int, input().split())) for _ in range(N)]

def calcDist(Y):
    dist = 0
    for i in range(1, len(Y)):
        dist += pow(
            pow(P[Y[i]][0] - P[Y[i - 1]][0], 2) + pow(P[Y[i]][1] - P[Y[i - 1]][1], 2),
            0.5,
        )
    return dist

def dfs(X):
    global ans
    if len(X) == N:
        ans.append(calcDist(X))
        return
    for i in range(N):
        if i not in X:
            X.append(i)
            dfs(X)
            X.pop()

ans = []
X = []
# dfs(X)
for X in itertools.permutations(list(range(N)), N):
    ans.append(calcDist(X))
print((sum(ans) / len(ans)))

+for X in itertools.permutations(list(range(N)), N):


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

print((800*N - 200*(N//15)))


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

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

A = sorted(A)

def make_divisors(n):

    divisors = []

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

        if n % i == 0:

            divisors.append(i)

            if i != n // i:

                divisors.append(n//i)

    return divisors

if len(A) <= 2:

    print((max(A)))

    exit()

else:

    all_divisors = list(set(make_divisors(A[0]) + make_divisors(A[1])))

ans = 1

for divisor in all_divisors:

    cnt = 0

    for a in A:

        if a % divisor != 0:

            cnt += 1

        if cnt == 2:

            break

    if cnt < 2:

        ans = max(ans, divisor)

print(ans)

import sys

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

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

A = sorted(A)

def make_divisors(n):

    divisors = []

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

        if n % i == 0:

            divisors.append(i)

            if i != n // i:

                divisors.append(n//i)

    return divisors

def main():

    if len(A) <= 2:

        print((max(A)))

        exit()

    else:

        all_divisors = list(set(make_divisors(A[0]) + make_divisors(A[1])))

    ans = 1

    for divisor in all_divisors:

        cnt = 0

        for a in A:

            if a % divisor != 0:

                cnt += 1

            if cnt == 2:

                break

        if cnt < 2:

            ans = max(ans, divisor)

    print(ans)

if __name__ == '__main__':

    main()

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

if len(A) <= 2:
    print((max(A)))
    exit()
else:
    all_divisors = list(set(make_divisors(A[0]) + make_divisors(A[1])))
ans = 1
for divisor in all_divisors:
    cnt = 0
    for a in A:
        if a % divisor != 0:
            cnt += 1
        if cnt == 2:
            break
    if cnt < 2:
        ans = max(ans, divisor)
print(ans)

import sys

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

def main():
    if len(A) <= 2:
        print((max(A)))
        exit()
    else:
        all_divisors = list(set(make_divisors(A[0]) + make_divisors(A[1])))
    ans = 1
    for divisor in all_divisors:
        cnt = 0
        for a in A:
            if a % divisor != 0:
                cnt += 1
            if cnt == 2:
                break
        if cnt < 2:
            ans = max(ans, divisor)
    print(ans)

if __name__ == "__main__":
    main()

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

-    all_divisors = list(set(make_divisors(A[0]) + make_divisors(A[1])))

+        all_divisors = list(set(make_divisors(A[0]) + make_divisors(A[1])))


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

cset = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

sset = ['a'] * N

def rec(di, usedci):

    if di >= len(sset):

        print((''.join(sset)))

        return

    for i in range(usedci+1):

        sset[di] = cset[i]

        rec(di+1, usedci)

    sset[di] = cset[usedci+1]

    rec(di+1, usedci+1)

rec(1, 0)

N = int(eval(input()))

cset = [chr(ord('a')+i) for i in range(N)]

sset = ['a'] * N

def rec(di, usedci):

    if di >= len(sset):

        print((''.join(sset)))

        return

    for i in range(usedci+1):

        sset[di] = cset[i]

        rec(di+1, usedci)

    sset[di] = cset[usedci+1]

    rec(di+1, usedci+1)

rec(1, 0)

N = int(eval(input()))
cset = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
sset = ["a"] * N

def rec(di, usedci):
    if di >= len(sset):
        print(("".join(sset)))
        return
    for i in range(usedci + 1):
        sset[di] = cset[i]
        rec(di + 1, usedci)
    sset[di] = cset[usedci + 1]
    rec(di + 1, usedci + 1)

rec(1, 0)

N = int(eval(input()))
cset = [chr(ord("a") + i) for i in range(N)]
sset = ["a"] * N

def rec(di, usedci):
    if di >= len(sset):
        print(("".join(sset)))
        return
    for i in range(usedci + 1):
        sset[di] = cset[i]
        rec(di + 1, usedci)
    sset[di] = cset[usedci + 1]
    rec(di + 1, usedci + 1)

rec(1, 0)

+cset = [chr(ord("a") + i) for i in range(N)]


Input: print(('A' + input().split()[1][0] +'C'))

a,b,c = input().split()

print('A',b[0],'C',sep='')

a, b, c = input().split()
print("A", b[0], "C", sep="")


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

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

a.sort()

mod=10**9+7

MAX_N=n+5

fac = [1,1] + [0]*MAX_N

finv = [1,1] + [0]*MAX_N

inv = [0,1] + [0]*MAX_N

for i in range(2,MAX_N):

  fac[i] = fac[i-1] * i % mod

  inv[i] = mod - inv[mod % i] * (mod // i) % mod

  finv[i] = finv[i-1] * inv[i] % mod

def nCk(n,k):

  if n<k:

    return 0

  if n<0 or k<0:

    return 0

  return fac[n] * (finv[k] * finv[n-k] % mod) % mod

max_x=0

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

  max_x+=a[i]*nCk(i,k-1)

  max_x%=mod

min_x=0

for i in range(n-k+1):

  min_x+=a[i]*nCk(n-i-1,k-1)

  min_x%=mod

print(((max_x-min_x)%mod))

from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()

a=lnii()

a.sort()

mod=10**9+7

MAX_N = n+5

fac = [1,1] + [0]*MAX_N

finv = [1,1] + [0]*MAX_N

inv = [0,1] + [0]*MAX_N

for i in range(2,MAX_N):

  fac[i] = fac[i-1] * i % mod

  inv[i] = mod - inv[mod % i] * (mod // i) % mod

  finv[i] = finv[i-1] * inv[i] % mod

def nCk(n,k):

  if n<k:

    return 0

  if n<0 or k<0:

    return 0

  return fac[n] * (finv[k] * finv[n-k] % mod) % mod

min_X=0

for i in range(n-k+1):

  min_X+=a[i]*nCk(n-i-1,k-1)

  min_X%=mod

max_X=0

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

  max_X+=a[i]*nCk(i,k-1)

  max_X%=mod

ans=max_X-min_X

ans%=mod

print(ans)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
mod = 10**9 + 7
MAX_N = n + 5
fac = [1, 1] + [0] * MAX_N
finv = [1, 1] + [0] * MAX_N
inv = [0, 1] + [0] * MAX_N
for i in range(2, MAX_N):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod

def nCk(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

max_x = 0
for i in range(k - 1, n):
    max_x += a[i] * nCk(i, k - 1)
    max_x %= mod
min_x = 0
for i in range(n - k + 1):
    min_x += a[i] * nCk(n - i - 1, k - 1)
    min_x %= mod
print(((max_x - min_x) % mod))

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
n, k = nii()
a = lnii()
a.sort()
mod = 10**9 + 7
MAX_N = n + 5
fac = [1, 1] + [0] * MAX_N
finv = [1, 1] + [0] * MAX_N
inv = [0, 1] + [0] * MAX_N
for i in range(2, MAX_N):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod

def nCk(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

min_X = 0
for i in range(n - k + 1):
    min_X += a[i] * nCk(n - i - 1, k - 1)
    min_X %= mod
max_X = 0
for i in range(k - 1, n):
    max_X += a[i] * nCk(i, k - 1)
    max_X %= mod
ans = max_X - min_X
ans %= mod
print(ans)

+nii = lambda: list(map(int, stdin.readline().split()))

+lnii = lambda: list(map(int, stdin.readline().split()))


Input:
# ABC067D - Fennec VS. Snuke (ARC078D)

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 9)

def dfs(v: int, x: int, d: "List[int]") -> None:

    d[v] = x

    for u in G[v]:

        if not d[u]:

            dfs(u, x + 1, d)

def main():

    global G, DB, DW

    N = int(eval(input()))

    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))

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

    for v, u in E:

        G[v] += [u]

        G[u] += [v]

    DB, DW = [0] * (N + 1), [0] * (N + 1)

    dfs(1, 1, DB), dfs(N, 1, DW)

    b, w = 0, 0

    for i, j in zip(DB[1:], DW[1:]):

        if i <= j:

            b += 1

        else:

            w += 1

    flg = b > w

    print(("Fennec" if flg else "Snuke"))

if __name__ == "__main__":

    main()

# ABC067D - Fennec VS. Snuke (ARC078D)

from collections import deque

def bfs(s: int, d: "List[int]") -> None:

    q = deque([s])

    while q:

        v = q.popleft()

        for u in G[v]:

            if not d[u]:

                q.append(u)

                d[u] = d[v] + 1

def main():

    global G, DB, DW

    N, *E = list(map(int, open(0).read().split()))

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

    for i in range(0, (N - 1) * 2, 2):

        v, u = E[i : i + 2]

        G[v] += [u]

        G[u] += [v]

    DB, DW = [0] * (N + 1), [0] * (N + 1)

    bfs(1, DB), bfs(N, DW)

    b, w = 0, 0

    for i, j in zip(DB[1:], DW[1:]):

        if i <= j:

            b += 1

        else:

            w += 1

    flg = b > w

    print(("Fennec" if flg else "Snuke"))

if __name__ == "__main__":

    main()

# ABC067D - Fennec VS. Snuke (ARC078D)
import sys

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

def dfs(v: int, x: int, d: "List[int]") -> None:
    d[v] = x
    for u in G[v]:
        if not d[u]:
            dfs(u, x + 1, d)

def main():
    global G, DB, DW
    N = int(eval(input()))
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    G = [[] for _ in range(N + 1)]
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    DB, DW = [0] * (N + 1), [0] * (N + 1)
    dfs(1, 1, DB), dfs(N, 1, DW)
    b, w = 0, 0
    for i, j in zip(DB[1:], DW[1:]):
        if i <= j:
            b += 1
        else:
            w += 1
    flg = b > w
    print(("Fennec" if flg else "Snuke"))

if __name__ == "__main__":
    main()

-def dfs(v: int, x: int, d: "List[int]") -> None:

+def bfs(s: int, d: "List[int]") -> None:

-    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))

+    N, *E = list(map(int, open(0).read().split()))


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

W2 = W-1

c = [0] * (W2+1)

cnt = 0

MOD = 10**9 + 7

for bit in range(1 << W2):

    s0 = bit&1

    flg=True

    for i in range(1, W2):

        if (bit>>i)&1 and s0 == 1:

            flg = False

            break

        s0 = (bit>>i)&1

    if flg:

        cnt += 1

        for i in range(W2):

            if (bit >> i)&1:

                c[i] += 1

dp = [[0]*W for _ in range(H+1)]

dp[0][0] = 1

for h in range(H):

    for i in range(W):

        if i != 0:

            dp[h+1][i-1] += dp[h][i]*c[i-1]

            dp[h+1][i-1] %= MOD

        if i != W-1:

            dp[h+1][i+1] += dp[h][i]*c[i]

            dp[h+1][i+1] %= MOD

        dp[h+1][i] += dp[h][i]*(cnt-c[i-1]-c[i])

        dp[h+1][i] %= MOD

print((dp[H][K-1]))

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

MOD, p, cnt = 10**9+7, [0]*W, 0

for bit in range(1<<(W-1)):

    s0 = bit&1

    flg=True

    for w in range(1, W-1):

        if (bit>>w)&1 and s0 == 1:flg=False; break

        s0 = (bit>>w)&1

    if flg:

        cnt += 1

        for w in range(W - 1):

            if (bit >> w)&1:p[w] += 1

dp = [[0]*W for _ in range(H+1)]

dp[0][0] = 1

for h in range(H):

    for w in range(W):

        if w:

            dp[h+1][w-1] += dp[h][w]*p[w-1]

            dp[h+1][w-1] %= MOD

        if w-(W - 1):

            dp[h+1][w+1] += dp[h][w]*p[w]

            dp[h+1][w+1] %= MOD

        dp[h+1][w]+=dp[h][w]*(cnt-p[w-1]-p[w])

        dp[h+1][w]%=MOD

print((dp[H][K-1]))

H, W, K = list(map(int, input().split()))
W2 = W - 1
c = [0] * (W2 + 1)
cnt = 0
MOD = 10**9 + 7
for bit in range(1 << W2):
    s0 = bit & 1
    flg = True
    for i in range(1, W2):
        if (bit >> i) & 1 and s0 == 1:
            flg = False
            break
        s0 = (bit >> i) & 1
    if flg:
        cnt += 1
        for i in range(W2):
            if (bit >> i) & 1:
                c[i] += 1
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for h in range(H):
    for i in range(W):
        if i != 0:
            dp[h + 1][i - 1] += dp[h][i] * c[i - 1]
            dp[h + 1][i - 1] %= MOD
        if i != W - 1:
            dp[h + 1][i + 1] += dp[h][i] * c[i]
            dp[h + 1][i + 1] %= MOD
        dp[h + 1][i] += dp[h][i] * (cnt - c[i - 1] - c[i])
        dp[h + 1][i] %= MOD
print((dp[H][K - 1]))

H, W, K = list(map(int, input().split()))
MOD, p, cnt = 10**9 + 7, [0] * W, 0
for bit in range(1 << (W - 1)):
    s0 = bit & 1
    flg = True
    for w in range(1, W - 1):
        if (bit >> w) & 1 and s0 == 1:
            flg = False
            break
        s0 = (bit >> w) & 1
    if flg:
        cnt += 1
        for w in range(W - 1):
            if (bit >> w) & 1:
                p[w] += 1
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for h in range(H):
    for w in range(W):
        if w:
            dp[h + 1][w - 1] += dp[h][w] * p[w - 1]
            dp[h + 1][w - 1] %= MOD
        if w - (W - 1):
            dp[h + 1][w + 1] += dp[h][w] * p[w]
            dp[h + 1][w + 1] %= MOD
        dp[h + 1][w] += dp[h][w] * (cnt - p[w - 1] - p[w])
        dp[h + 1][w] %= MOD
print((dp[H][K - 1]))


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

ans = 0

for x in range(K + 1):

    for y in range(K + 1):

        z = S - (x + y)

        if 0 <= z and z <= K:

            ans += 1

print(ans)

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

ans = 0

for x in range(K + 1):

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

        z = S - (x + y)

        if y <= z and z <= K:

            if x == y and y == z:

                ans += 1

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

                ans += 3

            else:

                ans += 6

print(ans)

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


Input:
from collections import deque

N = int(eval(input()))

S = [list(eval(input())) for _ in range(N)]

def bfs(i):

    d = [-1 for _ in range(N)]

    d[i] = 0

    que = deque([(i, 0, -1)])

    finished = set()

    while que:

        ci, dist, p = que.popleft()

        # print(ci, dist, p)

        for j in range(N):

            if S[ci][j] == '1':

                if j != p and d[j] >= 0:

                    if d[j] == dist or (d[j] != dist+1 and j not in finished):

                        # print(ci, j)

                        return -1

                elif d[j] == -1:

                    d[j] = dist+1

                    que.append((j, dist+1, ci))

        finished.add(ci)

    return dist+1

ans = -1

for i in range(N):

    b = bfs(i)

    ans = max(ans, b)

print(ans)

from collections import deque

N = int(eval(input()))

G = {k: [] for k in range(N)}

for i in range(N):

    S = eval(input())

    for j in range(N):

        if S[j] == '1':

            G[i].append(j)

            G[j].append(i)

def bfs(i):

    visited = [-1 for _ in range(N)]

    visited[i] = 1

    M = 1

    que = deque([(i, -1)])

    while que:

        ci, p = que.popleft()

        for ni in G[ci]:

            if ni != p:

                if visited[ni] != -1:

                    if (visited[ci]+1-visited[ni]) % 2 == 1:

                        print((-1))

                        exit()

                else:

                    que.append((ni, ci))

                    visited[ni] = visited[ci]+1

                    M = max(M, visited[ni])

    return M

ans = 0

for i in range(N):   # start node

    ans = max(ans, bfs(i))

print(ans)

from collections import deque

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

def bfs(i):
    d = [-1 for _ in range(N)]
    d[i] = 0
    que = deque([(i, 0, -1)])
    finished = set()
    while que:
        ci, dist, p = que.popleft()
        # print(ci, dist, p)
        for j in range(N):
            if S[ci][j] == "1":
                if j != p and d[j] >= 0:
                    if d[j] == dist or (d[j] != dist + 1 and j not in finished):
                        # print(ci, j)
                        return -1
                elif d[j] == -1:
                    d[j] = dist + 1
                    que.append((j, dist + 1, ci))
        finished.add(ci)
    return dist + 1

ans = -1
for i in range(N):
    b = bfs(i)
    ans = max(ans, b)
print(ans)

from collections import deque

N = int(eval(input()))
G = {k: [] for k in range(N)}
for i in range(N):
    S = eval(input())
    for j in range(N):
        if S[j] == "1":
            G[i].append(j)
            G[j].append(i)

def bfs(i):
    visited = [-1 for _ in range(N)]
    visited[i] = 1
    M = 1
    que = deque([(i, -1)])
    while que:
        ci, p = que.popleft()
        for ni in G[ci]:
            if ni != p:
                if visited[ni] != -1:
                    if (visited[ci] + 1 - visited[ni]) % 2 == 1:
                        print((-1))
                        exit()
                else:
                    que.append((ni, ci))
                    visited[ni] = visited[ci] + 1
                    M = max(M, visited[ni])
    return M

ans = 0
for i in range(N):  # start node
    ans = max(ans, bfs(i))
print(ans)

-S = [list(eval(input())) for _ in range(N)]

-                if j != p and d[j] >= 0:

-                    if d[j] == dist or (d[j] != dist + 1 and j not in finished):

-                    que.append((j, dist + 1, ci))

+                    if (visited[ci] + 1 - visited[ni]) % 2 == 1:

+                    que.append((ni, ci))

+                    visited[ni] = visited[ci] + 1

+                    M = max(M, visited[ni])


Input:
import math

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

x=max(a,b)

y=min(a,b)

p=abs(x-y)

P = 10**9 + 7

N = 1000000

inv_t = [0]+[1]

for i in range(2,N):

  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

if (x+y)%3!=0:

    print((0))

elif x>y*2:

    print((0))

else:

    n=(x+y)//3

    q=(2*x-y)//3

    r=(2*y-x)//3

    #print(math.factorial(q+r)//math.factorial(q)//math.factorial(r)%(10**9+7))

    ans=1

    qq=1

    rr=1

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

        ans*=i

        ans%=10**9+7

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

        ans*=inv_t[i]

        ans%=10**9+7

    P = 10**9 + 7

    N = r+2

    inv_t = [0]+[1]

    for i in range(2,N):

        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

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

        ans*=inv_t[i]

        ans%=10**9+7

    print(ans)

import math

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

x=max(a,b)

y=min(a,b)

p=abs(x-y)

if (x+y)%3!=0:

    print((0))

elif x>y*2:

    print((0))

else:

    n=(x+y)//3

    q=(2*x-y)//3

    r=(2*y-x)//3

    #print(math.factorial(q+r)//math.factorial(q)//math.factorial(r)%(10**9+7))

    ans=1

    qq=1

    rr=1

    P = 10**9 + 7

    N = max(q,r)+2

    inv_t = [0]+[1]

    for i in range(2,N):

        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

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

        ans*=i

        ans%=10**9+7

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

        ans*=inv_t[i]

        ans%=10**9+7

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

        ans*=inv_t[i]

        ans%=10**9+7

    print(ans)

import math

a, b = list(map(int, input().split()))
x = max(a, b)
y = min(a, b)
p = abs(x - y)
P = 10**9 + 7
N = 1000000
inv_t = [0] + [1]
for i in range(2, N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
if (x + y) % 3 != 0:
    print((0))
elif x > y * 2:
    print((0))
else:
    n = (x + y) // 3
    q = (2 * x - y) // 3
    r = (2 * y - x) // 3
    # print(math.factorial(q+r)//math.factorial(q)//math.factorial(r)%(10**9+7))
    ans = 1
    qq = 1
    rr = 1
    for i in range(1, q + r + 1):
        ans *= i
        ans %= 10**9 + 7
    for i in range(1, q + 1):
        ans *= inv_t[i]
        ans %= 10**9 + 7
    P = 10**9 + 7
    N = r + 2
    inv_t = [0] + [1]
    for i in range(2, N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
    for i in range(1, r + 1):
        ans *= inv_t[i]
        ans %= 10**9 + 7
    print(ans)

import math

a, b = list(map(int, input().split()))
x = max(a, b)
y = min(a, b)
p = abs(x - y)
if (x + y) % 3 != 0:
    print((0))
elif x > y * 2:
    print((0))
else:
    n = (x + y) // 3
    q = (2 * x - y) // 3
    r = (2 * y - x) // 3
    # print(math.factorial(q+r)//math.factorial(q)//math.factorial(r)%(10**9+7))
    ans = 1
    qq = 1
    rr = 1
    P = 10**9 + 7
    N = max(q, r) + 2
    inv_t = [0] + [1]
    for i in range(2, N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
    for i in range(1, q + r + 1):
        ans *= i
        ans %= 10**9 + 7
    for i in range(1, q + 1):
        ans *= inv_t[i]
        ans %= 10**9 + 7
    for i in range(1, r + 1):
        ans *= inv_t[i]
        ans %= 10**9 + 7
    print(ans)


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

print((a+b//2))

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

print((x+y//2))

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

x, y = list(map(int, input().split()))
print((x + y // 2))

-a, b = list(map(int, input().split()))
-print((a + b // 2))
+x, y = list(map(int, input().split()))
+print((x + y // 2))


Input:
# ABC063 D - Widespread

def check(x,hp):

    hp=[hh-(b*x) for hh in hp]

    explosion=0

    for hhh in hp:

        if hhh<=0:continue

        if hhh%(a-b)==0:

            explosion+=hhh//(a-b)

        else:

            explosion+=hhh//(a-b)+1

    return explosion<=x

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

h=[int(eval(input())) for i in range(n)]

lo=0

hi=10**9

while hi-lo>1:

    mid=(hi+lo)//2

    if check(mid,h):

        hi=mid

    else:

        lo=mid

print((lo+1))

from math import ceil

def check(x,hp):

    hp=[hh-(b*x) for hh in hp]

    cnt=0

    for p in hp:

        if p<=0:continue

        cnt+=ceil(p/(a-b))

    return cnt<=x

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

h=[int(eval(input())) for i in range(n)]

lo=0

hi=10**9

while hi-lo>1:

    mid=(hi+lo)//2

    if check(mid,h):

        hi=mid

    else:

        lo=mid

ans=hi

# htとloどちらを出力すればよい？

# print(lo)

print(hi)

# ABC063 D - Widespread
def check(x, hp):
    hp = [hh - (b * x) for hh in hp]
    explosion = 0
    for hhh in hp:
        if hhh <= 0:
            continue
        if hhh % (a - b) == 0:
            explosion += hhh // (a - b)
        else:
            explosion += hhh // (a - b) + 1
    return explosion <= x

n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
lo = 0
hi = 10**9
while hi - lo > 1:
    mid = (hi + lo) // 2
    if check(mid, h):
        hi = mid
    else:
        lo = mid
print((lo + 1))

from math import ceil

def check(x, hp):
    hp = [hh - (b * x) for hh in hp]
    cnt = 0
    for p in hp:
        if p <= 0:
            continue
        cnt += ceil(p / (a - b))
    return cnt <= x

n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
lo = 0
hi = 10**9
while hi - lo > 1:
    mid = (hi + lo) // 2
    if check(mid, h):
        hi = mid
    else:
        lo = mid
ans = hi
# htとloどちらを出力すればよい？
# print(lo)
print(hi)

-            explosion += hhh // (a - b)

-            explosion += hhh // (a - b) + 1

+# htとloどちらを出力すればよい？


Input:
def push(x, top, S):

      S.append(x)

      top = top + 1

def pop(top):

      del S[top-1]

      top = top - 1

if __name__ == "__main__":

      stdin = eval(input())

      stdin = stdin.split()

      n = len(stdin)

      S = []

      top = len(S)

      for i in range(0, n):

            if stdin[i] == '+':

                  b = S[top-1]

                  a = S[top-2]

                  pop(top)

                  S[top-1] = a + b

            elif stdin[i] == '-':

                  b = S[top-1]

                  a = S[top-2]

                  pop(top)

                  S[top-1] = a - b

            elif stdin[i] == '*':

                  b = S[top-1]

                  a = S[top-2]

                  pop(top)

                  S[top-1] = a * b

            else:

                  push(int(stdin[i]), top, S)

      print((S[top]))

def push(S, top, x):

      S.append(x)

      top = top + 1

def pop(S, top):

      t = int(S[top-1])

      del S[top-1]

      top = top -1

      return t

if __name__ == "__main__":

      top = 0

      inpt = (eval(input())).split()

      n = len(inpt)

      S = []

      for i in range(0,n):

            if inpt[i] == "+":

                  b = pop(S, top)

                  a = pop(S, top)

                  c = a + b

                  push(S, top, c)

            elif inpt[i] == "-":

                  b = pop(S, top)

                  a = pop(S, top)

                  c = a - b

                  push(S, top, c)

            elif inpt[i] == "*":

                  b = pop(S, top)

                  a = pop(S, top)

                  c = a * b

                  push(S, top, c)

            else :

                  push(S, top, int(inpt[i]))

      print((S[top-1]))

def push(x, top, S):
    S.append(x)
    top = top + 1

def pop(top):
    del S[top - 1]
    top = top - 1

if __name__ == "__main__":
    stdin = eval(input())
    stdin = stdin.split()
    n = len(stdin)
    S = []
    top = len(S)
    for i in range(0, n):
        if stdin[i] == "+":
            b = S[top - 1]
            a = S[top - 2]
            pop(top)
            S[top - 1] = a + b
        elif stdin[i] == "-":
            b = S[top - 1]
            a = S[top - 2]
            pop(top)
            S[top - 1] = a - b
        elif stdin[i] == "*":
            b = S[top - 1]
            a = S[top - 2]
            pop(top)
            S[top - 1] = a * b
        else:
            push(int(stdin[i]), top, S)
    print((S[top]))

def push(S, top, x):
    S.append(x)
    top = top + 1

def pop(S, top):
    t = int(S[top - 1])
    del S[top - 1]
    top = top - 1
    return t

if __name__ == "__main__":
    top = 0
    inpt = (eval(input())).split()
    n = len(inpt)
    S = []
    for i in range(0, n):
        if inpt[i] == "+":
            b = pop(S, top)
            a = pop(S, top)
            c = a + b
            push(S, top, c)
        elif inpt[i] == "-":
            b = pop(S, top)
            a = pop(S, top)
            c = a - b
            push(S, top, c)
        elif inpt[i] == "*":
            b = pop(S, top)
            a = pop(S, top)
            c = a * b
            push(S, top, c)
        else:
            push(S, top, int(inpt[i]))
    print((S[top - 1]))

-            push(int(stdin[i]), top, S)


Input:
class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

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

            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

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

        self.parents[y] = x

    def size(self, x):

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

    def same(self, x, y):

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

    def members(self, x):

        root = self.find(x)

        return (i for i in range(self.n) if self.find(i) == root)

    def roots(self):

        return (i for i, x in enumerate(self.parents) if x < 0)

    def group_count(self):

        return len(self.roots())

    def all_group_members(self):

        d = {}

        for i in range(self.n):

            p = self.find(i)

            d[p] = d.get(p, []) + [i]

        return d

    def __str__(self):

        return '\n'.join('{}: {}'.format(k, v) for k, v in list(self.all_group_members().items()))

def resolve():

    import sys

    input = sys.stdin.readline

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

    u = UnionFind(n)

    for _ in range(m):

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

        u.union(a - 1, b - 1)

    ans = 0

    for i in u.roots():

        ans = max(u.size(i), ans)

    print(ans)

if __name__ == '__main__':

    resolve()

class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

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

            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

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

        self.parents[y] = x

    def size(self, x):

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

    def same(self, x, y):

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

    def members(self, x):

        root = self.find(x)

        return (i for i in range(self.n) if self.find(i) == root)

    def roots(self):

        return (i for i, x in enumerate(self.parents) if x < 0)

    def group_count(self):

        return len(self.roots())

    def sizes(self):

        return {x: self.size(x) for x in self.roots()}

    def all_group_members(self):

        d = {}

        for i in range(self.n):

            p = self.find(i)

            d[p] = d.get(p, []) + [i]

        return d

    def __str__(self):

        return '\n'.join('{}: {}'.format(k, v) for k, v in list(self.all_group_members().items()))

def resolve():

    import sys

    input = sys.stdin.readline

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

    u = UnionFind(n)

    for _ in range(m):

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

        u.union(a - 1, b - 1)

    ans = 0

    for i in list(u.sizes().values()):

        ans = max(i, ans)

    print(ans)

if __name__ == '__main__':

    resolve()

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return (i for i in range(self.n) if self.find(i) == root)

    def roots(self):
        return (i for i, x in enumerate(self.parents) if x < 0)

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        d = {}
        for i in range(self.n):
            p = self.find(i)
            d[p] = d.get(p, []) + [i]
        return d

    def __str__(self):
        return "\n".join(
            "{}: {}".format(k, v) for k, v in list(self.all_group_members().items())
        )

def resolve():
    import sys

    input = sys.stdin.readline
    n, m = list(map(int, input().split()))
    u = UnionFind(n)
    for _ in range(m):
        a, b = list(map(int, input().split()))
        u.union(a - 1, b - 1)
    ans = 0
    for i in u.roots():
        ans = max(u.size(i), ans)
    print(ans)

if __name__ == "__main__":
    resolve()

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return (i for i in range(self.n) if self.find(i) == root)

    def roots(self):
        return (i for i, x in enumerate(self.parents) if x < 0)

    def group_count(self):
        return len(self.roots())

    def sizes(self):
        return {x: self.size(x) for x in self.roots()}

    def all_group_members(self):
        d = {}
        for i in range(self.n):
            p = self.find(i)
            d[p] = d.get(p, []) + [i]
        return d

    def __str__(self):
        return "\n".join(
            "{}: {}".format(k, v) for k, v in list(self.all_group_members().items())
        )

def resolve():
    import sys

    input = sys.stdin.readline
    n, m = list(map(int, input().split()))
    u = UnionFind(n)
    for _ in range(m):
        a, b = list(map(int, input().split()))
        u.union(a - 1, b - 1)
    ans = 0
    for i in list(u.sizes().values()):
        ans = max(i, ans)
    print(ans)

if __name__ == "__main__":
    resolve()

+        return {x: self.size(x) for x in self.roots()}


Input:
# C

import math

n = int(eval(input()))

a = []

for i in range(5):

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

ans = math.ceil((n/min(a) + 5) - 1)

print(ans)

from math import ceil

n = int(eval(input()))

a = []

for i in range(5):

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

ans = ceil(n / min(a)) + 4

print(ans)

# C
import math

n = int(eval(input()))
a = []
for i in range(5):
    a.append(int(eval(input())))
ans = math.ceil((n / min(a) + 5) - 1)
print(ans)

-# C
-import math
+from math import ceil
-ans = math.ceil((n / min(a) + 5) - 1)
+ans = ceil(n / min(a)) + 4


Input:
def gcd(a, b):

    while b != 0 :

        t = a % b

        a = b

        b = t

    return a

sum = 0

N=int(eval(input("")))

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

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

        x = gcd(a, b)

        if x == 1:

            sum = sum + N

        elif x == 2:

            sum = sum + (N + 1) // 2 + N // 2 * 2

        else:

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

                sum = sum + gcd(x, c)

print(sum)

def gcd(a, b):

    while b != 0 :

        t = a % b

        a = b

        b = t

    return a

sum = 0

N=int(eval(input("")))

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

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

        x = gcd(a, b)

        if x == 1:

            sum = sum + N

        elif x == 2:

            sum = sum + (N + 1) // 2 + N // 2 * 2

        elif x == 3:

            sum = sum + N // 3 * 3 + (N - N // 3)

        else:

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

                sum = sum + gcd(x, c)

print(sum)

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

sum = 0
N = int(eval(input("")))
for a in range(1, N + 1):
    for b in range(1, N + 1):
        x = gcd(a, b)
        if x == 1:
            sum = sum + N
        elif x == 2:
            sum = sum + (N + 1) // 2 + N // 2 * 2
        else:
            for c in range(1, N + 1):
                sum = sum + gcd(x, c)
print(sum)

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

sum = 0
N = int(eval(input("")))
for a in range(1, N + 1):
    for b in range(1, N + 1):
        x = gcd(a, b)
        if x == 1:
            sum = sum + N
        elif x == 2:
            sum = sum + (N + 1) // 2 + N // 2 * 2
        elif x == 3:
            sum = sum + N // 3 * 3 + (N - N // 3)
        else:
            for c in range(1, N + 1):
                sum = sum + gcd(x, c)
print(sum)


Input:
import math

class FenwickTree:

    def __init__(self, a_list, f, default):

        # 0-indexed

        self.N = len(a_list)

        self.bit = a_list[:]

        self.f = f

        self.default = default

        for _ in range(self.N, 1 << (math.ceil(math.log(self.N, 2)))):

            self.bit.append(self.default)

        for i in range(self.N - 1):

            self.bit[i | (i + 1)] = self.f(self.bit[i | (i + 1)], self.bit[i])

    def update(self, i, val):

        while i < self.N:

            self.bit[i] = self.f(self.bit[i], val)

            i |= i + 1

    def query(self, n):

        # [0, n]

        ret = 0

        while n >= 0:

            ret = self.f(ret, self.bit[n])

            n = (n & (n + 1)) - 1

        return ret

N = int(eval(input()))

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

dp = FenwickTree([0] * N, lambda x, y: max(x, y), 0)

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

    dp.update(i, dp.query(i) + x)

print((N * (N + 1) // 2 - dp.query(N - 1)))

import math

import sys

if sys.version[0] == '2':

    range, input = xrange, raw_input

class FenwickTree:

    def __init__(self, a_list, f, default):

        # 0-indexed

        self.N = len(a_list)

        self.bit = a_list[:]

        self.f = f

        self.default = default

        for _ in range(self.N, 1 << int(math.ceil(math.log(self.N, 2)))):

            self.bit.append(self.default)

        for i in range(self.N - 1):

            self.bit[i | (i + 1)] = self.f(self.bit[i | (i + 1)], self.bit[i])

    def update(self, i, val):

        while i < self.N:

            self.bit[i] = self.f(self.bit[i], val)

            i |= i + 1

    def query(self, n):

        # [0, n]

        ret = 0

        while n >= 0:

            ret = self.f(ret, self.bit[n])

            n = (n & (n + 1)) - 1

        return ret

N = int(eval(input()))

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

dp = FenwickTree([0] * N, lambda x, y: max(x, y), 0)

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

    dp.update(i, dp.query(i) + x)

print((N * (N + 1) // 2 - dp.query(N - 1)))

import math
import sys

if sys.version[0] == "2":
    range, input = xrange, raw_input

class FenwickTree:
    def __init__(self, a_list, f, default):
        # 0-indexed
        self.N = len(a_list)
        self.bit = a_list[:]
        self.f = f
        self.default = default
        for _ in range(self.N, 1 << int(math.ceil(math.log(self.N, 2)))):
            self.bit.append(self.default)
        for i in range(self.N - 1):
            self.bit[i | (i + 1)] = self.f(self.bit[i | (i + 1)], self.bit[i])

    def update(self, i, val):
        while i < self.N:
            self.bit[i] = self.f(self.bit[i], val)
            i |= i + 1

    def query(self, n):
        # [0, n]
        ret = 0
        while n >= 0:
            ret = self.f(ret, self.bit[n])
            n = (n & (n + 1)) - 1
        return ret

N = int(eval(input()))
X = [int(x) for x in input().split()]
dp = FenwickTree([0] * N, lambda x, y: max(x, y), 0)
for x, i in sorted((x, i) for i, x in enumerate(X)):
    dp.update(i, dp.query(i) + x)
print((N * (N + 1) // 2 - dp.query(N - 1)))

-        for _ in range(self.N, 1 << (math.ceil(math.log(self.N, 2)))):

+        for _ in range(self.N, 1 << int(math.ceil(math.log(self.N, 2)))):


Input:
from collections import deque

MOD = 10**9 + 7

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

G = [eval(input()) for _ in range(H)]

def main():

    dist = [[-1] * W for _ in range(H)]

    dist[0][0] = 0

    dp = [[0] * W for _ in range(H)]

    for i in range(H):

        if G[i][0] == '#':

            break

        dp[i][0] = 1

    for i in range(W):

        if G[0][i] == '#':

            break

        dp[0][i] = 1

    que = deque([(0, 0)])

    while que:

        h, w = que.popleft()

        for dh, dw in ((1, 0), (0, 1)):

            nh = h + dh

            nw = w + dw

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

                continue

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

                continue

            if dist[nh][nw] != -1:

                continue

            if nh > 0 and nw > 0:

                dp[nh][nw] = (dp[nh - 1][nw] + dp[nh][nw - 1]) % MOD

            dist[nh][nw] = dist[h][w] + 1

            que.append((nh, nw))

    print((dp[H - 1][W - 1]))

if __name__ == "__main__":

    main()

from collections import deque

MOD = 10**9 + 7

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

G = [eval(input()) for _ in range(H)]

def main():

    dp = [[0] * W for _ in range(H)]

    for i in range(H):

        if G[i][0] == '#':

            break

        dp[i][0] = 1

    for i in range(W):

        if G[0][i] == '#':

            break

        dp[0][i] = 1

    que = deque([(0, 0)])

    while que:

        h, w = que.popleft()

        for dh, dw in ((1, 0), (0, 1)):

            nh = h + dh

            nw = w + dw

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

                continue

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

                continue

            if nh > 0 and nw > 0:

                if dp[nh][nw]:

                    continue

                dp[nh][nw] = (dp[nh - 1][nw] + dp[nh][nw - 1]) % MOD

            que.append((nh, nw))

    print((dp[H - 1][W - 1]))

if __name__ == "__main__":

    main()

from collections import deque

MOD = 10**9 + 7
H, W = list(map(int, input().split()))
G = [eval(input()) for _ in range(H)]

def main():
    dist = [[-1] * W for _ in range(H)]
    dist[0][0] = 0
    dp = [[0] * W for _ in range(H)]
    for i in range(H):
        if G[i][0] == "#":
            break
        dp[i][0] = 1
    for i in range(W):
        if G[0][i] == "#":
            break
        dp[0][i] = 1
    que = deque([(0, 0)])
    while que:
        h, w = que.popleft()
        for dh, dw in ((1, 0), (0, 1)):
            nh = h + dh
            nw = w + dw
            if nh < 0 or nw < 0 or nh >= H or nw >= W:
                continue
            if G[nh][nw] == "#":
                continue
            if dist[nh][nw] != -1:
                continue
            if nh > 0 and nw > 0:
                dp[nh][nw] = (dp[nh - 1][nw] + dp[nh][nw - 1]) % MOD
            dist[nh][nw] = dist[h][w] + 1
            que.append((nh, nw))
    print((dp[H - 1][W - 1]))

if __name__ == "__main__":
    main()

from collections import deque

MOD = 10**9 + 7
H, W = list(map(int, input().split()))
G = [eval(input()) for _ in range(H)]

def main():
    dp = [[0] * W for _ in range(H)]
    for i in range(H):
        if G[i][0] == "#":
            break
        dp[i][0] = 1
    for i in range(W):
        if G[0][i] == "#":
            break
        dp[0][i] = 1
    que = deque([(0, 0)])
    while que:
        h, w = que.popleft()
        for dh, dw in ((1, 0), (0, 1)):
            nh = h + dh
            nw = w + dw
            if nh < 0 or nw < 0 or nh >= H or nw >= W:
                continue
            if G[nh][nw] == "#":
                continue
            if nh > 0 and nw > 0:
                if dp[nh][nw]:
                    continue
                dp[nh][nw] = (dp[nh - 1][nw] + dp[nh][nw - 1]) % MOD
            que.append((nh, nw))
    print((dp[H - 1][W - 1]))

if __name__ == "__main__":
    main()

-    dist = [[-1] * W for _ in range(H)]

-            dist[nh][nw] = dist[h][w] + 1


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

XYU=[tuple(input().split()) for _ in range(N)]

U=[]

R=[]

D=[]

L=[]

for x,y,u in XYU:

 x,y = int(x),int(y)

 if u=="U":

  U.append((x,y))

 elif u=="D":

  D.append((x,y))

 elif u=="L":

  L.append((x,y))

 else:

  R.append((x,y))

ans=[10**9]

def z(A):

 A.sort()

 n=p=-10**9

 for k,c,a in A:

  if k!=n:

   if a==1:

    n=k

    p=c

   continue

  if a==1:

   p=c

   continue

  if (c-p)*5<ans[0]:

   ans[0]=(c-p)*5

z([(x,y,1) for x,y in U]+[(x,y,-1) for x,y in D])

z([(y,x,1) for x,y in R]+[(y,x,-1) for x,y in L])

z([(x+y,x-y,1) for x,y in R]+[(x+y,x-y,-1) for x,y in U])

z([(x+y,x-y,1) for x,y in D]+[(x+y,x-y,-1) for x,y in L])

z([(x-y,x+y,1) for x,y in U]+[(x-y,x+y,-1) for x,y in L])

z([(x-y,x+y,1) for x,y in R]+[(x-y,x+y,-1) for x,y in D])

print(("SAFE" if ans[0]>=10**9 else ans[0]))

N=int(eval(input()))

XYU=[tuple(input().split()) for _ in range(N)]

U=[]

R=[]

D=[]

L=[]

for x,y,u in XYU:

 x,y = int(x),int(y)

 if u=="U":

  U.append((x,y))

 elif u=="D":

  D.append((x,y))

 elif u=="L":

  L.append((x,y))

 else:

  R.append((x,y))

ans=10**9

def z(A):

 global ans

 A.sort()

 n=p=-10**9

 for k,c,a in A:

  if k!=n:

   if a==1:

    n=k

    p=c

   continue

  if a==1:

   p=c

   continue

  if (c-p)*5<ans:

   ans=(c-p)*5

z([(x,y,1) for x,y in U]+[(x,y,-1) for x,y in D])

z([(y,x,1) for x,y in R]+[(y,x,-1) for x,y in L])

z([(x+y,x-y,1) for x,y in R]+[(x+y,x-y,-1) for x,y in U])

z([(x+y,x-y,1) for x,y in D]+[(x+y,x-y,-1) for x,y in L])

z([(x-y,x+y,1) for x,y in U]+[(x-y,x+y,-1) for x,y in L])

z([(x-y,x+y,1) for x,y in R]+[(x-y,x+y,-1) for x,y in D])

print(("SAFE" if ans>=10**9 else ans))

N = int(eval(input()))
XYU = [tuple(input().split()) for _ in range(N)]
U = []
R = []
D = []
L = []
for x, y, u in XYU:
    x, y = int(x), int(y)
    if u == "U":
        U.append((x, y))
    elif u == "D":
        D.append((x, y))
    elif u == "L":
        L.append((x, y))
    else:
        R.append((x, y))
ans = [10**9]

def z(A):
    A.sort()
    n = p = -(10**9)
    for k, c, a in A:
        if k != n:
            if a == 1:
                n = k
                p = c
            continue
        if a == 1:
            p = c
            continue
        if (c - p) * 5 < ans[0]:
            ans[0] = (c - p) * 5

z([(x, y, 1) for x, y in U] + [(x, y, -1) for x, y in D])
z([(y, x, 1) for x, y in R] + [(y, x, -1) for x, y in L])
z([(x + y, x - y, 1) for x, y in R] + [(x + y, x - y, -1) for x, y in U])
z([(x + y, x - y, 1) for x, y in D] + [(x + y, x - y, -1) for x, y in L])
z([(x - y, x + y, 1) for x, y in U] + [(x - y, x + y, -1) for x, y in L])
z([(x - y, x + y, 1) for x, y in R] + [(x - y, x + y, -1) for x, y in D])
print(("SAFE" if ans[0] >= 10**9 else ans[0]))

N = int(eval(input()))
XYU = [tuple(input().split()) for _ in range(N)]
U = []
R = []
D = []
L = []
for x, y, u in XYU:
    x, y = int(x), int(y)
    if u == "U":
        U.append((x, y))
    elif u == "D":
        D.append((x, y))
    elif u == "L":
        L.append((x, y))
    else:
        R.append((x, y))
ans = 10**9

def z(A):
    global ans
    A.sort()
    n = p = -(10**9)
    for k, c, a in A:
        if k != n:
            if a == 1:
                n = k
                p = c
            continue
        if a == 1:
            p = c
            continue
        if (c - p) * 5 < ans:
            ans = (c - p) * 5

z([(x, y, 1) for x, y in U] + [(x, y, -1) for x, y in D])
z([(y, x, 1) for x, y in R] + [(y, x, -1) for x, y in L])
z([(x + y, x - y, 1) for x, y in R] + [(x + y, x - y, -1) for x, y in U])
z([(x + y, x - y, 1) for x, y in D] + [(x + y, x - y, -1) for x, y in L])
z([(x - y, x + y, 1) for x, y in U] + [(x - y, x + y, -1) for x, y in L])
z([(x - y, x + y, 1) for x, y in R] + [(x - y, x + y, -1) for x, y in D])
print(("SAFE" if ans >= 10**9 else ans))

-print(("SAFE" if ans[0] >= 10**9 else ans[0]))

+print(("SAFE" if ans >= 10**9 else ans))


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

ans= min(A+B,2*C)*min(X,Y)

if X>Y:

  ans+=min(A,2*C)*(X-Y)

else:

  ans+=min(B,2*C)*(Y-X)

print(ans)

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

ans=a*x+b*y

ans=min(ans,c*x*2 +max(0,y-x)*b,c*y*2+max(0,x-y)*a)

print(ans)

A, B, C, X, Y = list(map(int, input().split()))
ans = min(A + B, 2 * C) * min(X, Y)
if X > Y:
    ans += min(A, 2 * C) * (X - Y)
else:
    ans += min(B, 2 * C) * (Y - X)
print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans = a * x + b * y
ans = min(ans, c * x * 2 + max(0, y - x) * b, c * y * 2 + max(0, x - y) * a)
print(ans)

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

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


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

cnt = 0

for i in range(0,k+1):

    for j in  range(0,k+1):

        if s-i-j <= k and 0 <= s-i-j:

            cnt += 1

print(cnt)

k,s = list(map(int,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)

k, s = list(map(int, input().split()))
cnt = 0
for i in range(0, k + 1):
    for j in range(0, k + 1):
        if s - i - j <= k and 0 <= s - i - j:
            cnt += 1
print(cnt)

k, s = list(map(int, 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)

-        if s - i - j <= k and 0 <= s - i - j:


Input:
# test

class fenwick_tree:

  def __init__(s, n):

    s._n = n

    s.data = [0] * n

  def add(s, p, x):

    p += 1

    while p <= s._n:

      s.data[p - 1] += x

      p += p & -p

  def sumlr(s, l, r):

    return s.sum(r) - s.sum(l)

  def sum(self, r):

    s = 0

    while r > 0:

      s += self.data[r - 1]

      r -= r & -r

    return s

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

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

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

bit = fenwick_tree(N)

for i in range(N):

  bit.add(i, a[i])

for q in Query:

  if q[0] == 0:

    _, p, x = q

    bit.add(p, x)

  else:

    _, l, r = q

    print((bit.sumlr(l, r)))

class BIT:

  def __init__(s, n):

    s._n = n

    s.data = [0] * n

  def add(s, p, x):

    p += 1

    while p <= s._n:

      s.data[p - 1] += x

      p += p & -p

  def sum(s, l, r):

    return s.zum(r) - s.zum(l)

  def zum(s, r):

    ans = 0

    while r > 0:

      ans += s.data[r - 1]

      r -= r & -r

    return ans

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

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

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

bit = BIT(N)

for i in range(N):

  bit.add(i, a[i])

for q in Query:

  if q[0] == 0:

    _, p, x = q

    bit.add(p, x)

  else:

    _, l, r = q

    print((bit.sum(l, r)))

-# test
-class fenwick_tree:
+class BIT:
-    def sumlr(s, l, r):
-        return s.sum(r) - s.sum(l)
+    def sum(s, l, r):
+        return s.zum(r) - s.zum(l)
-    def sum(self, r):
-        s = 0
+    def zum(s, r):
+        ans = 0
-            s += self.data[r - 1]
+            ans += s.data[r - 1]
-        return s
+        return ans
-bit = fenwick_tree(N)
+bit = BIT(N)
-        print((bit.sumlr(l, r)))
+        print((bit.sum(l, r)))


Input:
import sys

N=int(eval(input()))

a=[[] for i in range(N)]

for i in range(N):

    a[i]=eval(input())

for i in range(N):

    if i>0:

        if a[i-1][len(a[i-1])-1]!=a[i][0]:

            print("No")

            sys.exit()

for i in range(N):

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

        if a[i] == a[N-j]:

                print("No")

                sys.exit()

print("Yes")

#!/usr/bin/python

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

n = int(input())

s = []

for _ in range(n):

    s.append(input())

ss = set()

last = None

ret = 'Yes'

for w in s:

    if w in ss:

        ret = 'No'

        break

    if last is None:

        ss.add(w)

        last = w

        continue

    if last[-1] != w[0]:

        ret = 'No'

        break

    ss.add(w)

    last = w

print(ret)

import sys

N = int(eval(input()))
a = [[] for i in range(N)]
for i in range(N):
    a[i] = eval(input())
for i in range(N):
    if i > 0:
        if a[i - 1][len(a[i - 1]) - 1] != a[i][0]:
            print("No")
            sys.exit()
for i in range(N):
    for j in range(1, N - i - 1):
        if a[i] == a[N - j]:
            print("No")
            sys.exit()
print("Yes")

#!/usr/bin/python
# -*- coding: utf-8 -*-
n = int(input())
s = []
for _ in range(n):
    s.append(input())
ss = set()
last = None
ret = "Yes"
for w in s:
    if w in ss:
        ret = "No"
        break
    if last is None:
        ss.add(w)
        last = w
        continue
    if last[-1] != w[0]:
        ret = "No"
        break
    ss.add(w)
    last = w
print(ret)


Input:
def f(n,k):

  if k<1: return 1

  if n<10:

    if k<2: return n

    return 0

  d,m=n//10,n%10

  return f(d,k-1)*m+f(d-1,k-1)*(9-m)+f(d,k)

print((f(int(eval(input())),int(eval(input())))))

s=eval(input())

n=len(s)

K=int(eval(input()))

dp=[[[0,0] for _ in range(K+1)] for _ in range(n+1)]

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

r=range

for i in r(n):

  nd=int(s[i])

  for j in r(K+1):

    for k in r(2):

      for d in r(10):

        ni,nj,nk=i+1,j,k

        if d: nj+=1

        if nj>K: continue

        if k<1:

          if d>nd: continue

          if d<nd: nk=1

        dp[ni][nj][nk]+=dp[i][j][k]

print((dp[n][K][0]+dp[n][K][1]))

def f(n, k):
    if k < 1:
        return 1
    if n < 10:
        if k < 2:
            return n
        return 0
    d, m = n // 10, n % 10
    return f(d, k - 1) * m + f(d - 1, k - 1) * (9 - m) + f(d, k)

print((f(int(eval(input())), int(eval(input())))))

s = eval(input())
n = len(s)
K = int(eval(input()))
dp = [[[0, 0] for _ in range(K + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1
r = range
for i in r(n):
    nd = int(s[i])
    for j in r(K + 1):
        for k in r(2):
            for d in r(10):
                ni, nj, nk = i + 1, j, k
                if d:
                    nj += 1
                if nj > K:
                    continue
                if k < 1:
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1
                dp[ni][nj][nk] += dp[i][j][k]
print((dp[n][K][0] + dp[n][K][1]))

+dp = [[[0, 0] for _ in range(K + 1)] for _ in range(n + 1)]

+                ni, nj, nk = i + 1, j, k


Input:
from fractions import gcd

def solve():

    A,B,C,D,E,F = list(map(int, input().split()))

    ans = {"w":A*100, "s":0}

    def density(water, sugar):

        return 100*sugar/(water+sugar)

    G = gcd(C,D)

    for a in range(31):

        for b in range(31):

            water = (a*A+b*B)*100

            if water>F:

                continue

            max_sugar = min((a*A+b*B)*E, F-water)

            sugar = int(G*(max_sugar//G))

            if sugar<min(C,D): continue

            if water+sugar==0:

                continue

            if density(water, sugar)>density(ans["w"], ans["s"]):

                ans["w"] = water

                ans["s"] = sugar

                #print(water, sugar)

    print((ans["w"]+ans["s"], ans["s"]))

if __name__ == '__main__':

    solve()

A,B,C,D,E,F = list(map(int, input().split()))

ans = {"w":A*100, "s":0}

def density(water, sugar):

    return 100*sugar/(water+sugar)

for a in range(31):

    for b in range(31):

        water = (a*A+b*B)*100

        if water>F:

            continue

        max_sugar = min((a*A+b*B)*E, F-water)

        for c in range(max_sugar//C+1):

            sugar = c*C

            sugar += ((max_sugar-sugar)//D)*D

            if water+sugar==0:

                continue

            if density(water, sugar)>density(ans["w"], ans["s"]):

                ans["w"] = water

                ans["s"] = sugar

print((ans["w"]+ans["s"], ans["s"]))

from fractions import gcd

def solve():
    A, B, C, D, E, F = list(map(int, input().split()))
    ans = {"w": A * 100, "s": 0}

    def density(water, sugar):
        return 100 * sugar / (water + sugar)

    G = gcd(C, D)
    for a in range(31):
        for b in range(31):
            water = (a * A + b * B) * 100
            if water > F:
                continue
            max_sugar = min((a * A + b * B) * E, F - water)
            sugar = int(G * (max_sugar // G))
            if sugar < min(C, D):
                continue
            if water + sugar == 0:
                continue
            if density(water, sugar) > density(ans["w"], ans["s"]):
                ans["w"] = water
                ans["s"] = sugar
                # print(water, sugar)
    print((ans["w"] + ans["s"], ans["s"]))

if __name__ == "__main__":
    solve()

A, B, C, D, E, F = list(map(int, input().split()))
ans = {"w": A * 100, "s": 0}

def density(water, sugar):
    return 100 * sugar / (water + sugar)

for a in range(31):
    for b in range(31):
        water = (a * A + b * B) * 100
        if water > F:
            continue
        max_sugar = min((a * A + b * B) * E, F - water)
        for c in range(max_sugar // C + 1):
            sugar = c * C
            sugar += ((max_sugar - sugar) // D) * D
            if water + sugar == 0:
                continue
            if density(water, sugar) > density(ans["w"], ans["s"]):
                ans["w"] = water
                ans["s"] = sugar
print((ans["w"] + ans["s"], ans["s"]))

+A, B, C, D, E, F = list(map(int, input().split()))

-    A, B, C, D, E, F = list(map(int, input().split()))

+    return 100 * sugar / (water + sugar)

-        return 100 * sugar / (water + sugar)

-            max_sugar = min((a * A + b * B) * E, F - water)

-            sugar = int(G * (max_sugar // G))

+        max_sugar = min((a * A + b * B) * E, F - water)

+        for c in range(max_sugar // C + 1):

+            sugar += ((max_sugar - sugar) // D) * D


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

A={}

for i in range(n):

  s=str(sorted(eval(input())))

  if s in list(A.keys()):

    A[s]+=1

  else:

    A[s]=1

ans=0

for i in list(A.values()):

  ans+=int(i*(i-1)/2)

print(ans)

def resolve():

    n=int(eval(input()))

    s={}

    for i in range(n):

        x=str(sorted(list(eval(input()))))

        if x in list(s.keys()):

            s[x]+=1

        else:

            s[x]=1

    ans=0

    if s:

        for i in list(s.values()):

            ans+=i*(i-1)//2

    print(ans)

if __name__ == '__main__':

    resolve()

n = int(eval(input()))
A = {}
for i in range(n):
    s = str(sorted(eval(input())))
    if s in list(A.keys()):
        A[s] += 1
    else:
        A[s] = 1
ans = 0
for i in list(A.values()):
    ans += int(i * (i - 1) / 2)
print(ans)

def resolve():
    n = int(eval(input()))
    s = {}
    for i in range(n):
        x = str(sorted(list(eval(input()))))
        if x in list(s.keys()):
            s[x] += 1
        else:
            s[x] = 1
    ans = 0
    if s:
        for i in list(s.values()):
            ans += i * (i - 1) // 2
    print(ans)

if __name__ == "__main__":
    resolve()

+        x = str(sorted(list(eval(input()))))


Input:
x = input().split()

A = []

for i in x:

    try:

        A.append(int(i))

    except:

        b = A.pop()

        a = A.pop()

        if i == '+':

            A.append(a + b)

        if i == '-':

            A.append(a - b)

        if i == '*':

            A.append(a * b)

print((A.pop()))

inList = input().split()

stack = []

for i in inList:

    if i in ['+', '-', '*']:

        b, a = stack.pop(), stack.pop()

        if i == '+':

            stack.append(b + a)

        if i == '-':

            stack.append(a - b)

        if i == '*':

            stack.append(b * a)

    else:

        stack.append(int(i))

print((stack.pop()))

x = input().split()
A = []
for i in x:
    try:
        A.append(int(i))
    except:
        b = A.pop()
        a = A.pop()
        if i == "+":
            A.append(a + b)
        if i == "-":
            A.append(a - b)
        if i == "*":
            A.append(a * b)
print((A.pop()))

inList = input().split()
stack = []
for i in inList:
    if i in ["+", "-", "*"]:
        b, a = stack.pop(), stack.pop()
        if i == "+":
            stack.append(b + a)
        if i == "-":
            stack.append(a - b)
        if i == "*":
            stack.append(b * a)
    else:
        stack.append(int(i))
print((stack.pop()))

+        b, a = stack.pop(), stack.pop()


Input:
def main():

    x = eval(input())

    x1, x2, x3 = x.split(' ')

    a = int(x1)

    b = int(x2)

    c = int(x3)

    z = [a, b, c]

    z.sort()

    print((z[0],z[1],z[2]))

if __name__ == "__main__":

    main()

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

a, b, c = sorted(three_numbers)

print((a, b, c))

def main():
    x = eval(input())
    x1, x2, x3 = x.split(" ")
    a = int(x1)
    b = int(x2)
    c = int(x3)
    z = [a, b, c]
    z.sort()
    print((z[0], z[1], z[2]))

if __name__ == "__main__":
    main()

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


Input:
import collections

N = int(eval(input()))

Y = list(eval(input()))

X = []

ans = 0

for n in range(N):

    X.append(Y.pop(0))

    X_and_Y = set(X) & set(Y)

    ans = max(ans,len(X_and_Y))

print(ans)

N = int(eval(input()))

S = eval(input())

ans = 0

for i in range(N):

    a = S[:i+1]

    b = S[i+1:]

    c = 0

    for j in range(26):

        if chr(j+97) in a and chr(j+97) in b:

            c += 1

    ans = max(ans,c)

print(ans)

import collections

N = int(eval(input()))
Y = list(eval(input()))
X = []
ans = 0
for n in range(N):
    X.append(Y.pop(0))
    X_and_Y = set(X) & set(Y)
    ans = max(ans, len(X_and_Y))
print(ans)

N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(N):
    a = S[: i + 1]
    b = S[i + 1 :]
    c = 0
    for j in range(26):
        if chr(j + 97) in a and chr(j + 97) in b:
            c += 1
    ans = max(ans, c)
print(ans)

+        if chr(j + 97) in a and chr(j + 97) in b:


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

for i in range(10):

  temp = r*x - d

  print(temp)

  x = temp

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

for i in range(10):x=r*x-d;print(x)

r, d, x = list(map(int, input().split()))
for i in range(10):
    temp = r * x - d
    print(temp)
    x = temp

r, d, x = list(map(int, input().split()))
for i in range(10):
    x = r * x - d
    print(x)

-    temp = r * x - d
-    print(temp)
-    x = temp
+    x = r * x - d
+    print(x)


Input:
def inpl():

    return input().split()

n = int(eval(input()))

a = list(map(int, inpl()))

d = {}

for i in range(n):

    d[a[i]] = d.get(a[i], 0) + 1

ans = 0

for k in list(d.keys()):

    b = 0

    b += d.get(k - 1, 0)

    b += d.get(k, 0)

    b += d.get(k + 1, 0)

    ans = max(ans, b)

print(ans)

def main():

    from collections import deque

    N = int(eval(input()))

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

    b = [0] * (10 ** 5 + 10)

    for x in a:

        b[x] += 1

    dq = deque()

    b_iter = iter(b)

    dq.append(next(b_iter))

    dq.append(next(b_iter))

    dq.append(next(b_iter))

    t = sum(dq)

    ans = t

    for x in b:

        dq.append(x)

        y = dq.popleft()

        t = t + x - y

        if ans < t:

            ans = t

    print(ans)

if __name__ == '__main__':

    main()

def main():
    from collections import deque

    N = int(eval(input()))
    (*a,) = list(map(int, input().split()))
    b = [0] * (10**5 + 10)
    for x in a:
        b[x] += 1
    dq = deque()
    b_iter = iter(b)
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    t = sum(dq)
    ans = t
    for x in b:
        dq.append(x)
        y = dq.popleft()
        t = t + x - y
        if ans < t:
            ans = t
    print(ans)

if __name__ == "__main__":
    main()

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


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

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

cnt = 0

tot = A[0]

while cnt<N and tot<=x:

    cnt += 1

    if cnt<N:

        tot += A[cnt]

if cnt==N and tot<x:

    cnt -= 1

print(cnt)

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

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

if x>=2*sum(A):

    print((0))

else:

    ind = N

    for i in range(N):

        x -= A[i]

        if x<0:

            ind = i

            break

    if ind==N and x>0:

        A = sorted(A,reverse=True)

        for i in range(N):

            x -= A[i]

            if x<0:

                ind -= 1

                break

    print(ind)

N, x = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
cnt = 0
tot = A[0]
while cnt < N and tot <= x:
    cnt += 1
    if cnt < N:
        tot += A[cnt]
if cnt == N and tot < x:
    cnt -= 1
print(cnt)

N, x = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
if x >= 2 * sum(A):
    print((0))
else:
    ind = N
    for i in range(N):
        x -= A[i]
        if x < 0:
            ind = i
            break
    if ind == N and x > 0:
        A = sorted(A, reverse=True)
        for i in range(N):
            x -= A[i]
            if x < 0:
                ind -= 1
                break
    print(ind)

-cnt = 0
-tot = A[0]
-while cnt < N and tot <= x:
-    cnt += 1
-    if cnt < N:
-        tot += A[cnt]
-if cnt == N and tot < x:
-    cnt -= 1
-print(cnt)
+if x >= 2 * sum(A):
+    print((0))
+else:
+    ind = N
+    for i in range(N):
+        x -= A[i]
+        if x < 0:
+            ind = i
+            break
+    if ind == N and x > 0:
+        A = sorted(A, reverse=True)
+        for i in range(N):
+            x -= A[i]
+            if x < 0:
+                ind -= 1
+                break
+    print(ind)


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

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

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

S=[0 for i in range(n)]

S1=[0 for i in range(n)]

S2=[0 for i in range(n)]

vel=[0 for i in range(n)]

dt=[0 for i in range(n)]

v0=[0 for i in range(n)]

ve=[0 for i in range(n)]

ok=0

for i in range(n):

    if n ==1:

        dt[0]=t[0]

    elif i==n-1:

        v0[i]=ve[i-1]

        ve[i]=0

        dt[i]=t[i]

    else:

        v0[i]=ve[i-1]

        dt[i]=t[i]

        ve[i]=min(v[i+1],v[i],v0[i]+dt[i])

#print(dt)

#print(v0)

#print(ve)

while ok==0:

    for i in range(n-1):

#        if  abs((ve[i]-ve[i+1])/dt[i+1]) >1:

        if  abs((ve[i+1]-v0[i+1])/dt[i+1]) >1:

                ve[i]=ve[i]-1

                v0[i+1]=v0[i+1]-1

#                v0[i]=v0[i]-1

#                print("dt",dt)

#                print("v0",v0)

#                print("ve",ve)

                break

    else:

        ok=1

#print(dt)

#print(v0)

#print(ve)

for i in range(n):

    ttt=0.5*(ve[i]+dt[i]-v0[i])

    vvv=ttt+v0[i]

    if vvv-v[i]>=0:

        S[i]=0.5*(v0[i]+vvv)*ttt + 0.5*(ve[i]+vvv)*(dt[i]-ttt) - (ttt-v[i]+v0[i])*(vvv-v[i])

        S1[i]=0.5*(v0[i]+vvv)*ttt + 0.5*(ve[i]+vvv)*(dt[i]-ttt)

        S2[i]=(ttt-v[i]+v0[i])*(vvv-v[i])

    else:

        S[i]=0.5*(v0[i]+vvv)*ttt + 0.5*(ve[i]+vvv)*(dt[i]-ttt)

        S1[i]=0.5*(v0[i]+vvv)*ttt + 0.5*(ve[i]+vvv)*(dt[i]-ttt)

        S2[i]=0

print((sum(S)))

n = int(eval(input()))
t = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
S = [0 for i in range(n)]
S1 = [0 for i in range(n)]
S2 = [0 for i in range(n)]
vel = [0 for i in range(n)]
dt = [0 for i in range(n)]
v0 = [0 for i in range(n)]
ve = [0 for i in range(n)]
ok = 0
for i in range(n):
    if n == 1:
        dt[0] = t[0]
    elif i == n - 1:
        v0[i] = ve[i - 1]
        ve[i] = 0
        dt[i] = t[i]
    else:
        v0[i] = ve[i - 1]
        dt[i] = t[i]
        ve[i] = min(v[i + 1], v[i], v0[i] + dt[i])
# print(dt)
# print(v0)
# print(ve)
while ok == 0:
    for i in range(n - 1):
        #        if  abs((ve[i]-ve[i+1])/dt[i+1]) >1:
        if abs((ve[i + 1] - v0[i + 1]) / dt[i + 1]) > 1:
            ve[i] = ve[i] - 1
            v0[i + 1] = v0[i + 1] - 1
            #                v0[i]=v0[i]-1
            #                print("dt",dt)
            #                print("v0",v0)
            #                print("ve",ve)
            break
    else:
        ok = 1
# print(dt)
# print(v0)
# print(ve)
for i in range(n):
    ttt = 0.5 * (ve[i] + dt[i] - v0[i])
    vvv = ttt + v0[i]
    if vvv - v[i] >= 0:
        S[i] = (
            0.5 * (v0[i] + vvv) * ttt
            + 0.5 * (ve[i] + vvv) * (dt[i] - ttt)
            - (ttt - v[i] + v0[i]) * (vvv - v[i])
        )
        S1[i] = 0.5 * (v0[i] + vvv) * ttt + 0.5 * (ve[i] + vvv) * (dt[i] - ttt)
        S2[i] = (ttt - v[i] + v0[i]) * (vvv - v[i])
    else:
        S[i] = 0.5 * (v0[i] + vvv) * ttt + 0.5 * (ve[i] + vvv) * (dt[i] - ttt)
        S1[i] = 0.5 * (v0[i] + vvv) * ttt + 0.5 * (ve[i] + vvv) * (dt[i] - ttt)
        S2[i] = 0
print((sum(S)))

+# n個の区間について

+v0 = [0 for i in range(n)]  # 各区間の最初の速度

+ve = [0 for i in range(n)]  # 各区間の最後の速度

+S = [0 for i in range(n)]  # 各区間に走った距離（v-tグラフの面積）

+ok = 0  # ok牧場　後でフラグに使う

-            #                print("dt",dt)

-            #                print("ve",ve)

+print((sum(S)))  # 各区間の走った距離の総和（答え）を出力


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

ans = 0

for i in range(1,10):

  if i <= n:

    ans += 1

  else:

    break

if n > 99:

  for i in range(100,1000):

    if i <= n:

      ans += 1

    else:

      break

if n > 9999:

  for i in range(10000,100000):

    if i <= n:

      ans += 1

    else:

      break

print(ans)

n = int(eval(input()))
ans = 0
for i in range(1, 10):
    if i <= n:
        ans += 1
    else:
        break
if n > 99:
    for i in range(100, 1000):
        if i <= n:
            ans += 1
        else:
            break
if n > 9999:
    for i in range(10000, 100000):
        if i <= n:
            ans += 1
        else:
            break
print(ans)