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

#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")


def solve(D: int, G: int, p: "List[int]", c: "List[int]"):

    scores = []
    for i, (pp, cc) in enumerate(zip(p, c)):
        s = [100*(i+1)]*pp
        s[-1] += cc
        scores.append(s)

    m = INF
    for l in itertools.permutations(range(D), D):
        junjo = []
        for ll in l:
            junjo.extend(scores[ll][:])
        s = 0
        for i, ju in enumerate(junjo):
            s += ju
            if s >= G:
                break
        # print(l, i+1, junjo)
        m = min(m, i+1)
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  # type: int
    G = int(next(tokens))  # type: int
    p = [int()] * (D)  # type: "List[int]"
    c = [int()] * (D)  # type: "List[int]"
    for i in range(D):
        p[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(D, G, p, c)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
import operator
from queue import Queue
INF = float("inf")


def dfs(curr, goal, count, probs):
    if curr >= goal:
        return count

    if len(probs) == 0:
        return INF

    # ラス一問目を解かない
    m1 = dfs(curr, goal, count, probs[:-1])

    # ラス一問目を解ききる
    m2 = dfs(curr+probs[-1][0] * probs[-1][1] + probs[-1][2],
             goal, count+probs[-1][1], probs[:-1])

    # ラス一問目を途中まで解く
    m3 = INF
    s = goal-curr
    if (probs[-1][0] * probs[-1][1]) >= s:
        m3 = count + int(math.ceil(s / probs[-1][0]))

    # print(m1, m2, m3, curr, count, probs)
    return min(m1, m2, m3)


def solve(D: int, G: int, p: "List[int]", c: "List[int]"):

    probs = []
    for i in range(D):
        probs.append([100*(i+1), p[i], c[i]])

    m = dfs(0, G, 0, probs)
    print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  # type: int
    G = int(next(tokens))  # type: int
    p = [int()] * (D)  # type: "List[int]"
    c = [int()] * (D)  # type: "List[int]"
    for i in range(D):
        p[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(D, G, p, c)


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

from collections import deque
n=int(input())
a=[int(input()) for _ in range(n)]
ans=max(a)
for i in range(n):
    print(ans if a[i]!=ans else sorted(a)[-2])

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = [int(input()) for _ in range(n)]
ans=max(a)
if a.count(ans)>1:
    for _ in range(n):
        print(ans)
else:
    for i in range(n):
        print(ans if a[i]!=ans else sorted(a)[-2])
### BUGGY CODE ###

from itertools import combinations_with_replacement

N,K = map(int,input().split())
ans = 0
for cmb in combinations_with_replacement([i for i in range(1,N+1)],3):
  if all([True if a%K ==0 else False for a in [cmb[0]+cmb[1], cmb[1]+cmb[2],cmb[2]+cmb[0]]]):
    set_num = len(set(cmb))
    if set_num == 1: ans += 1
    elif set_num == 2: ans += 3
    elif set_num == 3: ans += 6
  #print(ans, cmb)
print(ans)

### FIXED CODE ###

from itertools import combinations_with_replacement

def calc_cases(num):
  cases = num
  if num == 2: cases += num*(num-1)*3
  elif num >= 3: cases += num*(num-1)*3 + num*(num-1)*(num-2)
  return int(cases)

N,K = map(int,input().split())
num, num2 = 0, 0
if K%2 ==1:
  for i in range(1,N+1):
    if i%K == 0: num +=1
else:
  for i in range(1,N+1):
    if i%K == 0:
      num +=1
    elif i%K == K//2:
      num2 += 1

print(calc_cases(num)+calc_cases(num2))
#print(num, calc_cases(num), num2, calc_cases(num2))
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    MAX_V = 10 ** 18

    ans = 1
    for a in A:
        ans *= a
    if ans > MAX_V:
        ans = -1
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    MAX_V = 10 ** 18

    if A[-1] == 0:
        print(0)
        exit()

    ans = 1
    for a in A:
        ans *= a
        if ans > MAX_V:
            ans = -1
            break
    print(ans)

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

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

n = int(input())
s = input()
cnt = 0
for i in range(1000):
    c = str(i)
    one,two,three = -1,-1,-1
    if len(c)<3:
        while True:
            if len(c) == 3:
                break
            c = "0" + c
    for j in range(n):
        if s[j] == c[0]:
            one = j
            break
    if one != -1:
        for j in range(one+1,n):
            if s[j] == c[1]:
                two = j
                break
    if two != -1:
        for j in range(two+1,n):
            if s[j] == c[2]:
                three = j
                break
    if three != -1:
        cnt+=1
print(cnt)


### FIXED CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

n = int(input())
s = input()
cnt = 0
for i in range(1000):
    c = str(i)
    one,two,three = -1,-1,-1
    if len(c)<3:
        while True:
            if len(c) == 3:
                break
            c = "0" + c
    for j in range(n):
        if s[j] == c[0]:
            one = j
            break
    if one != -1:
        for j in range(one+1,n):
            if s[j] == c[1]:
                two = j
                break
    if two != -1:
        for j in range(two+1,n):
            if s[j] == c[2]:
                three = j
                break
    if three != -1:
        cnt+=1
print(cnt)
### BUGGY CODE ###

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

j = 1
sm = abs(A[1])
while j < N:
        sm += abs(A[j]-A[j+1])
        j += 1
print(sm)

for i in range(1,N):
    j = 0
    sm = abs(A[0])
    while j < N:
        if j+1 == i and j+2 < N+1:
            sm += abs(A[j]-A[j+2])
            j += 2
        else:
            sm += abs(A[j]-A[j+1])
            j += 1
    print(sm)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.append(0)
sm = abs(A[0])
j = 0
while j < N:
        sm += abs(A[j]-A[j+1])
        j += 1

for i in range(N):
    if i == 0:
        print(sm-abs(A[0]-0)
                -abs(A[1]-A[0])
                +abs(A[1]-0))
        continue
    print(sm-abs(A[i]-A[i-1])
            -abs(A[i+1]-A[i])
            +abs(A[i+1]-A[i-1]))
### BUGGY CODE ###

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

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

def lcm(a, b):
    return a * b // gcd(a, b)

l = 1
for ai in a:
    l = lcm(l, ai)

mod = 1000000007
ret = 0
for ai in a:
    ret = (ret + l // ai) % mod
print(ret)


### FIXED CODE ###

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

mod = 1000000007

lcm = {}
ps = []
for i in range(n): 
    ai = a[i]
    p = 2
    ps.append({})
    while p * p <= ai:
        if ai % p == 0:
            ps[i][p] = 0
            while ai % p == 0:
                ps[i][p] += 1
                ai //= p
            lcm[p] = max(lcm.get(p, 0), ps[i][p])
        p += 1
    if ai > 1:
        ps[i][ai] = 1
        lcm[ai] = max(lcm.get(ai, 0), ps[i][ai])

lcmv = 1
for p in lcm:
    lcmv = (lcmv * (p ** lcm[p])) % mod

def inv(p, k):
    k = mod - k - 1
    ret = 1
    b = p
    while k > 0:
        if k % 2 == 1:
            ret = (ret * b) % mod
        b = (b * b) % mod
        k //= 2
    return ret

ret = 0
for i in range(n):
    prod = lcmv
    for p in ps[i]:
        prod = (prod * inv(p, ps[i][p])) % mod
    ret = (ret + prod) % mod

print(ret)
### BUGGY CODE ###

import heapq
n, m = map(int, input().split())
cards = list(map(int, input().split()))
heapq.heapify(cards)
rules = []
for _ in range(m):
    x, y = map(int, input().split())
    rules.append((x, y))
for c, v in rules:
    count = 0
    while count < c:
        p = heapq.heappop(cards)
        if p < v:
            heapq.heappush(cards, v)
            count += 1
        else:
            heapq.heappush(cards, p)
            break
print(sum(cards))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
cards = list(map(int, input().split()))
heapq.heapify(cards)
rules = []
for _ in range(m):
    x, y = map(int, input().split())
    rules.append((x, y))
for c, v in sorted(rules, key=lambda x: x[1], reverse=True):
    count = 0
    while count < c:
        p = heapq.heappop(cards)
        if p < v:
            heapq.heappush(cards, v)
            count += 1
        else:
            heapq.heappush(cards, p)
            break
print(sum(cards))
### BUGGY CODE ###

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

seen = [0]*n

for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1
  
for i in range(n):
  count = 0
  seen[a[i]-1] = seen[a[i]-1] - 1
  for j in range(n):
    if (seen[j] == 0) or (seen[j] == 1):
      continue
    count = count + (seen[j]*(seen[j]-1))//2
    
  print(int(count))
  seen[a[i]-1] = seen[a[i]-1] + 1


### FIXED CODE ###

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

seen = [0]*n
count = 0
for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if (seen[i] == 0) or (seen[i] == 1):
      continue
   count = count +seen[i]*(seen[i]-1)//2

for i in a:
  ans = count - (seen[i-1]*(seen[i-1]-1))//2 + ((seen[i-1]-2)*(seen[i-1]-1))//2
    
  print(int(ans))
### BUGGY CODE ###

N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = []
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.append(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

### FIXED CODE ###

N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)
### BUGGY CODE ###

import itertools
x,y,z,k = list(map(int, input().split())) 
a = sorted(list(map(int, input().split())),reverse=True)
b = sorted(list(map(int, input().split())),reverse=True)
c = sorted(list(map(int, input().split())),reverse=True)

del a[min(k,x):]
del b[min(k,y):]
del c[min(k,z):]

ab = [i + j for (i, j) in list(itertools.product(a, b))]

ab.sort(reverse=True)
del ab[min(k,x*y):]

abc = [ij + h for (ij, h) in list(itertools.product(ab, c))]

abc.sort(reverse=True)

for g in range(k):
  print(abc[g])

### FIXED CODE ###

import heapq
x,y,z,k = list(map(int, input().split())) 
a = sorted(list(map(int, input().split())),reverse=True)
b = sorted(list(map(int, input().split())),reverse=True)
c = sorted(list(map(int, input().split())),reverse=True)

ans = []
log = set()

total = (a[0] + b[0] + c[0]) * (-1)
heapq.heappush(ans, (total, 0, 0, 0))
log.add((0, 0, 0))

for i in range(k):
  (total, aa, bb, cc) = heapq.heappop(ans)
  print(total * (-1))
  if (aa+1, bb, cc) not in log:
    if aa+1 < x:
      total = (a[aa+1] + b[bb] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa+1, bb, cc))
      log.add((aa+1, bb, cc))
  if (aa, bb+1, cc) not in log:
    if bb+1 < y:
      total = (a[aa] + b[bb+1] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa, bb+1, cc))
      log.add((aa, bb+1, cc))
  if (aa, bb, cc+1) not in log:
    if cc+1 < z:
      total = (a[aa] + b[bb] + c[cc+1]) * (-1)
      heapq.heappush(ans, (total, aa, bb, cc+1))
      log.add((aa, bb, cc+1))
### BUGGY CODE ###

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

allsum = 0
for i in range(n-1):
    allsum += a[i] * sum(a[i+1:])
print(allsum % (10**9+7))


### FIXED CODE ###

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

"""
allsum = 0
for i in range(n-1):
    allsum += a[i] * sum(a[i+1:])
print(allsum % (10**9+7))
"""
s, s2 = 0, 0
for i in range(n):
    s += a[i]
    s2 += a[i] * a[i]
print(((s*s - s2)//2) % (10**9+7))
### BUGGY CODE ###

s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
ans = ''
while(dp[n][m]>0):
  if dp[n][m] == dp[n-1][m-1] +1 and dp[n][m] == dp[n-1][m] +1 and dp[n][m] == dp[n][m-1] +1:
    ans += s[n-1]
    n -= 1
    m -= 1
  elif dp[n-1][m] > dp[n][m-1]:
    n -= 1
  else:
    m -= 1
print(''.join(reversed(list(ans))))

### FIXED CODE ###

s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
ans = ''
while(dp[n][m]>0):
  if dp[n][m] == dp[n-1][m-1] +1 and dp[n][m] == dp[n-1][m] +1 and dp[n][m] == dp[n][m-1] +1:
    ans = ''.join([s[n-1],ans])
    n -= 1
    m -= 1
  elif dp[n-1][m] > dp[n][m-1]:
    n -= 1
  else:
    m -= 1
print(ans)
### BUGGY CODE ###

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] > tmax:
        tmax = t[i]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
rokuga = 0
for Si, Ti, Ci in zip(s,t,c):
    for j in range(2*Si-1, 2*Ti+1):
        c_timeline[j][Ci-1] = 1
        time = sum(c_timeline[j])
        if rokuga < time:
            rokuga = time

print(rokuga)


### FIXED CODE ###

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)
### BUGGY CODE ###


import bisect

N = int(input())

Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
Ci = list(map(int,input().split()))

Bi.sort()
Ci.sort()

ans = 0

for i in range(len(Ai)):
    #Ai[i]より大きいものの絞り込み (以上ならleft、より大きいならright)
    bi = bisect.bisect_right(Bi,Ai[i])
    #Biのどの値もAi[i]より大きくないなら無理
    if bi >= len(Bi):
        continue
    #Bi[bi]以降がiよりも大きい(中部として使える)
    for j in range(bi,len(Bi)):
        #Bi[bi]以降が中部として使えるので次は下部として使える範囲を絞り込む
        ci = bisect.bisect_right(Ci,Bi[j])
        #Ciのどの値もBi[i]より大きくないなら無理
        if ci >= len(Ci):
            continue
        #Ci[ci]以降が下部として使える
        ans += len(Ci) - ci

print(ans)


### FIXED CODE ###


import bisect

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
C.sort()

ans = 0

#中央を固定する
for bi in B:
    #biより小さいものをAから絞り込む
    ai = bisect.bisect_left(A,bi)
    #biより大きいものをCから絞り込む
    ci = len(C) - bisect.bisect_right(C,bi)

    ans += ai * ci

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

# Problem D - Xor Sum 4

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
ans = 0
MOD = 10**9 + 7

# count
for i in range(60):
    tmp_count = 0
    one_count = 0
    zero_count = 0
    for a in a_nums:
        if (a>>i)&1==1:
            one_count += 1
        else:
            zero_count += 1
    tmp_count = one_count * zero_count
    ans += (tmp_count * (2**i))%MOD

# output
print(ans%MOD)


### FIXED CODE ###

# Problem D - Xor Sum 4

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
ans = 0
MOD = 10**9 + 7

# count
two_factor = 1
for i in range(60):
    tmp_count = 0
    one_count = 0
    zero_count = 0
    for j in range(N):
        if (a_nums[j]>>i)&1==1:
            one_count += 1
        else:
            zero_count += 1
    tmp_count = (one_count * zero_count)%MOD
    ans += (tmp_count * two_factor)%MOD
    two_factor = (two_factor * 2)%MOD

# output
print(ans%MOD)
### BUGGY CODE ###

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

answer = 0
mod = 1000000007
for i in range(N-1):
  total = sum(A[i+1:])
  multi = ((A[i] % mod) * (total % mod)) % mod
  answer = (answer + multi) % mod
print(str(answer))

### FIXED CODE ###

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

answer = 0
a_sum = sum(A)
mod = 10**9+7

for i in range(N-1):
  a_sum -= A[i]
  answer += a_sum * A[i]
print(str(answer % mod))
### BUGGY CODE ###

import sys
s = sys.stdin.readlines()
N = int(s[0])
S = s[1]
Q = int(s[2])


seg = [set([]) for _ in range(2*N-1)]
def update(k, x):
    k += N-1
    seg[k] = set([x])
    while k:
        k = (k-1)//2
        seg[k] = seg[2*k+1] | seg[2*k+2]
        
def query(p, q):
    p += N-1
    q += N-2
    res = set([])
    while q-p > 1:
        if p&1 == 0:
            res = res | seg[p]
        if q&1 == 1:
            res = res | seg[q]
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res |= seg[q]
    else:
        res |= seg[p] | seg[q]
    return len(res)

for i in range(N):
    update(i, S[i])
    
for e in s[3:]:
    a,b,c = map(str, e.split())
    if a == "1":
        update(int(b)-1, c)
    else:
        print(query(int(b)-1, int(c)))

### FIXED CODE ###

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

seg = [0]*(2*N-1)

def update(k, x):
    k += N-1
    seg[k] = 2**x
    while k:
        k = (k-1)//2
        seg[k] = seg[2*k+1] | seg[2*k+2]
        
def query(p, q):
    p += N-1
    q += N-2
    res = 0
    while q-p > 1:
        if p&1 == 0:
            res = res | seg[p]
        if q&1 == 1:
            res = res | seg[q]
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res |= seg[q]
    else:
        res |= seg[p] | seg[q]
    return bin(res).count("1")

def f(s):
    return ord(s) - ord("a") + 1

for i in range(N):
    update(i, f(S[i]))
    
Q = int(input())
for _ in range(Q):
    a,b,c = map(str, input().split())
    if a == "1":
        update(int(b)-1, f(c))
    else:
        print(query(int(b)-1, int(c)))
### BUGGY CODE ###

from itertools import accumulate, combinations

n, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))

