Input:
class SegmentTree:

    def __init__(self, a: list, e: 'default' = 0, f: 'function' = max):

        size = len(a)

        n = 1 << (size - 1).bit_length()

        seg = [e] * (n * 2 - 1)

        for i, a_ in enumerate(a, n - 1):

            seg[i] = a_

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

            seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2])

        self.size = size

        self.n = n

        self.seg = seg

        self.a = a

        self.e = e

        self.f = f

    def update(self, k, x):

        n = self.n

        seg = self.seg

        f = self.f

        k += n - 1

        seg[k] = x

        while k > 0:

            k = (k - 1) // 2

            seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2])

    def query(self, a, b, k=0, l=0, r=-1):

        if r < 0:

            r = self.n

        if r <= a or b <= l:

            return self.e

        if a <= l and r <= b:

            return self.seg[k]

        m = (l + r) // 2

        vl = self.query(a, b, k * 2 + 1, l, m)

        vr = self.query(a, b, k * 2 + 2, m, r)

        return self.f(vl, vr)

n = int(eval(input()))

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

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

dp = [0] * (n + 1)

# dp[j] := 末尾jの単調増加列の美しさの総和の最大値

seg = SegmentTree(a=dp, e=0, f=max)

for h_, a_ in zip(h, a):

    # i本目を取って末尾にするとき

    max_ = seg.query(0, h_) + a_

    seg.update(h_, max_)

print((seg.query(0, n + 1)))

# seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)

class SegmentTree:

    # original: @solzard_

    def __init__(self,

                 init_val: 'initial value: iterable',

                 segfunc: 'operation unique in case',

                 ide_ele: 'identity element corresponding init_val' = 0,

                 ):

        self.segfunc = segfunc

        self.ide_ele = ide_ele

        self.size = 1 << (len(init_val) - 1).bit_length()

        self.tree = self._build(init_val)

    def _build(self, init_val) -> 'tree':

        segfunc = self.segfunc

        tree = [self.ide_ele] * (self.size * 2 - 1)

        for idx, val in enumerate(init_val, self.size - 1):  # set

            # modify val if needed (e.g. str -> ord())

            tree[idx] = val

        for idx in range(self.size - 2, -1, -1):  # build

            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

        return tree

    def update(self, idx: int, val) -> None:

        tree = self.tree

        segfunc = self.segfunc

        idx += self.size - 1

        # modify val if needed as same as in _build()

        tree[idx] = val

        while idx > 0:

            idx = (idx - 1) // 2

            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

    def query(self, left: int, right: int) -> 'result':

        left += self.size

        right += self.size

        ret = self.ide_ele  # left >= right: return self.ide_ele

        segfunc = self.segfunc

        tree = self.tree

        while left < right:

            if left & 1:  # odd

                ret = segfunc(ret, tree[left - 1])

                left += 1

            if right & 1:  # odd

                right -= 1

                ret = segfunc(ret, tree[right - 1])

            left >>= 1

            right >>= 1

        return ret

n = int(eval(input()))

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

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

dp = [0] * (n + 1)

# dp[j] := 末尾jの単調増加列の美しさの総和の最大値

seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)

for h_, a_ in zip(h, a):

    # i本目を取って末尾にするとき

    max_ = seg.query(0, h_) + a_

    seg.update(h_, max_)

print((seg.query(0, n + 1)))

class SegmentTree:
    def __init__(self, a: list, e: "default" = 0, f: "function" = max):
        size = len(a)
        n = 1 << (size - 1).bit_length()
        seg = [e] * (n * 2 - 1)
        for i, a_ in enumerate(a, n - 1):
            seg[i] = a_
        for i in range(n - 2, -1, -1):
            seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2])
        self.size = size
        self.n = n
        self.seg = seg
        self.a = a
        self.e = e
        self.f = f

    def update(self, k, x):
        n = self.n
        seg = self.seg
        f = self.f
        k += n - 1
        seg[k] = x
        while k > 0:
            k = (k - 1) // 2
            seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2])

    def query(self, a, b, k=0, l=0, r=-1):
        if r < 0:
            r = self.n
        if r <= a or b <= l:
            return self.e
        if a <= l and r <= b:
            return self.seg[k]
        m = (l + r) // 2
        vl = self.query(a, b, k * 2 + 1, l, m)
        vr = self.query(a, b, k * 2 + 2, m, r)
        return self.f(vl, vr)

n = int(eval(input()))
h = tuple(map(int, input().split()))
a = tuple(map(int, input().split()))
dp = [0] * (n + 1)
# dp[j] := 末尾jの単調増加列の美しさの総和の最大値
seg = SegmentTree(a=dp, e=0, f=max)
for h_, a_ in zip(h, a):
    # i本目を取って末尾にするとき
    max_ = seg.query(0, h_) + a_
    seg.update(h_, max_)
print((seg.query(0, n + 1)))

# seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)
class SegmentTree:
    # original: @solzard_
    def __init__(
        self,
        init_val: "initial value: iterable",
        segfunc: "operation unique in case",
        ide_ele: "identity element corresponding init_val" = 0,
    ):
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.size = 1 << (len(init_val) - 1).bit_length()
        self.tree = self._build(init_val)

    def _build(self, init_val) -> "tree":
        segfunc = self.segfunc
        tree = [self.ide_ele] * (self.size * 2 - 1)
        for idx, val in enumerate(init_val, self.size - 1):  # set
            # modify val if needed (e.g. str -> ord())
            tree[idx] = val
        for idx in range(self.size - 2, -1, -1):  # build
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])
        return tree

    def update(self, idx: int, val) -> None:
        tree = self.tree
        segfunc = self.segfunc
        idx += self.size - 1
        # modify val if needed as same as in _build()
        tree[idx] = val
        while idx > 0:
            idx = (idx - 1) // 2
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

    def query(self, left: int, right: int) -> "result":
        left += self.size
        right += self.size
        ret = self.ide_ele  # left >= right: return self.ide_ele
        segfunc = self.segfunc
        tree = self.tree
        while left < right:
            if left & 1:  # odd
                ret = segfunc(ret, tree[left - 1])
                left += 1
            if right & 1:  # odd
                right -= 1
                ret = segfunc(ret, tree[right - 1])
            left >>= 1
            right >>= 1
        return ret

n = int(eval(input()))
h = tuple(map(int, input().split()))
a = tuple(map(int, input().split()))
dp = [0] * (n + 1)
# dp[j] := 末尾jの単調増加列の美しさの総和の最大値
seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)
for h_, a_ in zip(h, a):
    # i本目を取って末尾にするとき
    max_ = seg.query(0, h_) + a_
    seg.update(h_, max_)
print((seg.query(0, n + 1)))

+# seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)

-    def __init__(self, a: list, e: "default" = 0, f: "function" = max):

-        n = 1 << (size - 1).bit_length()

-        for i, a_ in enumerate(a, n - 1):

+        init_val: "initial value: iterable",

+        segfunc: "operation unique in case",

+        ide_ele: "identity element corresponding init_val" = 0,

+        self.size = 1 << (len(init_val) - 1).bit_length()

+        self.tree = self._build(init_val)

+    def _build(self, init_val) -> "tree":

+        tree = [self.ide_ele] * (self.size * 2 - 1)

+        for idx, val in enumerate(init_val, self.size - 1):  # set

+            # modify val if needed (e.g. str -> ord())

+        for idx in range(self.size - 2, -1, -1):  # build

+            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

-    def query(self, a, b, k=0, l=0, r=-1):

-        vl = self.query(a, b, k * 2 + 1, l, m)

-        vr = self.query(a, b, k * 2 + 2, m, r)

+    def update(self, idx: int, val) -> None:

+        # modify val if needed as same as in _build()

+    def query(self, left: int, right: int) -> "result":

+        ret = self.ide_ele  # left >= right: return self.ide_ele

+                ret = segfunc(ret, tree[left - 1])

+                ret = segfunc(ret, tree[right - 1])

+seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)


Input:
import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x) - 1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())

s = ns()

n = len(s)

ans = [0]*n

#左からRを見る

nextl = [-1]*n

curl = n-1

for i, si in enumerate(s[::-1]):

    if si == "R":

        nextl[n-i-1] = curl

    else:

        curl = n-i-1

for i, nli in enumerate(nextl):

    if nli == -1:

        continue

    if(nli - i) % 2:

        ans[nli-1] += 1

    else:

        ans[nli] += 1

# 右からLを見る

nextr = [-1]*n

curr = 0

for i, si in enumerate(s):

    if si == "L":

        nextr[i] = curr

    else:

        curr = i

for i, nri in enumerate(nextr):

    if nri == -1:

        continue

    if (i - nri) % 2:

        ans[nri+1] += 1

    else:

        ans[nri] += 1

print((*ans))

import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x) - 1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())

s = lc()

n = len(s)

tol = [0]*n

tor = [0]*n

ans = [0]*n

# Rにいる子のLまでの距離

dist = 0

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

    if s[i] == "L":

        dist = 0

    else:

        dist += 1

        tol[i] = dist

# Lにいる子のRまでの距離

dist = 0

for i in range(n):

    if s[i] == "R":

        dist = 0

    else:

        dist += 1

        tor[i] = dist

# それぞれの最終的な位置

for j, tolj in enumerate(tol):

    if tolj == 0:

        continue

    elif tolj % 2:

        ans[j + tolj - 1] += 1

    else:

        ans[j + tolj] += 1

for j, torj in enumerate(tor):

    if torj == 0:

        continue

    elif torj % 2:

        ans[j - torj + 1] += 1

    else:

        ans[j -torj] += 1

print((*ans))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)

def li():
    return list(map(int, stdin.readline().split()))

def li_():
    return [int(x) - 1 for x in stdin.readline().split()]

def lf():
    return list(map(float, stdin.readline().split()))

def ls():
    return stdin.readline().split()

def ns():
    return stdin.readline().rstrip()

def lc():
    return list(ns())

def ni():
    return int(stdin.readline())

def nf():
    return float(stdin.readline())

s = ns()
n = len(s)
ans = [0] * n
# 左からRを見る
nextl = [-1] * n
curl = n - 1
for i, si in enumerate(s[::-1]):
    if si == "R":
        nextl[n - i - 1] = curl
    else:
        curl = n - i - 1
for i, nli in enumerate(nextl):
    if nli == -1:
        continue
    if (nli - i) % 2:
        ans[nli - 1] += 1
    else:
        ans[nli] += 1
# 右からLを見る
nextr = [-1] * n
curr = 0
for i, si in enumerate(s):
    if si == "L":
        nextr[i] = curr
    else:
        curr = i
for i, nri in enumerate(nextr):
    if nri == -1:
        continue
    if (i - nri) % 2:
        ans[nri + 1] += 1
    else:
        ans[nri] += 1
print((*ans))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)

def li():
    return list(map(int, stdin.readline().split()))

def li_():
    return [int(x) - 1 for x in stdin.readline().split()]

def lf():
    return list(map(float, stdin.readline().split()))

def ls():
    return stdin.readline().split()

def ns():
    return stdin.readline().rstrip()

def lc():
    return list(ns())

def ni():
    return int(stdin.readline())

def nf():
    return float(stdin.readline())

s = lc()
n = len(s)
tol = [0] * n
tor = [0] * n
ans = [0] * n
# Rにいる子のLまでの距離
dist = 0
for i in range(n - 1, -1, -1):
    if s[i] == "L":
        dist = 0
    else:
        dist += 1
        tol[i] = dist
