Input:
def main():

    n = int(eval(input()))

    s = eval(input())

    r_set, g_set, b_set = set(), set(), set()

    for i, c in enumerate(s):

        if c == "R":

            r_set.add(i)

        elif c == "G":

            g_set.add(i)

        elif c == "B":

            b_set.add(i)

    cnt = 0

    for i in range(n):

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

            k = 2 * j - i

            if i in r_set and j in g_set and k in b_set:

                cnt += 1

            elif i in r_set and j in b_set and k in g_set:

                cnt += 1

            elif i in g_set and j in r_set and k in b_set:

                cnt += 1

            elif i in g_set and j in b_set and k in r_set:

                cnt += 1

            elif i in b_set and j in r_set and k in g_set:

                cnt += 1

            elif i in b_set and j in g_set and k in r_set:

                cnt += 1

    print((len(r_set) * len(g_set) * len(b_set) - cnt))

if __name__ == "__main__":

    main()

def main():

    n = int(eval(input()))

    s = eval(input())

    r_set, g_set, b_set = set(), set(), set()

    for i, c in enumerate(s):

        if c == "R":

            r_set.add(i)

        elif c == "G":

            g_set.add(i)

        elif c == "B":

            b_set.add(i)

    cnt = 0

    for i in range(n):

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

            k = 2 * j - i

            if k >= n:

                continue

            if s[i] == s[j] or s[j] == s[k] or s[k] == s[i]:

                continue

            cnt += 1

    print((len(r_set) * len(g_set) * len(b_set) - cnt))

if __name__ == "__main__":

    main()

-            if i in r_set and j in g_set and k in b_set:

-            elif i in r_set and j in b_set and k in g_set:

-            elif i in g_set and j in r_set and k in b_set:

-            elif i in g_set and j in b_set and k in r_set:

-            elif i in b_set and j in r_set and k in g_set:

-            elif i in b_set and j in g_set and k in r_set:


Input:
import sys

n, *p = list(map(int, sys.stdin.read().split()))

def main():

    mi = float('inf')

    res = 0

    for i in range(n):

        if p[i] <= mi:

            res += 1

            mi = p[i]

    return res

if __name__ == '__main__':

    ans = main()

    print(ans)

import sys

n, *p = list(map(int, sys.stdin.read().split()))

def main():

    m = float('inf')

    cnt = 0

    for x in p:

        if x > m: continue

        cnt += 1

        m = x

    print(cnt)

if __name__ ==  '__main__':

    main()

import sys

n, *p = list(map(int, sys.stdin.read().split()))

def main():
    mi = float("inf")
    res = 0
    for i in range(n):
        if p[i] <= mi:
            res += 1
            mi = p[i]
    return res

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

import sys

n, *p = list(map(int, sys.stdin.read().split()))

def main():
    m = float("inf")
    cnt = 0
    for x in p:
        if x > m:
            continue
        cnt += 1
        m = x
    print(cnt)

if __name__ == "__main__":
    main()

-    mi = float("inf")
-    res = 0
-    for i in range(n):
-        if p[i] <= mi:
-            res += 1
-            mi = p[i]
-    return res
+    m = float("inf")
+    cnt = 0
+    for x in p:
+        if x > m:
+            continue
+        cnt += 1
+        m = x
+    print(cnt)
-    ans = main()
-    print(ans)
+    main()


Input:
import itertools

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

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

def min_cost(target, l_list):

  if target in l_list:

    return 0

  else:

    res = 1000

    for l in l_list:

      res = min(res, abs(target - l))

    for i, l in enumerate(l_list):

      res = min(res, min_cost(target-l, l_list[:i]+l_list[i+1:]) + 10)

    return res

ans = 1000 * 3

combs = list(itertools.product([0, 1, 2], repeat=N))

for comb in combs:

  labc = [[], [], []]

  for i, idx in enumerate(comb):

    labc[idx].append(L[i])

  la, lb, lc = labc

  if len(la)*len(lb)*len(lc):

    ans = min(ans, min_cost(A, la)+min_cost(B, lb)+min_cost(C, lc))

print(ans)

import itertools

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

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

def min_cost(target, l_list):

  return 10*(len(l_list) - 1) + abs(target - sum(l_list))

ans = 1000 * 3

combs = list(itertools.product([0, 1, 2, 3], repeat=N))

for comb in combs:

  labcn = [[], [], [], []]

  for i, idx in enumerate(comb):

    labcn[idx].append(L[i])

  la, lb, lc, ln = labcn

  if len(la)*len(lb)*len(lc):

    ans = min(ans, min_cost(A, la)+min_cost(B, lb)+min_cost(C, lc))

print(ans)

import itertools

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]

def min_cost(target, l_list):
    if target in l_list:
        return 0
    else:
        res = 1000
        for l in l_list:
            res = min(res, abs(target - l))
        for i, l in enumerate(l_list):
            res = min(res, min_cost(target - l, l_list[:i] + l_list[i + 1 :]) + 10)
        return res

ans = 1000 * 3
combs = list(itertools.product([0, 1, 2], repeat=N))
for comb in combs:
    labc = [[], [], []]
    for i, idx in enumerate(comb):
        labc[idx].append(L[i])
    la, lb, lc = labc
    if len(la) * len(lb) * len(lc):
        ans = min(ans, min_cost(A, la) + min_cost(B, lb) + min_cost(C, lc))
print(ans)

import itertools

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]

def min_cost(target, l_list):
    return 10 * (len(l_list) - 1) + abs(target - sum(l_list))

ans = 1000 * 3
combs = list(itertools.product([0, 1, 2, 3], repeat=N))
for comb in combs:
    labcn = [[], [], [], []]
    for i, idx in enumerate(comb):
        labcn[idx].append(L[i])
    la, lb, lc, ln = labcn
    if len(la) * len(lb) * len(lc):
        ans = min(ans, min_cost(A, la) + min_cost(B, lb) + min_cost(C, lc))
print(ans)

-            res = min(res, abs(target - l))

-            res = min(res, min_cost(target - l, l_list[:i] + l_list[i + 1 :]) + 10)

+    return 10 * (len(l_list) - 1) + abs(target - sum(l_list))

-combs = list(itertools.product([0, 1, 2], repeat=N))

+combs = list(itertools.product([0, 1, 2, 3], repeat=N))


Input:
# coding: utf-8

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

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

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

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

P.sort(reverse=True)

Q.sort(reverse=True)

R.sort(reverse=True)

ans = 0

L = P[:X] + Q[:Y]

Rt = [False for _ in range(C)]

L.sort()

idx = 0

for i in range(X+Y):

    if idx >= C:

        break

    if L[i] < R[idx]:

        L[i] = R[idx]

        idx += 1

print((sum(L)))

# coding: utf-8

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

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

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

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

P.sort(reverse=True)

Q.sort(reverse=True)

R.sort(reverse=True)

ans = 0

L = P[:X] + Q[:Y]

L.sort()

idx = 0

for i in range(X+Y):

    if idx >= C:

        break

    if L[i] < R[idx]:

        L[i] = R[idx]

        idx += 1

print((sum(L)))

# coding: utf-8
X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
ans = 0
L = P[:X] + Q[:Y]
Rt = [False for _ in range(C)]
L.sort()
idx = 0
for i in range(X + Y):
    if idx >= C:
        break
    if L[i] < R[idx]:
        L[i] = R[idx]
        idx += 1
print((sum(L)))

# coding: utf-8
X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
ans = 0
L = P[:X] + Q[:Y]
L.sort()
idx = 0
for i in range(X + Y):
    if idx >= C:
        break
    if L[i] < R[idx]:
        L[i] = R[idx]
        idx += 1
print((sum(L)))


Input:
x = eval(input())

print((int(x)**3))

n = int(eval(input()))
print((n * n * n))

-x = eval(input())
-print((int(x) ** 3))
+n = int(eval(input()))
+print((n * n * n))


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

s = eval(input())

d1 = set()

d2 = set()

d3 = set()

for c in s:

    for t in d2:

        d3.add(t + c)

    for t in d1:

        d2.add(t + c)

    d1.add(c)

print((len(d3)))

from bisect import bisect

n = int(eval(input()))

s = eval(input())

location = [[] for _ in range(10)]

for i, c in enumerate(map(int, s)):

    location[c].append(i)

location = [loc for loc in location if loc]

last_indices = [loc[-1] for loc in location]

ans = 0

for loc_x in location:

    i = loc_x[0]

    for loc_y in location:

        ji = bisect(loc_y, i)

        if ji >= len(loc_y):

            continue

        j = loc_y[ji]

        ans += sum(j < li for li in last_indices)

print(ans)

+location = [loc for loc in location if loc]

+last_indices = [loc[-1] for loc in location]

+        ans += sum(j < li for li in last_indices)


Input:
N=int(input())

d={}

for i in range(N):

  tmp = input()

  if tmp in d:

    d[tmp] += 1

  else:

    d[tmp] = 1

max_v=max(d.values())

ans=list(filter(lambda x: x[1] == max_v, d.items()))

[print(i[0]) for i in sorted(ans)]

from collections import Counter

N = int(eval(input()))

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

l = Counter(S)

MAXNUM = max(l.values())

for s in sorted(list(set(S))):

    if l[s] == MAXNUM:

        print(s)

N = int(input())
d = {}
for i in range(N):
    tmp = input()
    if tmp in d:
        d[tmp] += 1
    else:
        d[tmp] = 1
max_v = max(d.values())
ans = list(filter(lambda x: x[1] == max_v, d.items()))
[print(i[0]) for i in sorted(ans)]

-ans = list(filter(lambda x: x[1] == max_v, d.items()))


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

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

def bfs():

    q = [(0, 0, 1)]

    m = []

    while len(q) > 0:

        x, y, c = q.pop(0)

        for xx, yy in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:

            if (H, W) == (yy + 1, xx + 1):

                return c + 1

            if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == '.' and \

                    (xx, yy) not in m:

                m.append((xx, yy))

                q.append((xx, yy, c + 1))

    return -1

def main():

    dc = 0

    for i in range(H):

        for j in range(W):

            if S[i][j] == '.':

                dc += 1

    c = bfs()

    if c == -1:

        print(-1)

    else:

        print(dc - c)

main()

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

S = [input() for _ in range(H)]

def bfs():

    q = [(0, 0, 1)]

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

    while len(q) > 0:

        x, y, c = q.pop(0)

        for xx, yy in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:

            if (H, W) == (yy + 1, xx + 1):

                return c + 1

            if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == '.' and \

                    m[yy][xx] == 0:

                q.append((xx, yy, c + 1))

                m[yy][xx] = 1

    return -1

def main():

    dc = 0

    for i in range(H):

        dc += S[i].count('.')

    c = bfs()

    if c == -1:

        print(-1)

    else:

        print(dc - c)

main()

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

def bfs():
    q = [(0, 0, 1)]
    m = []
    while len(q) > 0:
        x, y, c = q.pop(0)
        for xx, yy in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
            if (H, W) == (yy + 1, xx + 1):
                return c + 1
            if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == "." and (xx, yy) not in m:
                m.append((xx, yy))
                q.append((xx, yy, c + 1))
    return -1

