AtCoder Beginner Contest 152 - Handstand 2

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-----
25

-----Sample Output-----
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).

Difficulty: MEDIUM

Starter code:

Solutions:
n = int(input())
l = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	st = str(i)
	start = int(st[0])
	end = int(st[-1])
	l[start][end] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += l[i][j] * l[j][i]
print(ans)


N = int(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)


n = int(input())
graph = [[0] * 9 for i in range(9)]
for i in range(1, n + 1):
	if i % 10 != 0:
		i = str(i)
		sentou = int(i[0])
		matubi = int(i[-1])
		graph[sentou - 1][matubi - 1] += 1
import numpy as np
graph = np.array(graph)
print(np.trace(np.dot(graph, graph)))


n = int(input())
c = [[0] * 10 for i in range(10)]
for a in range(1, n + 1):
	a = str(a)
	c[int(a[-1])][int(a[0])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += c[i][j] * c[j][i]
print(ans)


N = int(input())
grp = [[0] * 10 for i in range(10)]
for x in range(N + 1):
	grp[int(str(x)[0])][int(str(x)[-1])] += 1
result = 0
for i in range(1, 10):
	for j in range(1, 10):
		result += grp[i][j] * grp[j][i]
print(result)


N = int(input())
ans = 0
lst = [0] * 100
for i in range(1, N + 1):
	A = str(i)
	(a, b) = (A[0], A[-1])
	if b == '0':
		pass
	else:
		lst[int(b + a)] += 1
for i in range(1, N + 1):
	A = str(i)
	(a, b) = (A[0], A[-1])
	c = int(a + b)
	ans += lst[c]
print(ans)


d = [0] * 100
for i in range(int(input())):
	s = str(i + 1)
	d[int(s[0] + s[-1])] += 1
print(sum((d[i] * d[i % 10 * 10 + i // 10] for i in range(100))))


N = int(input())
d = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
	n = str(i)
	d[int(n[0])][int(n[-1])] += 1
r = 0
for i in range(9):
	for j in range(9):
		r += d[i + 1][j + 1] * d[j + 1][i + 1]
print(r)


n = int(input())
ct = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	ct[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += ct[i][j] * ct[j][i]
print(ans)


def main():
	import numpy as np
	N = int(input())
	cnt = np.zeros((10, 10), dtype=np.int64)
	for n in map(str, list(range(1, N + 1))):
		cnt[int(n[0])][int(n[-1])] += 1
	print(np.sum(cnt * cnt.T))

def __starting_point():
	main()
__starting_point()


def solve():
	table = [[0] * 10 for _ in range(10)]
	for i in range(N + 1):
		s = list(map(int, str(i)))
		table[s[0]][s[-1]] += 1
	return sum((table[i][j] * table[j][i] for i in range(1, 10) for j in range(1, 10)))
N = int(input())
print(solve())


N = int(input())
keep = [[0 for i in range(10)] for j in range(10)]
ans = 0
for i in range(1, N + 1):
	first = int(str(i)[0])
	end = int(str(i)[-1])
	keep[first - 1][end - 1] += 1
for i in range(9):
	for j in range(9):
		ans += keep[i][j] * keep[j][i]
print(ans)


n = int(input())
l = [[0] * 10 for i in range(10)]
for i in range(1, min(10, n + 1), 1):
	l[i][i] += 1
if len(str(n)) >= 2:
	for k in range(2, len(str(n)), 1):
		for i in range(1, 10, 1):
			for j in range(1, 10, 1):
				l[i][j] += 10 ** (k - 2)
	for i in range(1, int(str(n)[0]), 1):
		for j in range(1, 10, 1):
			l[i][j] += 10 ** (len(str(n)) - 2)
	if len(str(n)) >= 3:
		for j in range(1, 10, 1):
			if j <= int(str(n)[-1]):
				l[int(str(n)[0])][j] += int(str(n)[1:-1]) + 1
			else:
				l[int(str(n)[0])][j] += int(str(n)[1:-1])
	else:
		for j in range(1, 10, 1):
			if j <= int(str(n)[-1]):
				l[int(str(n)[0])][j] += 1
t = 0
for i in range(1, 10, 1):
	for j in range(1, 10, 1):
		t += l[i][j] * l[j][i]
print(t)


n = int(input())
l = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	l[int(str(i)[0])][i % 10] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += l[i][j] * l[j][i]
print(ans)


def main():
	import sys
	from collections import defaultdict

	def input():
		return sys.stdin.readline().rstrip()
	n = int(input())
	nd = defaultdict(int)
	for i in range(1, n + 1):
		tmp = str(i)
		(h, t) = (int(tmp[0]), int(tmp[-1]))
		nd[h, t] += 1
	ans = 0
	for i in range(1, 10):
		for j in range(1, 10):
			ans += nd[i, j] * nd[j, i]
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
import collections
import bisect

def main():
	n = int(input())
	(ac, bc) = (collections.Counter([str(i + 1)[0] + str(i + 1)[-1] for i in range(n)]), collections.Counter([str(i + 1)[-1] + str(i + 1)[0] for i in range(n)]))
	print(sum((ac[i] * bc[i] for i in list(ac.keys()))))

def __starting_point():
	main()
__starting_point()


n = int(input())
l = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	s = str(i)
	l[int(s[0])][int(s[-1])] += 1
r = 0
for i in range(1, 10):
	for j in range(1, 10):
		r += l[i][j] * l[j][i]
print(r)


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

def kazu(start_num, end_num):
	nonlocal memo
	if memo[start_num][end_num] > 0:
		return memo[start_num][end_num]
	else:
		ans = 0
		if start_num == end_num:
			if start_num <= n:
				ans += 1
		if start_num * 10 + end_num <= n:
			ans += 1
		for i in range(10):
			if start_num * 100 + i * 10 + end_num <= n:
				ans += 1
			else:
				break
		for i in range(100):
			if start_num * 1000 + i * 10 + end_num <= n:
				ans += 1
			else:
				break
		for i in range(1000):
			if start_num * 10000 + i * 10 + end_num <= n:
				ans += 1
			else:
				break
		for i in range(10000):
			if start_num * 100000 + i * 10 + end_num <= n:
				ans += 1
			else:
				break
		memo[start_num][end_num] = ans
		return ans
n = int(input())
str_n = str(n)
kotae = 0
for a in range(1, n + 1):
	if a % 10 != 0:
		str_a = str(a)
		kotae += kazu(int(str_a[-1]), int(str_a[0]))
print(kotae)


n = int(input())
mat = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	(a, b) = (int(str(i)[0]), i % 10)
	mat[a][b] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += mat[i][j] * mat[j][i]
print(ans)


N = int(input())
Mat = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
	s = str(i)
	Mat[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += Mat[i][j] * Mat[j][i]
print(ans)


N = int(input())
from collections import defaultdict
dic = defaultdict(int)
for i in range(1, N + 1):
	s = str(i)
	dic[s[0], s[-1]] += 1
ans = 0
for key in dic.keys():
	(a, b) = key
	if (b, a) in dic:
		ans += dic[a, b] * dic[b, a]
print(ans)


N = int(input())
ans = 0
for i in range(1, N + 1):
	a = list(map(int, str(i)))
	x = a[0]
	y = a[-1]
	if x == y:
		ans += 1
	if y != 0:
		for j in (5, 4, 3, 2, 1):
			z = (y + 1) * 10 ** j
			if z <= N:
				ans += 10 ** (j - 1)
			elif y * 10 ** j + x <= N and N < z:
				s = N - y * 10 ** j
				ans += int(s / 10)
				if N % 10 >= x:
					ans += 1
print(ans)


N = int(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(10):
	for j in range(10):
		ans += c[i][j] * c[j][i]
print(ans)


n = int(input())
l = []
for i in range(1, n + 1):
	t = list(str(i))
	l.append((t[0], t[-1]))
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += l.count((str(i), str(j))) * l.count((str(j), str(i)))
print(ans)


n = int(input())
if n <= 9:
	print(n)
	return
dp = [[0] * 10 for _ in range(10)]
for k in range(1, n + 1):
	s = str(k)
	dp[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += dp[i][j] * dp[j][i]
print(ans)


n = int(input())
c = [[0] * 10 for _ in range(10)]
ans = 0
for i in range(1, n + 1):
	s = str(i)
	c[int(s[0])][int(s[-1])] += 1
for i in range(1, 10):
	for j in range(1, 10):
		ans += c[i][j] * c[j][i]
print(ans)


n = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for k in range(1, n + 1):
	c[int(str(k)[0])][int(str(k)[-1])] += 1
cnt = 0
for i in range(10):
	for j in range(10):
		cnt += c[i][j] * c[j][i]
print(cnt)


n = int(input())
li = [0] * 100
for i in range(n + 1):
	li[int(str(i)[0] + str(i)[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += li[int(str(i) + str(j))] * li[int(str(j) + str(i))]
print(ans)


N = int(input())
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
	x = i
	while x >= 10:
		x //= 10
	cnt[x][i % 10] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += cnt[i][j] * cnt[j][i]
print(ans)


N = int(input())
dp = [[0] * 9 for _ in range(9)]
for i in range(1, N + 1):
	if i % 10:
		st = str(i)
		start = int(st[0])
		end = int(st[-1])
		dp[start - 1][end - 1] += 1
ans = 0
for i in range(9):
	for j in range(9):
		ans += dp[i][j] * dp[j][i]
print(ans)


n = int(input())
t = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	s = str(i)
	t[int(s[0])][int(s[-1])] += 1
result = 0
for i in range(1, 10):
	for j in range(1, 10):
		result += t[i][j] * t[j][i]
print(result)


N = int(input())
X = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
	s = str(i)
	(a, b) = (int(s[0]), int(s[-1]))
	X[a][b] += 1
ans = 0
for a in range(10):
	for b in range(10):
		ans += X[a][b] * X[b][a]
print(ans)


N = int(input())
X = [[0 for j in range(10)] for i in range(10)]
for k in range(1, N + 1):
	X[int(str(k)[0])][int(str(k)[-1])] += 1
Ans = 0
for i in range(10):
	for j in range(10):
		Ans += X[i][j] * X[j][i]
print(Ans)


from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
	n = int(input())
	ans = 0
	for i in range(1, n + 1):
		s = str(i)
		if s[-1] == '0':
			continue
		if s[0] == s[-1]:
			ans += 1
		if i < 10:
			continue
		if s[0] == s[-1]:
			ans += 2
		l = len(s)
		for i in range(2, l):
			ans += 10 ** (i - 2) * 2
		if s[0] < s[-1]:
			continue
		if s[0] > s[-1]:
			ans += 10 ** (l - 2) * 2
		elif l > 2:
			dp = int(s[1])
			for i in range(2, l - 1):
				dp *= 10
				dp += int(s[i])
			ans += dp * 2
	print(ans)
main()


n = int(input())
num = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	j = str(i)
	x = j[0]
	y = j[-1]
	if x != '0' and y != '0':
		num[int(x)][int(y)] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += num[i][j] * num[j][i]
print(ans)


from collections import defaultdict as d
dic = d(int)
for i in range(1, int(input()) + 1):
	dic[int(str(i)[0]), i % 10] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += dic[i, j] * dic[j, i]
print(ans)


n = int(input())
c = [0 for i in range(100)]
for i in range(n + 1):
	s = str(i)
	if s[-1] == 0:
		continue
	c[int(s[0]) * 10 + int(s[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += c[i * 10 + j] * c[i + j * 10]
print(ans)


n = int(input())
m = [[0] * 10 for _ in range(0, 10)]
for i in range(1, n + 1):
	s = str(i)
	a = int(s[0])
	b = int(s[-1])
	m[a][b] += 1
ans = 0
for a in range(1, 10):
	for b in range(1, 10):
		ans += m[a][b] * m[b][a]
print(ans)


N = int(input())
d = {}
for i in range(1, 10):
	for j in range(1, 10):
		d[i * 10 + j] = 0
for i in range(1, min(10, N + 1)):
	d[i * 10 + i] = 1
for i in range(11, N + 1):
	i = str(i)
	(h, t) = (int(i[0]) * 10, int(i[-1]))
	if t != 0:
		d[h + t] += 1
ans = 0
for i in range(1, 9):
	for j in range(i + 1, 10):
		ans += d[i * 10 + j] * d[j * 10 + i] * 2
for i in range(1, 10):
	ans += d[i * 10 + i] ** 2
print(ans)


n = int(input())
A = [[0 for i in range(9)] for i in range(9)]
for i in range(1, n + 1):
	q = int(str(i)[0])
	w = i % 10
	if w == 0:
		continue
	A[q - 1][w - 1] += 1
ans = 0
for i in range(9):
	for j in range(9):
		ans += A[i][j] * A[j][i]
print(ans)


n = int(input())
c = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	p = int(str(i)[0])
	q = int(str(i)[-1])
	c[p][q] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += c[i][j] * c[j][i]
print(ans)


N = int(input())
c = [[0] * 10 for _ in range(10)]
for k in range(1, N + 1):
	c[int(str(k)[0])][int(str(k)[-1])] += 1
ans = 0
for k in range(81):
	i = k // 9 + 1
	j = k % 9 + 1
	ans += c[i][j] * c[j][i]
print(ans)


n = int(input())
cnt = [[0] * 9 for _ in range(9)]
for i in range(1, n + 1):
	s = str(i)
	if s[-1] != '0':
		cnt[int(s[0]) - 1][int(s[-1]) - 1] += 1
ans = 0
for i in range(9):
	for j in range(9):
		ans += cnt[i][j] * cnt[j][i]
print(ans)


N = int(input())
table = [[0] * 9 for i in range(9)]
for i in range(1, N + 1):
	if int(str(i)[len(str(i)) - 1]) == 0:
		continue
	table[int(str(i)[0]) - 1][int(str(i)[len(str(i)) - 1]) - 1] += 1
ans = 0
for i in range(9):
	for j in range(i, 9):
		if i == j:
			ans += table[i][j] * table[j][i]
		else:
			ans += table[i][j] * table[j][i] * 2
print(ans)


from collections import defaultdict
x = int(input())
s = set()
d = defaultdict(int)
for i in range(1, x + 1):
	p = str(i)
	k = p[0] + p[len(p) - 1]
	d[k] += 1
	s.add(k)
a = 0
for i in s:
	c = i[::-1]
	a += d[i] * d[c]
print(a)


n = int(input())
count = 0
ab = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	k = str(i)
	a = int(k[0])
	b = int(k[-1])
	ab[b][a] += 1
for i in range(10):
	for j in range(10):
		count += ab[i][j] * ab[j][i]
print(count)


c = [[0] * 10 for _ in [0] * 10]
for i in range(1, int(input()) + 1):
	c[int(str(i)[0])][int(str(i)[-1])] += 1
print(sum((c[i][j] * c[j][i] for i in range(10) for j in range(10))))


n = int(input())
ans = 0
d = {}
for i in range(1, n + 1):
	t = str(i)
	key = t[0] + t[-1]
	if '0' not in key:
		d[key] = d.get(key, 0) + 1
for k in d:
	k2 = k[1] + k[0]
	ans += d[k] * d.get(k2, 0)
print(ans)


N = int(input())
Cij = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
	(a, b) = (int(str(i)[0]), int(str(i)[-1]))
	Cij[a][b] += 1
print(sum((Cij[i][j] * Cij[j][i] for i in range(10) for j in range(10))))


n = int(input())
D = {}
for i in range(1, n + 1):
	s = (str(i)[0], str(i)[-1])
	if s in D:
		D[s] += 1
	else:
		D[s] = 1
ans = 0
for (aj, bj) in D:
	if (bj, aj) in D:
		ans += D[aj, bj] * D[bj, aj]
print(ans)


h = [[0] * 10 for _ in range(10)]
n = int(input())
for i in range(1, n + 1):
	k = i % 10
	s = i // 10 ** (len(str(i)) - 1)
	h[s][k] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += h[i][j] * h[j][i]
print(ans)


n = int(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
res = 0
for i in range(1, 10):
	for j in range(1, 10):
		res += cnt[i][j] * cnt[j][i]
print(res)


N = int(input())
d = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
	s = str(n)
	d[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += d[i][j] * d[j][i]
print(ans)


n = int(input())
lst = [[0 for i in range(9)] for j in range(9)]
for i in range(1, n + 1):
	s = str(i)
	if i % 10:
		lst[int(s[0]) - 1][i % 10 - 1] += 1
res = 0
for i in range(9):
	for j in range(9):
		res += lst[i][j] * lst[j][i]
print(res)


import math

def main():
	N = int(input())
	c = [[0] * 10 for i in range(10)]
	for i in range(1, N + 1):
		digit = int(math.log10(i)) + 1
		c[i // 10 ** (digit - 1)][i % 10] += 1
	cnt = 0
	for i in range(10):
		for j in range(10):
			cnt += c[i][j] * c[j][i]
	print(cnt)
main()


N = int(input())
c = [[0 for _ in range(10)] for _ in range(10)]
for h in range(1, N + 1):
	num = str(h)
	c[int(num[-1])][int(num[0])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += c[i][j] * c[j][i]
print(ans)


N = int(input())
m = 0
x = [[0] * 9 for i in range(9)]
for i in range(1, N + 1):
	if i % 10 == 0:
		continue
	b = int(str(i)[0])
	g = int(i % 10)
	x[b - 1][g - 1] += 1
ans = 0
for i in range(9):
	for j in range(9):
		ans += x[i][j] * x[j][i]
print(ans)


import sys
readline = sys.stdin.readline
N = int(readline())
from collections import defaultdict
dic = defaultdict(int)
for i in range(1, N + 1):
	s = str(i)
	dic[int(s[0]), int(s[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += dic[i, j] * dic[j, i]
print(ans)


N = int(input())
M = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
	S = str(i)
	f = int(S[0])
	b = int(S[-1])
	M[f][b] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += M[i][j] * M[j][i]
print(ans)


import numpy as np
N = int(input())
cnt = np.zeros((10, 10))
for x in map(str, range(0, N + 1)):
	cnt[int(x[0]), int(x[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += cnt[i, j] * cnt[j, i]
print(int(ans))


N = int(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)


N = int(input())
memo = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
	s = str(i)
	memo[int(s[0])][int(s[-1])] += 1
rlt = 0
for i in range(1, 10):
	for j in range(1, 10):
		rlt += memo[i][j] * memo[j][i]
print(rlt)


from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n + 1):
	s = str(i)
	d[s[0], s[-1]] += 1
ans = 0
x = list(d.keys())
for i in x:
	ans += d[i[::-1]] * d[i]
print(ans)


N = int(input())
a = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
	s = str(i)
	a[int(s[0])][int(s[-1])] += 1
ans = sum((a[i][j] * a[j][i] for i in range(10) for j in range(10)))
print(ans)


from collections import defaultdict
n = int(input())
dct = defaultdict(int)
for i in range(1, n + 1):
	s = str(i)
	dct[s[0], s[-1]] += 1
ans = 0
for i in range(1, n + 1):
	s = str(i)
	ans += dct[s[-1], s[0]]
print(ans)


from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n + 1):
	if str(i)[-1] == '0':
		continue
	d[int(str(i)[0] + str(i)[-1])] += 1
ans = 0
for i in range(11, 100):
	ans += d[i] * d[int(str(i)[1] + str(i)[0])]
print(ans)


n = int(input())
v = [0] * 100
ans = 0
for i in range(1, n + 1):
	x = int(str(i)[0])
	y = int(str(i)[-1])
	v[x * 10 + y] += 1
for i in range(len(v)):
	x = int(str(i)[0])
	y = int(str(i)[-1])
	ans += v[i] * v[10 * y + x]
print(ans)


N = int(input())
DP = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
	DP[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += DP[i][j] * DP[j][i]
print(ans)


N = int(input())
num = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
	num[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(1, N + 1):
	ans += num[int(str(i)[-1])][int(str(i)[0])]
print(ans)


n = int(input())
t = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
	t[int(str(i)[0])][int(str(i)[-1])] += 1
g = 0
for i in range(1, 10):
	for j in range(1, 10):
		g += t[i][j] * t[j][i]
print(g)


N = int(input())
t = [[0] * 10 for _ in range(10)]
cnt = 0
for i in range(N + 1):
	s = str(i)
	t[int(s[0])][int(s[-1])] += 1
for i in range(1, 10):
	for j in range(1, 10):
		cnt += t[i][j] * t[j][i]
print(cnt)


def solve():
	N = int(input())
	cnt = [[0] * 10 for i in range(10)]
	for i in range(1, N + 1):
		target_str = str(i)
		cnt[int(target_str[0])][int(target_str[-1])] += 1
	ans = 0
	for i in range(1, 10):
		for j in range(1, 10):
			ans += cnt[i][j] * cnt[j][i]
	print(ans)

def __starting_point():
	solve()
__starting_point()


n = int(input())
x = [0] * 101
ans = 0
for i in range(1, n + 1):
	v = str(i)
	w = int(v[0] + v[-1])
	x[w] += 1
for i in range(101):
	if x[i] != 0:
		v = str(i)
		w = int(v[-1] + v[0])
		ans += x[i] * x[w]
print(ans)


n = int(input())
l = [[0] * 10 for _ in range(10)]
for x in range(1, n + 1):
	l[int(str(x)[0])][int(str(x)[-1])] += 1
print(sum((l[i][j] * l[j][i] for i in range(10) for j in range(10))))


l = [0] * 100
r = range(10)
for i in range(int(input())):
	s = str(i + 1)
	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]))


N = int(input())
c = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
	c[int(str(i)[0])][int(str(i)[-1])] += 1
cnt = 0
for i in range(10):
	for j in range(10):
		cnt += c[i][j] * c[j][i]
print(cnt)


import sys
import math

def count(a, b, N):
	keta = len(str(N))
	cnt = 0
	if a == b:
		cnt += 1 if a <= N else 0
	if keta == 1:
		return cnt
	if keta == 2:
		cnt += 1 if b * 10 + a <= N else 0
		return cnt
	for k in range(2, keta):
		cnt += 10 ** (k - 2)
	s = N // 10 ** (keta - 1)
	t = N % 10
	if b > s:
		return cnt
	elif b < s:
		cnt += 10 ** (keta - 2)
	else:
		tempN = (N - s * 10 ** (keta - 1) - t) // 10
		cnt += tempN + 1
		if a > t:
			cnt -= 1
	return cnt

def count_aa(a, N):
	keta = len(str(N))
	cnt = 0
	if keta == 1:
		return 1 if a <= N[-1] else 0
	cnt += 1
	if keta == 2:
		return cnt + 1 if a <= N[-1] else 0
	for k in range(2, keta):
		cnt += 10 ** (k - 2)
	s = N // 10 ** (keta - 1)
	t = N % 10
	if b > s:
		return cnt
	elif b < s:
		cnt += 10 ** (keta - 2)
	else:
		tempN = (N - s * 10 ** (keta - 1) - t) // 10
		cnt += tempN + 1
		if a > t:
			cnt -= 1
	return cnt
N = int(input())
c = 0
for i in range(1, N + 1):
	a = int(str(i)[0])
	b = i % 10
	if b == 0:
		continue
	c += count(a, b, N)
print(c)


n = int(input())
d = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	(a, b) = map(int, [str(i)[0], str(i)[-1]])
	d[a][b] += 1
cnt = 0
for i in range(1, 10):
	for j in range(1, 10):
		cnt += d[i][j] * d[j][i]
print(cnt)


N = int(input())
dp = [[0 for i in range(10)] for j in range(10)]
for i in range(1, N + 1):
	i = str(i)
	dp[int(i[0])][int(i[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += dp[i][j] * dp[j][i]
print(ans)


from collections import defaultdict
N = int(input())
head_tail = defaultdict(int)
for i in range(1, N + 1):
	tail = i % 10
	head = int(str(i)[0])
	head_tail[head, tail] += 1
answer = 0
for i in range(1, N + 1):
	head = int(str(i)[0])
	tail = i % 10
	answer += head_tail[tail, head]
print(answer)


from collections import defaultdict
N = int(input())
cnts = defaultdict(int)
for i in range(1, N + 1):
	if i % 10 == 0:
		continue
	digits = []
	while i > 0:
		(i, r) = divmod(i, 10)
		digits.append(r)
	digits = digits[::-1]
	cnts[digits[0], digits[-1]] += 1
ans = 0
for ((head, tail), c1) in list(cnts.items()):
	c2 = cnts.get((tail, head), 0)
	ans += c1 * c2
print(ans)


N = int(input())
dp = [0] * 100
for i in range(N):
	s = str(i + 1)
	dp[int(s[0]) * 10 + int(s[-1])] += 1
ans = sum((dp[i * 10 + j] * dp[j * 10 + i] for i in range(1, 10) for j in range(1, 10)))
print(ans)


n = int(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)


n = int(input())
m = [0] * 100
for i in range(1, n + 1):
	if str(i)[-1] != '0':
		m[int(str(i)[0]) * 10 + int(str(i)[-1])] += 1
res = sum([m[i] * m[int(str(i)[::-1])] for i in range(100)])
print(res)


import numpy as np
N = int(input())
list_all = np.zeros((9, 9))
num_list = [str(i) for i in range(1, N + 1)]
overlap = [0 for i in range(9)]
for i in range(N):
	head = int(num_list[i][0])
	length = len(num_list[i])
	tail = int(num_list[i][length - 1])
	if head == 0 or tail == 0:
		continue
	list_all[head - 1, tail - 1] += 1
sum1 = 0
for i in range(9):
	for j in range(i + 1):
		if i == j:
			sum1 += list_all[i, j] * list_all[j, i]
		else:
			sum1 += list_all[i, j] * list_all[j, i] * 2
print(int(sum1))


n = int(input())
d = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	d[int(str(i)[0])][i % 10] += 1
ret = 0
for s in range(10):
	for e in range(10):
		ret += d[s][e] * d[e][s]
print(ret)


import math
a = int(input())
ans = 0
c = [[0 for i in range(10)] for j in range(10)]
for i in range(1, a + 1):
	aa = str(i)
	c[int(aa[0])][int(aa[-1])] += 1
for i in range(10):
	for j in range(10):
		ans += c[i][j] * c[j][i]
print(ans)


N = int(input())
dp = [[0] * 10 for _ in range(10)]
for a in range(N + 1):
	A = str(a)
	dp[int(A[0])][int(A[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += dp[i][j] * dp[j][i]
print(ans)


N = int(input())
A = [[0 for s in range(10)] for t in range(10)]
for i in range(1, N + 1):
	s = str(i)
	A[int(s[0])][int(s[-1])] += 1
x = 0
for s in range(10):
	for t in range(10):
		x += A[s][t] * A[t][s]
print(x)


n = int(input())
D = {}
for i in range(1, n + 1):
	s = (str(i)[0], str(i)[-1])
	if s not in D:
		D[s] = 1
	else:
		D[s] += 1
ans = 0
for i in D:
	if (i[1], i[0]) in D:
		ans += D[i] * D[i[1], i[0]]
print(ans)


def II():
	return int(input())
N = II()
tbl = [0] * 101
for i in range(1, N + 1):
	i = str(i)
	tbl[int(str(i[0] + i[-1]))] += 1
ans = 0
for i in range(1, N + 1):
	i = str(i)
	ans += tbl[int(str(i[-1] + i[0]))]
print(ans)


n = int(input())
A = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	t = str(i)
	(a, b) = (int(t[0]), int(t[-1]))
	A[a][b] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += A[i][j] * A[j][i]
print(ans)


n = int(input())
cnt = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	s = str(i)
	h = int(s[0])
	t = int(s[-1])
	cnt[h][t] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += cnt[i][j] * cnt[j][i]
print(ans)


import sys
import collections
import bisect

def main():
	n = int(input())
	a = [str(i + 1)[0] + str(i + 1)[-1] for i in range(n)]
	b = [str(i + 1)[-1] + str(i + 1)[0] for i in range(n)]
	(ac, bc) = (collections.Counter(a), collections.Counter(b))
	acKeys = list(ac.keys())
	bcKeys = list(bc.keys())
	cnt = 0
	for i in acKeys:
		cnt += ac[i] * bc[i]
	print(cnt)

def __starting_point():
	main()
__starting_point()


N = int(input())
l = [[0 for j in range(10)] for i in range(10)]
for n in range(1, N + 1):
	s = str(n)
	i = int(s[0])
	j = int(s[-1])
	l[i][j] += 1
ans = sum([l[i][j] * l[j][i] for i in range(10) for j in range(10)])
print(ans)


N = int(input())
C = [0] * 100
for i in range(1, N + 1):
	s = str(i)
	C[10 * int(s[0]) + int(s[-1])] += 1
print(sum([C[10 * i + j] * C[10 * j + i] for i in range(10) for j in range(10)]))


N = int(input())
BL = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
	BL[int(str(i)[0])][int(str(i)[-1])] += 1
ANS = 0
for i in range(10):
	for j in range(10):
		ANS += BL[i][j] * BL[j][i]
print(ANS)


N = int(input())
C = [[0 for _ in range(10)] for __ in range(10)]
for i in range(1, N + 1):
	C[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += C[i][j] * C[j][i]
print(ans)


N = int(input())
d = {}
for i in range(1, N + 1):
	i = str(i)[0] + str(i)[-1]
	d[i] = d.get(i, 0) + 1
ans = 0
for i in map(str, range(1, 10)):
	for j in map(str, range(1, 10)):
		ans += d.get(i + j, 0) * d.get(j + i, 0)
print(ans)


n = int(input())
d = [0 for _ in range(100)]
for i in range(1, n + 1):
	s = str(i)
	d[int(s[0]) * 10 + int(s[-1])] += 1
result = 0
for i in range(1, 10):
	for j in range(1, 10):
		result += d[i * 10 + j] * d[j * 10 + i]
print(result)


n = int(input())
l = [[0 for i in range(10)] for s in range(10)]
for i in range(n + 1):
	if i % 10:
		l[int(str(i)[0]) - 1][int(str(i)[-1]) - 1] += 1
ans = 0
for i in range(9):
	for j in range(9):
		ans += l[i][j] * l[j][i]
print(ans)


import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter, defaultdict, deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7

def inp():
	return int(input())

def inpm():
	return map(int, input().split())

def inpl():
	return list(map(int, input().split()))

def inpls():
	return list(input().split())

def inplm(n):
	return list((int(input()) for _ in range(n)))

def inplL(n):
	return [list(input()) for _ in range(n)]

def inplT(n):
	return [tuple(input()) for _ in range(n)]

def inpll(n):
	return [list(map(int, input().split())) for _ in range(n)]

def inplls(n):
	return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
ans = 0
n_ketasuu = len(str(n))
sta_max = int(str(n)[0])
end_max = int(str(n)[n_ketasuu - 1])
for i in range(1, n + 1):
	sta = int(str(i)[len(str(i)) - 1])
	end = int(str(i)[0])
	if sta == 0:
		continue
	if sta == end:
		ans += 1
	if n_ketasuu >= 2 and sta * 10 + end <= n:
		ans += 1
	if n_ketasuu > 3 or (n_ketasuu == 3 and sta < sta_max):
		ans += 10
	elif n_ketasuu == 3 and sta == sta_max:
		ans += int(str(n)[1:n_ketasuu - 1])
		if end <= end_max:
			ans += 1
	if n_ketasuu > 4 or (n_ketasuu == 4 and sta < sta_max):
		ans += 100
	elif n_ketasuu == 4 and sta == sta_max:
		ans += int(str(n)[1:n_ketasuu - 1])
		if end <= end_max:
			ans += 1
	if n_ketasuu > 5 or (n_ketasuu == 5 and sta < sta_max):
		ans += 1000
	elif n_ketasuu == 5 and sta == sta_max:
		ans += int(str(n)[1:n_ketasuu - 1])
		if end <= end_max:
			ans += 1
	if n_ketasuu > 6 or (n_ketasuu == 6 and sta < sta_max):
		ans += 10000
	elif n_ketasuu == 6 and sta == sta_max:
		ans += int(str(n)[1:n_ketasuu - 1])
		if end <= end_max:
			ans += 1
print(ans)


x = int(input())
dp = [[0 for n in range(10)] for n in range(10)]
dp1 = dp.copy()
for n in range(x + 1):
	v = str(n)
	p = int(v[0])
	q = int(v[-1])
	for a in range(10):
		for b in range(10):
			if a == p and b == q:
				dp[a][b] += 1
res = -1
for n in range(10):
	for k in range(10):
		res += dp[n][k] * dp[k][n]
print(res)


N = int(input())
Cij = [0] * 100
for i in range(1, N + 1):
	Cij[int(str(i)[0] + str(i)[-1])] += 1
count = 0
for i in range(10):
	for j in range(10):
		count += Cij[i * 10 + j] * Cij[j * 10 + i]
print(count)


N = int(input())
A = [[0 for j in range(9)] for i in range(9)]
count = 0
for x in range(1, N + 1):
	if x % 10 == 0:
		continue
	if x >= 10 ** (count + 1):
		count += 1
	i = x % 10
	j = x // 10 ** count
	A[i - 1][j - 1] += 1
ans = 0
for i in range(9):
	for j in range(i, 9):
		r = 2 if i != j else 1
		ans += A[i][j] * A[j][i] * r
print(ans)


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


n = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for i in range(n + 1):
	left = int(str(i)[0])
	right = i % 10
	c[left][right] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += c[i][j] * c[j][i]
print(ans)


n = int(input())
num = [[0 for j in range(10)] for i in range(10)]
for i in range(1, n + 1):
	X = str(i)
	num[int(X[0])][int(X[-1])] += 1
ans = 0
print(sum((num[i][j] * num[j][i] for i in range(10) for j in range(10))))


N = int(input())
counter = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, N + 1):
	counter[k % 10][int(str(k)[0])] += 1
ans = 0
for k in range(1, 10):
	for j in range(1, 10):
		ans += counter[k][j] * counter[j][k]
print(ans)


n = int(input())
cnt = [[0 for i in range(10)] for j in range(10)]
for k in range(n + 1):
	head = int(str(k)[0])
	foot = int(str(k)[-1])
	cnt[head][foot] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += cnt[i][j] * cnt[j][i]
print(ans)


n = int(input())
a = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	a[int(str(i)[0])][i % 10] += 1
ans = 0
for x in range(1, 10):
	ans += a[x][x] ** 2
	for y in range(x + 1, 10):
		ans += a[y][x] * a[x][y] * 2
print(ans)


n = int(input())
memo = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	a = int(str(i)[0])
	b = int(str(i)[-1])
	memo[a][b] += 1
ans = 0
for i in range(1, n + 1):
	b = int(str(i)[0])
	a = int(str(i)[-1])
	ans += memo[a][b]
print(ans)


N = int(input())
t = [0] * 100
ans = 0
for k in range(1, N + 1):
	if k % 10 != 0:
		t[10 * int(str(k)[0]) + int(str(k)[-1])] += 1
for k in range(11, 100):
	if k % 10 != 0:
		ans += t[k] * t[10 * (k % 10) + k // 10]
print(ans)


N = int(input())
num = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
	top = int(str(i)[0])
	end = int(str(i)[-1])
	num[top][end] += 1
count = 0
for i in range(10):
	for j in range(10):
		count += num[i][j] * num[j][i]
print(count)


N = int(input())
arr = [0] * 100
for num in range(1, N + 1):
	arr[int(str(num)[0] + str(num)[-1])] += 1
print(sum([arr[i * 10 + j] * arr[j * 10 + i] for i in range(10) for j in range(10)]))


N = int(input())
memo = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
	memo[i // 10 ** (len(str(i)) - 1)][i % 10] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += memo[i][j] * memo[j][i]
print(ans)


n = int(input())
a = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n + 1):
	s = str(i)
	if s[-1] != '0':
		a[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += a[i][j] * a[j][i]
print(ans)


n = int(input())
ans = 0
X = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	t = int(str(i)[0])
	b = int(str(i)[-1])
	X[t][b] += 1
for i in range(1, 10):
	for j in range(1, 10):
		ans += X[i][j] * X[j][i]
print(ans)


n = int(input())
res = 0
M = [[0 for _ in range(10)] for _ in range(10)]
for i in range(n + 1):
	a = i % 10
	b = int(str(i)[0])
	M[a][b] += 1
for i in range(1, 10):
	for j in range(1, 10):
		res += M[i][j] * M[j][i]
print(res)


N = int(input())
LUT = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
	LUT[int(str(n)[0])][int(str(n)[-1])] += 1
ans = sum([sum([LUT[i][j] * LUT[j][i] for i in range(10)]) for j in range(10)])
print(ans)


n = int(input())
cnt = 0
memo = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	memo[int(str(i)[0])][int(str(i)[-1])] += 1
for i in range(10):
	for j in range(10):
		cnt += memo[i][j] * memo[j][i]
print(cnt)


N = int(input())
D = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
	s = str(n)
	i = int(s[0])
	j = int(s[-1])
	D[i][j] += 1
r = 0
for i in range(10):
	for j in range(10):
		r += D[i][j] * D[j][i]
print(r)


n = int(input())
D = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
	s = str(i)
	D[int(s[0])][int(s[-1])] += 1
a = 0
for i in range(10):
	for j in range(10):
		a += D[i][j] * D[j][i]
print(a)


def main():
	N = int(input())
	comb_count = [[0 for i in range(10)] for j in range(10)]
	res = 0
	for i in range(1, N + 1):
		s = str(i)
		(max, min) = (int(s[0]), int(s[-1]))
		comb_count[max][min] += 1
	for l in range(1, 10):
		for r in range(1, 10):
			res += comb_count[l][r] * comb_count[r][l]
	print(res)

def __starting_point():
	main()
__starting_point()


n = int(input())
p = [[0 for _ in range(10)] for _2 in range(10)]
ans = 0
for i in range(1, n + 1):
	l = int(str(i)[0])
	r = int(str(i)[-1])
	ans += 2 * p[r][l]
	p[l][r] += 1
	if l == r:
		ans += 1
print(ans)


N = int(input())
c = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
	c[int(str(n)[0])][int(str(n)[-1])] += 1
sum = 0
for i in range(10):
	for j in range(10):
		sum += c[i][j] * c[j][i]
print(sum)


N = int(input())
(a, b) = divmod(N, 10)
h = lambda n: h(n // 10) if n > 9 else n
print(a ** 2 + 8 + sum(((h(i) <= b) * (i % 10 == h(N)) * (1 + (a != i // 10)) for i in range(1, N + 1))) if a else N)


n = int(input())
t = [0] * 100
for i in range(11, 100):
	msb = i // 10
	lsb = i % 10
	if lsb == 0:
		continue
	for j in range(1, n + 1):
		if j % 10 == lsb and int(str(j)[0]) == msb:
			t[i] += 1
ans = 0
for i in range(11, 100):
	msb = i // 10
	lsb = i % 10
	if lsb == 0:
		continue
	if msb == lsb:
		ans += t[i] ** 2
	else:
		ans += t[i] * t[lsb * 10 + msb]
print(ans)


import collections
d = collections.defaultdict(int)
n = int(input())
for i in range(1, n + 1):
	s = str(i)
	d[s[0], s[-1]] += 1
ans = 0
for i in range(1, n + 1):
	s = str(i)
	ans += d[s[-1], s[0]]
print(ans)


n = int(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)


n = int(input())
count = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for _ in range(10)]
for i in range(1, n + 1):
	count[int(list(str(i))[0]) - 1][int(list(str(i))[-1]) - 1] += 1
ans = 0
for j in range(10):
	for k in range(10):
		ans += count[j][k] * count[k][j]
print(ans)


N = int(input())
D = {}
for i in range(1, N + 1):
	i = str(i)
	D[i[0], i[-1]] = D.get((i[0], i[-1]), 0) + 1
ans = 0
for i in range(1, N + 1):
	i = str(i)
	ans += D.get((i[-1], i[0]), 0)
print(ans)


n = int(input())
a = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	keta = str(i)[0]
	makkou = str(i)[-1]
	a[int(makkou) - 1][int(keta) - 1] += 1
ans = 0
for j in range(10):
	for i in range(10):
		ans += a[j][i] * a[i][j]
print(ans)


from collections import Counter
N = int(input())
c = Counter()
for i in range(1, N + 1):
	a = str(i)
	c[a[0], a[-1]] += 1
ans = 0
for (k, v) in c.items():
	ans += v * c[k[1], k[0]]
print(ans)


N = int(input())
l = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
	s = len(str(i))
	if s == 1:
		l[i][i] += 1
	else:
		l[i // 10 ** (s - 1)][i % 10] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += l[i][j] * l[j][i]
print(ans)


n = int(input())
lr_cnt = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
	str_i = str(i)
	start = int(str_i[0])
	end = int(str_i[-1])
	lr_cnt[start][end] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += lr_cnt[i][j] * lr_cnt[j][i]
print(ans)


import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
Comlist = []
Ans = dict()
Answer = 0
for i in range(1, 10):
	for j in range(1, 10):
		M = i * 10 + j
		Comlist.append(str(M))
		Ans[str(M)] = 0
for k in range(1, N + 1):
	strk = str(k)
	if k < 10:
		Tar = strk + strk
		Ans[Tar] += 1
	else:
		Tar = strk[0] + strk[-1]
		if Tar in Ans:
			Ans[Tar] += 1
Answer = 0
for q in range(len(Comlist)):
	p = Comlist[q]
	pin = p[1] + p[0]
	Answer += Ans[p] * Ans[pin]
print(Answer)


n = int(input())
a = [0] * 100
count = 0
for i in range(1, n + 1):
	x = i % 10
	y = int(str(i)[0])
	a[10 * y + x] += 1
for i in range(1, n + 1):
	x = i % 10
	y = int(str(i)[0])
	count += a[10 * x + y]
print(count)


N = int(input())
results = {(str(i), str(j)): 0 for i in range(1, 10) for j in range(1, 10)}
for i in range(N + 1):
	s = str(i)
	if (s[0], s[-1]) in results.keys():
		results[s[0], s[-1]] += 1
cnt = 0
for i in range(1, 10):
	for j in range(1, 10):
		cnt += results[str(i), str(j)] * results[str(j), str(i)]
print(cnt)


N = int(input())
count = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
	s = str(i)
	head = int(s[0])
	tail = int(s[-1])
	count[head][tail] += 1
ans = 0
for a in range(1, N + 1):
	s = str(a)
	head = int(s[0])
	tail = int(s[-1])
	ans += count[tail][head]
print(ans)


def N():
	return int(input())

def L():
	return list(map(int, input().split()))

def NL(n):
	return [list(map(int, input().split())) for i in range(n)]
mod = pow(10, 9) + 7
import sys
import math
import collections
n = N()
c = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	h = int(str(i)[0])
	t = int(str(i)[-1])
	c[h][t] += 1
sum = 0
for i in range(1, 10):
	for j in range(1, 10):
		sum += c[i][j] * c[j][i]
print(sum)


n = int(input())
hist = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
	top = int(str(i)[0])
	bot = int(str(i)[-1])
	hist[top][bot] += 1
ans = 0
for i in range(1, n + 1):
	top = int(str(i)[0])
	bot = int(str(i)[-1])
	ans += hist[bot][top]
print(ans)


n = int(input())
l = [0] * 100
ans = 0
for i in range(1, n + 1):
	s = str(i)
	l[int(s[0]) * 10 + int(s[-1])] += 1
for i in range(1, 10):
	for j in range(1, 10):
		ans += l[i * 10 + j] * l[j * 10 + i]
print(ans)


from collections import defaultdict
n = int(input())
counter = defaultdict(int)
for x in map(str, range(1, n + 1)):
	head = x[0]
	tail = x[-1]
	counter[head, tail] += 1
ans = 0
items = list(counter.items())
for ((head, tail), cnt) in items:
	ans += cnt * counter[tail, head]
print(ans)


import sys
from itertools import chain

def solve(N: int):
	m = [0] * 100
	for n in range(N + 1):
		s = str(n)
		h = int(s[0])
		l = int(s[-1])
		if l != 0:
			m[h * 10 + l] += 1
	answer = 0
	for h in range(1, 10):
		for l in range(1, 10):
			answer += m[h * 10 + l] * m[l * 10 + h]
	return answer

def main():
	N = int(input())
	answer = solve(N)
	print(answer)

def __starting_point():
	main()
__starting_point()


N = int(input())
d = dict()
for i in range(1, N + 1):
	_0 = str(i)[0]
	_1 = str(i)[-1]
	if _1 == '0':
		continue
	s = _0 + _1
	if s in d:
		d[s] += 1
	else:
		d[s] = 1
res = 0
for i in range(1, N + 1):
	_0 = str(i)[0]
	_1 = str(i)[-1]
	if _1 == '0':
		continue
	s = _1 + _0
	if s in d:
		res += d[s]
print(res)


N = int(input())
A = [[0 for i in range(10)] for j in range(10)]
for i in range(1, N + 1):
	i = str(i)
	ii = len(i)
	A[int(i[0])][int(i[ii - 1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += A[i][j] * A[j][i]
print(ans)


n = int(input())
A = [0] * 105
for i in range(1, n + 1):
	x = str(i)
	A[int(x[0] + x[len(x) - 1])] += 1
ans = 0
for i in range(11, 100):
	y = str(i)
	if '0' in y:
		continue
	ans += A[i] * A[int(y[1] + y[0])]
print(ans)


from collections import defaultdict
N = int(input())
d = defaultdict(int)
for i in range(1, N + 1):
	s = str(i)
	d[s[0], s[-1]] += 1
ans = 0
for i in range(1, N + 1):
	s = str(i)
	ans += d[s[-1], s[0]]
print(ans)


n = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(1, n + 1):
	d[str(i)[0] + str(i)[-1]] += 1
sm = 0
for i in range(1, 10):
	for j in range(1, 10):
		sm += d[str(i) + str(j)] * d[str(j) + str(i)]
print(sm)


n = int(input())
d = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	i_ = str(i)
	x = int(i_[0])
	y = int(i_[-1])
	d[x][y] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += d[i][j] * d[j][i]
print(ans)


n = input()
d = [[0] * 10 for _ in range(10)]
for i in range(1, int(n) + 1):
	k = str(i)
	d[int(k[0])][int(k[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += d[i][j] * d[j][i]
print(ans)


N = int(input())
d = {}
for i in range(1, 10):
	for j in range(1, 10):
		d[i * 10 + j] = 0
for i in range(1, min(10, N + 1)):
	d[i * 10 + i] = 1
(p, h, t, c) = (10, 10, 1, 1)
for i in range(11, N + 1):
	if t == 10:
		t = 1
	else:
		d[h + t] += 1
		t += 1
	if p == c:
		h += 10
		c = 0
	if h == 100:
		h = 10
		p *= 10
	c += 1
ans = 0
for i in range(1, 9):
	for j in range(i + 1, 10):
		ans += d[i * 10 + j] * d[j * 10 + i] * 2
for i in range(1, 10):
	ans += d[i * 10 + i] ** 2
print(ans)


N = int(input())
ab = [[0 for i in range(9)] for j in range(9)]
for i in range(1, N + 1):
	if i % 10 != 0:
		s = str(i)
		ab[int(s[0]) - 1][int(s[-1]) - 1] += 1
ans = 0
for i in range(9):
	for j in range(9):
		ans += ab[i][j] * ab[j][i]
print(ans)


N = int(input())
A = [str(i) for i in range(1, 10)]
ans = 0
for a in A:
	for b in A:
		countA = 0
		if a == b and int(a) <= N:
			countA += 1
		for i in range(5):
			m = int(a + '0' * i + b)
			M = int(a + '9' * i + b)
			if m <= N:
				if M <= N:
					countA += 10 ** i
				else:
					while m <= N:
						countA += 1
						m += 10
		countB = 0
		if b == a and int(b) <= N:
			countB += 1
		for i in range(5):
			m = int(b + '0' * i + a)
			M = int(b + '9' * i + a)
			if m <= N:
				if M <= N:
					countB += 10 ** i
				else:
					while m <= N:
						countB += 1
						m += 10
		ans += countA * countB
print(ans)


N = int(input())
C = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
	C[int(str(i)[0])][int(str(i)[-1])] += 1
answer = 0
for i in range(10):
	for j in range(10):
		answer += C[i][j] * C[j][i]
print(answer)


def main():
	n = int(input())
	dp = [[0 for i in range(10)] for i in range(10)]
	for i in range(1, n + 1):
		(h, t) = (int(str(i)[0]), int(str(i)[-1]))
		dp[h][t] += 1
	ans = 0
	for i in range(10):
		for j in range(10):
			ans += dp[i][j] * dp[j][i]
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(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(10):
	for j in range(10):
		ans += C[i][j] * C[j][i]
print(ans)


n = int(input())
a = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
	j = i % 10
	while i > 9:
		i //= 10
	a[i][j] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += a[i][j] * a[j][i]
print(ans)


from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n + 1):
	s = str(i)
	f = int(s[0])
	b = int(s[-1])
	d[f, b] += 1
ans = 0
for a in range(1, 10):
	for b in range(1, 10):
		ans += d[a, b] * d[b, a]
print(ans)


n = int(input())
c = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
	t = int(str(i)[0])
	b = int(str(i)[-1])
	c[t][b] += 1
s = 0
for t in range(10):
	for b in range(10):
		s += c[t][b] * c[b][t]
print(s)


N = int(input())
A = [0] * 100
for i in range(1, N + 1):
	first = int(str(i)[0])
	last = int(str(i)[-1])
	A[first * 10 + last] += 1
score = 0
for i in range(10):
	for j in range(10):
		score += A[i * 10 + j] * A[j * 10 + i]
print(score)


n = int(input())
lst = [[0 for i in range(10)] for j in range(10)]
cnt = 0
for i in range(1, n + 1):
	(l, r) = (int(str(i)[0]), int(str(i)[-1]))
	lst[l][r] += 1
for i in range(10):
	for j in range(10):
		cnt += lst[i][j] * lst[j][i]
print(cnt)


N = int(input())
data = [[0] * 10 for i in range(10)]
for u in range(N + 1):
	data[int(str(u)[0])][int(str(u)[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += data[i][j] * data[j][i]
print(ans)


N = int(input())
k = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
	sn = str(n)
	k[int(sn[0])][int(sn[-1])] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += k[i][j] * k[j][i]
print(ans)


n = int(input())
c = []
for i in range(0, 10):
	c.append([0] * 10)
for k in range(1, n + 1):
	x = str(k)
	a = int(x[0])
	b = int(x[-1])
	c[a][b] += 1
s = 0
for i in range(1, 10):
	for j in range(1, 10):
		s += c[i][j] * c[j][i]
print(s)


n = int(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)


import sys
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.141592653589793

def read_str():
	return sys.stdin.readline().strip()

def read_int():
	return int(sys.stdin.readline().strip())

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

def read_ints2(x):
	return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())

def read_str_list():
	return list(sys.stdin.readline().strip().split())

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

def GCD(a: int, b: int) -> int:
	return b if a % b == 0 else GCD(b, a % b)

def LCM(a: int, b: int) -> int:
	return a * b // GCD(a, b)

def f(num):
	front = num
	back = num
	while front >= 10:
		front //= 10
	while back >= 10:
		back %= 10
	return (front, back)

def Main():
	n = read_int()
	cnt = [[0] * 10 for _ in range(10)]
	for x in range(1, n + 1):
		(front, back) = f(x)
		cnt[front][back] += 1
	ans = 0
	for x in range(10):
		for y in range(10):
			ans += cnt[x][y] * cnt[y][x]
	print(ans)

def __starting_point():
	Main()
__starting_point()


n = int(input())
g = [[0] * 10 for _ in range(10)]
for i in range(1, 1 + n):
	a = int(str(i)[0])
	b = i % 10
	g[a][b] += 1
ans = sum((g[a][b] * g[b][a] for a in range(10) for b in range(10)))
print(ans)


N = int(input())
bucket = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
	n = str(n)
	bucket[int(n[0])][int(n[-1])] += 1
ans = 0
for i in range(10):
	for j in range(10):
		ans += bucket[i][j] * bucket[j][i]
print(ans)


n = int(input())
a = [[0 for j in range(10)] for i in range(10)]
for i in range(1, n + 1):
	if i >= 10 ** 5:
		tmp1 = i // 10 ** 5
	elif i >= 10 ** 4:
		tmp1 = i // 10 ** 4
	elif i >= 10 ** 3:
		tmp1 = i // 10 ** 3
	elif i >= 10 ** 2:
		tmp1 = i // 10 ** 2
	elif i >= 10:
		tmp1 = i // 10
	else:
		tmp1 = i
	tmp2 = i % 10
	a[tmp1][tmp2] += 1
cnt = 0
for i in range(1, 10):
	for j in range(1, 10):
		cnt += a[i][j] * a[j][i]
print(cnt)


n = int(input())
cnt = [[0] * 10 for i in range(10)]
for i in range(n + 1):
	a = int(str(i)[0])
	b = int(str(i)[-1])
	if a == 0 or b == 0:
		continue
	cnt[a][b] += 1
ans = 0
for i in range(n + 1):
	a = int(str(i)[0])
	b = int(str(i)[-1])
	ans += cnt[b][a]
print(ans)


n = int(input())
a = [[0] * 9 for _ in range(9)]
for i in range(1, n + 1):
	s = str(i)
	l = int(s[0])
	r = int(s[len(s) - 1])
	if l * r != 0:
		a[l - 1][r - 1] += 1
x = 0
for i in range(9):
	for j in range(9):
		x += a[i][j] * a[j][i]
print(x)


N = int(input())
M = [0] * 100
for i in range(1, N + 1):
	i = str(i)
	(l, r) = (int(i[0]), int(i[-1]))
	M[l * 10 + r] += 1
ans = 0
for (i, cnt) in enumerate(M):
	(l, r) = divmod(i, 10)
	ans += cnt * M[r * 10 + l]
print(ans)


n = int(input())
dat = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
	dat[int(str(i)[0])][int(str(i)[-1])] += 1
res = sum([dat[a][b] * dat[b][a] for a in range(10) for b in range(10)])
print(res)