Harryxun/stf_run huggingface dataset:
def main():
    n, k = [int(i) for i in input().split()]
    s = [int(i) for i in list(input())]
    table = []
    now = 1
    cnt = 0
    for i in range(n):
        if s[i] == now:
            cnt += 1
        else:
            table.append(cnt)
            cnt = 1
            now ^= 1 # 0　と 1 の切り替え
    if cnt != 0:
        table.append(cnt)
    if len(table)%2 == 0:
        # 奇数で終わらせれば、1 で終わったことになる
        table.append(0)
    ans = 0
    l = 0
    d = min(len(table), 2*k+1)
    r = l + d
    tmp = sum(table[l:r])
    while r <= len(table):
        ans = max(ans, tmp)
        if l < len(table):
            tmp -= table[l]
        l += 1
        if l < len(table):
            tmp -= table[l]
        l += 1
        r += 1
        if r <= len(table):
            tmp += table[r-1]
        r += 1
        if r <= len(table):
            tmp += table[r-1]
    print(ans)


if __name__ == '__main__':

### FIXED CODE ###

def main():
    n, k = [int(i) for i in input().split()]
    s = [int(i) for i in list(input())]
    table = []
    now = 1
    cnt = 0
    for i in range(n):
        if s[i] == now:
            cnt += 1
        else:
            table.append(cnt)
            cnt = 1
            now ^= 1 # 0　と 1 の切り替え
    if cnt != 0:
        table.append(cnt)
    if len(table)%2 == 0:
        # 奇数で終わらせれば、1 で終わったことになる
        table.append(0)
    ans = 0
    l = 0
    d = min(len(table), 2*k+1)
    r = l + d
    tmp = sum(table[l:r])
    while r <= len(table):
        ans = max(ans, tmp)
        if l < len(table):
            tmp -= table[l]
        l += 1
        if l < len(table):
            tmp -= table[l]
        l += 1
        r += 1
        if r <= len(table):
            tmp += table[r-1]
        r += 1
        if r <= len(table):
            tmp += table[r-1]
    print(ans)


if __name__ == '__main__':
    main()
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
flag = True
print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            f += i[1]
        elif (flag=True and i[1]=="2") or (flag==False and i[1]=="1":
            l += i[1]
S = f+S+l
if flag:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
from collections import deque 
flag = True
f = ""
l = ""
#print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            f += i[2] 
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            l += i[2]
S = f[::-1]+S+l
if flag:
    print(S)
else:
    print(S[::-1])
import numpy as np
 
mod = 10**9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    n_1 = np.count_nonzero((A >> n)&1)   
    n_0 = N - num_1                       
    ans += ((2 ** n)*n_1*n_0) % mod

print(ans%mod)

### FIXED CODE ###

import numpy as np
 
data = int(input())
array = np.fromiter(map(int, input().split()), np.int64)
 
result = 0
for bit in range(60):
    array01 = int((array & 1).sum())
    result = (result + array01 * (data - array01) * (1 << bit)) % 1000000007
    array >>= 1
print(result)
from collections import deque
from bisect import bisect_left

def dfs(v, p=-1):
    a = A[v]
    idx = bisect_left(LIS, a)
    old_val = LIS[idx]
    LIS[idx] = a

    ans[v] = bisect_left(LIS, INF)

    for u in G[v]:
        if u == p:
            continue
        dfs(u, v)
    
    LIS[idx] = old_val

INF = 10**9 + 1
N = int(input())
A = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(N-1):
    u, v = list(map(int, input().split()))
    G[u-1].append(v-1)
    G[v-1].append(u-1)

LIS = [INF] * N
ans = [0] * N

dfs(0)

print(*ans, sep='\n')

### FIXED CODE ###

from collections import deque
from bisect import bisect_left

INF = 10**9 + 1
N = int(input())
A = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(N-1):
    u, v = list(map(int, input().split()))
    G[u-1].append(v-1)
    G[v-1].append(u-1)

LIS = [INF] * N
ans = [0] * N

stack = deque()
stack.append((0, None, None)) # (current_node, prev_node, old_val)
while stack:
    c_node, p_node, old_val = stack.pop()

    if c_node == -1:
        LIS[p_node] = old_val
        continue

    a = A[c_node]
    idx = bisect_left(LIS, a)
    old_val = LIS[idx]
    LIS[idx] = a 
    
    ans[c_node] = bisect_left(LIS, INF)

    stack.append((-1, idx, old_val))

    for next_node in G[c_node]:
        if next_node != p_node:
            stack.append((next_node, c_node, old_val))

print(*ans, sep="\n")
import sys

line = sys.stdin.readline()

tate, yoko = line.split(" ")

S = tate * yoko
T = 2 * (tate + yoko)

print S, " ", T

### FIXED CODE ###

import sys

line = sys.stdin.readline()

tate, yoko = line.split(" ")

tate = int(tate)
yoko = int(yoko)

S = tate * yoko
T = 2 * (tate + yoko)

print '%d %d' % (S, T)
N = int(input())
X = input()
S = len(str(X))

k = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2] #17まで