def main():
    dc = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                dc += 1
    c = bfs()
    if c == -1:
        print(-1)
    else:
        print(dc - c)

main()

H, W = map(int, input().split())
S = [input() for _ in range(H)]

def bfs():
    q = [(0, 0, 1)]
    m = [[0 for _ in range(W)] for _ in range(H)]
    while len(q) > 0:
        x, y, c = q.pop(0)
        for xx, yy in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
            if (H, W) == (yy + 1, xx + 1):
                return c + 1
            if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == "." and m[yy][xx] == 0:
                q.append((xx, yy, c + 1))
                m[yy][xx] = 1
    return -1

def main():
    dc = 0
    for i in range(H):
        dc += S[i].count(".")
    c = bfs()
    if c == -1:
        print(-1)
    else:
        print(dc - c)

main()

+    m = [[0 for _ in range(W)] for _ in range(H)]

-            if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == "." and (xx, yy) not in m:

+            if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == "." and m[yy][xx] == 0:


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

l, r = [0] * q, [0] * q

for i in range(q):

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

mini = min(min(l), min(r))

maxi = max(max(l), max(r))

ans = [0] * (maxi + 1)

prime = [0] * (maxi + 1)

def judge_prime(n):

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

        if n % i == 0:

            return False

    return True if n != 1 else False

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

    prime[i] = judge_prime(i)

for i in range(mini, maxi + 1, 2):

    ans[i] = ans[i - 2] + 1 if prime[i] and prime[(i + 1) // 2] else ans[i - 2]

for i in range(q):

    print((ans[r[i]] - ans[max(0, l[i] - 2)]))

import math

import numpy as np

def get_prime(n):

    if n<= 1:

        return[]

    prime = [2]

    limit = int(math.sqrt(n))

    data = [i + 1 for i in range(2,n,2)]

    while limit > data[0]:

        prime.append(data[0])

        data = [j for j in data if j % data[0] != 0]

    return prime + data

def is_prime(n):

    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):

        if n % k == 0:

            return False

    return True

n = int(eval(input()))

l = []

r = []

for i in range(n):

    l_, r_ =list(map(int,input().split()))

    l.append(l_)

    r.append(r_)

a = get_prime(10**5+1)

b = np.array([0]*(10**5+2))

c =0

d = 0

add = 0

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

    if is_prime((a[i]+1)/2):

        d = a[i]

        b[c:d] = add

        c = d

        add +=1

b[c:] = add

b[0::2] = 0

for i in range(n):

    e = b[max(0, l[i] - 2)]

    f = b[r[i]]

    print((f - e))

q = int(eval(input()))
l, r = [0] * q, [0] * q
for i in range(q):
    l[i], r[i] = list(map(int, input().split()))
mini = min(min(l), min(r))
maxi = max(max(l), max(r))
ans = [0] * (maxi + 1)
prime = [0] * (maxi + 1)

def judge_prime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True if n != 1 else False

for i in range((mini + 1) // 2, maxi + 1):
    prime[i] = judge_prime(i)
for i in range(mini, maxi + 1, 2):
    ans[i] = ans[i - 2] + 1 if prime[i] and prime[(i + 1) // 2] else ans[i - 2]
for i in range(q):
    print((ans[r[i]] - ans[max(0, l[i] - 2)]))

import math
import numpy as np

def get_prime(n):
    if n <= 1:
        return []
    prime = [2]
    limit = int(math.sqrt(n))
    data = [i + 1 for i in range(2, n, 2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data

def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(eval(input()))
l = []
r = []
for i in range(n):
    l_, r_ = list(map(int, input().split()))
    l.append(l_)
    r.append(r_)
a = get_prime(10**5 + 1)
b = np.array([0] * (10**5 + 2))
c = 0
d = 0
add = 0
for i in range(1, len(a)):
    if is_prime((a[i] + 1) / 2):
        d = a[i]
        b[c:d] = add
        c = d
        add += 1
b[c:] = add
b[0::2] = 0
for i in range(n):
    e = b[max(0, l[i] - 2)]
    f = b[r[i]]
    print((f - e))

-    l[i], r[i] = list(map(int, input().split()))

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

+    data = [i + 1 for i in range(2, n, 2)]

+        data = [j for j in data if j % data[0] != 0]

-for i in range((mini + 1) // 2, maxi + 1):

-    ans[i] = ans[i - 2] + 1 if prime[i] and prime[(i + 1) // 2] else ans[i - 2]

+    for k in range(2, int(math.sqrt(n)) + 1):

+    l_, r_ = list(map(int, input().split()))


Input:
x=input().split()

y=list(map(int,x))

a=y[0]

b=y[1]

c=y[2]

d=sorted([a,b,c])

print(("{0} {1} {2}".format(d[0],d[1],d[2])))

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


Input:
import sys

input = sys.stdin.buffer.readline

import fractions

from functools import reduce

def main():

    N = int(eval(input()))

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

    MOD = 10**9+7

    def lcm(x,y):

        return((x*y)//fractions.gcd(x,y))

    l = reduce(lcm,a)

    ans = 0

    for num in a:

        ans += l//num

    print((ans%MOD))

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.buffer.readline

from collections import defaultdict

def main():

    N = int(eval(input()))

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

    MOD = 10**9+7

    d = defaultdict(int)

    for x in a:

        num = x

        count = 0

        while num%2 == 0:

            num //= 2

            count += 1

        d[2] = max(d[2],count)

        for i in range(3,int(x**(1/2))+1,2):

            if num%i == 0:

                count = 0

                while num%i == 0:

                    num //= i

                    count += 1

                d[i] = max(d[i],count)

        if num != 1:

            d[num] = max(d[num],1)

    base = 1

    for x,y in list(d.items()):

        base *= pow(x,y,MOD)

        base %= MOD

    s = 0

    for num in a:

        inv_a = pow(num,MOD-2,MOD)

        s += inv_a

        s %= MOD

    print(((base*s)%MOD))

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.buffer.readline
import fractions
from functools import reduce

def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))
    MOD = 10**9 + 7

    def lcm(x, y):
        return (x * y) // fractions.gcd(x, y)

    l = reduce(lcm, a)
    ans = 0
    for num in a:
        ans += l // num
    print((ans % MOD))

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))
    MOD = 10**9 + 7
    d = defaultdict(int)
    for x in a:
        num = x
        count = 0
        while num % 2 == 0:
            num //= 2
            count += 1
        d[2] = max(d[2], count)
        for i in range(3, int(x ** (1 / 2)) + 1, 2):
            if num % i == 0:
                count = 0
                while num % i == 0:
                    num //= i
                    count += 1
                d[i] = max(d[i], count)
        if num != 1:
            d[num] = max(d[num], 1)
    base = 1
    for x, y in list(d.items()):
        base *= pow(x, y, MOD)
        base %= MOD
    s = 0
    for num in a:
        inv_a = pow(num, MOD - 2, MOD)
        s += inv_a
        s %= MOD
    print(((base * s) % MOD))

if __name__ == "__main__":
    main()

-        return (x * y) // fractions.gcd(x, y)

+                d[i] = max(d[i], count)


Input:
from collections import deque

import sys

sys.setrecursionlimit(10**7)

input = sys.stdin.readline

def solve():

  h,w,d  = (int(i) for i in input().split())

  a = deque([])

  for i in range(h):

    tmp = list(int(i) for i in input().split())

    a.append(tmp)

  query = [False]*(h*w)

  distance = [0]*(h*w+1)

  for i in range(h):

    for j in range(w):

      query[a[i][j] - 1] = (i,j)

  q = int(eval(input()))

  for i in range(d,h*w):

    leftx,lefty = query[i-d]

    rightx,righty = query[i]

    distance[i] = distance[i-d]+abs(rightx-leftx)+abs(righty-lefty)

  #print(distance)

  for i in range(q):

    l,r = (int(m) for m in input().split())

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

solve()

from collections import deque

import sys

sys.setrecursionlimit(10**7)

input = sys.stdin.readline

def solve():

  h,w,d  = (int(i) for i in input().split())

  a = deque([])

  for i in range(h):

    tmp = list(int(i) for i in input().split())

    a.append(tmp)

  query = [False]*(h*w)

  distance = [0]*(h*w+1)

  for i in range(h):

    for j in range(w):

      query[a[i][j] - 1] = (i,j)

  q = int(eval(input()))

  for i in range(d,h*w):

    leftx,lefty = query[i-d]

    rightx,righty = query[i]

    distance[i] = distance[i-d]+abs(rightx-leftx)+abs(righty-lefty)

  #print(distance)

  ans = []

  for i in range(q):

    l,r = (int(m) for m in input().split())

    ans.append(distance[r-1]-distance[l-1])

  print(("\n".join(map(str,ans))))

solve()

from collections import deque
import sys

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

def solve():
    h, w, d = (int(i) for i in input().split())
    a = deque([])
    for i in range(h):
        tmp = list(int(i) for i in input().split())
        a.append(tmp)
    query = [False] * (h * w)
    distance = [0] * (h * w + 1)
    for i in range(h):
        for j in range(w):
            query[a[i][j] - 1] = (i, j)
    q = int(eval(input()))
    for i in range(d, h * w):
        leftx, lefty = query[i - d]
        rightx, righty = query[i]
        distance[i] = distance[i - d] + abs(rightx - leftx) + abs(righty - lefty)
    # print(distance)
    for i in range(q):
        l, r = (int(m) for m in input().split())
        print((distance[r - 1] - distance[l - 1]))

solve()

from collections import deque
import sys

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

def solve():
    h, w, d = (int(i) for i in input().split())
    a = deque([])
    for i in range(h):
        tmp = list(int(i) for i in input().split())
        a.append(tmp)
    query = [False] * (h * w)
    distance = [0] * (h * w + 1)
    for i in range(h):
        for j in range(w):
            query[a[i][j] - 1] = (i, j)
    q = int(eval(input()))
    for i in range(d, h * w):
        leftx, lefty = query[i - d]
        rightx, righty = query[i]
        distance[i] = distance[i - d] + abs(rightx - leftx) + abs(righty - lefty)
    # print(distance)
    ans = []
    for i in range(q):
        l, r = (int(m) for m in input().split())
        ans.append(distance[r - 1] - distance[l - 1])
    print(("\n".join(map(str, ans))))

solve()

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

+        ans.append(distance[r - 1] - distance[l - 1])


Input:
s = eval(input())

ans = ""

for i in range(len(s)):

    if i%2 == 0:

        ans = ans + s[i]

print(ans)

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

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


Input:
def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    #from collections import defaultdict

    from itertools import combinations, permutations, accumulate, groupby

    #from itertools import product

    from bisect import bisect_left,bisect_right

    from heapq import heapify, heappop, heappush

    from math import floor, ceil

    #from operator import itemgetter

    #inf = 10**17

    #mod = 10**9 + 7

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

    s,p,r = list(map(int, input().split()))

    t = input().rstrip()

    hasi = []

    res = 0

    for i in range(n):

        if t[i]=='r':

            a = r

            b = 'p'

        if t[i]=='s':

            a = s

            b = 'r'

        if t[i]=='p':

            a = p

            b = 's'

        if i<k:

            res += a

            hasi.append(b)

        else:

            if t[i]==t[i-k] and b in hasi[i-k]:

                hasi.append('x')

                continue

            else:

                res += a

                hasi.append(b)

    print(res)

if __name__ == '__main__':

    main()

def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    #from collections import defaultdict

    from itertools import combinations, permutations, accumulate, groupby, product

    from bisect import bisect_left,bisect_right

    from heapq import heapify, heappop, heappush

    from math import floor, ceil

    #from operator import itemgetter

    #inf = 10**17

    #mod = 10**9 + 7

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

    r,s,p = list(map(int, input().split()))

    t = list(input().rstrip())

    score = []

    for i in t:

        if i == 'r':

            score.append(p)

        if i == 's':

            score.append(r)

        if i == 'p':

            score.append(s)

    res = sum(score)

    for i in range(k, n):

        if t[i] == t[i-k]:

            res -= score[i]

            t[i] = 'u'

    print(res)

if __name__ == '__main__':

    main()

def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque

    # from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby

    # from itertools import product
    from bisect import bisect_left, bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil

    # from operator import itemgetter
    # inf = 10**17
    # mod = 10**9 + 7
    n, k = list(map(int, input().split()))
    s, p, r = list(map(int, input().split()))
    t = input().rstrip()
    hasi = []
    res = 0
    for i in range(n):
        if t[i] == "r":
            a = r
            b = "p"
        if t[i] == "s":
            a = s
            b = "r"
        if t[i] == "p":
            a = p
            b = "s"
        if i < k:
            res += a
            hasi.append(b)
        else:
            if t[i] == t[i - k] and b in hasi[i - k]:
                hasi.append("x")
                continue
            else:
                res += a
                hasi.append(b)
    print(res)

if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque

    # from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left, bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil

    # from operator import itemgetter
    # inf = 10**17
    # mod = 10**9 + 7
    n, k = list(map(int, input().split()))
    r, s, p = list(map(int, input().split()))
    t = list(input().rstrip())
    score = []
    for i in t:
        if i == "r":
            score.append(p)
        if i == "s":
            score.append(r)
        if i == "p":
            score.append(s)
    res = sum(score)
    for i in range(k, n):
        if t[i] == t[i - k]:
            res -= score[i]
            t[i] = "u"
    print(res)

if __name__ == "__main__":
    main()

-    from itertools import combinations, permutations, accumulate, groupby

+    from itertools import combinations, permutations, accumulate, groupby, product

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

-            if t[i] == t[i - k] and b in hasi[i - k]:

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


Input:
(n,m,*b),a,*q=[list(map(int,t.split()))for t in open(0)]

t=[-1]*n

def r(x):

 while-1<t[x]:x=t[x]

 return x

def u(x):

 x,y=list(map(r,x))

 if x-y:

  if t[x]>t[y]:x,y=y,x

  t[x]+=t[y];t[y]=x

[*list(map(u,q))]

i=c=0

k=j=n+~m<<1

*d,=eval('[],'*n)

for v in a:d[r(i)]+=v,;i+=1

for p in d:x,*y=sorted(p)+[0];c+=x;b+=y[:-1];j-=p>[]

print(((c+sum(sorted(b)[:j]),'Impossible')[k>n]*(k>0)))

(n,m,*b),a,*q=[list(map(int,t.split()))for t in open(0)]

t=[-1]*n

def r(x):

 while-1<t[x]:x=t[x]

 return x

def u(x):

 x,y=list(map(r,x))

 if x-y:

  if t[x]>t[y]:x,y=y,x

  t[x]+=t[y];t[y]=x

[*list(map(u,q))]

i=c=0

k=j=n+~m<<1

*d,=eval('[],'*n)

for v in a:d[r(i)]+=v,;i+=1

for p in d:

 if p:x,*y=sorted(p);c+=x;b+=y;j-=1

print(((c+sum(sorted(b)[:j]),'Impossible')[k>n]*(k>0)))

(n, m, *b), a, *q = [list(map(int, t.split())) for t in open(0)]
t = [-1] * n

def r(x):
    while -1 < t[x]:
        x = t[x]
    return x

def u(x):
    x, y = list(map(r, x))
    if x - y:
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x

[*list(map(u, q))]
i = c = 0
k = j = n + ~m << 1
(*d,) = eval("[]," * n)
for v in a:
    d[r(i)] += (v,)
    i += 1
for p in d:
    x, *y = sorted(p) + [0]
    c += x
    b += y[:-1]
    j -= p > []
print(((c + sum(sorted(b)[:j]), "Impossible")[k > n] * (k > 0)))

(n, m, *b), a, *q = [list(map(int, t.split())) for t in open(0)]
t = [-1] * n

def r(x):
    while -1 < t[x]:
        x = t[x]
    return x

def u(x):
    x, y = list(map(r, x))
    if x - y:
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x

[*list(map(u, q))]
i = c = 0
k = j = n + ~m << 1
(*d,) = eval("[]," * n)
for v in a:
    d[r(i)] += (v,)
    i += 1
for p in d:
    if p:
        x, *y = sorted(p)
        c += x
        b += y
        j -= 1
print(((c + sum(sorted(b)[:j]), "Impossible")[k > n] * (k > 0)))


Input:
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

n = int(eval(input()))

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

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

for i, p in enumerate(P, 1):

  T[p-1].append(i)

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

D = [[-1]*n for _ in range(2)]

def dfs(color, v):

  if D[color][v] != -1:

    return D[color][v]

  l = len(T[v])

  x = X[v]

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

  dp[0][0] = 0

  for i, nv in enumerate(T[v]):

    for j in range(x+1):

      if j >= X[nv]:

        dp[i+1][j] = min(dp[i+1][j], dp[i][j-X[nv]]+dfs(color, nv))

      if j >= dfs(color^1, nv):

        dp[i+1][j] = min(dp[i+1][j], dp[i][j-dfs(color^1, nv)]+X[nv])

  res = min(dp[l])

  D[color][v] = res

  return res

ans = dfs(0, 0)

if ans == float("inf"):

  print("IMPOSSIBLE")

else:

  print("POSSIBLE")

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

import numpy as np

INF = 2**30

n = int(eval(input()))

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

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

for i, p in enumerate(P, 1):

  T[p-1].append(i)

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

D = [[-1]*n for _ in range(2)]

def dfs(color, v):

  if D[color][v] != -1:

    return D[color][v]

  l = len(T[v])

  x = X[v]

  dp = np.full(x+1, INF, dtype=np.int64)

  dp[0] = 0

  for i, nv in enumerate(T[v]):

    k = np.full(x+1, INF, dtype=np.int64)

    if x+1 >= X[nv]:

      np.minimum(k[X[nv]:], dp[:x+1-X[nv]]+dfs(color, nv), out=k[X[nv]:])

    if x+1 >= dfs(color^1, nv):

      np.minimum(k[dfs(color^1, nv):], dp[:x+1-dfs(color^1, nv)]+X[nv], out=k[dfs(color^1, nv):])

    dp = k.copy()

  res = dp.min()

  D[color][v] = res

  return res

ans = dfs(0, 0)

if ans == INF:

  print("IMPOSSIBLE")

else:

  print("POSSIBLE")

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(eval(input()))
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
    T[p - 1].append(i)
X = list(map(int, input().split()))
D = [[-1] * n for _ in range(2)]

def dfs(color, v):
    if D[color][v] != -1:
        return D[color][v]
    l = len(T[v])
    x = X[v]
    dp = [[float("inf")] * (x + 1) for _ in range(l + 1)]
    dp[0][0] = 0
    for i, nv in enumerate(T[v]):
        for j in range(x + 1):
            if j >= X[nv]:
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - X[nv]] + dfs(color, nv))
            if j >= dfs(color ^ 1, nv):
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - dfs(color ^ 1, nv)] + X[nv])
    res = min(dp[l])
    D[color][v] = res
    return res

