Input:
import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007

# Reference: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/

# Python3 code to find number of

# distinct numbers in a subarray

MAX = 1000001

# structure to store queries

class Query:

    def __init__(self, l, r, idx):

        self.l = l

        self.r = r

        self.idx = idx

# updating the bit array

def update(idx, val, bit, n):

    while idx <= n:

        bit[idx] += val

        idx += idx & -idx

# querying the bit array

def query(idx, bit, n):

    summ = 0

    while idx:

        summ += bit[idx]

        idx -= idx & -idx

    return summ

def answeringQueries(arr, n, queries, q):

    # initialising bit array

    bit = [0] * (n + 1)

    # holds the rightmost index of

    # any number as numbers of a[i]

    # are less than or equal to 10^6

    last_visit = [-1] * MAX

    # answer for each query

    ans = [0] * q

    query_counter = 0

    for i in range(n):

        # If last visit is not -1 update -1 at the

        # idx equal to last_visit[arr[i]]

        if last_visit[arr[i]] != -1:

            update(last_visit[arr[i]] + 1, -1, bit, n)

        # Setting last_visit[arr[i]] as i and

        # updating the bit array accordingly

        last_visit[arr[i]] = i

        update(i + 1, 1, bit, n)

        # If i is equal to r of any query store answer

        # for that query in ans[]

        while query_counter < q and queries[query_counter].r == i:

            ans[queries[query_counter].idx] = query(queries[query_counter].r + 1, bit, n) - query(

                queries[query_counter].l, bit, n

            )

            query_counter += 1

    # print answer for each query

    for i in range(q):

        print((ans[i]))

# This code is contributed by

# sanjeev2552

def main():

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

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

    (*LR,) = list(map(int, read().split()))

    queries = [0] * Q

    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):

        queries[i] = Query(l - 1, r - 1, i)

    queries.sort(key=lambda x: x.r)

    answeringQueries(C, N, queries, Q)

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007

class BIT:

    def __init__(self, n):

        self.n = n

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

    def add(self, i, x=1):

        i += 1

        while i <= self.n:

            self.data[i] += x

            i += i & -i

    def get_sum(self, i):

        i += 1

        x = 0

        while i > 0:

            x += self.data[i]

            i -= i & -i

        return x

    # Return sum for [l, r)

    def get_sum_range(self, l, r):

        return self.get_sum(r - 1) - self.get_sum(l - 1)

def main():

    N, Q = map(int, readline().split())

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

    LR = map(int, read().split())

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

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

    for i, c in enumerate(C):

        if prev[c] != -1:

            ps[prev[c]].append(i)

        prev[c] = i

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

    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):

        l -= 1

        r -= 1

        qs[l].append((r, i))

    ans = [0] * Q

    bit = BIT(N)

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

        for r in ps[l]:

            bit.add(r)

        for r, i in qs[l]:

            ans[i] = (r - l + 1) - bit.get_sum(r)

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

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
# Reference: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/
# Python3 code to find number of
# distinct numbers in a subarray
MAX = 1000001
# structure to store queries
class Query:
    def __init__(self, l, r, idx):
        self.l = l
        self.r = r
        self.idx = idx

# updating the bit array
def update(idx, val, bit, n):
    while idx <= n:
        bit[idx] += val
        idx += idx & -idx

# querying the bit array
def query(idx, bit, n):
    summ = 0
    while idx:
        summ += bit[idx]
        idx -= idx & -idx
    return summ

def answeringQueries(arr, n, queries, q):
    # initialising bit array
    bit = [0] * (n + 1)
    # holds the rightmost index of
    # any number as numbers of a[i]
    # are less than or equal to 10^6
    last_visit = [-1] * MAX
    # answer for each query
    ans = [0] * q
    query_counter = 0
    for i in range(n):
        # If last visit is not -1 update -1 at the
        # idx equal to last_visit[arr[i]]
        if last_visit[arr[i]] != -1:
            update(last_visit[arr[i]] + 1, -1, bit, n)
        # Setting last_visit[arr[i]] as i and
        # updating the bit array accordingly
        last_visit[arr[i]] = i
        update(i + 1, 1, bit, n)
        # If i is equal to r of any query store answer
        # for that query in ans[]
        while query_counter < q and queries[query_counter].r == i:
            ans[queries[query_counter].idx] = query(
                queries[query_counter].r + 1, bit, n
            ) - query(queries[query_counter].l, bit, n)
            query_counter += 1
    # print answer for each query
    for i in range(q):
        print((ans[i]))

# This code is contributed by
# sanjeev2552
def main():
    N, Q = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    (*LR,) = list(map(int, read().split()))
    queries = [0] * Q
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        queries[i] = Query(l - 1, r - 1, i)
    queries.sort(key=lambda x: x.r)
    answeringQueries(C, N, queries, Q)
    return

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)

def main():
    N, Q = map(int, readline().split())
    C = list(map(int, readline().split()))
    LR = map(int, read().split())
    prev = [-1] * (N + 1)
    ps = [[] for _ in range(N)]
    for i, c in enumerate(C):
        if prev[c] != -1:
            ps[prev[c]].append(i)
        prev[c] = i
    qs = [[] for _ in range(N + 1)]
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        l -= 1
        r -= 1
        qs[l].append((r, i))
    ans = [0] * Q
    bit = BIT(N)
    for l in range(N - 1, -1, -1):
        for r in ps[l]:
            bit.add(r)
        for r, i in qs[l]:
            ans[i] = (r - l + 1) - bit.get_sum(r)
    print(*ans, sep="\n")
    return

if __name__ == "__main__":
    main()

+        return self.get_sum(r - 1) - self.get_sum(l - 1)

-def answeringQueries(arr, n, queries, q):

-        # If last visit is not -1 update -1 at the

-        # idx equal to last_visit[arr[i]]

-            update(last_visit[arr[i]] + 1, -1, bit, n)

-        # Setting last_visit[arr[i]] as i and

-        # updating the bit array accordingly

-        # If i is equal to r of any query store answer

-        while query_counter < q and queries[query_counter].r == i:

-            ans[queries[query_counter].idx] = query(

-                queries[query_counter].r + 1, bit, n

-            ) - query(queries[query_counter].l, bit, n)

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

+    N, Q = map(int, readline().split())

-    (*LR,) = list(map(int, read().split()))

-        queries[i] = Query(l - 1, r - 1, i)

+            ans[i] = (r - l + 1) - bit.get_sum(r)


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

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

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

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

asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)

print((asort[0] + bsort[0] + csort[0]))

already = [[0,0,0]]

x,y,z = 0,0,0

place_sum = []

check = []

for k in range(K - 1):

    if [x + 1,y,z] not in already and x + 1 < X:

        already.append([x + 1,y,z])

        place_sum.append([x + 1,y,z])

        check.append(asort[x + 1] + bsort[y] + csort[z])

    if [x,y + 1,z] not in already and y + 1 < Y:

        already.append([x,y + 1,z])

        place_sum.append([x,y + 1,z])

        check.append(asort[x] + bsort[y + 1] + csort[z])

    if [x,y,z + 1] not in already and z + 1 < Z:

        already.append([x,y,z + 1])

        place_sum.append([x,y,z + 1])

        check.append(asort[x] + bsort[y] + csort[z + 1])

    print((max(check)))

    x,y,z = place_sum[check.index(max(check))][0],place_sum[check.index(max(check))][1],place_sum[check.index(max(check))][2]

    place_sum.pop(check.index(max(check)))

    check.remove(max(check))

import heapq

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

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

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

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

asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)

already = [[0,0,0]]

print((asort[0] + bsort[0] + csort[0]))

x,y,z = 0,0,0

check = []

for k in range(K - 1):

    if [x + 1,y,z] not in already and x + 1 < X:

        already.append([x + 1,y,z])

        heapq.heappush(check,(-(asort[x + 1] + bsort[y] + csort[z]),x + 1,y,z))

    if [x,y + 1,z] not in already and y + 1 < Y:

        already.append([x,y + 1,z])

        heapq.heappush(check,(-(asort[x] + bsort[y + 1] + csort[z]),x,y + 1,z))

    if [x,y,z + 1] not in already and z + 1 < Z:

        already.append([x,y,z + 1])

        heapq.heappush(check,(-(asort[x] + bsort[y] + csort[z + 1]),x,y,z + 1))

    maxsum = heapq.heappop(check)

    print((-maxsum[0]))

    x,y,z = maxsum[1],maxsum[2],maxsum[3]

X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
asort, bsort, csort = (
    sorted(A, reverse=True),
    sorted(B, reverse=True),
    sorted(C, reverse=True),
)
print((asort[0] + bsort[0] + csort[0]))
already = [[0, 0, 0]]
x, y, z = 0, 0, 0
place_sum = []
check = []
for k in range(K - 1):
    if [x + 1, y, z] not in already and x + 1 < X:
        already.append([x + 1, y, z])
        place_sum.append([x + 1, y, z])
        check.append(asort[x + 1] + bsort[y] + csort[z])
    if [x, y + 1, z] not in already and y + 1 < Y:
        already.append([x, y + 1, z])
        place_sum.append([x, y + 1, z])
        check.append(asort[x] + bsort[y + 1] + csort[z])
    if [x, y, z + 1] not in already and z + 1 < Z:
        already.append([x, y, z + 1])
        place_sum.append([x, y, z + 1])
        check.append(asort[x] + bsort[y] + csort[z + 1])
    print((max(check)))
    x, y, z = (
        place_sum[check.index(max(check))][0],
        place_sum[check.index(max(check))][1],
        place_sum[check.index(max(check))][2],
    )
    place_sum.pop(check.index(max(check)))
    check.remove(max(check))

import heapq

X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
asort, bsort, csort = (
    sorted(A, reverse=True),
    sorted(B, reverse=True),
    sorted(C, reverse=True),
)
already = [[0, 0, 0]]
print((asort[0] + bsort[0] + csort[0]))
x, y, z = 0, 0, 0
check = []
for k in range(K - 1):
    if [x + 1, y, z] not in already and x + 1 < X:
        already.append([x + 1, y, z])
        heapq.heappush(check, (-(asort[x + 1] + bsort[y] + csort[z]), x + 1, y, z))
    if [x, y + 1, z] not in already and y + 1 < Y:
        already.append([x, y + 1, z])
        heapq.heappush(check, (-(asort[x] + bsort[y + 1] + csort[z]), x, y + 1, z))
    if [x, y, z + 1] not in already and z + 1 < Z:
        already.append([x, y, z + 1])
        heapq.heappush(check, (-(asort[x] + bsort[y] + csort[z + 1]), x, y, z + 1))
    maxsum = heapq.heappop(check)
    print((-maxsum[0]))
    x, y, z = maxsum[1], maxsum[2], maxsum[3]

-        place_sum.append([x + 1, y, z])

-        check.append(asort[x + 1] + bsort[y] + csort[z])

+        heapq.heappush(check, (-(asort[x + 1] + bsort[y] + csort[z]), x + 1, y, z))

-        place_sum.append([x, y + 1, z])

-        check.append(asort[x] + bsort[y + 1] + csort[z])

+        heapq.heappush(check, (-(asort[x] + bsort[y + 1] + csort[z]), x, y + 1, z))

-        place_sum.append([x, y, z + 1])

-        check.append(asort[x] + bsort[y] + csort[z + 1])

