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

s = input()
Q = int(input())

# qs = list()
# for i in range(Q):
#     qs.append(input().split())

ns = s
cnt_r = 0
for i in range(Q):
    q = input().split()
# for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                ns = ns + c
            else:
                ns = c + ns
        else:
            if cnt_r % 2 == 1:
                ns = c + ns
            else:
                ns = ns + c

if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)

### FIXED CODE ###

s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)
### BUGGY CODE ###

s = input()
t = input()

x = len(s)
y = len(t)
dp = [[0]*(y+1) for _ in range(x+1)]

for i in range(x):
    for j in range(y):
        if s[i]==t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])

res = ""
while x>0 and y>0:
    if dp[x][y] == dp[x-1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y-1]:
        y -= 1
    else:
        res = s[x-1] + res
        x -= 1
        y -= 1
print(res)

### FIXED CODE ###

s = input()
t = input()

x = len(s)
y = len(t)
dp = [[0]*(y+1) for _ in range(x+1)]

for i in range(x):
    for j in range(y):
        if s[i]==t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])

res = ""
while x>0 and y>0:
    if dp[x][y] == dp[x-1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y-1]:
        y -= 1
    else:
        res = s[x-1] + res
        x -= 1
        y -= 1
print(res)
### BUGGY CODE ###

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

if P == 2 or P == 5:
    def solve25(N, P, S):
        c = 0
        for i in range(N-1, -1, -1):
            if int(S[i]) % P == 0:
                # 以降桁を増やしてもOK
                c += i+1
        return c
    print(solve25(N, P, S))
else:
    def solve(N, P, S):
        dicmodp = {}
        dicmodp[0] = 1 # sそのものが割り切れた場合に引き算する相手がいないから
        for i in range(len(S)):
            s = int(S[i:N])
            r = s % P
            dicmodp.setdefault(r, 0)
            dicmodp[r] += 1
        c = 0
        for k, v in dicmodp.items():
            if v > 1:
                c += v*(v-1)//2
        return c
    print(solve(N, P, S))

### FIXED CODE ###

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

if P == 2 or P == 5:
    def solve25(N, P, S):
        c = 0
        for i in range(N-1, -1, -1):
            if int(S[i]) % P == 0:
                # 以降桁を増やしてもOK
                c += i+1
        return c
    print(solve25(N, P, S))
else:
    def solve(N, P, S):
        rcounts = [0] * P
        rcounts[0] = 1 # sそのものが割り切れた場合に引き算する相手がいないから
        ints = 0
        for i, s in enumerate(S[::-1]):
            ints += int(s) * pow(10, i, P)
            r = ints % P
            rcounts[r] += 1
        c = 0
        for v in rcounts:
            c += v*(v-1)//2
        return c
    print(solve(N, P, S))
### BUGGY CODE ###

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

ans = 10 ** 9

cum_sum = [10 ** 7] * N

for i in range(1,N):
  left = S[:i]
  right = S[i:]
  turn = left.count("W")+ right.count("E")
  if S[i - 1] == "W":
    turn -= 1
  cum_sum[i - 1] = turn
    
print(min(cum_sum))

### FIXED CODE ###

N = int(input())
S = input()
L = [0] * N
e = 0

for i in range(N - 1):
  #E,Wが互い違いになっていると相殺されるため手数は変わらない
  #iが増える = カーソルが右に行くにつれ
  #Eが続けて増えると手数は減り(カーソルの方向へ向く人が増えるため)、
  #Wが続けて増えると手数は増える(カーソルと逆方向を向く人が増えるため)
  if S[i + 1] == "E":
    #累積和を取っていくとともに、東の方向を向いている人数を記録する
    #カーソルが西端にあるとき、Eの総数が手数となる
    ##Eが続けて増えるとき累積和が減り、Eの総数からカーソル以西のEが相殺され、
    ##カーソル以東のEだけが計上される
    e += 1
    if S[i] == "E":
      L[i + 1] = L[i] - 1
    else: 
      L[i + 1] = L[i]
  else:
    if S[i] == "W":
      L[i + 1] = L[i] + 1
    else:
      L[i + 1] = L[i]