c = 0
for i in range(S):
    if X[i] == "1":
        c += 1

for i in range(S):
    if X[i] == "1":
        waru = c-1
    else:
        waru = c+1
    #print(waru)
    atai = 0
    for j in range(S):
        if i != j:
            atai += 2**(S-1-j)*int(X[j])
        else:
            atai += 2**(S-1-j)* ((int(X[j])+1)%2)

    nex = atai % waru
    print(1+k[nex])

### FIXED CODE ###

N = int(input())
X = input()

def popcnt1(n):
    return bin(n).count("1")

k = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2,1] #18まで

c = 0
for i in range(N):
    if X[i] == "1":
        c += 1

m1 = 0
p1 = 0

for i in range(N):
    if c != 1:
        if X[i] == "1":
            m1 += pow(2,N-1-i,c-1)
            m1 %= c-1
            p1 += pow(2,N-1-i,c+1)
            p1 %= c+1
    else:
        if X[i] == "1":
            p1 += pow(2,N-1-i,c+1)
            p1 %= c+1

for i in range(N):
    if c != 1: 
        if X[i] == "0":
            B2 = p1 + pow(2,N-1-i,c+1)
            B2 %= c+1
        else:
            B2 = m1 - pow(2,N-1-i,c-1)
            B2 %= c-1
    else:
        if X[i] == "0":
            B2 = p1 + pow(2,N-1-i,c+1)
            B2 %= c+1
        else:
            print(0)
            continue

    S = len(bin(B2))
    c2 = popcnt1(B2)

    if c2 == 0:
        print(1)
    else:
        print(2+k[B2%c2])
S = input()
cntb = 1000000 if if S[0] == "B" and S[-1] == "B" else 0
cntw = 1000000 if S[0] == "W" and S[-1] == "W" else 0
for s in S.split("B"):
  if s != "":
    cntb += 1
for s in S.split("W"):
  if s != "":
    cntw += 1
print(min(cntb, cntw))

### FIXED CODE ###

from sys import exit
S = input()
#0回判定
x = len(S)
if S.count("B") == x or S.count("W") == x:
    print(0)
    exit()



cntw=0
for s in S.split("W"):
    if s:
        cntw += 1
cntb=0
for s in S.split("B"):
    if s:
        cntb += 1
