Harryxun/stf_run huggingface dataset:
#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(n, W):
    # oxoxoxoxoxoxox
    mini = sys.maxsize
    #print(n, W)
    for i in range(len(W)):
        #print(i)
        mini = min(abs(sum(W[0:i]) - sum(W[i:len(W)])), mini)
    #print("end")
    return mini


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    #print(parsed_lines)
    n = int(parsed_lines[0][0])
    W = [int(x) for x in parsed_lines[1]]
    # k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, W


if not do_submit:
    n, W = input_parse("""
    3
    1 2 3
    """)
    print(sol(n, W))

    n, W = input_parse("""
    4
    1 3 1 1
    """)
    print(sol(n, W))

else:
    n = int(input().split())
    W = list(map(int, input().split()))
    # print(sol(n, k, S))
    #S = input().strip()
    # S = input().strip()
    print(sol(n, W))



### FIXED CODE ###

#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(n, W):
    # oxoxoxoxoxoxox
    mini = sys.maxsize
    #print(n, W)
    for i in range(len(W)):
        #print(i)
        mini = min(abs(sum(W[0:i]) - sum(W[i:len(W)])), mini)
    #print("end")
    return mini


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    #print(parsed_lines)
    n = int(parsed_lines[0][0])
    W = [int(x) for x in parsed_lines[1]]
    # k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, W


if not do_submit:
    n, W = input_parse("""
    3
    1 2 3
    """)
    print(sol(n, W))

    n, W = input_parse("""
    4
    1 3 1 1
    """)
    print(sol(n, W))

else:
    n = int(input())
    W = list(map(int, input().split()))
    # print(sol(n, k, S))
    #S = input().strip()
    # S = input().strip()
    print(sol(n, W))
a, b, c = map(int, input().split())
print(a + b + c)

### FIXED CODE ###

s = input()
print(s.count('1'))
test=1
Copy
H,W,M = list(map(int,input().split()))
 
h = [0] * H
w = [0] * W
 
hw = []
 
for _ in range(H):
    hw.append([0] * W)

    
for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)
 
hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]
 

### FIXED CODE ###

h,w,m=map(int,input().split())
a=[0]*h
b=[0]*w
hw=[]
for _ in range(m):
    hh,ww=map(int,input().split())
    hw+=((hh-1,ww-1)),
    a[hh-1]+=1
    b[ww-1]+=1
    
ma=max(a)
mb=max(b)

# x_ind=[i for i,j in enumerate(a) if j==ma]
# y_ind=[i for i,j in enumerate(b) if j==mb]



cnt=0
# sonzai suru

for i,j in hw:
    if a[i]==ma and b[j]==mb:cnt+=1

if cnt==a.count(ma)*b.count(mb):
    print(ma+mb-1)
else:
    print(ma+mb)
