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

import heapq

class Graph_CONNECT:
    """
    接続リスト方式
    """
    def __init__(self, N):
        self.number_of_node = N
        self.neighbour_list = [[] for _ in range (N)]

    def connect(self, from_node, to_node, weight):
        """
        from_nodeからto_nodeに長さweightの辺を追加する
        """
        self.neighbour_list[from_node].append((to_node, weight))

    def dijkstra(self, source_node, target_node = None):
        """
        source_nodeからtarget_nodeへの最短路計算
        source_nodeの入次数は0と仮定する
        """
        INF = 1 << 32
        dist = [INF] * self.number_of_node
        #prev = [-1] * self.number_of_node
        dist[source_node] = 0
        hq = []
        heapq.heappush(hq, (0, source_node))
        while len(hq) > 0:
            d, from_node = heapq.heappop(hq)
            if dist[from_node] < d:
                continue
            for to_node, weight in self.neighbour_list[from_node]:
                """
                weight = adj[from_node][to_node]
                # 辺がないところはスキップ
                if weight < 0:
                    continue
                """
                if dist[to_node] == INF or dist[from_node] + weight < dist[to_node]:
                    dist[to_node] = dist[from_node] + weight
                    heapq.heappush(hq, (dist[to_node], to_node))
                    #prev[to_node] = from_node
        if target_node is None:
            return dist
        else:
            return dist[target_node]

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

graph = Graph_CONNECT(N + 1)
for i in range(N+1):
    for j in range(i+1, N+1):
        if A[i] + 1 == A[j]:
            graph.connect(i,j,-1)

dist = graph.dijkstra(0)

ans = min(dist)
if ans >= 0:
    print(-1)
else:
    print(N+ans)

### FIXED CODE ###

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

cnt = 0
for num in A:
    if num == cnt + 1:
        cnt+=1
if cnt == 0:
    print(-1)
else:
    print(N - cnt)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
def f(x):
  if x==1:
    return dict()
  y=x
  r=dict()
  for i in range(2,int(x**0.5)+1):
    if y%i==0:
      r[i]=0
      while y%i==0:
        r[i]+=1
        y=y//i
    if y==1:
      break
  if y!=1:
    r[y]=1
  return r

B=[f(A[i]) for i in range(N)]
G=dict()
def g(x,y):
  z=list(set(x.keys())|set(y.keys()))
  r=dict()
  for i in range(len(z)):
    r[z[i]]=max(x.get(z[i],0),y.get(z[i],0))
  return r

for i in range(N):
  G=g(G,B[i])
X=1
mod=10**9+7
P=0
Y=list(G.keys())
for i in range(len(Y)):
  X=X*pow(Y[i],G[Y[i]],mod)%mod
for i in range(N):
  P=(P+X*pow(A[i],mod-2,mod))%mod
print(P)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
def f(x):
  if x==1:
    return dict()
  y=x
  r=dict()
  for i in range(2,int(x**0.5)+1):
    if y%i==0:
      r[i]=0
      while y%i==0:
        r[i]+=1
        y=y//i
    if y==1:
      break
  if y!=1:
    r[y]=1
  return r

B=[f(A[i]) for i in range(N)]
def g(X):
  if len(X)==1:
    return X[0]
  a,b=g(X[:len(X)//2]),g(X[len(X)//2:])
  c=list(set(a.keys())|set(b.keys()))
  for i in range(len(c)):
    a[c[i]]=max(a.get(c[i],0),b.get(c[i],0))
  return a

G=g(B)
X=1
mod=10**9+7
P=0
Y=list(G.keys())
for i in range(len(Y)):
  X=X*pow(Y[i],G[Y[i]],mod)%mod
for i in range(N):
  P=(P+X*pow(A[i],mod-2,mod))%mod
print(P)
### BUGGY CODE ###

N = int(input())
A = input().split(' ')

for i in range(N):
    A[i] = int(A[i])

A.sort()
A.reverse()

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in reversed(range(0, A[0])):

        count = 0

        for i in range(N):
            if(A[i] % term !=0):
                count += 1
            if(count == 2):
                break

        if(count <= 1):
            break

    print(term)

### FIXED CODE ###

def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(end_i, A):
    if(end_i == 0):
        return 0
    
    a = 0
    for i in range(end_i):
        a = gcd(a, A[i])
    return a


def R(start_i, A, N):
    if(start_i == N - 1):
        return 0

    a = 0
    for i in range(start_i + 1, N):
        a = gcd(a, A[i])
    return a


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

left = [0] * N
right = [0] * N

for i in range(1, N):
    left[i] = gcd(left[i - 1], A[i - 1])
#print(left)

for i in reversed(range(0, N - 1)):
    right[i] = gcd(A[i + 1], right[i + 1])
#print(right)

M = []
for i in range(N):
    M.append(gcd(left[i], right[i]))
#print(M)

print(max(M))
### BUGGY CODE ###

from bisect import bisect_left, bisect_right

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

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = bisect_right(L[j+1:], abs(l1-l2))
            e = bisect_left(L[j+1:], l1+l2)

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)

### FIXED CODE ###

from bisect import bisect_left, bisect_right

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

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = max(j+1, bisect_right(L, abs(l1-l2)))
            e = max(j+1, bisect_left(L, l1+l2))

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)
### BUGGY CODE ###