-        place_sum[check.index(max(check))][0],

-        place_sum[check.index(max(check))][1],

-        place_sum[check.index(max(check))][2],

-    place_sum.pop(check.index(max(check)))

+        heapq.heappush(check, (-(asort[x] + bsort[y] + csort[z + 1]), x, y, z + 1))

+    x, y, z = maxsum[1], maxsum[2], maxsum[3]


Input:
import sys

def main():

    input = sys.stdin.readline

    N = int(input())

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

    ans = 0

    for C in range(1, N//2):

        n = N // C

        point = 0

        used = set([0])

        for k in range(1, n):

            A = N - 1 - k*C

            if A in used or k*C in used or A == k*C:

                break

            used.add(A)

            used.add(k*C)

            point += S[A] + S[k*C]

            ans = max(ans, point)

    return ans

if __name__ == '__main__':

    print((main()))

import sys

def main():

    input = sys.stdin.readline

    N = int(input())

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

    ans = 0

    # C = A - B

    for C in range(1, N//2):

        n = (N-1) // C

        point = 0

        for k in range(1, n):

            A = N-1 - k*C

            # Check A and B are positive integer, and S_i is not used twice.

            #

            # B = A - C and B >= 0, so A must be over C (A > C).

            #

            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1

            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than

            # or equal kC, the A's value is already used by kC.

            if A < C or ((N-1) % C == 0 and A <= k*C):

                break

            point += S[A] + S[k*C]

            ans = max(ans, point)

    return ans

if __name__ == '__main__':

    print((main()))

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))
    ans = 0
    for C in range(1, N // 2):
        n = N // C
        point = 0
        used = set([0])
        for k in range(1, n):
            A = N - 1 - k * C
            if A in used or k * C in used or A == k * C:
                break
            used.add(A)
            used.add(k * C)
            point += S[A] + S[k * C]
            ans = max(ans, point)
    return ans

if __name__ == "__main__":
    print((main()))

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))
    ans = 0
    # C = A - B
    for C in range(1, N // 2):
        n = (N - 1) // C
        point = 0
        for k in range(1, n):
            A = N - 1 - k * C
            # Check A and B are positive integer, and S_i is not used twice.
            #
            # B = A - C and B >= 0, so A must be over C (A > C).
            #
            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1
            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than
            # or equal kC, the A's value is already used by kC.
            if A < C or ((N - 1) % C == 0 and A <= k * C):
                break
            point += S[A] + S[k * C]
            ans = max(ans, point)
    return ans

if __name__ == "__main__":
    print((main()))

-            if A in used or k * C in used or A == k * C:

+            # Check A and B are positive integer, and S_i is not used twice.

+            # B = A - C and B >= 0, so A must be over C (A > C).

+            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1

+            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than

+            # or equal kC, the A's value is already used by kC.


Input:
from math import sqrt

from bisect import bisect_left

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

    xd = x2 - x1; yd = y2 - y1

    d = xd**2 + yd**2

    k = sqrt((4.0 - d) / d) / 2.0

    xc = (x1 + x2) / 2.0

    yc = (y1 + y2) / 2.0

    return [[xc - k*yd, yc + k*xd], [xc + k*yd, yc - k*xd]]

while 1:

    n = int(input())

    if n==0: break

    p = [list(map(float, input().split())) for i in range(n)]

    p.sort()

    prev = 0

    ans = 1

    for i in range(n):

        bx, by = p[i]

        while bx - p[prev][0] >= 2.0: prev += 1

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

            cx, cy = p[j]

            if cx - bx >= 2.0: break

            if (bx - cx)**2 + (by - cy)**2 <= 4.0:

                for ex, ey in circle_center(bx, by, cx, cy):

                    count = 2

                    for k in range(prev, n):

                        if k==i or k==j: continue

                        dx, dy = p[k]

                        if dx - bx >= 2.0: break

                        if (ex - dx)**2 + (ey - dy)**2 <= 1.0:

                            count += 1

                    ans = max(ans, count)

    print(ans)

from math import sqrt

from bisect import bisect_left

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

    xd = x2 - x1; yd = y2 - y1

    d = xd**2 + yd**2

    k = sqrt((4.0 - d) / d) / 2.0

    xc = (x1 + x2) / 2.0; yc = (y1 + y2) / 2.0

    xd *= k; yd *= k

    return [[xc - yd, yc + xd], [xc + yd, yc - xd]]

while 1:

    n = int(input())

    if n==0: break

    p = sorted(list(map(float, input().split())) for i in range(n))

    prev = 0

    ans = 1

    for i in range(n):

        bx, by = p[i]

        while bx - p[prev][0] >= 2.0: prev += 1

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

            cx, cy = p[j]

            if cx - bx >= 2.0: break

            if (bx - cx)**2 + (by - cy)**2 <= 4.0:

                for ex, ey in circle_center(bx, by, cx, cy):

                    count = 2

                    for k in range(prev, n):

                        if k==i or k==j: continue

                        dx, dy = p[k]

                        if dx - ex >= 1.0: break

                        if (ex - dx)**2 + (ey - dy)**2 <= 1.0:

                            count += 1

                    ans = max(ans, count)

    print(ans)

from math import sqrt
from bisect import bisect_left

def circle_center(x1, y1, x2, y2):
    xd = x2 - x1
    yd = y2 - y1
    d = xd**2 + yd**2
    k = sqrt((4.0 - d) / d) / 2.0
    xc = (x1 + x2) / 2.0
    yc = (y1 + y2) / 2.0
    return [[xc - k * yd, yc + k * xd], [xc + k * yd, yc - k * xd]]

while 1:
    n = int(input())
    if n == 0:
        break
    p = [list(map(float, input().split())) for i in range(n)]
    p.sort()
    prev = 0
    ans = 1
    for i in range(n):
        bx, by = p[i]
        while bx - p[prev][0] >= 2.0:
            prev += 1
        for j in range(i + 1, n):
            cx, cy = p[j]
            if cx - bx >= 2.0:
                break
            if (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:
                for ex, ey in circle_center(bx, by, cx, cy):
                    count = 2
                    for k in range(prev, n):
                        if k == i or k == j:
                            continue
                        dx, dy = p[k]
                        if dx - bx >= 2.0:
                            break
                        if (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0:
                            count += 1
                    ans = max(ans, count)
    print(ans)

from math import sqrt
from bisect import bisect_left

def circle_center(x1, y1, x2, y2):
    xd = x2 - x1
    yd = y2 - y1
    d = xd**2 + yd**2
    k = sqrt((4.0 - d) / d) / 2.0
    xc = (x1 + x2) / 2.0
    yc = (y1 + y2) / 2.0
    xd *= k
    yd *= k
    return [[xc - yd, yc + xd], [xc + yd, yc - xd]]

while 1:
    n = int(input())
    if n == 0:
        break
    p = sorted(list(map(float, input().split())) for i in range(n))
    prev = 0
    ans = 1
    for i in range(n):
        bx, by = p[i]
        while bx - p[prev][0] >= 2.0:
            prev += 1
        for j in range(i + 1, n):
            cx, cy = p[j]
            if cx - bx >= 2.0:
                break
            if (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:
                for ex, ey in circle_center(bx, by, cx, cy):
                    count = 2
                    for k in range(prev, n):
                        if k == i or k == j:
                            continue
                        dx, dy = p[k]
                        if dx - ex >= 1.0:
                            break
                        if (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0:
                            count += 1
                    ans = max(ans, count)
    print(ans)

-    return [[xc - k * yd, yc + k * xd], [xc + k * yd, yc - k * xd]]

+    return [[xc - yd, yc + xd], [xc + yd, yc - xd]]

-    p = [list(map(float, input().split())) for i in range(n)]

+    p = sorted(list(map(float, input().split())) for i in range(n))


Input:
a=65280; b=61680; c=52428; d=43690; e=65535

L = {el: 1 for el in [a, b, c, d, e, 0]}

for i in range(6):

    R = sorted(L.items(), key=lambda x: x[1])

    for p, l in R:

        if l < 16:

            L[p ^ e] = min(L.get(p ^ e, 16), l+1)

            if l+3 < 16:

                for q, r in R:

                    if l+r+3 <= 16:

                        L[p & q] = min(L.get(p & q, 16), l+r+3)

                        L[p ^ q] = min(L.get(p ^ q, 16), l+r+3)

                    else: break

        else: break

print(*(L[e & eval(s)] for s in open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]),sep='\n')

a=65280; b=61680; c=52428; d=43690; e=65535

from heapq import heappush, heappop

base = [a, b, c, d, e, 0]

Q = [(1, el) for el in base]

L = {el: 1 for el in base}

H = []

while Q:

    l, p = heappop(Q)

    if L[p] < l: continue

    if l+1 < L.get(p ^ e, 17):

        L[p^e] = l+1

        if l+1 < 16: heappush(Q, (l+1, p^e))

    if l+3 < 16:

        for q, r in H:

            if l+r+3 <= 16:

                if l+r+3 < L.get(p & q, 17):

                    L[p & q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p & q))

                if l+r+3 < L.get(p ^ q, 17):

                    L[p ^ q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p ^ q))

            else: break

    if l < 7: H.append((p, l))

print(*(L[e & eval(s)] for s in open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]),sep='\n')

a = 65280
b = 61680
c = 52428
d = 43690
e = 65535
L = {el: 1 for el in [a, b, c, d, e, 0]}
for i in range(6):
    R = sorted(L.items(), key=lambda x: x[1])
    for p, l in R:
        if l < 16:
            L[p ^ e] = min(L.get(p ^ e, 16), l + 1)
            if l + 3 < 16:
                for q, r in R:
                    if l + r + 3 <= 16:
                        L[p & q] = min(L.get(p & q, 16), l + r + 3)
                        L[p ^ q] = min(L.get(p ^ q, 16), l + r + 3)
                    else:
                        break
        else:
            break
print(
    *(
        L[e & eval(s)]
        for s in open(0)
        .read()
        .replace(*"-~")
        .replace(*"*&")
        .replace(*"1e")
        .split()[:-1]
    ),
    sep="\n"
)

a = 65280
b = 61680
c = 52428
d = 43690
e = 65535
from heapq import heappush, heappop

base = [a, b, c, d, e, 0]
Q = [(1, el) for el in base]
L = {el: 1 for el in base}
H = []
while Q:
    l, p = heappop(Q)
    if L[p] < l:
        continue
    if l + 1 < L.get(p ^ e, 17):
        L[p ^ e] = l + 1
        if l + 1 < 16:
            heappush(Q, (l + 1, p ^ e))
    if l + 3 < 16:
        for q, r in H:
            if l + r + 3 <= 16:
                if l + r + 3 < L.get(p & q, 17):
                    L[p & q] = l + r + 3
                    if l + r + 3 < 16:
                        heappush(Q, (l + r + 3, p & q))
                if l + r + 3 < L.get(p ^ q, 17):
                    L[p ^ q] = l + r + 3
                    if l + r + 3 < 16:
                        heappush(Q, (l + r + 3, p ^ q))
            else:
                break
    if l < 7:
        H.append((p, l))
print(
    *(
        L[e & eval(s)]
        for s in open(0)
        .read()
        .replace(*"-~")
        .replace(*"*&")
        .replace(*"1e")
        .split()[:-1]
    ),
    sep="\n"
)

-L = {el: 1 for el in [a, b, c, d, e, 0]}

-    R = sorted(L.items(), key=lambda x: x[1])

+            heappush(Q, (l + 1, p ^ e))

+                        heappush(Q, (l + r + 3, p & q))

+                        heappush(Q, (l + r + 3, p ^ q))


Input:
n=int(input())

s=input()

x=["SS","SW","WS","WW"]

def check0(i):

    if x[i][0]=="S":

        if s[0]=="o":

            if x[i][-1]=="S":

                return x[i][1]=="S"

            else:

                return x[i][1]=="W"

        else:

            if x[i][-1]=="S":

                return x[i][1]=="W"

            else:

                return x[i][1]=="S"

    else:

        if s[0]=="o":

            if x[i][-1]=="S":

                return x[i][1]=="W"

            else:

                return x[i][1]=="S"

        else:

            if x[i][-1]=="S":

                return x[i][1]=="S"

            else:

                return x[i][1]=="W"

def check1(i):

    if x[i][n-1]=="S":

        if s[n-1]=="o":

            if x[i][n-2]=="S":

                return x[i][0]=="S"

            else:

                return x[i][0]=="W"

        else:

            if x[i][n-2]=="S":

                return x[i][0]=="W"

            else:

                return x[i][0]=="S"

    else:

        if s[n-1]=="o":

            if x[i][n-2]=="S":

                return x[i][0]=="W"

            else:

                return x[i][0]=="S"

        else:

            if x[i][n-2]=="S":

                return x[i][0]=="S"

            else:

                return x[i][0]=="W"

for i in range(4):

    for j in range(n-2):

        if x[i][j+1]=="S":

            if s[j+1]=="o":

                if x[i][j]=="S":

                    x[i]+="S"

                else:

                    x[i]+="W"

            else:

                if x[i][j]=="S":

                    x[i]+="W"

                else:

                    x[i]+="S"

        else:

            if s[j+1]=="o":

                if x[i][j]=="S":

                    x[i]+="W"

                else:

                    x[i]+="S"

            else:

                if x[i][j]=="S":

                    x[i]+="S"

                else:

                    x[i]+="W"

    #print(x[i])

    if check0(i) and check1(i):

        print((x[i]))

        break

else:

    print((-1))


Input:
import sys

readline = sys.stdin.readline

sys.setrecursionlimit(10**8)

mod = 10**9+7

#mod = 998244353

INF = 10**18

eps = 10**-7

m,n,k = list(map(int,readline().split()))

def comb(n, r, mod):

    r = min(r, n-r)

    mol = 1

    deno = 1

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

        mol = mol * (n-r+i) % mod

        deno = deno * i % mod

    ret = mol * pow(deno, mod-2, mod) % mod

    return ret

def f1(x,y,a,b):

    return (a+b-x-y)*(a-x+1)*(b-y+1)//2

def f2(x,a):

    return (a-x)*(a-x+1)//2

ans = 0

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

    for y in range(1,m+1):

        ans += f1(x,y,n,m)+f1(1,1,x,y)+f1(1,y,x,m)+f1(x,1,n,y)

        ans -= f2(x,n) + f2(1,x) + f2(1,y) + f2(y,m)

        ans %= mod

ans = (ans * comb(m*n-2,k-2,mod))%mod

ans = ans*pow(2,mod-2,mod)%mod

print(ans)

import sys

readline = sys.stdin.readline

sys.setrecursionlimit(10**8)

mod = 10**9+7

#mod = 998244353

INF = 10**18

eps = 10**-7

m,n,k = list(map(int,readline().split()))

def comb(n, r, mod):

    r = min(r, n-r)

    mol = 1

    deno = 1

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

        mol = mol * (n-r+i) % mod

        deno = deno * i % mod

    ret = mol * pow(deno, mod-2, mod) % mod

    return ret

def f1(x,y,a,b):

    return (a+b-x-y)*(a-x+1)*(b-y+1)//2

def f2(x,a):

    return (a-x)*(a-x+1)//2

ans = 0

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

    for y in range(1,m+1):

        a = n-x+1

        b = m-y+1

        c = m*(a*(a-1)+x*(x-1))

        d = n*(b*(b-1)+y*(y-1))

        ans += (c+d)//2

        ans %= mod

ans = (ans * comb(m*n-2,k-2,mod))%mod

ans = ans*pow(2,mod-2,mod)%mod

print(ans)

import sys

readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
# mod = 998244353
INF = 10**18
eps = 10**-7
m, n, k = list(map(int, readline().split()))

def comb(n, r, mod):
    r = min(r, n - r)
    mol = 1
    deno = 1
    for i in range(1, r + 1):
        mol = mol * (n - r + i) % mod
        deno = deno * i % mod
    ret = mol * pow(deno, mod - 2, mod) % mod
    return ret

def f1(x, y, a, b):
    return (a + b - x - y) * (a - x + 1) * (b - y + 1) // 2

def f2(x, a):
    return (a - x) * (a - x + 1) // 2

ans = 0
for x in range(1, n + 1):
    for y in range(1, m + 1):
        ans += f1(x, y, n, m) + f1(1, 1, x, y) + f1(1, y, x, m) + f1(x, 1, n, y)
        ans -= f2(x, n) + f2(1, x) + f2(1, y) + f2(y, m)
        ans %= mod
ans = (ans * comb(m * n - 2, k - 2, mod)) % mod
ans = ans * pow(2, mod - 2, mod) % mod
print(ans)

import sys

readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
# mod = 998244353
INF = 10**18
eps = 10**-7
m, n, k = list(map(int, readline().split()))

def comb(n, r, mod):
    r = min(r, n - r)
    mol = 1
    deno = 1
    for i in range(1, r + 1):
        mol = mol * (n - r + i) % mod
        deno = deno * i % mod
    ret = mol * pow(deno, mod - 2, mod) % mod
    return ret

def f1(x, y, a, b):
    return (a + b - x - y) * (a - x + 1) * (b - y + 1) // 2

def f2(x, a):
    return (a - x) * (a - x + 1) // 2

ans = 0
for x in range(1, n + 1):
    for y in range(1, m + 1):
        a = n - x + 1
        b = m - y + 1
        c = m * (a * (a - 1) + x * (x - 1))
        d = n * (b * (b - 1) + y * (y - 1))
        ans += (c + d) // 2
        ans %= mod
ans = (ans * comb(m * n - 2, k - 2, mod)) % mod
ans = ans * pow(2, mod - 2, mod) % mod
print(ans)


Input:
import sys

init = ''.join(sys.stdin.read().split())

# Bidirectional search using breadth-first search

def solve(start, goal):

    if start == goal:

        return 0

    generated_state = {start: 0, goal: 1}   # 0: foreward, 1: backward

    step = {start: 0, goal: 0}

    s = 0

    c_d = [(start, 0), (goal, 1)] # configure and direction

    while True:

        q = iter(c_d)

        c_d = []

        s += 1

        for c, d in q:

            i = c.find('0')

            if 0 <= i <= 5:

                t = str.maketrans('0' + c[i+3], c[i+3] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

            if i >= 3:

                t = str.maketrans('0' + c[i-3], c[i-3] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

            if i == 0 or i == 1 or i == 3 or i == 4 or i == 6 or i == 7:

                t = str.maketrans('0' + c[i+1], c[i+1] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

            if i == 1 or i == 2 or i == 4 or i == 5 or i == 7 or i == 8:

                t = str.maketrans('0' + c[i-1], c[i-1] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

print((solve(init, '123456780')))

adjacent = (

    (1, 3),       # 0

    (0, 2, 4),    # 1

    (1, 5),       # 2

    (0, 4, 6),    # 3

    (1, 3, 5, 7), # 4

    (2, 4, 8),    # 5

    (3, 7),       # 6

    (4, 6, 8),    # 7

    (5, 7)        # 8

)

import collections

GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 0]

# Bidirectional search using breadth-first search

def solve(start):

    if start == GOAL:

        return 0

    # 0: forward, 1: backward

    generated_state = {tuple(start): 0, tuple(GOAL): 1}

    step = {tuple(start): 0, tuple(GOAL): 0}

    s = 0

    state1 = [(start, 0), (GOAL, 1)]

    while state1:

        state2 = state1[:]

        state1 = []

        s += 1

        for s2, d in state2:

            i = s2.index(0)

            for p in adjacent[i]:

                s1 = s2[:]

                s1[i], s1[p] = s1[p], 0

                key = tuple(s1)

                if key in generated_state:

                    if generated_state[key] != d:

                        return s + step[key]

                    continue

                state1.append((s1, d))

                generated_state[key] = d

                step[key] = s

import sys

start = list(map(int, sys.stdin.read().split()))

print((solve(start)))

import sys

init = "".join(sys.stdin.read().split())
# Bidirectional search using breadth-first search
def solve(start, goal):
    if start == goal:
        return 0
    generated_state = {start: 0, goal: 1}  # 0: foreward, 1: backward
    step = {start: 0, goal: 0}
    s = 0
    c_d = [(start, 0), (goal, 1)]  # configure and direction
    while True:
        q = iter(c_d)
        c_d = []
        s += 1
        for c, d in q:
            i = c.find("0")
            if 0 <= i <= 5:
                t = str.maketrans("0" + c[i + 3], c[i + 3] + "0")
                t_c = c.translate(t)
                if t_c in generated_state:
                    if generated_state[t_c] != d:
                        return s + step[t_c]
                else:
                    generated_state[t_c] = d
                    step[t_c] = s
                    c_d.append((t_c, d))
            if i >= 3:
                t = str.maketrans("0" + c[i - 3], c[i - 3] + "0")
                t_c = c.translate(t)
                if t_c in generated_state:
                    if generated_state[t_c] != d:
                        return s + step[t_c]
                else:
                    generated_state[t_c] = d
                    step[t_c] = s
                    c_d.append((t_c, d))
            if i == 0 or i == 1 or i == 3 or i == 4 or i == 6 or i == 7:
                t = str.maketrans("0" + c[i + 1], c[i + 1] + "0")
                t_c = c.translate(t)
                if t_c in generated_state:
                    if generated_state[t_c] != d:
                        return s + step[t_c]
                else:
                    generated_state[t_c] = d
                    step[t_c] = s
                    c_d.append((t_c, d))
            if i == 1 or i == 2 or i == 4 or i == 5 or i == 7 or i == 8:
                t = str.maketrans("0" + c[i - 1], c[i - 1] + "0")
                t_c = c.translate(t)
                if t_c in generated_state:
                    if generated_state[t_c] != d:
                        return s + step[t_c]
                else:
                    generated_state[t_c] = d
                    step[t_c] = s
                    c_d.append((t_c, d))

print((solve(init, "123456780")))

adjacent = (
    (1, 3),  # 0
    (0, 2, 4),  # 1
    (1, 5),  # 2
    (0, 4, 6),  # 3
    (1, 3, 5, 7),  # 4
    (2, 4, 8),  # 5
    (3, 7),  # 6
    (4, 6, 8),  # 7
    (5, 7),  # 8
)
import collections

GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 0]
# Bidirectional search using breadth-first search
def solve(start):
    if start == GOAL:
        return 0
    # 0: forward, 1: backward
    generated_state = {tuple(start): 0, tuple(GOAL): 1}
    step = {tuple(start): 0, tuple(GOAL): 0}
    s = 0
    state1 = [(start, 0), (GOAL, 1)]
    while state1:
        state2 = state1[:]
        state1 = []
        s += 1
        for s2, d in state2:
            i = s2.index(0)
            for p in adjacent[i]:
                s1 = s2[:]
                s1[i], s1[p] = s1[p], 0
                key = tuple(s1)
                if key in generated_state:
                    if generated_state[key] != d:
                        return s + step[key]
                    continue
                state1.append((s1, d))
                generated_state[key] = d
                step[key] = s

import sys

start = list(map(int, sys.stdin.read().split()))
print((solve(start)))

+# Bidirectional search using breadth-first search

+    generated_state = {tuple(start): 0, tuple(GOAL): 1}

+    step = {tuple(start): 0, tuple(GOAL): 0}

+                if key in generated_state:

+                    if generated_state[key] != d:

+                        return s + step[key]

+                generated_state[key] = d

-# Bidirectional search using breadth-first search

-    generated_state = {start: 0, goal: 1}  # 0: foreward, 1: backward

-    c_d = [(start, 0), (goal, 1)]  # configure and direction

-                if t_c in generated_state:

-                    if generated_state[t_c] != d:

-                        return s + step[t_c]

-                    generated_state[t_c] = d

-                    c_d.append((t_c, d))

-                if t_c in generated_state:

-                    if generated_state[t_c] != d:

-                        return s + step[t_c]

-                    generated_state[t_c] = d

-                    c_d.append((t_c, d))

-                if t_c in generated_state:

-                    if generated_state[t_c] != d:

-                        return s + step[t_c]

-                    generated_state[t_c] = d

-                    c_d.append((t_c, d))

-                if t_c in generated_state:

-                    if generated_state[t_c] != d:

-                        return s + step[t_c]

-                    generated_state[t_c] = d

-                    c_d.append((t_c, d))

+start = list(map(int, sys.stdin.read().split()))


Input:
import sys

def main():

    input = sys.stdin.readline

    N = int(input())

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

    for i in range(N-1):

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

        a, b = a-1, b-1

        E[a].append((b,i))

        E[b].append((a,i))

    def dfs(s, g):

        par = [(-1,-1)] * N

        par[s] = (s,-1)

        stack = [s]

        while stack:

            v = stack.pop()

            for to, i in E[v]:

                if par[to][0] >= 0: continue

                par[to] = (v, i)

                if to == g: break

                stack.append(to)

        r = set()

        v = g

        while v != s:

            v, i = par[v]

            r.add(i)

        return r

    M = int(input())

    path = [None] * M

    for i in range(M):

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

        u, v = u-1, v-1

        path[i] = dfs(u, v)

    def calc(s): return 1<<(N-1-len(s))

    i_ans = 0

    for p in range(1, 1<<M):

        is_odd = bin(p).count('1') & 1

        s = set()

        for i in range(M):

            if p&1: s |= path[i]

            p >>= 1

        if is_odd: i_ans += calc(s)

        else: i_ans -= calc(s)

    print(((1<<(N-1)) - i_ans))

if __name__ == '__main__':

    main()

import sys

def main():

    input = sys.stdin.readline

    N = int(input())

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

    for i in range(N-1):

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

        a, b = a-1, b-1

        E[a].append((b,i))

        E[b].append((a,i))

    def dfs(s, g):

        par = [(-1,-1)] * N

        par[s] = (s,-1)

        stack = [s]

        while stack:

            v = stack.pop()

            for to, i in E[v]:

                if par[to][0] >= 0: continue

                par[to] = (v, i)

                if to == g: break

                stack.append(to)

        r = set()

        v = g

        while v != s:

            v, i = par[v]

            r.add(i)

        return r

    M = int(input())

    path = [None] * M

    for i in range(M):

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

        u, v = u-1, v-1

        path[i] = dfs(u, v)

    def calc(s): return 1<<(N-1-len(s))

    i_ans = 0

    for p in range(1, 1<<M):

        is_odd = 0

        s = set()

        for i in range(M):

            if p&1:

                s |= path[i]

                is_odd ^= 1

            p >>= 1

        if is_odd: i_ans += calc(s)

        else: i_ans -= calc(s)

    print(((1<<(N-1)) - i_ans))

if __name__ == '__main__':

    main()

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    E = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a, b = a - 1, b - 1
        E[a].append((b, i))
        E[b].append((a, i))

    def dfs(s, g):
        par = [(-1, -1)] * N
        par[s] = (s, -1)
        stack = [s]
        while stack:
            v = stack.pop()
            for to, i in E[v]:
                if par[to][0] >= 0:
                    continue
                par[to] = (v, i)
                if to == g:
                    break
                stack.append(to)
        r = set()
        v = g
        while v != s:
            v, i = par[v]
            r.add(i)
        return r

    M = int(input())
    path = [None] * M
    for i in range(M):
        u, v = list(map(int, input().split()))
        u, v = u - 1, v - 1
        path[i] = dfs(u, v)

    def calc(s):
        return 1 << (N - 1 - len(s))

    i_ans = 0
    for p in range(1, 1 << M):
        is_odd = bin(p).count("1") & 1
        s = set()
        for i in range(M):
            if p & 1:
                s |= path[i]
            p >>= 1
        if is_odd:
            i_ans += calc(s)
        else:
            i_ans -= calc(s)
    print(((1 << (N - 1)) - i_ans))

if __name__ == "__main__":
    main()

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    E = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a, b = a - 1, b - 1
        E[a].append((b, i))
        E[b].append((a, i))

    def dfs(s, g):
        par = [(-1, -1)] * N
        par[s] = (s, -1)
        stack = [s]
        while stack:
            v = stack.pop()
            for to, i in E[v]:
                if par[to][0] >= 0:
                    continue
                par[to] = (v, i)
                if to == g:
                    break
                stack.append(to)
        r = set()
        v = g
        while v != s:
            v, i = par[v]
            r.add(i)
        return r

    M = int(input())
    path = [None] * M
    for i in range(M):
        u, v = list(map(int, input().split()))
        u, v = u - 1, v - 1
        path[i] = dfs(u, v)

    def calc(s):
        return 1 << (N - 1 - len(s))

    i_ans = 0
    for p in range(1, 1 << M):
        is_odd = 0
        s = set()
        for i in range(M):
            if p & 1:
                s |= path[i]
                is_odd ^= 1
            p >>= 1
        if is_odd:
            i_ans += calc(s)
        else:
            i_ans -= calc(s)
    print(((1 << (N - 1)) - i_ans))

if __name__ == "__main__":
    main()

-        is_odd = bin(p).count("1") & 1
+        is_odd = 0
+                is_odd ^= 1


Input:
'''

    Auther: ghoshashis545 Ashis Ghosh

    College: jalpaiguri Govt Enggineering College

'''

from os import path

import sys

from functools import cmp_to_key as ctk

from collections import deque,defaultdict as dd

from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

from itertools import permutations

from datetime import datetime

from math import ceil,sqrt,log,gcd

def ii():return int(input())

def si():return input()

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

def li():return list(mi())

abc='abcdefghijklmnopqrstuvwxyz'

mod=1000000007

#mod=998244353

inf = float("inf")

vow=['a','e','i','o','u']

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

def bo(i):

    return ord(i)-ord('a')

file = 0

def solve():

    # for _ in range(ii()):

    n=ii()

    n%=1000

    if n!=0:

        n=1000-n

    print(n)

if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):

            sys.stdin=open('input1.txt', 'r')

            sys.stdout=open('output1.txt','w')

        else:

            input=sys.stdin.readline

    solve()

'''

    Auther: ghoshashis545 Ashis Ghosh

    College: jalpaiguri Govt Enggineering College

'''

from os import path

import sys

from heapq import heappush,heappop

from functools import cmp_to_key as ctk

from collections import deque,defaultdict as dd

from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

from itertools import permutations

from datetime import datetime

from math import ceil,sqrt,log,gcd

def ii():return int(input())

def si():return input()

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

def li():return list(mi())

abc='abcdefghijklmnopqrstuvwxyz'

mod=1000000007

# mod=998244353

inf = float("inf")

vow=['a','e','i','o','u']

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

def bo(i):

    return ord(i)-ord('a')

file=0

def solve():

    # for _ in range(ii()):

    n=ii()

    n%=1000

    if(n!=0):

        n=1000-n

    print(n)

if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):

            sys.stdin=open('input1.txt', 'r')

            sys.stdout=open('output1.txt','w')

        else:

            input=sys.stdin.readline

    solve()

"""
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College
"""
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
    return int(input())

def si():
    return input()

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

def li():
    return list(mi())

abc = "abcdefghijklmnopqrstuvwxyz"
mod = 1000000007
# mod=998244353
inf = float("inf")
vow = ["a", "e", "i", "o", "u"]
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]