btfl =[]
for i in range(0, n):
    for j in range(i + 1, n + 1):
        btfl.append(a[j] - a[i])

ans = 0
for l in combinations(btfl, k):
    cnt = l[0]
    for i in l:
        cnt &= i
    ans = max(ans, cnt)
print(ans)


### FIXED CODE ###

from itertools import accumulate
n, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))

btfl = []
for i in range(0, n):
    for j in range(i + 1, n + 1):
        btfl.append(a[j] - a[i])

# 解説AC
ans = 0
for i in range(50)[::-1]:
    num, cnt = ans + pow(2, i), 0
    for b in btfl:
        if num == num & b:
            cnt += 1
    if cnt >= k:
        ans = num
print(ans)
### BUGGY CODE ###

from itertools import accumulate,combinations
n,k = map(int,input().split())
a = list(map(int,input().split()))
acc = [0]+list(accumulate(a))
ls = []
for i,j in combinations(acc,2):
  ls.append(j-i)
x = max(ls).bit_length()
ans = 0
for i in range(x-1,-1,-1):
  cnt = 0
  for j in ls:
    if ans+2**i & j == ans+2**i:
      cnt += 1
  if cnt >= k:
    ans += 2**i
print(ans)

### FIXED CODE ###

from itertools import accumulate,combinations
n,k = map(int,input().split())
a = list(map(int,input().split()))
acc = [0]+list(accumulate(a))
ls = []
for i,j in combinations(acc,2):
  ls.append(j-i)
