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

ans = 0

def calc(i):
    lst = []
    while i!=0:
        lst.append(i%10)
        i = i//10
    lst.reverse()
    return lst
  
for a in range(1, N+1):
    lsta = calc(a)
    m = len(lsta)

    if lsta[0] > lsta[m-1]:
        if lsta[m-1]==0:continue
        ans += sum([2*10**(l) for l in range(m-1)])
    elif lsta[0] == lsta[-1]:
        if m <= 2:ans += 2*m-1
        else:
            ans += (a%(10**(m-1))//10)*2 +1
            for l in range(m-2):
                ans += 10**(l)*2
            ans += 2
      
    else:
        if m == 2:continue
        else:
            for l in range(m-2):
                ans += 2*10**(l)
print(ans)

Solution (Python):
def main():
    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(1, 10):
        for j in range(1, 10):
            ans += c[i][j]*c[j][i]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from numpy import *

N = int(input())

l = zeros((10, 10), dtype=int)

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

count = 0
for i in range(1, 10):
    for j in range(1, 10):
        count += l[i][j] * l[j][i]


print(count)

Solution (Python):
def solve():
    strN = input()
    N = int(strN)

    maxD = len(strN)

    numss = [[0]*(10) for _ in range(10)]
    for x in range(1, 10):
        for y in range(1, 10):
            num = 0
            for d in range(1, maxD-2):
                num += 10**d
            if maxD-2 > 0:
                if x < int(strN[0]):
                    num += 10**(maxD-2)
                elif x == int(strN[0]):
                    num += int(strN[1:-1]) + 1
                    if y > int(strN[-1]):
                        num -= 1
            j = x*10 + y
            if 1 <= j <= N:
                num += 1
            if x == y:
                j = x
                if 1 <= j <= N:
                    num += 1
            numss[x][y] = num

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

    print(ans)


solve()

Solution (Python):
def solve():
    N = int(input())

    numss = [[0]*(10) for _ in range(10)]
    for x in range(1, 10):
        for y in range(1, 10):
            num = 0
            for d in range(1, 5):
                for i in range(10**d):
                    j = x*10**(d+1) + i*10 + y
                    if 1 <= j <= N:
                        num += 1
                    else:
                        break
            j = x*10 + y
            if 1 <= j <= N:
                num += 1
            if x == y:
                j = x
                if 1 <= j <= N:
                    num += 1
            numss[x][y] = num

    ans = 0
    for A in range(1, N+1):
        ss = str(A)
        ans += numss[int(ss[-1])][int(ss[0])]

    print(ans)


solve()

Solution (Python):
def solve():
    strN = input()
    N = int(strN)

    maxD = len(strN)

    numss = [[0]*(10) for _ in range(10)]
    for x in range(1, 10):
        for y in range(1, 10):
            num = 0
            for d in range(1, maxD-2):
                num += 10**d
            if maxD-2 > 0:
                if x < int(strN[0]):
                    num += 10**(maxD-2)
                elif x == int(strN[0]):
                    num += int(strN[1:-1]) + 1
                    if y > int(strN[-1]):
                        num -= 1
            j = x*10 + y
            if 1 <= j <= N:
                num += 1
            if x == y:
                j = x
                if 1 <= j <= N:
                    num += 1
            numss[x][y] = num

    ans = 0
    for A in range(1, N+1):
        ss = str(A)
        ans += numss[int(ss[-1])][int(ss[0])]

    print(ans)


solve()

Solution (Python):
import collections

N=int(input())

Pair = [()]

for i in range(N):
	numst = str(i + 1)
	Pair.append((numst[0], numst[-1:]))

Pair = collections.Counter(Pair)
count = 0
for k1, v1 in Pair.items():
	for k2, v2 in Pair.items():
		if not k1 or not k2:
			continue
		elif k1[0]==k2[1] and k1[1]==k2[0]:
			count += v1*v2
print(count)

Solution (Python):
n = int(input())
a = [[0 for j in range(9)] for i in range(9)]
for i in range(1,n+1):
	if str(i)[-1] == "0":
		continue
	a[int(str(i)[0])-1][int(str(i)[-1])-1] += 1

s = 0

for i in range(9):
	for j in range(9):
		if i == j:
			s += a[i][j]**2
		else:
			s += a[i][j] * a[j][i]
print (s)

Solution (Python):
n = int(input())
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, n+1):
    x, y = int(str(i)[0]), int(str(i)[-1])
    cnt[x][y] += 1
res = 0
for i in range(1, 10):
    for j in range(1, 10):
        res += cnt[i][j] * cnt[j][i]