print(abs(cntb - cntw) + min(cntb, cntw) * 2 - 1)
hoge = [0] + ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(1, 10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx = 0
    for i in range(1, n+1):
        if hoge[i] == input():
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
    print(*sorted(list(set(man))))

### FIXED CODE ###

hoge = ["FizzBuzz" if i % 15 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = list(range(1, m+1))
    game = [input() for _ in range(n)]
    idx = 0
    for i in range(n):
        if game[i] != hoge[i+1]:
            del man[idx]
            if len(man) == 1:
                break
        else:
            idx += 1
        idx %= len(man)
    print(*man)
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())

class Node():
    def __init__(self):
        self.parent = -1
        self.children = []
        self.depth = -1
        self.count = 0

def dfs(G, v=0, d=0):
    G[v].depth = d
    for child in G[v].children:
        dfs(G, child, d+1)

def add_count(G, v, x):
    G[v].count += x
    for child in G[v].children:
        add_count(G, child, x)

G = [Node() for _ in range(N)]
for _ in range(N-1):
    p, c = map(int, input().split())
    p -= 1
    c -= 1
    G[p].children.append(c)
    G[c].parent = p

dfs(G)

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    add_count(G, p, x)

counts = [node.count for node in G]
print(*counts)




### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x
    
q = [(1,0)]
while q:
    x,parent = q.pop()
    value[x] += value[parent]
    for y in graph[x]:
        if y == parent:
            continue
        q.append((y,x))

answer = ' '.join(map(str,value[1:]))
print(answer)
a, b, k = map(int, input().split())
lst = list(range(a, b+1))
print(*lst[:k], *lst[-k:], sep='\n')

### FIXED CODE ###

a, b, k = map(int, input().split())
lst = range(a, b+1)
for i in sorted(set(lst[:k]) | set(lst[-k:])):
  print(i)
from fractions import*
from functools import*
n,x,*a=map(int,open(0).read().split())
a=[abs(a[i+1]-a[i]) for i in range(n-1)]
print(reduce(gcd,a))

### FIXED CODE ###

from fractions import*
from functools import*
n,x,*a=map(int,open(0).read().split())
b=[abs(x-i)for i in a]
print(reduce(gcd,b))
#!/usr/bin/env python3

def main():
    N, M = map(int, input().split())
    groups = []
    for _ in range(M):
        a, b = map(int, input().split())
        if len(groups) == 0:
            groups.append({a, b})
        else:
            flag = True
            for g in groups:
                if a in g:
                    g.add(b)
                    flag = False
                if b in g:
                    g.add(a)
                    flag = False
            if flag:
                groups.append({a, b})
        ans = 0
        for g in groups:
            ans = max(ans, len(g))

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3


class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1] * (n + 1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0] * (n + 1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード

    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


def main():
    N, M = map(int, input().split())
    UF = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        UF.Unite(a, b)
    ans = 0
    for i in range(N):
        ans = max(ans, UF.Count(i + 1))
    print(ans)


if __name__ == "__main__":
    main()
# ABC107C - Candles (ARC101C)
def main():
    N, K, *X = map(int, open(0).read().split())
    ans = float("inf")
    for l, r in zip(X, X[k - 1 :]):
        ans = min(ans, r - l + min(abs(l), abs(r)))
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# ABC107C - Candles (ARC101C)
def main():
    n, k = tuple(map(int, input().rstrip().split()))
    x = tuple(map(int, input().rstrip().split()))
    ans = float("inf")
    for i in range(n - k + 1):
        a, b = x[i], x[i + k - 1]
        if a < b < 0 or 0 < a < b:
            ans = min(ans, max(abs(a), abs(b)))
        else:
            ans = min(ans, max(abs(a), abs(b)) + min(abs(a), abs(b)) * 2)
    print(ans)


if __name__ == "__main__":
    main()
import math
A, B = map(int, input().split())
ans = A*B
ant = math.floor(ans)
print(ant)

### FIXED CODE ###

def resolve():
    A, B = input().split()
    ans = int(A)*int(B[0])*100+int(A)*int(B[2:])
    print(str(ans)[:-2] if len(str(ans)) >= 3 else "0")
resolve()
while True:
    try:
        p=raw_input().lower()
    except:
        break
    ip+=p
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for i in alphabet:
    print i +' : '+ str(ip.count(i))

### FIXED CODE ###

ip=''
while True:
    try:
        p=raw_input()
    except:
        break
    ip+=p.lower()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for i in alphabet:
    print i +' : '+ str(ip.count(i))
a = input()
if a.islower():
  print(a)
else:
  print(A)

### FIXED CODE ###

A = input()

if A.isupper():
    print('A')
else:
    print('a')
import sys
readline = sys.stdin.readline
n, m = map(int, input().split())
a = []
b = []
for _ in range(m):
    aa, bb = list(map(int, readline().split()))
    a.append(aa - 1)
    b.append(bb - 1)
a = a[::-1]
b = b[::-1]
ans = int(n * (n - 1) / 2)
ans_rec = [0] * m
ans_rec[-1] = ans
p = [-1 for i in range(n)]
size = [1 for i in range(n)]
def find(x):
    px = p[x]
    if px < 0:
        return x
    else:
        pxx = find(px)
        p[x] = pxx
        return pxx
for k in range(m - 1):
    pa = find(a[k])
    pb = find(b[k])
    if pa == pb:
        pass
    else:
        ans -= size[pa] * size[pb]
        size[pa] += size[pb]
        p[pb] = pa
    ans_rec[- k - 2] = ans
print(*ans_rec, sep="\n")


### FIXED CODE ###

import sys
readline = sys.stdin.readline
N, M = map(int, input().split())
ab = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(M)]
class UnionFind:
    def __init__(self, size):
        self.rank = [-1 for _ in range(size)]
        self.number = [1 for _ in range(size)]
    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x
    def union(self, s1, s2):
        if s1 == s2:
            return
        if self.rank[s1] == self.rank[s2]:
            self.rank[s1] -= 1
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        elif self.rank[s1] < self.rank[s2]:
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        else:
            self.rank[s1] = s2
            self.number[s2] += self.number[s1]
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in reversed(ab[1:]):
    px = uf.find(x)
    py = uf.find(y)
    if px != py:
        p -= uf.number[px] * uf.number[py]
        uf.union(px, py)
    ans.append(p)
