Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N, P = MAP()
	S = input()

	if P == 2 or P == 5:
		ans = 0

		for i, s in enumerate(S):
			if int(s)%P == 0:
				ans += i+1
		print(ans)

	else:
		tmp = ""

		mod_cnt = [0]*P

		for i, s in enumerate(S[::-1]):
			tmp = s + tmp
			mod_cnt[int(tmp)%P] += 1
		ans = 0
		for v in mod_cnt:
			ans += v*(v-1)//2
		print(ans+mod_cnt[0])


if __name__ == '__main__':
	main()


### FIXED CODE ###

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

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N, P = MAP()
	S = list(map(int, list(input())))

	if P == 2 or P == 5:
		ans = 0

		for i, s in enumerate(S):
			if int(s)%P == 0:
				ans += i+1
		print(ans)

	else:
		tmp = 0

		mod_cnt = [0]*P

		z = 1
		for i, n in enumerate(S[::-1]):
			tmp += n*z
			z = z * 10 % P
			mod_cnt[int(tmp)%P] += 1
		ans = 0
		for v in mod_cnt:
			ans += v*(v-1)//2
		print(ans+mod_cnt[0])


if __name__ == '__main__':
	main()
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A, B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    A = [
        [int(a) - 1 for a in input().split()]
        for _ in range(N)
    ]

    count = 0
    while True:
        pool = []
        for i, ai in enumerate(A):
            if len(ai) == 0:
                continue
            target = ai[0]
            if target < i:
                continue
            target_q = A[target]
            if target_q[0] == i:
                pool.append(i)
                pool.append(target)
                # ai.pop(0)
                # target_q.pop(0)

        if len(pool) == 0:
            if not all(len(a) == 0 for a in A):
                print(-1)
                return
        for i in pool:
            A[i].pop(0)
        count += 1
        if all(len(a) == 0 for a in A):
            print(count)
            return


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A, B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    A = {
        i: list(reversed([int(a) - 1 for a in input().split()]))
        for i in range(N)
    }

    Q = set(range(N))

    count = 0
    while True:
        pool = []
        for i in Q:
            ai = A[i]
            if len(ai) == 0:
                continue
            target = ai[-1]
            # if target < i:
            #     continue
            target_q = A[target]
            if target_q[-1] == i:
                # print(i,target)
                pool.append(i)
                pool.append(target)

        if len(pool) == 0:
            if len(Q) != 0:
                print(-1)
                return
            else:
                raise ValueError("test")

        qq = []
        for i in set(pool):
            A[i].pop()
            if len(A[i]) != 0:
                qq.append(i)
        Q = set(qq)

        count += 1
        if len(Q) == 0:
            print(count)
            return


if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

ans = 1

for i in l:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

import sys
N = int(input())
l = list(map(int,input().split()))

if 0 in l:
    print(0)
    sys.exit()

ans = 1

for i in l:
    ans *= i
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
inputs = [int(i) for i in input().split()]

dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = abs(inputs[i] - inputs[i-1])
    else:
        tmp = 10 ** 9
        count = 0
        for j in range(i):
            if count >= K or i - (j + 1) < 0:
                break
            tmp = min(tmp, dp[i-(j+1)] + abs(inputs[i] - inputs[i-(j+1)]))
            count += 1
        dp[i] = tmp

print(dp[-1])


### FIXED CODE ###

import numpy as np


N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])

dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()

print(dp[-1])
### BUGGY CODE ###

def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    t = 0
    for ai, a in enumerate(L):
        hi = ai + 1
        for bi, b in enumerate(L[ai + 1:], ai + 1):
            ab = a + b
            lo = hi
            hi = len(L) - 1
            while lo != hi:
                mid = (lo + hi + 1) // 2
                if L[mid] < ab:
                    lo = mid
                else:
                    hi = mid - 1
            t += hi - bi
    print(t)


main()


### FIXED CODE ###

import bisect

def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    t = 0
    l = len(L) - 1
    for ai, a in enumerate(L):
        ci = ai + 1
        for bi, b in enumerate(L[ai + 1:], ai + 1):
            ci = bisect.bisect_left(L, a + b, ci) - 1
            t += ci - bi
    print(t)


main()
### BUGGY CODE ###

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

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

TDlist.sort(key = lambda x: x[1],reverse=True)
kinds = []
seconds = []
answer = 0