# Lにいる子のRまでの距離
dist = 0
for i in range(n):
    if s[i] == "R":
        dist = 0
    else:
        dist += 1
        tor[i] = dist
# それぞれの最終的な位置
for j, tolj in enumerate(tol):
    if tolj == 0:
        continue
    elif tolj % 2:
        ans[j + tolj - 1] += 1
    else:
        ans[j + tolj] += 1
for j, torj in enumerate(tor):
    if torj == 0:
        continue
    elif torj % 2:
        ans[j - torj + 1] += 1
    else:
        ans[j - torj] += 1
print((*ans))

-s = ns()
+s = lc()
+tol = [0] * n
+tor = [0] * n
-# 左からRを見る
-nextl = [-1] * n
-curl = n - 1
-for i, si in enumerate(s[::-1]):
-    if si == "R":
-        nextl[n - i - 1] = curl
+# Rにいる子のLまでの距離
+dist = 0
+for i in range(n - 1, -1, -1):
+    if s[i] == "L":
+        dist = 0
-        curl = n - i - 1
-for i, nli in enumerate(nextl):
-    if nli == -1:
+        dist += 1
+        tol[i] = dist
+# Lにいる子のRまでの距離
+dist = 0
+for i in range(n):
+    if s[i] == "R":
+        dist = 0
+    else:
+        dist += 1
+        tor[i] = dist
+# それぞれの最終的な位置
+for j, tolj in enumerate(tol):
+    if tolj == 0:
-    if (nli - i) % 2:
-        ans[nli - 1] += 1
+    elif tolj % 2:
+        ans[j + tolj - 1] += 1
-        ans[nli] += 1
-# 右からLを見る
-nextr = [-1] * n
-curr = 0
-for i, si in enumerate(s):
-    if si == "L":
-        nextr[i] = curr
+        ans[j + tolj] += 1
+for j, torj in enumerate(tor):
+    if torj == 0:
+        continue
+    elif torj % 2:
+        ans[j - torj + 1] += 1
-        curr = i
-for i, nri in enumerate(nextr):
-    if nri == -1:
-        continue
-    if (i - nri) % 2:
-        ans[nri + 1] += 1
-    else:
-        ans[nri] += 1
+        ans[j - torj] += 1


Input:
def main():

    n = int(eval(input()))

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

    MAX = 10**18

    if 0 in set(a):

        print((0))

    else:

        ans = a[0]

        for ai in a[1:]:

            ans *= ai

            if ans > MAX:

                print((-1))

                return

        print(ans)

if __name__ == "__main__":

    main()

def main():

    n = int(eval(input()))

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

    if 0 in a:

        print((0))

        exit(0)

    ans = 1

    MAX = 10**18

    for ai in a:

        ans *= ai

        if ans > MAX:

            print((-1))

            exit(0)

    print(ans)

if __name__ == "__main__":

    main()

+    if 0 in a:
+        print((0))
+        exit(0)
+    ans = 1
-    if 0 in set(a):
-        print((0))
-    else:
-        ans = a[0]
-        for ai in a[1:]:
-            ans *= ai
-            if ans > MAX:
-                print((-1))
-                return
-        print(ans)
+    for ai in a:
+        ans *= ai
+        if ans > MAX:
+            print((-1))
+            exit(0)
+    print(ans)


Input:
class Node():

    def __init__(self, node_id, left, right):

        self.node_id    =   node_id

        self.left       =   left

        self.right      =   right

    def pre_order_search(self):

        l = self.left

        r = self.right

        print("",self.node_id, end="")

        if l != -1:

            tree[l].pre_order_search()

        if r != -1:

            tree[r].pre_order_search()

    def in_order_search(self):

        l = self.left

        r = self.right

        if l != -1:

            tree[l].in_order_search()

        print("",self.node_id, end="")

        if r != -1:

            tree[r].in_order_search()

    def post_order_search(self):

        l = self.left

        r = self.right

        if l != -1:

            tree[l].post_order_search()

        if r != -1:

            tree[r].post_order_search()

        print("",self.node_id, end="")

n = int(input())

tree = [None for i in range(n)]

root_set = set(range(n))

for i in range(n):

    node_id, left, right = map(int, input().split())

    tree[node_id] = Node(node_id, left, right)

    root_set -= set([left, right])

root = root_set.pop()

print("Preorder")

tree[root].pre_order_search()

print("")

print("Inorder")

tree[root].in_order_search()

print()

print("Postorder")

tree[root].post_order_search()

print()

class Node():

    def __init__(self, node_id, left, right):

        self.node_id    =   node_id

        self.left       =   left

        self.right      =   right

    def pre_order_search(self):

        l = self.left

        r = self.right

        print("",self.node_id, end="")

        if l != -1:

            tree[l].pre_order_search()

        if r != -1:

            tree[r].pre_order_search()

    def in_order_search(self):

        l = self.left

        r = self.right

        if l != -1:

            tree[l].in_order_search()

        print("",self.node_id, end="")

        if r != -1:

            tree[r].in_order_search()

    def post_order_search(self):

        l = self.left

        r = self.right

        if l != -1:

            tree[l].post_order_search()

        if r != -1:

            tree[r].post_order_search()

        print("",self.node_id, end="")

n = int(input())

tree = [None for i in range(n)]

root_set = set(range(n))

for i in range(n):

    node_id, left, right = map(int, input().split())

    tree[node_id] = Node(node_id, left, right)

    root_set -= set([left, right])

root = root_set.pop()

print("Preorder")

tree[root].pre_order_search()

print("")

print("Inorder")

tree[root].in_order_search()

print("")

print("Postorder")

tree[root].post_order_search()

print("")

class Node:
    def __init__(self, node_id, left, right):
        self.node_id = node_id
        self.left = left
        self.right = right

    def pre_order_search(self):
        l = self.left
        r = self.right
        print("", self.node_id, end="")
        if l != -1:
            tree[l].pre_order_search()
        if r != -1:
            tree[r].pre_order_search()

    def in_order_search(self):
        l = self.left
        r = self.right
        if l != -1:
            tree[l].in_order_search()
        print("", self.node_id, end="")
        if r != -1:
            tree[r].in_order_search()

    def post_order_search(self):
        l = self.left
        r = self.right
        if l != -1:
            tree[l].post_order_search()
        if r != -1:
            tree[r].post_order_search()
        print("", self.node_id, end="")

n = int(input())
tree = [None for i in range(n)]
root_set = set(range(n))
for i in range(n):
    node_id, left, right = map(int, input().split())
    tree[node_id] = Node(node_id, left, right)
    root_set -= set([left, right])
root = root_set.pop()
print("Preorder")
tree[root].pre_order_search()
print("")
print("Inorder")
tree[root].in_order_search()
print()
print("Postorder")
tree[root].post_order_search()
print()

class Node:
    def __init__(self, node_id, left, right):
        self.node_id = node_id
        self.left = left
        self.right = right

    def pre_order_search(self):
        l = self.left
        r = self.right
        print("", self.node_id, end="")
        if l != -1:
            tree[l].pre_order_search()
        if r != -1:
            tree[r].pre_order_search()

    def in_order_search(self):
        l = self.left
        r = self.right
        if l != -1:
            tree[l].in_order_search()
        print("", self.node_id, end="")
        if r != -1:
            tree[r].in_order_search()

    def post_order_search(self):
        l = self.left
        r = self.right
        if l != -1:
            tree[l].post_order_search()
        if r != -1:
            tree[r].post_order_search()
        print("", self.node_id, end="")

n = int(input())
tree = [None for i in range(n)]
root_set = set(range(n))
for i in range(n):
    node_id, left, right = map(int, input().split())
    tree[node_id] = Node(node_id, left, right)
    root_set -= set([left, right])
root = root_set.pop()
print("Preorder")
tree[root].pre_order_search()
print("")
print("Inorder")
tree[root].in_order_search()
print("")
print("Postorder")
tree[root].post_order_search()
print("")


Input:
N, M = [int(i) for i in input().split()]

def prime_decomposition(n):

  i = 2

  table = []

  while i * i <= n:

    while n % i == 0:

      n //= i

      table.append(i)

    i += 1

  if n > 1:

    table.append(n)

  return table

def cmb(n, r):

    N, R = n, r

    for i in range(1, r):

        N *= n - i

        R *= r - i

    return N // R

from collections import Counter

A = Counter(prime_decomposition(M))

mod = 10 ** 9 + 7

result = 1

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

    result = result * cmb(a + N - 1, a) % mod

print(result)

N, M = [int(i) for i in input().split()]

def prime_decomposition(n):

  table = []

  i = 2

  while i * i <= n:

    count = 0

    while n % i == 0:

      n //= i

      count += 1

    if count != 0:

        table.append((i, count))

    i += 1

  if n > 1:

    table.append((n, 1))

  return table

def cmb(n, r):

    N, R = n, r

    for i in range(1, r):

        N *= n - i

        R *= r - i

    return N // R

mod = 10 ** 9 + 7

A = prime_decomposition(M)

result = 1

for _, a in A:

    result = result * cmb(a + N - 1, a) % mod

print(result)

N, M = [int(i) for i in input().split()]

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

def cmb(n, r):
    N, R = n, r
    for i in range(1, r):
        N *= n - i
        R *= r - i
    return N // R

from collections import Counter

A = Counter(prime_decomposition(M))
mod = 10**9 + 7
result = 1
for a in list(A.values()):
    result = result * cmb(a + N - 1, a) % mod
print(result)

N, M = [int(i) for i in input().split()]

def prime_decomposition(n):
    table = []
    i = 2
    while i * i <= n:
        count = 0
        while n % i == 0:
            n //= i
            count += 1
        if count != 0:
            table.append((i, count))
        i += 1
    if n > 1:
        table.append((n, 1))
    return table

def cmb(n, r):
    N, R = n, r
    for i in range(1, r):
        N *= n - i
        R *= r - i
    return N // R

mod = 10**9 + 7
A = prime_decomposition(M)
result = 1
for _, a in A:
    result = result * cmb(a + N - 1, a) % mod
print(result)

+    table = []
-    table = []
+        count = 0
-            table.append(i)
+            count += 1
+        if count != 0:
+            table.append((i, count))
-        table.append(n)
+        table.append((n, 1))
-from collections import Counter
-A = Counter(prime_decomposition(M))
+A = prime_decomposition(M)
-for a in list(A.values()):
+for _, a in A:


Input:
import decimal