print(res)

Solution (Python):
n = int(input())

mem = [[0]*10 for _ in range(10)]

for i in range(n):
  a = int(str(i+1)[0])
  b = int(str(i+1)[-1])
  mem[a][b] += 1
  
ans = 0

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

Solution (Python):
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:
    t=(i[1],i[0])
    if t in D:
        ans+=D[t]*D[i]
print(ans)

Solution (Python):
import numpy as np

def main():
    N = np.array([str(i) for i in range(1,int(input())+1)])
    C = np.zeros((10,10), dtype=np.int)
    ans = 0

    
    for n in N:
        C[int(n[0])][int(n[-1])] += 1

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    nl = [[0 for _ in range(10)] for _ in range(10)]
    
    for i in range(1,N+1):
        s = str(i)
        if s[-1] != "0":
            nl[int(s[0])][int(s[-1])] += 1

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

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())

cnt = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1, N + 1):
  s = str(i)
  if int(s[-1]) != 0:
    cnt[int(s[0])][int(s[-1])] += 1
    
answer = 0
for i in range(1, 10):
  for j in range(1, 10):
    answer += cnt[i][j] * cnt[j][i]

print(answer)

Solution (Python):
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)

Solution (Python):
def main():
    n=int(input())
    C=[[0]*10 for _ 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)

if __name__=='__main__':
    main()

Solution (Python):
def f(n, h, t):
    if 10*h + t > n:
        return 0
    return 1 + sum(f(n, 10*h+x, t) for x in range(10))

def solve(n):
    ans = 0
    for h in range(1,10):
        for t in range(1,10):
            
            s = int((h == t) and (h <= n))
            ans += (f(n, h, t) + s) * (f(n, t, h) + s)
    return ans

n = int(input())
print(solve(n))

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    memo = defaultdict(int)
    for i in range(1,N+1):
        head,tail = str(i)[0], str(i)[-1]
        memo[head,tail] += 1
    ans = 0
    for i in range(1,N+1):
        head,tail = str(i)[0], str(i)[-1]
        ans += memo[tail,head]
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
a=int(input())

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

for i in range(a+1):
    if i%10 == 0:
        continue
    x = str(i)
    dp[int(x[0])][int(x[-1])] += 1


count = 0

for i in range(10):
    for w in range(10):
        count += dp[i][w]*dp[w][i]

print(count)

Solution (Python):
def main():
    n = int(input())
    c = [[0 for _ in range(10)] for _ in range(10)]
    tmp = 1
    for i in range(1, n + 1):
        if i >= tmp * 10:
            tmp *= 10
        c[i // tmp][i % 10] += 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()

Solution (Python):
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)

Solution (Python):

N = int(input())
dp = [[0 for _ in range(10)] for _ in range(10)]

def pair(n):
  num = str(n)
  p = int(num[0])
  s = n % 10
  return (p, s)


for i in range(1, N+1):
  pre, suf = pair(i)
  dp[pre][suf] += 1

ans = 0
for i in range(1, N+1):
  suf, pre = pair(i)
  ans += dp[pre][suf]

print(ans)

Solution (Python):
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)

Solution (Python):
import numpy as np
N=int(input())
c=np.array([[0]*10]*10)
for n in range(1,N+1):
  sn=str(n)
  i=int(sn[0])
  j=int(sn[-1])
  c[i][j]+=1

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

Solution (Python):
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)))

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

Solution (Python):
import numpy as np


N = int(input())

countup = np.zeros(100, dtype=int)

for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    countup[A*10+B] += 1

ans = 0
for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    ans += countup[B*10+A]

print(ans)

Solution (Python):
def main():
    N = int(input())
    print(solve(N))