for x in TDlist[:K]:
    if not x[0] in kinds:
        kinds.append(x[0])
    else:
        seconds.append(x[1])
    answer += x[1]

answer += len(kinds)**2
score = answer
max_score = answer

for x in TDlist[K:]:
    if seconds == []:
        break
    if x[0] in kinds:
        continue
    kinds.append(x[0])
    y = seconds.pop()
    score += (x[1] - y) + (len(kinds)*2 -1)
    max_score = max(score,answer)
    

answer = max(answer,max_score)

print(answer)

### FIXED CODE ###

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

for x in range(0,N):
    TDlist.append(list(map(int,input().split())))

TDlist= sorted(TDlist, key = lambda x: x[1],reverse=True)
kinds = set()
seconds = []
answer = 0

for x in TDlist[:K]:
    if not x[0] in kinds:
        kinds.add(x[0])
    else:
        seconds.append(x[1])
    answer += x[1]

answer += len(kinds)**2
score = answer

for x in TDlist[K:]:
    if seconds == []:
        break
    if x[0] in kinds:
        continue
    kinds.add(x[0])
    y = seconds.pop()
    score += (x[1] - y) + (len(kinds)*2 -1)
    answer = max(score,answer)

print(answer)
### BUGGY CODE ###

n=int(input())
import fractions 
from functools import reduce
arr = list(map(int,input().split()))


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

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
    
a = lcm(arr)

ans = 0

for i in arr:
    ans+= a//i
    
print(ans %(1000000000+7))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
 
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
 
a = 1
for i in range(N):
    a = lcm(a, A[i])
 
ans = 0
for i in range(N):
    ans += a * pow(A[i], mod-2, mod)
 
print(ans % mod)
### BUGGY CODE ###

n=int(input())
ans=0
for i in range(n):
    ans+=i
print(ans)

### FIXED CODE ###

n=int(input())
ans=n*(n-1)//2
print(ans)
### BUGGY CODE ###

a,b = [int(x) for x in input().split()]

def f(a,b):
    l = []
    for i in range(1,min(a,b)+1):
        if a % i == 0 and b % i == 0:
            l.append(i)
    return l

def sosu(n):
    ret = True
    for i in range(2,int((n**0.5)+1)):
        if n % i == 0:
            ret = False
            break
    return ret

l = f(a,b)
ans = 0
for x in l:
    if sosu(x):
        ans += 1

print(ans)

### FIXED CODE ###

a,b = [int(x) for x in input().split()]

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

d = gcd(a,b)
pf = {}
for i in range(2, int(d**0.5)+1):
    while d%i == 0:
        pf[i] = pf.get(i,0)+1
        d//=i
if d>1:
    pf[d] = 1
P = list(pf.keys())
print(len(P)+1)
### BUGGY CODE ###

def calcScore(d, g, scoreMap, index, score, solved):
    minSolved = 0
    for i in range(scoreMap[index][0] + 1):
        scoreNow = score + 100 * (index + 1) * i
        if i == scoreMap[index][0]:
            scoreNow += scoreMap[index][1]
        solvedNow = solved + i
        if scoreNow >= g:
            if minSolved == 0 or minSolved > solvedNow:
                return solvedNow
            else:
                return minSolved
        tmpSolved = 0
        if index < d - 1:
            tmpSolved = calcScore(d, g, scoreMap, index + 1, scoreNow, solvedNow)
            if minSolved == 0 or (minSolved > tmpSolved and tmpSolved != 0):
                minSolved = tmpSolved
    return minSolved


d, g = map(int, input().split())
scoreMap = [list(map(int, input().split())) for i in range(d)]

solved = calcScore(d, g, scoreMap, 0, 0, 0)

print(solved)

### FIXED CODE ###

d, g = map(int, input().split())
scoreMap = [list(map(int, input().split())) for i in range(d)]

minimum = 0

for i in range(2**d):
    score = 0
    solved = 0
    for j in range(d):
        if (i >> j) & 1 == 1:
            score += scoreMap[j][0] * 100 * (j + 1) + scoreMap[j][1]
            solved += scoreMap[j][0]
    if score < g:
        for k in range(d)[::-1]:
            if (i >> k) & 1 == 0:
                if (g - score > scoreMap[k][0] * 100 * (k + 1)):
                    score += scoreMap[k][0] * 100 * (k + 1) + scoreMap[k][1]
                    solved += scoreMap[k][0]
                    if score > g:
                        break
                else:
                    solved += (g - score) // (100 * (k + 1))
                    if (g - score) % (100 * (k + 1)) != 0:
                        solved += 1
                    score = g
                    break
    if minimum == 0 or solved < minimum:
        minimum = solved