ans = min(L) + e
print(ans)
### BUGGY CODE ###

N, P = map(int, input().split())
S = list(input())
left_idx = 0
right_idx = N-1
count_multiples = 0
for right_idx in range(N-1, -1, -1):
  current_sum = 0
  for left_idx in range(right_idx, -1, -1):
    current_sum = (current_sum + int(S[left_idx])*pow(10, right_idx-left_idx, P))%P
    count_multiples += int(current_sum==0)
print(count_multiples)

### FIXED CODE ###

N, P = map(int, input().split())
S = input()
total = 0
if P == 2:
  for idx, right_value in enumerate(S, 1):
    if int(int(right_value)%2==0):
      total += idx
elif P == 5:
  valid_options = (0, 5)
  for idx, right_value in enumerate(S, 1):
    if int(int(right_value) in valid_options):
      total += idx
else:
  histo_modsuffix = [0]*P
  previous = 0
  for i, val in enumerate(reversed(S)):
    scale = pow(10, i, P)
    new_val = (previous + scale*int(val))%P
    histo_modsuffix[new_val] += 1
    previous = new_val
  for val in histo_modsuffix:
    total += val*(val-1)//2
  total += histo_modsuffix[0] # when right hand side is at far end
print(total)
### BUGGY CODE ###

from collections import deque

# input
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]

# bfs
bfs = [[-1 for j in range(W)] for i in range(H)]
que = deque()
for i in range(H):
    for j in range(W):
        if(A[i][j] == '#'):
            que.append((i, j))
            bfs[i][j] = 0
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
while(len(que)):
    p = que.popleft()
    for i in range(4):
        if(0 <= p[0]+dx[i] < H and 0 <= p[1]+dy[i] < W):
            if(bfs[p[0]+dx[i]][p[1]+dy[i]] == -1):
                que.append((p[0]+dx[i], p[1]+dy[i]))
                bfs[p[0]+dx[i]][p[1]+dy[i]] = bfs[p[0]][p[1]] + 1

# print ans
print(max([max(l) for l in bfs]))


### FIXED CODE ###

from collections import deque

# input
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]

# bfs
bfs = [[-1 for j in range(W)] for i in range(H)]
que = deque()
for i in range(H):
    for j in range(W):
        if(A[i][j] == '#'):
            que.append((i, j))
            bfs[i][j] = 0
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
while(len(que)):
    p = que.popleft()
    for i in range(4):
        if(0 <= p[0]+dx[i] < H and 0 <= p[1]+dy[i] < W):
            if(bfs[p[0]+dx[i]][p[1]+dy[i]] == -1):
                que.append((p[0]+dx[i], p[1]+dy[i]))
                bfs[p[0]+dx[i]][p[1]+dy[i]] = bfs[p[0]][p[1]] + 1

# print ans
print(max([max(l) for l in bfs]))
### BUGGY CODE ###

# from scipy.special import comb
from scipy.misc import comb
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
comb_tmp = []
for i in range(k - 1, n):
    comb_tmp.append(comb(i, k - 1, exact=True))
max_a = 0
for i in range(k - 1, n):
    max_a += a[i] * comb_tmp[i + 1 - k]
min_a = 0
for i in range(n - k + 1):
    min_a += a[i] * comb_tmp[n - k - i]
print(int((max_a - min_a) % 1000000007))

### FIXED CODE ###

n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
fact = [1]
for i in range(1, n + 1):
    fact.append(fact[-1] * i % 1000000007)
max_a = 0
for i in range(k - 1, n):
    max_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
a = a[::-1]
min_a = 0
for i in range(k - 1, n):
    min_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
print(int((max_a - min_a) % 1000000007))
### BUGGY CODE ###

n = int(input())
s = input()
min_ = 10**12
for i in range(n):
    s1 =s[:i]
    s2 =s[i:]
    hantai = 0
    for k in s1:
        if k == 'W':
            hantai += 1
    for k in s2:
        if k == 'E':
            hantai += 1
    min_ = min(min_, hantai)
    