print(*ans[::-1], sep="\n")
import sys
input=sys.stdin.readline

N=int(input())

X1={}
X2={}

X={}
Y={}

for i in range(N):
    x,y,u=input().split()
    x=int(x)
    y=int(y)
    if x+y not in X1:
        X1[x+y]=[[x,u]]
    else:
        X1[x+y].append([x,u])
    if y-x not in X2:
        X2[y-x]=[[x,u]]
    else:
        X2[y-x].append([x,u])
    if x not in X:
        X[x]=[[y,u]]
    else:
        X[x].append([y,u])
    if y not in Y:
        Y[y]=[[x,u]]
    else:
        Y[y].append([x,u])


Dead=10**9


for k,v in X1.items():
    D=-1
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="D":
            D=a
        elif u=="R":
            R=a
        elif u=="L":
            if D>=0:
                Dead=min(Dead,(a-D)*10)
        elif u=="U":
            if R>=0:
                Dead=min(Dead,(a-R)*10)
for k,v in X2.items():
    U=-1
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="U":
            U=a
        elif u=="R":
            R=a
        elif u=="L":
            if U>=0:
                Dead=min(Dead,(a-U)*10)
        elif u=="D":
            if L>=0:
                Dead=min(Dead,(a-R)*10)
for k,v in X.items():
    U=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="U":
            U=a
        elif u=="D":
            if U>=0:
                Dead=min(Dead,(a-U)*5)
for k,v in Y.items():
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="R":
            R=a
        elif u=="L":
            if R>=0:
                Dead=min(Dead,(a-R)*5)
if Dead==10**9:
    print("SAFE")
else:
    print(Dead)

### FIXED CODE ###

import sys
input=sys.stdin.readline

N=int(input())

X1={}
X2={}

X={}
Y={}

for i in range(N):
    x,y,u=input().split()
    x=int(x)
    y=int(y)
    if x+y not in X1:
        X1[x+y]=[[x,u]]
    else:
        X1[x+y].append([x,u])
    if y-x not in X2:
        X2[y-x]=[[x,u]]
    else:
        X2[y-x].append([x,u])
    if x not in X:
        X[x]=[[y,u]]
    else:
        X[x].append([y,u])
    if y not in Y:
        Y[y]=[[x,u]]
    else:
        Y[y].append([x,u])


Dead=10**9


for k,v in X1.items():
    D=-1
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="D":
            D=a
        elif u=="R":
            R=a
        elif u=="L":
            if D>=0:
                Dead=min(Dead,(a-D)*10)
        elif u=="U":
            if R>=0:
                Dead=min(Dead,(a-R)*10)
for k,v in X2.items():
    U=-1
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="U":
            U=a
        elif u=="R":
            R=a
        elif u=="L":
            if U>=0:
                Dead=min(Dead,(a-U)*10)
        elif u=="D":
            if R>=0:
                Dead=min(Dead,(a-R)*10)
for k,v in X.items():
    U=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="U":
            U=a
        elif u=="D":
            if U>=0:
                Dead=min(Dead,(a-U)*5)
for k,v in Y.items():
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="R":
            R=a
        elif u=="L":
            if R>=0:
                Dead=min(Dead,(a-R)*5)
if Dead==10**9:
    print("SAFE")
else:
    print(Dead)
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
    r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(z,i3)
      s+=z2
print (s)

### FIXED CODE ###

def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
  r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(i3,z)
      s+=z2
print (s)
from math import inf
D = []
c = []
d = {}
N,C = map(int,input().split())
for i in range(C):
    D.append(list(map(int,input().split())))
for i in range(N):
    c.append(list(map(int,input().split())))