print(minimum)
### BUGGY CODE ###

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

N = int(input())
S = input().rstrip()

s = set()
l = list(itertools.combinations(S, 3))

for x in l:
    s.add(x[0]+x[1]+x[2])

print(len(s))


### FIXED CODE ###

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

N = int(input())
S = input().rstrip()

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    t1 = S.find(t[0])
    if t1 == -1:
        continue
    t2 = S.find(t[1], t1+1)
    if t2 == -1:
        continue
    t3 = S.find(t[2], t2+1)
    if t3 == -1:
        continue
    ans += 1

print(ans)
### BUGGY CODE ###

import numpy as np
N=int(raw_input())
AN=map(int, raw_input().split())
BN=[0 for i in xrange(N)]
for i in AN:
    BN[i-1] += 1
BN=[i for i in BN if i > 0]
BN.sort(reverse=True)

for K in xrange(1, N+1):
    x = np.zeros(K)
    for i in BN:
        x[x.argmin()] += i

    print (int(x.min()))

### FIXED CODE ###

N=int(raw_input())
AN=map(int, raw_input().split())

BN=[0 for i in xrange(N)]
for i in AN:
    BN[i-1] += 1
BN.sort()

LN = [0 for i in xrange(N)]
s = 0
j = 0
try:
    for X in xrange(1, N+1):
        while j<N and  BN[j] < X:
            s += BN[j]
            j += 1
        LN[X-1] = (s + X*(N - j)) / X
except IndexError:
    pass

KN = [0 for i in xrange(N)]
for i in xrange(len(LN)):
    KN[LN[i]-1] = i+1

for i in xrange(len(KN)-2, -1, -1):
    if KN[i] == 0:
        KN[i] = KN[i+1]

for i in KN:
    print (str(i))
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

sys.setrecursionlimit(10**5)

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
peer_nodes = [[] for _ in range(N)]
edge_colors = [[0]*(N) for _ in range(N)]
pairs = []
for _ in range(N-1):
    a,b = list(map(int, input().split()))
    a -= 1
    b -= 1
    pairs.append([a,b])
    peer_nodes[a].append(b)
    if not a in peer_nodes[b]:
        peer_nodes[b].append(a)
    edge_colors[a][b] = 0

#print(peer_nodes,edge_colors)

def draw_color_return_max_colors(node):
    max_colors = 0
    peers = peer_nodes[node]
    if len(peers) == 0:
        return 0
    used_colors = []
    for p in peers:
        c = edge_colors[node][p]
        if c != 0:
            used_colors.append(c)
    #print('----', node, peers,used_colors)
    if len(used_colors) == len(peers):
        return 0
    color = 1
    for p in peers:
        if edge_colors[node][p] > 0:
            continue
        else:
            while(color in used_colors):
                color += 1
            if edge_colors[node][p] == 0:
                used_colors.append(color)
                edge_colors[node][p] = color
                edge_colors[p][node] = color
    max_colors = max(used_colors)
    for p in peers:
        max_colors = max(max_colors, draw_color_return_max_colors(p))

    return max_colors


print(draw_color_return_max_colors(pairs[0][0]))

for a,b in pairs:
    print(edge_colors[a][b])


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

sys.setrecursionlimit(10**5)

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
peers = [[] for _ in range(N)]
colors = [{} for _ in range(N)]
pairs = []
for _ in range(N-1):
    a,b = list(map(int, input().split()))
    a -= 1
    b -= 1
    pairs.append([a,b])
    peers[a].append(b)
    colors[a][b] = 0


def draw(node, parent_edge_color):
    _peers = peers[node]
    if len(_peers) == 0:
        return 0
    color = 1
    max_nrof_color = 1
    for peer in _peers:
        #print(node,peer,color)
        if color == parent_edge_color:
            color +=1
        colors[node][peer] = color
        max_nrof_color = max(max_nrof_color, color, draw(peer, color))
        color += 1

    return max_nrof_color


print(draw(0,0))
for a,b in pairs:
    print(colors[a][b])
### BUGGY CODE ###

n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