ans = dfs(0, 0)
if ans == float("inf"):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np

INF = 2**30
n = int(eval(input()))
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
    T[p - 1].append(i)
X = list(map(int, input().split()))
D = [[-1] * n for _ in range(2)]

def dfs(color, v):
    if D[color][v] != -1:
        return D[color][v]
    l = len(T[v])
    x = X[v]
    dp = np.full(x + 1, INF, dtype=np.int64)
    dp[0] = 0
    for i, nv in enumerate(T[v]):
        k = np.full(x + 1, INF, dtype=np.int64)
        if x + 1 >= X[nv]:
            np.minimum(k[X[nv] :], dp[: x + 1 - X[nv]] + dfs(color, nv), out=k[X[nv] :])
        if x + 1 >= dfs(color ^ 1, nv):
            np.minimum(
                k[dfs(color ^ 1, nv) :],
                dp[: x + 1 - dfs(color ^ 1, nv)] + X[nv],
                out=k[dfs(color ^ 1, nv) :],
            )
        dp = k.copy()
    res = dp.min()
    D[color][v] = res
    return res

ans = dfs(0, 0)
if ans == INF:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

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

+    dp = np.full(x + 1, INF, dtype=np.int64)

-                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - X[nv]] + dfs(color, nv))

-            if j >= dfs(color ^ 1, nv):

+        k = np.full(x + 1, INF, dtype=np.int64)

+            np.minimum(k[X[nv] :], dp[: x + 1 - X[nv]] + dfs(color, nv), out=k[X[nv] :])

+        if x + 1 >= dfs(color ^ 1, nv):

+                k[dfs(color ^ 1, nv) :],

+                dp[: x + 1 - dfs(color ^ 1, nv)] + X[nv],

+                out=k[dfs(color ^ 1, nv) :],


Input:
import sys, re, os

from collections import deque, defaultdict, Counter

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

from itertools import permutations, combinations, product, accumulate

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from fractions import gcd

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

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

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

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

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

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

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

N = INT()

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

dic = defaultdict(int)

for s in S:

    if s[0] in "MARCH":

        dic[s[0]] += 1

march = list("MARCH")

comb = list(combinations(march, 3))

ans = 0

for a, b, c in comb:

    ans += dic[a] * dic[b] * dic[c]

print(ans)

import sys, re, os

from collections import deque, defaultdict, Counter

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

from itertools import permutations, combinations, product, accumulate

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from fractions import gcd

from bisect import bisect, bisect_left, bisect_right

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

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

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

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

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

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

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

N = INT()

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

dic = defaultdict(list)

for s in S:

    dic[s[0]].append(s)

L = list(combinations(list("MARCH"), 3))

# print(L)

cnt = 0

for l in L:

    # print(l)

    cnt += len(dic[l[0]]) * len(dic[l[1]]) * len(dic[l[2]])

print(cnt)

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

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

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

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

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

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

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

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
S = [eval(input()) for i in range(N)]
dic = defaultdict(int)
for s in S:
    if s[0] in "MARCH":
        dic[s[0]] += 1
march = list("MARCH")
comb = list(combinations(march, 3))
ans = 0
for a, b, c in comb:
    ans += dic[a] * dic[b] * dic[c]