for C1 in range(C):
    for C2 in range(C):
        for C3 in range(C):
            if C1 != C2 and C2 != C3 and C3 != C1:
                d[(C1+1,C2+1,C3+1)]=0
            else:
                d[C1+1,C2+1,C3+1]=inf

for i in range(N):
    for j in range(N):
        for C1 in range(C):
            for C2 in range(C):
                for C3 in range(C):
                    if (i+j)%3==0:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C1]
                    elif (i+j)%3==1:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C2]
                    else:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C3]

l = []
for x in d:
    l.append(d[x])
print(min(l))

### FIXED CODE ###

import numpy as np
D = []
c = []
d0 = {}
d1 = {}
d2 = {}

N,C = map(int,input().split())
a = np.zeros((3,C))
for i in range(C):
    D.append(list(map(int,input().split())))
for i in range(N):
    c.append(list(map(int,input().split())))

D = np.array(D)
c = np.array(c)

for i in range(N):
    for j in range(N):
        a[(i+j)%3] += D[c[i][j]-1]

l = []
for C1 in range(C):
    for C2 in range(C):
        for C3 in range(C):
            if C1 != C2 and C2 != C3 and C3 != C1:
                l.append(a[0][C1]+a[1][C2]+a[2][C3])

print(int(min(l)))
import numpy as np
import sys

N = int(input())
X = np.zeros(N, dtype = np.int64)
Y = np.zeros(N, dtype = np.int64)
H = np.zeros(N, dtype = np.int64)
for i in range(N):
    x, y, h = map(int, input().split())
    X[i] = x
    Y[i] = y
    H[i] = h
node = 10 ** 9
for x in range(101):
    for y in range(101):
        result = (abs(X - x) + abs(Y - y) + H) * (H != 0)
        s = set(result)
        if 0 in s:
            s -= {0}
        if len(s) <= 1:
            height = (abs(X - x) + abs(Y - y) + H).min()
            print(x, y, height)
            sys.exit(0)

### FIXED CODE ###

N = int(input())
hxy = []
for _ in range(N):
    x, y, h = map(int, input().split())
    hxy.append((h, x, y))
hxy.sort(reverse=True)
for x in range(101):
    for y in range(101):
        H = abs(hxy[0][1] - x) + abs(hxy[0][2] - y) + hxy[0][0]
        for j in range(1, N):
            if max(0, H - abs(x - hxy[j][1]) - abs(y - hxy[j][2])) == hxy[j][0]:
                continue
            else:
                break
        else:
            print(x, y, H)
import numpy

### FIXED CODE ###

import sys

list_line = sys.stdin.readlines()

for index, element in enumerate(list_line):
    list_line[index] = element.rstrip('\n')

counter = 1
for i in list_line:
    if i != '0':
        print("Case %d: %s" % (counter, i))
        counter += 1
    else:
        counter = 1
a = int(input())
flag = 0

for i in range(8):
  if a % (i+2) == 0:
    flag = 1

if flag = 1:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

a = int(input())
flag = 0

for i in range(9):
  for j in range(9):
    if (i+1)*(j+1) == a:
      flag = 1

if flag == 1:
	print("Yes")
else:
	print("No")
a,b,c,x,y=map(int,input().split())
if 2*c<=min(a,b):
  print(2*c*max(x,y))
elif max(a,b)<=2*c:
  print(a*x+b*y)
elif a>=2*c:
  print(2*c*x+b*max(y-x,0))
elif b>=2*c:
  prinr(2*c*y+a*max(x-y,0))

### FIXED CODE ###

a,b,c,x,y=map(int,input().split())
if x>y:
  ans=min(a*x+b*y,2*c*x,2*c*y+a*(x-y))
else:
  ans=min(a*x+b*y,2*c*y,2*c*x+b*(y-x))
print(ans)
from math import gcd

def solve():
    K = int(input())
    ans = 0
    
    for i in range(1,K+1):
        num = [0, 0, 0]
        num[0] = i
        for k in range(1,K+1):
            num[1] = k
            for m in range(1,K+1):
                num[2] = m
                ans += reduce(gcd, num)
    return ans

print(solve())

### FIXED CODE ###

from math import gcd

K = int(input())
ans = 0

for i in range(1,K+1):
    for k in range(1,K+1):
        b = gcd(i, k)
        for m in range(1,K+1):
            ans += gcd(b, m)

print(ans)