def bo(i):
    return ord(i) - ord("a")

file = 0

def solve():
    # for _ in range(ii()):
    n = ii()
    n %= 1000
    if n != 0:
        n = 1000 - n
    print(n)

if __name__ == "__main__":
    if file:
        if path.exists("input1.txt"):
            sys.stdin = open("input1.txt", "r")
            sys.stdout = open("output1.txt", "w")
        else:
            input = sys.stdin.readline
    solve()

"""
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College
"""
from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
    return int(input())

def si():
    return input()

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

def li():
    return list(mi())

abc = "abcdefghijklmnopqrstuvwxyz"
mod = 1000000007
# mod=998244353
inf = float("inf")
vow = ["a", "e", "i", "o", "u"]
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]

def bo(i):
    return ord(i) - ord("a")

file = 0

def solve():
    # for _ in range(ii()):
    n = ii()
    n %= 1000
    if n != 0:
        n = 1000 - n
    print(n)

if __name__ == "__main__":
    if file:
        if path.exists("input1.txt"):
            sys.stdin = open("input1.txt", "r")
            sys.stdout = open("output1.txt", "w")
        else:
            input = sys.stdin.readline
    solve()


Input:
G_MAX = 40*10

N_MAX = 40

INF = float('inf')

dp = [[[INF]*(G_MAX+1) for _ in range(G_MAX+1)]

      for _ in range(N_MAX+1)]