def resolve():

    a, b = list(map(decimal.Decimal, input().split()))

    print((a * b // 1))

if __name__ == "__main__":

    resolve()

def resolve():

    a, b = input().split()

    a = int(a)

    b = int(float(b) * 100 + .5)

    ans = a*b

    print((ans//100))

if __name__ == "__main__":

    resolve()

def resolve():
    a, b = input().split()
    a = int(a)
    b = int(float(b) * 100 + 0.5)
    ans = a * b
    print((ans // 100))

if __name__ == "__main__":
    resolve()

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


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

S = eval(input())

leftWest = 0

rightEast = S.count("E")

ans = 10 ** 6

for i in range(len(S)):

    if S[i] == "E":

        rightEast -= 1

    ans = min(ans, leftWest + rightEast)

    if S[i] == "W":

        leftWest += 1

print(ans)

N = int(eval(input()))

S = eval(input())

leftWest = 0

rightEast = list(S).count("E")

ans = 10 ** 6

for si in S:

    if si == "E":

        rightEast -= 1

    ans = min(ans, leftWest + rightEast)

    if si == "W":

        leftWest += 1

print(ans)

N = int(eval(input()))
S = eval(input())
leftWest = 0
rightEast = S.count("E")
ans = 10**6
for i in range(len(S)):
    if S[i] == "E":
        rightEast -= 1
    ans = min(ans, leftWest + rightEast)
    if S[i] == "W":
        leftWest += 1
print(ans)

N = int(eval(input()))
S = eval(input())
leftWest = 0
rightEast = list(S).count("E")
ans = 10**6
for si in S:
    if si == "E":
        rightEast -= 1
    ans = min(ans, leftWest + rightEast)
    if si == "W":
        leftWest += 1
print(ans)

-rightEast = S.count("E")
+rightEast = list(S).count("E")
-for i in range(len(S)):
-    if S[i] == "E":
+for si in S:
+    if si == "E":
-    if S[i] == "W":
+    if si == "W":


Input:
import numpy as np

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

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

char = []

for i in range(n):

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

npcond = np.asarray(cond)

npchar = np.asarray(char)

npstat = npchar * npcond

npstat1 = np.sum(npstat, axis = 1) + c

print((np.count_nonzero(npstat1 > 0)))

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

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

a = []

for i in range(n):

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

ab=0

ans=0

for i in range(n):

    for j in range(m):

        ab+=a[i][j]*b[j]

    if ab+c>0:

        ans+=1

        ab = 0

    else:

         ab = 0

print(ans)

import numpy as np

n, m, c = list(map(int, input().split()))
cond = list(map(int, input().split()))
char = []
for i in range(n):
    char.append(list(map(int, input().split())))
npcond = np.asarray(cond)
npchar = np.asarray(char)
npstat = npchar * npcond
npstat1 = np.sum(npstat, axis=1) + c
print((np.count_nonzero(npstat1 > 0)))

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

-    char.append(list(map(int, input().split())))

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


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

for i in range(120):

 for j in range(-75,i):

  if i**5-j**5==x:print((i,j));exit()

x=int(eval(input()))

for i in range(120):

 for j in range(-62,i):

  if i**5-j**5==x:print((i,j));exit()

x = int(eval(input()))
for i in range(120):
    for j in range(-75, i):
        if i**5 - j**5 == x:
            print((i, j))
            exit()

x = int(eval(input()))
for i in range(120):
    for j in range(-62, i):
        if i**5 - j**5 == x:
            print((i, j))
            exit()

-    for j in range(-75, i):
+    for j in range(-62, i):


Input:
def getN():

    return int(eval(input()))

def getNM():

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

def getList():

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

def getArray(intn):

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

def input():

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

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

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

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)

def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)

from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

import heapq

import math

from fractions import gcd

import random

import string

import copy

from itertools import combinations, permutations, product

from operator import mul

from functools import reduce

from bisect import bisect_left, bisect_right

import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7

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

# Main Code #

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

N, M = getNM()

dp = [float("inf")] * (1 << N)

dp[0] = 0

# 1 ~ Nを全て開けられる鍵を揃えるコストの最小値がO(M * 2 ** N)でわかる

# 各鍵について

for i in range(M):

    a, b = getNM()

    c = getList()

    bit = 0

    # その鍵で開けられる部屋を揃える

    for item in c:

        bit |= (1 << (item - 1))

    # 部屋の各状態について

    # そこからさらに鍵cを取得した場合と他の鍵を使用した場合とで比較する

    for j in range(1 << N):

        dp[j | bit] = min(dp[j | bit], dp[j] + a)

if dp[(1 << N) - 1] == float("inf"):

    print((-1))

else:

    print((dp[(1 << N) - 1]))

def getN():

    return int(eval(input()))

def getNM():

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

def getList():

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

def getArray(intn):

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

def input():

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

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

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

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)

def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)

from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

import heapq

import math

from fractions import gcd

import random

import string

import copy

from itertools import combinations, permutations, product

from operator import mul

from functools import reduce

from bisect import bisect_left, bisect_right

import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7

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

# Main Code #

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

N, M = getNM()

weight = []

value = []

for i in range(M):

    a, b = getNM()

    c = getList()

    weight.append(a)

    value.append(c)

"""

N, M = 4, 6

weight = [67786, 3497, 44908, 2156, 26230, 86918]

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

"""

# N個のものを全て手に入れるのに必要なコストの最小値

# コストを1にすれば最小個数がわかる

# Nの数が十分に小さいと使用可能

def get_everything(n, weight, value):

    m = len(weight)

    dp = [float("inf")] * (1 << n)

    dp[0] = 0

    for i in range(m):

        bit = 0

        for item in value[i]:

            bit |= (1 << (item - 1))

        for j in range(1 << n):

            dp[j | bit] = min(dp[j | bit], dp[j] + weight[i])

    return dp[(1 << N) - 1]

ans = get_everything(N, weight, value)

if ans == float("inf"):

    print((-1))

else:

    print(ans)

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

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

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

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

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

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

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

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

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

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N, M = getNM()
dp = [float("inf")] * (1 << N)
dp[0] = 0
# 1 ~ Nを全て開けられる鍵を揃えるコストの最小値がO(M * 2 ** N)でわかる
# 各鍵について
for i in range(M):
    a, b = getNM()
    c = getList()
    bit = 0
    # その鍵で開けられる部屋を揃える
    for item in c:
        bit |= 1 << (item - 1)
    # 部屋の各状態について
    # そこからさらに鍵cを取得した場合と他の鍵を使用した場合とで比較する
    for j in range(1 << N):
        dp[j | bit] = min(dp[j | bit], dp[j] + a)
if dp[(1 << N) - 1] == float("inf"):
    print((-1))
else:
    print((dp[(1 << N) - 1]))

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

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

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

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

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

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

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

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

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

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N, M = getNM()
weight = []
value = []
for i in range(M):
    a, b = getNM()
    c = getList()
    weight.append(a)
    value.append(c)
"""
N, M = 4, 6
weight = [67786, 3497, 44908, 2156, 26230, 86918]
value = [[1, 3, 4], [2], [2, 3, 4], [2, 3, 4], [2], [3]]
"""
# N個のものを全て手に入れるのに必要なコストの最小値
# コストを1にすれば最小個数がわかる
# Nの数が十分に小さいと使用可能
def get_everything(n, weight, value):
    m = len(weight)
    dp = [float("inf")] * (1 << n)
    dp[0] = 0
    for i in range(m):
        bit = 0
        for item in value[i]:
            bit |= 1 << (item - 1)
        for j in range(1 << n):
            dp[j | bit] = min(dp[j | bit], dp[j] + weight[i])
    return dp[(1 << N) - 1]

ans = get_everything(N, weight, value)
if ans == float("inf"):
    print((-1))
else:
    print(ans)

-# 1 ~ Nを全て開けられる鍵を揃えるコストの最小値がO(M * 2 ** N)でわかる

-    # その鍵で開けられる部屋を揃える

-    # 部屋の各状態について

-    # そこからさらに鍵cを取得した場合と他の鍵を使用した場合とで比較する

-        dp[j | bit] = min(dp[j | bit], dp[j] + a)

+# N個のものを全て手に入れるのに必要なコストの最小値

+# コストを1にすれば最小個数がわかる

+# Nの数が十分に小さいと使用可能

+            dp[j | bit] = min(dp[j | bit], dp[j] + weight[i])


Input:
def main():

    # 1.input

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

    #2. judge

    if abs(a-c) <= d:

        print("Yes")

    elif abs(a-b) <= d and abs(b-c) <= d:

        print("Yes")

    else:

        print("No")

if __name__ == "__main__":

    main()

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

if abs(c-a)<=d or (abs(b-a)<=d and abs(c-b)<=d):

    print("Yes")

else:

    print("No")

def main():
    # 1.input
    a, b, c, d = list(map(int, input().split()))
    # 2. judge
    if abs(a - c) <= d:
        print("Yes")
    elif abs(a - b) <= d and abs(b - c) <= d:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

a, b, c, d = list(map(int, input().split()))
if abs(c - a) <= d or (abs(b - a) <= d and abs(c - b) <= d):
    print("Yes")
else:
    print("No")

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

-    elif abs(a - b) <= d and abs(b - c) <= d:

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

+if abs(c - a) <= d or (abs(b - a) <= d and abs(c - b) <= d):


Input:
import numpy as np

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

ATK, MP = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64).T

MAX_ATK = ATK.max()

table = np.zeros((H + MAX_ATK,), dtype=np.int64)

for damage in range(1, H + 1):

    table[damage] = (table[damage - ATK[np.arange(N, dtype=np.int16)]] + MP[np.arange(N, dtype=np.int16)]).min()

print((table[H]))

import numpy as np

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

ATK, MP = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64).T

MAX_ATK = ATK.max()

table = np.zeros((H + MAX_ATK,), dtype=np.int64)

for damage in range(1, H + 1):

    table[damage] = (table[damage - ATK] + MP).min()

print((table[H]))

import numpy as np

H, N = list(map(int, input().split()))
ATK, MP = np.array(
    tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64
).T
MAX_ATK = ATK.max()
table = np.zeros((H + MAX_ATK,), dtype=np.int64)
for damage in range(1, H + 1):
    table[damage] = (
        table[damage - ATK[np.arange(N, dtype=np.int16)]]
        + MP[np.arange(N, dtype=np.int16)]
    ).min()
print((table[H]))

import numpy as np

H, N = list(map(int, input().split()))
ATK, MP = np.array(
    tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64
).T
MAX_ATK = ATK.max()
table = np.zeros((H + MAX_ATK,), dtype=np.int64)
for damage in range(1, H + 1):
    table[damage] = (table[damage - ATK] + MP).min()
print((table[H]))

-        table[damage - ATK[np.arange(N, dtype=np.int16)]]

-        + MP[np.arange(N, dtype=np.int16)]

+    table[damage] = (table[damage - ATK] + MP).min()


Input:
import sys, re, os

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from fractions import gcd

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

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

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

def S_MAP(): return list(map(str, input().split()))

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

def S_LIST(): return list(map(str, input().split()))

import itertools

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

def dist(x1, x2, y1, y2):

  d = sqrt((x1-x2)**2 + (y1-y2)**2)

  return d

N = INT()

b = []

for i in range(N):

  a = LIST()

  b.append(a)

# print(b)

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

c = list(itertools.permutations(jun))

# print(c)

ans2 = 0

for j in c:

  # tuple

  ans = 0

  # print(j)

  for i in range(len(j)-1):

    # print(j[i])

    # print(j[i+1])

    x1 = b[j[i]][0]

    x2 = b[j[i+1]][0]

    y1 = b[j[i]][1]

    y2 = b[j[i+1]][1]

    ans += dist(x1, x2, y1, y2)

    # print(ans)

  # print(ans)

  ans2 += ans

  # print(ans2)

    # print(dist(x1, x2, y1, y2))

print((ans2/len(c)))

# なぜかうまくいかない

import sys, re, os

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from fractions import gcd

from bisect import bisect, bisect_right, bisect_left

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

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

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

def S_MAP(): return list(map(str, input().split()))

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

def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

N = INT()

L = [LIST() for i in range(N)]

