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

from functools import lru_cache


def factorize(n):
    f = []
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        while tmp % i == 0:
            f.append(i)
            tmp //= i
    if tmp != 1:
        f.append(tmp)
    if not f:
        f.append(n)
    return f


def distance(s):
    a, b = 1, 1
    for i, si in enumerate(s):
        if si == "0":
            a *= factors[i]
        else:
            b *= factors[i]
    return a + b - 2


@lru_cache()
def kp(i, s):
    if i == 0:
        return 0, s
    else:
        if distance("0" + s) < distance("1" + s):
            return kp(i - 1, "0" + s)
        else:
            return kp(i - 1, "1" + s)


def sa(f):
    d = 999999999999
    for i in range(2 ** len(f)):
        d = min(d, distance("{}{}".format("0" * (len(f) - 1), bin(i)[2:])[-len(f):]))
    return d


N = int(input())
factors = factorize(N)
print(sa(factors))

### FIXED CODE ###

n = int(input())
ans = 1000000000000
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        a = i
        b = n // i
        ans = min(ans, a + b - 2)
print(ans)
### BUGGY CODE ###

k,s=map(int,input().split())
print(sum([x+y+z ==s for x in range(k+1) for y in range(k+1) for z in range(k+1)]))


### FIXED CODE ###

k,s=map(int,input().split())
print(len([1 for y in range(k+1) for z in range(k+1) if 0<=s-y-z<=k]))
### BUGGY CODE ###

from collections import Counter
import sys

sys.setrecursionlimit(20000)


def _ia(): return map(int, sys.stdin.readline().strip().split())


class UnionFind:
    def __init__(self, n: int) -> None:
        self._par = [i for i in range(n)]
        self._rank = [0] * n

    def root(self, n: int) -> int:
        p = self._par[n]
        if p == n:
            return p
        else:
            # compress
            self._par[n] = self.root(p)
            return self._par[n]

    def same(self, n: int, m: int) -> bool:
        return self.root(n) == self.root(m)

    def unite(self, n: int, m: int) -> None:
        pn = self.root(n)
        pm = self.root(m)
        if pn == pm:
            return
        self._par[pm] = pn


def main():
    n, m = _ia()
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(lambda x: x-1, _ia())
        uf.unite(a, b)
    c = Counter([uf.root(i) for i in range(n)])
    return max(c.values())


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

from collections import Counter
import sys

sys.setrecursionlimit(20000)


def _ia(): return map(int, sys.stdin.readline().strip().split())


