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

# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(N):
        new = (mod_list[-1]+S[N-1-i]*10**i)%2019
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
if __name__ == "__main__":
    main()

### FIXED CODE ###

# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(1,N+1):
        new1 =pow(10,i-1,2019)
        new = (new1*S[-i]+mod_list[-1])%2019
        #print(new)
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

prev = 1
for i in range(K):
    prev *= A[i]

idx = 0
for i in range(K, N):
    now = prev // A[idx] * A[i]
    if prev < now:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

    prev = now
    idx += 1

### FIXED CODE ###

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

idx = 0
for i in range(K, N):
    if A[idx] < A[i]:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

    idx += 1
### BUGGY CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

sl = []

for _ in range(h):
    s = list(input())
    sl.append(s)

uf = UnionFind(h*w)
for i in range(h):
    for j in range(w):
        if j+1 < w:
            if sl[i][j] != sl[i][j+1]:
                uf.union(i*w+j, i*w+j+1)
        if i+1 < h:
            if sl[i][j] != sl[i+1][j]:
                uf.union(i * w + j, i * w + j + w)

ans = 0
for group in uf.all_group_members().values():
    a = 0
    b = 0
    for p in group:
        i = p // w
        j = p % w
        if sl[i][j] == "#":
            a += 1
        else:
            b += 1
    ans += a*b

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

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

sl = []

for _ in range(h):
    s = list(input())
    sl.append(s)