print(ans)

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

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

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

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

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

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

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

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
S = [eval(input()) for i in range(N)]
dic = defaultdict(list)
for s in S:
    dic[s[0]].append(s)
L = list(combinations(list("MARCH"), 3))
# print(L)
cnt = 0
for l in L:
    # print(l)
    cnt += len(dic[l[0]]) * len(dic[l[1]]) * len(dic[l[2]])
print(cnt)

+from bisect import bisect, bisect_left, bisect_right

+L = list(combinations(list("MARCH"), 3))


Input:
from copy import deepcopy, copy

class QueenMAP():

    __slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]

    def __init__(self):

        self.yoko = set()

        self.tate = set()

        self.naname1 = set()

        self.naname2 = set()

        self.MAP = [["."] * 8 for _ in range(8)]

    def add(self, y, x):

        self.MAP[y][x] = "Q"

        self.yoko.add(y)

        self.tate.add(x)

        self.naname1.add(y - x)

        self.naname2.add(x + y)

    def check(self, y, x):

        if x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:

            return False

        return True

    def allcheck(self):

        for i in range(8):

            if not "Q" in self.MAP[i]:

                return False

        return True

def MAIN():

    f = lambda M: "\n".join("".join(map(str, m)) for m in M)

    QM = QueenMAP()

    n = int(eval(input()))

    for _ in range(n):

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

        QM.add(a, b)

    dp = [(deepcopy(QM), n)]

    while dp:

        Q, cnt = dp.pop()

        if cnt == 8:

            if Q.allcheck():

                print((f(Q.MAP)))

                break

            continue

        cnt += 1

        for i in range(8):

            if i in Q.yoko:

                continue

            for j in range(8):

                if Q.check(i, j):

                    CQ = deepcopy(Q)

                    CQ.add(i, j)

                    dp.append((CQ, cnt))

MAIN()

from copy import deepcopy, copy

class QueenMAP():

    __slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]

    def __init__(self):

        self.yoko = set()

        self.tate = set()

        self.naname1 = set()

        self.naname2 = set()

        self.MAP = [["."] * 8 for _ in range(8)]

    def add(self, y, x):

        self.MAP[y][x] = "Q"

        self.yoko.add(y)

        self.tate.add(x)

        self.naname1.add(y - x)

        self.naname2.add(x + y)

    def check(self, y, x):

        if y in self.yoko or x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:

            return False

        return True

    def allcheck(self):

        for i in range(8):

            if not "Q" in self.MAP[i]:

                return False

        return True

def MAIN():

    f = lambda M: "\n".join("".join(m) for m in M)

    QM = QueenMAP()

    n = int(eval(input()))

    for _ in range(n):

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

        QM.add(a, b)

    dp = [(deepcopy(QM), n)]

    while dp:

        Q, cnt = dp.pop()

        if cnt == 8:

            if Q.allcheck():

                print((f(Q.MAP)))

                break

            continue

        cnt += 1

        for i in range(8):

            for j in range(8):

                if Q.check(i, j):

                    CQ = deepcopy(Q)

                    CQ.add(i, j)

                    dp.append((CQ, cnt))

MAIN()

from copy import deepcopy, copy

class QueenMAP:
    __slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]

    def __init__(self):
        self.yoko = set()
        self.tate = set()
        self.naname1 = set()
        self.naname2 = set()
        self.MAP = [["."] * 8 for _ in range(8)]

    def add(self, y, x):
        self.MAP[y][x] = "Q"
        self.yoko.add(y)
        self.tate.add(x)
        self.naname1.add(y - x)
        self.naname2.add(x + y)

    def check(self, y, x):
        if x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:
            return False
        return True

    def allcheck(self):
        for i in range(8):
            if not "Q" in self.MAP[i]:
                return False
        return True

def MAIN():
    f = lambda M: "\n".join("".join(map(str, m)) for m in M)
    QM = QueenMAP()
    n = int(eval(input()))
    for _ in range(n):
        a, b = list(map(int, input().split()))
        QM.add(a, b)
    dp = [(deepcopy(QM), n)]
    while dp:
        Q, cnt = dp.pop()
        if cnt == 8:
            if Q.allcheck():
                print((f(Q.MAP)))
                break
            continue
        cnt += 1
        for i in range(8):
            if i in Q.yoko:
                continue
            for j in range(8):
                if Q.check(i, j):
                    CQ = deepcopy(Q)
                    CQ.add(i, j)
                    dp.append((CQ, cnt))

MAIN()

from copy import deepcopy, copy

class QueenMAP:
    __slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]

    def __init__(self):
        self.yoko = set()
        self.tate = set()
        self.naname1 = set()
        self.naname2 = set()
        self.MAP = [["."] * 8 for _ in range(8)]

    def add(self, y, x):
        self.MAP[y][x] = "Q"
        self.yoko.add(y)
        self.tate.add(x)
        self.naname1.add(y - x)
        self.naname2.add(x + y)

    def check(self, y, x):
        if (
            y in self.yoko
            or x in self.tate
            or (y - x) in self.naname1
            or (x + y) in self.naname2
        ):
            return False
        return True

    def allcheck(self):
        for i in range(8):
            if not "Q" in self.MAP[i]:
                return False
        return True

def MAIN():
    f = lambda M: "\n".join("".join(m) for m in M)
    QM = QueenMAP()
    n = int(eval(input()))
    for _ in range(n):
        a, b = list(map(int, input().split()))
        QM.add(a, b)
    dp = [(deepcopy(QM), n)]
    while dp:
        Q, cnt = dp.pop()
        if cnt == 8:
            if Q.allcheck():
                print((f(Q.MAP)))
                break
            continue
        cnt += 1
        for i in range(8):
            for j in range(8):
                if Q.check(i, j):
                    CQ = deepcopy(Q)
                    CQ.add(i, j)
                    dp.append((CQ, cnt))

MAIN()

-        if x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:

-    f = lambda M: "\n".join("".join(map(str, m)) for m in M)

+    f = lambda M: "\n".join("".join(m) for m in M)


Input:
s = eval(input())

q = int(eval(input()))

reverse_now = 0

first = ""

latter = ""

for i in range(q):

    k = list(input().split())

    if k[0] == "1":

        reverse_now = 1 - reverse_now

    else:

        f,c = k[1], k[2]

        if f == "1" and reverse_now == 0:

            first = c + first

        if f == "1" and reverse_now == 1:

            latter += c

        if f == "2" and reverse_now == 0:

            latter +=  c

        if f == "2" and reverse_now == 1:

            first = c + first

if reverse_now == 1:

    ans = list(first + s + latter)

    ans.reverse()

    ans = "".join(ans)

else:

    ans = first + s + latter

print(ans)

from collections import deque

s = eval(input())

q = int(eval(input()))

reverse_now = 0

first = deque([])

latter = ""

for i in range(q):

    k = list(input().split())

    if k[0] == "1":

        reverse_now = 1 - reverse_now

    else:

        f,c = k[1], k[2]

        if f == "1" and reverse_now == 0:

            first.appendleft(c)

        if f == "1" and reverse_now == 1:

            latter += c

        if f == "2" and reverse_now == 0:

            latter +=  c

        if f == "2" and reverse_now == 1:

            first.appendleft(c)

first = "".join(first)

if reverse_now == 1:

    ans = list(first + s + latter)

    ans.reverse()

    ans = "".join(ans)

else:

    ans = first + s + latter

print(ans)

s = eval(input())
q = int(eval(input()))
reverse_now = 0
first = ""
latter = ""
for i in range(q):
    k = list(input().split())
    if k[0] == "1":
        reverse_now = 1 - reverse_now
    else:
        f, c = k[1], k[2]
        if f == "1" and reverse_now == 0:
            first = c + first
        if f == "1" and reverse_now == 1:
            latter += c
        if f == "2" and reverse_now == 0:
            latter += c
        if f == "2" and reverse_now == 1:
            first = c + first
if reverse_now == 1:
    ans = list(first + s + latter)
    ans.reverse()
    ans = "".join(ans)
else:
    ans = first + s + latter
print(ans)

from collections import deque

s = eval(input())
q = int(eval(input()))
reverse_now = 0
first = deque([])
latter = ""
for i in range(q):
    k = list(input().split())
    if k[0] == "1":
        reverse_now = 1 - reverse_now
    else:
        f, c = k[1], k[2]
        if f == "1" and reverse_now == 0:
            first.appendleft(c)
        if f == "1" and reverse_now == 1:
            latter += c
        if f == "2" and reverse_now == 0:
            latter += c
        if f == "2" and reverse_now == 1:
            first.appendleft(c)
first = "".join(first)
if reverse_now == 1:
    ans = list(first + s + latter)
    ans.reverse()
    ans = "".join(ans)
else:
    ans = first + s + latter
print(ans)

+from collections import deque
+
-first = ""
+first = deque([])
-            first = c + first
+            first.appendleft(c)
-            first = c + first
+            first.appendleft(c)
+first = "".join(first)


Input:
import math

import string

import collections

from collections import Counter

def readints():

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

def nCr(n, r):

    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def has_duplicates2(seq):

    seen = []

    for item in seq:

        if not(item in seen):

            seen.append(item)

    return len(seq) != len(seen)

def divisor(n):

    divisor = []

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

        if n % i == 0:

            divisor.append(i)

    return divisor

# coordinates

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

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

n = int(eval(input()))

h = readints()

cnt = 0

ans = 0

for i in range(n-1):

    if h[i] >= h[i+1]:

        cnt += 1

    else:

        ans = max(cnt, ans)

        cnt = 0

print((max(ans, cnt)))

from copy import deepcopy

import math

import string

import collections

from collections import Counter

from collections import deque

from decimal import Decimal

import sys

import fractions

from operator import itemgetter

import itertools

import copy

def readints():

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

def nCr(n, r):

    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def has_duplicates2(seq):

    seen = []

    for item in seq:

        if not(item in seen):

            seen.append(item)

    return len(seq) != len(seen)

def divisor(n):

    divisor = []

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

        if n % i == 0:

            divisor.append(i)

    return divisor

# coordinates

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

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

n = int(eval(input()))

h = readints()

# print(h)

cnt = 0

ans = -1

for i in range(n-1):

    if h[i] >= h[i+1]:

        cnt += 1

    else:

        ans = max(cnt, ans)

        cnt = 0

print((max(ans, cnt)))

import math
import string
import collections
from collections import Counter

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

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not (item in seen):
            seen.append(item)
    return len(seq) != len(seen)

def divisor(n):
    divisor = []
    for i in range(1, n + 1):
        if n % i == 0:
            divisor.append(i)
    return divisor

# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(eval(input()))
h = readints()
cnt = 0
ans = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        cnt += 1
    else:
        ans = max(cnt, ans)
        cnt = 0
print((max(ans, cnt)))

from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy

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

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not (item in seen):
            seen.append(item)
    return len(seq) != len(seen)

def divisor(n):
    divisor = []
    for i in range(1, n + 1):
        if n % i == 0:
            divisor.append(i)
    return divisor

# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(eval(input()))
h = readints()
# print(h)
cnt = 0
ans = -1
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        cnt += 1
    else:
        ans = max(cnt, ans)
        cnt = 0
print((max(ans, cnt)))

+from copy import deepcopy
+from collections import deque
+from decimal import Decimal
+import sys
+import fractions
+from operator import itemgetter
+import itertools
+import copy
+# print(h)
-ans = 0
+ans = -1


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

s_list = []

for i in range(n):

    s_list.append(eval(input()))

# リストの各要素を空文字でjoin

s_str = ''.join(sorted(s_list))

print(s_str)

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

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

# リストの各要素を空文字でjoin

s_str = ''.join(sorted(s_list))

print(s_str)

n, l = list(map(int, input().split()))
s_list = []
for i in range(n):
    s_list.append(eval(input()))
# リストの各要素を空文字でjoin
s_str = "".join(sorted(s_list))
print(s_str)

n, length = list(map(int, input().split()))
s_list = [eval(input()) for i in range(n)]
# リストの各要素を空文字でjoin
s_str = "".join(sorted(s_list))
print(s_str)

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

+s_list = [eval(input()) for i in range(n)]


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

r1 = 0

count = 0

while r*r1 <= n:

    g1 = 0

    while r*r1+g*g1 <= n:

        if (n-(r*r1+g*g1))%b==0:

            count += 1

        g1 += 1

    r1 += 1

print(count)

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

ans = 0

for r in range(1+N//R):

    for g in range(1+N//G):

        #print(N-(r*R+g*G),r*R, g*G)

        if N-(r*R+g*G) < 0:

            break

        if (N-(r*R+g*G))%B==0:

            ans += 1

print(ans)

r, g, b, n = list(map(int, input().split()))
r1 = 0
count = 0
while r * r1 <= n:
    g1 = 0
    while r * r1 + g * g1 <= n:
        if (n - (r * r1 + g * g1)) % b == 0:
            count += 1
        g1 += 1
    r1 += 1
print(count)

R, G, B, N = list(map(int, input().split()))
ans = 0
for r in range(1 + N // R):
    for g in range(1 + N // G):
        # print(N-(r*R+g*G),r*R, g*G)
        if N - (r * R + g * G) < 0:
            break
        if (N - (r * R + g * G)) % B == 0:
            ans += 1
print(ans)

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

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


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

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

AB.sort()

res = 0

cnt = 0

for a, b in AB:

    tmp = M - cnt

    if tmp <= b:

        res += a * tmp

        break

    res += a * b

    cnt += b

print(res)

import sys

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

AB = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N)]

AB.sort()

res = 0

for a, b in AB:

    if M > b:

        M -= b

        res += a * b

    else:

        res += a * M

        break

print(res)

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

+AB = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N)]


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

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

ans=[0]*n

for i in a:

    ans[i-1]+=1

for k in ans:

    print(k)

n=int(input())

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

ans=[0]*n

for i in a:

    ans[i-1]+=1

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

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

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

-n = int(eval(input()))
+n = int(input())
-for k in ans:
-    print(k)
+print(*ans, sep="\n")


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

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

def FLOAT(): return float(eval(input()))

MOD = 10**9+7

n = INT()

a = [MAP() for _ in range(n)]

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

for i in range(n):

    for j in range(3):

        for k in range(3):

            if j==k:

                continue

            dp[i+1][k] = max(dp[i+1][k],dp[i][j]+a[i][k])

print((max(dp[n])))

n = int(eval(input()))

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

a = []

for i in range(n):

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

for i in range(n):

    for j in range(3):

        for k in range(3):

            if j==k:

                continue

            dp[i+1][j] = max(dp[i+1][j],dp[i][k] + a[i][j])

print((max(dp[n])))

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

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

def FLOAT():
    return float(eval(input()))

MOD = 10**9 + 7
n = INT()
a = [MAP() for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n + 1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])
print((max(dp[n])))

n = int(eval(input()))
dp = [[0] * 3 for i in range(n + 1)]
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + a[i][j])
print((max(dp[n])))

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

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


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

g = int(eval(input()))

print((g*2 - r))

r, g = list(map(int, [eval(input()) for _ in range(2)]))

print((g*2 - r))

r = int(eval(input()))
g = int(eval(input()))
print((g * 2 - r))

r, g = list(map(int, [eval(input()) for _ in range(2)]))
print((g * 2 - r))

+r, g = list(map(int, [eval(input()) for _ in range(2)]))


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

ret = 0

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

    ret += b

print(ret)

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