def count(n, start, end):
    """n以下の数字でsで始まりeで終わる数字の個数
    732, 1, 2 -> 12, 102, 112, 122, ... , 192 = 11
    Examples:
        >>> count(732, 1, 2)
        11
        >>> count(25, 1, 1)
        2
        >>> count(25, 3, 3)
        1
        >>> count(100, 1, 2)
        1
        >>> count(102, 1, 2)
        2
    """

    if n <= 9:
        return 1 if start == end and start <= n else 0
    if n <= 99:
        one_digit = 1 if start == end else 0
        two_digit = 1 if start * 10 + end <= n else 0
        return one_digit + two_digit
    digit_length = len(str(n))
    
    ret1 = count(10 ** (digit_length - 1) - 1, start, end)
    
    min_cand = start * (10 ** (digit_length - 1)) + end
    if min_cand > n:
        return ret1
    ret2 = min((n-min_cand) // 10 + 1, 10 ** (digit_length - 2))
    return ret1 + ret2


def solve(n):
    """n以下の組で, (213, 382)のような末尾と先頭が等しい数の個数"""
    result = 0
    for i in range(1, 10):
        for j in range(i + 1, 10):
            result += 2 * count(n, i, j) * count(n, j, i)
    for i in range(1, 10):
        result += count(n, i, i) * count(n, i, i)
    return result


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
result=0
for i in range(1,n+1):
  if 1<=i<=9:
    result+=1
  else:
    num=str(i)
    a=int(num[0])
    b=int(num[len(num)-1])
    middle=(i-10**(len(num)-1)*a-b)//10
    numbers=0
    if b!=0:
      for j in range(2,len(num)):
        numbers+=10**(j-2)
      if a==b:
        numbers+=2+middle
        result+=numbers*2-1
      elif a>b:
        numbers +=10**(len(num)-2)
        result+=numbers*2
      else:
        result+=numbers*2
print(result)

Solution (Python):
import copy

N=int(input())

def arrange(List,n=N):  
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        List[up][down]+=1
    return List

original=[]
component=[]
for x in range(10):
    component.append(0)
for y in range(10):
    original.append(copy.deepcopy(component))


L=arrange(original)

ans=0

for j in range(10):
    for k in range(10):
        ans+=L[j][k]*L[k][j]

print(ans)

Solution (Python):
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)

Solution (Python):
n = int(input())
abba = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    top = int(str(i)[0])
    btm = i % 10
    abba[top][btm] += 1
cnt = 0
for i in range(10):
    for j in range(10):
        cnt += abba[i][j] * abba[j][i]
print(cnt)

Solution (Python):
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
for i in range(1, 10):
  for j in range(i, 10):
    a = str(i)
    b = str(j)
    for h in range(1,N+1):
      x = str(h)
      if x[0]==a and x[-1]==b:
        dic[(a,b)] += 1
      elif x[0]==b and x[-1]==a:
        dic[(b,a)] += 1

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

Solution (Python):
def top_number(num):
    top = 0
    while num > 0:
        top = num
        num //= 10
    return top


def main():
    N = int(input())
    group = [[0] * 10 for _ in range(10)]
    result = 0
    for i in range(1, N + 1):
        group[top_number(i)][i % 10] += 1
    for i in range(10):
        for j in range(10):
            result += group[i][j] * group[j][i]
    print(result)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

can_list = [[0 for _ in range(10)] for _ in range(10)]

str_list = list(map(str, range(1, N+1)))

for n in range(N):
    idx = str(n + 1)[0] + str(n + 1)[-1]
    can_list[int(idx[0])][int(idx[1])] += 1

res = 0
for i in range(10):
    for j in range(10):
        res += can_list[i][j] * can_list[j][i]


print(res)

Solution (Python):
n = int(input())
dp = []
ans = 0
for i in range(9):
  A = [0]*9
  dp.append(A)
for i in range(1,n+1):
  st = str(i)
  if len(st) == 1:
    dp[i-1][i-1] += 1
  else:
    top = int(st[0])
    tale = int(st[len(st)-1])
    if tale != 0:
      dp[top-1][tale-1] += 1
for i in range(9):
  for j in range(i,9):
    if i != j:
      ans += dp[i][j]*dp[j][i]*2
    else:
      ans += dp[i][i]**2
print(ans)

Solution (Python):
def resolve():
    N = int(input())
    c = 0
    for i in range(1, 10):
        for j in range(1, 10):
            a = 0
            b = 0
            for n in range(1, N+1):
                s = str(n)
                if s[0] == str(i) and s[-1] == str(j):
                    a += 1
                if s[0] == str(j) and s[-1] == str(i):
                    b += 1
            c += a * b
    print(c)
resolve()

Solution (Python):
n = int(input())
z100 = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1,n+1):
  h = int(str(i)[0])
  t = int(str(i)[-1])
  z100[h][t] += 1
ans = 0
for h in range(10):
  for t in range(10):
    ans += z100[h][t] * z100[t][h]
print(ans)

Solution (Python):
n = int(input())
z100 = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1,n+1):
  h = int(str(i)[0])
  t = int(str(i)[-1])
  z100[h][t] += 1
  
ans = 0
for h in range(10):
  for t in range(10):
    ans += z100[h][t] * z100[t][h]

print(ans)

Solution (Python):
N = int(input())
S = {}
for i in range(1,N+1):
    i = str(i)
    s = (i[0],i[-1])
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