# print(list(combinatins(L, 2)))

A = [n for n in range(N)]

ans = 0

for i in list(combinations(A, 2)):

    l, r = i

    a, b = L[r], L[l]

    c = (a[0] - b[0]) ** 2

    d = (a[1] - b[1]) ** 2

    ans += sqrt(c + d)

print((ans/ N * 2))

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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

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

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

def S_MAP():
    return list(map(str, input().split()))

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

def S_LIST():
    return list(map(str, input().split()))

import itertools

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7

def dist(x1, x2, y1, y2):
    d = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
    return d

N = INT()
b = []
for i in range(N):
    a = LIST()
    b.append(a)
# print(b)
jun = [i for i in range(N)]
c = list(itertools.permutations(jun))
# print(c)
ans2 = 0
for j in c:
    # tuple
    ans = 0
    # print(j)
    for i in range(len(j) - 1):
        # print(j[i])
        # print(j[i+1])
        x1 = b[j[i]][0]
        x2 = b[j[i + 1]][0]
        y1 = b[j[i]][1]
        y2 = b[j[i + 1]][1]
        ans += dist(x1, x2, y1, y2)
        # print(ans)
    # print(ans)
    ans2 += ans
    # print(ans2)
    # print(dist(x1, x2, y1, y2))
print((ans2 / len(c)))

# なぜかうまくいかない
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_right, bisect_left

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

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

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

def S_MAP():
    return list(map(str, input().split()))

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

def S_LIST():
    return list(map(str, input().split()))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
L = [LIST() for i in range(N)]
# print(list(combinatins(L, 2)))
A = [n for n in range(N)]
ans = 0
for i in list(combinations(A, 2)):
    l, r = i
    a, b = L[r], L[l]
    c = (a[0] - b[0]) ** 2
    d = (a[1] - b[1]) ** 2
    ans += sqrt(c + d)
print((ans / N * 2))

+# なぜかうまくいかない

+from bisect import bisect, bisect_right, bisect_left


Input:
import sys

import collections

import copy

input = sys.stdin.readline

def main():

    N = int(eval(input()))

    A = [collections.deque([int(x) for x in input().split()]) for _ in range(N)]

    day = 0

    c = 0

    nxt = [x for x in range(N)]

    oppo = [0] * N

    while c != N * (N - 1):

        day += 1

        for i in nxt:

            oppo[i] = A[i].popleft() if A[i] else -1

        tmp = set()

        for i in nxt:

            if i == -1 or i in tmp:

                continue

            if i == oppo[oppo[i] - 1] - 1:

                tmp.add(i)

                tmp.add(oppo[i] - 1)

                c += 2

        if not tmp:

            print((-1))

            return

        nxt = tmp

    print(day)

if __name__ == '__main__':

    main()

import sys

import collections

from collections import defaultdict

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

def main():

    N = int(eval(input()))

    A = [[int(x) for x in input().split()] for _ in range(N)]

    q = [collections.deque() for j in range(N)]

    for i, a in enumerate(A):

        for aa in a:

            q[i].append(aa)

    ans = 0

    current = defaultdict(int)

    for i, v in enumerate(q):

        current[i + 1] = v[0]

    while True:

        v = set()

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

            if k == q[current[k] - 1][0]:

                v.add(k)

                v.add(current[k])

        current = defaultdict(int)

        if len(v) == 0:

            break

        for vv in v:

            q[vv - 1].popleft()

            if len(q[vv - 1]):

                current[vv] = q[vv - 1][0]

        ans += 1

    # 全て空なら

    size = 0

    for i in range(N):

        size += len(q[i])

    if size == 0:

        print(ans)

    else:

        print((-1))

if __name__ == '__main__':

    main()

import sys
import collections
import copy

input = sys.stdin.readline

def main():
    N = int(eval(input()))
    A = [collections.deque([int(x) for x in input().split()]) for _ in range(N)]
    day = 0
    c = 0
    nxt = [x for x in range(N)]
    oppo = [0] * N
    while c != N * (N - 1):
        day += 1
        for i in nxt:
            oppo[i] = A[i].popleft() if A[i] else -1
        tmp = set()
        for i in nxt:
            if i == -1 or i in tmp:
                continue
            if i == oppo[oppo[i] - 1] - 1:
                tmp.add(i)
                tmp.add(oppo[i] - 1)
                c += 2
        if not tmp:
            print((-1))
            return
        nxt = tmp
    print(day)

if __name__ == "__main__":
    main()

import sys
import collections
from collections import defaultdict

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

def main():
    N = int(eval(input()))
    A = [[int(x) for x in input().split()] for _ in range(N)]
    q = [collections.deque() for j in range(N)]
    for i, a in enumerate(A):
        for aa in a:
            q[i].append(aa)
    ans = 0
    current = defaultdict(int)
    for i, v in enumerate(q):
        current[i + 1] = v[0]
    while True:
        v = set()
        for k in list(current.keys()):
            if k == q[current[k] - 1][0]:
                v.add(k)
                v.add(current[k])
        current = defaultdict(int)
        if len(v) == 0:
            break
        for vv in v:
            q[vv - 1].popleft()
            if len(q[vv - 1]):
                current[vv] = q[vv - 1][0]
        ans += 1
    # 全て空なら
    size = 0
    for i in range(N):
        size += len(q[i])
    if size == 0:
        print(ans)
    else:
        print((-1))

if __name__ == "__main__":
    main()

-    A = [collections.deque([int(x) for x in input().split()]) for _ in range(N)]

-            oppo[i] = A[i].popleft() if A[i] else -1

-            if i == oppo[oppo[i] - 1] - 1:

+    A = [[int(x) for x in input().split()] for _ in range(N)]

+    q = [collections.deque() for j in range(N)]

+                current[vv] = q[vv - 1][0]

+    # 全て空なら


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

import numpy as np

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

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

dp = np.zeros(N)

for n in range(1, N):

    k = min(K, n)

    temp = np.min(dp[n-k:n] + np.abs(h[n]-h[n-k:n]))

    dp[n] = temp

print((int(dp[-1])))

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

import numpy as np

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

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

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

for n in range(1, N):

    k = min(K, n)

    temp = np.min(dp[n-k:n] + np.abs(h[n]-h[n-k:n]))

    dp[n] = temp

print((dp[-1]))

# -*- coding: utf-8 -*-
import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))
dp = np.zeros(N)
for n in range(1, N):
    k = min(K, n)
    temp = np.min(dp[n - k : n] + np.abs(h[n] - h[n - k : n]))
    dp[n] = temp
print((int(dp[-1])))

# -*- coding: utf-8 -*-
import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))
dp = np.zeros(N, dtype=np.int)
for n in range(1, N):
    k = min(K, n)
    temp = np.min(dp[n - k : n] + np.abs(h[n] - h[n - k : n]))
    dp[n] = temp
print((dp[-1]))


Input:
def f(i, k):

    if i == n and k == 0:

        global d

        hr1, hb1 = 0, 0

        hr2, hb2 = 0, 0

        cntr, cntb = 0, 0

        for j in range(n):

            if c[j]:

                hr1 += x[j] * pow(b1, cntr, mod)

                hr2 += x[j] * pow(b2, cntr, mod)

                hr1 %= mod

                hr2 %= mod

                cntr += 1

            else:

                hb1 += x[j] * pow(b1, cntb, mod)

                hb2 += x[j] * pow(b2, cntb, mod)

                hb1 %= mod

                hb2 %= mod

                cntb += 1

        if min(cntr, cntb) == 0:

            return

        if (hr1, hr2, hb1, hb2) in d:

            d[(hr1, hr2, hb1, hb2)] += 1

        else:

            d[(hr1, hr2, hb1, hb2)] = 1

        return

    elif i == n and k == 1:

        hr1, hb1 = 0, 0

        hr2, hb2 = 0, 0

        cntr, cntb = 0, 0

        for j in range(n):

            if c[j]:

                hr1 += y[j] * powb1[cntr]

                hr2 += y[j] * powb2[cntr]

                hr1 %= mod

                hr2 %= mod

                cntr += 1

            else:

                hb1 += y[j] * powb1[cntb]

                hb2 += y[j] * powb2[cntb]

                hb1 %= mod

                hb2 %= mod

                cntb += 1

        if min(cntr, cntb) == 0:

            return

        if (hr1, hr2, hb1, hb2) in d:

            global ans

            ans += d[(hr1, hr2, hb1, hb2)]

        return

    c[i] = 1

    f(i + 1, k)

    c[i] = 0

    f(i + 1, k)

n = int(eval(input()))

s = list(eval(input()))

mod = pow(2, 31) - 1

b1, b2 = 27, 31

powb1 = [pow(27, i, mod) for i in range(n)]

powb2 = [pow(31, i, mod) for i in range(n)]

d = {}

x, y = [], []

for i in range(n):

    x.append(ord(s[i]) - 96)

    y.append(ord(s[-(i + 1)]) - 96)

ans = 0 if not x == y else 2

c = [0] * n

f(0, 0)

c = [0] * n

f(0, 1)

print(ans)

def f(i, k):

    if i == n and k == 0:

        global d

        hr1, hb1 = 0, 0

        hr2, hb2 = 0, 0

        cntr, cntb = 0, 0

        for j in range(n):

            if c[j]:

                hr1 += x[j] * powb1[cntr]

                hr2 += x[j] * powb2[cntr]

                hr1 %= mod

                hr2 %= mod

                cntr += 1

            else:

                hb1 += x[j] * powb1[cntb]

                hb2 += x[j] * powb2[cntb]

                hb1 %= mod

                hb2 %= mod

                cntb += 1

        if min(cntr, cntb) == 0:

            return

        if (hr1, hr2, hb1, hb2) in d:

            d[(hr1, hr2, hb1, hb2)] += 1

        else:

            d[(hr1, hr2, hb1, hb2)] = 1

        return

    elif i == n and k == 1:

        hr1, hb1 = 0, 0

        hr2, hb2 = 0, 0

        cntr, cntb = 0, 0

        for j in range(n):

            if c[j]:

                hr1 += y[j] * powb1[cntr]

                hr2 += y[j] * powb2[cntr]

                hr1 %= mod

                hr2 %= mod

                cntr += 1

            else:

                hb1 += y[j] * powb1[cntb]

                hb2 += y[j] * powb2[cntb]

                hb1 %= mod

                hb2 %= mod

                cntb += 1

        if min(cntr, cntb) == 0:

            return

        if (hr1, hr2, hb1, hb2) in d:

            global ans

            ans += d[(hr1, hr2, hb1, hb2)]

        return

    c[i] = 1

    f(i + 1, k)

    c[i] = 0

    f(i + 1, k)

n = int(eval(input()))

s = list(eval(input()))

mod = pow(2, 31) - 1

b1, b2 = 27, 31

powb1 = [pow(27, i, mod) for i in range(n)]

powb2 = [pow(31, i, mod) for i in range(n)]

d = {}

x, y = [], []

for i in range(n):

    x.append(ord(s[i]) - 96)

    y.append(ord(s[-(i + 1)]) - 96)

ans = 0 if not x == y else 2

c = [0] * n

f(0, 0)

c = [0] * n

f(0, 1)

print(ans)

-                hr1 += x[j] * pow(b1, cntr, mod)

-                hr2 += x[j] * pow(b2, cntr, mod)

+                hr1 += x[j] * powb1[cntr]

