Problem:
Score : 400 points

Problem Statement

Given is a positive integer N.

Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:

When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Constraints

1 \leq N \leq 2 \times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

25

Sample Output 1

17

The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

Sample Input 2

1

Sample Output 2

1

Sample Input 3

100

Sample Output 3

108

Sample Input 4

2020

Sample Output 4

40812

Sample Input 5

200000

Sample Output 5

400000008

Solution in PyPy3 (2.4.0) (judge verdict: Accepted)

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
nx = str(n)[0]
ny = str(n)[-1]
digit = len(str(n))
is_full = [1, 11, 111, 1111, 11111]

for i in range(1, n + 1):
    x = str(i)[0]
    y = str(i)[-1]
    if y == "0":  # 0が先頭になるときを考えない
        continue

    if x == y:  # xとyが同じとき3などの一桁の値をとりうるので+1する
        ans += 1

    if y < nx:  # 注目している数字の末尾，つまり考えている数字y??xの先頭の文字yがnxより小さいとき
        if digit - 2 < 0:  # 無条件で取れる，ものが無ければcontinue
            continue
        ans += is_full[digit - 2]
    elif y == nx:
        if digit - 3 >= 0:
            ans += is_full[digit - 3]
        for num, k in enumerate(list(str(n))[1: -1], 1):  # y???xとnx???nyを比較していく
            ans += int(k) * 10 ** (digit - 2 - num)

        if digit >= 2 and x <= ny:  # 10の位をもうひとつ上げられるとき
            ans += 1
    else:  # 注目している数字の末尾，つまり考えている数字y??xの先頭の文字yがnxより大きいとき
        if digit - 3 < 0:  # このときは無条件に取れるis_fullの位が一段階下がる
            continue
        ans += is_full[digit - 3]

print(ans)