N,Ma,Mb = list(map(int, input().split()))

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

for _ in range(N):

    ai,bi,ci = list(map(int, input().split()))

    a.append(ai)

    b.append(bi)

    c.append(ci)

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

from math import isinf

for i in range(N):

    for ca in range(G_MAX+1):

        for cb in range(G_MAX+1):

            if isinf(dp[i][ca][cb]): continue

            dp[i+1][ca][cb] = min(dp[i+1][ca][cb],

                                 dp[i][ca][cb])

            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]],

                                           dp[i][ca][cb]+c[i])

ans = INF

for ca in range(1,G_MAX+1):

    for cb in range(1,G_MAX+1):

        if ca*Mb==cb*Ma:

            ans = min(ans, dp[N][ca][cb])

if isinf(ans): ans = -1

print(ans)

from math import isinf

N, Ma, Mb = list(map(int, input().split()))

a = [0]*N

b = [0]*N

c = [0]*N

for i in range(N):

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

W_MAX = 40*10

dp = [[float('inf')]*(W_MAX+1) for _ in range(W_MAX+1)]

dp[0][0] = 0

for i in range(N):

    for wa in reversed(list(range(W_MAX+1))):

        for wb in reversed(list(range(W_MAX+1))):

            if isinf(dp[wa][wb]): continue

            if wa+a[i]<=W_MAX and wb+b[i]<=W_MAX:

                dp[wa+a[i]][wb+b[i]] = min(dp[wa+a[i]][wb+b[i]],

                                           dp[wa][wb]+c[i])