+                hr2 += x[j] * powb2[cntr]

-                hb1 += x[j] * pow(b1, cntb, mod)

-                hb2 += x[j] * pow(b2, cntb, mod)

+                hb1 += x[j] * powb1[cntb]

+                hb2 += x[j] * powb2[cntb]


Input:
# https://atcoder.jp/contests/abc063/tasks/arc075_a

n = int(eval(input()))

nums = []

for _ in range(n):

    nums.append(int(eval(input())))

total = sum(nums)

dp = [[False for _ in range(total + 1)] for _ in range(n + 1)]

dp[0][0] = True

for i in range(n):

    num = nums[i]

    dp[i + 1][num] = True

    for j in range(total + 1):

        if dp[i][j] and num + j <= total:

            dp[i + 1][num + j] = True

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

for i in range(len(dp[0]))[::-1]:

    if dp[-1][i] and i % 10 != 0:

        print(i)

        break

else:

    print((0))

n = int(eval(input()))

nums = []

for _ in range(n):

    nums.append(int(eval(input())))

nums.sort()

ans = sum(nums)

if ans % 10 != 0:

    print(ans)

else:

    for num in nums:

        t = ans - num

        if t % 10 != 0:

            print(t)

            break

    else:

        print((0))

-dp = [[False for _ in range(total + 1)] for _ in range(n + 1)]

-        if dp[i][j] and num + j <= total:


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

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

if 0 in A:

    print((0))

else:

    p = 1

    for a in A:

        p *= a

        if p > 10**18:

            p = -1

            break

    print(p)

N = int(eval(input()))

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

if 0 in A:

    print((0))

else:

    r = 1

    for a in A:

        r *= a

        if r > 10**18:

            r = -1

            break

    print(r)

N = int(eval(input()))
A = tuple(map(int, input().split()))
if 0 in A:
    print((0))
else:
    p = 1
    for a in A:
        p *= a
        if p > 10**18:
            p = -1
            break
    print(p)

N = int(eval(input()))
A = list(map(int, input().split()))
if 0 in A:
    print((0))
else:
    r = 1
    for a in A:
        r *= a
        if r > 10**18:
            r = -1
            break
    print(r)

-A = tuple(map(int, input().split()))
+A = list(map(int, input().split()))
-    p = 1
+    r = 1
-        p *= a
-        if p > 10**18:
-            p = -1
+        r *= a
+        if r > 10**18:
+            r = -1
-    print(p)
+    print(r)


Input:
"""

AtCoder Beginner Contest 051

B - Sum of Three Integers

"""

if __name__ == "__main__":

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

    ans = 0

    for x in range(K+1):

        for y in range(K+1):

            if x + y > S or S - (x + y) > K:

                continue

            ans += 1

    print(ans)

"""

AtCoder Beginner Contest 051

B - Sum of Three Integers

"""

if __name__ == "__main__":

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

    ans = 0

    A = [i for i in range(K+1)]

    for x in A:

        for y in A:

            if x + y > S or S - (x + y) > K:

                continue

            ans += 1

    print(ans)

"""
AtCoder Beginner Contest 051
B - Sum of Three Integers
"""
if __name__ == "__main__":
    K, S = list(map(int, input().split()))
    ans = 0
    for x in range(K + 1):
        for y in range(K + 1):
            if x + y > S or S - (x + y) > K:
                continue
            ans += 1
    print(ans)

"""
AtCoder Beginner Contest 051
B - Sum of Three Integers
"""
if __name__ == "__main__":
    K, S = list(map(int, input().split()))
    ans = 0
    A = [i for i in range(K + 1)]
    for x in A:
        for y in A:
            if x + y > S or S - (x + y) > K:
                continue
            ans += 1
    print(ans)

-    for x in range(K + 1):
-        for y in range(K + 1):
+    A = [i for i in range(K + 1)]
+    for x in A:
+        for y in A:


Input:
import sys

import numba as nb

import numpy as np

input = sys.stdin.readline

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

def binary_search(a, key):

    """Meguru type binary search"""

    ng = -1

    ok = len(a)

    def is_ok(a, key, idx):

        if a[idx] > key:

            return True

        else:

            return False

    while (abs(ok - ng) > 1):

        mid = (ok + ng) // 2

        if is_ok(a, key, mid):

            ok = mid

        else:

            ng = mid

    return ok

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

def solve(N, A, B, C):

    A.sort()

    B.sort()

    C.sort()

    BC = np.zeros(shape=N + 1, dtype=np.int64)

    for i in range(N):

        BC[i] = N - binary_search(C, B[i])

    ans = 0

    for a in A:

        idx = binary_search(B, a)

        ans += np.sum(BC[idx:])

    return ans

def main():

    N = int(eval(input()))

    A = np.array(input().split(), dtype=np.int64)

    B = np.array(input().split(), dtype=np.int64)

    C = np.array(input().split(), dtype=np.int64)

    ans = solve(N, A, B, C)

    print(ans)

if __name__ == "__main__":

    main()

import sys

from bisect import bisect_left, bisect_right

input = sys.stdin.readline

def main():

    N = int(eval(input()))

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

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

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

    A.sort()

    B.sort()

    C.sort()

    ans = 0

    for b in B:

        n_a = bisect_left(A, b)

        n_c = N - bisect_right(C, b)

        ans += n_a * n_c

    print(ans)

if __name__ == "__main__":

    main()

import sys
import numba as nb
import numpy as np

input = sys.stdin.readline

@nb.njit("i8(i8[:],i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ng = -1
    ok = len(a)

    def is_ok(a, key, idx):
        if a[idx] > key:
            return True
        else:
            return False

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(a, key, mid):
            ok = mid
        else:
            ng = mid
    return ok

@nb.njit("i8(i8,i8[:],i8[:],i8[:])", cache=True)
def solve(N, A, B, C):
    A.sort()
    B.sort()
    C.sort()
    BC = np.zeros(shape=N + 1, dtype=np.int64)
    for i in range(N):
        BC[i] = N - binary_search(C, B[i])
    ans = 0
    for a in A:
        idx = binary_search(B, a)
        ans += np.sum(BC[idx:])
    return ans

def main():
    N = int(eval(input()))
    A = np.array(input().split(), dtype=np.int64)
    B = np.array(input().split(), dtype=np.int64)
    C = np.array(input().split(), dtype=np.int64)
    ans = solve(N, A, B, C)
    print(ans)

if __name__ == "__main__":
    main()

+from bisect import bisect_left, bisect_right

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

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

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

-    BC = np.zeros(shape=N + 1, dtype=np.int64)

-        BC[i] = N - binary_search(C, B[i])

-    A = np.array(input().split(), dtype=np.int64)

-    B = np.array(input().split(), dtype=np.int64)

-    C = np.array(input().split(), dtype=np.int64)


Input:
import numpy as np

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

#input

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

for _ in range(M):

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

    lst[R][L] += 1

lst = np.array(lst)

# print (lst)

#2次元累積和

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

    lst[:,i] += lst[:, i - 1]

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

    lst[j,:] += lst[j - 1, :]

#output

for _ in range(Q):

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

    print((lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1]))

# print (lst)

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

atlas=[[0]*(n+1) for _ in range(n+1)]

for _ in range(m):

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

    atlas[l][r] +=1

for i in range(n+1):

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

        atlas[i][j] +=atlas[i][j-1]

for i in range(n+1):

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

        atlas[i][j] +=atlas[i-1][j]

for p,q in [list(map(int,input().split())) for _ in range(q)]:

    print((atlas[q][q]-atlas[q][p-1]-atlas[p-1][q]+atlas[p-1][p-1]))

import numpy as np

N, M, Q = list(map(int, input().split()))
# input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = list(map(int, input().split()))
    lst[R][L] += 1
lst = np.array(lst)
# print (lst)
# 2次元累積和
for i in range(1, N + 1):
    lst[:, i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j, :] += lst[j - 1, :]
# output
for _ in range(Q):
    p, q = list(map(int, input().split()))
    print((lst[q, q] - lst[p - 1, q] - lst[q, p - 1] + lst[p - 1, p - 1]))
# print (lst)

n, m, q = list(map(int, input().split()))
atlas = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
    l, r = list(map(int, input().split()))
    atlas[l][r] += 1
for i in range(n + 1):
    for j in range(1, n + 1):
        atlas[i][j] += atlas[i][j - 1]
for i in range(n + 1):
    for j in range(1, n + 1):
        atlas[i][j] += atlas[i - 1][j]
for p, q in [list(map(int, input().split())) for _ in range(q)]:
    print((atlas[q][q] - atlas[q][p - 1] - atlas[p - 1][q] + atlas[p - 1][p - 1]))

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

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

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

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

+atlas = [[0] * (n + 1) for _ in range(n + 1)]

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

+for p, q in [list(map(int, input().split())) for _ in range(q)]:

+    print((atlas[q][q] - atlas[q][p - 1] - atlas[p - 1][q] + atlas[p - 1][p - 1]))


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

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

M = 998244353

from collections import Counter

if D[0] != 0:

    print((0))

    exit(0)

cd = Counter(D)

if cd[0] != 1:

    print((0))

    exit(0)

tmp = sorted(list(cd.items()), key=lambda x: x[0])

ans = 1

for kx in range(1, max(D)+1):

    ans *= pow(cd[kx-1], cd[kx],M)

    ans %= M

print(ans)

N = int(eval(input()))

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

M = 998244353

from collections import Counter

if D[0] != 0:

    print((0))

    exit(0)

cd = Counter(D)

if cd[0] != 1:

    print((0))

    exit(0)

tmp = sorted(list(cd.items()), key=lambda x: x[0])

ans = 1

for kx in range(1, max(D)+1):

    # __, p = tmp[kx-1]

    # _, v = tmp[kx]

    p = cd[kx-1]

    v = cd[kx]

    # print("{}^{}".format(p, v))

    while v > 0:

        ans *= p

        ans %= M

        v -= 1

# print(cd)

# for kx in range(1, max(D)+1):

#     ans *= pow(cd[kx-1], cd[kx],M)

#     ans %= M

print(ans)

N = int(eval(input()))
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print((0))
    exit(0)
cd = Counter(D)
if cd[0] != 1:
    print((0))
    exit(0)
tmp = sorted(list(cd.items()), key=lambda x: x[0])
ans = 1
for kx in range(1, max(D) + 1):
    ans *= pow(cd[kx - 1], cd[kx], M)
    ans %= M
print(ans)

N = int(eval(input()))
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print((0))
    exit(0)
cd = Counter(D)
if cd[0] != 1:
    print((0))
    exit(0)
tmp = sorted(list(cd.items()), key=lambda x: x[0])
ans = 1
for kx in range(1, max(D) + 1):
    # __, p = tmp[kx-1]
    # _, v = tmp[kx]
    p = cd[kx - 1]
    v = cd[kx]
    # print("{}^{}".format(p, v))
    while v > 0:
        ans *= p
        ans %= M
        v -= 1
# print(cd)
# for kx in range(1, max(D)+1):
#     ans *= pow(cd[kx-1], cd[kx],M)
#     ans %= M
print(ans)

-    ans *= pow(cd[kx - 1], cd[kx], M)
-    ans %= M
+    # __, p = tmp[kx-1]
+    # _, v = tmp[kx]
+    p = cd[kx - 1]
+    v = cd[kx]
+    # print("{}^{}".format(p, v))
+    while v > 0:
+        ans *= p
+        ans %= M
+        v -= 1
+# print(cd)
+# for kx in range(1, max(D)+1):
+#     ans *= pow(cd[kx-1], cd[kx],M)
+#     ans %= M


