CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
ts = [int(eval(input())) for i in range(N)]
ts.sort()
ts.reverse()
ma = sum(ts) // 3 + 50
s = [[[0 for i in range(ma)] for j in range(ma)] for k in range(N + 1)]
for i in range(N):
    for j in range(ma):
        for k in range(ma):
            p = [s[i][j][k] + ts[i]]
            if(j >= ts[i]):
                p.append(s[i][j - ts[i]][k])
            if(k >= ts[i]):
                p.append(s[i][j][k - ts[i]])
            s[i + 1][j][k] = min(p)
i = 0
while True:
    if(s[N][i][i] <= i):
        break
    i += 1
print(i)

# Optimized solution
N = int(eval(input()))
ts = [int(eval(input())) for i in range(N)]
ma = sum(ts) // 3 + 50
s = [[[0 for i in range(ma)] for j in range(ma)] for k in range(N + 1)]
for i in range(N):
    for j in range(ma):
        for k in range(j, ma):
            p = [s[i][j][k] + ts[i]]
            if(j >= ts[i]):
                p.append(s[i][j - ts[i]][k])
            if(k >= ts[i]):
                p.append(s[i][j][k - ts[i]])
            s[i + 1][j][k] = s[i + 1][k][j] = min(p)
i = 0
while True:
    if(s[N][i][i] <= i):
        break
    i += 1
print(i)
# Original solution
n = int(eval(input()));l=[0 for _ in range(100)]
for i in range(1,n+1):
    l[int(str(i)[0]+str(i)[-1])]+=1
print((sum([l[i*10+j]*l[j*10+i]for i in range(10) for j in range(10)])))

# Optimized solution
l=[0 for _ in range(100)];r=list(range(10))
for i in range(1,int(eval(input()))+1):
    s=str(i);l[int(s[0]+s[-1])]+=1
print((sum([l[i*10+j]*l[j*10+i]for i in r for j in r])))
# Original solution
N = int(eval(input()))
count = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, N + 1):
    if str(i)[0] != "0" and str(i)[-1] != "0":
        count[int(str(i)[0]) - 1][int(str(i)[-1]) - 1] += 1
ans = 0
for i in range(0, 9):
    for k in range(0, 9):
        ans += count[i][k] * count[k][i]
print(ans)

# Optimized solution
N = int(eval(input()))
nums = [0 for i in range(100)]
for i in range(1, N + 1):
    i = str(i)
    nums[int(i[0] + i[-1])] += 1
ans = 0
for i in range(1, 10):
    for j in range(i, 10):
        i = str(i)
        j = str(j)
        if i != j:
            ans += nums[int(i + j)] * nums[int(j + i)] * 2
        else:
            n = nums[int(i + j)]
            ans += n * (n - 1)
            ans += n
print(ans)
# Original solution
from itertools import product


def solve(string):
    n = int(string)
    t = [[0] * 10 for _ in range(10)]
    for i in range(n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    return str(sum(t[i][j] * t[j][i] for i, j in product(list(range(1, 10)), repeat=2)))


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
from itertools import product


"""
def solve(string):
    n = int(string)
    t = [[0] * 10 for _ in range(10)]
    for i in range(n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    # print(t)
    # return str(sum(t[i][j] * t[j][i] for i, j in product(range(1, 10), repeat=2)))
"""


def solve(string):
    l = len(string)
    n = int(string)
    c = [0] + [10**i for i in range(6)]
    t = sum(c[:l - 1])
    t = [[t] * 10 for _ in range(10)]
    if l > 1:
        for i in range(10):
            t[i][i] += 1
    for i in range(10 ** (l - 1), n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    return str(sum(t[i][j] * t[j][i] for i, j in product(list(range(1, 10)), repeat=2)))

if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))
# Original solution
from itertools import product


"""
def solve(string):
    n = int(string)
    t = [[0] * 10 for _ in range(10)]
    for i in range(n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    # print(t)
    # return str(sum(t[i][j] * t[j][i] for i, j in product(range(1, 10), repeat=2)))
"""