x = max(ls).bit_length()
ans = 0
for i in range(x-1,-1,-1):
  cnt = 0
  for j in ls:
    if ans+2**i & j == ans+2**i:
      cnt += 1
  if cnt >= k:
    ans += 2**i
print(ans)
### BUGGY CODE ###

import fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.gcd, numbers)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += gcd([i,j,k])

print(ans)

### FIXED CODE ###

import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += gcd([i,j,k])

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

from copy import deepcopy
from collections import deque

# 最短にする
# 0回以上でたどり着けるのでスタート=ゴールのことがある ふざけんな
h, w = map(int, input().split())
table = [[] for _ in range(h)]
for i in range(h):
    table[i] = list(input())


def bfs(y, x, t):
    steps = [0, 1, 0, -1, 0]
    queue = deque([[y, x]])
    arr = []
    while len(queue) > 0:
        cur_y, cur_x = queue.popleft()
        for i in range(4):
            next_y, next_x = cur_y + steps[i], cur_x + steps[i + 1]
            if 0 <= next_y < h and 0 <= next_x < w:
                if t[next_y][next_x] == "G":
                    arr.append(t[cur_y][cur_x])
                    continue
                if t[next_y][next_x] == ".":
                    t[next_y][next_x] = t[cur_y][cur_x] + 1
                    queue.append([next_y, next_x])

    return 0 if len(arr) == 0 else min(arr) + 1