Input:
#!python3

import sys

iim = lambda: map(int, sys.stdin.readline().rstrip().split())

from functools import lru_cache

mod = 10 **9 + 7

@lru_cache(100)

def calc(n):

    m = (n-5) // 2

    #return (1+m)*(2+m)*(3+m)*(4+m)*(5+m)*(1025024*m**10+3003*(-4+n)*(-3+n)*(-2+n)*(-1+n)*n*(1+n)*(2+n)*(3+n)*(4+n)*(5+n)-549120*m**9*(-1+10*n)+42240*m**8*(-398+45*n*(-1+7*n))-369600*m**7*(3+2*(-2+n)*n*(49+26*n))+2688*m**6*(33529+75*n*(-33-679*n+91*n**3))-336*m**5*(88065+2*n*(426107+7*n*(-6675+13*n*(-2420+9*n*(5+22*n)))))+560*m**4*(-291598+n*(216249+7*n*(95465+26*n*(-495+n*(-980+11*n*(3+5*n))))))-30*m**3*(-3080960+n*(-10447602+7*n*(854525+13*n*(93170+n*(-15295+22*n*(-714+5*n*(7+6*n)))))))+2*m**2*(28412712+25*n*(-3433650+n*(-4123841+13*n*(189882+n*(142177+22*n*(-1344+n*(-791+27*n*(2+n))))))))-m*(30149280+n*(31294296+n*(-93275400+13*n*(-3808420+n*(2988195+11*n*(111678+25*n*(-1302+n*(-456+n*(45+14*n))))))))))/1307674368000

    return (

        (1+m)*(2+m)*(3+m)*(4+m)*(5+m)%mod*(

            1025024*pow(m,10,mod)+3003*(-4+n)%mod*(-3+n)%mod*(-2+n)%mod*(-1+n)*n*(1+n)%mod*(2+n)%mod*(3+n)%mod*(4+n)%mod*(5+n)%mod

            -549120*pow(m,9,mod)*(-1+10*n)%mod

            +42240*pow(m,8,mod)*(-398+45*n*(-1+7*n)%mod)%mod

            -369600*pow(m,7,mod)*(3+2*(-2+n)*n*(49+26*n)%mod)%mod

            +2688*pow(m,6,mod)*(33529+75*n*(-33-679*n+91*n**3)%mod)%mod

            -336*pow(m,5,mod)*(88065+2*n*(426107+7*n*(-6675+13*n*(-2420+9*n*(5+22*n)%mod)%mod)%mod)%mod)%mod

            +560*pow(m,4,mod)*(-291598+n*(216249+7*n*(95465+26*n*(-495+n*(-980+11*n*(3+5*n)%mod)%mod)%mod)%mod)%mod)%mod

            -30*pow(m,3,mod)*(-3080960+n*(-10447602+7*n*(854525+13*n*(93170+n*(-15295+22*n*(-714+5*n*(7+6*n)%mod)%mod)%mod)%mod)%mod)%mod)%mod

            +2*pow(m,2,mod)*(28412712+25*n*(-3433650+n*(-4123841+13*n*(189882+n*(142177+22*n*(-1344+n*(-791+27*n*(2+n)%mod)%mod)%mod)%mod)%mod)%mod)%mod)%mod

            -m*(30149280+n*(31294296+n*(-93275400+13*n*(-3808420+n*(2988195+11*n*(111678+25*n*(-1302+n*(-456+n*(45+14*n)%mod)%mod)%mod)%mod)%mod)%mod)%mod)%mod)%mod

        )%mod*pow(1307674368000%mod, mod-2, mod)%mod

    )

def resolve():

    it = map(int, sys.stdin.read().split())

    N = next(it)

    ans = [0] * N

    for i in range(N):

        n = next(it)

        ans[i] = calc(n)

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

if __name__ == "__main__":

    resolve()


Input:
import numpy as np

n = int(eval(input()))

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

As = sorted(A)

m = As[-1]

s = np.searchsorted(As,m/2)

d1 = abs(m/2-As[s])

d2 = abs(m/2-As[s-1])

if d1 >= d2:

    r = As[s-1]

else:

    r = As[s]

print((m,r))

n = int(eval(input()))

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

m = max(A)

min = float("inf")

for i in range(n):

  if min > abs(A[i] - m/2) and A[i] != m:

    min = abs(A[i] - m/2)

    r = A[i]

print((m,r))

import numpy as np

n = int(eval(input()))
A = list(map(int, input().split()))
As = sorted(A)
m = As[-1]
s = np.searchsorted(As, m / 2)
d1 = abs(m / 2 - As[s])
d2 = abs(m / 2 - As[s - 1])
if d1 >= d2:
    r = As[s - 1]
else:
    r = As[s]
print((m, r))

n = int(eval(input()))
A = list(map(int, input().split()))
m = max(A)
min = float("inf")
for i in range(n):
    if min > abs(A[i] - m / 2) and A[i] != m:
        min = abs(A[i] - m / 2)
        r = A[i]
print((m, r))

+    if min > abs(A[i] - m / 2) and A[i] != m:


Input:
N = int(input())

X = []

for i, x in enumerate(map(int, input().split())):

    X.append((x, i))

X.sort()

Y = [0] * N

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

    Y[i] = j

mid = N / 2

l = X[N // 2 - 1][0]

r = X[N // 2][0]

ans = []

for j in Y:

    if j < mid:

        ans.append(r)

    else:

        ans.append(l)

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

N = int(eval(input()))

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

order = {}

for idx, x in enumerate(X):

    order[idx] = x

X.sort()

m = N // 2

l = X[m - 1]

r = X[m]

for idx in range(N):

    x = order[idx]

    if x <= l:

        print(r)

    else:

        print(l)

N = int(input())
X = []
for i, x in enumerate(map(int, input().split())):
    X.append((x, i))
X.sort()
Y = [0] * N
for j, (x, i) in enumerate(X):
    Y[i] = j
mid = N / 2
l = X[N // 2 - 1][0]
r = X[N // 2][0]
ans = []
for j in Y:
    if j < mid:
        ans.append(r)
    else:
        ans.append(l)
print(*ans, sep="\n")

-for i, x in enumerate(map(int, input().split())):


Input:
from operator import mul

from functools import reduce

nCr = {}

def cmb(n, r):

    if r == 0 or r == n: return 1

    if r == 1: return n

    if (n,r) in nCr: return nCr[(n,r)]

    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)

    return nCr[(n,r)]

a = int(eval(input()))

b = [0 for i in range(15)]

j = 0

c = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]

d = [0 for i in range(101)]

p = 0

pp = 0

g = 0

gg = 0

ggg = 0

co = 0

for i in range(1,101):

  k = i

  while True:

    if k % c[j] == 0 and k >= c[j]:

      b[j] += 1

      k //= c[j]

    else:

      j += 1

      if j == 15:

        j = 0

        break

  for k in range(15):

    if b[k] >= 74:

      g += 1

    if b[k] >= 24:

      gg += 1

    if b[k] >= 14:

      ggg += 1

    if b[k] >= 4:

      p += 1

    if b[k] >= 2:

      pp += 1

  if i >= 10:

    d[i] = cmb(p, 2)*cmb((pp-2), 1) + cmb(g, 1) + cmb(gg, 1)*cmb((pp-1), 1) + cmb(ggg, 1)*cmb((p-1), 1)

  p = 0

  pp = 0

  g = 0

  gg = 0

  ggg = 0

print((d[a]))

def cmb(n, r):

    if n - r < r: r = n - r

    if n <= 0: return 0

    if r == 0: return 1

    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]

    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):

        pivot = denominator[p - 1]

        if pivot > 1:

            offset = (n - r) % p;

            for k in range(p-1,r,p):

                numerator[k - offset] //= pivot

                denominator[k] //= pivot

    result = 1

    for k in range(r):

        if numerator[k] > 1:

            result *= int(numerator[k])

    return result

a = int(eval(input()))

b = [0 for i in range(15)]

j = 0

c = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]

d = [0 for i in range(101)]

p = 0

pp = 0

g = 0

gg = 0

ggg = 0

co = 0

for i in range(1,101):

  k = i

  while True:

    if k % c[j] == 0 and k >= c[j]:

      b[j] += 1

      k //= c[j]

    else:

      j += 1

      if j == 15:

        j = 0

        break

  for k in range(15):

    if b[k] >= 74:

      g += 1

    if b[k] >= 24:

      gg += 1

    if b[k] >= 14:

      ggg += 1

    if b[k] >= 4:

      p += 1

    if b[k] >= 2:

      pp += 1

  if i >= 10:

    d[i] = cmb(p, 2)*cmb((pp-2), 1) + cmb(g, 1) + cmb(gg, 1)*cmb((pp-1), 1) + cmb(ggg, 1)*cmb((p-1), 1)

  p = 0

  pp = 0

  g = 0

  gg = 0

  ggg = 0

print((d[a]))

from operator import mul
from functools import reduce

nCr = {}

def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
    return nCr[(n, r)]

a = int(eval(input()))
b = [0 for i in range(15)]
j = 0
c = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
d = [0 for i in range(101)]
p = 0
pp = 0
g = 0
gg = 0
ggg = 0
co = 0
for i in range(1, 101):
    k = i
    while True:
        if k % c[j] == 0 and k >= c[j]:
            b[j] += 1
            k //= c[j]
        else:
            j += 1
            if j == 15:
                j = 0
                break
    for k in range(15):
        if b[k] >= 74:
            g += 1
        if b[k] >= 24:
            gg += 1
        if b[k] >= 14:
            ggg += 1
        if b[k] >= 4:
            p += 1
        if b[k] >= 2:
            pp += 1
    if i >= 10:
        d[i] = (
            cmb(p, 2) * cmb((pp - 2), 1)
            + cmb(g, 1)
            + cmb(gg, 1) * cmb((pp - 1), 1)
            + cmb(ggg, 1) * cmb((p - 1), 1)
        )
    p = 0
    pp = 0
    g = 0
    gg = 0
    ggg = 0
print((d[a]))

def cmb(n, r):
    if n - r < r:
        r = n - r
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r == 1:
        return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result

a = int(eval(input()))
b = [0 for i in range(15)]
j = 0
c = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
d = [0 for i in range(101)]
p = 0
pp = 0
g = 0
gg = 0
ggg = 0
co = 0
for i in range(1, 101):
    k = i
    while True:
        if k % c[j] == 0 and k >= c[j]:
            b[j] += 1
            k //= c[j]
        else:
            j += 1
            if j == 15:
                j = 0
                break
    for k in range(15):
        if b[k] >= 74:
            g += 1
        if b[k] >= 24:
            gg += 1
        if b[k] >= 14:
            ggg += 1
        if b[k] >= 4:
            p += 1
        if b[k] >= 2:
            pp += 1
    if i >= 10:
        d[i] = (
            cmb(p, 2) * cmb((pp - 2), 1)
            + cmb(g, 1)
            + cmb(gg, 1) * cmb((pp - 1), 1)
            + cmb(ggg, 1) * cmb((p - 1), 1)
        )
    p = 0
    pp = 0
    g = 0
    gg = 0
    ggg = 0