print(min_)

### FIXED CODE ###

n = int(input())
s = input()
INF = 10**12
li = [INF]*n
c = 0
for i in range(len(s)):
    if i == 0:
        continue
    else:
        if s[i] == 'E':
            c+=1
li[0] = c
for i in range(n):
    if i == 0:
        continue
    else:
        li[i] = li[i-1]
        if s[i] == 'E':
            li[i] -= 1
        if s[i-1] == 'W':
            li[i] += 1

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

import collections
N = int(input())
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0

for i in A.keys():
    if A[i] >= 2:
        tyouhou = tyouhou+[i]
    if A[i] >= 4:
        seihou = seihou+[i]

if len(seihou) >= 1:
    ans = max(seihou)**2

if len(tyouhou) >= 2:
    c = max(tyouhou)
    tyouhou.remove(c)
    ans = max(ans, c*max(tyouhou))
print(ans)

### FIXED CODE ###

import collections
N = int(input())
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0

for i in A.keys():
    if A[i] >= 2:
        tyouhou.append(i)
    if A[i] >= 4:
        seihou.append(i)

if len(seihou) >= 1:
    ans = max(seihou)**2

if len(tyouhou) >= 2:
    c = max(tyouhou)
    tyouhou.remove(c)
    ans = max(ans, c*max(tyouhou))
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
import sys
sys.setrecursionlimit(10 ** 5+1)

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M = ds_in()

to_par = {i: [] for i in range(1, N+1)}
to_chi = {i: [] for i in range(1, N+1)}
con_list = []
for _ in range(N - 1 + M):
    a, b = ds_in()
    to_par[b].append(a)
    to_chi[a].append(b)

for i in range(1, N+1):
    if len(to_par[i]) == 0:
        node = i


TREE = {i: (-1, -1) for i in range(1, N+1)}


def depth_search(par, cand, depth):
    if TREE[cand][1] < depth:
        TREE[cand] = (par, depth)
    for child in to_chi[cand]:
        depth_search(cand, child, depth + 1)


depth_search(0, node, 0)

for i in range(1, N+1):
    print(TREE[i][0])


### FIXED CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
# import sys
# sys.setrecursionlimit(10 ** 5+1)
import numpy as np
# import IPython

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M = ds_in()

child = {i+1: [] for i in range(N)}
parent = {i+1: [] for i in range(N)}
inflow = {i+1: 0 for i in range(N)}
for _ in range(N+M-1):
    a, b = ds_in()
    child[a].append(b)
    parent[b].append(a)
    inflow[b] += 1

candidates = []
for i, j in inflow.items():
    if j == 0:
        candidates.append(i)

sorted_edges = []
while len(sorted_edges) < N:
    par = candidates.pop()
    sorted_edges.append(par)
    for chi in child[par]:
        inflow[chi] -= 1
        if inflow[chi] == 0:
            candidates.append(chi)


sorted_index = np.zeros(N+1, dtype=int)
sorted_index[sorted_edges] = np.arange(N)

for i in range(1, N+1):
    if i == sorted_edges[0]:
        print(0)
    else:
        print(parent[i][np.argmax(sorted_index[parent[i]])])
### BUGGY CODE ###

from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P, X = [], []
for _ in range(M):
  p, x = map(int, input().split())
  P.append(p)
  X.append(x)
  dic[p].append(x)
for key in dic:
  dic[key] = sorted(dic[key])
for i in range(M):
  print(str(P[i]).zfill(6) + str((dic[P[i]].index(X[i]) + 1)).zfill(6))
  


### FIXED CODE ###

import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))
### BUGGY CODE ###

print(sum(range(int(input()))))

### FIXED CODE ###

n = int(input())

