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

import sys
S = list(input())

if len(S) == 1:
  print(0)
  sys.exit()

cnt = 0
while True:
  o = True
  i=0
  while i < len(S)-1:
    s=S[i]
    if s != S[i+1]:
      S.pop(i)
      S.pop(i)
      o = False
      cnt += 2
      break
    i+=1
  if o:
    break

print(cnt)

### FIXED CODE ###

S = input()
print(min(S.count('0'), S.count('1'))*2)
### BUGGY CODE ###

H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())

is_white = True
st = []
st.append([False, 0, 0, 0])
min_cnt = 1000

while st:
    is_prev_black, cnt, ph, pw = st.pop()
    
    is_now_black = True
    if s[ph][pw] == ".":
        is_now_black = False

    if not is_prev_black and is_now_black:
        cnt += 1

    if ph == H-1 and pw == W-1:
        min_cnt = min(min_cnt, cnt)

    if ph+1 < H:
        st.append([is_now_black, cnt, ph+1, pw])
    if pw+1 < W:
        st.append([is_now_black, cnt, ph, pw+1])

print(min_cnt)


### FIXED CODE ###

H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())

is_white = True
st = []
st.append([False, H-1, W-1, 0])
dp = [[1000] * W for i in range(H)]

for h in reversed(range(H)):
    for w in reversed(range(W)):
        if h == H-1 and w == W-1:
            if s[h][w] == '#':
                dp[h][w] = 1
            else:
                dp[h][w] = 0
            continue

        if w+1 < W:
            cnt = dp[h][w+1]
            if s[h][w] == '#' and s[h][w+1] == '.':
                cnt += 1
            if cnt < dp[h][w]:
                dp[h][w] = cnt

        if h+1 < H:
            cnt = dp[h+1][w]
            if s[h][w] == '#' and s[h+1][w] == '.':
                cnt += 1
            if cnt < dp[h][w]:
                dp[h][w] = cnt

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

from heapq import heappush, heappop
sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx,sy,0)]
data+=[tuple(map(int,input().split())) for i in range(n)]
data.append((gx,gy,0))
for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=((data[i][0]-data[j][0])**2+(data[i][1]-data[j][1])**2)**0.5-data[i][2]-data[j][2]
        g[i].append((tmp,j))
        g[j].append((tmp,i))

dist=[2828427127 for i in range(len(g))]
dist[0]=0
que=[]
heappush(que,(0,0))
while len(que):
    c,v=heappop(que)
    if dist[v]<c:
        continue
    for x in g[v]:
        tmp=max(x[0],0)+c
        if tmp<dist[x[1]]:
            dist[x[1]]=tmp
            heappush(que,(tmp,x[1]))
print(dist[n+1])


### FIXED CODE ###

from heapq import heappush, heappop
sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx+sy*1j,0)]
for i in range(n):
    a,b,c=map(int,input().split())
    data.append((a+b*1j,c))
data.append((gx+gy*1j,0))

for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=abs(data[i][0]-data[j][0])-data[i][1]-data[j][1]
        g[i].append((tmp,j))
        g[j].append((tmp,i))

dist=[2828427127 for i in range(n+2)]
visited=[False for i in range(n+2)]
dist[0]=0
que=[]
heappush(que,(0,0))

while que:
    c,v=heappop(que)
    if visited[v]:
        continue
    visited[v]=True
    for x in g[v]:
        if visited[x[1]]:
            continue
        tmp=x[0]+c if not x[0]<0 else c
        if tmp<dist[x[1]]:
            dist[x[1]]=tmp
            heappush(que,(tmp,x[1]))
print(dist[n+1])
### BUGGY CODE ###

from sys import stdin
import numpy as np
N = list(map(int, (stdin.readline().strip().split())))[0]
M = list(map(int, (stdin.readline().strip().split())))
M=np.array(M)
c_list=[]
ans=0
for i in range(1,max(M)+1):
    num=np.count_nonzero(M == i)
    c_list.append(num)
    #num = M.count(i)
    ans+=(num*(num-1))//2