print((d[a]))

+    numerator = [n - r + k + 1 for k in range(r)]

+    denominator = [k + 1 for k in range(r)]

+            for k in range(p - 1, r, p):

+                numerator[k - offset] //= pivot

+                denominator[k] //= pivot

+            result *= int(numerator[k])


Input:
import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

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

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

indeg = [0 for _ in range(n)]

for _ in range(m):

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

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

    indeg[y-1] += 1

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

def LP(v):

    if dp[v] != -1:

        return dp[v]

    ans = 0

    for w in g[v]:

        ans = max(ans, LP(w)+1)

    dp[v] = ans

    return dp[v]

for i in range(n):

    LP(i)

print((max(dp)))

from collections import deque

import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

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

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

indeg = [0 for _ in range(n)]

for _ in range(m):

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

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

    indeg[y-1] += 1

dp = [0 for _ in range(n)]

q = deque([])

for i in range(n):

    if indeg[i] == 0:

        q.append(i)

while q:

    v = q.popleft()

    for w in g[v]:

        indeg[w] -= 1

        if indeg[w] == 0:

            q.append(w)

            dp[w] = max(dp[w], dp[v]+1)

print((max(dp)))

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
indeg = [0 for _ in range(n)]
for _ in range(m):
    x, y = list(map(int, input().split()))
    g[x - 1].append(y - 1)
    indeg[y - 1] += 1
dp = [-1 for _ in range(n)]

def LP(v):
    if dp[v] != -1:
        return dp[v]
    ans = 0
    for w in g[v]:
        ans = max(ans, LP(w) + 1)
    dp[v] = ans
    return dp[v]

for i in range(n):
    LP(i)
print((max(dp)))

from collections import deque
import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
indeg = [0 for _ in range(n)]
for _ in range(m):
    x, y = list(map(int, input().split()))
    g[x - 1].append(y - 1)
    indeg[y - 1] += 1
dp = [0 for _ in range(n)]
q = deque([])
for i in range(n):
    if indeg[i] == 0:
        q.append(i)
while q:
    v = q.popleft()
    for w in g[v]:
        indeg[w] -= 1
        if indeg[w] == 0:
            q.append(w)
            dp[w] = max(dp[w], dp[v] + 1)
print((max(dp)))


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

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

for i in range(1,N):

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

        A[int(min(j-i,abs(X-i)+abs(Y-j)+1))].append(1)

for i in range(N):

    if i!=0:

        print((sum(A[i])))

N,X,Y=list(map(int,input().split()))

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

for i in range(1,N):

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

        A[int(min(j-i,abs(X-i)+abs(Y-j)+1))]+=1

del A[0]

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

N, X, Y = list(map(int, input().split()))
A = [[] for i in range(N + 1)]
for i in range(1, N):
    for j in range(i, N + 1):
        A[int(min(j - i, abs(X - i) + abs(Y - j) + 1))].append(1)
for i in range(N):
    if i != 0:
        print((sum(A[i])))

N, X, Y = list(map(int, input().split()))
A = [0 for i in range(N)]
for i in range(1, N):
    for j in range(i + 1, N + 1):
        A[int(min(j - i, abs(X - i) + abs(Y - j) + 1))] += 1
del A[0]
print(*A, sep=("\n"))

-        A[int(min(j - i, abs(X - i) + abs(Y - j) + 1))].append(1)


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

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

d={}

for i in range(N):

    d[i+1]=Students[i]

d_2 = sorted(list(d.items()),key=lambda x: x[1])

ans=[]

for k in d_2:

    ans.append(k[0])

print((*ans))

n=int(eval(input()))

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

b=[]

for i in range(n):

    tmp=[i+1,a[i]]

    b.append(tmp)

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

ans=[]

for j in b:

    ans.append(j[0])

print((*ans))

N = int(eval(input()))
Students = list(map(int, input().split()))
d = {}
for i in range(N):
    d[i + 1] = Students[i]
d_2 = sorted(list(d.items()), key=lambda x: x[1])
ans = []
for k in d_2:
    ans.append(k[0])
print((*ans))

n = int(eval(input()))
a = list(map(int, input().split()))
b = []
for i in range(n):
    tmp = [i + 1, a[i]]
    b.append(tmp)
b = sorted(b, key=lambda x: x[1])
ans = []
for j in b:
    ans.append(j[0])
print((*ans))

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

-d_2 = sorted(list(d.items()), key=lambda x: x[1])


Input:
n = int(input())

ss = "abcdefghijklmnopqrstuvwxyz"

dmin = {}

for s in ss:

  dmin[s] = 51

for i in range(n):

  S = input()

  d ={}

  for s in S:

    if s not in d.keys():

      d[s] = 1

    else:

      d[s] += 1

  for s in ss:

    if s not in d.keys():

      dmin[s] = 0

  for s in d.keys():

    dmin[s] = min(dmin[s], d[s])

for k in dmin.keys():

  print(k*dmin[k],sep="",end="")

print()

n = int(input())
ss = "abcdefghijklmnopqrstuvwxyz"
dmin = {}
for s in ss:
    dmin[s] = 51
for i in range(n):
    S = input()
    d = {}
    for s in S:
        if s not in d.keys():
            d[s] = 1
        else:
            d[s] += 1
    for s in ss:
        if s not in d.keys():
            dmin[s] = 0
    for s in d.keys():
        dmin[s] = min(dmin[s], d[s])
for k in dmin.keys():
    print(k * dmin[k], sep="", end="")
print()


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

x1 = max([int(i) for i in input().split()]) + 1

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

if x1 <= y1 and x1 <= y and y1 > x:

    print('No War')

else:

    print('War')

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

x1 = max(list(map(int,input().split()))) + 1

y1 = min(list(map(int,input().split())))

if x1 <= y1 and x1 <= y and y1 > x:

    print('No War')

else:

    print('War')

n, m, x, y = list(map(int, input().split()))
x1 = max([int(i) for i in input().split()]) + 1
y1 = min([int(i) for i in input().split()])
if x1 <= y1 and x1 <= y and y1 > x:
    print("No War")
else:
    print("War")

n, m, x, y = list(map(int, input().split()))
x1 = max(list(map(int, input().split()))) + 1
y1 = min(list(map(int, input().split())))
if x1 <= y1 and x1 <= y and y1 > x:
    print("No War")
else:
    print("War")

-x1 = max([int(i) for i in input().split()]) + 1

-y1 = min([int(i) for i in input().split()])

+x1 = max(list(map(int, input().split()))) + 1

+y1 = min(list(map(int, input().split())))


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

l = []

for i in range(n):

  if (i+1)%3 != 0 and (i+1)%5 != 0:

    l.append(i+1)

  else:

    l.append(0)

print((sum(l)))

n = int(eval(input()))

ans = 0

for i in range(n+1):

  if i%3 == 0 or i%5 == 0:

    ans += 0

  else:

    ans += i

print(ans)

n = int(eval(input()))
l = []
for i in range(n):
    if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:
        l.append(i + 1)
    else:
        l.append(0)
print((sum(l)))

n = int(eval(input()))
ans = 0
for i in range(n + 1):
    if i % 3 == 0 or i % 5 == 0:
        ans += 0
    else:
        ans += i
print(ans)


Input:
# !入力

# グラフの構築

# クエリの入力

# Kからの各点のの距離をdfs

# クエリの処理

from collections import deque

n=int(eval(input()))

edge=[[]for _ in range(n)]

for i in range(n-1):

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

  edge[a-1].append((b-1,c))

  edge[b-1].append((a-1,c))

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

dist=[0]*n

seen=[False]*n

todo=deque([k-1])

while todo:

  par=todo.pop()

  seen[par]=True

  for cld,cost in edge[par]:

    if dist[cld]==0:

      if seen[cld]==False:

        dist[cld]=dist[par]+cost

        seen[cld]=True

        todo.append(cld)

for i in range(q):

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

  print((dist[x-1]+dist[y-1]))

# !入力

# グラフの構築

# クエリの入力

# Kからの各点のの距離をdfs

# クエリの処理

from collections import deque

n=int(eval(input()))

edge=[[]for _ in range(n)]

for i in range(n-1):

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

  edge[a-1].append((b-1,c))

  edge[b-1].append((a-1,c))

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

dist=[0]*n

seen=[False]*n

todo=deque([k-1])

while todo:

  par=todo.popleft()

  seen[par]=True

  for cld,cost in edge[par]:

    if dist[cld]==0:

      if seen[cld]==False:

        dist[cld]=dist[par]+cost

        seen[cld]=True

        todo.append(cld)

for i in range(q):

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

  print((dist[x-1]+dist[y-1]))

# !入力
# グラフの構築
# クエリの入力
# Kからの各点のの距離をdfs
# クエリの処理
from collections import deque

n = int(eval(input()))
edge = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    edge[a - 1].append((b - 1, c))
    edge[b - 1].append((a - 1, c))
q, k = list(map(int, input().split()))
dist = [0] * n
seen = [False] * n
todo = deque([k - 1])
while todo:
    par = todo.pop()
    seen[par] = True
    for cld, cost in edge[par]:
        if dist[cld] == 0:
            if seen[cld] == False:
                dist[cld] = dist[par] + cost
                seen[cld] = True
                todo.append(cld)
for i in range(q):
    x, y = list(map(int, input().split()))
    print((dist[x - 1] + dist[y - 1]))

# !入力
# グラフの構築
# クエリの入力
# Kからの各点のの距離をdfs
# クエリの処理
from collections import deque

n = int(eval(input()))
edge = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    edge[a - 1].append((b - 1, c))
    edge[b - 1].append((a - 1, c))
q, k = list(map(int, input().split()))
dist = [0] * n
seen = [False] * n
todo = deque([k - 1])
while todo:
    par = todo.popleft()
    seen[par] = True
    for cld, cost in edge[par]:
        if dist[cld] == 0:
            if seen[cld] == False:
                dist[cld] = dist[par] + cost
                seen[cld] = True
                todo.append(cld)
for i in range(q):
    x, y = list(map(int, input().split()))
    print((dist[x - 1] + dist[y - 1]))

-    par = todo.pop()
+    par = todo.popleft()


Input:
# coding: utf-8

import sys

N = int(eval(input()))

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

btn = 1

cnt = 0

for a in lst:

    btn = lst[btn-1]

    cnt += 1

    if btn == 2:

        print(cnt)

        sys.exit()

print((-1))

# coding: utf-8

import sys

N = int(eval(input()))

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

btn = 1

cnt = 0

for a in lst:

    btn = lst[btn-1]

    cnt += 1

    if btn == 2:

        print(cnt)

        sys.exit()

print((-1))

# coding: utf-8
import sys

N = int(eval(input()))
lst = [int(eval(input())) for _ in range(N)]
btn = 1
cnt = 0
for a in lst:
    btn = lst[btn - 1]
    cnt += 1
    if btn == 2:
        print(cnt)
        sys.exit()
print((-1))

# coding: utf-8
import sys

N = int(eval(input()))
lst = [int(i) for i in sys.stdin]
btn = 1
cnt = 0
for a in lst:
    btn = lst[btn - 1]
    cnt += 1
    if btn == 2:
        print(cnt)
        sys.exit()
print((-1))

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


Input:
import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

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

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

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

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

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

MOD = 10 ** 9 + 7

N, Q = MAP()

S = eval(input())

lr = [LIST() for _ in range(Q)]