print(n*(n-1)//2)
### BUGGY CODE ###

s = input()
t = input()
for i in range(len(s)):
  if s[i] != t[i]:
    s = s.translate(str.maketrans(s[i]+t[i],t[i]+s[i]))

if s == t:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
t = input()
used_str = []
for i in range(len(s)):
  if s[i] != t[i] and not s[i] in used_str and not t[i] in used_str:
    s = s.translate(str.maketrans(s[i]+t[i],t[i]+s[i]))
    used_str.append(s[i])
    used_str.append(t[i])

if s == t:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

#python3

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    sval = sum(a)
    for k in range(1, n+1):
        a_s = 0
        for l in range(n//2):
            a_s += a[((k+1)+(2*l))%n-1]
        ans = sval - 2 * a_s
        print(ans, end=' ')
main()


### FIXED CODE ###

#python3

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    c = 0
    for i in range(n):
        if i%2 == 0:
            c += a[i]
        else:
            c -= a[i]
    x = c//2
    xs = []
    xs.append(x)
    for i in range(2, n+1):
        z = a[i-2] - xs[i-2]
        xs.append(z)
    for i in range(n):
        xs[i] = 2*xs[i]
    for i in range(n):
        if i == n-1:
            print(xs[i])
        else:
            print(xs[i], end=' ')
main()
### BUGGY CODE ###

import numpy as np

def main():
    N, K = map(int, input().split())
    p = list(map(float, input().split()))

    p = np.array(p)
    p_prime = p
    p_1 = p + 1
    p = p * p_1 / 2
    p = p / p_prime

    su = 0
    for i in range(0, N-K+1):
        tmp = sum(p[i:(i+K)])
        if tmp > su:
            su = tmp
    print(su)


    return 0

if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))

    P_e = []
    for p in P:
        P_e.append((1 + p)/2)

    P_sum = [0]
    tmp = 0
    for i in range(N):
        tmp += P_e[i]
        P_sum.append(tmp)

    max = 0
    for i in range(K, N+1):
        tmp = P_sum[i] - P_sum[i-K]
        if tmp > max:
            max = tmp

    print(max)
    return 0
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(1, n+1):
    for j in range(0, n):
        if a[j] == i:
            ans.append(j+1)
print(' '.join(map(str, ans)))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append([i, a[i]])
b = sorted(b, key=lambda x: x[1])
c = []
for k, v in b:
    c.append(k+1)
print(' '.join(map(str, c)))
### BUGGY CODE ###