x = int(input())
done=False
for a in range(-8000,8001):
  for b in range(-8000,8001):
    if(not done and a**5-b**5==x):
      print(a,b)
      done=True

### FIXED CODE ###


x = int(input())
for a in range(-300,301):
  if(a<0):
    for b in range(-300,a):
      if(a**5-b**5==x):
        print(a,b)
        break
    else: continue
    break
  else:
    for b in range(-300,a):
      if(a**5-b**5==x):
        print(a,b)
        break
    else: continue
    break
### BUGGY CODE ###

# 難易度 484
# 800~
# 解法805,pi~pjの合計が最大となる区間を求める
# Kの区間が固定されているので0~K-1 -> N-K~N-1を足していイケば良い
# 2~10^5こしかNがないので，せいぜいO(N)で終わるので十分
# 期待値の計算をいちいちしていたら，計算量がもタンクなるかも？最初から計算しておくか

N, K = map(int,input().split())
P = list(map(int,input().split()))
P_MAX = 10**3
E = [0]*(P_MAX+1)
for i in range(1,P_MAX+1):
    E[i] = sum([1/i * j for j in range(1,i+1)])

ans = 0
for i in range(0,N-K+1):
    ans = max(sum([E[l] for l in P[i:i+K]]), ans)
print(ans)




### FIXED CODE ###

# 難易度 484
# 800~
# 解法805,pi~pjの合計が最大となる区間を求める
# Kの区間が固定されているので0~K-1 -> N-K~N-1を足していイケば良い
# 2~10^5こしかNがないので，せいぜいO(N)で終わるので十分
# 期待値の計算をいちいちしていたら，計算量がもタンクなるかも？最初から計算しておくか
# なぜTLEが起こるのかがよくわからない

N, K = map(int,input().split())
P = list(map(int,input().split()))
P_MAX = 10**3
E = [0]*(P_MAX+1)
for i in range(1,P_MAX+1):
    E[i] = sum([1/i * j for j in range(1,i+1)])

ans = 0
for i in range(0,N-K+1):
    if i == 0:
        old = sum([E[l] for l in P[0:0+K]])
        ans = old
        continue
    new = old - E[P[i-1]] + E[P[i+K-1]]
    ans = max(ans,new)
    old = new
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
dics = {}
for i in range(len(a)):
    if a[i] in dics:
        dics[a[i]] = dics[a[i]]  + 1
    else:
        dics.update({a[i]:1})
    
#dics min max
dicsmin = min(list(dics.keys()))
dicsmax = max(list(dics.keys()))

counter = []
for i in range(dicsmin,dicsmax + 1):
    xcount = 0
    x = i
    xcount = a.count(x) + a.count(x-1) + a.count(x + 1)
    counter.append(xcount)

print(max(counter))
        
    

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
aa = []
amax = max(a) + 100


for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 1    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)
### BUGGY CODE ###

from collections import defaultdict

N = int(input())
E = [[] for _ in range(N+1)]
inp = []
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
    inp.append((a, b))


# node: (id, parent_id)
root_node = (1, -1)
open_list = [root_node]
n2c = defaultdict(list)
ans = {}
colors = [-1]*(N-1)
while True:
    if len(open_list)==0:
        break
    cur_node = open_list.pop()
    cur_id, parent_id = cur_node
    adj_id_list = E[cur_id]
    for child_id in adj_id_list:
        if child_id == parent_id:
            continue
        color = 1
        while True:
            if not color in n2c[cur_id]:
                n2c[cur_id].append(color)
                n2c[child_id].append(color)
                ans[(cur_id, child_id)] = color
                break
            color += 1
        open_list.append((child_id, cur_id))