accum = []

count = 0

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

	accum.append(count)

	if S[i] == "A" and S[i+1] == "C":

		count += 1

accum.append(count)

# print(accum)

for l, r in lr:

	print((accum[r-1]-accum[l-1]))

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import accumulate, permutations, combinations, product

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

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

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

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

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

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

N, Q = MAP()

S = eval(input())

lis = [0]*N

count = 0

for i in range(N-1):

	if S[i] == "A" and S[i+1] == "C":

		lis[i+1] = 1

lis_acc = list(accumulate(lis))

for _ in range(Q):

	l, r = MAP()

	print((lis_acc[r-1]-lis_acc[l-1]))

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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

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

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

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

sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N, Q = MAP()
S = eval(input())
lr = [LIST() for _ in range(Q)]
accum = []
count = 0
for i in range(len(S) - 1):
    accum.append(count)
    if S[i] == "A" and S[i + 1] == "C":
        count += 1
accum.append(count)
# print(accum)
for l, r in lr:
    print((accum[r - 1] - accum[l - 1]))

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

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

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

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

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

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N, Q = MAP()
S = eval(input())
lis = [0] * N
count = 0
for i in range(N - 1):
    if S[i] == "A" and S[i + 1] == "C":
        lis[i + 1] = 1
lis_acc = list(accumulate(lis))
for _ in range(Q):
    l, r = MAP()
    print((lis_acc[r - 1] - lis_acc[l - 1]))

-from itertools import permutations, combinations, product

+from itertools import accumulate, permutations, combinations, product

-    print((accum[r - 1] - accum[l - 1]))

+    print((lis_acc[r - 1] - lis_acc[l - 1]))


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

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

cnt = 1

ans = 0

for i in range(n):

    if a[i] != cnt:

        ans += 1

    else:

        cnt += 1

if ans == n:

    print((-1))

else:

    print(ans)

n = int(eval(input()))

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

ans = 0

cnt = 1

for i in a:

    if cnt == i:

        cnt += 1

    else:

        ans += 1

if ans == n:

    print((-1))

else:

    print(ans)

+ans = 0
-ans = 0
-for i in range(n):
-    if a[i] != cnt:
+for i in a:
+    if cnt == i:
+        cnt += 1
+    else:
-    else:
-        cnt += 1


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

cnt = 0

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

    if i%d==0: cnt += 1

print(cnt)

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

print((r//d - (l-1)//d))

l, r, d = list(map(int, input().split()))
cnt = 0
for i in range(l, r + 1):
    if i % d == 0:
        cnt += 1
print(cnt)

l, r, d = list(map(int, input().split()))
print((r // d - (l - 1) // d))

-cnt = 0
-for i in range(l, r + 1):
-    if i % d == 0:
-        cnt += 1
-print(cnt)
+print((r // d - (l - 1) // d))


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

a=[0]+list(map(int,input().split()))

p=[]

for i in range(n):

	a[i+1]+=a[i]

for i in range(n+1):

	for j in range(i):

		p.append(a[i]-a[j])

p.sort(reverse=True)

ans=0

from math import log,ceil

r=ceil(log(sum(p))+10**-3)

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

	cnt=0

	for j in range(len(p)):

		if (ans+2**i)&p[j]==ans+2**i:

			cnt+=1

		if cnt==k:

			break

	if cnt==k:

		ans+=2**i

print(ans)

def main():

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

	a=[0]+list(map(int,input().split()))

	p=[]

	for i in range(n):

		a[i+1]+=a[i]

	for i in range(n+1):

		for j in range(i):

			p.append(a[i]-a[j])

	p.sort()

	ans=0

	from math import log,ceil

	r=ceil(log(sum(p))+10**-3)

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

		cnt=0

		for j in range(len(p)):

			if (ans+2**i)&p[j]==ans+2**i:

				cnt+=1

				if cnt==k:

					break

		if cnt==k:

			ans+=2**i

	print(ans)

if __name__ == '__main__':

	main()

n, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
p = []
for i in range(n):
    a[i + 1] += a[i]
for i in range(n + 1):
    for j in range(i):
        p.append(a[i] - a[j])
p.sort(reverse=True)
ans = 0
from math import log, ceil

r = ceil(log(sum(p)) + 10**-3)
for i in range(r + 3, -1, -1):
    cnt = 0
    for j in range(len(p)):
        if (ans + 2**i) & p[j] == ans + 2**i:
            cnt += 1
        if cnt == k:
            break
    if cnt == k:
        ans += 2**i
print(ans)

def main():
    n, k = list(map(int, input().split()))
    a = [0] + list(map(int, input().split()))
    p = []
    for i in range(n):
        a[i + 1] += a[i]
    for i in range(n + 1):
        for j in range(i):
            p.append(a[i] - a[j])
    p.sort()
    ans = 0
    from math import log, ceil

    r = ceil(log(sum(p)) + 10**-3)
    for i in range(r + 2, -1, -1):
        cnt = 0
        for j in range(len(p)):
            if (ans + 2**i) & p[j] == ans + 2**i:
                cnt += 1
                if cnt == k:
                    break
        if cnt == k:
            ans += 2**i
    print(ans)

if __name__ == "__main__":
    main()

-a = [0] + list(map(int, input().split()))

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

+    a = [0] + list(map(int, input().split()))


Input:
from itertools import combinations

N, X, Y = list(map(int, input().split()))

A = [0] * N

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

    A[min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(X - j) + abs(Y - i) + 1)] += 1

for a in A[1:]:

    print(a)

from itertools import combinations

from collections import Counter

N, X, Y = list(map(int, input().split()))

C = Counter(min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(X - j) + abs(Y - i) + 1) for i, j in combinations(list(range(1, N + 1)), 2))

print(("\n".join(str(C[k]) for k in range(1, N))))

from itertools import combinations
from collections import Counter

N, X, Y = list(map(int, input().split()))
C = Counter(
    min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(X - j) + abs(Y - i) + 1)
    for i, j in combinations(list(range(1, N + 1)), 2)
)
print(("\n".join(str(C[k]) for k in range(1, N))))

-for i, j in combinations(list(range(1, N + 1)), 2):

+    min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(X - j) + abs(Y - i) + 1)

+    for i, j in combinations(list(range(1, N + 1)), 2)

+print(("\n".join(str(C[k]) for k in range(1, N))))


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

print((C if B // A > C else B // A))

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

print((min(C, B // A)))

-print((C if B // A > C else B // A))
+print((min(C, B // A)))


Input:
def main():

    x = int(eval(input()))

    for a in range(-120, 121):

        for b in range(-120, 121):

            if (a**5-b**5==x):

                print((a, b))

                exit(0)

if __name__ == "__main__":

    main()

def main():

    x = int(eval(input()))

    for i in range(-120, 121):

        for j in range(-120, 121):

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

                print((i, j))

                exit(0)

if __name__ == "__main__":

    main()

def main():
    x = int(eval(input()))
    for a in range(-120, 121):
        for b in range(-120, 121):
            if a**5 - b**5 == x:
                print((a, b))
                exit(0)

if __name__ == "__main__":
    main()


Input:
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

def calcGroup(s):

  whiteCount = 0

  blackCount = 0

  prev = ""

  for i in range(len(s)):

    if s[i] == prev:

      pass

    else:

      if s[i] == "W":

        whiteCount += 1

      elif s[i] == "B":

        blackCount += 1

      else:

        raise ValueError

    prev = s[i]

  return whiteCount,blackCount

# @njit

def solve(s):

  white,black = calcGroup(s)

  if abs(white-black) == 0:

    return (white-1)*2+1

  else:

    return min(white,black)*2

def main():

  s = eval(input())

  print((solve(s)))

  return

if __name__ == '__main__':

  main()

#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

def calcDivision(s):

  res = 0

  prev = ""

  for i in range(len(s)):

    if s[i] == prev:

      pass

    else:

      if prev == "":

        pass

      else:

        res += 1

    prev = s[i]

  return res

# @njit

def solve(s):

  return calcDivision(s)

def main():

  s = eval(input())

  print((solve(s)))

  return

if __name__ == '__main__':

  main()

#!/usr/bin/env python3
# from numba import njit
# input = stdin.readline
def calcGroup(s):
    whiteCount = 0
    blackCount = 0
    prev = ""
    for i in range(len(s)):
        if s[i] == prev:
            pass
        else:
            if s[i] == "W":
                whiteCount += 1
            elif s[i] == "B":
                blackCount += 1
            else:
                raise ValueError
        prev = s[i]
    return whiteCount, blackCount

# @njit
def solve(s):
    white, black = calcGroup(s)
    if abs(white - black) == 0:
        return (white - 1) * 2 + 1
    else:
        return min(white, black) * 2

def main():
    s = eval(input())
    print((solve(s)))
    return

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
# from numba import njit
# input = stdin.readline
def calcDivision(s):
    res = 0
    prev = ""
    for i in range(len(s)):
        if s[i] == prev:
            pass
        else:
            if prev == "":
                pass
            else:
                res += 1
        prev = s[i]
    return res

# @njit
def solve(s):
    return calcDivision(s)

def main():
    s = eval(input())
    print((solve(s)))
    return

if __name__ == "__main__":
    main()

-def calcGroup(s):
-    whiteCount = 0
-    blackCount = 0
+def calcDivision(s):
+    res = 0
-            if s[i] == "W":
-                whiteCount += 1
-            elif s[i] == "B":
-                blackCount += 1
+            if prev == "":
+                pass
-                raise ValueError
+                res += 1
-    return whiteCount, blackCount
+    return res
-    white, black = calcGroup(s)
-    if abs(white - black) == 0:
-        return (white - 1) * 2 + 1
-    else:
-        return min(white, black) * 2
+    return calcDivision(s)


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

set1 = set([int(eval(input())) for i in range(cnt)])

print((len(set1)))

n= int(eval(input()))

lst = [0] * (100 + 1)

for i in range(n):

    lst[int(eval(input()))] = 1

ans = 0

for j in lst:

    ans += j

print(ans)

n = int(eval(input()))
lst = [0] * (100 + 1)
for i in range(n):
    lst[int(eval(input()))] = 1
ans = 0
for j in lst:
    ans += j
print(ans)

-set1 = set([int(eval(input())) for i in range(cnt)])


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

d = {str(x) for x in input().split()}

a = {int(x) for x in range(10)}

l = a - d

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

    i2 = str(i)

    for j in range(len(i2))[::-1]:

        if i2[j] in d:

            break

    else:

        print(i2)

        break

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

d = {str(x) for x in input().split()}

a = {str(x) for x in range(10)}

l = a - d

while True:

    if all(j in l for j in str(n)):

        print(n)

        break

    else:

        n += 1

n, k = list(map(int, input().split()))
d = {str(x) for x in input().split()}
a = {int(x) for x in range(10)}
l = a - d
for i in range(n, 100000 + 1):
    i2 = str(i)
    for j in range(len(i2))[::-1]:
        if i2[j] in d:
            break
    else:
        print(i2)
        break

-a = {int(x) for x in range(10)}
+a = {str(x) for x in range(10)}
-for i in range(n, 100000 + 1):
-    i2 = str(i)
-    for j in range(len(i2))[::-1]:
-        if i2[j] in d:
-            break
+while True:
+    if all(j in l for j in str(n)):
+        print(n)
+        break
-        print(i2)
-        break
+        n += 1