c = 0
for i in range(1,N+1):
    i = str(i)
    s = (i[-1],i[0])
    if s in S:
        c += S[s]
print(c)

Solution (Python):
import numpy as np
N = int(input())

c = np.zeros((10,10),dtype = int)

for k in range(1,N+1):
	c[int(str(k)[0])][int(str(k)[-1])] += 1

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

Solution (Python):
N = int(input())
c = [[0 for _ in range(10)] for _ in range(10)]

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

Solution (Python):
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)

Solution (Python):
N = int(input())

"""考え方
先頭と末尾の組み合わせごとに何個あるかをカウント。
掛け合わせ数を積み上げ
"""


com = [10*[0] for _ in range(10)]
for n in range(1,N+1):
  _ = str(n)
  if _[0] == '0' or _[-1] == '0':
    continue
  com[int(_[0])][int(_[-1])] += 1



ans = 0
for x in range(10):
  for y in range(10):
    ans += com[x][y] * com[y][x] 

print(ans)

Solution (Python):


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)

Solution (Python):
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)

Solution (Python):
N = int(input())

c = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N+1):
    t = str(i)
    a, b = int(t[0]), int(t[-1])
    c[a][b] += 1

sum_num = 0
for s1 in range(10):
    for e1 in range(10):
        for s2 in range(10):
            for e2 in range(10):
                if s1 == e2 and e1 == s2:
                    sum_num += c[s1][e1] * c[s2][e2]

print(sum_num)

Solution (Python):
N = int(input())


C = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1,N+1):
  topi = int(str(i)[0])
  boti = i % 10
  C[topi][boti] += 1
  



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

Solution (Python):
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)

Solution (Python):

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    N = iRaw()
    numTB = [[0]*10 for _ in range(0,10)]

    for n in range(1,N+1):
        strN = str(n)
        numTB[int(strN[0])][int(strN[-1])]+=1
    ans = 0
    for a in range(1,10):
        for b in range(1,10):
            ans+= numTB[a][b] * numTB[b][a]
    return ans


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

Solution (Python):
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-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)

Solution (Python):
N = int(input())

x = 0




c = [[0]*10 for _ in range(10)]

for num in range(N+1):
    i = int(str(num)[0])
    j = int(str(num)[-1])
    c[i][j] += 1

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

print(x)

Solution (Python):

import sys


def solve(N: int):
    memo = [[0]*10 for _ in range(10)]

    for num in range(1,N+1):
        s_num = str(num)
        memo[int(s_num[0])][int(s_num[-1])] += 1
    
    answer = 0
    for i in range(10):
        for j in range(10):
            answer += memo[i][j]*memo[j][i]
    
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
N = int(input())

res = 0
freq = defaultdict(int)

for i in range(1, N+1):
    si = str(i)
    freq['{}{}'.format(si[0], si[-1])] += 1
    
for i in range(1, N+1):
    si = str(i)
    res += freq['{}{}'.format(si[-1], si[0])]
        
print(res)

Solution (Python):
n=int(input())
ans=0
dp=[]
for i in range(10):
  dp.append(i)
l=len(str(n))
for i in range(10,n+1):
  num1=int(str(i)[0])
  num2=int(str(i)[-1])
  if num2==0:
    dp.append(dp[-1])
    pass
  else: 
    num=dp[-1]
    nums=0
    l=len(str(i))
    for j in range(2,l):
      nums+=10**(j-2)     
    if num2>num1:
      num4=0
    elif num1>num2:
      num4=10**(l-2)
    else:
      num4=(i-(num2*10**(l-1)+num1))//10
    nums+=num4
    
    num+=nums*2
    if num1==num2:
      num+=3
    dp.append(num)
print(dp[n])

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

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

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline

def main():
    N = int(input())
    
    count = Counter()
    
    for i in range(1, N+1):
        s = str(i)
        count[(s[0], s[-1])] += 1
        
    ans = 0
    
    for i in range(1, N+1):
        s = str(i)
        ans += count[(s[-1], s[0])]
        
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict as dd
N = int(input())
dic = dd(int)
for i in range(1,N+1):
    dic[(str(i)[0],str(i)[-1])] += 1