print(max(list(map(lambda x:len(x), n2c.values()))))
for a, b in inp:
    if (a, b) in ans.keys():
        print(ans[(a, b)])
    else:
        print(ans[(b, a)])

### FIXED CODE ###

from collections import defaultdict, deque

N = int(input())
E = [[] for _ in range(N+1)]
edge_order = []
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
    edge_order.append(b)


# node: (id, parent_id)
root_node = (1, -1)
open_list = deque([root_node])
ans = {}
colors = [-1]*(N+1)
while open_list:
    cur_node = open_list.popleft()
    cur_id, parent_id = cur_node
    adj_id_list = E[cur_id]
    c = 1
    for child_id in adj_id_list:
        if child_id == parent_id:
            continue
        if c == colors[cur_id]:
            c += 1
        colors[child_id] = c
        c += 1
        open_list.append((child_id, cur_id))

print(max(colors))
for i in edge_order:
    print(colors[i])
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
hyouten=[0]*(N+5)

for i in range(K+1,N+1):
    for j in range(i-K,i):
        if hyouten[i]==0:
            hyouten[i]=A[j]
        else:
            hyouten[i]*=A[j]
    prevhyouten=hyouten[i]/A[i-1]*A[i-K-1]
    if hyouten[i] > prevhyouten:
        # print(prevhyouten,hyouten[i])
        print("Yes")
    else:
        # print(prevhyouten,hyouten[i])
        print("No")
    


### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(0,N-K):
    if A[i]< A[i+K]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

# coding: utf-8
from math import factorial
def modpow(x, n, mod):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return modpow((x**2) % mod, n // 2, mod)
    else:
        return x * modpow(x, n - 1, mod) % mod
def modcomb(n, r, mod):
    "nCr = X/Yとおく"
    X = factorial(n) % mod
    Y = factorial(n-r) % mod * factorial(r) % mod 
    Y_over = modpow(Y, mod - 2, mod)
    return (X * Y) % mod

N, A, B = map(int, input().split())
mod = 10 ** 9 + 7
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod
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) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
ans = modpow(2, N, mod) - 1
# ans -= modcomb(N, A, mod)
# ans -= modcomb(N, B, mod)
ans %= mod
ans -= cmb(N, A, mod) % mod
ans %= mod
ans -= cmb(N, B, mod) % mod
ans %= mod
print(ans)

### FIXED CODE ###

# coding: utf-8
def modcomb(n, r, mod):
    "nCr = X/Yとおく"
    r = min(r, n - r)
    X, Y = 1, 1
    for i in range(1, r + 1):
        X = X * (n + 1 - i) % mod
        Y = Y * i % mod
    # return ue * modpow(sita, mod-2, mod)
    return X * pow(Y, mod-2, mod) % mod

N, A, B = map(int, input().split())
mod = 10 ** 9 + 7
ans = pow(2, N, mod) - 1
a = modcomb(N, A, mod)
# ans %= mod
b = modcomb(N, B, mod)
ans -= a + b
print(ans % mod)
### BUGGY CODE ###

import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

from decimal import Decimal

def get_primes(n):
	divs = defaultdict(int)
	for i in [2,5]:
		c = 0
		while n % i == 0:
			n = n // i
			c += 1
		if c > 0:
			divs[i] = c
	return divs

L = 10**9
N = ri()
A = []
for i in range(N):
	d = Decimal(rs())
	A.append(int(d*L))
#print(A)

C = [[0, 0] for i in range(N)]
for i, r in enumerate(A):
	ps = get_primes(r)
	C[i] = [min(ps[2], 18), min(ps[5], 18)]
#print(C)

h = defaultdict(int)
ans = 0
for c in C:
	d = [18-c[0], 18-c[1]]
	for i in range(d[0], 19):
		for j in range(d[1], 19):
			if (i, j) in h:
				ans += h[(i,j)] - (c == (i,j))
	h[tuple(c)] += 1

print(ans)


### FIXED CODE ###

import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

from decimal import Decimal

def gcd(a, b):
	return gcd(b, a%b) if b else a