ans = float('inf')

for wa in range(1, W_MAX+1):

    for wb in range(1, W_MAX+1):

        if wa*Mb == wb*Ma:

            ans = min(ans, dp[wa][wb])

if isinf(ans): ans = -1

print(ans)

G_MAX = 40 * 10
N_MAX = 40
INF = float("inf")
dp = [[[INF] * (G_MAX + 1) for _ in range(G_MAX + 1)] for _ in range(N_MAX + 1)]
N, Ma, Mb = list(map(int, input().split()))
a, b, c = [], [], []
for _ in range(N):
    ai, bi, ci = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)
    c.append(ci)
dp[0][0][0] = 0
from math import isinf

for i in range(N):
    for ca in range(G_MAX + 1):
        for cb in range(G_MAX + 1):
            if isinf(dp[i][ca][cb]):
                continue
            dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb])
            dp[i + 1][ca + a[i]][cb + b[i]] = min(
                dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]
            )
ans = INF
for ca in range(1, G_MAX + 1):
    for cb in range(1, G_MAX + 1):
        if ca * Mb == cb * Ma:
            ans = min(ans, dp[N][ca][cb])
if isinf(ans):
    ans = -1
print(ans)

from math import isinf

N, Ma, Mb = list(map(int, input().split()))
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = list(map(int, input().split()))
W_MAX = 40 * 10
dp = [[float("inf")] * (W_MAX + 1) for _ in range(W_MAX + 1)]
dp[0][0] = 0
for i in range(N):
    for wa in reversed(list(range(W_MAX + 1))):
        for wb in reversed(list(range(W_MAX + 1))):
            if isinf(dp[wa][wb]):
                continue
            if wa + a[i] <= W_MAX and wb + b[i] <= W_MAX:
                dp[wa + a[i]][wb + b[i]] = min(
                    dp[wa + a[i]][wb + b[i]], dp[wa][wb] + c[i]
                )
ans = float("inf")
for wa in range(1, W_MAX + 1):
    for wb in range(1, W_MAX + 1):
        if wa * Mb == wb * Ma:
            ans = min(ans, dp[wa][wb])
if isinf(ans):
    ans = -1
print(ans)

-dp = [[[INF] * (G_MAX + 1) for _ in range(G_MAX + 1)] for _ in range(N_MAX + 1)]

-N, Ma, Mb = list(map(int, input().split()))

-    ai, bi, ci = list(map(int, input().split()))

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

+    a[i], b[i], c[i] = list(map(int, input().split()))

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

+    for wa in reversed(list(range(W_MAX + 1))):

+        for wb in reversed(list(range(W_MAX + 1))):

-            ans = min(ans, dp[N][ca][cb])

+            if wa + a[i] <= W_MAX and wb + b[i] <= W_MAX:

+                dp[wa + a[i]][wb + b[i]] = min(


Input:
INF = 2*10**7

def main():

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

    A = []

    B = []

    C = []

    for _ in range(M):

        a, b = (int(i) for i in input().split())

        A.append(a)

        B.append(b)

        bit = 0

        for i in input().split():

            bit |= (1 << (int(i)-1))

        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]

    dp[0][0] = 0

    for i in range(M):

        for j in range(1 << N):

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

            if dp[i][j] != INF:

                next_bit = j | C[i]

                dp[i+1][next_bit] = min(dp[i+1][next_bit], dp[i][j] + A[i])

    ans = dp[-1][-1]

    if ans == INF:

        print((-1))

    else:

        print(ans)

    # print(*dp, sep="\n")

if __name__ == '__main__':

    main()

INF = 2*10**7

def main():

    import sys

    input = sys.stdin.buffer.readline

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

    A = []

    B = []

    C = []

    for _ in range(M):

        a, b = (int(i) for i in input().split())

        A.append(a)

        B.append(b)

        bit = 0

        for i in input().split():

            bit |= (1 << (int(i)-1))

        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]

    dp[0][0] = 0

    for i in range(M):

        for j in range(1 << N):

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

            if dp[i][j] != INF:

                next_bit = j | C[i]

                dp[i+1][next_bit] = min(dp[i+1][next_bit], dp[i][j] + A[i])

    ans = dp[-1][-1]

    if ans == INF:

        print((-1))

    else:

        print(ans)

    # print(*dp, sep="\n")

if __name__ == '__main__':

    main()

INF = 2 * 10**7