def solve(string):
    l = len(string)
    n = int(string)
    c = [0] + [10**i for i in range(6)]
    t = sum(c[:l - 1])
    t = [[t] * 10 for _ in range(10)]
    if l > 1:
        for i in range(10):
            t[i][i] += 1
    for i in range(10 ** (l - 1), n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    return str(sum(t[i][j] * t[j][i] for i, j in product(list(range(1, 10)), repeat=2)))

if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
from itertools import product


def solve(string):
    l = len(string)
    *ns, = list(map(int, string))
    n = int(string)
    c = [0] + [10**i for i in range(6)]
    t = sum(c[:l - 1])
    t = [[t] * 10 for _ in range(10)]
    if l > 1:
        for i in range(10):
            t[i][i] += 1
    for i in range(1, ns[0]):
        for j in range(1, 10):
            t[i][j] += c[l - 1]
    for i in range(ns[0] * 10**(l - 1), n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    return str(sum(t[i][j] * t[j][i] for i, j in product(list(range(1, 10)), repeat=2)))


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))
# Original solution
from itertools import product


def solve(string):
    l = len(string)
    *ns, = list(map(int, string))
    n = int(string)
    c = [0] + [10**i for i in range(6)]
    t = sum(c[:l - 1])
    t = [[t] * 10 for _ in range(10)]
    if l > 1:
        for i in range(10):
            t[i][i] += 1
    for i in range(1, ns[0]):
        for j in range(1, 10):
            t[i][j] += c[l - 1]
    for i in range(ns[0] * 10**(l - 1), n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    return str(sum(t[i][j] * t[j][i] for i, j in product(list(range(1, 10)), repeat=2)))


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
from itertools import product


def solve(string):
    d = len(string)
    if d == 1:
        return string
    s0, ss, sn = int(string[0]), int(string[1:-1] or 0), int(string[-1])
    t = [[0] * 10] + [[int("1" * (d - 2) or 0)] * 10 for _ in range(9)]
    for i in range(1, 10):
        t[i][i] += 1
    for i, j in product(list(range(1, s0)), list(range(10))):
        t[i][j] += 10**(d - 2)
    for j in range(sn + 1):
        t[s0][j] += ss + 1
    for j in range(sn + 1, 10):
        t[s0][j] += ss
    return str(sum(t[i][j] * t[j][i] for i, j in product(list(range(1, 10)), repeat=2)))


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))
# Original solution


N = int(eval(input()))

if len(str(N))<4:
    ans = 0
    
    for i in range(1, N+1):
        for j in range(1, N+1):
            if str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]:
                ans += 1
    
    print(ans)
    exit()
    
L = len(str(N))
n = int(str(N)[1:])
ans = 0
F = int(str(N)[0])
L2 = int(str(N)[-1])
S = str(N)
M = int(S[1:len(S)-1])

for i in range(1, N+1):
    f = int(str(i)[0])
    l = int(str(i)[-1])

    if f==0 or l==0:
        continue
    
    for k in range(1, L+1):
        
        if k==1 and f!=l:
            continue
        
        if k==1:
            ans += 1
            continue
        
        if k<L:
            ans += 10**(k-2)
        else:
            if F<l:
                continue
                
            if l<F:
                ans += 10**(k-2)
            else:
                if len(S)<=2:
                    continue
                
                ans += M
                
                if L2>=f:
                    ans += 1

print(ans)

# Optimized solution
N = int(eval(input()))
cnt = [[0]*10 for _ in range(10)]

for i in range(1, N+1):
    f = int(str(i)[0])
    l = int(str(i)[-1])
    cnt[f][l] += 1

ans = 0

for i in range(1, 10):
    for j in range(1, 10):
        ans += cnt[i][j]*cnt[j][i]