L = 10**9
LL = 10**18
N = ri()
A = []
for i in range(N):
	d = Decimal(rs())
	A.append(int(d*L))

h = defaultdict(int)
for i in range(N):
	g = gcd(A[i], LL)
	h[g] += 1

ans = 0
for g, c in h.items():
	for g2, c2 in h.items():
		if g == g2:
			if g*g % LL == 0:
				ans += c*(c-1)//2
		elif g < g2:
			if g*g2 % LL == 0:
				ans += c * c2
print(ans)
### BUGGY CODE ###

n = int(input())
total = 0
for i in range(n):
    total += i
print(total)

### FIXED CODE ###

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

N = int(input())
A=[]
for j in range(N): 
    A.append([int(i) for i in input().split()])
    
for list in A:
    list.reverse()

day = 0
empty = [0] * N 

#whileループ一回を一日と考える
while N==N:
    #print(A)
    q = []
    day +=1
    for i in range(N):
        #print(A)
        #print(i)
        #i行目が空なら空であることを示すemptyリストを1に
        if len(A[i]) == 0:
            empty[i] = None
        #iが既にqに入っていればパス
        elif i in q:
            pass
        #i行目の末尾の数字で示された相手方が一致していればキューに追加
        elif int(A[int(A[i][-1])-1][-1]) == i+1:
                #print(i, int(A[i][-1]))
                q.append(i)
                q.append(int(A[i][-1])-1)
    #ループ後にqが空ならそれ以上進めないので判定
    if len(q) == 0:
        if not(0 in empty):
            print(day-1)
            exit()
        else:
            print(-1)
            exit()
    #そうでなければキューに追加されている行の末尾を削除する
    else:
        for d in q:
            #print(d)
            A[d].pop(-1)

### FIXED CODE ###

import copy
import collections

N = int(input())
A=[]
for j in range(N): 
    A.append(collections.deque(int(i) for i in input().split()))

day = 0
empty = [0] * N 
s = [i for i in range(N)]

#whileループ一回を一日と考える
while N==N:
    #print(A)
    q = []
    day +=1
    for i in s:
        #print(A)
        #print(i)
        #i行目が空なら空であることを示すemptyリストを1に
        if len(A[i]) == 0:
            empty[i] = None
        #iが既にqに入っていればパス
        elif i in q:
            pass
        #i行目の末尾の数字で示された相手方が一致していればキューに追加
        elif int(A[int(A[i][0])-1][0]) == i+1:
                #print(i, int(A[i][-1]))
                q.append(i)
                q.append(int(A[i][0])-1)
                s = copy.copy(q)
    #ループ後にqが空ならそれ以上進めないので判定
    if len(q) == 0:
        if not(0 in empty):
            print(day-1)
            exit()
        else:
            print(-1)
            exit()
    
    #そうでなければキューに追加されている行の末尾を削除する
    else:
        for d in q:
            #print(d)
            A[d].popleft()
### BUGGY CODE ###

import sys
from collections import deque

v,e,r=map(int, input().split());

e_1=[0]*e;
e_2=[0]*e;
e_w=[0]*e;

for i in range(e):
    e_1[i], e_2[i], e_w[i] = map(int, input().split());

v_q=deque();

INF = 9999999999999999999
d = [INF for i in range(v)]
d[r] = 0
v_q.append((0,r))
while(len(v_q) != 0):
    cost,u = v_q.popleft()
    if(cost > d[u]):
        continue
    for j in range(e):
        if(u == e_1[j]):
            alt = cost+e_w[j]
            if(d[e_2[j]] > alt):
                d[e_2[j]] = alt
                v_q.append((alt,e_2[j]))

for i in range(v):
    if(d[i] != INF):
        print(d[i])
    else:
        print("INF")


### FIXED CODE ###

import sys
from collections import deque

v,e,r=map(int, input().split());

edge_info=[0]*v;
for i in range(v):
    edge_info[i] = []

for i in range(e):
    e1, e2, w = map(int, input().split());
    edge_info[e1].append((e2,w))

v_q=deque();

INF = 9999999999999999999
d = [INF for i in range(v)]
d[r] = 0
v_q.append((0,r))
while(len(v_q) != 0):
    cost,u = v_q.popleft()
    if(cost > d[u]):
        continue
    for j in range(len(edge_info[u])):
        e2,w = edge_info[u][j]
        alt = cost+w
        if(d[e2] > alt):
            d[e2] = alt
            v_q.append((alt,e2))