class UnionFind:
    def __init__(self, n):
        self._par = [-1]*(n+1)
        self._rnk = [0]*(n+1)

    def root(self, x):
        if self._par[x] < 0:
            return x
        else:
            self._par[x] = self.root(self._par[x])
            return self._par[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        elif self._rnk[x] > self._rnk[y]:
            self._par[x] += self._par[y]
            self._par[y] = x
        else:
            self._par[y] += self._par[x]
            self._par[x] = y
            if self._rnk[x] == self._rnk[y]:
                self._rnk[y] += 1

    def same(self, x, y):
        return self.root(x) == self.root(y)


def main():
    n, m = _ia()
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(lambda x: x-1, _ia())
        uf.unite(a, b)
    c = Counter([uf.root(i) for i in range(n)])
    return max(c.values())


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

from itertools import product

def main():
    N, M = map(int, input().split())
    XYZ = [list(map(int, input().split())) for _ in range(N)]

    INF = 2**60
    ans = -INF 
    for a, b, c in product([-1, 1], repeat=3):
        dp = [-INF]*(M+1)
        dp[0] = 0
        for i in range(N):
            for j in range(M-1, -1, -1):
                if dp[j] != -INF:
                    s = a * XYZ[i][0] + b * XYZ[i][1] + c * XYZ[i][2]
                    dp[j+1] = max(dp[j+1], dp[j]+s)
        ans = max(ans, dp[M])
    print(ans)

main()


### FIXED CODE ###

import sys

def main():
    INF = -2**60
    N, M = map(int, sys.stdin.buffer.readline().split())
    XYZ = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

    sgn = [[1,1,1], [1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
    ans = INF 
    for a, b, c in sgn:
        dp = [INF]*(M+1)
        dp[0] = 0
        for x, y, z in XYZ:
            for j in range(M-1, -1, -1):
                if dp[j] == INF: continue
                s = dp[j]+ a*x + b*y + c*z
                if s > dp[j+1]:
                    dp[j+1] = s
        if dp[M] > ans:
            ans = dp[M]
    print(ans)

main()
### BUGGY CODE ###

import math
import sys
pin=sys.stdin.readline

def main():
  N,X,M=map(int,pin().split())
  A=X
  d=[X]
  su=X
  for i in range(N-1):
    A=(A**2)%M
    if A in d:
      t=d.index(A)
      T=N-i-1
      d=d[t:]
      l=len(d)
      su+=sum(d)*(T//l)
      T=T%(T//l)
      su+=sum(d[:T])
      print(su)
      return
    d.append(A)
    su+=A
  print(su)
  return
main()

### FIXED CODE ###

import math
import sys
pin=sys.stdin.readline

def main():
  N,X,M=map(int,pin().split())
  A=X
  d=[X]
  su=X
  for i in range(N-1):
    A=(A**2)%M
    if A in d:
      t=d.index(A)
      T=N-i-1
      d=d[t:]
      l=len(d)
      su+=sum(d)*(T//l)
      T=T%(T//l)
      su+=sum(d[:T])
      print(su)
      return
    d.append(A)
    su+=A
  print(su)
  return
main()
### BUGGY CODE ###

from collections import defaultdict

N, X, Y = map(int, input().split())
dists = defaultdict(lambda: N)
for k in range(1, N):
    for i in range(1 + k, N + 1):
        dists[(i - k, i)] = min(dists[(i - k, i)], k)
    for i in range(k):
        for a, b in (
            (X - i, Y + k - 1 - i),
            (X - i, Y - (k - 1 - i)),
            (X + i, Y + k - 1 - i),
            (X + i, Y - (k - 1 - i)),
        ):
            if 1 <= a <= N and 1 <= b <= N and a < b:
                dists[(a, b)] = min(dists[(a, b)], k)

d = defaultdict(int)
for v in dists.values():
    d[v] += 1
for k in range(1, N):
    print(d.get(k, 0))

### FIXED CODE ###

N, X, Y = map(int, input().split())
dists = [0] * N
for i in range(1, N):
    for j in range(i + 1, N + 1):
        d = min(j - i, abs(X - i) + abs(Y - j) + 1)
        dists[d] += 1

for k in range(1, N):
    print(dists[k])
### BUGGY CODE ###

N = int(input())
X_bin = input()

X_int = int(X_bin, 2)  # bin => int


def calc_ans(next_int):
    ans = 0
    while next_int > 0:
        next_bin = format(next_int, 'b')
        # popcount
        cnt = 0
        for i in next_bin:
            if i == '1':
                cnt += 1
        next_int = next_int % cnt
        next_bin = format(next_int, 'b')
        ans += 1
    return ans


for i in range(N):
    if X_bin[i] == '1':
        print(calc_ans(X_int - (2**(N-i-1))))
    else:
        print(calc_ans(X_int + (2**(N-i-1))))


### FIXED CODE ###

N = int(input())
X_bin = input()
#N = 10**5
#X_bin = '1' * N

X_int = int(X_bin, 2)  # bin => int


def calc_bin_cnt(next_int):
    if next_int == 0:
        return 0
    next_bin = bin(next_int)[2:]
    # popcount
    cnt = 0
    for i in next_bin:
        if i == '1':
            cnt += 1
    return cnt


def calc_ans(next_int, cnt=None):
    if next_cnt == 0:
        return 0
    if next_int == 0:
        return 1
    if cnt is None:
        cnt = calc_bin_cnt(next_int)
    next_int = next_int % cnt
    if next_int > 0:
        ans = calc_ans(next_int) + 1
    else:
        ans = 1
    return ans


X_cnt = calc_bin_cnt(X_int)
f_p = X_int % (X_cnt+1)
if X_cnt-1 == 0:
    f_m = 0
else:
    f_m = X_int % (X_cnt-1)
for i in range(N):
    if X_bin[i] == '1':
        next_cnt = X_cnt - 1
        if next_cnt == 0:
            next_int = 0
        else:
            next_int = f_m - pow(2, (N-i-1), next_cnt)  # マイナスでも正しく求まる？
    else:
        next_cnt = X_cnt + 1
        next_int = f_p + pow(2, (N-i-1), next_cnt)
    print(calc_ans(next_int, next_cnt))
    #calc_ans(next_cnt, next_cnt)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
n=int(input())
p = [float(i) for i in input().split()]

dp=[0]*(n+1)
dp[0]=1
for i in range(n):
    for j in range(n,-1,-1):
        dp[j] = dp[j]*(1-p[i]) + dp[j-1]*p[i]
#    print(dp)

print(sum(dp[(n+1)//2:]))        

### FIXED CODE ###

# coding: utf-8
# Your code here!
n=int(input())
p = [float(i) for i in input().split()]

dp=[0]*(n+1)
dp[0]=1
for i in range(n):
    for j in range(n,-1,-1):
        dp[j] = dp[j]*(1-p[i]) + dp[j-1]*p[i]
#    print(dp)

print(sum(dp[(n+1)//2:]))
### BUGGY CODE ###

n = int(input())
v = input().split()

vv = list(set(v))

if len(vv) >= 2:
    vvv = vv.copy()

    min = 10**6
    for i in vv:
        vvv.remove(i)
        for j in vvv:
            ct = 0
            a = [i if k % 2 == 0 else j for k in range(n)]
            for k in range(n):
                if a[k] != v[k]:
                    ct += 1
            if ct < min:
                min = ct
        vvv.append(i)
    print(min)
else:
    print(int(n/2))


### FIXED CODE ###

import collections

n = int(input())
v = input().split()

e = [v[i] for i in range(n) if i % 2 == 0]
o = [v[i] for i in range(n) if i % 2 == 1]

c_e = collections.Counter(e).most_common()
c_o = collections.Counter(o).most_common()

e_0 = c_e[0]
o_0 = c_o[0]

if e_0 != o_0:
    print(len(e) - e_0[1] + len(o) - o_0[1])
else:
    if len(c_e) == 1:
        e_1 = [0, 0]
    else:
        e_1 = c_e[1]
    if len(c_o) == 1:
        o_1 = [0, 0]
    else:
        o_1 = c_o[1]
    print(min(len(e)-e_0[1]+len(o)-o_1[1], len(e)-e_1[1]+len(o)-o_0[1]))
### BUGGY CODE ###

def d_wizard_in_maze():
    from collections import deque
    H, W = [int(i) for i in input().split()]
    Start_row, Start_col = [int(i) - 1 for i in input().split()]
    Goal_row, Goal_col = [int(i) - 1 for i in input().split()]
    Grid = [input() for _ in range(H)]

    warp_count = [[-1] * W for i in range(H)]
    neighbor_4 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    neighbor_25 = [(i, j) for i in range(-2, 3) for j in range(-2, 3)]
    queue = deque([(Start_row, Start_col, 0)])  # コスト 0 の移動は左詰めする

    def can_walk(row, col):
        return 0 <= row < H and 0 <= col < W and Grid[row][col] == '.'

    def move(row, col, neighbor, cond, func):
        nonlocal warp_count
        for dr, dc in neighbor:
            nr, nc = row + dr, col + dc
            if can_walk(nr, nc):
                if eval(cond):
                    func((nr, nc, count + int(len(neighbor) == 25)))

    while(queue):
        row, col, count = queue.popleft()
        if warp_count[row][col] != -1:
            continue
        warp_count[row][col] = count

        move(row, col, neighbor_4, 'warp_count[nr][nc] == -1', queue.appendleft)
        move(row, col, neighbor_25, 'True', queue.append)

    return warp_count[Goal_row][Goal_col]

print(d_wizard_in_maze())

### FIXED CODE ###

def d_wizard_in_maze():
    from collections import deque
    H, W = [int(i) for i in input().split()]
    Start_row, Start_col = [int(i) - 1 for i in input().split()]
    Goal_row, Goal_col = [int(i) - 1 for i in input().split()]
    Grid = [input() for _ in range(H)]

    warp_count = [[-1] * W for i in range(H)]
    neighbor_4 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    neighbor_25 = [(i, j) for i in range(-2, 3) for j in range(-2, 3)]
    queue = deque([(Start_row, Start_col, 0)])  # コスト 0 の移動は左詰めする

    while(queue):
        row, col, count = queue.popleft()
        if warp_count[row][col] != -1:
            continue
        warp_count[row][col] = count

        for dr, dc in neighbor_4:
            nr, nc = row + dr, col + dc
            if 0 <= nr < H and 0 <= nc < W and Grid[nr][nc] == '.':
                if warp_count[nr][nc] == -1:
                    queue.appendleft((nr, nc, count))

        for dr, dc in neighbor_25:
            nr, nc = row + dr, col + dc
            if 0 <= nr < H and 0 <= nc < W and Grid[nr][nc] == '.':
                queue.append((nr, nc, count + 1))

    return warp_count[Goal_row][Goal_col]

print(d_wizard_in_maze())
### BUGGY CODE ###

# -*- Coding: utf-8 -*-

N,M = map(int,raw_input().split())

list_in = []

for i in xrange(M):
	list_in.append(map(int,raw_input().split()))

count = 0
for i in xrange(N):
	flag = 0
	for j in xrange(M):
		if ((i+1)<list_in[j][0]) | ((i+1)>list_in[j][1]):
			flag = 1
			break

	if flag==1:
		flag = 0
	else:
		count += 1

print count

### FIXED CODE ###

# -*- Coding: utf-8 -*-

N,M = map(int,raw_input().split())

L = 0
R = N

for i in xrange(M):
	li,ri = map(int,raw_input().split())
	L = max(L,li)
	R = min(R,ri)

print max(0,R-L+1)
### BUGGY CODE ###

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

N,M = map(int,input().split())
to = [[] for i in range(N)]
for i in range(N-1) :
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    to[u].append(v)
    to[v].append(u)

ans = [0]*N

def dfs(u, p) :
    for v in to[u] :
        if v == p :
            continue
        ans[v] += ans[u]
        dfs(v, u)

for i in range(M) :
    p,x = map(int,input().split())
    p -= 1
    ans[p] += x

dfs(0, -1)

print(*ans)


### FIXED CODE ###

from collections import deque

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

L = [[] for i in range(N)]
for i in range(N-1) :
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    L[u].append(v)
    L[v].append(u)

par = [-1]*N

cnt = [0]*N

for i in range(Q) :
    p,x = map(int,input().split())
    p -= 1
    cnt[p] += x

q = deque([0])
while len(q) :
    u = q.popleft()
    for v in L[u] :
        if v == par[u] :
            continue
        par[v] = u
        cnt[v] += cnt[u]
        q.append(v)


"""
for i in range(Q) :
    p,x = map(int,input().split())
    p -= 1
    q = deque([p])
    while len(q) :
        u = q.popleft()
        cnt[u] += x
        for v in L[u] :
            if v != par[u] :
                q.append(v)
"""
print(*cnt)
### BUGGY CODE ###

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
C = list(map(int, input().split()))


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


num = 2 ** ((n - 1).bit_length())
SEG = [0] * (2 * num)


def func(a, b):
    return a | b


for idx, val in enumerate(C):
    idx += num
    SEG[idx] = 1 << (val - 1)
    while idx > 0:
        idx //= 2
        SEG[idx] = func(SEG[2 * idx], SEG[2 * idx + 1])


def query(left, right):
    resleft = 0
    resright = 0
    left += num
    right += num
    while right - left > 0:
        if left % 2 == 1:
            resleft = func(resleft, SEG[left])
            left += 1
        if right % 2 == 1:
            right -= 1
            resright = func(resright, SEG[right])
        left //= 2
        right //= 2
    return func(resleft, resright)


for _ in range(q):
    l, r = map(int, input().split())
    temp = query(l - 1, r)
    print(popcnt(temp))


### FIXED CODE ###

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
for i in range(q):
    l, r = map(int, input().split())
    LR.append((l, r, i))
LR.sort(key=lambda x: x[1])


BIT = [0] * (n + 1)


def update(idx, val):
    while idx <= n:
        BIT[idx] += val
        idx += idx & (-idx)


def query(idx):
    res = 0
    while idx > 0:
        res += BIT[idx]
        idx -= idx & (-idx)
    return res


pos = [-1] * (n + 1)


def func(idx):
    temp = C[idx]
    if pos[temp] == -1:
        pos[temp] = idx + 1
        update(idx + 1, 1)
    else:
        pre = pos[temp]
        pos[temp] = idx + 1
        update(pre, -1)
        update(idx + 1, 1)


ans = [0] * (q)
idx = 0
for i in range(q):
    l, r, ans_num = LR[i]
    # l,rは0-indexに戻す
    l -= 1
    r -= 1
    while idx < r + 1:  # rになるまで増やす
        if idx < n:  # n超えないように注意
            func(idx)
            idx += 1
        else:
            break
    res = 0
    res += query(r + 1)
    if l > 0:
        res -= query(l)
    ans[ans_num] = res

print(*ans, sep="\n")
### BUGGY CODE ###

from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    adj = [set() for _ in range(N)]
    for i in range(N-1):
        u, v = map(int, input().split())
        adj[u-1].add(v-1)
        adj[v-1].add(u-1)
    ans = [0] * N
    q = [(0, -1, [])]
    while len(q):
        cur, prev, lis = q.pop()
        idx = bisect_left(lis, A[cur])
        nxt_lis = lis[:idx] + [A[cur]] + lis[idx+1:]
        ans[cur] = len(nxt_lis)
        for nxt in adj[cur]:
            if nxt == prev:
                continue
            q.append((nxt, cur, nxt_lis))
    for i in range(N):
        print(ans[i])


if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    adj = [set() for _ in range(N)]
    for i in range(N-1):
        u, v = map(int, input().split())
        adj[u-1].add(v-1)
        adj[v-1].add(u-1)
    ans = [0] * N
    q = [(0, -1, [], 0)]
    history = []
    while len(q):
        cur, prev, lis, depth = q.pop()
        while depth < len(history):
            pos, val = history.pop()
            if val is None:
                lis.pop()
            else:
                lis[pos] = val
        idx = bisect_left(lis, A[cur])
        if idx == len(lis):
            history.append((idx, None))
            lis.append(A[cur])
        else:
            history.append((idx, lis[idx]))
            lis[idx] = A[cur]
        ans[cur] = len(lis)
        for nxt in adj[cur]:
            if nxt == prev:
                continue
            q.append((nxt, cur, lis, depth+1))
    for i in range(N):
        print(ans[i])


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

from collections import deque


def atcoder_input():
    H, W = (int(i) for i in input().split())

    Q = deque()

    for h in range(H):
        l = [j for j in input().split()]

        for w in range(W):
            if list(l[0])[w] == "#":
                Q.append((h + 1, w + 1, 0))

    return Q, H, W


def main():
    Q, H, W = atcoder_input()
    searched = [[0] * (W + 2) for _ in range(H + 2)]

    for h in range(H + 2):
        searched[h][0] = 1
        searched[h][-1] = 1

    for w in range(W + 2):
        searched[0][w] = 1
        searched[-1][w] = 1

    max_count = 0

    while Q:
        h, w, count = Q.popleft()

        for (h2, w2) in ([h + 1, w], [h, w + 1], [h - 1, w], [h, w - 1]):
            if searched[h2][w2] == 1:
                continue
            else:
                searched[h2][w2] = 1

                if count + 1 > max_count:
                    max_count = count + 1
                Q.append((h2, w2, count + 1))

    print(max_count)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


# Graph
def r(p):
    q_list = []
    h = p // W
    w = p % W
    if h != 0:
        q_list.append(p - W)
    if h != H-1:
        q_list.append(p + W)
    if w != 0:
        q_list.append(p - 1)
    if w != W-1:
        q_list.append(p + 1)
    return q_list


queue = deque(black_cells)
d = [10000] * (H * W)
for i in black_cells:
    d[i] = 0

# dijkstra
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

print(max(d))
### BUGGY CODE ###

N = int(input())
INF = float('inf')
A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
A = sorted(A, key=lambda x: x[1], reverse = True)
dp = [[-INF] * (N+1) for _ in range(N+1)]
dp[0][0] = 0

for s in range(1, N+1):
    for l in range(s+1):
        r = s - l
        dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))

ans = 0
for m in range(N):
    if dp[m][N-m] > ans:
        ans = dp[m][N-m]

print(ans)

### FIXED CODE ###

def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)

  dp = [[-INF] * (N+1) for _ in range(N+1)]
  dp[0][0] = 0

  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)

main()
### BUGGY CODE ###

s = input().rstrip()
N = int(s)

ans = 0
i = 1

while i < N + 1:
    j = int(str(i)[0])
    while j < N + 1:
        if str(i)[-1] == str(j)[0] and str(i)[0] == str(j)[-1]:
            ans = ans + 1
        j = j +  10
    i = i + 1

print(ans)


### FIXED CODE ###

s = input().rstrip()
N = int(s)

ans = 0
i = 1
order = len(str(N))

params = {}

for i in range(1, N + 1):
    Akey = str(i)[-1] + str(i)[0] 
    if params.get(Akey) is not None:
        params[Akey] = params[Akey] + 1
    else:
        params[Akey] = 1

for i in range(1, N + 1):
    Bkey = str(i)[0] + str(i)[-1] 
    count = params.get(Bkey)
    if count is not None:
        ans =  ans + count;

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

N=int(input())
A=list(map(int,input().split()))
w=sorted(list(set(A)))[::-1]
leng=[0]*2
k=0
for i in w:
    if A.count(i)==2 or A.count(i)==3:
        leng[k]=i
        k+=1
    elif A.count(i)>3 and k==1:
        leng[k]=i
        k+=1
    elif A.count(i)>3 and k==0:
        leng[k]=i
        leng[k+1]=i
        k+=2
    
    if k==2:
        break

print(leng[0]*leng[1])

### FIXED CODE ###

from collections import Counter

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

x=sorted([i for i in A.items() if i[1]>=2])

if len(x)<2:
    print(0)
elif x[-1][1]>=4:
    print(x[-1][0]**2)
else:
    print(x[-1][0]*x[-2][0])
### BUGGY CODE ###

X,Y,Z,K=map(int,input().split())
Ax=sorted(list(map(int,input().split())), reverse=True)
By=sorted(list(map(int,input().split())), reverse=True)
Cz=sorted(list(map(int,input().split())), reverse=True)
n = []
for a in range(min(K, len(Ax))):
    for b in range(min(K, len(By))):
        for c in range(min(K, len(Cz))):
            n.append(Ax[a] + By[b] + Cz[c])
n.sort(reverse=True)
for k in range(K):
    print(n[k])


### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
Ax=sorted(list(map(int,input().split())), reverse=True)
By=sorted(list(map(int,input().split())), reverse=True)
Cz=sorted(list(map(int,input().split())), reverse=True)

a=b=c=0
s = set([(a,b,c)])
t = set()
for k in range(K):
    best_value = 0
    best_tuple = None
    for x,y,z in s:
        if (x,y,z) not in t:
            m = Ax[x]+By[y]+Cz[z]
            if m > best_value:
                best_value = m
                best_tuple = (x,y,z)
    print(best_value)

    t.add(best_tuple)
    s.remove(best_tuple)
    x,y,z=best_tuple
    if x < X-1:
        if (x+1,y,z) not in s:
            s.add((x+1,y,z))
    if y < Y-1:
        if (x,y+1,z) not in s:
            s.add((x,y+1,z))
    if z < Z-1:
        if (x,y,z+1) not in s:
            s.add((x,y,z+1))
### BUGGY CODE ###



a,b,c,x,y = map(int,input().split())
p_lists = []
#print(a,b,c,x,y)

if x > y:
  d = x
else:
  d = y

#print(d)

for i in range(x + 1):
    for j in range(y + 1):
        for k in range(2 * d + 1):
            if (i + k / 2 >= x and j + k / 2 >= y):
                price = a * i + b * j + c * k
                maxprice = a * x + b * y
                if price <= maxprice:
                    p_lists.append(price)      



#print(p_lists)
print(min(p_lists))


### FIXED CODE ###




a,b,c,x,y = map(int,input().split())

price = a * x + b * y


for i in range(max(x,y) + 1):
    ab = 2 * i
    cand = ab * c + a * max(0, x - i) + b * max(0, y-i)

    price = min(price, cand)

print(price)