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

s = []
l = input()
for i in range(len(l)):
	s.append(l[i:i+1])
g = 0
q = int(input())
for i in range(q):
	d = input().split(" ")
	if d[0] == "1":
		if g == 0:
			g = 1
		else:
			g = 0
	if d[0] == "2":
		f = d[1]
		if g == 0:
			if f == "1":
				s.insert(0, d[2])
			else:
				s.append(d[2])
		else:
			if f == "1":
				s.append(d[2])
			else:
				s.insert(0, d[2])
if g == 1:
	s.reverse()
	ans = "".join(s)
	print(ans)
else:
	ans = "".join(s)
	print(ans)	

### FIXED CODE ###

from collections import deque
s = deque()
l = input()
for i in range(len(l)):
	s.append(l[i:i+1])
g = 0
q = int(input())
for i in range(q):
	d = input().split(" ")
	if d[0] == "1":
		if g == 0:
			g = 1
		else:
			g = 0
	if d[0] == "2":
		f = d[1]
		if g == 0:
			if f == "1":
				s.appendleft(d[2])
			else:
				s.append(d[2])
		else:
			if f == "1":
				s.append(d[2])
			else:
				s.appendleft(d[2])
if g == 1:
	s.reverse()
	ans = "".join(s)
	print(ans)
else:
	ans = "".join(s)
	print(ans)
### BUGGY CODE ###

n,k,l=[int(x) for x in input().split()]
from collections import deque
road=[[i] for i in range(n)]
rail=[[i] for i in range(n)]
for i in [0]*k:
    p,q=[int(x)-1 for x in input().split()]
    road[p].append(q)
    road[q].append(p)
