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

# coding: utf-8
# Your code here!
r , g , b , n = map(int,input().split())
ans = 0
R = -(-n//r)
G = -(-n//g)
for i in range(R+1):
    for j in range(G+1):
        su = n-r*i-g*j
        if n-r*i-g*j < 0:
            break
        else:
            if (su/b).is_integer():
                ans += 1
print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!
r , g , b , n = map(int,input().split())
ans = 0
R = -(-n//r)
G = -(-n//g)
for i in range(R+1):
    for j in range(G+1):
        su = n-r*i-g*j
        if n-r*i-g*j < 0:
            break
        else:
            if (su/b).is_integer():
                ans += 1
print(ans)
### BUGGY CODE ###

import numpy as np

def main():
  N, K = list(map(int, input().split()))
  h = np.asarray(list(map(int, input().split())))

  if N == 2:
    print(abs(h[1] - h[0]))
    exit()
  
  DP = np.full(N, int(10e10), dtype = np.int32)

  mi = min(N, K + 1)
  
  DP[1: mi] = np.abs(h[1: mi] - h[0])
  
  for i in range(1, N - 1):
    t = i + K + 1
    T = np.abs(h[i + 1: t] - h[i]) + DP[i]
    DP[i + 1: t] = np.where(T < DP[i + 1: t], T, DP[i + 1: t])
  
  print(DP[N-1])
main()


### FIXED CODE ###

def main():
  N, K = list(map(int, input().split()))
  h = tuple(map(int, input().split()))

  if N == 2:
    print(abs(h[1] - h[0]))
    exit()

  DP = [0 for i in range(N)]

  mi = min(N, K + 1)
  for i in range(1, mi):
    DP[i] = abs(h[i] - h[0])
  for i in range(1, N - 1):
    mi = min(N, i + K)
    for j in range(i, mi):
      t = DP[i] + abs(h[j] - h[i])
      if DP[j] > t:
        DP[j] = t
    if i + K <= N - 1:
      DP[i+K] = DP[i] + abs(h[i+K] - h[i])
  print(DP[N-1])
  
main()
### BUGGY CODE ###

K,S = map(int,input().split())
num = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if (i+j+k) == S: num += 1
print(num)

### FIXED CODE ###

K,S = map(int,input().split())
num = 0
for i in range(K+1):
    for j in range(K+1):
        a = S - i - j
        if 0<=a<=K: num+=1
print(num)
### BUGGY CODE ###

#  入力
N = int(input())
A = [int(x) for x in input().split()]

# 初期化
dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(0,N):

    # 最も嬉しさの高い子供から場所を選択していく
    id = A.index(max(A))
    a = A[id]
    for x in range(0,i+1):
        y = i - x

        # print("{}回目 x {}, y {}".format(i, x, y))
        # print("{}, {}点　移動係数 x {}, y {}".format(id, A[id], id - x, ((N-1)-y) - id))
        
        dp[x+1][y] = max(dp[x+1][y], dp[x][y] + a * (id - x))
        # print("x", A[id], id, id - x, dp[x+1][y])
        dp[x][y+1] = max(dp[x][y+1], dp[x][y] + a * (((N-1)-y) - id))
        # print("y", A[id], id, ((N-1)-y) - id, dp[x][y+1])
        
    A[id] = 0

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)

### FIXED CODE ###

#  入力
N = int(input())
A = [int(x) for x in input().split()]

# 初期化
dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(0,N):

    # 最も嬉しさの高い子供から場所を選択していく
    a = max(A)
    id = A.index(a)
    
    for x in range(0,i+1):
        y = i - x

        d = dp[x][y]
        tmp = d + a * (id - x)
        if dp[x+1][y] < tmp:
        	dp[x+1][y] = tmp
        tmp = d + a * (((N-1)-y) - id)            
        if dp[x][y+1] < tmp:
        	dp[x][y+1] = tmp
        
    A[id] = 0

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)
### BUGGY CODE ###

from math import gcd
n = int(input())
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            a = list(set([i,j,k]))
            if len(a)==1: ans+=a[0]
            elif len(a)==2:
                a = gcd(max(a), min(a))
                ans+=a
            else:
                tmp = gcd(i,j)
                tmp = gcd(tmp, k)
                ans+=tmp
print(ans)

### FIXED CODE ###

from math import gcd
n = int(input())
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            if i==j and j==k: ans+=i
            else:
                tmp = gcd(k, gcd(i,j))
                ans+=tmp
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
ans=[]
for i in range(len(s)-1):
    if s[i:i+2]=='AC':ans.append(i)
for _ in range(q):
    l,r=map(int,input().split())
    cnt=0
    for x in ans:
        if l-1<=x<r-1: cnt+=1
    print(cnt)

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
ans=[0]*n
cnt=0
for i in range(len(s)-1):
    if s[i:i+2]=='AC': cnt+=1
    ans[i]=cnt
for _ in range(q):
    l,r=map(int,input().split())
    print(ans[r-2]-ans[l-2])
### BUGGY CODE ###

a,b=map(int,input().split())
l=[]
for x in range(1,a*b+1):
  if x%a==0 and x%b==0:
    l.append(x)
print(min(l))


### FIXED CODE ###

import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)
print(a*b//g)
### BUGGY CODE ###

N,M=map(int,input().split())
q=[[] for i in range(N+1)]
for i in range(M):
    l,r,x=map(int,input().split())
    q[r].append((l,x))
mod=10**9+7

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

i=N
for j in range(N+1):
    for k in range(N+1):
        check=7
        for l,x in q[i]:
            if x==1:
                if i-1>=l>j:
                    check&=1
                elif i==l:
                    check&=7
                else:
                    check=0
            elif x==2:
                if i==l:
                    check=0
                elif i-1>=l>j:
                    check&=6
                elif j>=l>k:
                    check&=3
                else:
                    check=0
            else:
                if i==l:
                    check=0
                elif i-1>=l>j:
                    check=0
                elif j>=l>k:
                    check&=4
        dp[j][k]=bin(check).count("1")

ndp=[[0 for j in range(N+1)] for k in range(N+1)]
s=[(j,k) for j in range(N+1) for k in range(N+1)]
for i in range(N-1,0,-1):
    for j,k in s:
        check=7
        for l,x in q[i]:
            if i==l:
                check=(x==1)*check
            elif i-1>=l>j:
                check=(x==1)*(check%2)+(x==2)*(check&6)
            elif j>=l>k:
                check=(x==2)*(check&3)+(x==3)*(check&4)
            else:
                check*=(x==3)
            
        ndp[j][k]=(dp[j][k]*((check//1)%2)+dp[i-1][k]*((check//2)%2)+dp[i-1][j]*((check//4)%2))%mod
    dp=ndp

print(dp[0][0])

### FIXED CODE ###

N,M=map(int,input().split())
q=[[] for i in range(N+1)]
for i in range(M):
    l,r,x=map(int,input().split())
    q[r].append((l,x))
mod=10**9+7

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

i=N
for j in range(N+1):
    for k in range(N+1):
        check=7
        for l,x in q[i]:
            if i==l:
                check=(x==1)*check
            elif i-1>=l>j:
                check=(x==1)*(check%2)+(x==2)*(check&6)
            elif j>=l>k:
                check=(x==2)*(check&3)+(x==3)*(check&4)
            else:
                check*=(x==3)
        dp[j][k]=bin(check).count("1")

ndp=[[0 for j in range(N+1)] for k in range(N+1)]
for i in range(N-1,0,-1):
    for j in range(i):
        for k in range(j+1):
            check=7
            for l,x in q[i]:
                if i==l:
                    check=(x==1)*check
                elif i-1>=l>j:
                    check=(x==1)*(check%2)+(x==2)*(check&6)
                elif j>=l>k:
                    check=(x==2)*(check&3)+(x==3)*(check&4)
                else:
                    check*=(x==3)
            ndp[j][k]=(dp[j][k]*((check//1)%2)+dp[i-1][k]*((check//2)%2)+dp[i-1][j]*((check//4)%2))%mod

    dp=ndp

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

h, w = map(int, input().split())

s = [[j for j in list(str(input()))] for i in range(h)]

board = [[[0 for _ in range(4)] for _ in range(w)] for _ in range(h)]

# 右、左、上、下の順に走査
for i in range(h):
    cnt_continue = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt_continue += 1
        else:
            cnt_continue = 0
        board[i][j][0] = cnt_continue

for i in range(h):
    cnt_continue = 0
    for j in reversed(range(w)):
        if s[i][j] == ".":
            cnt_continue += 1
        else:
            cnt_continue = 0
        board[i][j][1] = cnt_continue

for i in range(w):
    cnt_continue = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt_continue += 1
        else:
            cnt_continue = 0
        board[j][i][2] = cnt_continue

for i in range(w):
    cnt_continue = 0
    for j in reversed(range(h)):
        if s[j][i] == ".":
            cnt_continue += 1
        else:
            cnt_continue = 0
        board[j][i][3] = cnt_continue

ans = 0

for i in range(h):
    for j in range(w):
        v = sum(board[i][j]) - 3
        ans = max(ans, v)

print(ans)


### FIXED CODE ###

h, w = map(int, input().split())

s = [input() for i in range(h)]

board_w = [[0 for _ in range(w)] for _ in range(h)]
board_h = [[0 for _ in range(w)] for _ in range(h)]

# 右、左、上、下の順に走査
for i in range(h):
    cnt_continue = 0
    for j in range(w):
        if s[i][j] == "#":
            cnt_continue = 0
        else:
            cnt_continue += 1
            board_w[i][j] = cnt_continue

    for j in reversed(range(w-1)):
        if board_w[i][j] == 0:
            continue
        board_w[i][j] = max(board_w[i][j], board_w[i][j+1])

for i in range(w):
    cnt_continue = 0
    for j in range(h):
        if s[j][i] == "#":
            cnt_continue = 0
        else:
            cnt_continue += 1
            board_h[j][i] = cnt_continue

    for j in reversed(range(h-1)):
        if board_h[j][i] == 0:
            continue
        board_h[j][i] = max(board_h[j][i], board_h[j+1][i])


ans = 0

for i in range(h):
    for j in range(w):
        v = board_w[i][j] + board_h[i][j] - 1
        ans = max(ans, v)

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

def d_xxor(N, K, A):
    # 参考: http://drken1215.hatenablog.com/entry/2019/02/03/224200
    ans = 0
    # N, K <= 10**12 < 2**40 なので、dの上限を40とする
    for d in range(40, -2, -1):
        # d=-1のケースはX=Kのケースを意味する
        if d != -1 and (K & (1 << d)) == 0:
            continue

        tmp = 0
        for e in range(40, -1, -1):
            bit_mask = 1 << e

            # Aの各要素を2進表記したとき、e番目のビットが立っているものは何個か？
            num = 0
            for a in A:
                if a & bit_mask != 0:
                    num += 1

            # このビットがfに貢献する値を決める。
            if e > d:
                if K & bit_mask != 0:
                    tmp += bit_mask * (N - num)  # X_e=1とする
                else:
                    tmp += bit_mask * num  # X_e=0とする
            elif e == d:
                tmp += bit_mask * num  # このビットは0とする(解説pdf参照)
            else:
                # これを満たすビットについては、独立に決めていい。
                # よって、貢献する値が大きな方を選べばいい
                tmp += bit_mask * max(num, N - num)
        ans = max(ans, tmp)
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_xxor(N, K, A))

### FIXED CODE ###

def d_xxor(N, K, A):
    bit_max = 40  # N,K <= 10**12 < 2**40 なので、入力は40bit以下で表せる
    ans = 0

    for b in range(bit_max, -1, -1):
        power = 1 << b
        # Aの各要素を2進表記したとき、b番目のビットに1は何個立つか？
        bit_count_1 = len([1 for a in A if a & power != 0])

        # 解説における、「X_k=0とするか1とするか判定する」部分
        tmp = bit_count_1
        if power <= K and bit_count_1 <= N - bit_count_1:
            # X_k=1とした。XとKとの差を補正する。
            tmp = N - bit_count_1
            K -= power
        contribution = power * tmp

        ans += contribution  # 「b番目のビットがfに貢献する値」
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_xxor(N, K, A))
### BUGGY CODE ###

S = input()
Q = int(input())
query_q = [input().split() for _ in range(Q)]

for query in query_q:
    if query[0] == '1':
        S = S[::-1]
    if query[0] == '2':
        if query[1] == '1':
            S = query[2] + S
        elif query[1] == '2':
            S = S + query[2]

print(S)

### FIXED CODE ###

def main():

    S = input()
    Q = int(input())

    reverse = False
    head = ''
    tail = ''

    for _ in range(Q):
        query= input()
        if query == '1':
            reverse = not reverse
            head, tail = tail, head
        else:
            _, f, c = query.split()
            if f == '1':
                head = ''.join([head,c])
            else:
                tail = ''.join([tail,c])

    if reverse:
        S = S[::-1]

    print(''.join([head[::-1], S, tail]))

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

from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,m=input2()
AB=[input_array() for _ in range(m)]
D=[[0]*n for _ in range(n)]

for ab in AB:
	a=ab[0]
	b=ab[1]
	D[a-1][b-1]=1

csr=csr_matrix(D)

ans=connected_components(csr, return_labels=False) -1
print(ans)

### FIXED CODE ###

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

class UnionFind():
	"""docstring for UnionFind"""
	def __init__(self, n):
		self.parents = [-1]*n

	def find(self,x):
		if self.parents[x] < 0: #自分が親である時
			return x
		else: #自分が子供である時
			self.parents[x]=self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		# 各要素の親要素を返す
		x=self.find(x)
		y=self.find(y)

		if x==y:
			return
		if self.parents[x] > self.parents[y]:
			x,y=y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x
		# print(self.parents)
n,m=input2()
AB=[input_array() for _ in range(m)]


uf = UnionFind(n)
for ab in AB:
	a=ab[0]
	b=ab[1]
	uf.union(a-1,b-1)

ans=0
for i in uf.parents:
	if i < 0:
		ans+=1
print(ans-1)
### BUGGY CODE ###

from bisect import insort

n, m = map(int, input().split())
a_s = sorted(list(map(int, input().split())))

for i in range(m):
	new_amax = a_s[-1] // 2
	a_s = a_s[:-1]
	insort(a_s, new_amax)

res = sum(a_s)
print(res)

### FIXED CODE ###

from math import ceil
from heapq import *

n, m = map(int, input().split())
a_s = [-int(a) for a in input().split()]
heapify(a_s)

for _ in range(m):
	amax = heappop(a_s)
	heappush(a_s, ceil(amax / 2))

res = sum([-heappop(a_s) for _ in range(n)])
print(res)
### BUGGY CODE ###

from collections import defaultdict
from collections import Counter

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

arr = defaultdict(int)

for k, v in Counter(a).items():
    arr[k] = v

q = int(input())
    
for _ in range(q):
    b, c = map(int, input().split())
    arr[c] += arr[b]
    arr[b] = 0
    print(sum([x * y for x, y in arr.items()]))

### FIXED CODE ###

from collections import defaultdict
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
arr = defaultdict(int)
for k, v in Counter(a).items():
    arr[k] = v
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))

whole = sum([x * y for x, y in arr.items()])

for b, c in bc:
    arr[c] += arr[b]
    tmp = arr[b]
    arr[b] = 0
    whole += (c - b) * tmp
    print(whole)
### BUGGY CODE ###

from bisect import bisect_left, bisect_right


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

dp1 = [[0] * (K + 1) for _ in range(N + 1)]
dp1[0][0] = 1
for i in range(N):
    a = A[i]
    for j in range(K + 1):
        here = dp1[i][j]
        dp1[i + 1][min(K, j + a)] |= here
        dp1[i + 1][j] |= here

dp2 = [[0] * (K + 1) for _ in range(N + 1)]
dp2[0][0] = 1
for i in range(N):
    a = A[N - 1 - i]
    for j in range(K + 1):
        here = dp2[i][j]
        dp2[i + 1][min(K, j + a)] |= here
        dp2[i + 1][j] |= here

cnt = 0
for i in range(N):
    d1 = []
    d2 = []
    n = A[i]
    for j, k in enumerate(dp1[i]):
        if k:
            d1.append(j)
    for j, k in enumerate(dp2[N - 1 - i]):
        if k:
            d2.append(j)
    for a in d1:
        l = bisect_left(d2, K - n - a)
        r = bisect_left(d2, K - a)
        if r - l >= 1:
            cnt += 1
            break
    
print(N - cnt)


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp=[0]*N

    for i in range(1,N):
        dp[i] = min(
            dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
        )
    print(dp[N-1])
main()

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp=[0]*N

    for i in range(1,N):
        dp[i] = min(
            dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
        )
    print(dp[N-1])
main()
### BUGGY CODE ###

from collections import deque

N=int(input())
cost=[[float("inf")]*N for _ in range(N)]
graph=[[] for _ in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)
    cost[a][b]=c
    cost[b][a]=c

def dfs(start):
    visited=[False]*N
    queue=deque([start])
    visited[start]=0
    while queue:
        x=queue.pop()
        for y in graph[x]:
            if visited[y]!=False:
                continue
            visited[y]=visited[x]+cost[x][y]
            queue.append(y)
    return visited

Q,K=map(int,input().split())
K-=1
d=dfs(K)
for _ in range(Q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(d[x]+d[y])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

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

def dfs(start):
    for x,cost in graph[start]:
        if d[x]==-1:
            d[x]=d[start]+cost
            dfs(x)

Q,K=map(int,input().split())
K-=1
d=[-1]*N
d[K]=0
dfs(K)
for i in range(Q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(d[x]+d[y])
### BUGGY CODE ###

from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    md = 10 ** 9 + 7
    n = int(input())
    cc = [int(input()) for _ in range(n)]
    dp = [0] * (n + 1)
    dp[0] = 1
    ll = defaultdict(list)
    pc = -1
    for r, c in enumerate(cc):
        dp[r + 1] = dp[r]
        if c == pc: continue
        for l in ll[c]:
            dp[r + 1] += dp[l]
        dp[r + 1] %= md
        ll[c].append(r)
        pc = c
    print(dp[n])

main()


### FIXED CODE ###

from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    md = 10 ** 9 + 7
    n = int(input())
    cc = [int(input()) for _ in range(n)]
    dp = [0] * (n + 1)
    dp[0] = 1
    ll = defaultdict(int)
    pc = -1
    for r, c in enumerate(cc):
        dp[r + 1] = dp[r]
        if c == pc: continue
        dp[r + 1] = (dp[r + 1] + ll[c]) % md
        ll[c] = (ll[c] + dp[r]) % md
        pc = c
    print(dp[n])

main()
### BUGGY CODE ###

# D Knapsack 1


n, w = map(int,input().split())
wv_list = [[int(x) for x in input().split()] for y in range(n)]

dp = [[float("-Inf")] * (w+1) for _ in range(n+1)]
dp[0] = [0]*(w+1)
memo = [[False] * (w+1) for _ in range(n+1)]
memo[0] = [True] * (w+1)

def dp_solve(dp, wv_list, i, j):
    if memo[i][j]:
        return dp[i][j]
    _w,_v = wv_list[i-1]
    _ret = 0
    if j-_w < 0:
        _ret = dp_solve(dp, wv_list, i-1, j)
    else:
        _ret = max(dp_solve(dp, wv_list, i-1, j), dp_solve(dp, wv_list, i-1, j-_w) + _v)
    dp[i][j] = _ret
    return _ret

print(dp_solve(dp, wv_list, n, w))

### FIXED CODE ###

# D Knapsack 1

from collections import deque

n, w = map(int,input().split())
wv_list = deque([[int(x) for x in input().split()] for y in range(n)])

dp = [[float("-Inf")] * (w+1) for _ in range(n+1)]
dp[0] = [0]*(w+1)

for i in range(n):
    _w,_v = wv_list.popleft()
    for j in range(w+1):
        if j-_w < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-_w]+_v)

print(dp[n][w])
### BUGGY CODE ###

N=int(input())
contain=[]
for i in range(N+1):
    if str(i)[-1]!='0' or str(i)[-1]!='0':
        contain.append([str(i)[0],str(i)[-1]])

ans=0
for i in range(len(contain)):
    for j in range(len(contain)):    
        if contain[i][0]==contain[j][-1] and contain[i][-1]==contain[j][0]:
            ans+=1
print(ans)

### FIXED CODE ###

N=int(input())

contain=[[0 for i in range(10)] for _ in range(10)]
ans=0

for i in range(N+1):
    if str(i)[-1]!='0' or str(i)[-1]!='0':
        contain[int(str(i)[0])][int(str(i)[-1])]+=1

for i in range(10):
    for j in range(10):
        ans+=contain[i][j]*contain[j][i]
        
print(ans)
### BUGGY CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

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

for i in range(n):
  if a[i]%2 == 0:
    temp = factorization(a[i])
    count = count + temp[0][1]
    
print(count)

### FIXED CODE ###

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

for i in range(n):
  count = 0
  temp = a[i]
  while (temp%2 == 0):
    temp = temp//2
    count = count + 1
    
  ans = ans + count
  
print(ans)
### BUGGY CODE ###

from itertools import accumulate

def solve(left, right):
    if left == right:
        return 0
    ret = dp[left][right]
    if ret > 0:
        return ret
    ret = inf
    for mid in range(left, right):
        ret = min([ret, solve(left, mid)+solve(mid+1, right)])
    ret += s[right] - (s[left-1] if left > 0 else 0)
    dp[left][right] = ret
    return ret

inf = 10**15
N = int(input())
A = list(map(int, input().split()))
s = list(accumulate(A))
dp = [[0]*(N) for _ in range(N)]
print(solve(0, N-1))


### FIXED CODE ###

from itertools import accumulate

def solve(left, right):
    if left == right:
        return 0
    ret = dp[left][right]
    if ret > 0:
        return ret
    ret = inf
    for mid in range(left, right):
        ret = min([ret, solve(left, mid)+solve(mid+1, right)])
    ret += s[right] - (s[left-1] if left > 0 else 0)
    dp[left][right] = ret
    return ret

inf = 10**15
N = int(input())
A = list(map(int, input().split()))
s = list(accumulate(A))
dp = [[0]*(N) for _ in range(N)]
print(solve(0, N-1))
### BUGGY CODE ###

s = input()
cnt = 0
while True:
  pos = s.find("ABC")
  if pos == -1:
    break
  s = s[:pos] + "BCA" + s[pos + 3:]
  cnt += 1
print(cnt)

### FIXED CODE ###

cnt, tmp = 0, 0
for c in input().replace("BC", "X"):
  if c == "A":
    tmp += 1
  elif c == "X":
    cnt += tmp
  else:
    tmp = 0
print(cnt)
### BUGGY CODE ###

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

ans = 1
for i in a:
  ans *= i
if ans > 10**18:
  print(-1)
  exit()  
print(ans)

### FIXED CODE ###

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

if 0 in a:
    print(0)
    exit()
    
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)