for k in range(N):
    num=c_list[M[k]-1]-1
    #num = M.count(M[k])-1
    print(ans-num)

### FIXED CODE ###

from sys import stdin
import numpy as np
N = list(map(int, (stdin.readline().strip().split())))[0]
M = list(map(int, (stdin.readline().strip().split())))
num_list=np.array([0]*(2*10**5+1))
ans=0
for i in M:
    num_list[i-1]+=1
ans=sum(num_list*(num_list-1))//2
for k in range(N):
    num=num_list[M[k]-1]-1
    print(ans-num)
### BUGGY CODE ###

INIT = 0
n, m = map(int, input().split())
a = [INIT for i in range(m)]
for i in range(m):
    a[i] = int(input())

dp = [INIT for i in range(n + 1)]
dp[0] = 1

for i in range(1, n + 1):
    if (i in a):
        dp[i] = 0
    elif (i <= 1):
        dp[i] = dp[i - 1]
    else:
        dp[i] = dp[i - 1] + dp[i - 2]

print(dp[n] % 1000000007)


### FIXED CODE ###

INIT = 1
n, m = map(int, input().split())
dp = [INIT for i in range(n + 1)]

for i in range(m):
    a = int(input())
    dp[a] = 0

for i in range(2, n + 1):
    dp[i] = (dp[i - 1] + dp[i - 2]) * dp[i]

print(dp[n] % 1000000007)
### BUGGY CODE ###

N = int(input())
gachalist = []
for i in range(N):
    item = input()
    if item in gachalist:
        continue
    else:
        gachalist.append(item)
print(len(gachalist))

### FIXED CODE ###

N = int(input())
gachalist=[]
for i in range(N):
    gachalist.append(input())
print(len(set(gachalist)))
### BUGGY CODE ###

from collections import defaultdict
import sys

n = int(input())
orders = [[x - 1 for x in list(map(int, input().split()))] for _ in range(n)]

d = defaultdict(list)
e = defaultdict(list)

for i in range(n):
	for j in range(n - 2):
		a1, a2 = min(i, orders[i][j]), max(i, orders[i][j])
		b1, b2 = min(i, orders[i][j + 1]), max(i, orders[i][j + 1])
		d[(a1, a2)].append((b1, b2))
		e[(b1, b2)].append((a1, a2))

visited = [[0 for _ in range(n)] for _ in range(n)]
cnt_dict = defaultdict(int)

ans = []
def visit(cur):
	a, b = cur
	if visited[a][b] == -1:
		print(-1)
		sys.exit()
	elif visited[a][b] == 0:
		visited[a][b] = -1
		if e[cur]:
			cnt = max([visit(x) for x in e[cur]])
		else:
			cnt = 0
		visited[a][b] = 1
		ans.append(cur)
		cnt_dict[cur] = max(cnt_dict[cur], cnt + 1)
		return cnt + 1
	else:
		return cnt_dict[cur]

max_cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		if visited[i][j] == 0:
			max_cnt = max(visit((i, j)), max_cnt)
print(max_cnt)

### FIXED CODE ###

from collections import deque

n = int(input())
orders = [deque([x - 1 for x in list(map(int, input().split()))] + [-1]) for _ in range(n)]

nxt = [orders[i].popleft() for i in range(n)]
days = [0 for _ in range(n)]

q = deque([i for i in range(n)])
while q:
	a = q.popleft()
	b = nxt[a]
	if nxt[nxt[a]] == a:
		days[a], days[b] = [max(days[a], days[b]) + 1 for _ in range(2)]
		nxt[a] = orders[a].popleft()
		nxt[b] = orders[b].popleft()
		q.append(a)
		q.append(b)

if sum(nxt) == -n:
	print(max(days))
else:
	print(-1)
### BUGGY CODE ###

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

# リーダーより西にいる人のうち西を向いている人数+リーダーより東にいる人のうち東を向いている人数 を調べる
n_turn_list = []
for i in range(N):
    n_turn_list.append(S[:i].count("W") + S[i+1:].count("E"))

print(min(n_turn_list))

### FIXED CODE ###

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