for i in [0]*l:
    r,s=[int(x)-1 for x in input().split()]
    rail[r].append(s)
    rail[s].append(r)
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    d=deque(road[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        flag[tmp]=1
        d.extend(road[tmp])
        road[i].extend(road[tmp])
    for j in road[i]:
        road[j]=road[i]
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    d=deque(rail[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        d.extend(rail[tmp])
        rail[i].extend(rail[tmp])
    for j in rail[i]:
        rail[j]=rail[i]
ans=[]
for i,j in zip(road,rail):
    ans.append(str(len(set(i)&set(j))))
print(" ".join(ans))

### FIXED CODE ###

n,k,l=[int(x) for x in input().split()]
from collections import deque
road=[{i} for i in range(n)]
rail=[{i} for i in range(n)]
for i in [0]*k:
    p,q=[int(x)-1 for x in input().split()]
    road[p].add(q)
    road[q].add(p)
for i in [0]*l:
    r,s=[int(x)-1 for x in input().split()]
    rail[r].add(s)
    rail[s].add(r)
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    flag[i]=1
    d=deque(road[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        flag[tmp]=1
        d.extend(road[tmp])
        road[i].update(road[tmp])
    for j in road[i]:
        road[j]=road[i]
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    flag[i]=1
    d=deque(rail[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        flag[tmp]=1
        d.extend(rail[tmp])
        rail[i].update(rail[tmp])
    for j in rail[i]:
        rail[j]=rail[i]
ans=[0]*n
for i in range(n):
    if ans[i]!=0:
        continue
    sumset=road[i]&rail[i]
    for j in sumset:
        ans[j]=str(len(sumset))
print(" ".join(ans))
### BUGGY CODE ###

import math

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

m = 0
c = 0
if n<b:
    m = math.floor(a*n/b)
else:
    for x in range(b,n+1,b):
        c = math.floor(a*(x-1)/b)-a*math.floor((x-1)/b)
        if c >= m:
            m=c
        else:
            break
print(m)

### FIXED CODE ###

import math

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

m = 0
if n<b:
    m = math.floor(a*n/b)
else:
    m = math.floor(a*(b-1)/b)-a*math.floor((b-1)/b)
print(m)
### BUGGY CODE ###

from bisect import bisect_left
n, m = map(int, input().split())
p, y = [0]*m, [0]*m
dict_p = {}
for i in range(m):
    p[i], y[i] = map(int, input().split())
    if p[i] not in dict_p.keys():
        dict_p[p[i]] = list()

    dict_p[p[i]].append(y[i])
#print(dict_p)
ans = [0]*m
for i in range(m):
    dict_p[p[i]].sort()
    x = bisect_left(dict_p[p[i]], y[i])
    ans = "{:006}".format(p[i]) + "{:006}".format(x+1)
    print(ans)


### FIXED CODE ###

from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
py = []
dict_p = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    py.append((p, y))
    dict_p[p].append(y)
#print(dict_p)
for values in dict_p.values():
    values.sort()

for p, y in py:
    x = bisect_left(dict_p[p], y)
    ans = "{:006}".format(p) + "{:006}".format(x+1)
    print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
MOD = 998244353
S = []
for _ in range(K):
    S.append(tuple(map(int, input().split())))

dp = [0] * (N + 1)
dp[1] = 1

for i in range(2, N+1):
    sum_list = [0 for L, R in S]

    j = 0
    for L, R in S:
        RR = i - L
        if RR <= 0:
            continue
        LL = max(1, i-R)
        if sum_list[j] == 0:
            t = sum(dp[LL:RR+1])
            sum_list[j] = t
            dp[i] += t
        else:
            if LL >= 2:
                sum_list[j] -= dp[1]
            sum_list[j] += dp[RR]
            dp[i] += sum_list[j]
        j += 1

    dp[i] %= MOD

print(dp[N])


### FIXED CODE ###

N, K = map(int, input().split())
MOD = 998244353
S = []
for _ in range(K):
    S.append(tuple(map(int, input().split())))

dp = [0] * (N + 1)
dp[1] = 1
sum_list = [0] * (N + 1)
sum_list[1] = 1

for i in range(2, N+1):
    for L, R in S:
        RR = i - L
        if RR <= 0:
            continue
        LL = max(1, i-R)
        if LL <= RR:
            t = sum_list[RR] - sum_list[LL-1]
            dp[i] += t
    sum_list[i] = (sum_list[i-1] + dp[i]) % MOD
    dp[i] %= MOD

print(dp[N])
### BUGGY CODE ###

S=input()
N=len(S)
count=0
for l in range(N-3):
    for r in range(l+3,N):
        if int(S[l:r+1])%2019==0:
            count+=1
print(count)


### FIXED CODE ###

S=input()
N=len(S)
R=[0]*(N+1)
mul=1
for i in range(1,N+1):
    R[-(i+1)]=(((int(S[-i])*mul))%(2019)+R[-i])%2019
    mul*=10
    mul%=2019
#print(R)
L=[0]*2019
for r in R:
    L[r]+=1
ans=0
for l in L:
    if l>=2:
        ans+=l*(l-1)//2
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())

s = []
for i in range(h):
   s.append(input().rstrip('\n'))

INF = 10 ** 10
d = [INF] * (h*w)

stack = deque([[ch-1, cw-1, 0]])
stack_append = stack.append
stack_popleft = stack.popleft

nex = []
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i, j) in [(-1,0),(1,0),(0,-1),(0,1),(0,0)]:
            continue
        else:
            nex.append((i,j))

while stack:
    curh, curw, cnt = stack_popleft()
    if d[curh * w + curw] <= cnt:
        continue
    else:
        d[curh * w + curw] = cnt
    for dh, dw in ((-1,0), (1,0), (0,1), (0,-1)):
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.':
            stack_append([nh, nw, cnt])
    for dh, dw in nex:
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.':
            stack_append([nh, nw, cnt+1])

# for item in d:
#     print(item)
gh -= 1
gw -= 1

if d[gh*w + gw] == INF:
    print(-1)
else:
    print(d[gh*w + gw])


### FIXED CODE ###

import sys
input = sys.stdin.readline

import heapq

INF = 10 ** 10

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    h = []
    heapq.heappush(h, (0, s))

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        d, v = heapq.heappop(h)
        if dist[v] < d:
            continue
        # vから到達可能な頂点について、距離が短くなれば更新
        for end, cost in G[v]:
            if dist[end] > dist[v] + cost:
                dist[end] = dist[v] + cost
                heapq.heappush(h, (dist[end], end))
    return dist


H, W = map(int, input().split())
N = H * W
ch, cw = map(lambda x:int(x)-1, input().split())
gh, gw = map(lambda x:int(x)-1, input().split())

s = []
es = tuple([] for i in range(N))

for h in range(H):
   s.append(input().rstrip('\n'))

for h in range(H):
    for w in range(W):
        if s[h][w] != '.':
            continue
        a = h*W+w
        esappend = es[a].append
        for dh in (-2, -1, 0, 1, 2):
            for dw in (-2, -1, 0, 1, 2):
                if dh == 0 and dw == 0:
                    continue
                nh = h + dh
                nw = w + dw
                if 0 <= nh and nh < H and 0 <= nw and nw < W and s[nh][nw] == '.':
                    b = nh*W+nw
                    if (dh, dw) in [(-1,0),(1,0),(0,-1),(0,1)]:
                        esappend((b, 0))
                    else:
                        esappend((b, 1))

dist = dijkstra(N, es, ch*W+cw)
if dist[gh*W+gw] == INF:
    print(-1)
else:
    print(dist[gh*W+gw])
### BUGGY CODE ###

N=int(input())
member=["0"]+input().split()
for i,x in enumerate(member):
    print(member.count(str(i+1)))


### FIXED CODE ###

a=[0]*int(input())
for i in input().split():a[int(i)-1]+=1
print(*a)
### BUGGY CODE ###

from bisect import bisect_left


n, m, q = map(int, input().split())
lrlist = [[int(x) for x in input().split()] for _ in range(m)]
pqlist = [[int(x) for x in input().split()] for _ in range(q)]

lrlist.sort(key=lambda lr: lr[1])
lrlist.sort(key=lambda lr: lr[0])

llist = [lr[0] for lr in lrlist]
rlist = [lr[1] for lr in lrlist]

for p, q in pqlist:
    cnt = 0
    i = bisect_left(llist, p)
    for r in rlist[i:]:
        if r <= q:
            cnt += 1
    print(cnt)

### FIXED CODE ###

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

lr = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
    l, r = map(int, input().split())
    lr[l][r] += 1

sumlr = [[0 for _ in range(n+1)] for _ in range(n+1)]
for l, r in ((l, r) for l in range(1, n+1) for r in range(1, n+1)):
    sumlr[l][r] = lr[l][r] + sumlr[l-1][r] + sumlr[l][r-1] - sumlr[l-1][r-1]

for _ in range(q):
    p, q = map(int, input().split())
    print(sumlr[q][q] - sumlr[p-1][q] - sumlr[q][p-1] + sumlr[p-1][p-1])
### BUGGY CODE ###

from dataclasses import dataclass


@dataclass
class Tembodai:
    id: int
    height: int


@dataclass
class Route:
    frm: int
    to: int


N, M = [int(x) for x in input().strip().split(" ")]
H = [int(x) for x in input().strip().split(" ")]
AB = [
    [int(x) for x in input().strip().split(" ")]
    for _ in range(M)
]

tembodai_all = {i: Tembodai(i, h) for i, h in enumerate(H)}
route_list = []
for ab in AB:
    route_list.append(Route(ab[0] - 1, ab[1] - 1))
    route_list.append(Route(ab[1] - 1, ab[0] - 1))

ok = []
for i, t in tembodai_all.items():
    routes = [r for r in route_list if r.frm == i]
    if len(routes) == 0:
        ok.append(i)
        continue
    higher = [r for r in routes if tembodai_all[r.to].height >= t.height]
    if len(higher) == 0:
        ok.append(i)
        continue
print(len(ok))

### FIXED CODE ###

N, M = [int(x) for x in input().strip().split(" ")]
H = [int(x) for x in input().strip().split(" ")]

no_good = []
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    a -= 1
    b -= 1
    if H[a] == H[b]:
        no_good += [a, b]
    elif H[a] < H[b]:
        no_good.append(a)
    elif H[a] > H[b]:
        no_good.append(b)
print(N - len(set(no_good)))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split(" ")))
acc = [0] * N
acc[0] = A[0]
for i in range(N-1):
	acc[i+1] = acc[i]^A[i+1]
	A[i+1] += A[i]

	

ans = 0
for i in range(N):
	l = i
	r = N-1
	k = i
	while l <= r:
		mid = (l + r)//2
		if i == 0:
			if acc[mid] == A[mid]:
				l = mid + 1
				k = mid
			else:
				r = mid - 1

		elif (acc[mid] ^ acc[i-1]) == (A[mid] - A[i-1]):
			l = mid + 1
			k = mid
		else:
			r = mid - 1

	ans += (k - i + 1)

print(ans)


### FIXED CODE ###

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

cnt = 0
r = 0
tmp = 0
for l in range(N):
	while r < N and (tmp & A[r]) == 0:
		tmp |= A[r]
		r += 1
	cnt += (r - l)
	tmp ^= A[l]
print(cnt)
### BUGGY CODE ###

target, m = map(int, input().split())

ship_count = 1
next_ships = []
next_start = []
for i in range(m):
  a, b = map(int, input().split())
  if a == 1:
    next_start.append(b)
  else:
    next_ships.append([a, b])

if len(next_start) == 0:
  print('IMPOSSIBLE')
  exit(0)

for i in next_ships:
  a, b = i[0], i[1]
  if a in next_start and b == target:
    print('POSSIBLE')
    exit(0)

print('IMPOSSIBLE')


### FIXED CODE ###

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

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append(b)
  if b == n:
    e.append(a)

if set(s) & set(e):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')
### BUGGY CODE ###

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

for i in range(Q):
    B,C = (int(x) for x in input().split())

    for j in range(N):

        try:
            idx = A.index(B)
            A[idx]=C
        except ValueError:
            break
    
    print(sum(A))


### FIXED CODE ###

# 371 ms, 27032 KB
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
 
bc = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]
 
dic = {}
for aa in a:
    dic[aa] = dic.get(aa, 0) + 1
 
s = sum(a)
for i in range(q):
    if b[i] not in dic:
        print (str(s))
        continue
    s += (c[i]-b[i]) * dic[b[i]]
    dic[c[i]] = dic.get(c[i], 0) + dic[b[i]]
    del dic[b[i]]
    print(s)
### BUGGY CODE ###

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

for i in range(N):
  ans = 0
  for j in range(i, N + i):
    if (j - i) % 2 == 0:
      ans += A[j % N]
    else:
      ans -= A[j % N]
  print(ans ,end = "")
  if i != N - 1:
    print(" ", end = "")
  else:
    print()

### FIXED CODE ###

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

ans = 0
for i in range(N):
  tmp = ans
  if i == 0:
    for j in range(N):
      if j % 2 == 0:
        ans += A[j]
      else:
        ans -= A[j]
  else:
    ans = 2 * A[i - 1] - tmp

  tmp = ans
  print(ans, end = "")
  if i != N - 1:
    print(" ", end = "")
  else:
    print()
### BUGGY CODE ###

import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
    else:
        if (tot_1 + int(i[2])) % 2 == 0:
            s = s + i[4]
        else:
            s = i[4] + s
if tot_1 % 2 == 1:
    s = s[::-1]
print(s)

### FIXED CODE ###

import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)
### BUGGY CODE ###

import sys
from bisect import bisect, bisect_left
sys.setrecursionlimit(1000000)

def count(i, Edge, Connect):
    if Edge[i] == i: 
        Connect[i] = 0
        return 0
    if Connect[i] > -1: return Connect[i]   
    far = 0
    for k in range(i + 1, Edge[i] + 1): far = max(far, k - i + count(k, Edge, Connect))
    Connect[i] = far
    return far

def solve():
    input = sys.stdin.readline
    N = int(input())
    R = [[int(i) for i in input().split()] for _ in range(N)]
    R.sort()
    mod = 998244353
    X = [R[i][0] for i in range(N)]
    D = [R[i][1] for i in range(N)]
    Edge = [i for i in range(N)]
    Connect = [-1] * N
    for i in range(N):
        k = bisect_left(X, X[i] + D[i])
        Edge[i] = k - 1

    #print(Edge)
    for i in range(N):
        if Connect[i] == -1: count(i, Edge, Connect)
    #print(Connect)
    DP = [0] * N
    DP.append(1)
    for i in reversed(range(N)):
        right = i + Connect[i]
        DP[i] = (DP[right + 1] + DP[i+1]) % mod
        
    print(DP[0])
    

    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
from bisect import bisect, bisect_left

class SquareDiv(): #区間の最大値を求める
    def __init__(self, N, V):
        k = 1
        while k ** 2 < N: k += 1
        self.array = [V] * k
        self.size = k
        self.indivisual = [V] * N

    def update(self, i, v): #i番目をvに更新する
        self.indivisual[i] = v
        self.array[i // self.size] = max(self.array[i // self.size], v)

    def search(self, left, right): #[left, right]の最大値を求める
        lk, rk = left // self.size, right // self.size
        if lk == rk:
            maxN = 0
            for i in range(left, right + 1): maxN = max(maxN, self.indivisual[i])
            return maxN
        else:
            maxN = self.search(left, (lk + 1) * self.size - 1)
            for k in range(lk + 1, rk): maxN = max(maxN, self.array[k])
            maxN = max(maxN, self.search(rk * self.size, right))
            return maxN

def solve():
    input = sys.stdin.readline
    N = int(input())
    R = [[int(i) for i in input().split()] for _ in range(N)]
    R.sort()
    mod = 998244353
    X = [R[i][0] for i in range(N)]
    Connect = SquareDiv(N, 0)
    DP = dict()
    DP[N] = 1
    for i in reversed(range(N)):
        right = max(i, Connect.search(i, bisect_left(X, sum(R[i])) - 1))
        Connect.update(i, right)
        DP[i] = (DP[right + 1] + DP[i + 1]) % mod
    print(DP[0])
    

    return 0

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

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

def cul(l):
    l.sort()
    ans = 0
    i = 0
    while True:
        cnt = 0
        while l[i + cnt] == l[i]:
            cnt += 1
            if i + cnt == len(l):
                break
        ans += cnt*(cnt - 1)//2
        i += cnt
        if i == len(l):
            break
    return ans

for i in range(n):
    num = a[i]
    del a[i]
    l = a.copy()
    print(cul(l))
    a.insert(0, num)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))

d = Counter(a)
key = d.keys()
ans = 0
for i in key:
    ans += (d[i]*(d[i]  - 1))//2

for i in a:
    print(ans - d[i] + 1)
### BUGGY CODE ###

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

for i in range(1,n+1):
    print(a.count(i))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(1,n+1):
    if i not in d:
        d[i] = 0

for i in range(len(a)):
    d[a[i]] += 1

for i in range(1,n+1):
    print(d[i])
### BUGGY CODE ###

from collections import Counter
N = int(input())
li = list(map(int, input().split()))
for k in range(N):
    check_li, ans = li[:k]+li[k+1:], 0
    counter = Counter(check_li)
    for i in counter.most_common():
        cnt = i[1]
        ans += cnt * (cnt-1) // 2
    print(ans)

### FIXED CODE ###

from collections import Counter
N, li = int(input()), list(map(int, input().split()))
cnt_dict, cnt_total = Counter(li), 0
for i in cnt_dict.items():
    cnt_total += i[1] * (i[1]-1) // 2
for k in range(N):
    buf = cnt_dict[li[k]]
    print(cnt_total - buf*(buf-1)//2 + (buf-1)*(buf-2)//2)
### BUGGY CODE ###


import math


def main():
    N = int(input())
    A = [int(arg) for arg in input().split()]
    ans = 1
    for i in range(N):
        ans *= A[i]

    if ans > 10**18:
        print("-1")
    else:
        print(str(ans))


if __name__ == '__main__':
    main()


### FIXED CODE ###


def main():
    N = int(input())
    A = [int(arg) for arg in input().split()]
    ans = 1

    for i in range(N):
        if A[i] == 0:
            print(0)
            return

    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            return

    print(ans)


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

import math


def calc(A, b):
    retval = 0
    for a in A:
        retval += abs(a - b)
    return retval


def main():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] -= (i + 1)

    left = min(A)
    right = max(A)

    while left < right:
        c1 = math.floor((left + left + right) / 3)
        c2 = math.floor((left + right + right) / 3)
        if calc(A, left) <= calc(A, right):
            right = c2
        else:
            left = c1
    print(calc(A, left))


if __name__ == "__main__":
    main()


### FIXED CODE ###


def calc(A, b):
    retval = 0
    for a in A:
        retval += abs(a - b)
    return retval


def main():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] -= (i + 1)

    print(calc(A, sorted(A)[(N)//2]))

#    left = min(A)
#    right = max(A)
#
#    while left < right:
#        c1 = (left + left + right) // 3       # floor
#        c2 = -(-(left + right + right) // 3)  # ceil
#        if calc(A, c1) <= calc(A, c2):
#            right = c2 - 1
#        else:
#            left = c1 + 1
#    print(calc(A, left))


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

import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for i in range(1,3501):
    for j in range(1,i):
      for k in range(1,j):
        if 4*i*j*k==N*(i*j+ j*k+k*i):
          print(i,j,k)
          sys.exit()

### FIXED CODE ###

import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
  sys.exit()
for a in range(1,3501):
  for b in range(1,a):
    M=N*a*b
    L=4*a*b-N*(a+b)
    if L>0:
      if M%L==0:
        print(a,b,M//L)
        sys.exit()
### BUGGY CODE ###

from math import floor

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

mv = 0
while N > 0:
    mv = max(mv, floor(A*N/B) - A*floor(N/B))
    N -= 1

print(mv)

### FIXED CODE ###

from math import floor

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

if B > N:
    print(floor(A*N/B) - A*floor(N/B))
else:
    N = B - 1
    print(floor(A*N/B) - A*floor(N/B))
### BUGGY CODE ###

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


count = 0
for x in range(K+1):
    if x > S :
        break
    elif S - x > 2*K:
        continue
    for y in range(K+1):
        if x + y > S:
            break
        elif S - (x+y) > K:
            continue
        for z in range(K+1):
            if x + y + z > S:
                break
            elif x + y + z == S:
                count +=1
print(count)


### FIXED CODE ###

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


count = 0
for x in range(K+1):
    if x > S :
        break
    elif S - x > 2*K:
        continue
    for y in range(K+1):
        if x + y > S:
            break
        elif S - (x+y) > K:
            continue
        count+= 1
print(count)
### BUGGY CODE ###

#!/usr/bin/env python3
k = int(input())
if k % 2 < 1 or k % 5 < 0:
    print(-1)
else:
    c = 1
    mod = 7 % k
    mop = 7 % k
    while mod > 0:
        mop = mop*10%k
        mod += mop
        mod %= k
        c += 1
    print(c)


### FIXED CODE ###

#!/usr/bin/env python3
k = int(input())
if k % 2 < 1 or k % 5 < 1:
    print(-1)
else:
    c = 1
    mod = 7 % k
    mop = 7 % k
    while mod > 0:
        mop = mop*10%k
        mod += mop
        mod %= k
        c += 1
    print(c)
### BUGGY CODE ###

L, R = map(int, input().split())
min = 2019

for i in range(L, R+1):
	if i % 2019 == 0:
		min = 0
		break
	if min == 0:
		break
	for j in range(i+1, R+1):
		if i % 673 == 0 and j % 3 == 0:
			min = 0
			break 
		num = i * j % 2019
		if j > i and num < min:
			min = num

print(min)

### FIXED CODE ###

L, R = map(int, input().split())
min = 2019

if R -L >= 2019:
	min = 0
else:

	for i in range(L, R+1):
		for j in range(i+1, R+1):
			num = i * j % 2019
			if j > i and num < min:
				min = num

print(min)
### BUGGY CODE ###

from math import factorial

s = input()
mod = 2019
array = [0]*mod

for i in range(len(s)):
    array[int(s[i:len(s)]) % mod] += 1
    
array[0] += 1
    
cnt = 0
for i in range(mod):
    if array[i] > 1:
        cnt += factorial(array[i]) / (factorial(2)*factorial(array[i] - 2))
        
print(int(cnt))

### FIXED CODE ###

s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
    

    
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += w*(w-1)/2
    
print(int(cnt))