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

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [A[0]]
for n in range(N-1):
    B = B+[max(B[-1], A[n + 1])]
C = [A[-1]]
for n in range(N - 1):
    C = [max(C[0], A[-n - 2])] + C
D = [C[1]]+[max(B[n-1], C[n+1]) for n in range(1, N-2+1)]+[B[N-2]]
for d in D:
    print(d)


### FIXED CODE ###

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
for n in range(N):
    if n == 0:
        print(C[1])
    elif n == N - 1:
        print(B[N - 2])
    else:
        print(max(B[n-1], C[n+1]))
### BUGGY CODE ###

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

A.sort()

ans = 0

pre = -1

while A:
    maxim = A.pop()
    if maxim == pre:continue

    for item in A:
        if maxim % item == 0:
            ans -= 1
            break
    ans += 1
    pre = maxim

print(ans)

### FIXED CODE ###

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

cnt = {}

for item in a:
    if item not in cnt:
        cnt[item] = 0
    cnt[item] += 1

A = list(set(a))

candidate = []

for item in A:
    if cnt[item] == 1:
        candidate.append(item)

judge = [True] *(10**6 + 1)

for item in A:
    for i in range(2, ((10**6)//item) + 1):
        judge[item*i] = False

ans = 0

for item in candidate:
    if judge[item]:
        ans += 1

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

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

def main():
    N, W = map(int, input().split())
    dp = [[0] * (W+1) for i in range(N+1)]
    #dp[i][j]  iまでをみてjの重さでの最大価値
    for i in range(1,N+1):
        w, v = map(int, input().split())
        dp[i][:] = dp[i-1][:]
        for j in range(w, W+1):
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v)
#    print(dp)
    print(dp[N][W])

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
N, W = map(int, input().split())
dp = np.zeros(W+1, dtype=np.int)
for n in range(1,N+1):
  wn, vn = map(int, input().split())
  dp[wn:]=np.maximum(dp[wn:], dp[:-wn]+vn)
print(dp[W])
### BUGGY CODE ###

n = int(input())
a = 1
s_list = list(map(int, input().split()))
for i in s_list:
    a*=i
    if a>10**18:
        a=-1
if a<0:
    a=-1
print(a)

### FIXED CODE ###

n = int(input())
a = 1
s = list(map(int, input().split()))
if 0 in s:
    print(0)
    exit()
for i in s:
    a*=i
    if a>10**18:
        print(-1)
        exit()
else:
    print(a)
### BUGGY CODE ###

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

cnt=0
for i in range(1,n):
    if min(p[0:i])<p[i]:
            cnt+=1
print(n-cnt)

### FIXED CODE ###

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

a=p[0]
cnt=1
for i in range(1,n):
    if a>=p[i]:
        cnt+=1
        a=p[i]

print(cnt)
### BUGGY CODE ###

from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    tmp = 0
    res = []
    tmp = 1
    tmp2 = a[0]
    for i in range(k):
        tmp*=a[i]
    res.append(tmp)
    ind = 0
    for i in range(k,n):
        tmp/=tmp2
        tmp*=a[i]
        ind+=1
        tmp2 = a[ind]
        res.append(tmp)

    for i in range(1,len(res)):
        if(res[i] > res[i-1]):
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    tmp = 0
    res = []
    ind = 0
    for i in range(n-k):
        if(a[ind] < a[ind+k]):
            res.append(1)
        else:
            res.append(0)
        ind += 1

    for i in range(0,len(res)):
        if(res[i]):
            print("Yes")
        else:
            print("No")


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

N = int(input())
S = input()
list = [str(S[i]) for i in range(N)]

result = []

def cal(n):
    count = 0
    count = list[:n].count("W") + list[n:].count("E")
    return count

for i in range(N):
    result.append(cal(i))
    
# print(result)
print(min(result))

### FIXED CODE ###

N = int(input())
S = input()

if S[0] == "E":
    count = S.count("E") -1
    result = count
    for i in range(1,N):
        if S[i-1] == "W" and S[i] == "W":
            count += 1
        elif S[i-1] == "E" and S[i] == "E":
            count -= 1
            if result > count:
                result = count
else:
    count = S.count("E")
    result = count
    for i in range(1,N):
        if S[i-1] == "W" and S[i] == "W":
            count += 1
        elif S[i-1] == "E" and S[i] == "E":
            count -= 1
            if result > count:
                result = count

print(result)
### BUGGY CODE ###

N=int(input())
A=[i for i in map(int,input().split())]
mini=min(A)
while mini>0:
    for i in range(len(A)):
        if A[i]!=mini:
            A[i]=A[i]%mini
    z=A.count(0)
    A=sorted(A)[z:]
    m=A[0]
    if m==1:
        break
print(A[0])

### FIXED CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)
### BUGGY CODE ###

n, t = map(int ,raw_input().split())
li = map(int , raw_input().split())

ans = 1
temp = 0
for i in range(len(li)):
	for j in range(i+1,len(li)):
		if(li[j] - li[i] == temp):
			ans += 1
		elif(li[j] - li[i] > temp):
			temp = li[j] - li[i]
			ans = 1

print ans

### FIXED CODE ###

import numpy as np

if __name__ == "__main__":
	n,t = map(int,raw_input().split())
	li = map(int,raw_input().split())

	minv = li[0]
	dm = 0
	ans = 1
	for i in range(1, len(li)):
		minv = min(minv, li[i])
		if(dm == li[i] - minv):
			ans += 1
		elif(dm < li[i]-minv):
			dm = li[i] - minv
			ans = 1

	print ans
### BUGGY CODE ###

import math


K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += math.gcd(math.gcd(i, j), k)

print(ans)

### FIXED CODE ###

import math

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            x = math.gcd(math.gcd(i, j), k)
            if i == j == k:
                ans += x
            elif i != j != k:
                ans += x * 6
            else:
                ans += x * 3

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

n = int(input())
x = list(map(int, input().split()))
lists = []
ind = ((n-1) + 1) // 2
for i in range(n):
    if i == 0:
        ans = x[i + 1:]
        ans.sort()
        lists.append(ans[ind-1])
    else:
        ans = x[0:i] + x[i + 1:]
        ans.sort()
        lists.append(ans[ind - 1])
tuple_lists = tuple(lists)
[print(x) for x in tuple_lists]


### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
y = sorted(x)[n//2-1:n//2+1]
for i in x:print(y[i <= y[0]])
### BUGGY CODE ###

from collections import deque
S = deque(list(input()))
Q = int(input())
for i in range(Q):
    query = [_ for _ in input().split()]
    if len(query) == 1:
        S.reverse()
    else:
        if query[1] == '1':
            S.appendleft(query[2])
        else:
            S.append(query[2])
print(*list(S), sep='')


### FIXED CODE ###

from collections import deque
S = deque(list(input()))
Q = int(input())
rev_cnt = 0
for i in range(Q):
    query = [_ for _ in input().split()]
    if len(query) == 1:
        rev_cnt += 1
    else:
        if query[1] == '1':
            if rev_cnt%2 == 0:
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if rev_cnt%2 == 0:
                S.append(query[2])
            else:
                S.appendleft(query[2])
if rev_cnt % 2 == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))  # 整数のリスト

    next_A = [0 for _ in range(N)]

    for _ in range(K):
        for i in range(N):
            for j in range(i-A[i], i+A[i]+1):
                if j >= 0 and j < N:
                    next_A[j] += 1
        A = next_A
        next_A = [0 for _ in range(N)]

    for i in A:
        print(i, end=" ")

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))  # 整数のリスト
    B = [0] * N

    for j in range(min(K, 41)):
        for i in range(N):
            l = max(0, i-A[i])
            r = min(N-1, i+A[i])
            B[l] += 1
            if r+1 < N: B[r+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        A = B
        B = [0] * N

    for i in A:
        print(i, end=" ")

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

import bisect
N,M,Q = map(int,input().split())
I = {}
for _ in range(M):
    L,R = map(int,input().split())
    if L not in I:
        I[L] = []
    I[L].append(R)
A = sorted(list(I.keys()))
for _ in range(Q):
    p,q = map(int,input().split())
    indL = bisect.bisect_left(A,p)
    indR = bisect.bisect_right(A,q)
    cnt = 0
    for i in range(indL,indR):
        for y in I[A[i]]:
            if y<=q:
                cnt += 1
    print(cnt)

### FIXED CODE ###

N,M,Q = map(int,input().split())
A = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    L,R = map(int,input().split())
    A[L][R] += 1
B = [[0 for _ in range(N+2)] for _ in range(N+2)]
for i in range(N,0,-1):
    for j in range(1,N+1):
        B[i][j] = A[i][j]+B[i+1][j]+B[i][j-1]-B[i+1][j-1]
for _ in range(Q):
    p,q = map(int,input().split())
    print(B[p][q])
### BUGGY CODE ###

a,b = map(int,input().split())
su = 0
for i in range(a,b+1):
  su ^= i
print(su)

### FIXED CODE ###

a,b = map(lambda x:
          int(format(int(x),'b')),input().split())
a -= 1
A = str(a)
la = len(A)
ga = [0]*la
if a%4 == 1 or a%4 == 2:
  ga[-1] = 1
for ai in range(0,la-1):
  if A[ai] == '1' and A[-1] == '0':
    ga[ai] = 1
aa = 0
for ai in range(la):
  aa *= 2
  aa += ga[ai]
B = str(b)
lb = len(B)
gb = [0]*lb
if b%4 == 1 or b%4 == 2:
  gb[-1] = 1
for bi in range(0,lb-1):
  if B[bi] == '1' and B[-1] == '0':
    gb[bi] = 1
bb = 0
for bi in range(lb):
  bb *= 2
  bb += gb[bi]
if a < 0:
  print(bb)
else:
  print(aa^bb)
### BUGGY CODE ###

a,b,k = map(int, input().split())
for i in range(k):
  if a>=1:
    a-=1
  elif b>=1:
    b-=1
  if a == b == 0:
    print(0,0)
    exit()
print(a,b)

### FIXED CODE ###

a,b,k = map(int, input().split())
if a>=k:
  print(a-k,b)
elif k>=a+b:
  print(0,0)
else:
  print(0,str(b-k+a))
### BUGGY CODE ###

N = int(input())
S = input()

ans = N
left_black = [0]
right_white = [0]

for i in range(N):
    if S[i] == '#':
        left_black.append(left_black[-1] + 1)
    else:
        left_black.append(left_black[-1])
    if S[N - 1 - i] == '.':
        right_white.insert(0, right_white[0] + 1)
    else:
        right_white.insert(0, right_white[0])

for i in range(N + 1):
    ans = min(ans, left_black[i] + right_white[i])
print(ans)


### FIXED CODE ###

N = int(input())
S = input()

one, d = 0, 0
for i in range(N):
    if S[i] == '#':
        one += 1
    elif d > one - (i + 1 - one):
        d = one - (i + 1 - one)
print(d + N - one)
### BUGGY CODE ###

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

ans = 1
tmp = P
start = P // (2 ** N) + 1
# for i in range(start, 1, -1):
#     newtmp, rest = divmod(tmp, (i**N))
#     print(i, tmp, rest, ans)
#     if rest == 0:
#         ans = ans * i
#         tmp = newtmp

for i in range(2, P):
    while True:
        newtmp, rest = divmod(tmp, (i**N))
        # print(i, tmp, rest, ans)
        if rest:
            break
        else:
            ans = ans * i
            tmp = newtmp

    if newtmp == 0:
        break

print(ans)


### FIXED CODE ###

N, P = list(map(int, input().split()))
if N == 1:
    print(P)
    exit()
elif P == 1:
    print("1")
    exit()

ans = 1
tmp = P

for i in range(2, int(pow(P, 1 / N)) + 1):
    po = pow(i, N)
    while tmp % po == 0:
        tmp = tmp // po
        ans = ans * i
        # print(i, tmp, ans)

    if tmp < po:
        break

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

MOD = 10**9 + 7

def main():
    s = open(0).read()[:-1][::-1]
    n = len(s)

    prev = [0] * 13
    if s[0] == '?':
        for j in range(10):
            prev[j] = 1
    else:
        prev[int(s[0])] = 1

    mod13 = [1, 10, 9, 12, 3, 4]
    for i, cur_s in enumerate(s[1:], start=1):
        next = [0] * 13
        if cur_s == '?':
            for j in range(10):
                remain = j * mod13[i % 6] % 13
                for k in range(13):
                    next[(k + remain) % 13] += prev[k]
        else:
            remain = int(cur_s) * mod13[i % 6] % 13
            for k in range(13):
                next[(k + remain) % 13] += prev[k]
        prev = [cur_next % MOD for cur_next in next]

    ans = prev[5] % MOD
    print(ans)
    return()

if __name__ == '__main__':
    main()


### FIXED CODE ###

MOD = 10**9 + 7

def main():
    s = [int(in_i) if in_i != '?' else -1 for in_i in list(open(0).read())[:-1]]
    n = len(s)

    cnt = [0] * 13
    if s[0] == -1:
        for j in range(10):
           cnt[j] = 1
    else:
        cnt[s[0]] = 1

    for cur_s in s[1:]:
        dp = [0] * 26
        for i in range(13):
            dp[i*10%13] = cnt[i] % MOD
        dp[13:] = dp[:13]

        if cur_s == -1:
            for i in range(13):
                cnt[i] = sum(dp[i+4:i+14])
        else:
            for i in range(13):
                cnt[i] = dp[i+13-cur_s]

    ans = cnt[5] % MOD
    print(ans)
    return()

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

import bisect

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

count = 0
lenB = len(B)
lenC = len(C)
for a in A:
  startB = bisect.bisect_right(B, a)
  for i in range(startB, lenB):
    count += lenC - bisect.bisect_right(C, B[i])
print(count)


### FIXED CODE ###

import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
count = 0
lenA = len(A)
lenB = len(B)
lenC = len(C)
for b in B:
  count += (bisect.bisect_left(A, b))*(lenC-bisect.bisect_right(C, b))
print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def lcs_sol(x, y):
    n = len(x)
    m = len(y)
    dp = [0 for j in range(m + 1)]

    for i in range(1, n + 1):
        dp_prev = dp[:]
        for j in range(1, m + 1):
            if x[i - 1] == y[j - 1]:
                dp[j] = dp_prev[j - 1] + 1
            elif dp_prev[j] < dp[j - 1]:
                dp[j] = dp[j - 1]

    return dp[m]


if __name__ == '__main__':
    import sys
    q = int(sys.stdin.readline().strip())
    for i in range(q):
        x = sys.stdin.readline().strip()
        y = sys.stdin.readline().strip()
        print(lcs_sol(x, y))



### FIXED CODE ###

def m():
 e=input
 a=''
 for _ in[0]*int(e()):
  X,z=e(),[]
  for y in e():
   s=i=0
   for k in z:
    t=X.find(y,s)+1
    if t<1:break
    if t<k:z[i]=t
    s=k;i+=1
   else:
    t=X.find(y,s)+1
    if t:z+=[t]
  a+=f'\n{len(z)}'
 print(a[1:])
if'__main__'==__name__:m()
### BUGGY CODE ###

import collections

h,w=map(int,input().split())
board=[list(input()) for _ in range(h)]
q=collections.deque()
if board[0][0]=='#':
  q.append((0,0,1,1))
else:
  q.append((0,0,0,0))
ans=10**18
while len(q)!=0:
  x,y,cnt,flag=q.popleft()
  if x==w-1 and y==h-1:
    ans=min(ans,cnt)
  else:
    if x!=w-1:
      if flag==0:
        if board[y][x+1]=='#':
          q.append((x+1,y,cnt+1,1))
        else:
          q.append((x+1,y,cnt,0))
      else:
        if board[y][x+1]=='#':
          q.append((x+1,y,cnt,1))
        else:
          q.append((x+1,y,cnt,0))
    if y!=h-1:
      if flag==0:
        if board[y+1][x]=='#':
          q.append((x,y+1,cnt+1,1))
        else:
          q.append((x,y+1,cnt,0))
      else:
        if board[y+1][x]=='#':
          q.append((x,y+1,cnt,1))
        else:
          q.append((x,y+1,cnt,0))
print(ans)

### FIXED CODE ###

import collections

h,w=map(int,input().split())
board=[list(input()) for _ in range(h)]
q=collections.deque()
if board[0][0]=='#':
  q.append((0,0,1,1))
else:
  q.append((0,0,0,0))
dp=[[10**18]*w for _ in range(h)]
ans=10**18
while len(q)!=0:
  x,y,cnt,flag=q.popleft()
  if x==w-1 and y==h-1:
    ans=min(ans,cnt)
  else:
    if x!=w-1:
      if flag==0:
        if board[y][x+1]=='#':
          if dp[y][x+1]>cnt+1:
            q.append((x+1,y,cnt+1,1))
            dp[y][x+1]=cnt+1
        else:
          if dp[y][x+1]>cnt:
            q.append((x+1,y,cnt,0))
            dp[y][x+1]=cnt
      else:
        if board[y][x+1]=='#':
          if dp[y][x+1]>cnt:
            q.append((x+1,y,cnt,1))
            dp[y][x+1]=cnt
        else:
          if dp[y][x+1]>cnt:
            q.append((x+1,y,cnt,0))
            dp[y][x+1]=cnt
    if y!=h-1:
      if flag==0:
        if board[y+1][x]=='#':
          if dp[y+1][x]>cnt+1:
            q.append((x,y+1,cnt+1,1))
            dp[y+1][x]=cnt+1
        else:
          if dp[y+1][x]>cnt:
            q.append((x,y+1,cnt,0))
            dp[y+1][x]=cnt
      else:
        if board[y+1][x]=='#':
          if dp[y+1][x]>cnt:
            q.append((x,y+1,cnt,1))
            dp[y+1][x]=cnt
        else:
          if dp[y+1][x]>cnt:
            q.append((x,y+1,cnt,0))
            dp[y+1][x]=cnt
print(dp[-1][-1])
### BUGGY CODE ###

import math
A,B,N = map(int,input().split())
ans = list()
for x in range(1,N+1):
    ans.append(math.floor(A*x/B)-A*math.floor(x/B))
print(max(ans))

### FIXED CODE ###

import math
A,B,N = map(int,input().split())
x = min(B-1,N)
print(math.floor(A*x/B)-A*math.floor(x/B))
### BUGGY CODE ###

N = int(input())
ARR = []

for i in range(N-1):
    ARR.append([int(s)for s in input().split(" ")])

def aaa(currentIndex, m, arr):
    currentStartTime = arr[currentIndex][1]
    currentCost = arr[currentIndex][0]
    currentFrequency = arr[currentIndex][2]

    i = 0
    cm = currentStartTime + currentFrequency * i
    while cm < m:
        i = i + 1
        cm = currentStartTime + currentFrequency * i

    if currentIndex == len(arr) - 1:
        return cm + currentCost
    else:
        return aaa(currentIndex + 1, cm+currentCost, arr)




def calculate(n, arr):
    for index in range(n):
        if index == n - 1:
            print(0)
            continue

        start = arr[index][1]

        result = aaa(index,start,arr)
        print(result)

calculate(N, ARR)


### FIXED CODE ###

import math

N = int(input())
ARR = []

for i in range(N-1):
    ARR.append([int(s) for s in input().split(" ")])


def calculate(n, arr):
    result = []
    for i in range(n-1):
        m = arr[i][1] + arr[i][0]
        for j in range(i+1,n-1):
            nextStart = arr[j][1]
            nextCost = arr[j][0]
            nextFrequency = arr[j][2]

            if m <= nextStart:
                m = nextStart

            if m  > nextStart:
                m = nextStart + math.ceil((m - nextStart)/ nextFrequency)*nextFrequency

            m = m + nextCost
        result.append(m)

    result.append(0)
    return result


result = calculate(N, ARR)


for res in result:
    print(res)
### BUGGY CODE ###

#入力
K, S = map(int, input().split())

count = 0
x = 0
while x <= K:
    y = 0
    while y <= K:
        if S-x-y <= K and S-x-y >= 0:
            count += 1
        y += 1
    x += 1

print(count)

### FIXED CODE ###

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

count = 0
for x in range(0,K+1):
    for y in range(0,K+1):
        a = S-x-y
        if a <= K and a>= 0:
            count += 1
print (count)
### BUGGY CODE ###

S = input()
N = int(input())
Q = [input().split() for n in range(N)]
F = False

for n in range(N-1):
  if F:
    F = False
    continue
  if int(Q[n][0])==1 and int(Q[n+1][0])==1:
    F = True
    continue
  else:
    if int(Q[n][0])==1:
      S = S[::-1]
    else:
      if int(Q[n][1])==1:
        S = Q[n][2]+S
      else:
        S = S+Q[n][2]

if int(Q[-1][0])==1:
  if F:
    print(S)
  else:
    print(S[::-1])
else:
  if int(Q[-1][1])==1:
    print(Q[-1][2]+S)
  else:
    print(S+Q[-1][2])

### FIXED CODE ###

S = input()
Q = int(input())
T = ""

for q in range(Q):
  que = input().split()
  if que[0]=="1":
        S,T = T,S
  else:
    if que[1]=="1":
      T+=que[2]
    else:
      S+=que[2]

print(T[::-1]+S)
### BUGGY CODE ###

s = input()
q = int(input())
for i in range(q):
    xxx = input()
    if len(xxx) == 1:
        s = s[::-1]
    else:
        T,F,C=xxx.split()
        F = int(F)
        T = int(T)
        if T == 1:
            s = s[::-1]
        else:
            if F == 1:
                s = C+s
            else:
                s = s+C
print(s)


### FIXED CODE ###

s = input()
q = int(input())
adv = ''
bac = ''
Flag = True
for i in range(q):
    xxx = input()
    if len(xxx) == 1:
        if Flag == True:
            Flag = False
        else:
            Flag = True
    else:#T=2
        T,F,C=xxx.split()
        F = int(F)
        if F == 1:
            if Flag == True:
                adv +=C
            else:
                bac +=C
        else:#F=2
            if Flag == True:
                bac +=C
            else:
                adv +=C
if Flag == True:
    s = adv[::-1] + s + bac
    print(s)
else:
    s = bac[::-1] + s[::-1] + adv
    print(s)
### BUGGY CODE ###

n = int(input())
a= input().split()
level = pow(10, 18)
product = 1

if n%2 == 1:
  a.append(1)
  n += 1

for num in range(int(n/2)):
  product *= int(a[num]) * int(a[n - 1 - num])

if product > level:
  print("-1")
else:
  print(product)

### FIXED CODE ###

n = int(input())
a= input().split()
level = pow(10, 18)
product = 1

if "0" in a:
  print(0)
else:
  for num in range(n):
    product *= int(a[num])
    if product > level:
      print("-1")
      break
  if product <= level:
    print(product)
### BUGGY CODE ###

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

ans = 0
for i in range(61):
  count_one = sum(a>>i & 1 for a in A)
  ans += (count_one * (N - count_one) * (2 ** i) ) % MOD
  
    
print(ans%MOD)

### FIXED CODE ###

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

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

ans = 0
two = 1
for i in range(61):
  n = len([ a for a in A if (a >> i) & 1 ])
  ans += (n * (N - n) * two % MOD)
  two *= 2 
print(ans%MOD)
### BUGGY CODE ###

S = int(input())

str_S = str(S)
count = 0

for i in range(len(str_S)-1):
    for j in range(i+1, len(str_S)+1):
        partial = int(str_S[i:j])
        if partial % 2019 == 0:
            count += 1

print(count)

### FIXED CODE ###

s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)