for i in range(v):
    if(d[i] != INF):
        print(d[i])
    else:
        print("INF")
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(input())

for i in range(N):
  print(max(A[:i] + A[i+1:]))

### FIXED CODE ###

import numpy as np
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)
### BUGGY CODE ###

# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
from time import time

N,M=map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
update_ = []

for _ in range(M):
    temp = list(map(int, input().split()))
    update_.append(temp)

# C_i の値をkeyにしてソートする
update_ = sorted(update_,key = lambda x:x[1], reverse=True)

update = []
for e in update_:
    #print([e[1] for _ in range(e)])
    update.extend([e[1] for _ in range(e[0])])

for i in range(N):
    if i >= len(update):
        break
    if(A[i] > update[i]):
        break
    A[i] = update[i]

print(sum(A))

### FIXED CODE ###

# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
from time import time

N,M=map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
update = []

for _ in range(M):
    temp = list(map(int, input().split()))
    update.append(temp)

# C_i の値をkeyにしてソートする
update = sorted(update,key = lambda x:x[1], reverse=True)

idx = 0
for b, c in update:
    for i in range(b):
        if idx >= N:
            break
        if A[idx] < c:
            A[idx] = c
            idx += 1
        else:
            break

print(sum(A))
### BUGGY CODE ###


N = int(input())
S = input()
count = 0
for i in range(N-1):
  for j in range(i+1, N-1):
    if S[i] != S[j]:
      for k in range(j+1, N):
        if S[i] != S[k] and S[j] != S[k] and j - i != k - j:
          count += 1
print(count)

### FIXED CODE ###

N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)
### BUGGY CODE ###

# B 
a, b, c, d = list(map(int, input().split(" ")))
maxnum = -1000000000
for i in range(b-a+1):
    x = a + i
    for j in range(d-c+1):
        y = c + j
        if x*y > maxnum:
            maxnum = x*y
print(maxnum)

### FIXED CODE ###

# B 
a, b, c, d = list(map(int, input().split(" ")))
numlist = [a*c, a*d, b*c, b*d]
maxnum = max(numlist)
print(maxnum)
### BUGGY CODE ###

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

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
#print(tmp)

answer = 0
for a in A:
  answer = (answer + tmp // a) % MOD
print(answer)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
#print(tmp)

answer = 0
for a in A:
  answer += tmp // a
print(answer % MOD)
### BUGGY CODE ###

N = int(input())
now_next = {}
for i in range(N):
    now_next[i + 1] = int(input())
count = 0
history = [1]
while True:
    light = now_next[history[-1]]
    if light in history:
        print(-1)
        exit()
    count += 1
    if light == 2:
        print(count)
        exit()
    else:
        history.append(light)

### FIXED CODE ###

N = int(input())
next = []
for i in range(N):
    next.append(int(input()))
count = 0
light = 1
for i in range(N):
    light = next[light - 1]
    count += 1
    if light == 2:
        print(count)
        exit()
print(-1)
### BUGGY CODE ###

N = int(input())
ans = 0
tmp = [[] for i in range(N + 1)]
tmp[0] = [0]
chk = []
flag = 0
s = [1]
for i in range(5):
    s.append(9** (i + 1))
for i in range(6):
    s.append(6** (i + 1))
s.sort()

for i in range(1, N + 1):
    t_l = []
    for j in range(len(tmp[i - 1])):
        for k in range(12):
            if tmp[i - 1][j] + s[k] <= N and tmp[i - 1][j] + s[k] not in chk:
                t_l.append(tmp[i - 1][j] + s[k])
    t_l = list(set(t_l))
    tmp[i].extend(t_l)
    chk.extend(t_l)
    if N in tmp[i]:
        break
print(i)

### FIXED CODE ###

N = int(input())
tmp = [-1 for i in range(N + 1)]
tmp[0] = 0
s = [1]

for i in range(5):
    s.append(9** (i + 1))
for i in range(6):
    s.append(6** (i + 1))

for i in range(1, N+1):
    for j in range(N+1):
        if tmp[j] == i - 1:
            for k in range(12):
                a = j + s[k]
                if a <= N and tmp[a] == -1:
                    tmp[a] = i
    if tmp[N] > -1:
        break
print(i)