def main():
    h, w = map(int, input().split())
    s = [""]*(h+2)
    for j in range(w+2):
        s[0] += "#"
        s[h+1] += "#"
    for i in range(1, h+1):
        s[i] = "#" + input() + "#"
    cost = [[[0]*4 for j in range(w+2)] for i in range(h+2)]
    for i in range(1, h+1):
        for j in range(1, w+1):
            if s[i][j] == ".":
                cost[i][j][0] = 1
                cost[i][j][2] = 1
                cost[i][j][0] += cost[i-1][j][0]
                cost[i][j][2] += cost[i][j-1][2]
            if s[h+1-i][w+1-j] == ".":
                cost[h+1-i][w+1-j][1] = 1
                cost[h+1-i][w+1-j][3] = 1
                cost[h+1-i][w+1-j][1] += cost[h+1-i+1][w+1-j][1]
                cost[h+1-i][w+1-j][3] += cost[h+1-i][w+1-j+1][3]
    ans = 0
    for i in range(1, h+1):
        for j in range(1, w+1):
            if s[i][j] == ".":
                tmp = cost[i-1][j][0] + cost[i+1][j][1] + cost[i][j-1][2] + cost[i][j+1][3] + 1
                ans = ans if ans > tmp else tmp
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
def main():
    h, w = map(int, input().split())
    s = np.array([list(input()) for _ in range(h)])
    t = np.zeros((h+2, w+2))
    t[1:-1, 1:-1][s == "."] = 1
    row = np.zeros((h+2, w+2))
    col = np.zeros((w+2, h+2))
    for i in range(1, h+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        row[i, idx[:-1]+1] += dif-1
        row[i, idx[1:]] -= dif-1
        row[i] = np.cumsum(row[i])
    t = t.T
    for i in range(1, w+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        col[i, idx[:-1]] += dif-2
        col[i, idx[1:]] -= dif-2
        col[i] = np.cumsum(col[i])
    col = col.T
    cost = np.add(row, col)
    print(int(np.max(cost)))

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

import math

s = input()

N = len(s)
s = "#" + s
possible = 1
if s[-1] == "1" or s[1] == "0":
  possible = 0
for i in range(1,math.floor(N/2)):
  if s[i] != s[N - i]:
    possible = 0

if not possible:
  print(-1)
elif N == 2:
  if s[1] == "1" and s[2] == "0":
    print(1, 2)
  else:
    print(-1)
elif N == 3:
  if s[1] == "1" and s[2] == "1":
    print(1,2)
    print(2,3)
  else:
    print(-1)
else:
  destination = [1] * (N+1)
  root = 2
  for i in range(math.floor(N/2), -1, -1):
    if s[i] == "1":
      destination = destination[:root+1] + [root]*(i-1) + destination[root+i:]
      root += 1
  for i in range(2,N+1):
    print(i, destination[i])

### FIXED CODE ###

import math

s = input()

N = len(s)
s = "#" + s
possible = 1
if s[-1] == "1" or s[1] == "0":
  possible = 0
for i in range(1,math.floor(N/2)):
  if s[i] != s[N - i]:
    possible = 0

if not possible:
  print(-1)
elif N == 2:
  if s[1] == "1" and s[2] == "0":
    print(1, 2)
  else:
    print(-1)
elif N == 3:
  if s[1] == "1" and s[2] == "1":
    print(1,2)
    print(2,3)
  else:
    print(-1)
else:
  destination = [1] * (N+1)
  dest_change = [0] * (N+1)
  root = 2
  max_bit = math.floor(N/2)
  for i in range(max_bit, -1, -1):
    if s[i] == "1":
      #destination = destination[:root+1] + [root]*(i-1) + destination[root+i:]
      dest_change[root + 1] = dest_change[root + 1] + 1
      dest_change[root + i] = dest_change[root + i] - 1
      root += 1
  for i in range(1,N+1):
    destination[i] = destination[i - 1] + dest_change[i]
  for i in range(2,N+1):
    print(i, destination[i])
### BUGGY CODE ###

import queue
import copy

def replace(s, n, c):
    if n < 0 or n >= len(s):
        return s
    return s[:n]+c[0]+s[n+1:]

h, w = map(int, input().split())
l = [input() for _ in range(h)]

def dist(m, x1, y1, x2, y2):
    q = queue.Queue()
    q.put((x1, y1, 0))
    while not q.empty():
        x, y, count = q.get()
        if (x, y) == (x2, y2):
            return count
        if x > 0 and m[y][x-1] == ".":
            m[y] = replace(m[y], x-1, "#")
            q.put((x-1, y, count+1))
        if y > 0 and m[y-1][x] == ".":
            m[y-1] = replace(m[y-1], x, "#")
            q.put((x, y-1, count+1))
        if x < w-1 and m[y][x+1] == ".":
            m[y] = replace(m[y], x+1, "#")
            q.put((x+1, y, count+1))
        if y < h-1 and m[y+1][x] == ".":
            m[y+1] = replace(m[y+1], x, "#")
            q.put((x, y+1, count+1))

ans = 0
for i in range(h):
    for j in range(w):
        for _i in range(h):
            for _j in range(w):
                if l[i][j] == "." and l[_i][_j] == ".":
                    ans = max(ans, dist(copy.copy(l), j, i, _j, _i))
print(ans)

### FIXED CODE ###

import queue
import copy

h, w = map(int, input().split())
l = [input() for _ in range(h)]

def dist(m, x1, y1):
    q = queue.Queue()
    q.put((x1, y1, 0))
    checked=[[False for _ in range(w)] for __ in range(h)]
    checked[y1][x1] = True
    while not q.empty():
        x, y, count = q.get()
        if x > 0 and m[y][x-1] == "." and checked[y][x-1] == False:
            checked[y][x-1] = True
            q.put((x-1, y, count+1))
        if y > 0 and m[y-1][x] == "." and checked[y-1][x] == False:
            checked[y-1][x] = True
            q.put((x, y-1, count+1))
        if x < w-1 and m[y][x+1] == "." and checked[y][x+1] == False:
            checked[y][x+1] = True
            q.put((x+1, y, count+1))
        if y < h-1 and m[y+1][x] == "." and checked[y+1][x] == False:
            checked[y+1][x] = True
            q.put((x, y+1, count+1))
    return count

ans = 0
for i in range(h):
    for j in range(w):
        if l[i][j] == ".":
            ans = max(ans, dist(l, j, i))
print(ans)
### BUGGY CODE ###

pf={}
res = []
m= int(input())
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        res.append(i)
        m//=i
if m>1:
    res.append(m)
    pf[m]=1

cgg = []
for index in range(2**len(res)):

    s1 = 1
    s2 = 1
    for j in range(len(res)):
        if (index >> j & 1) == 1:
            s1 = s1 * res[j]
        else:
            s2 = s2 * res[j]

    cgg.append(s1-1 + s2 - 1)


print(min(cgg))




### FIXED CODE ###

import math

N = 10000000019
N = 50
N = 10
N = int(input())

result = []
for i in range(1, math.ceil(math.sqrt(N))+1):
    if N % i == 0:
        result.append((i + (N // i)) - 2)

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

import itertools

a,b=(int(x) for x in input().split())
l = range(a+1)
count = 0
m = [0 for x,y,z in itertools.product(l,l,l)if (x+y+z) == b]
#m = [0 for x in l for y in l for z in l if (x+y+z) == b]
print(len(m))

### FIXED CODE ###

import itertools
a,b=(int(x) for x in input().split())
l = range(a+1)
count = 0
m = [x+y for x,y in itertools.product(l,l) if (x+y)<=b]
for i in m:
  if b-i <= a:
    count+=1
print(count)
### BUGGY CODE ###

N, M = map(int, input().split())
s = [[] for i in range(N+1)]
e = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    s[a].append(b)
    e[b].append(a)

for i in s[1]:
    for j in e[N]:
        if i == j:
            print('POSSIBLE')
            exit()

print('IMPOSSIBLE')

### FIXED CODE ###

N, M = map(int, input().split())
s = [[] for i in range(N+1)]
e = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    s[a].append(b)
    e[b].append(a)

for i in s[1]:
    if N in s[i]:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')
### BUGGY CODE ###

S=input()
Q=int(input())
r_count=0
top=[1,2]
tail=[2,1]

for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        r_count+=1
    else:
        q[1]=int(q[1])
        if q[1]==1:
            q[1]=top[r_count%2]
        else:
            q[1]=tail[r_count%2]
        
        if q[1]==1:
            S=q[2]+S
        else:
            S=S+q[2]
if r_count%2==1:
    print(S[::-1])
else:
    print(S)

### FIXED CODE ###

from collections import deque
S=input()
Q=int(input())
r_count=0
top=[1,2]
tail=[2,1]
S=deque(list(S))

for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        r_count+=1
    else:
        q[1]=int(q[1])
        if q[1]==1:
            q[1]=top[r_count%2]
        else:
            q[1]=tail[r_count%2]
        
        if q[1]==1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
S=list(S)
if r_count%2==1:
    S.reverse()
print(''.join(S))
### BUGGY CODE ###


S=input()

tmp=S.split()

L=int(tmp[0])
R=int(tmp[1])

result=100000000000

for i in range(L,R+1):
    for j in range(i+1,R+1):
        if i>=j:
            break
        n=(i*j)%2019
        if result>n:
            result=n

print(result)

### FIXED CODE ###


S=input()

tmp=S.split()

L=int(tmp[0])
R=int(tmp[1])

R=min(L+2019,R)

flag=False
result=1000000000000
for i in range(L,R+1):
    for j in range(i+1,R+1):
        if i>=j:
            flag=True
            break
        n=(i*j)%2019
        if result>n:
            result=n
    if(flag):
        break



print(result)