# 左端からリーダーにしていく
# リーダーを1つ右隣に移すとき、振り向く合計人数は、リーダーと右隣の人の向きが(W,W)なら+1、(E,E)なら-1、(E,W)or(W,E)なら変化なし
n_turn_list = [S[1:].count("E")] # 左端リーダーのときに振り向く人数

for leader_position in range(N-1): # 右端の1つ左まで
    if S[leader_position+1] == "W" and S[leader_position] == "W":
        n_turn_list.append(n_turn_list[leader_position]+1)
    elif S[leader_position+1] == "E" and S[leader_position] == "E":
        n_turn_list.append(n_turn_list[leader_position]-1)
    else:
        n_turn_list.append(n_turn_list[leader_position])

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

#create date: 2020-05-02 21:28

import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, q = na()
    l = list()
    for i in range(q):
        l.append(na())
    ans = 0
    for switch in product(range(1, m+1), repeat=n):
        switch = list(switch)
        switch.sort()
        s = switch
        cnt = 0
        for a, b, c, d in l:
            a -= 1
            b -= 1
            if s[b] - s[a] ==c:
                cnt += d
        ans = max(cnt, ans)
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

#create date: 2020-06-30 14:42

import sys
stdin = sys.stdin
from itertools import combinations_with_replacement

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, q = na()
    matrix = list()
    for i in range(q):
        matrix.append(na())
    l = list(combinations_with_replacement(range(1, m+1), n))
    ans = 0
    for li in l:
        res = 0
        for q in matrix:
            a, b, c, d = q
            if li[b-1] - li[a-1] == c:
                res += d
        ans = max(ans, res)
    print(ans)

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

import sys

def longestcommonsubsequence(seq1, seq2):
    a,b = len(seq1)+1, len(seq2)+1
    length = [[0 for i in range(b)] for j in range(a)]

    for i in range(a):
        e1=seq1[i-1]
        for j in range(b):
            if i==0 or j==0:
                length[i][j]=0
            else:
                if e1 == seq2[j-1]:
                    length[i][j] = length[i-1][j-1] + 1
                else:
                    length[i][j] = max(length[i-1][j], length[i][j-1])
    return length[a-1][b-1]

n = input()
for i2 in range(n):
    seq1 = raw_input()
    seq2 = raw_input()

    print longestcommonsubsequence(seq1, seq2)

### FIXED CODE ###

import sys

def longestcommonsubsequence():
    seq1 = raw_input()
    seq2 = raw_input()

    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        #x1 = [0 for i2 in range(b+1)]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1]<x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]

n = input()
for i2 in range(n):

    print longestcommonsubsequence()
### BUGGY CODE ###

import numpy as np

MOD = 10**9 + 7
def solve(n, a, p=64):
    s = np.zeros(p, dtype=int)
    t = np.zeros(p, dtype=int)
    a = a[::-1]
    for i in range(n):
        mask = bin(a[i])[2:].zfill(p)[::-1]
        mask = np.asarray(list(map(int, mask)), dtype=int)
        s += mask
        for j in range(p):
            if mask[j] == 1:
                t[j] += i - s[j] + 1
            else:
                t[j] += s[j]
    res = 0
    for j in range(p):
        res += int(t[j]) * (2**j)
    return res % MOD

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

### FIXED CODE ###

MOD = 10**9 + 7
def solve(n, a, p=60):
    res, m = 0, 1
    for i in range(p):
        y = sum(x & m for x in a) // m
        res += y * (n-y) * m
        m *= 2
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
### BUGGY CODE ###

import collections

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

answer = []
for i in range(n):
  answer.append(a.count(i+1))


for j in range(n):
  print(answer[j])

### FIXED CODE ###

import collections
import numpy as np

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

answer = np.zeros(n ,dtype=int)
for number in l:
  answer[number-1] += 1


for j in range(n):
  c = round(answer[j])
  print(c)
### BUGGY CODE ###

s = list(input())
ans = 0
while True:
    for i in range(len(s)-1):
        if s[i]+s[i+1]=='BW':
            s[i], s[i+1] = s[i+1], s[i]
            ans += 1
            break
    else: break
    continue
print(ans)