def main():
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for i in input().split():
            bit |= 1 << (int(i) - 1)
        C.append(bit)
    dp = [[INF] * (1 << N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i + 1][next_bit] = min(dp[i + 1][next_bit], dp[i][j] + A[i])
    ans = dp[-1][-1]
    if ans == INF:
        print((-1))
    else:
        print(ans)
    # print(*dp, sep="\n")

if __name__ == "__main__":
    main()

INF = 2 * 10**7

def main():
    import sys

    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for i in input().split():
            bit |= 1 << (int(i) - 1)
        C.append(bit)
    dp = [[INF] * (1 << N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i + 1][next_bit] = min(dp[i + 1][next_bit], dp[i][j] + A[i])
    ans = dp[-1][-1]
    if ans == INF:
        print((-1))
    else:
        print(ans)
    # print(*dp, sep="\n")

if __name__ == "__main__":
    main()

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


Input:
def prime_factorize(num):

    """

    This function performs prime factorization on the input natural number.

    The result is returned in the form of a dictionary with the prime number as the key

    and its number as the value.

    :param num:

    :return prime_factor: Dictionary with the prime number as the key and its number as the value.

    """

    prime_factor = {}

    i = 2

    while i ** 2 <= num:

        while num % i == 0:

            num //= i

            if i in list(prime_factor.keys()):

                prime_factor[i] += 1

            else:

                prime_factor[i] = 1

        i += 1

    if num > 1:

        prime_factor[num] = 1

    return prime_factor

from math import factorial

def comb(n, r, R):

    if n not in R:

        a = factorial(n)

        R[n] = a

    else:

        a = R[n]

    if n - r not in R:

        b = factorial(n - r)

        R[n - r] = b

    else:

        b = R[n - r]

    if r not in R:

        c = factorial(r)

        R[r] = c

    else:

        c = R[r]

    return a // (b * c)

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

r = 1

R = dict()

prime_fac = prime_factorize(m)

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

    r *= comb(v + n - 1, v, R)

mod = 1000000000 + 7

print((r % mod))

def prime_factorize(num):

    """

    This function performs prime factorization on the input natural number.

    The result is returned in the form of a dictionary with the prime number as the key

    and its number as the value.

    :param num:

    :return prime_factor: Dictionary with the prime number as the key and its number as the value.

    """

    prime_factor = {}

    i = 2

    while i ** 2 <= num:

        while num % i == 0:

            num //= i

            if i in list(prime_factor.keys()):

                prime_factor[i] += 1

            else:

                prime_factor[i] = 1

        i += 1

    if num > 1:

        prime_factor[num] = 1

    return prime_factor

def combination(n, r):

    r = min(n-r, r)

    result = 1

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

        result *= i

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

        result //= i

    return result

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

r = 1

prime_fac = prime_factorize(m)

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

    r *= combination(v + n - 1, v)

mod = 1000000000 + 7

print((r % mod))

def prime_factorize(num):
    """
    This function performs prime factorization on the input natural number.
    The result is returned in the form of a dictionary with the prime number as the key
    and its number as the value.
    :param num:
    :return prime_factor: Dictionary with the prime number as the key and its number as the value.
    """
    prime_factor = {}
    i = 2
    while i**2 <= num:
        while num % i == 0:
            num //= i
            if i in list(prime_factor.keys()):
                prime_factor[i] += 1
            else:
                prime_factor[i] = 1
        i += 1
    if num > 1:
        prime_factor[num] = 1
    return prime_factor

from math import factorial

def comb(n, r, R):
    if n not in R:
        a = factorial(n)
        R[n] = a
    else:
        a = R[n]
    if n - r not in R:
        b = factorial(n - r)
        R[n - r] = b
    else:
        b = R[n - r]
    if r not in R:
        c = factorial(r)
        R[r] = c
    else:
        c = R[r]
    return a // (b * c)

n, m = list(map(int, input().split()))
r = 1
R = dict()
prime_fac = prime_factorize(m)
for v in list(prime_fac.values()):
    r *= comb(v + n - 1, v, R)
mod = 1000000000 + 7
print((r % mod))

def prime_factorize(num):
    """
    This function performs prime factorization on the input natural number.
    The result is returned in the form of a dictionary with the prime number as the key
    and its number as the value.
    :param num:
    :return prime_factor: Dictionary with the prime number as the key and its number as the value.
    """
    prime_factor = {}
    i = 2
    while i**2 <= num:
        while num % i == 0:
            num //= i
            if i in list(prime_factor.keys()):
                prime_factor[i] += 1
            else:
                prime_factor[i] = 1
        i += 1
    if num > 1:
        prime_factor[num] = 1
    return prime_factor

def combination(n, r):
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result

n, m = list(map(int, input().split()))
r = 1
prime_fac = prime_factorize(m)
for v in list(prime_fac.values()):
    r *= combination(v + n - 1, v)
mod = 1000000000 + 7
print((r % mod))

-from math import factorial
-def comb(n, r, R):
-    if n not in R:
-        a = factorial(n)
-        R[n] = a
-    else:
-        a = R[n]
-    if n - r not in R:
-        b = factorial(n - r)
-        R[n - r] = b
-    else:
-        b = R[n - r]
-    if r not in R:
-        c = factorial(r)
-        R[r] = c
-    else:
-        c = R[r]
-    return a // (b * c)
+def combination(n, r):
+    r = min(n - r, r)
+    result = 1
+    for i in range(n, n - r, -1):
+        result *= i
+    for i in range(1, r + 1):
+        result //= i
+    return result
-R = dict()
-    r *= comb(v + n - 1, v, R)
+    r *= combination(v + n - 1, v)


Input:
import sys

input = sys.stdin.readline

from collections import deque

N = int(input())

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

for i in range(N-1):

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

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

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

i0 = min([i for i in range(N) if len(X[i]) == 1])

P = [-1] * N

Q = deque([i0])

R = []

while Q:

    i = deque.popleft(Q)

    R.append(i)

    for a in X[i]:

        if a != P[i]:

            P[a] = i

            X[a].remove(i)

            deque.append(Q, a)

mod = 10 ** 9 + 7

inv2 = (mod + 1) // 2

A = [1] * N

for i in R[::-1]:

    s = 0

    for j in X[i]:

        A[i] += A[j]

ans = 0

for i in range(N):

    s = pow(inv2, N - A[i], mod)

    t = 1 + (1-pow(inv2, N - A[i], mod)) * pow(2, N - A[i], mod)

    for j in X[i]:

        s = (s * pow(inv2, A[j], mod)) % mod

        t = (t + (1-pow(inv2, A[j], mod)) * pow(2, A[j], mod)) % mod

    ans = (ans + 1 - s * t) % mod

print((ans * inv2 % mod))

import sys

input = sys.stdin.readline

from collections import deque

N = int(input())

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

for i in range(N-1):

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

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

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

i0 = min([i for i in range(N) if len(X[i]) == 1])

P = [-1] * N

Q = deque([i0])

R = []

while Q:

    i = deque.popleft(Q)

    R.append(i)

    for a in X[i]:

        if a != P[i]:

            P[a] = i

            X[a].remove(i)

            deque.append(Q, a)

mod = 10 ** 9 + 7

pow2 = [1]

for i in range(N + 10):

    pow2.append(pow2[-1] * 2 % mod)

inv2 = (mod + 1) // 2

invpow2 = [pow(pow2[-1], mod-2, mod)]

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

    invpow2.append(invpow2[-1] * 2 % mod)

invpow2 = invpow2[::-1]

A = [1] * N

for i in R[::-1]:

    s = 0

    for j in X[i]:

        A[i] += A[j]

ans = 0

for i in range(N):

    s = pow(inv2, N - A[i], mod)

    t = 1 + (1-invpow2[N-A[i]]) * pow2[N-A[i]]

    for j in X[i]:

        s = (s * invpow2[A[j]]) % mod

        t = (t + (1-invpow2[A[j]]) * pow2[A[j]]) % mod

    ans = (ans + 1 - s * t) % mod

print((ans * inv2 % mod))

import sys

input = sys.stdin.readline
from collections import deque

N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
    x, y = list(map(int, input().split()))
    X[x - 1].append(y - 1)
    X[y - 1].append(x - 1)
i0 = min([i for i in range(N) if len(X[i]) == 1])
P = [-1] * N
Q = deque([i0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)
mod = 10**9 + 7
inv2 = (mod + 1) // 2
A = [1] * N
for i in R[::-1]:
    s = 0
    for j in X[i]:
        A[i] += A[j]
ans = 0
for i in range(N):
    s = pow(inv2, N - A[i], mod)
    t = 1 + (1 - pow(inv2, N - A[i], mod)) * pow(2, N - A[i], mod)
    for j in X[i]:
        s = (s * pow(inv2, A[j], mod)) % mod
        t = (t + (1 - pow(inv2, A[j], mod)) * pow(2, A[j], mod)) % mod
    ans = (ans + 1 - s * t) % mod
print((ans * inv2 % mod))

import sys

input = sys.stdin.readline
from collections import deque

N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
    x, y = list(map(int, input().split()))
    X[x - 1].append(y - 1)
    X[y - 1].append(x - 1)
i0 = min([i for i in range(N) if len(X[i]) == 1])
P = [-1] * N
Q = deque([i0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)
mod = 10**9 + 7
pow2 = [1]
for i in range(N + 10):
    pow2.append(pow2[-1] * 2 % mod)
inv2 = (mod + 1) // 2
invpow2 = [pow(pow2[-1], mod - 2, mod)]
for i in range(N + 10)[::-1]:
    invpow2.append(invpow2[-1] * 2 % mod)
invpow2 = invpow2[::-1]
A = [1] * N
for i in R[::-1]:
    s = 0
    for j in X[i]:
        A[i] += A[j]
ans = 0
for i in range(N):
    s = pow(inv2, N - A[i], mod)
    t = 1 + (1 - invpow2[N - A[i]]) * pow2[N - A[i]]
    for j in X[i]:
        s = (s * invpow2[A[j]]) % mod
        t = (t + (1 - invpow2[A[j]]) * pow2[A[j]]) % mod
    ans = (ans + 1 - s * t) % mod
print((ans * inv2 % mod))

+invpow2 = [pow(pow2[-1], mod - 2, mod)]

+    invpow2.append(invpow2[-1] * 2 % mod)

-        s = (s * pow(inv2, A[j], mod)) % mod


Input:
import sys

stdin = sys.stdin

ni = lambda: int(ns())

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

ns = lambda: stdin.readline()

def Solve():

    N,K=na()

    S=[int(d) for d in input()]

    l=[]

    N=len(S)

    if(S[0]==0):

        l.append(0)

    b=S[0]

    ct=1

    for i in S[1:]:

        if(b!=i):

            l.append(ct)

            ct=1

            b=i

        else:

            ct+=1

    l.append(ct)

    len_l=len(l)

    if(len_l//2 <= K):

        return sum(l)

    ans = res = sum(l[:2*K+1])

    if(len_l%2==0):

        l.append(0)

        len_l+=1

    g = K * 2 + 1

    for i in range(K*2+1,len_l-1,2):

        ans -= l[i-g] + l[i-g+1]

        ans += l[i] + l[1+i]

        if(res<ans):

            res=ans

    #print(S)

    #print(l)

    #print(len_l)

    return res

print((Solve()))

import sys

stdin = sys.stdin

ni = lambda: int(ns())

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

ns = lambda: stdin.readline()

def Solve():

    N,K=na()

    S=input()

    l=[]

    N=len(S)

    #print(len(S))

    if(S[0]=="0"):

        #print("00")

        l.append(0)

    t=S[0]

    ct=1

    #print("aa")

    #print(S)

    #print(S[0],S[1],S[2])

    for b in S[1:]:

        #print(b)

        if(t!=b):

            l.append(ct)

            ct=1

            t=b

        else:

            ct+=1

    #print("bb")

    l.append(ct)

    len_l=len(l)

    if(len_l//2 <= K):

        return sum(l)

    ans = res = sum(l[:2*K+1])

    if(len_l%2==0):

        l.append(0)

        len_l+=1

    g = K * 2 + 1

    for i in range(K*2+1,len_l-1,2):

        ans -= l[i-g] + l[i-g+1]

        ans += l[i] + l[1+i]

        if(res<ans):

            res=ans

    #print(S)

    #print(l)

    #print(len_l)

    return res

print((Solve()))

import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def Solve():
    N, K = na()
    S = [int(d) for d in input()]
    l = []
    N = len(S)
    if S[0] == 0:
        l.append(0)
    b = S[0]
    ct = 1
    for i in S[1:]:
        if b != i:
            l.append(ct)
            ct = 1
            b = i
        else:
            ct += 1
    l.append(ct)
    len_l = len(l)
    if len_l // 2 <= K:
        return sum(l)
    ans = res = sum(l[: 2 * K + 1])
    if len_l % 2 == 0:
        l.append(0)
        len_l += 1
    g = K * 2 + 1
    for i in range(K * 2 + 1, len_l - 1, 2):
        ans -= l[i - g] + l[i - g + 1]
        ans += l[i] + l[1 + i]
        if res < ans:
            res = ans
    # print(S)
    # print(l)
    # print(len_l)
    return res

print((Solve()))

import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def Solve():
    N, K = na()
    S = input()
    l = []
    N = len(S)
    # print(len(S))
    if S[0] == "0":
        # print("00")
        l.append(0)
    t = S[0]
    ct = 1
    # print("aa")
    # print(S)
    # print(S[0],S[1],S[2])
    for b in S[1:]:
        # print(b)
        if t != b:
            l.append(ct)
            ct = 1
            t = b
        else:
            ct += 1
    # print("bb")
    l.append(ct)
    len_l = len(l)
    if len_l // 2 <= K:
        return sum(l)
    ans = res = sum(l[: 2 * K + 1])
    if len_l % 2 == 0:
        l.append(0)
        len_l += 1
    g = K * 2 + 1
    for i in range(K * 2 + 1, len_l - 1, 2):
        ans -= l[i - g] + l[i - g + 1]
        ans += l[i] + l[1 + i]
        if res < ans:
            res = ans
    # print(S)
    # print(l)
    # print(len_l)
    return res

print((Solve()))


Input:
import random, math

random.seed()

def gen(a, b, num):

    result = set()

    while 1:

        while 1:

            v = random.randint(a, b)//2*2+1

            if v not in result:

                break

        for x in range(3, int(math.sqrt(v))+1, 2):

            if v % x == 0:

                break

        else:

            result.add(v)

            if len(result) == num:

                break

    return result

class RH():

    def __init__(self, s, base, mod):

        self.base = base

        self.mod = mod

        self.rev = pow(base, mod-2, mod)

        l = len(s)

        self.h = h = [0]*(l+1)

        tmp = 0

        for i in range(l):

            num = ord(s[i])

            tmp = (tmp*base + num) % mod

            h[i+1] = tmp

    def calc(self, l, r):

        return (self.h[r] - self.h[l] * pow(self.base, r-l, self.mod)) % self.mod

    def fixed(self, length):

        v = pow(self.base, length, self.mod)

        h = self.h; mod = self.mod

        def fixed_calc(l):

            return (h[length+l] - h[l] * v) % mod

        return fixed_calc

class RRH():

    def __init__(self, s, num=10, primes=None):

        primes = primes or gen(2, 10**3, num)

        MOD = 10**9+7

        self.rhs = [RH(s, p, MOD) for p in primes]

    def calc(self, l, r):

        return [rh.calc(l, r) for rh in self.rhs]

    def fixed(self, length):

        fs = [rh.fixed(length) for rh in self.rhs]

        def multi_fixed_calc(l):

            return list(f(l) for f in fs)

        return multi_fixed_calc

T = input(); P = input()

primes = gen(2, 10**3, 2)

HT = RRH(T, primes=primes)

HP = RRH(P, primes=primes)

pv = HP.calc(0, len(P))

calc = HT.fixed(len(P))

for i in range(len(T)-len(P)+1):

    if calc(i) == pv:

        print(i)

class RH():

    def __init__(self, s, base, mod):

        self.base = base

        self.mod = mod

        self.rev = pow(base, mod-2, mod)

        l = len(s)

        self.h = h = [0]*(l+1)

        tmp = 0

        for i in range(l):

            num = ord(s[i])

            tmp = (tmp*base + num) % mod

            h[i+1] = tmp

    def calc(self, l, r):

        return (self.h[r] - self.h[l] * pow(self.base, r-l, self.mod)) % self.mod

    def fixed(self, length):

        v = pow(self.base, length, self.mod)

        h = self.h; mod = self.mod

        def fixed_calc(l):

            return (h[length+l] - h[l] * v) % mod

        return fixed_calc

T = input(); P = input()

MOD = 10**18+9

HT = RH(T, 11, MOD)

HP = RH(P, 11, MOD)

pv = HP.calc(0, len(P))

calc = HT.fixed(len(P))

for i in range(len(T)-len(P)+1):

    if calc(i) == pv:

        print(i)

import random, math

random.seed()

def gen(a, b, num):
    result = set()
    while 1:
        while 1:
            v = random.randint(a, b) // 2 * 2 + 1
            if v not in result:
                break
        for x in range(3, int(math.sqrt(v)) + 1, 2):
            if v % x == 0:
                break
        else:
            result.add(v)
            if len(result) == num:
                break
    return result

class RH:
    def __init__(self, s, base, mod):
        self.base = base
        self.mod = mod
        self.rev = pow(base, mod - 2, mod)
        l = len(s)
        self.h = h = [0] * (l + 1)
        tmp = 0
        for i in range(l):
            num = ord(s[i])
            tmp = (tmp * base + num) % mod
            h[i + 1] = tmp

    def calc(self, l, r):
        return (self.h[r] - self.h[l] * pow(self.base, r - l, self.mod)) % self.mod

    def fixed(self, length):
        v = pow(self.base, length, self.mod)
        h = self.h
        mod = self.mod

        def fixed_calc(l):
            return (h[length + l] - h[l] * v) % mod

        return fixed_calc

class RRH:
    def __init__(self, s, num=10, primes=None):
        primes = primes or gen(2, 10**3, num)
        MOD = 10**9 + 7
        self.rhs = [RH(s, p, MOD) for p in primes]

    def calc(self, l, r):
        return [rh.calc(l, r) for rh in self.rhs]

    def fixed(self, length):
        fs = [rh.fixed(length) for rh in self.rhs]

        def multi_fixed_calc(l):
            return list(f(l) for f in fs)

        return multi_fixed_calc

T = input()
P = input()
primes = gen(2, 10**3, 2)
HT = RRH(T, primes=primes)
HP = RRH(P, primes=primes)
pv = HP.calc(0, len(P))
calc = HT.fixed(len(P))
for i in range(len(T) - len(P) + 1):
    if calc(i) == pv:
        print(i)

class RH:
    def __init__(self, s, base, mod):
        self.base = base
        self.mod = mod
        self.rev = pow(base, mod - 2, mod)
        l = len(s)
        self.h = h = [0] * (l + 1)
        tmp = 0
        for i in range(l):
            num = ord(s[i])
            tmp = (tmp * base + num) % mod
            h[i + 1] = tmp

    def calc(self, l, r):
        return (self.h[r] - self.h[l] * pow(self.base, r - l, self.mod)) % self.mod

    def fixed(self, length):
        v = pow(self.base, length, self.mod)
        h = self.h
        mod = self.mod

        def fixed_calc(l):
            return (h[length + l] - h[l] * v) % mod

        return fixed_calc

T = input()
P = input()
MOD = 10**18 + 9
HT = RH(T, 11, MOD)
HP = RH(P, 11, MOD)
pv = HP.calc(0, len(P))
calc = HT.fixed(len(P))
for i in range(len(T) - len(P) + 1):
    if calc(i) == pv:
        print(i)

-            v = random.randint(a, b) // 2 * 2 + 1

-        for x in range(3, int(math.sqrt(v)) + 1, 2):

-    def __init__(self, s, num=10, primes=None):

-        primes = primes or gen(2, 10**3, num)

-        self.rhs = [RH(s, p, MOD) for p in primes]

-        return [rh.calc(l, r) for rh in self.rhs]

-        fs = [rh.fixed(length) for rh in self.rhs]

-            return list(f(l) for f in fs)


Input:
#coding:utf-8

import bisect

import sys

sys.setrecursionlimit(10**6)

write = sys.stdout.write

dbg = lambda *something : print(*something) if DEBUG else 0

DEBUG = True

def main(given = sys.stdin.readline):

    input = lambda : given().rstrip()

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

    II = lambda : int(input())

    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, t = LMIIS()

    ab = XLMIIS(n)

    dp1 = [[0]*t for _ in range(n)]

    for i in range(1, n):

        for j in range(1, t):

            if j < ab[i-1][0]:

                dp1[i][j] = dp1[i-1][j]

            else:

                dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-ab[i-1][0]] + ab[i-1][1])

    dp2 = [[0]*t for _ in range(n)]

    for i in range(1, n):

        for j in range(1, t):

            if j < ab[n - i][0]:

                dp2[i][j] = dp2[i-1][j]

            else:

                dp2[i][j] = max(dp2[i-1][j], dp2[i-1][j-ab[n-i][0]] + ab[n-i][1])

    ans = 0

    for i in range(n):

        for j in range(t - 1):

            ans = max(ans, dp1[i][j] + dp2[n - i - 1][t - j - 1] + ab[i][1])

    print(ans)

if __name__ == '__main__':

    main()

#coding:utf-8

import bisect

import sys

sys.setrecursionlimit(10**6)

write = sys.stdout.write

dbg = lambda *something : print(*something) if DEBUG else 0

DEBUG = True

def main(given = sys.stdin.readline):

    input = lambda : given().rstrip()

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

    II = lambda : int(input())

    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, t = LMIIS()

    ab = XLMIIS(n)

    ab.sort()

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

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

        for j in range(1, t):

            if j < ab[i-1][0]:

                dp1[i][j] = dp1[i-1][j]

            else:

                dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-ab[i-1][0]] + ab[i-1][1])

    ans = 0

    for i in range(n):

        ans = max(ans, dp1[i][t-1] + ab[i][1])

    print(ans)

if __name__ == '__main__':

    main()

# coding:utf-8
import bisect
import sys

sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something: print(*something) if DEBUG else 0
DEBUG = True

def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int, input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    n, t = LMIIS()
    ab = XLMIIS(n)
    dp1 = [[0] * t for _ in range(n)]
    for i in range(1, n):
        for j in range(1, t):
            if j < ab[i - 1][0]:
                dp1[i][j] = dp1[i - 1][j]
            else:
                dp1[i][j] = max(
                    dp1[i - 1][j], dp1[i - 1][j - ab[i - 1][0]] + ab[i - 1][1]
                )
    dp2 = [[0] * t for _ in range(n)]
    for i in range(1, n):
        for j in range(1, t):
            if j < ab[n - i][0]:
                dp2[i][j] = dp2[i - 1][j]
            else:
                dp2[i][j] = max(
                    dp2[i - 1][j], dp2[i - 1][j - ab[n - i][0]] + ab[n - i][1]
                )
    ans = 0
    for i in range(n):
        for j in range(t - 1):
            ans = max(ans, dp1[i][j] + dp2[n - i - 1][t - j - 1] + ab[i][1])
    print(ans)

if __name__ == "__main__":
    main()

# coding:utf-8
import bisect
import sys

sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something: print(*something) if DEBUG else 0
DEBUG = True

def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int, input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    n, t = LMIIS()
    ab = XLMIIS(n)
    ab.sort()
    dp1 = [[0] * t for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, t):
            if j < ab[i - 1][0]:
                dp1[i][j] = dp1[i - 1][j]
            else:
                dp1[i][j] = max(
                    dp1[i - 1][j], dp1[i - 1][j - ab[i - 1][0]] + ab[i - 1][1]
                )
    ans = 0
    for i in range(n):
        ans = max(ans, dp1[i][t - 1] + ab[i][1])
    print(ans)

if __name__ == "__main__":
    main()

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


Input:
import sys

input = sys.stdin.readline

sys.setrecursionlimit(1000000)

from collections import deque

def getN():

    return int(input())

def getList():

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

import math

n = getN()

nums = getList()

# nums.sort(reverse=True)

mx = max(nums)

mn = (mx+1) // 2

mndx = (mx % 2) + 1

from collections import Counter

cnt = Counter(nums)

for i in range(mn+1, mx+1):

    if cnt[i] < 2:

        print("Impossible")

        sys.exit()

if cnt[mn] != mndx:

    print("Impossible")

else:

    print("Possible")

import sys

import math

import copy

from heapq import heappush, heappop, heapify

from functools import cmp_to_key

from bisect import bisect_left, bisect_right

from collections import defaultdict, deque, Counter

# sys.setrecursionlimit(1000000)

# input aliases

input = sys.stdin.readline

getS = lambda: input().strip()

getN = lambda: int(input())

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

getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")

MOD = 10**9 + 7

divide = lambda x: pow(x, MOD-2, MOD)

def pim():

    print("Impossible")

    sys.exit()

def pp():

    print("Possible")

    sys.exit()

def solve():

    n = getN()

    nums = getList()

    cnt = Counter(nums)

    mx = max(nums)

    mn = min(nums)

    if cnt[mx] < 2:

        pim()

    if mn < (mx + 1) // 2:

        pim()

    if mx % 2 == 0:

        if cnt[mx//2] != 1:

            pim()

    else:

        if cnt[(mx+1) // 2] != 2:

            pim()

    for i in range((mx + 1) // 2 + 1, mx+1):

        if cnt[i] < 2:

            pim()

    pp()

def main():

    n = getN()

    for _ in range(n):

        solve()

    return

if __name__ == "__main__":

    # main()

    solve()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque

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

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

import math

n = getN()
nums = getList()
# nums.sort(reverse=True)
mx = max(nums)
mn = (mx + 1) // 2
mndx = (mx % 2) + 1
from collections import Counter

cnt = Counter(nums)
for i in range(mn + 1, mx + 1):
    if cnt[i] < 2:
        print("Impossible")
        sys.exit()
if cnt[mn] != mndx:
    print("Impossible")
else:
    print("Possible")

import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter

# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def pim():
    print("Impossible")
    sys.exit()

def pp():
    print("Possible")
    sys.exit()

def solve():
    n = getN()
    nums = getList()
    cnt = Counter(nums)
    mx = max(nums)
    mn = min(nums)
    if cnt[mx] < 2:
        pim()
    if mn < (mx + 1) // 2:
        pim()
    if mx % 2 == 0:
        if cnt[mx // 2] != 1:
            pim()
    else:
        if cnt[(mx + 1) // 2] != 2:
            pim()
    for i in range((mx + 1) // 2 + 1, mx + 1):
        if cnt[i] < 2:
            pim()
    pp()

def main():
    n = getN()
    for _ in range(n):
        solve()
    return

if __name__ == "__main__":
    # main()
    solve()

+from heapq import heappush, heappop, heapify

+from bisect import bisect_left, bisect_right

+from collections import defaultdict, deque, Counter

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

+getZList = lambda: [int(x) - 1 for x in input().split()]

+divide = lambda x: pow(x, MOD - 2, MOD)

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


Input:
import math

n=int(input())

waru=10**9+7

li=[]

li2=[]

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

    tmp=math.factorial(n)

    flag=1

    for j in range(len(li)):

        if i%li[j]==0:

            flag=0

            break

    if flag==1:

        li.append(i)

        li2.append(0)

        while tmp%i==0:

            li2[len(li)-1]+=1

            tmp=tmp//i

ans=1

# print(li)

# print(li2)

for i in range(len(li2)):

    ans*=li2[i]+1

print((ans%waru))

import sys

from collections import *

import heapq

import math

import bisect

from itertools import permutations,accumulate,combinations,product

from math import gcd

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

def factorization(n):

    arr = []

    temp = n

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

        if temp%i==0:

            cnt=0

            while temp%i==0:

                cnt+=1

                temp //= i

            arr.append([i, cnt])

    if temp!=1:

        arr.append([temp, 1])

    if arr==[]:

        arr.append([n, 1])

    return arr

n=int(input())

if n==1:

    print((1))

    exit()

d=defaultdict(int)

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

    tmp=factorization(i)

    for j in tmp:

        yaku,ko=j

        d[yaku]+=ko

# print(d)

ans=1

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

    ans*=i+1

    ans%=mod

print(ans)

import math

n = int(input())
waru = 10**9 + 7
li = []
li2 = []
for i in range(2, n + 1):
    tmp = math.factorial(n)
    flag = 1
    for j in range(len(li)):
        if i % li[j] == 0:
            flag = 0
            break
    if flag == 1:
        li.append(i)
        li2.append(0)
        while tmp % i == 0:
            li2[len(li) - 1] += 1
            tmp = tmp // i
ans = 1
# print(li)
# print(li2)
for i in range(len(li2)):
    ans *= li2[i] + 1
print((ans % waru))

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations, accumulate, combinations, product
from math import gcd

def input():
    return sys.stdin.readline()[:-1]

def ruiseki(lst):
    return [0] + list(accumulate(lst))

mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-(n**0.5) // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n = int(input())
if n == 1:
    print((1))
    exit()
d = defaultdict(int)
for i in range(2, n + 1):
    tmp = factorization(i)
    for j in tmp:
        yaku, ko = j
        d[yaku] += ko
# print(d)
ans = 1
for i in list(d.values()):
    ans *= i + 1
    ans %= mod
print(ans)

+from itertools import permutations, accumulate, combinations, product

+al = [chr(ord("a") + i) for i in range(26)]


Input:
#!/usr/bin/env pypy3

# N,M = map(int,sys.stdin.readline().split())

# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param

# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param

# s = sys.stdin.readline().rstrip()

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

# INF = float("inf")

import math,sys

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

a = tuple(map(int,sys.stdin.readline().split()))

#n = int(input())

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

g = math.gcd(a[0],a[1])

for i in range(2,n):

    g = math.gcd(g,a[i])

M = max(a)

acc = a[0]

for i in range(n):

    acc = math.gcd(acc,a[i])

if acc != 1:

    print("not coprime")

    exit()

LIMIT=max(a)

minPrime = [0]*(LIMIT+1)

minPrime[1] = 1

def make():

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

        if minPrime[i] == 0:

            minPrime[i] = i

            #print(i)

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

                #print(i,j)

                if minPrime[j] == 0:

                    minPrime[j] = i

make()

def factrial(N):

     ret = []

     while minPrime[N] != N:

         ret.append(minPrime[N])

         N = N//minPrime[N]

     if N != 1:

         ret.append(N)

     return ret

judge = set([])

pc = True

pairwise = True

p = set() #all prime

for e in a:

    if not pairwise:

        break

    asf = set(factrial(e))

    if judge & asf != set():

        pc = False

    #     #pairwise = False

    #     print("setwise coprime")

    #     exit(0)

    judge |= asf

# for i in a:

#     if not pc:

#         break

#     asf = set(factrial(i))

#     if judge & asf != set():

#         pc = False

#     judge |= asf

if pc:

    print("pairwise coprime")

elif g == 1:

    print("setwise coprime")

else:

    print("not coprime")

#!/usr/bin/env pypy3

# N,M = map(int,sys.stdin.readline().split())

# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param

# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param

# s = sys.stdin.readline().rstrip()

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

# INF = float("inf")

import math,sys

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

a = tuple(map(int,sys.stdin.readline().split()))

#n = int(input())

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

g = math.gcd(a[0],a[1])

for i in range(2,n):

    g = math.gcd(g,a[i])

M = max(a)

acc = a[0]

for i in range(n):

    acc = math.gcd(acc,a[i])

if acc != 1:

    print("not coprime")

    exit()

LIMIT=max(a)

minPrime = [0]*(LIMIT+1)

minPrime[1] = 1

def make():

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

        if minPrime[i] == 0:

            minPrime[i] = i

            #print(i)

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

                #print(i,j)

                if minPrime[j] == 0:

                    minPrime[j] = i

make()

def factrial(N):

     ret = []

     while minPrime[N] != N:

         ret.append(minPrime[N])

         N = N//minPrime[N]

     if N != 1:

         ret.append(N)

     return ret

judge = set([])

for e in a:

    asf = set(factrial(e))

    if judge & asf != set():

        print("setwise coprime")

        exit()

    judge |= asf

    #judge = judge | asf #too slow

print("pairwise coprime")

#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math, sys

n = int(sys.stdin.readline())
a = tuple(map(int, sys.stdin.readline().split()))
# n = int(input())
# a = list(map(int,input().split()))
g = math.gcd(a[0], a[1])
for i in range(2, n):
    g = math.gcd(g, a[i])
M = max(a)
acc = a[0]
for i in range(n):
    acc = math.gcd(acc, a[i])
if acc != 1:
    print("not coprime")
    exit()
LIMIT = max(a)
minPrime = [0] * (LIMIT + 1)
minPrime[1] = 1

def make():
    for i in range(2, LIMIT + 1):
        if minPrime[i] == 0:
            minPrime[i] = i
            # print(i)
            for j in range(i + i, LIMIT + 1, i):
                # print(i,j)
                if minPrime[j] == 0:
                    minPrime[j] = i

make()

def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(minPrime[N])
        N = N // minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

judge = set([])
pc = True
pairwise = True
p = set()  # all prime
for e in a:
    if not pairwise:
        break
    asf = set(factrial(e))
    if judge & asf != set():
        pc = False
    #     #pairwise = False
    #     print("setwise coprime")
    #     exit(0)
    judge |= asf
# for i in a:
#     if not pc:
#         break
#     asf = set(factrial(i))
#     if judge & asf != set():
#         pc = False
#     judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")

#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math, sys

n = int(sys.stdin.readline())
a = tuple(map(int, sys.stdin.readline().split()))
# n = int(input())
# a = list(map(int,input().split()))
g = math.gcd(a[0], a[1])
for i in range(2, n):
    g = math.gcd(g, a[i])
M = max(a)
acc = a[0]
for i in range(n):
    acc = math.gcd(acc, a[i])
if acc != 1:
    print("not coprime")
    exit()
LIMIT = max(a)
minPrime = [0] * (LIMIT + 1)
minPrime[1] = 1

def make():
    for i in range(2, LIMIT + 1):
        if minPrime[i] == 0:
            minPrime[i] = i
            # print(i)
            for j in range(i + i, LIMIT + 1, i):
                # print(i,j)
                if minPrime[j] == 0:
                    minPrime[j] = i

make()

def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(minPrime[N])
        N = N // minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

judge = set([])
for e in a:
    asf = set(factrial(e))
    if judge & asf != set():
        print("setwise coprime")
        exit()
    judge |= asf
    # judge = judge | asf #too slow
print("pairwise coprime")

-pc = True
-pairwise = True
-p = set()  # all prime
-    if not pairwise:
-        break
-        pc = False
-    #     #pairwise = False
-    #     print("setwise coprime")
-    #     exit(0)
+        print("setwise coprime")
+        exit()
-# for i in a:
-#     if not pc:
-#         break
-#     asf = set(factrial(i))
-#     if judge & asf != set():
-#         pc = False
-#     judge |= asf
-if pc:
-    print("pairwise coprime")
-elif g == 1:
-    print("setwise coprime")
-else:
-    print("not coprime")
+    # judge = judge | asf #too slow
+print("pairwise coprime")


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

mod = 1000000007

def pow(x, n):

    ret = 1

    while n > 0:

        if (n & 1) == 1:

            ret = (ret * x) % mod

        x = (x * x) % mod

        n >>= 1

    return ret

fac = [1]

inv = [1]

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

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

    inv.append(pow(fac[i], mod - 2))

def cmb(n, k):

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

def doit(n, m, k):

    ret = 0

    for d in range(m):

        ret = (ret + d * (m - d)) % mod

    return (ret * n * n * cmb(n * m - 2, k - 2)) % mod

print(((doit(n, m, k) + doit(m, n, k)) % mod))

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

mod = 1000000007

fac = [1]

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

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

def pow(x, n):

    ret = 1

    while n > 0:

        if (n & 1) == 1:

            ret = (ret * x) % mod

        x = (x * x) % mod

        n >>= 1

    return ret

def inv(i):

    return pow(fac[i], mod - 2)

def cmb(n, k):

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

x = sum(d * (m - d) for d in range(m)) % mod

y = sum(d * (n - d) for d in range(n)) % mod

c = cmb(n * m - 2, k - 2)

x = (x * n * n * c) % mod

y = (y * m * m * c) % mod

print(((x + y) % mod))

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

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

-        ret = (ret + d * (m - d)) % mod

-    return (ret * n * n * cmb(n * m - 2, k - 2)) % mod

-print(((doit(n, m, k) + doit(m, n, k)) % mod))

+x = sum(d * (m - d) for d in range(m)) % mod

+y = sum(d * (n - d) for d in range(n)) % mod


Input:
def main():

    from sys import stdin

    input = stdin.readline

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

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

    for i in range(r):

        l[i] -= 1

    d = [[10**8] * n for _ in range(n)]

    for _ in range(m):

        i, j, k = list(map(int, input().split()))

        d[i-1][j-1] = k

        d[j-1][i-1] = k

    # Warshall-Floyd algorithm

    for k in range(n):

        for i in range(n):

            for j in range(n):

                if d[i][j] > d[i][k] + d[k][j]:

                    d[i][j] = d[i][k] + d[k][j]

    # full search

    # 8! = 40320

    from itertools import permutations

    answer = 10**8

    for i in permutations(l):

        ans = 0

        for j in range(r-1):

            ans += d[i[j]][i[j+1]]

        if ans < answer:

            answer = ans

    print(answer)

main()

def main():

    from sys import stdin

    input = stdin.readline

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

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

    for i in range(r):

        l[i] -= 1

    d = [[10**8] * n for _ in range(n)]

    for _ in range(m):

        i, j, k = list(map(int, input().split()))

        d[i-1][j-1] = k

        d[j-1][i-1] = k

    # Warshall-Floyd algorithm

    for k in range(n):

        for i in range(n-1):

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

                if d[i][j] > d[i][k] + d[k][j]:

                    d[i][j] = d[i][k] + d[k][j]

                    d[j][i] = d[i][j]

    # full search

    # 8! = 40320

    from itertools import permutations

    answer = 10**8

    for i in permutations(l):

        ans = 0

        for j in range(r-1):

            ans += d[i[j]][i[j+1]]

        if ans < answer:

            answer = ans

    print(answer)

main()

def main():
    from sys import stdin

    input = stdin.readline
    n, m, r = list(map(int, input().split()))
    l = list(map(int, input().split()))
    for i in range(r):
        l[i] -= 1
    d = [[10**8] * n for _ in range(n)]
    for _ in range(m):
        i, j, k = list(map(int, input().split()))
        d[i - 1][j - 1] = k
        d[j - 1][i - 1] = k
    # Warshall-Floyd algorithm
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
    # full search
    # 8! = 40320
    from itertools import permutations

    answer = 10**8
    for i in permutations(l):
        ans = 0
        for j in range(r - 1):
            ans += d[i[j]][i[j + 1]]
        if ans < answer:
            answer = ans
    print(answer)

main()

def main():
    from sys import stdin

    input = stdin.readline
    n, m, r = list(map(int, input().split()))
    l = list(map(int, input().split()))
    for i in range(r):
        l[i] -= 1
    d = [[10**8] * n for _ in range(n)]
    for _ in range(m):
        i, j, k = list(map(int, input().split()))
        d[i - 1][j - 1] = k
        d[j - 1][i - 1] = k
    # Warshall-Floyd algorithm
    for k in range(n):
        for i in range(n - 1):
            for j in range(i + 1, n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                    d[j][i] = d[i][j]
    # full search
    # 8! = 40320
    from itertools import permutations

    answer = 10**8
    for i in permutations(l):
        ans = 0
        for j in range(r - 1):
            ans += d[i[j]][i[j + 1]]
        if ans < answer:
            answer = ans
    print(answer)

main()

-        for i in range(n):
-            for j in range(n):
+        for i in range(n - 1):
+            for j in range(i + 1, n):
+                    d[j][i] = d[i][j]