print(ans)
# Original solution
N = int(eval(input()))
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    cnt[int(str(i)[0])][int(str(i)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]
        
print(ans)


# Optimized solution
N = int(eval(input()))

dp = [[0] * 10 for _ in range(10)]
for x in range(1, N + 1):
    j = x % 10
    while x >= 10:
        x //= 10
    i = x % 10
    dp[i][j] += 1
    
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += dp[i][j] * dp[j][i]
        
print(ans)
# Original solution
n = int(eval(input()))
if n > 30:
    x = n // 10
    basenum = x * x + 8
    addnum = 0
    #print("{0} {1}".format(x* 10 + 1, n))
    hassame = False
    for i in range(x * 10 + 1, n+1):
        #print(i)
        for j in range(1, n+1):
            #print(j)
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                addnum += 1
                if i == j:
                    hassame=True
                #print("{0},{1}".format(i, j))
    res = basenum + addnum * 2
    if hassame:
        res-=1
    #print("n={0}, x={1}, basenum={2}, addnum={3} res ={4}".format(n,x,basenum,addnum,res))
    print(res)
elif n==1:
    print((1))
else:
    res = 0
    for i in range(1, n):
        for j in range(1, n):
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                res += 1
    print(("{1}".format(n, res)))


# Optimized solution
n = int(eval(input()))
if n < 10:
    print(n)
else:
    x = n // 10
    basenum = x * x + 8
    addnum = 0
    # print("{0} {1}".format(x* 10 + 1, n))
    hassame = False
    for i in range(x * 10 + 1, n + 1):
        # print(i)
        for j in range(1, n + 1):
            # print(j)
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                addnum += 1
                if i == j:
                    hassame = True
                # print("{0},{1}".format(i, j))
    res = basenum + addnum * 2
    if hassame:
        res -= 1
    # print("n={0}, x={1}, basenum={2}, addnum={3} res ={4}".format(n,x,basenum,addnum,res))
    print(res)
# Original solution
N=int(eval(input()))
C=[[0]*9  for i in range(9)]
count=0

for n in range(1,N+1):
   if str(n)[-1]!="0":
      left=int(str(n)[0])-1
      right=int(str(n)[-1])-1
      C[left][right]+=1
      
for i in range(1,10):
   for j in range(1,10):
      count+=C[i-1][j-1]*C[j-1][i-1]

print(count)

# Optimized solution
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    d=dict()
    for i in range(1,N+1):
        i=str(i)
        head=i[0]
        tail=i[-1]
        if tail=="0":
            continue
        if (head,tail) not in d:
            d[(head,tail)]=1
        else:
            d[(head,tail)]+=1

    ans=0
    s=set()
    for k in list(d.keys()):
        m,l=k[0],k[1]
        if (m,l) in s:
            continue
        if (l,m) in d:
            ans+=d[(m,l)]*d[(l,m)]
            if (m,l)!=(l,m):
                ans+=d[(m,l)]*d[(l,m)]
        s.add((m,l))
        s.add((l,m))

    print(ans)

if __name__=="__main__":
    main()
# Original solution
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(eval(input()))
sN = str(N)
l = len(sN)

ans = 0
for n in range(1, min(10, N+1)):
    sn = str(n)
    ans += 1
    
    cnt = 1
    for i in range(2, l):
        ans += cnt
        cnt *= 10

    if l == 2:
        if sN >= sn[-1] + sn[0]:
            ans += 1
    elif l > 2 and sN[0] >= sn[-1]:
        if sN[0] == sn[-1]:
            hoge = int(sN[1:-1])
            if sN[-1] < sn[0]:
                hoge -= 1
            ans += hoge + 1
        elif sN[0] > sn[-1]:
            ans += cnt

for n in range(11, N+1):
    sn = str(n)
    if sn[-1] != "0":
        if n > 10 and sn[0] == sn[-1]:
            ans += 1


        cnt = 1
        for i in range(2, l):
            ans += cnt
            cnt *= 10

        if l == 2:
            if sN >= sn[-1] + sn[0]:
                ans += 1
        elif l > 2 and sN[0] >= sn[-1]:
            if sN[0] == sn[-1]:
                hoge = int(sN[1:-1])
                if sN[-1] < sn[0]:
                    hoge -= 1
                ans += hoge + 1
            elif sN[0] > sn[-1]:
                ans += cnt

print(ans)


# Optimized solution
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(eval(input()))

dp = makelist(10, 10)
for n in range(1, N+1):
    s = str(n)
    dp[int(s[-1])][int(s[0])] += 1

ans = 0
for a in range(1, 10):
    for b in range(1, 10):
        ans += dp[a][b] * dp[b][a]

print(ans)
# Original solution
N = int(eval(input()))
mat = list()
for i in range(10):
    mat.append([0] * 10)

for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    mat[A][B] += 1
ans = 0
for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    ans += mat[B][A]
print(ans)


# Optimized solution
N = int(eval(input()))
mat = list()
for i in range(10):
    mat.append([0] * 10)

for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    mat[A][B] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += mat[i][j] * mat[j][i]
print(ans)
# Original solution
n = int(eval(input()))
table = [[0 for _ in range(9)] for _ in range(9)]

for i in range(1, n+1):
    s = str(i)
    f, l = s[0], s[-1]
    if "0" in [f, l]: continue
    table[int(f)-1][int(l)-1] += 1

ans = 0
for i in range(9):
    for j in range(9):
        ans += table[i][j] * table[j][i]

print(ans)


# Optimized solution
n = int(eval(input()))
t = [[0] * 10 for _ in range(10)]

for i in range(1, n+1):
    si = str(i)
    t[int(si[0])][int(si[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += t[i][j] * t[j][i]

print(ans)
# Original solution
N = int(eval(input()))
ans = 0
ary = [0]*100
for n in range(1, N+1):
    s = str(n)
    ary[int(s[0])*10+int(s[-1])] += 1
for i in range(10, 100):
    s = str(i)
    j = int(s[-1])*10+int(s[0])
    ans += ary[i]*ary[j]
print(ans)


# Optimized solution
N = int(eval(input()))
A = [[0]*10 for _ in range(10)]
ans = 0
for i in range(1, N+1):
    s = str(i)
    A[int(s[0])][int(s[-1])] += 1
for i in range(1, 10):
    for j in range(1, 10):
        ans += A[i][j]*A[j][i]
print(ans)
# Original solution
import itertools
N = int(eval(input()))
Nketa = len(str(N))

range_count = [[0 for j in range(10)]for i in range(10)]


for p in range(1,N+1):
    mae = int(str(p)[0])
    ato = int(str(p)[-1])
    range_count[mae][ato] += 1

    

count = 0
for j in range(1,N+1):
    a_mae = int(str(j)[0])
    a_ato = int(str(j)[-1])
    
    b_mae = a_ato
    b_ato = a_mae
    
    if b_mae == 0:
        continue
    else:
        count += range_count[b_mae][b_ato]
print(count)
  

# Optimized solution
n = int(eval(input()))

all_count = 0
options = [str(i) for i in range(10)]

maeato = [[0 for i in range(10)] for j in range(10)]

for i in range(n+1):
    checking = str(i)
    maeato[int(checking[0])][int(checking[-1])]+=1
all_count = 0
for i in range(1,10):
    for j in range(1,10):
        for k in range(1,10):
            for p in range(1,10):
                if i == p and j == k:
                    all_count+=maeato[i][j]*maeato[k][p]
print(all_count)
# Original solution
n = int(eval(input()))
m = len(str(n))
ans = 0



for i in range(n + 1):
    A = str(i)
    first = A[0]
    end = A[-1]

    if end == '0':
        continue
    if first == end:
        ans += 1


    if m >= 3:
        for j in range(m - 2):
            ans += 10 ** (j)
    mini = int(end + '0' * (m - 2) + first)
    maxi = int(end + '9' * (m - 2) + first)
    # print(mini, maxi)
    if n < mini:
        continue
    elif mini <= n <= maxi:
        # print(i, mini, maxi)
        if int(str(n)[-1]) >= int(first):
            ans += int(str(n)[1:-1]) + 1
            # print('a')
        else:
            ans += int(str(n)[1:-1])
            # print('a')
    else:
        ans += (10 ** (m - 2))

print(ans)


# Optimized solution
n=int(eval(input()))
l=[[0]*10 for i in range(10)]
for i in range(n):
    t=str(i+1)
    l[int(t[0])][int(t[-1])]+=1
a=0
for i in range(10):
    for j in range(10):
        a+=l[i][j]*l[j][i]
print(a)
# Original solution
N = int(eval(input()))
digit = len(str(N))

ans = 0
for a in range(1, 10):
    for b in range(1, 10):
        x, y = 0, 0
        if a == b:
            if a <= N:
                x += 1
                y += 1

        if a*10+b <= N:
            x += 1

        if b*10+a <= N:
            y += 1

        if digit <= 2:
            ans += x*y
            continue

        d = 3
        while d < digit:
            x += 10**(d-2)
            y += 10**(d-2)
            d += 1

        for i in range(10**(digit-2)):
            if int(str(a)+str(i).zfill(digit-2)+str(b)) <= N:
                x += 1
            if int(str(b)+str(i).zfill(digit-2)+str(a)) <= N:
                y += 1
        ans += x*y

print(ans)


# Optimized solution
N = int(eval(input()))

C = [[0] * 10 for i in range(10)]

for n in range(1, N+1):
    i = int(str(n)[0])
    j = int(str(n)[-1])
    C[i][j] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += C[i][j]*C[j][i]
print(ans)
# Original solution
c=[10*[0]for _ in range(10)]
n=int(eval(input()))
for i in range(1,n+1):
  a=int(str(i)[0])
  b=int(str(i)[-1])
  c[a][b]+=1
ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=c[i][j]*c[j][i]
print(ans)

# Optimized solution
n=int(eval(input()))
d=[10*[0]for _ in range(10)]
for i in range(1,n+1):d[int(str(i)[0])][int(str(i)[-1])]+=1
ans=0
for i in range(1,10):
  for j in range(1,10):ans+=d[i][j]*d[j][i]
print(ans)
# Original solution
n = int(eval(input()))
dp = [[0] * 10 for _ in range(10)]
ans = 0

for i in range(1, n+1):
    top = int(str(i)[0])
    end = int(str(i)[-1])
    ans += 2 * dp[end][top]
    if top == end:
        ans += 1
    dp[top][end] += 1

print(ans)

# Optimized solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    dp = [[0] * 10 for _ in range(10)]

    ans = 0
    for i in range(1, N + 1):
        s = str(i)
        first = int(s[0])
        second = int(s[-1])

        ans += 2 * dp[second][first]

        if first == second:
            ans += 1

        dp[first][second] += 1

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
N_ = str(N)
f_N, l_N = int(N_[0]), int(N_[-1])
digit = len(N_)
if digit > 2:
    inter_N = int(N_[1:digit-1])
cnt = 0
for num in range(1, N+1):
    num = str(num)
    f, l = int(num[-1]), int(num[0])
    if f == 0:
        continue
    for i in range(1, digit+1):
        if i == 1:
            if f == l:
                cnt += 1
            else:
                continue
        else:
            if i != digit:
                cnt += 10**(i-2)
            elif digit == 2 and i == digit:
                if f*10+l <= N:
                    cnt += 1
                else:
                    continue
            else:
                if f > f_N:
                    continue
                elif f == f_N:
                    if l > l_N:
                        cnt += inter_N
                    elif l <= l_N:
                        cnt += (inter_N+1)
                else:
                    cnt += 10**(i-2)
print(cnt)

# Optimized solution
N = int(eval(input()))
cnt = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
    cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)
# Original solution
N = int(eval(input()))

c = [[0 for i in range(9)] for i in range(9)]

for i in range(9):
  for j in range(9):
    for n in range(1, N+1):
      if (n % 10) == j+1 and int(str(n)[0]) == i+1:
        c[i][j] += 1
        
ans = 0
for i in range(9):
  for j in range(9):
    ans = ans + c[i][j]*c[j][i]
print(ans)

# Optimized solution
N = int(eval(input()))

c = [[0 for i in range(10)] for i in range(10)]

for n in range(1, N+1):
  i = int(str(n)[0])
  j = n % 10
  c[i][j] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans = ans + c[i][j]*c[j][i]
print(ans)
# Original solution
n = int(eval(input()))

cnt = 0
for i in range(1, n+1):
    i_str = str(i)
    if len(i_str) == 1:
        cnt += 1
        continue
    if len(i_str) == 2:
        if int(i_str[0]) == int(i_str[1]):
            cnt += 3
        elif int(i_str[1]) != 0 and int(i_str[0]) > int(i_str[1]):
            cnt += 2
        continue
    if len(i_str) == 3:
        if int(i_str[0]) == int(i_str[2]):
            cnt += 4 + (2 * (int(i_str[1])+1) - 1)
        elif int(i_str[2]) != 0 and int(i_str[0]) > int(i_str[2]):
            cnt += 22
        elif int(i_str[0]) < int(i_str[2]):
            cnt += 2
        continue
    if len(i_str) == 4:
        if int(i_str[0]) == int(i_str[3]):
            cnt += 24 + 20 * int(i_str[1]) + 2 * (int(i_str[2])+1) - 1
        elif int(i_str[3]) != 0 and int(i_str[0]) > int(i_str[3]):
            cnt += 222
        elif int(i_str[0]) < int(i_str[3]):
            cnt += 22
        continue
    if len(i_str) == 5:
        if int(i_str[0]) == int(i_str[4]):
            cnt += 224 + 200 * int(i_str[1]) + 20 * int(i_str[2]) + 2 * (int(i_str[3])+1) - 1
        elif int(i_str[4]) != 0 and int(i_str[0]) > int(i_str[4]):
            cnt += 2222
        elif int(i_str[0]) < int(i_str[4]):
            cnt += 222
        continue
    if len(i_str) == 6:
        if int(i_str[0]) == int(i_str[5]):
            cnt += 2224 + 2000 * int(i_str[1]) + 200 * int(i_str[2]) + 20 * int(i_str[3]) + 2 * (int(i_str[4])+1) - 1
        elif int(i_str[5]) != 0 and int(i_str[0]) > int(i_str[5]):
            cnt += 22222
        elif int(i_str[0]) < int(i_str[5]):
            cnt += 2222
        continue

print(cnt)

# Optimized solution
n = int(eval(input()))

c = [[0 for _ in range(10)] for __ in range(10)]
for i in range(1, n+1):
    str_i = str(i)
    head = int(str_i[0])
    tail = int(str_i[-1])
    c[head][tail] += 1

cnt = 0
for i in range(10):
    for j in range(10):
        cnt += c[i][j] * c[j][i]

print(cnt)
# Original solution
n = int(eval(input()))
cou = 0
for i in range(1,n+1):
  i = str(i)
  if i[0]!="0" and i[-1]!="0":
    if int(i[0])>int(i[-1]):
      cou +=  (10**(len(i)-1)-1)//9
    elif int(i[0])<int(i[-1]):
      cou += (10**(len(i)-2)-1)//9
  #print(i,cou)

cou *= 2
    
l = [0 for i in range(9)]
for i in range(1,n+1):
  i = str(i)
  if i[0]==i[-1]:
    l[int(i[0])-1] += 1
l1 = [i*i for i in l]
print((sum(l1)+cou))

# Optimized solution
n = int(eval(input()))
dp = [[0]*10 for i in range(10)]
su = 0
for i in range(1,n+1):
  a,b = str(i)[0],str(i)[-1]
  dp[int(a)-1][int(b)-1] += 1
for i in range(10):
  for j in range(10):
    su += dp[i][j]*dp[j][i]
print(su)
# Original solution
def main():
    N = int(eval(input()))
    c = [[0]*10 for i in range(10)]
    for i in range(1, N+1):
        S = str(i)
        c[int(S[0])][int(S[-1])] += 1

    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += c[i][j]*c[j][i]
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(eval(input()))
    c = [[0]*10 for _ in range(10)]
    for n in range(1, N+1):
        s = str(n)
        c[int(s[0])][int(s[-1])] += 1
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            # if c[i][j]*c[j][i]:
            #     print(i, j, c[i][j]*c[j][i])
            ans += c[i][j] * c[j][i]
    print(ans)
    # print(*c, sep="\n")


if __name__ == '__main__':
    main()
# Original solution
def main():
    N = int(eval(input()))
    d = {}
    for i in range(0,10):
        for j in range(0,10):
            d[i*10+j] = 0
    
    for i in range(N+1):
        s = str(i)
        d[int(s[0])*10+int(s[-1])] += 1
    
    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += d[i*10+j] *d[j*10+i]

    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    N = int(eval(input()))
    d = [0] * 100
    
    for i in range(N+1):
        s = str(i)
        d[int(s[0])*10+int(s[-1])] += 1
    
    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += d[i*10+j] *d[j*10+i]

    print(ans)

if __name__ == '__main__':
    main()