### FIXED CODE ###

s = input()
b = 0
ans = 0
for i in s:
    if i=='B':
        b += 1
    else:
        ans += b
print(ans)
### BUGGY CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline


def dijkstra(edges, size, source):
    distance = [float('inf')] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance


N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    u, v = map(int, input().split())
    G[u].append(v)
S, T = map(int, input().split())
G2 = [[] for _ in range(N+1)]

for i in range(1, N+1):
    stack = []
    stack.append((i, 0))
    while stack:
        v, d = stack.pop()
        if d == 3:
            G2[i].append((v, 1))
        if d < 3:
            for u in G[v]:
                stack.append((u, d+1))

dist = dijkstra(G2, N+1, S)
print(dist[T] if dist[T] != float('inf') else -1)


### FIXED CODE ###

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

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    u, v = map(int, input().split())
    G[u].append(v)
S, T = map(int, input().split())
queue = deque()
queue.append((S, 0))
visited = [[False] * 3 for _ in range(N+1)]
while queue:
    u, d = queue.popleft()
    if visited[u][d % 3]:
        continue
    visited[u][d % 3] = True
    if d % 3 == 0 and u == T:
        print(d // 3)
        exit()
    for v in G[u]:
        queue.append((v, d+1))
print(-1)
### BUGGY CODE ###

k, s = map(int, input().split())

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                cnt += 1
print(cnt)

### FIXED CODE ###

k, s = map(int, input().split())

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - x - y <= k:
            cnt += 1
print(cnt)
### BUGGY CODE ###

import sys

N,M,K=list(map(int,input().split()))

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        
for i in range(N+1):
    can_update = 1
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            if can_update == 1:
                imax_b = j
                can_update = 0

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)
                break

print(nmax)

### FIXED CODE ###

import sys

N,M,K=list(map(int,input().split()))

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            imax_b = j

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)

            break

print(nmax)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
import fractions
X = A[0]
for i in range(1, N):
    X = X // fractions.gcd(X, A[i]) * A[i]

output = 0
for i in range(N):
    output += X*pow(A[i],10**9+5,10**9+7)%(10**9+7)
    output = output % (10**9+7)
print(output)

### FIXED CODE ###

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

import fractions

X = A[0]
for i in range(1, N):
    X = X*A[i] // fractions.gcd(X, A[i])

output = 0
D =10**9+7
X = X%D

for i in range(N):
    output += X*pow(A[i],D-2,D)%D
    output = output % (10**9+7)
print(int(output))
### BUGGY CODE ###

N = int(input())
list = list(map(int, input().split()))
no = 0
ans = 1
for i in range(N):
  ans = ans * list[no]
  no += 1
print(ans if ans <= 10**18 else "-1")

### FIXED CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    if 0 in A:
        print(0)
        exit()
    for i in A:
        ans *= i
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)
resolve()
### BUGGY CODE ###

n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**30
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)

### FIXED CODE ###

n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**20
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)
### BUGGY CODE ###

N, M = map(int, input().split())
mae = 0
sub = []
flag = False

for _ in range(M):
  broken = int(input())
  if mae == broken: # 不可能
    flag = True
  if flag:
    continue
  if mae+1 == broken:
    mae = broken + 1
    continue
  sub.append(broken-1-mae)
  mae = broken + 1
# 無理な時
if flag:
  print(0)
  exit()
# forの中で最後まで行ってない分の追加
if mae != N:
  sub.append(N-mae)

from operator import mul
from functools import reduce