res = 0
for i in range(100):
    res += dic[(str(i%10),str(i//10))]*dic[(str(i//10),str(i%10))]
print(res)

Solution (Python):
N=int(input())
resList=[[0]*10 for i in range(10)]
for i in range(1,N+1):
  SA=str(i)
  top=int(SA[0])
  bottom=int(SA[len(SA)-1])
  resList[top][bottom]+=1




res=0
for i in range(1,10):
  for j in range(i,10):
    if i==j:
      res+=resList[i][j]**2
    else:
      res+=resList[i][j]*resList[j][i]*2
print(res)

Solution (Python):
N = int(input())


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


for num in range(1,N + 1):
    temp = str(num)
    temp1 = int(temp[0])
    temp2 = int(temp[-1])
    pair[temp1][temp2] += 1
    
total = 0
for i in range(1,10):
    for j in range(1,10):
        total += pair[i][j] * pair[j][i]
        
print(total)

Solution (Python):
n=int(input())
a={}
b={}
for i in range(n+1):
    s=str(i)
    msd=s[0]
    lsd=s[len(s)-1]
    if msd=='0':
        continue
    if (msd,lsd) not in a:
        a[(msd,lsd)]=0
    if (msd,lsd) not in b:
        b[(msd,lsd)]=0
    a[(msd,lsd)]+=1
    b[(msd,lsd)]+=1
a_key=a.keys()
ans=0
for key in a_key:
    if key[1]==0:
        continue
    tmp=b.get((key[1],key[0]),0)
    ans+=tmp*a[(key[0],key[1])]
print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

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

for i in range(1,n+1):
    num = str(i)
    dp[int(num[0])][int(num[-1])] += 1
su = 0

for i in range(10):
    for j in range(10):
            su += dp[j][i] * dp[i][j]
print(su)

Solution (Python):
n = int(input())

num = 0

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

for i in range(10):
    for j in range(10):
        num += t_b[i][j]*t_b[j][i]

print(num)

Solution (Python):


N = int(input())
count = 0

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


for a in range(1,N+1):
    a_str = str(a)
    a_i, a_j = int(a_str[0]), int(a_str[-1]) 
    count_list[a_i][a_j] = count_list[a_i][a_j] + 1


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

print(count)

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

Solution (Python):
n = int(input())
ans = 0
for i in range(1, n+1):
	fix = 0
	L = int(str(i)[0])
	R = int(str(i)[-1])
	if L * R == 0:
		continue
	if L == R:
		fix += 1
	cur = 10
	dig = R*cur + L
	while dig <= n:
		fix += min(cur, max(0, n-dig+10)) // 10
		cur *= 10
		dig = R*cur + L
	ans += fix
	
print(ans)

Solution (Python):
def main():
    ns=input()
    ln=len(ns)
    n=int(ns)
    cd={}
    for b in range(1,10):
        for e in range(1,10):
            c=0
            if b==e and (ln>1 or b<=n):
                c+=1 
            if ln>2:
                c+=(10**(ln-2)-1)//9
            if ln>1:
                if b<int(ns[0]):
                    c+=10**(ln-2)
                elif b==int(ns[0]):
                    if ln>2:
                        c+=int(ns[1:-1])
                    if e<=int(ns[-1]):
                        c+=1
            cd[(b,e)]=c 
    s=0
    for b in range(1,10):
        for e in range(1,10):
            s+=cd[(b,e)]*cd[(e,b)]
    print(s)

main()

Solution (Python):
N = int(input())
ans = 0
l = [[0 for _ in range(10)] for _ in range(10)]
for A in range(1, N + 1):
    A = str(A)
    a = int(A[0])
    z = int(A[-1])
    l[a][z] += 1

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

print(ans)

Solution (Python):
n = int(input())
l = [[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])
    l[a][b] += 1

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

Solution (Python):
import sys
input = sys.stdin.readline

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:
    t=(i[1],i[0])
    if t in D:
        ans+=D[t]*D[i]
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
v = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    l = int(str(i)[0])
    r = int(str(i)[-1])
    v[l][r] += 1


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

print(ans)

Solution (Python):
n = int(input())

pair_count = {}
for i in range(1, 10):
    for j in range(1, 10):
        pair_count[(i,j)] = 0

for i in range(1,n+1):
    if(i % 10 == 0):
        continue
    s = str(i)
    key = (int(s[0]), int(s[-1]))
    pair_count[key] += 1

ans = 0
for k, v in pair_count.items():
    k_pair = (k[1], k[0])
    ans += v * pair_count[k_pair]

print(sum([pair_count[k] * pair_count[(k[1], k[0])] for k in pair_count]))

Solution (Python):
N = int(input())
data_list = [[0] * 10 for _ in range(10)]
ans = 0

for n in range(1, N+1):
    s = str(n)
    a, b = int(s[0]), int(s[-1])
    data_list[a][b] += 1

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