used = [-1 for i in range(h*w)]
def dfs(i, j):
    used[i] = j
    if i % w + 1 < w:
        if sl[i//w][i%w] != sl[i//w][i%w+1]:
            if used[i+1] == -1:
                dfs(i + 1, j)
    if i % w - 1 >= 0:
        if sl[i//w][i%w] != sl[i//w][i%w-1]:
            if used[i-1] == -1:
                dfs(i - 1, j)
    if i // w + 1 < h:
        if sl[i // w][i % w] != sl[i // w+1][i % w]:
            if used[i+w] == -1:
                dfs(i + w, j)
    if i // w - 1 >= 0:
        if sl[i // w][i % w] != sl[i // w-1][i % w]:
            if used[i-w] == -1:
                dfs(i -w, j)

while True:
    if min(used) >= 0:
        break
    for i, j in enumerate(used):
        if j == -1:
            dfs(i, i)

from collections import defaultdict
dic = defaultdict(list)

for i, j in enumerate(used):
    dic[j].append(i)

ans = 0
for group in dic.values():
    a = 0
    b = 0
    for p in group:
        i = p // w
        j = p % w
        if sl[i][j] == "#":
            a += 1
        else:
            b += 1
    ans += a*b
print(ans)
### BUGGY CODE ###

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

n = int(input())
s = [sorted(input()) for i in range(n)]
cnt = 0
for i in range(0, n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            cnt += 1
print(cnt)

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
d = {}
ans = 0
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
for string in s:
    if string in d:
        ans += d[string]
        d[string] += 1
    else:
        d[string] = 1
print(ans)
### BUGGY CODE ###

#c
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()) )
mod=10**9 + 7

def cmb(n, r, m,g1,g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % m

def nCrMOD(n,r,m):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range( 2, n + 1 ):
        g1.append( ( g1[-1] * i ) % m )
        inverse.append( ( -inverse[m % i] * (m//i) ) % m )
        g2.append( (g2[-1] * inverse[-1]) % m )
    return cmb(n,r,m,g1,g2)


c=0
for i in range(m-1):
    if a[i]==a[i+1]-1: c+=1
if c!=0:
    print(0)
elif m==0:
     print( sum( nCrMOD(n-i,i,mod) for i in range(n//2+1) )%mod )
    
    
else:
    b=[a[0]-1] + [a[j+1]-a[j]-2 for j in range(m-1)] + [n-a[-1]-1]
    cc=[ sum( nCrMOD(bb-i,i,mod) for i in range(bb//2+1) )%mod for bb in b ]

    ans=1
    for ccc in cc:
        ans = ans*ccc%mod
    print(ans)

### FIXED CODE ###

#c dp version
n,m = map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()) )
from collections import deque
a=deque(a)
mod=10**9 + 7

dp=[0]*(n+2)
dp[0]=0
dp[1]=1
aa=0
if len(a)>0:
    aa=a.popleft()
for i in range(2,n+2):
    if i-1 == aa:
        dp[i]=0
        if len(a)>0:
            aa=a.popleft()
    else:
        dp[i]=( dp[i-1]+dp[i-2] )%mod
print(dp[-1])
### BUGGY CODE ###

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N = int(input())
A = list(map(int, input().split()))
ANS = [0]*len(A)
sum=0
ansList = []
for i in range(len(A),0,-1):
    if(ANS[i-1]%2!=A[i-1]):
        tList = make_divisors(i)
        for j in tList:
            ANS[j-1]+=1
        sum+=1
        ansList.append(i)
ansList.sort()
#print("")
#print(A)
#print(ANS)
print(sum)
for i in ansList:
    print(i, end=" ")

### FIXED CODE ###

import math as math

N = int(input())
A = list(map(int, input().split()))
ANS = [0]*len(A)
for i in range(math.floor(N/2)+1,N):
    ANS[i] = A[i]

fnum=math.floor(N/2)
for i in range(fnum,-1,-1):
    j = i + 1
    tsum=A[i]
    for k in range(j,N+1,j):
        tsum+=ANS[k-1]
    ANS[i]=tsum%2

#print(ANS)
anslist=[]
for i in range(N):
    if ANS[i]==1:
        anslist.append(i+1)
 
print(len(anslist))
for s in anslist:
    print(s, end =" ")
### BUGGY CODE ###

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

P, Y = [], []
for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)

result = []
for n in range(M):
    result.append(1)
    for i in range(n):
        if P[n] == P[i]:
            if Y[n] > Y[i]:
                result[n] += 1
            else:
                result[i] += 1


for x, y in zip(P, result):
    x, y = str(x), str(y)
    print('0'*(6-len(x))+x+'0'*(6-len(y))+y)


### FIXED CODE ###

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

P, Y = [], []
for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)

result = [1] * M
citys = [[] for _ in range(N)]

for i, n in enumerate(P):
    citys[n-1].append([Y[i], i])

for c in citys:
    
    c.sort()
    for i, k in enumerate(c):
        result[k[1]] += i



for x, y in zip(P, result):
    x, y = str(x), str(y)
    print('0'*(6-len(x))+x+'0'*(6-len(y))+y)
### BUGGY CODE ###

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+= a[i]^a[j]
print(ans%MOD)

### FIXED CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

m = 1
ans=0
for _ in range(60):
    bit = sum(i & m for i in a)
    bit //= m
    non_bit = n-bit
    ans = (ans+bit*non_bit*m)%MOD
    m <<= 1
print(ans)
### BUGGY CODE ###

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

c=0
for i in range(n):
  s=p[0:i+1]
  s.sort()
  if s[0]==p[i]:
    c=c+1
    
print(c)

### FIXED CODE ###

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

c=0
mini=p[0]
for i in range(n):
  if mini>=p[i]:
    c=c+1
    mini=p[i]
    
print(c)
### BUGGY CODE ###

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

ans=1

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

### FIXED CODE ###

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

ans=1

if 0 in a:
    ans=0
else:
    for i in a:
        ans*=i
        if ans > 10 ** 18:
            ans = -1
            break

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

from collections import deque
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
Q=int(input())
Colors=[0]*N

def BFS(v,d,c):
  visited=[False]*N
  visited[v]==True
  stack=deque([(v,0)])
  global Colors
  while stack:
    n,m=stack.popleft()
    if m>d:
      break
    Colors[n]=c
    for s in G[n]:
      if not visited[s]:
        stack.append((s,m+1))
        visited[s]=True
        
for i in range(Q):
  v,d,c=map(int,input().split())
  BFS(v-1,d,c)
for c in Colors:
  print(c)


### FIXED CODE ###

N,M=map(int,input().split())
E=[]
for i in range(M):
  a,b=map(int,input().split())
  E.append((a-1,b-1))
Q=int(input())
dp=[[-1]*11 for i in range(N)]
C=[]
for i in range(Q):
  v,d,c=map(int,input().split())
  dp[v-1][d]=i
  C.append(c)
for d in range(1,11)[::-1]:
  for n in range(N):
    dp[n][d-1]=max(dp[n][d],dp[n][d-1])
  for a,b in E:
    dp[a][d-1]=max(dp[a][d-1],dp[b][d])
    dp[b][d-1]=max(dp[b][d-1],dp[a][d])
for i in range(N):
  if dp[i][0]>=0:
    print(C[dp[i][0]])
  else:
    print(0)
### BUGGY CODE ###

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

ans = 0
kinds = [set() for _ in range(N + 1)]
history = set()

for i in range(N - 1, -1, -1):
    kinds[i] = kinds[i + 1].union(S[i])

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if not (S[i], S[j],) in history:
            ans += len(kinds[j+1])
            history.add((S[i], S[j],))

print(ans)


### FIXED CODE ###

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = S.find(str(i))
            if fi < 0:
                continue
            fj = S[fi+1:].find(str(j))
            if fj < 0:
                continue
            fk = S[fi+fj+2:].find(str(k))
            if fk < 0:
                continue
            ans += 1

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

def main():
    import sys
    input = sys.stdin.readline

    R, C, K = map(int, input().split())

    G = [[0] * C for _ in range(R)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        r -= 1
        c -= 1
        G[r][c] = v

    dp = [[[0] * 4 for _ in range(C + 1)] for _ in range(R + 1)]

    for r in range(R):
        for c in range(C):
            dp[r][c][0] = max(
                dp[r - 1][c][0],
                dp[r - 1][c][1],
                dp[r - 1][c][2],
                dp[r - 1][c][3],
                dp[r][c - 1][0]
            )
            for i in range(1, 4):
                dp[r][c][i] = max(dp[r][c][i], dp[r][c - 1][i])
            for i in range(2, -1, -1):
                dp[r][c][i + 1] = max(dp[r][c][i + 1], dp[r][c][i] + G[r][c])

    # print(f'{dp=}')
    ans = max(dp[-2][-2])
    print(ans)


if __name__ == '__main__':
    main()

# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline

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

    G = [[0] * W for _ in range(H)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        G[r - 1][c - 1] = v

    pdp = [[0] * 4 for _ in range(W)]
    for r in range(H):
        dp = [[0] * 4 for _ in range(W)]
        left = [0] * 4
        for c in range(W):
            cell = dp[c]

            for k in range(4):
                cell[k] = left[k]

            up = max(pdp[c])
            if cell[0] < up:
                cell[0] = up

            for k in range(2, -1, -1):
                cell[k + 1] = max(
                    cell[k + 1],
                    cell[k] + G[r][c])
            left = cell
        pdp = dp

    # for k in range(4):
    #     for row in range(H):
    #         for col in range(W):
    #             print(dp[row][col][k], end=' ')
    #         print()
    #     print()

    # print(*G, sep='\n')

    ans = max(dp[-1])
    print(ans)


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

import sys
input = sys.stdin.readline
S=input()
N=int(len(S))
for _ in list(S):
    S=S.replace("10","")
    S=S.replace("01","")
print(N-int(len(S)))

### FIXED CODE ###

S=input()
print(min(S.count("0"),S.count("1"))*2)
### BUGGY CODE ###

import sys
import numpy as np
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):  # 各行について下に見ていく
    for j in range(W):  # その行の各列について右に見ていく
        if S[i][j] == '#':
            pass  # そのマスに置いたとき照らすのは0マス(置けないので)
        else:
            if i == 0 and j == 0:  # 左上
                trailLeft[i][j] = 1
                trailUp[i][j] = 1
            elif i == 0:  # 最上行
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = 1
            elif j == 0:  # 最左列
                trailLeft[i][j] = 1
                trailUp[i][j] = trailUp[i - 1][j] + 1
            else:
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = trailUp[i - 1][j] + 1

        k = H - i - 1  # H-1 to 0
        l = W - j - 1  # W-1 to 0
        # 左上に見ていく
        if S[k][l] == "#":
            pass
        else:
            if k == H - 1 and l == W - 1:  # 右下
                trailRight[k][l] = 1
                trailDown[k][l] = 1
            elif k == H - 1:  # 最下行
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = 1
            elif l == W - 1:  # 最右列
                trailRight[k][l] = 1
                trailDown[k][l] = trailDown[k + 1][l] + 1
            else:
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = trailDown[k + 1][l] + 1

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))


### FIXED CODE ###

# can't AC without numpy, Python array handling with for is SLOW
import numpy as np
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
S = (np.array(S) == ".") * 1

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):
    if i == 0:
        trailUp[i] = S[i]
        trailDown[H - i - 1] = S[H - i - 1] * 1
    else:
        trailUp[i] = (trailUp[i - 1] + 1) * S[i]
        trailDown[H - i - 1] = (trailDown[H - i] + 1) * S[H - i - 1]

for j in range(W):
    if j == 0:
        trailLeft[:, j] = S[:, j]
        trailRight[:, W - j - 1] = S[:, W - j - 1] * 1
    else:
        trailLeft[:, j] = (trailLeft[:, j - 1] + 1) * S[:, j]
        trailRight[:, W - j - 1] = (trailRight[:, W - j] + 1) * S[:, W - j - 1]

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
lst = []
flug = True
for i in range(n):
    if a[i] in lst:
        flug = False
        break
    lst.append(a[i])
if flug: print("YES")
else: print("NO")

### FIXED CODE ###

import time
start = time.time()

n = int(input())
a = list(map(int, input().split()))
# a = [i for i in range(n)]
st = set()
for i in range(n):
    st.add(a[i])
if len(st) == n: print("YES")
else: print("NO")

# print(time.time() - start)
### BUGGY CODE ###

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

for i in range(N):
  a = []
  for j in range(N):
    if j != i:
      a.append(A[j])
  #print('=======',a)
  c = collections.Counter(a)
  ans = 0
  for k in c.values():
    #print(k)
    if k > 1:
      ans += math.factorial(k) // (math.factorial(k-2) * math.factorial(2))
  print(ans)

### FIXED CODE ###

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

import collections
c = collections.Counter(A)
a = 0

for i,j in c.items():
    a += j *(j-1) //2
#print('===', a)
for k in range(n):
    nn = c[A[k]]
    ans = a -(nn-1)
    print(ans)
### BUGGY CODE ###

H, W, M = list(map(int, input().split()))
HW = set()
hd = {}
wd = {}
for i in range(M):
	h, w = tuple(map(int, input().split()))
	HW.add((h, w))
	if h in hd:
		hd[h] += 1
	else:
		hd[h] = 1
	if w in wd:
		wd[w] += 1
	else:
		wd[w] = 1

hm = [kv[0] for kv in hd.items() if kv[1] == max(hd.values())]
wm = [kv[0] for kv in wd.items() if kv[1] == max(wd.values())]
ans = 0
for h in hm:
	for w in wm:
		if (h, w) in HW:
			ans = max(ans, (hd[h] + wd[w] - 1))
		else:
			ans = max(ans, (hd[h] + wd[w]))
print(ans)


### FIXED CODE ###

H, W, M = list(map(int, input().split()))
HW = set(tuple(int(x) - 1 for x in input().split()) for _ in range(M))
h = [0] * H
w = [0] * W
for hi, wi in HW:
	h[hi] += 1
	w[wi] += 1
hm = max(h)
wm = max(w)

hh = [i for i, v in enumerate(h) if v == hm]
ww = [i for i, v in enumerate(w) if v == wm]

ans = hm + wm - 1
for h in hh:
	for w in ww:
		if (h, w) not in HW:
			ans += 1
			break 	
	else:
		continue
	break
print(ans)
### BUGGY CODE ###

N = int(input())
T = list(map(int,input().split()))
T.sort()
ANSL = []
for i in range(len(T)):
    S = []
    for j in range(len(T)):
        S.append(T[j])
    S.pop(i)
    ANS = 0
    while True:
        S.sort()
        LIS = []
        if S[0] == 1:
            ANS += 1
            break
        elif len(S) == 1:
            ANS += S[0]
            break
        else:
            LIS.append(S[0])
            for k in range(len(S)-1):
                if (S[k+1] % S[k] == 0) or (S[k+1] % LIS[0] == 0):
                    continue
                else:
                    LIS.append(S[k+1] % S[k])
                    LIS.sort()
        S = LIS
    ANSL.append(ANS)
print(max(ANSL))


### FIXED CODE ###

import copy 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if len(T) == 2:
    ANS = max(T[0],T[1])
elif F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANS = max(ANSU,ANSV)
    
else:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)
### BUGGY CODE ###

s = input()
q = int(input())
que = [list(map(str, list(input().split()))) for i in range(q)]

for i in range(q):
    if que[i][0] == "1":
        s = s[::-1]
    elif que[i][0] == "2":
        if que[i][1] == "1":
            s = que[i][2] + s
        elif que[i][1] == "2":
            s = s + que[i][2]

print(s)

### FIXED CODE ###

s = input()
q = int(input())
que = [list(map(str, list(input().split()))) for i in range(q)]

hanten = 0
left = ""
right = ""
for i in range(q):
    if que[i][0] == "1":
        if hanten == 0:
            hanten = 1
        else:
            hanten = 0
    elif que[i][0] == "2":
        if hanten == 0:
            if que[i][1] == "2":
                sub = [right, que[i][2]]
                right = ''.join(sub)
            elif que[i][1] == "1":
                sub = [que[i][2], left]
                left = ''.join(sub)
        else:
            if que[i][1] == "2":
                sub = [que[i][2],left]
                left = ''.join(sub)
            elif que[i][1] == "1":
                sub = [right,que[i][2]]
                right = ''.join(sub)

sub = [left, s, right]
s = ''.join(sub)
if hanten == 1:
    s = s[::-1]
print(s)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000000)
import math
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    A = lmis()
    l = 1
    for a in A:
        l = lcm(l, a)
    ans = 0
    for a in A:
        ans += l//a
        ans %= N1097
    print(ans)


main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
import math
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    A = lmis()
    l = 1
    for a in A:
        l = lcm(l, a)
    print(sum(l//a for a in A) % N1097)


main()
### BUGGY CODE ###

num = int(input())
j = 1
div = pow(10,9)+7
for i in range(num):
    j = (i+1)*j
print(j%div)

### FIXED CODE ###

import math
num = int(input())

#div = pow(10,9)+7
print(math.factorial(num)%(pow(10,9)+7))
### BUGGY CODE ###

N = int(input())
S = input()
cnt = 0
for i in range(0,1000):
  if i >= 100:
    i = str(i)
  elif i >= 10:
    i = "0" + str(i)
  else:
    i = "00" + str(i)
  checker = 0
  for j in range(N):
    if S[j] == i[checker]:
      checker += 1
    if checker == 3:
      cnt += 1
      break
print(cnt)
      

### FIXED CODE ###

N = int(input())
S = input()
count = 0
for i in range(0,1000):
  if i >= 100:
    t = str(i)
  elif i >= 10:
    t = "0"+str(i)
  else:
    t = "00"+str(i)
  ti = 0
  for j in range(N):
    if S[j] == t[ti]:
      ti += 1
      if ti == 3:
        count += 1
        break
print(count)