# nCrの関数
def C(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
# 壊れてるやつの間の上り方の場合の数
def count(n):
  ans = 1
  for i in range(n//2):
    ans += C(n-i-1, i+1)
  return ans

ans = 1
for s in sub:
  ans *= count(s)
print(ans%(10**9+7))

### FIXED CODE ###

N, M = map(int, input().split())
A = [True]*N
for _ in range(M):
  a = int(input())
  A[a-1] = False # 壊れてるところはfalse

waru = 10**9 + 7
dp = [0]*(N+1)

dp[0], dp[1] = 1, 1 # 初期条件
if not A[0]: # 1段目が壊れてたら
  dp[1] = 0

for i in range(2,N+1):
  # 壊れてるところはdp=0にする
  if not A[i-1]:
    dp[i] = 0
  else:
    dp[i] = (dp[i-1] + dp[i-2])%waru
print(dp[-1])
### BUGGY CODE ###

N= int(input())
s = []

for _ in range(N):
    s.append(input())
s

for i in range(N):
    s[i] = sorted(s[i])

counter = 0
for i in range(N):
    for j in range((i+1), N):
        if s[i] == s[j]:
            counter += 1

print(counter)  

### FIXED CODE ###

N= int(input())
s = []

for _ in range(N):
    s.append(input())

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

import collections
c = collections.Counter(s)
d = [i for i in c.values()]

counter = 0
from math import factorial
for i in d:
    if i > 1:
        counter += i*(i-1)/2

print(int(counter))
### BUGGY CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    S = list(map(int, readline().split()))
    T = list(map(int, readline().split()))

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N + 1):
        dp[i][0] = 1
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD
            if S[i] == T[j]:
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD

    print(dp[N][M])
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    S = list(map(int, readline().split()))
    T = list(map(int, readline().split()))

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N + 1):
        dp[i][0] = 1
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD
            if S[i] == T[j]:
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD

    print(dp[N][M])
    return


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

from math import gcd

# def GCD(a,N):
#     gcd = a[0]
#     for i in range(1, N):
#         gcd = math.gcd(gcd, a[i])
#     return gcd


k = int(input())

ans = 0
L = []
G = [0] * k**3

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            # _l = sorted([i,j,l])
            # if i==1 or j == 1 or l == 1:
            #     ans += 1
            # elif not _l in L:
            #     L.append(_l)
            #     g = GCD(_l, 3)
            #     G[L.index(_l)] = g
            #     ans += g
            # else:
            #     ans += G[L.index(_l)]
            ans += gcd(i,gcd(j,l))

print(ans)

### FIXED CODE ###

from math import gcd

# def GCD(a,N):
#     gcd = a[0]
#     for i in range(1, N):
#         gcd = math.gcd(gcd, a[i])
#     return gcd


k = int(input())

ans = 0
L = []
G = [0] * k**3

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            # _l = sorted([i,j,l])
            # if i==1 or j == 1 or l == 1:
            #     ans += 1
            # elif not _l in L:
            #     L.append(_l)
            #     g = GCD(_l, 3)
            #     G[L.index(_l)] = g
            #     ans += g
            # else:
            #     ans += G[L.index(_l)]
            ans += gcd(i,gcd(j,l))

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

n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
b=[]
c=[]
for i in range(0, m):
    ib,ic = map(int, input().split(" "))
    b.append(ib)
    c.append(ic)
for i in range(0, m):
    ax = list(map(lambda x: x if c[i] < x else c[i], a[0:b[i]]))
    a[0:b[i]] = ax
    a.sort()
print(sum(a))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))
### BUGGY CODE ###

x = int(input())

def func():
    for a in range(-10**2, 10**2):
        for b in range(-10**2, 10**2):
            if a**5 - b**5 == x:
                k = [a, b]
                return k
    for a in range(10**5, 10**2, -1):
        for b in range(10**5, 10**2, -1):
            if a**5 - b**5 == x:
                k = [a, b]
                return k
    

k = func()
for i in range(2):
    print(k[i], end=" ")

### FIXED CODE ###

x = int(input())

def func():
    for a in range(-10**2 - 200, 10**2 + 200):
        for b in range(-10**2 - 200, 10**2 + 200):
            if a**5 - b**5 == x:
                k = [a, b]
                return k
    

k = func()
for i in range(2):
    print(k[i], end=" ")
### BUGGY CODE ###

n,w = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(n)]
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j >= L[i][0]:
            dp[i+1][j] = max(dp[i][j-L[i][0]]+L[i][1],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[n][w])

### FIXED CODE ###

n,w = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(n)]
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j >= L[i][0]:
            dp[i+1][j] = max(dp[i][j-L[i][0]]+L[i][1],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[n][w])