for i in range(q):
    c = s[a[i]-1:b[i]]
    d = c.replace('AC','A')
    print(len(c)-len(d))

### FIXED CODE ###

n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])
### BUGGY CODE ###

S = input()
ans = 0
for i in range(int(S)//2019 + 1):
  d = str(2019*i)
  ans += S.count(d)
print(ans)

### FIXED CODE ###

s = input()
a = 0
mods = [0]*2019
mods[a] += 1
r = 1
for i in s[::-1]:
  a = (a+int(i)*r)%2019
  r = r*10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

def simple_solution(N, A, B):
    ret = 0
    for a in A:
        for b in B:
            ret ^= a + b
    return ret


def solution(N, A, B):
    import numpy as np
    pow_2_k = 1
    ans = 0
    A = np.array(A)
    B = np.array(B)
    for k in range(30):
        MA = A % (2 * pow_2_k)
        MB = np.sort(B % (2 * pow_2_k))
        # [2**k, 2 * (2**k)) か [3 * (2**k), 4 * (2**k)) の中に入るとk-bit目が1。
        # この a + b の数をカウントする。
        # → [2**k - a, 2 * (2**k) - a) か [3 * (2**k) - a, 4 * (2**k) - a) の中に入る b の数をカウント。
        cnt = 0
        for a in MA:
            index_1 = np.searchsorted(MB, pow_2_k - a, side='left')
            index_2 = np.searchsorted(MB, 2 * pow_2_k - a, side='left')
            index_3 = np.searchsorted(MB, 3 * pow_2_k - a, side='left')
            cnt += (N - index_1) - (N - index_2) + (N - index_3)
        if cnt % 2 == 1:
            ans += pow_2_k
        pow_2_k *= 2
    return ans


def check():
    import random
    random.seed(0)
    for N in range(1, 101):
        A = random.choices(range(2 ** 28), k=N)
        B = random.choices(range(2 ** 28), k=N)
        print('Checking the case with size: {}'.format(N))
        assert simple_solution(N, A, B) == solution(N, A, B)
    print('OK')


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    print(solution(N, A, B))


if __name__ == '__main__':
    main()
    # check()

### FIXED CODE ###

import numpy as np


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    pow_2_k = 1
    ans = 0
    for k in range(30):
        MA = A % (2 * pow_2_k)
        MB = B % (2 * pow_2_k)
        MB.sort()
        # [2**k, 2 * (2**k)) か [3 * (2**k), 4 * (2**k)) の中に入るとk-bit目が1。
        # この a + b の数をカウントする。
        # → [2**k - a, 2 * (2**k) - a) か [3 * (2**k) - a, 4 * (2**k) - a) の中に入る b の数をカウント。
        cnt = 0
        indices_1 = np.searchsorted(MB, pow_2_k - MA, side='left')
        indices_2 = np.searchsorted(MB, 2 * pow_2_k - MA, side='left')
        indices_3 = np.searchsorted(MB, 3 * pow_2_k - MA, side='left')
        cnt += ((N - indices_1) - (N - indices_2) + (N - indices_3)).sum()
        if cnt % 2 == 1:
            ans += pow_2_k
        pow_2_k *= 2
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, Q = map(int, input().split())
C = [int(i) for i in input().split()]
for i in range(Q):
    l, r = map(int, input().split())
    print(len(set(C[l-1:r])))


### FIXED CODE ###

N, Q = map(int, input().split())
C = [int(i) for i in input().split()]

pi = [-1]*(N+1)
ps = [[] for _ in range(N+1)]
for i in range(N):
    l = pi[C[i]]
    if l != -1:
        ps[l].append(i)
    pi[C[i]] = i

qs = [[] for _ in range(N+1)]
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    qs[l].append((r, i))


bit = [0]*(N+1)


def bit_sum(idx):
    res_sum = 0
    while idx > 0:
        res_sum += bit[idx]
        idx -= idx & (-idx)
    return res_sum


def bit_add(idx, x):
    while idx <= N:
        bit[idx] += x
        idx += idx & (-idx)
    return True


ans = [0]*Q
for x in range(N-1, -1, -1):
    for y in ps[x]:
        bit_add(y, 1)
    for r, i in qs[x]:
        ans[i] = r-x+1-bit_sum(r)


for i in range(Q):
    print(ans[i])
### BUGGY CODE ###

def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def lm(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


def gm(a, b):
    return a * b // lm(a, b)


def Prim(N):
    P = []
    M = int(N ** 0.5) + 1
    F = [False, False] + [True] * M
    for n in range(2, M):
        if not F[n]:
            continue
        P.append(n)
        for i in range(n, len(F), n):
            F[i] = False
    
    return P
 

def ps(a, P, K):
    d = {}
    for p in P:
        c = 0
        while a % p == 0:
            c += 1
            a //= p
        d[p] = c

        if a == 1:
            break
    
    if a != 1:
        d[a] = 1
        K.add(a)
    return d


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = read_list()
    P = Prim(max(A))
    K = set()

    DA = [ps(a, P, K) for a in A]
    P.extend(list(K))

    D = {}
    res = 0
    for d in DA:
        b = 1
        for i in P:
            v = d.setdefault(i, 0)
            r = D.setdefault(i, 0)
            if v > r:
                D[i] = v
                res = res * pow(i, v - r, mod) % mod
            else:
                b = b * pow(i, r - v, mod) % mod
        
        res = (res + b) % mod

    print(res)


if __name__ == "__main__":
    main()



### FIXED CODE ###

def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def g(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = read_list()

    B = 1
    for a in A:
        B *= a // g(B, a)
    
    print(sum(B // a for a in A) % mod)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))
DIV = 10 ** 9 + 7

# 各桁の1と0の数を数えて、((1の数) * (0の数)) * (2 ** i桁目(1桁目を0とする))を数える

K = max(A) # 最も大きい数が0になるまでループ
rate = 1
ans = 0
j = 0
while K:
  one = 0
  zero = 0
  for i in range(len(A)):
    if (A[i] >> j) & 1:
      one += 1
    else:
      zero += 1
  ans += (one % DIV) * (zero % DIV) * rate
  ans %= DIV
  rate *= 2
  rate %= DIV
  j += 1
  K >>= 1
  
print(ans)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
binA=[None]*n
for i in range(n):
  binA[i]=bin(A[i])[2:]
  
keta=[0]*60
for i in range(n):
  tar=binA[i]
  for j in range(len(tar)-1,-1,-1):
    if tar[j]=="1":
      keta[len(tar)-1-j]+=1

pair=[0]*60
for i in range(len(keta)):
  pair[i]=keta[i]*(len(A)-keta[i])
  
ans=0
mul=1
DIV=10**9+7
for i in range(len(pair)):
  ans+=pair[i]*mul
  ans%=DIV
  mul*=2
print(ans)
### BUGGY CODE ###

def main():
	N, M = map(int,input().split())
	INF = 10**9+7
	if M == 0:
		print("Yes")
		return
	x = [[INF for _ in range(N)] for _ in range(N)]
	for i in range(M):
		l, r, d = map(int, input().split())
		l, r = l-1, r-1
		x[l][r] = d
		x[r][l] = -d
	ans_exist = True
	for k in range(N):
		for i in range(N):
			for j in range(N):
				if x[i][j] == INF:
					continue
				x[i][j] = min(x[i][j], x[i][k]+x[k][j])

	for i in range(N):
		for j in range(N):
			if x[i][j] == x[j][i] and x[i][j] == INF:
				continue
			if x[i][j] != -x[j][i]:
				ans_exist = False
				break
	if ans_exist:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
	N, M = map(int,input().split())
	if M == 0:
		print("Yes")
		return
	x = [[] for _ in range(N)]
	ans = [0 for _ in range(N)]
	for i in range(M):
		l, r, d = map(int, input().split())
		l, r = l-1, r-1
		x[l].append([r, d])
		x[r].append([l, -d])

	visited = [False for _ in range(N)]

	def dfs(i):
		vs = [i]
		while vs:
			v = vs.pop()
			for nex in x[v]:
				if not visited[nex[0]]:
					visited[nex[0]] = True
					ans[nex[0]] = ans[v]+nex[1]
					vs.append(nex[0])
				else:
					if ans[nex[0]] != ans[v]+nex[1]:
						return False
		return True

	ans_exist = True
	for i in range(N):
		if not visited[i]:
			visited[i] = True
			ans_exist = dfs(i)
		if not ans_exist:
			break

	if ans_exist:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
print(*b)

### FIXED CODE ###

from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
b = deque()
f = True
for i in range(n):
    if f: b.append(a[i])
    else: b.appendleft(a[i])
    f = not f
if i % 2 == 0: b.reverse()
print(*b)