print((b * (t // a)))

-ret = 0
-for i in range(a, t + 1, a):
-    ret += b
-print(ret)
+print((b * (t // a)))


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

d = input().replace(" ","")

for i in range(n,10**9):

  check = True

  for j in str(i):

    if j in d:

      check = False

      break

  if check:

    print(i)

    break

import copy

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

d = input().split()

nd = list(map(str,list(range(10))))

for i in d:

  nd.remove(i)

l = len(str(n))

if "0" in nd:

  a1 = 1

else:

  a1 = 0

alist = nd[a1:]

for _ in range(l-1):

  tlist = []

  for i in alist:

    for j in nd:

      tlist.append(i+j)

  alist = copy.copy(tlist)

alist.append(nd[a1]+nd[0]*l)

for i in alist:

  if n <= int(i):

    print(i)

    exit()

n, k = list(map(int, input().split()))
d = input().replace(" ", "")
for i in range(n, 10**9):
    check = True
    for j in str(i):
        if j in d:
            check = False
            break
    if check:
        print(i)
        break

import copy

n, k = list(map(int, input().split()))
d = input().split()
nd = list(map(str, list(range(10))))
for i in d:
    nd.remove(i)
l = len(str(n))
if "0" in nd:
    a1 = 1
else:
    a1 = 0
alist = nd[a1:]
for _ in range(l - 1):
    tlist = []
    for i in alist:
        for j in nd:
            tlist.append(i + j)
    alist = copy.copy(tlist)
alist.append(nd[a1] + nd[0] * l)
for i in alist:
    if n <= int(i):
        print(i)
        exit()

+import copy
+
-d = input().replace(" ", "")
-for i in range(n, 10**9):
-    check = True
-    for j in str(i):
-        if j in d:
-            check = False
-            break
-    if check:
+d = input().split()
+nd = list(map(str, list(range(10))))
+for i in d:
+    nd.remove(i)
+l = len(str(n))
+if "0" in nd:
+    a1 = 1
+else:
+    a1 = 0
+alist = nd[a1:]
+for _ in range(l - 1):
+    tlist = []
+    for i in alist:
+        for j in nd:
+            tlist.append(i + j)
+    alist = copy.copy(tlist)
+alist.append(nd[a1] + nd[0] * l)
+for i in alist:
+    if n <= int(i):
-        break
+        exit()


Input:
from functools import reduce

def match_word(w1, w2):

    return w1 == w2 or w1+'.' == w2

def count_if(f, lst):

    count = 0

    for l in lst:

        count += 1 if f(l) else 0

    return count

def main():

    count = 0

    word = input().lower()

    while True:

        line = eval(input());

        if line == 'END_OF_TEXT':

            break

        count += count_if(lambda w: match_word(word, w.lower()), line.split())

    print(count)

if __name__ == '__main__':

    main()

def count_if(f, lst):

    count = 0

    for l in lst:

        count += 1 if f(l) else 0

    return count

def main():

    count = 0

    word = input().lower()

    while True:

        line = eval(input());

        if line == 'END_OF_TEXT':

            break

        count += count_if(lambda w: word == w.lower(), line.split())

    print(count)

if __name__ == '__main__':

    main()

from functools import reduce

def match_word(w1, w2):
    return w1 == w2 or w1 + "." == w2

def count_if(f, lst):
    count = 0
    for l in lst:
        count += 1 if f(l) else 0
    return count

def main():
    count = 0
    word = input().lower()
    while True:
        line = eval(input())
        if line == "END_OF_TEXT":
            break
        count += count_if(lambda w: match_word(word, w.lower()), line.split())
    print(count)

if __name__ == "__main__":
    main()

def count_if(f, lst):
    count = 0
    for l in lst:
        count += 1 if f(l) else 0
    return count

def main():
    count = 0
    word = input().lower()
    while True:
        line = eval(input())
        if line == "END_OF_TEXT":
            break
        count += count_if(lambda w: word == w.lower(), line.split())
    print(count)

if __name__ == "__main__":
    main()

-        count += count_if(lambda w: match_word(word, w.lower()), line.split())

+        count += count_if(lambda w: word == w.lower(), line.split())


Input:
import sys

input = lambda: sys.stdin.readline().rstrip()

class BIT:

  def __init__(self, n):

    self.bit = [0] * n

  def add(self, i, x):

    i += 1

    while i <= len(self.bit):

      self.bit[i-1] += x

      i += i & -i

  def sum_sub(self, i):

    a = 0

    i += 1

    while i:

      a += self.bit[i-1]

      i -= i & -i

    return a

  def sum(self, i, j):

    a = 0

    if j != 0:

      a += self.sum_sub(j-1)

    if i != 0:

      a -= self.sum_sub(i-1)

    return a

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

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

Bit=BIT(n)

for i in range(n):

  Bit.add(i,a[i])

for i in range(q):

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

  if t==0:

    Bit.add(a,b)

  else:

    print((Bit.sum(a,b)))

import sys

input = sys.stdin.readline

class BIT():

    def __init__(self, n, data=None):

        self.n = n

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

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

        if data:

            self.build(data)

    def build(self, data):

        for i in range(self.n):

            self.bit[i + 1] = self.data[i + 1] = data[i]

        for i in range(1, self.n):

            j = i + (i & (-i))

            if j <= self.n:

                self.bit[j] += self.bit[i]

    def add(self, idx, x):

        self.data[idx] += x

        while idx <= self.n:

            self.bit[idx] += x

            idx += (idx & (-idx))

    def sum(self, idx):

        s = 0

        while idx:

            s += self.bit[idx]

            idx -= (idx & (-idx))

        return s

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

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

bit=BIT(n,a)

for i in range(q):

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

    if t==0:

        bit.add(x+1,y)

    else:

        print((bit.sum(y)-bit.sum(x)))

import sys

input = lambda: sys.stdin.readline().rstrip()

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

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

    def sum_sub(self, i):
        a = 0
        i += 1
        while i:
            a += self.bit[i - 1]
            i -= i & -i
        return a

    def sum(self, i, j):
        a = 0
        if j != 0:
            a += self.sum_sub(j - 1)
        if i != 0:
            a -= self.sum_sub(i - 1)
        return a

n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
Bit = BIT(n)
for i in range(n):
    Bit.add(i, a[i])
for i in range(q):
    t, a, b = list(map(int, input().split()))
    if t == 0:
        Bit.add(a, b)
    else:
        print((Bit.sum(a, b)))

import sys

input = sys.stdin.readline

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

    def build(self, data):
        for i in range(self.n):
            self.bit[i + 1] = self.data[i + 1] = data[i]
        for i in range(1, self.n):
            j = i + (i & (-i))
            if j <= self.n:
                self.bit[j] += self.bit[i]

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

    def sum(self, idx):
        s = 0
        while idx:
            s += self.bit[idx]
            idx -= idx & (-idx)
        return s

n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
bit = BIT(n, a)
for i in range(q):
    t, x, y = list(map(int, input().split()))
    if t == 0:
        bit.add(x + 1, y)
    else:
        print((bit.sum(y) - bit.sum(x)))

-input = lambda: sys.stdin.readline().rstrip()

+            self.bit[i + 1] = self.data[i + 1] = data[i]

+                self.bit[j] += self.bit[i]

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

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

+        print((bit.sum(y) - bit.sum(x)))


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

t = 0

x = 0

y = 0

judge = True

for i in range(n):

    t1, x1, y1 = list(map(int, input().split()))

    if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1 or (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:

        judge = False

    x = x1

    y = y1

    t = t1

if judge == True:

    print("Yes")

else:

    print("No")

import sys

input = sys.stdin.readline

n = int(eval(input()))

t = 0

x = 0

y = 0

judge = True

for i in range(n):

    t1, x1, y1 = list(map(int, input().split()))

    if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1 or (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:

        judge = False

    x = x1

    y = y1

    t = t1

if judge == True:

    print("Yes")

else:

    print("No")

import sys

input = sys.stdin.readline
n = int(eval(input()))
t = 0
x = 0
y = 0
judge = True
for i in range(n):
    t1, x1, y1 = list(map(int, input().split()))
    if (abs(x1 - x) + abs(y1 - y)) / (t1 - t) > 1 or (
        abs(x1 - x) + abs(y1 - y)
    ) % 2 != (t1 - t) % 2:
        judge = False
    x = x1
    y = y1
    t = t1
if judge == True:
    print("Yes")
else:
    print("No")

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


Input:
import fractions

N = int(input())

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

ans = 1

for i in T:

    ans = ans / fractions.gcd(ans, i) * i

print(ans)

def gcd(x, y):

    if y == 0:

        return x

    else:

        return gcd(y, x%y)

def lcm(x,y):

    return x/gcd(x, y)*y

N = int(input())

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

ans = 1

for i in T:

    ans = lcm(ans, i)

print(ans)

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def lcm(x, y):
    return x / gcd(x, y) * y

N = int(input())
T = [int(input()) for _ in range(N)]
ans = 1
for i in T:
    ans = lcm(ans, i)
print(ans)

-    ans = ans / fractions.gcd(ans, i) * i


Input:
class Main:

    def __init__(self):

        self.N = int(eval(input()))

    def dfs(self, ret, cur, f1, f2, f3):

        if self.N < cur:

            return ret

        ret += 1 if f1 and f2 and f3 else 0

        ret = self.dfs(ret, cur * 10 + 7, True, f2, f3)

        ret = self.dfs(ret, cur * 10 + 5, f1, True, f3)

        ret = self.dfs(ret, cur * 10 + 3, f1, f2, True)

        return ret

    @staticmethod

    def main():

        main = Main()

        print((main.dfs(0, 0, False, False, False)))

Main.main()

N = eval(input())

def f(d, used, next):

    num = len(used | set(next))

    if d == 0:

        if num == 3:

            return 1

        else:

            return 0

    elif num == 3:

        return 3 ** d

    elif num == 2:

        return 3 ** d - 2 ** d

    else:

        return 3 ** d - 2 * (2 ** d) + 1

def high(N, used, ret):

    if N:

        if int(N[0]) > 3:

            ret += f(len(N) - 1, used, "3")

        if int(N[0]) > 5:

            ret += f(len(N) - 1, used, "5")

        if int(N[0]) > 7:

            ret += f(len(N) - 1, used, "7")

    else:

        if len(used) == 3:

            ret += 1

        return ret

    if N[0] in ["3", "5", "7"]:

        ret = high(N[1:], used | set(N[0]), ret)

    return ret

def low():

    d = 0

    ret = 0

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

        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)

        d += 1

    return ret

def main():

    print((high(N, set(), low())))

    return

main()

N = eval(input())

def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3**d
    elif num == 2:
        return 3**d - 2**d
    else:
        return 3**d - 2 * (2**d) + 1

def high(N, used, ret):
    if N:
        if int(N[0]) > 3:
            ret += f(len(N) - 1, used, "3")
        if int(N[0]) > 5:
            ret += f(len(N) - 1, used, "5")
        if int(N[0]) > 7:
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in ["3", "5", "7"]:
        ret = high(N[1:], used | set(N[0]), ret)
    return ret

def low():
    d = 0
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3**d - 2 ** (d + 1) + 1)
        d += 1
    return ret

def main():
    print((high(N, set(), low())))
    return

main()

-    def dfs(self, ret, cur, f1, f2, f3):

-        ret += 1 if f1 and f2 and f3 else 0

-        ret = self.dfs(ret, cur * 10 + 7, True, f2, f3)

-        ret = self.dfs(ret, cur * 10 + 5, f1, True, f3)

-        ret = self.dfs(ret, cur * 10 + 3, f1, f2, True)

-        print((main.dfs(0, 0, False, False, False)))

+        ret = high(N[1:], used | set(N[0]), ret)


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

txy = [0]*(N+1)

txy[0] = [0, 0, 0]

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

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

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

    dis = abs(txy[i][1] - txy[i-1][1]) + abs(txy[i][2] - txy[i-1][2])

    time = txy[i][0] - txy[i-1][0]

    if time < dis or (time - dis) % 2 != 0:

        print('No')

        break

else:

    print('Yes')

N = int(eval(input()))

now = [0, 0, 0]

for i in range(N):

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

    dis = abs(x-now[0]) + abs(y - now[1])

    if (t - now[2]) < dis:

        print('No')

        break

    elif ((t - now[2]) - dis) % 2 != 0:

        print('No')

        break

else:

    print('Yes')

N = int(eval(input()))
txy = [0] * (N + 1)
txy[0] = [0, 0, 0]
for i in range(1, N + 1):
    txy[i] = [int(i) for i in input().split()]
for i in range(1, N + 1):
    dis = abs(txy[i][1] - txy[i - 1][1]) + abs(txy[i][2] - txy[i - 1][2])
    time = txy[i][0] - txy[i - 1][0]
    if time < dis or (time - dis) % 2 != 0:
        print("No")
        break
else:
    print("Yes")

N = int(eval(input()))
now = [0, 0, 0]
for i in range(N):
    t, x, y = list(map(int, input().split()))
    dis = abs(x - now[0]) + abs(y - now[1])
    if (t - now[2]) < dis:
        print("No")
        break
    elif ((t - now[2]) - dis) % 2 != 0:
        print("No")
        break
else:
    print("Yes")

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

-    if time < dis or (time - dis) % 2 != 0:

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

+    dis = abs(x - now[0]) + abs(y - now[1])


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

area = [[0 for i in range(w)] for j in range(h)]

for i in range(n):

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

    if a == 1:

        for j in range(0, h):

            for k in range(0, x):

                area[j][k] = 1

    elif a == 2:

        for j in range(0, h):

            for k in range(x, w):

                area[j][k] = 1

    elif a == 3:

        for j in range(0, y):

            for k in range(0, w):

                area[j][k] = 1

    else:

        for j in range(y, h):

            for k in range(0, w):

                area[j][k] = 1

ans = 0

for i in range(h):

    for j in range(w):

        if area[i][j] == 0: ans += 1

print(ans)

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

l = 0

r = w

d = 0

u = h

for i in range(n):

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

    if a == 1: l = max(l, x)

    if a == 2: r = min(r, x)

    if a == 3: d = max(d, y)

    if a == 4: u = min(u, y)

ans = max(0, r - l) * max(0, u - d)

print(ans)

-area = [[0 for i in range(w)] for j in range(h)]


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

C = list(eval(input()))

l, r, c = 0, n-1, 0

while l < r:

    if C[l] == 'W' and C[r] == 'R':

        l += 1

        r -= 1

        c += 1

    elif C[l] != 'W': l += 1

    elif C[r] != 'R': r -= 1

print(c)

n = int(eval(input()))

C = list(eval(input()))

r = C.count('R')

c = 0

for i in range(r, n):

    if C[i] == 'R': c += 1

print(c)

n = int(eval(input()))
C = list(eval(input()))
l, r, c = 0, n - 1, 0
while l < r:
    if C[l] == "W" and C[r] == "R":
        l += 1
        r -= 1
        c += 1
    elif C[l] != "W":
        l += 1
    elif C[r] != "R":
        r -= 1
print(c)

n = int(eval(input()))
C = list(eval(input()))
r = C.count("R")
c = 0
for i in range(r, n):
    if C[i] == "R":
        c += 1
print(c)


Input:
from collections import deque

queue = deque()

for _ in range(int(eval(input()))):

    commands = input().split(" ")

    if commands[0] == "insert":

        queue.appendleft(commands[1])

    elif commands[0] == "delete":

        try:

            queue.remove(commands[1])

        except ValueError:

            pass

    elif commands[0] == "deleteFirst":

        queue.popleft()

    elif commands[0] == "deleteLast":

        queue.pop()

print((" ".join(queue)))

import sys

from collections import deque

n = int(eval(input()))

q = deque()

for i in range(n):

    c = sys.stdin.readline()[:-1]

    if c[0] == 'i':

        q.appendleft(c[7:])

    elif c[6] == ' ':

        try:

            q.remove(c[7:])

        except:

            pass

    elif c[6] == 'F':

        q.popleft()

    else:

        q.pop()

print((*q))

import sys
from collections import deque

n = int(eval(input()))
q = deque()
for i in range(n):
    c = sys.stdin.readline()[:-1]
    if c[0] == "i":
        q.appendleft(c[7:])
    elif c[6] == " ":
        try:
            q.remove(c[7:])
        except:
            pass
    elif c[6] == "F":
        q.popleft()
    else:
        q.pop()
print((*q))

+import sys
-queue = deque()
-for _ in range(int(eval(input()))):
-    commands = input().split(" ")
-    if commands[0] == "insert":
-        queue.appendleft(commands[1])
-    elif commands[0] == "delete":
+n = int(eval(input()))
+q = deque()
+for i in range(n):
+    c = sys.stdin.readline()[:-1]
+    if c[0] == "i":
+        q.appendleft(c[7:])
+    elif c[6] == " ":
-            queue.remove(commands[1])
-        except ValueError:
+            q.remove(c[7:])
+        except:
-    elif commands[0] == "deleteFirst":
-        queue.popleft()
-    elif commands[0] == "deleteLast":
-        queue.pop()
-print((" ".join(queue)))
+    elif c[6] == "F":
+        q.popleft()
+    else:
+        q.pop()
+print((*q))


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

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

S = [0]

for i in range(N):

        S.append(S[i]+A[i])

a_before = 1

c_before = 3

ans_tmp = []

for b in range(2,N-1):

        if S[a_before] > S[b] - S[a_before]:

                a=a_before

        else:

                for i in range(a_before,b):

                        if S[i] > S[b] - S[i]:

                                if abs(S[b]-S[i-1]-S[i-1]) < abs(S[b]-S[i]-S[i]):

                                        a=i-1

                                        a_before = i-1

                                        break

                                else:

                                        a=i

                                        a_before = i

                                        break

                else:

                        a=b-1

                        a_before = b-1

        if S[c_before] - S[b] > S[N] - S[c_before]:

                c=c_before

        else:

                for i in range(c_before,N):

                        if S[i] - S[b] > S[N] - S[i]:

                                if abs((S[N]-S[i-1]) - (S[i-1]-S[b])) < abs((S[N]-S[i]) - (S[i]-S[b])):

                                        c=i-1

                                        c_before = i-1

                                        break

                                else:

                                        c=i

                                        c_before = i

                                        break

                else:

                        c=N-1

                        c_before = N-1

        ans_tmp.append(max(S[N]-S[c],S[c]-S[b],S[b]-S[a],S[a]-S[0])-min(S[N]-S[c],S[c]-S[b],S[b]-S[a],S[a]-S[0]))

print((min(ans_tmp)))

N = int(eval(input()))

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

S = [0]

for i in range(N):

        S.append(S[i]+A[i])

a = 1

c = 3

ans_tmp = []

for b in range(2,N-1):

        while abs(S[b]-S[a]-S[a]) > abs(S[b]-S[a+1]-S[a+1]):

                a += 1

        while abs((S[N]-S[c]) - (S[c]-S[b])) > abs((S[N]-S[c+1]) - (S[c+1]-S[b])):

                c += 1

        ans_tmp.append(max(S[N]-S[c],S[c]-S[b],S[b]-S[a],S[a]-S[0])-min(S[N]-S[c],S[c]-S[b],S[b]-S[a],S[a]-S[0]))

print((min(ans_tmp)))

N = int(eval(input()))
A = list(map(int, input().split()))
S = [0]
for i in range(N):
    S.append(S[i] + A[i])
a_before = 1
c_before = 3
ans_tmp = []
for b in range(2, N - 1):
    if S[a_before] > S[b] - S[a_before]:
        a = a_before
    else:
        for i in range(a_before, b):
            if S[i] > S[b] - S[i]:
                if abs(S[b] - S[i - 1] - S[i - 1]) < abs(S[b] - S[i] - S[i]):
                    a = i - 1
                    a_before = i - 1
                    break
                else:
                    a = i
                    a_before = i
                    break
        else:
            a = b - 1
            a_before = b - 1
    if S[c_before] - S[b] > S[N] - S[c_before]:
        c = c_before
    else:
        for i in range(c_before, N):
            if S[i] - S[b] > S[N] - S[i]:
                if abs((S[N] - S[i - 1]) - (S[i - 1] - S[b])) < abs(
                    (S[N] - S[i]) - (S[i] - S[b])
                ):
                    c = i - 1
                    c_before = i - 1
                    break
                else:
                    c = i
                    c_before = i
                    break
        else:
            c = N - 1
            c_before = N - 1
    ans_tmp.append(
        max(S[N] - S[c], S[c] - S[b], S[b] - S[a], S[a] - S[0])
        - min(S[N] - S[c], S[c] - S[b], S[b] - S[a], S[a] - S[0])
    )
print((min(ans_tmp)))

N = int(eval(input()))
A = list(map(int, input().split()))
S = [0]
for i in range(N):
    S.append(S[i] + A[i])
a = 1
c = 3
ans_tmp = []
for b in range(2, N - 1):
    while abs(S[b] - S[a] - S[a]) > abs(S[b] - S[a + 1] - S[a + 1]):
        a += 1
    while abs((S[N] - S[c]) - (S[c] - S[b])) > abs(
        (S[N] - S[c + 1]) - (S[c + 1] - S[b])
    ):
        c += 1
    ans_tmp.append(
        max(S[N] - S[c], S[c] - S[b], S[b] - S[a], S[a] - S[0])
        - min(S[N] - S[c], S[c] - S[b], S[b] - S[a], S[a] - S[0])
    )
print((min(ans_tmp)))

-    if S[a_before] > S[b] - S[a_before]:

-    if S[c_before] - S[b] > S[N] - S[c_before]:


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

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

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

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

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

X = [[0] * N for _ in range(N)]

m = (1 << 64) - 1

for i in range(N):

    for j in range(N):

        if not S[i]:

            X[i][j] |= U[i]

        if not T[j]:

            X[i][j] |= V[j]

        X[i][j] |= U[i] & V[j]

A1 = [[m] * N for _ in range(N)]

A2 = [[m] * N for _ in range(N)]

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

    for j in range(N):

        A2[i][j] = A2[i+1][j] & X[i+1][j]

for i in range(N):

    a = 0

    for j in range(N):

        a |= X[i][j]

    for j in range(N):

        if i:

            A1[i][j] = A1[i-1][j] & X[i-1][j]

        if S[i] and not T[j]:

            X[i][j] |= U[i] & ~((A1[i][j] & A2[i][j]) | a)

        a |= X[i][j]

A1 = [[m] * N for _ in range(N)]

A2 = [[m] * N for _ in range(N)]

for j in range(N-1)[::-1]:

    for i in range(N):

        A2[i][j] = A2[i][j+1] & X[i][j+1]

for j in range(N):

    a = 0

    for i in range(N):

        a |= X[i][j]

    for i in range(N):

        if j:

            A1[i][j] = A1[i][j-1] & X[i][j-1]

        if T[j] and not S[i]:

            X[i][j] |= V[j] & ~((A1[i][j] & A2[i][j]) | a)

        a |= X[i][j]

for i in range(N):

    if S[i] == 0:

        s = m

        for j in range(N):

            s &= X[i][j]

        if s != U[i]:

            print((-1))

            exit()

    else:

        s = 0

        for j in range(N):

            s |= X[i][j]

        if s != U[i]:

            print((-1))

            exit()

for j in range(N):

    if T[j] == 0:

        s = m

        for i in range(N):

            s &= X[i][j]

        if s != V[j]:

            print((-1))

            exit()

    else:

        s = 0

        for i in range(N):

            s |= X[i][j]

        if s != V[j]:

            print((-1))

            exit()

for x in X:

    print((*x))

from functools import reduce

from operator import and_, or_

N = int(eval(input()))

S, T, U, V = [[int(a) for a in input().split()] for _ in range(4)]

X = [[U[i] & V[j] if S[i] and T[j] else U[i] if T[j] else V[j] if S[i] else U[i] | V[j] for j in range(N)] for i in range(N)]

m = (1 << 64) - 1

for _ in range(2):

    A1 = [[m] * N for _ in range(N)]

    A2 = [[m] * N for _ in range(N)]

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

        for j in range(N):

            A2[i][j] = A2[i+1][j] & X[i+1][j]

    for i in range(N):

        a = ~U[i] | reduce(or_, X[i])

        for j in range(N):

            if i:

                A1[i][j] = A1[i-1][j] & X[i-1][j]

            if S[i] and not T[j]:

                X[i][j] |= ~(A1[i][j] & A2[i][j] | a)

            a |= X[i][j]

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

    S, T, U, V = T, S, V, U

if [reduce(or_ if S[i] else and_, x) for i, x in enumerate(X)] != U or [reduce(or_ if T[j] else and_, x) for j, x in enumerate(zip(*X))] != V:

    print((-1))

    exit()

for x in X:

    print((*x))

N = int(eval(input()))
S = [int(a) for a in input().split()]
T = [int(a) for a in input().split()]
U = [int(a) for a in input().split()]
V = [int(a) for a in input().split()]
X = [[0] * N for _ in range(N)]
m = (1 << 64) - 1
for i in range(N):
    for j in range(N):
        if not S[i]:
            X[i][j] |= U[i]
        if not T[j]:
            X[i][j] |= V[j]
        X[i][j] |= U[i] & V[j]
A1 = [[m] * N for _ in range(N)]
A2 = [[m] * N for _ in range(N)]
for i in range(N - 1)[::-1]:
    for j in range(N):
        A2[i][j] = A2[i + 1][j] & X[i + 1][j]
for i in range(N):
    a = 0
    for j in range(N):
        a |= X[i][j]
    for j in range(N):
        if i:
            A1[i][j] = A1[i - 1][j] & X[i - 1][j]
        if S[i] and not T[j]:
            X[i][j] |= U[i] & ~((A1[i][j] & A2[i][j]) | a)
        a |= X[i][j]
A1 = [[m] * N for _ in range(N)]
A2 = [[m] * N for _ in range(N)]
for j in range(N - 1)[::-1]:
    for i in range(N):
        A2[i][j] = A2[i][j + 1] & X[i][j + 1]
for j in range(N):
    a = 0
    for i in range(N):
        a |= X[i][j]
    for i in range(N):
        if j:
            A1[i][j] = A1[i][j - 1] & X[i][j - 1]
        if T[j] and not S[i]:
            X[i][j] |= V[j] & ~((A1[i][j] & A2[i][j]) | a)
        a |= X[i][j]
for i in range(N):
    if S[i] == 0:
        s = m
        for j in range(N):
            s &= X[i][j]
        if s != U[i]:
            print((-1))
            exit()
    else:
        s = 0
        for j in range(N):
            s |= X[i][j]
        if s != U[i]:
            print((-1))
            exit()
for j in range(N):
    if T[j] == 0:
        s = m
        for i in range(N):
            s &= X[i][j]
        if s != V[j]:
            print((-1))
            exit()
    else:
        s = 0
        for i in range(N):
            s |= X[i][j]
        if s != V[j]:
            print((-1))
            exit()
for x in X:
    print((*x))

from functools import reduce
from operator import and_, or_

N = int(eval(input()))
S, T, U, V = [[int(a) for a in input().split()] for _ in range(4)]
X = [
    [
        U[i] & V[j]
        if S[i] and T[j]
        else U[i]
        if T[j]
        else V[j]
        if S[i]
        else U[i] | V[j]
        for j in range(N)
    ]
    for i in range(N)
]
m = (1 << 64) - 1
for _ in range(2):
    A1 = [[m] * N for _ in range(N)]
    A2 = [[m] * N for _ in range(N)]
    for i in range(N - 1)[::-1]:
        for j in range(N):
            A2[i][j] = A2[i + 1][j] & X[i + 1][j]
    for i in range(N):
        a = ~U[i] | reduce(or_, X[i])
        for j in range(N):
            if i:
                A1[i][j] = A1[i - 1][j] & X[i - 1][j]
            if S[i] and not T[j]:
                X[i][j] |= ~(A1[i][j] & A2[i][j] | a)
            a |= X[i][j]
    X = [[X[j][i] for j in range(N)] for i in range(N)]
    S, T, U, V = T, S, V, U
if [reduce(or_ if S[i] else and_, x) for i, x in enumerate(X)] != U or [
    reduce(or_ if T[j] else and_, x) for j, x in enumerate(zip(*X))
] != V:
    print((-1))
    exit()
for x in X:
    print((*x))

+S, T, U, V = [[int(a) for a in input().split()] for _ in range(4)]

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

+if [reduce(or_ if S[i] else and_, x) for i, x in enumerate(X)] != U or [

+    reduce(or_ if T[j] else and_, x) for j, x in enumerate(zip(*X))


Input:
from collections import deque

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

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

for i in range(M):

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

    Mlist[a].append(b)

    Mlist[b].append(a)

ans = [0] * (N+1)

d = deque()

d.append(1)

count = 0

while count != N:

    Q = d.popleft()

    for i in Mlist[Q]:

        if ans[i] == 0:

            ans[i] = Q

            d.append(i)

            count = count+1

print('Yes')

for i in range(N-1):

    print((ans[i+2]))

from collections import deque

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

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

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

d = deque()

for i in range(M):

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

    road[A].append(B)

    road[B].append(A)

d.append(1)

while len(d) != 0:

    look = d.popleft()

    for i in road[look]:

        if ans[i] == -1:

            d.append(i)

            ans[i] = look

print("Yes")

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

    print((ans[i]))

from collections import deque

N, M = list(map(int, input().split()))
Mlist = [[] for _ in range(N + 1)]
for i in range(M):
    a, b = list(map(int, input().split()))
    Mlist[a].append(b)
    Mlist[b].append(a)
ans = [0] * (N + 1)
d = deque()
d.append(1)
count = 0
while count != N:
    Q = d.popleft()
    for i in Mlist[Q]:
        if ans[i] == 0:
            ans[i] = Q
            d.append(i)
            count = count + 1
print("Yes")
for i in range(N - 1):
    print((ans[i + 2]))

from collections import deque

N, M = list(map(int, input().split()))
road = [[] for _ in range(N + 1)]
ans = [-1] * (N + 1)
d = deque()
for i in range(M):
    A, B = list(map(int, input().split()))
    road[A].append(B)
    road[B].append(A)
d.append(1)
while len(d) != 0:
    look = d.popleft()
    for i in road[look]:
        if ans[i] == -1:
            d.append(i)
            ans[i] = look
print("Yes")
for i in range(2, N + 1):
    print((ans[i]))

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

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


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

A = abs(x - a)

B = abs(x - b)

if(A < B):

  print('A')

else:

  print('B')

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

if(abs(x-a) < abs(x-b)):

  print('A')

else:

  print('B')

x, a, b = list(map(int, input().split()))
A = abs(x - a)
B = abs(x - b)
if A < B:
    print("A")
else:
    print("B")

x, a, b = list(map(int, input().split()))
if abs(x - a) < abs(x - b):
    print("A")
else:
    print("B")

-A = abs(x - a)
-B = abs(x - b)
-if A < B:
+if abs(x - a) < abs(x - b):


Input:
from collections import defaultdict, deque, Counter

from heapq import heappush, heappop, heapify

import math

import bisect

import random

from itertools import permutations, accumulate, combinations, product

import sys

import string

from bisect import bisect_left, bisect_right

from math import factorial, ceil, floor

from operator import mul

from functools import reduce

sys.setrecursionlimit(2147483647)

INF = 10 ** 20

def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

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

def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n): return [I() for i in range(n)]

def LIR(n): return [LI() for i in range(n)]

def SR(n): return [S() for i in range(n)]

def LSR(n): return [LS() for i in range(n)]

def SRL(n): return [list(S()) for i in range(n)]

def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n, k = LI()

A = [0] + LI()

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

    A[i] = (A[i] + A[i - 1]) % k

for i in range(n + 1):

    A[i] = (A[i] - i) % k

ans = 0

D = defaultdict(int)

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

    ans += D[A[j]]

    D[A[j]] += 1

    if j + k - 1 < n + 1:

        D[A[j + k - 1]] -= 1

if k == 1:

    print((0))

else:

    print(ans)

from collections import defaultdict, deque, Counter

from heapq import heappush, heappop, heapify

import math

import bisect

import random

from itertools import permutations, accumulate, combinations, product

import sys

import string

from bisect import bisect_left, bisect_right

from math import factorial, ceil, floor

from operator import mul

from functools import reduce

sys.setrecursionlimit(2147483647)

INF = 10 ** 20

def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

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

def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n): return [I() for i in range(n)]

def LIR(n): return [LI() for i in range(n)]

def SR(n): return [S() for i in range(n)]

def LSR(n): return [LS() for i in range(n)]

def SRL(n): return [list(S()) for i in range(n)]

def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n, k = LI()

A = [0] + LI()

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

    A[i] = (A[i] + A[i - 1] - 1) % k

ans = 0

D = defaultdict(int)

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

    ans += D[A[j]]

    D[A[j]] += 1

    if j + k - 1 < n + 1:

        D[A[j + k - 1]] -= 1

if k == 1:

    print((0))

else:

    print(ans)

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10**20

def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))

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

def LS():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()

def S():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8")

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

def SRL(n):
    return [list(S()) for i in range(n)]

def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007
n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
    A[i] = (A[i] + A[i - 1]) % k
for i in range(n + 1):
    A[i] = (A[i] - i) % k
ans = 0
D = defaultdict(int)
for j in range(n, -1, -1):
    ans += D[A[j]]
    D[A[j]] += 1
    if j + k - 1 < n + 1:
        D[A[j + k - 1]] -= 1
if k == 1:
    print((0))
else:
    print(ans)

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10**20

def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))

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

def LS():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()

def S():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8")

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

def SRL(n):
    return [list(S()) for i in range(n)]

def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007
n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
    A[i] = (A[i] + A[i - 1] - 1) % k
ans = 0
D = defaultdict(int)
for j in range(n, -1, -1):
    ans += D[A[j]]
    D[A[j]] += 1
    if j + k - 1 < n + 1:
        D[A[j + k - 1]] -= 1
if k == 1:
    print((0))
else:
    print(ans)


Input:
from sys import stdin

import numpy as np

def main():

    readline = stdin.readline

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

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

    res = []

    for i in range(2 ** n):

        price = 0

        skill = []

        for j in range(1 << n):

            if ((i >> j) & 1) == 1:

                price += a[j][0]

                skill.append(a[j][1:])

        np_skill = np.array(skill)

        skill_sum = np.sum(np_skill, axis=0)\

                        if np_skill.shape[0] > 1 else np_skill

        if skill_sum.size != 0 and (skill_sum >= x).all():

            res.append(price)

    if not res: return print('-1')

    return print(min(res))

if __name__ == '__main__':

    main()

from sys import stdin

import numpy as np

def bit_search(a, n, m, x):

    res = []

    for i in range(2 ** n):

        price = 0

        skill = np.zeros((n, m))

        for j in range(n):

            if (i >> j) & 1:

                price += a[j][0]

                skill[j] = a[j][1:]

        skill_sum = np.sum(skill, axis=0)\

                        if skill.shape[0] > 1 else skill

        if (skill_sum >= x).all(): res.append(price)

    return res

def main():

    readline = stdin.readline

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

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

    res = bit_search(a, n, m, x)

    print('-1' if not res else min(res))

    return

if __name__ == '__main__':

    main()

from sys import stdin
import numpy as np

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = []
    for i in range(2**n):
        price = 0
        skill = []
        for j in range(1 << n):
            if ((i >> j) & 1) == 1:
                price += a[j][0]
                skill.append(a[j][1:])
        np_skill = np.array(skill)
        skill_sum = np.sum(np_skill, axis=0) if np_skill.shape[0] > 1 else np_skill
        if skill_sum.size != 0 and (skill_sum >= x).all():
            res.append(price)
    if not res:
        return print("-1")
    return print(min(res))

if __name__ == "__main__":
    main()

from sys import stdin
import numpy as np

def bit_search(a, n, m, x):
    res = []
    for i in range(2**n):
        price = 0
        skill = np.zeros((n, m))
        for j in range(n):
            if (i >> j) & 1:
                price += a[j][0]
                skill[j] = a[j][1:]
        skill_sum = np.sum(skill, axis=0) if skill.shape[0] > 1 else skill
        if (skill_sum >= x).all():
            res.append(price)
    return res

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = bit_search(a, n, m, x)
    print("-1" if not res else min(res))
    return

if __name__ == "__main__":
    main()

+        skill_sum = np.sum(skill, axis=0) if skill.shape[0] > 1 else skill

-        skill_sum = np.sum(np_skill, axis=0) if np_skill.shape[0] > 1 else np_skill

-        if skill_sum.size != 0 and (skill_sum >= x).all():

+    print("-1" if not res else min(res))


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

  r=0

  x,y,z=0,0,0

  while 1:

    if b>=m:

      x=b//m

    else:

      x=0

    if a>=m:

      y=a//m

    else:

      y=0

    r+=x*n

    b-=x*m

    r+=(y*n*(n-1))>>1

    a-=y*m

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

    if x==0:

      break

    y=b-x*m

    z=y//a

    r+=(n+z)*x

    a,b,n,m=m,y-z*a,x,a

  return r

for i in range(int(eval(input()))):

  print((floor_sum(*list(map(int,input().split())))))

import sys

S=sys.stdin.readlines()

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

  r=0

  x,y,z=0,0,0

  while 1:

    if b>=m:

      x=b//m

    else:

      x=0

    if a>=m:

      y=a//m

    else:

      y=0

    r+=x*n

    b-=x*m

    r+=(y*n*(n-1))>>1

    a-=y*m

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

    if x==0:

      break

    y=b-x*m

    z=y//a

    r+=(n+z)*x

    a,b,n,m=m,y-z*a,x,a

  return r

for i in range(int(S[0])):

  print((floor_sum(*list(map(int,S[i+1].split())))))

def floor_sum(n, m, a, b):
    r = 0
    x, y, z = 0, 0, 0
    while 1:
        if b >= m:
            x = b // m
        else:
            x = 0
        if a >= m:
            y = a // m
        else:
            y = 0
        r += x * n
        b -= x * m
        r += (y * n * (n - 1)) >> 1
        a -= y * m
        x = (a * n + b) // m
        if x == 0:
            break
        y = b - x * m
        z = y // a
        r += (n + z) * x
        a, b, n, m = m, y - z * a, x, a
    return r

for i in range(int(eval(input()))):
    print((floor_sum(*list(map(int, input().split())))))

import sys

S = sys.stdin.readlines()

def floor_sum(n, m, a, b):
    r = 0
    x, y, z = 0, 0, 0
    while 1:
        if b >= m:
            x = b // m
        else:
            x = 0
        if a >= m:
            y = a // m
        else:
            y = 0
        r += x * n
        b -= x * m
        r += (y * n * (n - 1)) >> 1
        a -= y * m
        x = (a * n + b) // m
        if x == 0:
            break
        y = b - x * m
        z = y // a
        r += (n + z) * x
        a, b, n, m = m, y - z * a, x, a
    return r

for i in range(int(S[0])):
    print((floor_sum(*list(map(int, S[i + 1].split())))))

-    print((floor_sum(*list(map(int, input().split())))))

+    print((floor_sum(*list(map(int, S[i + 1].split())))))


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

s = 1

print((s*n*n*n))

n = int(eval(input()))
s = 1
print((s * n * n * n))

n = int(eval(input()))
print((n * n * n))

-s = 1
-print((s * n * n * n))
+print((n * n * n))