def insertionsort(A, n):
    for i in range(1, n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        prt(A)

def prt(A):
    for i in A:
        if i != A[len(A)-1]: print(i, end=" ")
        else print(i)

n = int(input())
A = input().split()
A = [int(i) for i in A]
prt(A)
insertionsort(A, n)


### FIXED CODE ###

def insertionsort(A, n):
    for i in range(1, n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        prt(A)

def prt(A):
    for i in A:
        if i != A[len(A)-1]: print(i, end=" ")
        else: print(i)

n = int(input())
A = input().split()
A = [int(i) for i in A]
prt(A)
insertionsort(A, n)
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
redq = deque(red[:x])
ans = 0
oisr = 0
#print(red,gw,gwrui)
for i in range(1,x+1):
    oisr += redq.popleft()
    temp = oisr
    temp += gwrui[x+y-i-1]
    ans = max(ans,temp)
print(ans)

### FIXED CODE ###

from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
red = red[:x]
rrui = []
rui = 0
for i in range(x):
    rui += red[i]
    rrui.append(rui)
rrui = [0] + rrui
ans = 0
oisr = 0
lgw = len(gw)
#print(red,gw,gwrui)
for i in range(0,x+1):
    temp = rrui[i]
    if x+y-i <= lgw:
        temp += gwrui[x+y-i-1]
        ans = max(ans,temp)
print(ans)
def abc070_d():
    import sys
    read = sys.stdin.buffer.read
    inp = iter(map(int, read().split()))

    import numpy as np
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import dijkstra

    n = next(inp)
    adjmtx = np.zeros((n, n), dtype=np.int64)
    for _ in range(n-1):
        a = next(inp) - 1
        b = next(inp) - 1
        c = next(inp)
        adjmtx[a, b] = c
        adjmtx[b, a] = c

    q = next(inp)
    k = next(inp) - 1

    graph = csr_matrix(adjmtx)
    dist = dijkstra(csgraph=graph, indices=k)
    eps = 1e-6

    for _ in range(q):
        x = next(inp) - 1
        y = next(inp) - 1
        ans = int(dist[x] + dist[y] + eps)
        print(ans)

if __name__ == '__main__':
    abc070_d()

### FIXED CODE ###

def abc070_d():
    import sys
    sys.setrecursionlimit(10010010)
    read = sys.stdin.buffer.read
    inp = iter(map(int, read().split()))

    n = next(inp)
    adjlist = [[] for _ in range(n)]
    for _ in range(n-1):
        a = next(inp) - 1
        b = next(inp) - 1
        c = next(inp)
        adjlist[a].append((b, c))
        adjlist[b].append((a, c))

    q = next(inp)
    k = next(inp) - 1

    dist = [-1] * n

    def dfs(x:int, d:int):
        dist[x] = d
        for nx, nd in adjlist[x]:
            if dist[nx] != -1: continue
            dfs(nx, d + nd)

    dfs(k, 0)

    for _ in range(q):
        x = next(inp) - 1
        y = next(inp) - 1
        ans = dist[x] + dist[y]
        print(ans)

if __name__ == '__main__':
    abc070_d()
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
dist_lap1 = T1 * A1 + T2 * A2
dist_lap2 = T1 * B1 + T2 * B2
if dist_lap1 == dist_lap2:
    print("infinity")
else:
    if dist_lap1 > dist_lap2:
        diff = T1 * B1 - T1 * A1
        print(diff // (dist_lap1 - dist_lap2) * 2 + 1)
    else:
        diff = T1 * A1 - T1 * B1
        print(dff // (dist_lap2 - dist_lap1) * 2 + 1)

### FIXED CODE ###

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
dist_lap1 = T1 * A1 + T2 * A2
dist_lap2 = T1 * B1 + T2 * B2
if dist_lap1 == dist_lap2:
    print("infinity")
else:
    if dist_lap1 > dist_lap2:
        diff = T1 * B1 - T1 * A1
        if diff < 0:
            print(0)
        else:
            if diff % (dist_lap1 - dist_lap2) == 0:
                print((diff // (dist_lap1 - dist_lap2)) * 2)
            else :
                print((diff // (dist_lap1 - dist_lap2)) * 2 + 1)
    else:
        diff = T1 * A1 - T1 * B1
        if diff < 0:
            print(0)
        else:
            if diff % (dist_lap2 - dist_lap1) == 0:
                print((diff // (dist_lap2 - dist_lap1)) * 2)
            else :
                print((diff // (dist_lap2 - dist_lap1)) * 2 + 1)
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n:
                DPy[i+1][j+y_d[i]] = True

if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a,b=map(int,input().split())
print((a+b+1)//2)
from collections import*
n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C)
if l==3:f=(len(set(c[1]for c in C))>1)+n%3>0
elif l==2:f=(abs(C[1][1]-C[0][1])!=n//3)+n%3>0
else:f=(l!=1)*(A[0]>0)
print('YNeos'[f::2])

### FIXED CODE ###

from collections import*
n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C)
if l==3:
  x=0
  for c in C:x^=c[0]
  f=(len(set(c[1]for c in C))>1)+n%3+x>0
elif l==2:f=(abs(sum(c[1]*(-1)**i for i,c in enumerate(C)))!=n//3)+n%3>0
else:f=(l!=1)+A[0]>0
print('YNeos'[f::2])
H, W = map(int,input().strip().split())
for i in range(H):
  line = input()
  for j in range(2):
  print(line)

### FIXED CODE ###

H, W = map(int,input().strip().split())
for i in range(H):
  line = input()
  for j in range(2):
  	print(line)
n, _ = map(int, input().split())
numbers = list(map(int, input().split()))
reqs = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

memo = {}


def max_counts(a, b):
    """
    a と b 大きい方を返す
    :param a: solve() の返り値
    :param b: solve() の返り値
    :return:
    """
    if a is None:
        return b
    if b is None:
        return a
    # 桁数は大きいほうが大きい
    if sum(a) > sum(b):
        return a
    if sum(a) < sum(b):
        return b
    # 桁数が同じなら、大きい数字の多いほうが大きい
    for a_c, b_c in zip(reversed(a), reversed(b)):
        if a_c > b_c:
            return a
        if a_c < b_c:
            return b
    return a


def solve(n):
    """
    n 本のマッチを使ったときの最大の整数の 0 から 9 までの使用回数をリストで返す
    :param n:
    :rtype: list of int
    """
    if n in memo:
        return memo[n]
    if n == 0:
        return [0 for _ in range(10)]
    if n < 0:
        return None

    res = None
    for num in numbers:
        counts = solve(n - reqs[num])
        if counts:
            res = max_counts(res, counts[:num] + [counts[num] + 1] + counts[num + 1:])

    memo[n] = res
    return res


result_counts = solve(n)
ans = ''
for num in range(9, 0, -1):
    for _ in range(result_counts[num]):
        ans += str(num)
print(ans)


### FIXED CODE ###

n, _ = map(int, input().split())
numbers = list(map(int, input().split()))
reqs = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

memo = {}


def max_counts(a, b):
    """
    a と b 大きい方を返す
    :param a: solve() の返り値
    :param b: solve() の返り値
    :return:
    """
    if a is None:
        return b
    if b is None:
        return a
    # 桁数は大きいほうが大きい
    if sum(a) > sum(b):
        return a
    if sum(a) < sum(b):
        return b
    # 桁数が同じなら、大きい数字の多いほうが大きい
    for a_c, b_c in zip(reversed(a), reversed(b)):
        if a_c > b_c:
            return a
        if a_c < b_c:
            return b
    return a


# https://atcoder.jp/contests/abc118/submissions/4911280
# DP 版
memo[0] = [0 for _ in range(10)]
for i in range(n):
    if i in memo:
        for num in numbers:
            next_n = i + reqs[num]
            next_counts = memo[next_n] if next_n in memo else None
            if next_n <= n:
                memo[next_n] = max_counts(
                    next_counts,
                    memo[i][:num] + [memo[i][num] + 1] + memo[i][num + 1:]
                )

ans = ''
for num in range(9, 0, -1):
    for _ in range(memo[n][num]):
        ans += str(num)
print(ans)
import queue

q = queue.Queue()
H,W = map(int, input().split())
memo = [[-1]*W for _ in range(H)]
board = [input() for _ in range(H)]
wall=0
direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def bfs():
    memo[0][0] = 0
    q.put((0, 0))
    while not q.empty():
        y,x= q.get()
        for (dy, dx) in direction:
            if 0<=y+dy<=H-1 and 0<=x+dx<=W-1 and board[y+dy][x+dx] == '.' and memo[y+dy][x+dx] == -1:
                q.put((y + dy, x + dx))
                memo[y + dy][x + dx] = memo[y][x] + 1
                if (y+dy, x+dx) == (H-1, W-1):
                    return memo[H-1][W-1]

for s in board:
    wall+=s.count('#')

print(H*W-wall-(bfs()+1))

### FIXED CODE ###

import queue

q = queue.Queue()
H,W = map(int, input().split())
memo = [[-1]*W for _ in range(H)]
board = [input() for _ in range(H)]
wall=0
direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def bfs():
    memo[0][0] = 0
    q.put((0, 0))
    while not q.empty():
        y,x= q.get()
        for (dy, dx) in direction:
            if 0<=y+dy<=H-1 and 0<=x+dx<=W-1 and board[y+dy][x+dx] == '.' and memo[y+dy][x+dx] == -1:
                q.put((y + dy, x + dx))
                memo[y + dy][x + dx] = memo[y][x] + 1
                if (y+dy, x+dx) == (H-1, W-1):
                    return memo[H-1][W-1]
    return -1


for s in board:
    wall+=s.count('#')

min_dist=bfs()
print(H*W-wall-(min_dist+1) if min_dist>0 else -1)
n = int(input())
a = [int(i) for i in input().split()]
count1 =0
count2 = 0
for i in a:
    if i%2==0:
        count1+=1
        if i%3==0 or i%5 == 0:
            count2+=1
    else:
        pass
if count1 == count2:
    print('APPROVED')
else:
    print("DENIED")

### FIXED CODE ###

s = input()

print("x"*len(s))
S = list(input())
position = [1] * len(S)
prev = position.copy()
for i in range(10**100):
    prev_prev = prev.copy()
    prev = position.copy()
    tmp = position.copy()
    for j, s in enumerate(S):
        if position[j] != 0:
            if s == 'R':
                position[j+1] += tmp[j]
                position[j] -= tmp[j]
            elif s == 'L':
                position[j-1] += tmp[j]
                position[j] -= tmp[j]
    if position == prev:
        print(*prev)
        break
    elif position == prev_prev:
        print(*prev_prev)
        break


### FIXED CODE ###

s = input()
tmp = [0]
for i in range(len(s)-1):
    if s[i] != s[i+1]:  # RとLが切り替わる時のインデックスを保存
        tmp.append(i+1)
tmp.append(len(s))
ans = [0 for i in range(len(s))]
for i in range(len(tmp)-1):
    if i % 2 == 1:
        ans[tmp[i]] = (tmp[i]-tmp[i-1])//2 + (tmp[i+1]-tmp[i]+1)//2
        ans[tmp[i]-1] = (tmp[i+1]-tmp[i])//2 + (tmp[i]-tmp[i-1]+1)//2
print(*ans)
# RRLLLLRLRRLL
a, b = raw_input.split()

if a == "H":
    print b
else:
    if b == "H":
        print "D"
    else:
        print "H"

### FIXED CODE ###

a, b = raw_input().split()

if a == "H":
    print b
else:
    if b == "H":
        print "D"
    else:
        print "H"
def insertionSort(A,n,g):
    for i in range(g,n,1):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            global cnt
            A[j + g] = A[j]
            j = j - g
            cnt = cnt + 1
        A[j+g] = v
            
def shellSort(A,n):
    global cnt
    global G
    G = []
    cnt = 0
    h = 1
    while h <= n:
        G.append(h)
        h = 3*h + 1
        if(len(G)>100):
            break
    m = len(G)
    print(m)
    G.reverse()
    print(' '.join(map(str, G)))
    for i in range(0,m,1):
        insertionSort(A,n,G[i])
    print(cnt)
        

n = int(input())
#改行で標準入力を受け付ける場合
A = [int(input()) for i in range(n)]
shellSort(A,n)
# print('\n'.join(A))
print(*A,sep='\n')


### FIXED CODE ###

import sys


def print_A(A):
    for i in range(len(A)):
        sys.stdout.write(str(A[i]))
        if i!= len(A) -1:
            sys.stdout.write(' ')
    print()


def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while (j>=0) and (A[j] > v):
            A[j + g] = A[j]
            j -= g
            cnt +=1
        A[j + g] = v
    return cnt

def shellSort(A,n,G):
    cnt = 0
    for i in range(len(G)):
        cnt += insertionSort(A,n,G[i])
    return cnt
        

def get_gap(n):
    G = []
    h = 1
    cnt = 1
    while h <= n:
        G.append(h)
        h = 3*h + 1
        cnt +=1
    if len(G) == 0: G.append(1)
    return list(reversed(G))


n = int(input())
A = [0] * n
for i in range(n):
    A[i] = int(input())
    
G = get_gap(n)
m = len(G)
cnt = shellSort(A,n,G)

print(m)
print_A(G)
print(cnt)
for i in range(n):
    print(A[i])
A, B = map(int, input()split())
x = A+B
y = A-B
z = A*B

if B>=0:
  if x - z >= 0:
    print(x)
  else:
    print(z)
else:
  if y - z >= 0:
    print(y)
  else:
    print(z)


### FIXED CODE ###

A, B = map(int, input().split())
x = A+B
y = A-B
z = A*B

if B>=0:
  if x - z >= 0:
    print(x)
  else:
    print(z)
else:
  if y - z >= 0:
    print(y)
  else:
    print(z)
a = []
for i in range(4):
  a.append(int(input()))

if a[0] > a[1]:
  print(a[3]*a[1]+a[4]*(a[2]-a[1]))
else:
  print(a[3]*a[1])

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())

if a <= b:
  print(a*c)
else:
  print(c*b+d*(a-b))
h, w = map(int, input().split())
s = []
l = []
r = []
u = []
d = []
for i in range(h):
  s.append(input())
  l.append([0 for j in range(w)])
  r.append([0 for j in range(w)])
  u.append([0 for j in range(w)])
  d.append([0 for j in range(w)])
  
# lみる
for x in range(w):
  for y in range(h):
    if s[y][x] == '.':
      if x == 0:
        l[y][x] = 1
      else:
        l[y][x] = l[y][x-1] + 1
 
# rみる
for x in range(w):
  for y in range(h):
    if s[h-1-y][w-1-x] == '.':
      if x == 0:
        r[y][x] = 1
      else:
        r[y][x] = r[y][x+1] + 1
 
# uみる
for y in range(h):
  for x in range(w):
    if s[y][x] == '.':
      if y == 0:
        u[y][x] = 1
      else:
        u[y][x] = u[y-1][x] + 1
 
# dみる
for y in range(h):
  for x in range(w):
    if s[h-1-y][w-1-x] == '.':
      if y == 0:
        d[y][x] = 1
      else:
        d[y][x] = d[y+1][x] + 1
 
 
max_all = 0
for y in range(h):
  for x in range(w):
    max_tmp = l[y][x] + r[y][x] + u[y][x] + d[y][x]
    if max_tmp > max_all:
      max_all = max_tmp
      
print(max_all - 3)

### FIXED CODE ###

h, w = map(int, input().split())
s = []
l = []
r = []
u = []
d = []
for i in range(h):
  s.append(input())
  l.append([0 for j in range(w)])
  r.append([0 for j in range(w)])
  u.append([0 for j in range(w)])
  d.append([0 for j in range(w)])
  
# lみる
for x in range(w):
  for y in range(h):
    if s[y][x] == '.':
      if x == 0:
        l[y][x] = 1
      else:
        l[y][x] = l[y][x-1] + 1
 
# rみる
for x in range(w-1, -1, -1):
  for y in range(h-1, -1, -1):
    if s[y][x] == '.':
      if x == w-1:
        r[y][x] = 1
      else:
        r[y][x] = r[y][x+1] + 1
 
# uみる
for y in range(h):
  for x in range(w):
    if s[y][x] == '.':
      if y == 0:
        u[y][x] = 1
      else:
        u[y][x] = u[y-1][x] + 1
 
# dみる
for y in range(h-1, -1, -1):
  for x in range(w-1, -1, -1):
    if s[y][x] == '.':
      if y == h-1:
        d[y][x] = 1
      else:
        d[y][x] = d[y+1][x] + 1
 
 
max_all = 0
for y in range(h):
  for x in range(w):
    max_tmp = l[y][x] + r[y][x] + u[y][x] + d[y][x]
    if max_tmp > max_all:
      max_all = max_tmp
      
print(max_all - 3)
ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    matrix = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for _h in range(h):
        for _w in range(w):
            if matrix[_h][_w] % 2 == 0:
                continue
            matrix[_h][_w] -= 1
            if _w < w - 1:
                matrix[_h][_w + 1] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 1, _w + 2))
            elif _h < h - 1:
                matrix[_h + 1][_w] += 1
                move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 2, _w + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


### FIXED CODE ###

h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))
x = raw_imput()
x = int(x)
print x ** 3

### FIXED CODE ###

x = raw_input()
x = int(x)
x = x ** 3
print x
x,y=map(int,input().split())




mod=10**9+7

if (2*x-y)%3==0 and (2*y-x)%3==0:
  a=(2*x-y)/3
  b=(2*y-x)/3
  #print(a,b)

  result=0.0
  bunbo=1
  bunshi=1
  for i in range(int(a)):
    bunbo=bunbo*(a+b-i)
    bunshi=bunshi*(1+i)
    #print(bunbo,bunshi)
  result=bunbo/bunshi%mod
  print(int(result))
  

  
else:
  print(0)

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

x,y=map(int,input().split())



if (x+y)%3!=0:
    print(0)
    exit()

if x==0 and y==0:
    print(0)
    exit()


n=(2*y-x)//3
m=(2*x-y)//3


if m<0 or n<0:
    print(0)
    exit()

if n==0 and m==1:
    print(1)
    exit()
if n==1 and m==0:
    print(1)
    exit()
    

#n+mCm
#(n+m)!/m!


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)



print(cmb(n+m, m, 10**9+7))
L, R = map(int, input().split())
for i in range(L, R+1):
    f = False
    for j in range(i+1, R+1):
        m = (i*j)%2019
        if  m  == 0:
            print(0)
            f = True
            break     
        ans = min(ans, m)
    if f:
        break
print(ans)

### FIXED CODE ###

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

ans = 2018
R = min(R, L+2020)
for i in range(L, R+1):
    f = False
    for j in range(i+1, R+1):
        m = (i*j)%2019
        if  m  == 0:
            ans = m
            f = True
            break     
        ans = min(ans, m)
    if f:
        break
print(ans)