ans = 0
for sy in range(h):
    for sx in range(w):
        # table[sy][sx]をスタート地点とする
        if table[sy][sx] != ".":
            continue
        for gy in range(h):
            for gx in range(w):
                if sy == gy and sx == gx:
                    continue
                if table[gy][gx] == ".":
                    mytable = deepcopy(table)
                    mytable[sy][sx] = 0
                    mytable[gy][gx] = "G"
                    # ans = min(ans, bfs(sy, sx, mytable))
                    ret = bfs(sy, sx, mytable)
                    ans = max(ans, ret)

print(ans)


### FIXED CODE ###

from copy import deepcopy
from collections import deque

# 最短にする
# 0回以上でたどり着けるのでスタート=ゴールのことがある ふざけんな
h, w = map(int, input().split())
table = [[] for _ in range(h)]
for i in range(h):
    table[i] = list(input())


def bfs(y, x, t):
    steps = [0, 1, 0, -1, 0]
    queue = deque([[y, x]])
    ret = 0
    while len(queue) > 0:
        cur_y, cur_x = queue.popleft()
        for i in range(4):
            next_y, next_x = cur_y + steps[i], cur_x + steps[i + 1]
            if 0 <= next_y < h and 0 <= next_x < w:
                if t[next_y][next_x] == ".":
                    t[next_y][next_x] = t[cur_y][cur_x] + 1
                    ret = max(ret, t[next_y][next_x])
                    queue.append([next_y, next_x])

    return ret


ans = 0
for sy in range(h):
    for sx in range(w):
        # table[sy][sx]をスタート地点とする
        if table[sy][sx] != ".":
            continue
        mytable = deepcopy(table)
        mytable[sy][sx] = 0
        ret = bfs(sy, sx, mytable)
        ans = max(ans, ret)

print(ans)