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



Sample input:
25


Sample output:
17

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
lenN=len(str(N))
lst=[]
lst2=[[0 for m in range(10)] for i in range(10)]

for i in range(11,100):
    if "0" not in str(i):
        lst.append(str(i))
for i in range(1,N+1):
    if "0" not in [int(str(i)[0]),int(str(i)[-1])]:
        lst2[int(str(i)[0])][int(str(i)[-1])]+=1
#print(lst)
count=0
for a in lst:
    for b in lst:
        if a[0]==b[-1] and b[0]==a[-1]:
            b=lst2[int(a[0])][int(a[-1])]*lst2[int(b[0])][int(b[-1])]
            count+=(b) if b>1 else b
print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())

ans = 0

f = lambda x: (int(str(x)[0]), int(str(x)[-1]))

freq = defaultdict(int)
for i in range(1, n+1):
    p = f(i)
    freq[p] += 1

for i in range(1, n+1):
    p = f(i)
    q = (p[1], p[0])
    ans += freq[q]
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
N = int(input())

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

for n in range(1, N + 1):
  l = n % 10
  if l == 0:
    continue
  t = n // (10 ** (len(str(n)) - 1))
  c[t - 1][l - 1] += 1

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def resolve():

    n = int(input())
    mat = [[0] * 10 for _ in range(10)]

    for k in range(1, n+1):

        str_k = str(k)

        i = int(str_k[0])
        j = int(str_k[-1])

        mat[i][j] += 1

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

    print(ans)
    
resolve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    dic = {}
    for i in range(10):
        for j in range(10):
            dic[(i, j)] = 0
    for num in range(1, n+1):
        str_num = str(num)
        i = int(str_num[0])
        j = int(str_num[-1])
        dic[(i, j)] += 1

    total = 0
    for i in range(10):
        for j in range(10):
            total += dic[(i, j)] * dic[(j, i)]
    print(total)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
def resolve():
    N = int(input())

    freq = np.zeros((10, 10))
    for i in range(1, N+1):
        s = str(i)
        head = int(s[0])
        tail = int(s[-1])
        freq[head][tail] += 1
        
    ans = 0
    for i in range(1, N+1):
        s = str(i)
        head = int(s[0])
        tail = int(s[-1])
        ans += freq[tail][head]      

    print(int(ans))
    

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())

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

# print(table)

for i in range(1,n+1):
    a = str(i)
    s = int(a[0])
    e = int(a[-1])
    table[s][e] += 1

# print(table)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

from collections import defaultdict

m = defaultdict(lambda: 0)

for a in range(1, n + 1):
  s = str(a)
  f = int(s[0])
  l = int(s[-1])
  m[(f, l)] += 1

ans = 0
for b in range(1, n + 1):
  s = str(b)
  f = int(s[0])
  l = int(s[-1])
  ans += m[(l, f)]

print(ans)

Submission status: Accepted

Solution code:
from itertools import product

N = input()
l = len(N)
a = int(N[0])
b = int(N[-1])

if l == 1:
    print(l)
    exit()
elif l == 2:
    print(9 + min(a, b) ** 2 * 2)
    exit()

N = N[1:-1]
table = [[0] * 10 for _ in range(10)]
for i in range(1, 10):
    table[i][i] = 1

for i, j in product(range(1, 10), repeat=2):
    table[i][j] += sum(10 ** (l - i) for i in range(3, l + 1))
    if i < a:
        table[i][j] += 10 ** (l - 2)
    elif i == a:
        if b < j:
            table[i][j] += sum((int(N[-i - 1])) * 10 ** i for i in range(l - 2))
        else:
            table[i][j] += sum((int(N[-i - 1])) * 10 ** i for i in range(l - 2)) + 1

answer = 0
for i, j in product(range(1, 10), repeat=2):
    answer += table[i][j] * table[j][i]
    # print(i, j, table[i][j], table[j][i])

print(answer)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
for i in range(1,n + 1):
    s = str(i)
    if s[0] == "0" or s[-1] == "0":
        continue
    else:
        d[int(s[0])][int(s[-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)

Submission status: Accepted

Solution code:
n=int(input())
cnt=0
# c(i,j)={先頭がiで末尾がjであるkの個数}
c=[[0 for _ in range(10)] for _ in range(10)]
for i in range(1,n+1):
  l=int(str(i)[0])
  r=int(str(i)[-1])
  c[l][r]+=1
'''
for i in range(10):
  for j in range(10):
    print(c[i][j], end=' ')
  print('')
'''
sum=0
for i in range(1,10):
  for j in range(1,10):
    sum+=c[i][j]*c[j][i]
print(sum)

Submission status: Accepted

Solution code:
N = int(input())

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

for n in range(1, N+1):
    first = int(str(n)[0])
    last = int(str(n)[-1])
    ctable[first][last] += 1

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

N=input()

L=defaultdict(lambda: 0) 
for i in range(1,N+1):
    i=str(i)
    begin=int(str(i)[0])
    end=int(str(i)[-1])
    L[(begin,end)]+=1


ans=0
for begin in range(1,10):
    for end in range(1,10):
        ans+=L[(begin,end)]*L[(end,begin)]

print ans

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    c = [[0] * 10 for _ in range(10)]
    for k in map(str, range(1, N+1)):
        i = int(k[0])
        j = int(k[-1])
        c[i][j] += 1
    n = 0
    for i in range(10):
        for j in range(10):
             n += c[i][j] * c[j][i]
    print(n)

resolve()

Submission status: Accepted

Solution code:
N = int(input())

c = []
for i in range(10):
    c.append([0] * 10)
    
#先頭がh,末尾がrの数字の数を記憶
for i in range(N):
    s = str(i+1)
    h = int(s[0])
    r = int(s[-1])
    c[h][r] += 1
    
    
ans = 0
for i in range(10):
  for j in range(10):
    ans += c[i][j]*c[j][i]
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
c = [[0]*10 for _ in range(10)]
for k in range(1,N+1):
    tmp = str(k)
    i = int(tmp[0])
    j = int(tmp[-1])
    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)

Submission status: Accepted

Solution code:

N = int(input())
res = 0
import collections
cnt = collections.Counter()
for i in range(1, N+1):
    str_i = str(i)
    cnt[str_i[0] + str_i[-1]] += 1
res = 0
# print(cnt)
for k, v in cnt.items():
    if k[0] == k[-1]:
        res += v * v
    elif k[-1]+k[0] in cnt:
        res += v * cnt[k[-1]+k[0]]
print(res)

Submission status: Accepted

Solution code:
def d_handstand2():
    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
    return sum([c[i][j] * c[j][i] for i in range(10) for j in range(10)])

print(d_handstand2())

Submission status: Accepted

Solution code:
ns = input()
n = int(ns)

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

for k in range(1,n+1):
    pre = k
    now = k
    j = k%10
    while now>=1:
        pre = now
        now //= 10
    c[pre][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)

Submission status: Accepted

Solution code:
n = int(input())
li = []
for i in range(9):
  li_2 = []
  for j in range(9):
    li_2.append(0)
  li.append(li_2)

ans = 0
for i in range(1,n+1):
  i = str(i)
  t = int(i[0])
  f = int(i[-1])
  if f != 0:
    li[t-1][f-1] += 1
for i in range(9):
  for j in range(9):
    cnt =  li[i][j]*li[j][i]
    ans += cnt
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(answer)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
dis = np.zeros((10,10))

for i in range(1,N+1):
  s = str(i)
  a = int(s[0])
  b = int(s[-1])
  if a != 0 and b != 0:
     dis[a][b] += 1

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

Submission status: Accepted

Solution code:
N=input()

L={}
for start in range(1,10):
    for end in range(1,10):
        t=0
        if start==end:
            n=start
            if n<=N: t+=1

        n=start*10**1+end
        if n<=N: t+=1

        for i in range(10):
            n=start*10**2+i*10**1+end
            if n<=N:
                t+=1

        for i in range(10):
            for ii in range(10):
                n=start*10**3+i*10**2+ii*10**1+end
                if n<=N:
                    t+=1

        for i in range(10):
            for ii in range(10):
                for iii in range(10):
                        n=start*10**4+i*10**3+ii*10**2+iii*10**1+end
                        if n<=N: t+=1


        for i in range(10):
            for ii in range(10):
                for iii in range(10):
                    for iiii in range(10):
                        n=start*10**5+i*10**4+ii*10**3+iii*10**2+iiii*10**1+end
                        if n<=N: t+=1
        L[(start,end)]=t
    

ans=0

for start in range(1,10):
    for end in range(1,10):
        ans+=L[(start,end)]*L[(end,start)]

print ans

Submission status: Accepted

Solution code:
n=int(input())
cnt=[[0 for i in range(10)] for _ in range(10)]
for i in range(1,n+1):
  a=int(str(i)[0])
  b=i%10
  if b==0:
    continue
  cnt[a][b]+=1
ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=cnt[i][j]*cnt[j][i]
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
candidate = []
ans = 0

import itertools

for i in range(1, n+1):
    if (i % 10) != 0:
        candidate.append(str(i))
for i, j in (itertools.product(['1', '2', '3', '4', '5', '6', '7', '8', '9'], repeat=2)):
# for i, j in (itertools.product(range(1, 10), repeat=2)):
    i_j = 0
    j_i = 0
    for k in candidate:
        start, end = k[0], k[-1]
        # start, end = int(k[0]), int(k[-1])
        if start == i and end == j:
            i_j += 1
        if start == j and end == i:
            j_i += 1
    ans += (i_j * j_i)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())

cnt = [[0]*10 for i in range(10)]
#print(cnt)

#先頭がi,末尾がjの数字のカウント: cnt[i][j]
for i in range(1, n+1):
    s = str(i)
    #print("---s: ", s)
    head = int(s[0])
    #print("head: ", head)
    tail = int(s[-1])
    #print("tail: ", tail)
    cnt[head][tail] += 1

#print(cnt)

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
memo = [[0 for i in range(10)] for j in range(10)]
for i in range(1,n+1):
    i_first = int(str(i)[0])
    i_last = int(str(i)[-1])
    memo[i_first][i_last] += 1
ans = 0
for i in range(1,n+1):
    i_first = int(str(i)[0])
    i_last = int(str(i)[-1])
    ans += memo[i_last][i_first]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=[[0 for i in range(9)] for j in range(9)]
for i in range(1,n+1):
  if i%10!=0:
    num=str(i)
    A[int(num[0])-1][int(num[-1])-1] +=1

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

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(1, n+1):
    val = str(i)
    s = val[0]
    e = val[-1]
    #print(val, s, e)
    c[int(s)][int(e)] += 1

#print(c)
ans = 0
for s in range(1, 10):
    for e in range(1, 10):
        ans += c[s][e] * c[e][s]
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
c = [[0 for i in range(10)] for j in range(10)]

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

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())

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

for k in range(1,n+1):
    atama = int(str(k)[0])
    ushiro = int(str(k)[-1])
    li[atama][ushiro] += 1

point = 0

for l in range(1,10):
    for m in range(1,10):
        point += li[l][m]*li[m][l]
print(point)

Submission status: Accepted

Solution code:
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)]))

Submission status: Accepted

Solution code:
import numpy as  np

N=int(input())
key=np.zeros((10,10))

for i in range(1, N+1):
    s = str(i)
    key[int(s[0]), int(s[-1])]+=1
print(int(sum(sum((key*np.transpose(key))))))

Submission status: Accepted

Solution code:
N = int(input())

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

# 先頭がi,末尾がjの数字のカウント : cnt[i][j]

for i in range(1,N+1):
    s = str(i)
    head = int(s[0])
    tail = int(s[-1])
    cnt[head][tail] += 1
# print(cnt)
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d=[10*[0]for _ in range(10)]
ans=0
for i in range(1,n+1):
  s=str(i)
  if s[0]=="0" or s[-1]=="0":
    continue
  else:
    d[int(s[0])][int(s[-1])]+=1
for i in range(1,10):
  for j in range(1,10):
    ans+=d[i][j]*d[j][i]
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
count = 0

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

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

for j in range(10):
    for k in range(10):
        count += c[j][k] * c[k][j]

print(count)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

tl = [i for i in range(1, n+1) if i % 10 != 0]

"""
l = list(itertools.product(tl, tl))

# print(l)

ans = []
count = 0
for pair in l:
    a = str(pair[0])
    b = str(pair[1])
    if (a[0] == b[len(b)-1]) and (a[len(a)-1] == b[0]):
        count += 1
        # ans.append(pair)

print(count)
# print(ans)
"""

c = [[0 for j in range(10)] for i in range(10)]
for k in range(1, n+1):
    i = int(str(k)[0])  # 先頭 k=114514 なら1
    j = int(str(k)[len(str(k))-1])  # 末尾 k=114514 なら4
    c[i][j] += 1

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
cand = 0
memo = dict()
ans = 0
for i in range(1, n+1):
    s = str(i)[0]
    f = str(i)[-1]
    if s+f in memo:
        ans += memo[s+f]
    else:
        count = 0
        for j in range(1,n+1):
            q = str(j)[0]
            r = str(j)[-1]
            if q == f and r == s:
                count += 1
        ans += count
        memo[s+f] = count
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

c = []
for i in range(10 * 10):
    c.append(0)

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

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

print(cc)

Submission status: Accepted

Solution code:

import numpy as np
N=int(input()) 
num=0
count=0
allcount=0
diglen=len(str(N)) #Nの桁数
#print(N%10,int(N/pow(10,diglen-1)),str(diglen))
table=np.zeros((10,10))

for i in range(N):
    num=str(i+1)
    b=int(num[len(num)-1])
    a=int(num[0])
    table[a][b]=table[a][b]+1
#print(table)
for i in range(10):
    for j in range(10):
        count=count+table[i][j]*table[j][i]
        
print(int(count))

Submission status: Accepted

Solution code:
N = int(input())
table = [[0] * 10 for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    if s[-1] == '0': continue
    table[int(s[0])][int(s[-1])] += 1

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

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n):
    c = [[0 for i in range(10)] for j in range(10)]
    for i in range(1, n+1):
        str_i = str(i)
        len_i = len(str_i)
        c[int(str_i[len_i-1])][int(str_i[0])] += 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__':
    n = int(sys.stdin.readline().strip())
    solve(n)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    
    res = [[0] * 10 for _ in range(10)]
    for i in range(1, n+1):
        s = str(i)
        if s[-1] == '0':
            continue
        res[int(s[0])][int(s[-1])] += 1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    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)
        A[int(s[0])][int(s[-1])] += 1
    ans = 0
#    [print(a) for a in A]
    for a in range(1, 10):
        for b in range(1, 10):
            ans += A[a][b] * A[b][a]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
c={}
for i in range(1,10):
  for j in range(1,10):
    l=str(i)
    r=str(j)
    c[l+r]=0


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

Submission status: Accepted

Solution code:
N = int(input())
c = [0]*9
for i in range(9):
    c[i] = [0]*9
#先頭がiで末尾がjの数を数えていく
for i in range(1,N+1):
    s = str(i)
    p = s[0]
    l = s[-1]
    p = int(p)
    l = int(l)
    if p != 0 and l != 0:
        c[p-1][l-1] += 1
ans = 0
#A=c[i][j],B=c[j][i]として(A,B)の組み合わせの数を数えていく
for i in range(9):
    for j in range(9):
        ans += c[i][j]*c[j][i]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
c = np.zeros((10, 10), dtype='int')

for k in range(1, N + 1):
    k = str(k)
    i, j = int(k[0]), int(k[-1])
    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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = 10
b = 0
x = np.zeros((10, 10, ))
for i in range(1,n+1):
  while (i // a != 0):
    a = a * 10
  c = (i * 10) // a
  d = i % 10
  x[c][d] += 1

for i in range(0,10):
  for j in range(0,10):
    b += int(x[i][j] * x[j][i])
print(b)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
cnt = defaultdict(int)

for i in range(1, N + 1):
    h = str(i)[0]
    f = str(i)[-1]
    if f == '0':
        continue
    cnt[(h, f)] += 1

ans = 0
dlst = list(cnt.items())
for i, v in dlst:
    ans += v * cnt[i[1], i[0]]

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
# TT = [[0]*10 for i in range(10)]
TT = np.zeros((10,10))

for i in range(N+1):
    top = int(str(i)[0])
    tail = int(str(i)[-1])
    TT[top,tail] += 1
#print(TT)
y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i,j]*TT[j,i]
print(int(y))

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
for i in range(1, n+1):
    s = str(i)
    if s[0] == "0" or s[-1] == "0": continue
    d[int(s[0])][int(s[-1])] += 1

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

Submission status: Accepted

Solution code:
N = int(input())
K = len(str(N))
MS = int(str(N)[0])
ML = int(str(N)[-1])
res = 0

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

    if AL == 0:
        continue

    for k in range(1, K+1):
        if k == 1:
            if AS == AL and AS <= N:
                res += 1
            continue
        if k == 2:
            if int(str(AL) + str(AS)) <= N:
                res += 1
            continue
        if k < K:
            res += 10 ** (k - 2)
            continue
        if k == K:
            if AL > MS:
                continue
            if AL < MS:
                res += 10 ** (k - 2)
                continue
            if AL == MS:
                if AS <= ML:
                    res += (int(str(N)[1:])+9) // 10
                    continue
                else:
                    res += (int(str(N)[1:])) // 10
                    continue


print(res)

Submission status: Accepted

Solution code:
n=int(input())
lists=[[ [] for j in range(10)]for i in range(10)]
for i in range(1,n+1):
    a=str(i)
    lists[int(str(a[0]))][int(str(a[-1]))].append(i)
c=0
for i in range(1,10):
    for j in range(1,10):
        c+=len(lists[i][j])*len(lists[j][i])
print(c)

Submission status: Accepted

Solution code:
N = int(input())
TT = [[0]*10 for i in range(10)]

for i in range(N+1):
    top = int(str(i)[0])
    tail = int(str(i)[-1])
    TT[top][tail] += 1
#print(TT)
y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i][j]*TT[j][i]
print(y)

Submission status: Accepted

Solution code:
N = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
    stri = str(i)
    c[int(stri[0])][int(stri[-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)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
c = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N+1):
    s, e = int(str(i)[0]), int(str(i)[-1])
    c[s][e] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

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

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

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

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    c = [[0 for i in range(10)] for j in range(10)]
    for k in range(1, N+1):
        s = str(k)
        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()

Submission status: Accepted

Solution code:

N = int(input())
if N <= 9:
    print(N)
    exit()

tot_count = 0
for af in map(str, range(1, 10)):
    for bf in map(str, range(1, 10)):
        a_count = 0
        b_count = 0
        for a in map(str, range(1, N + 1)):
            if a[0] == af and a[-1] == bf:
                a_count += 1
        for b in map(str, range(1, N + 1)):
            if b[0] == bf and b[-1] == af:
                b_count += 1

        tot_count += a_count * b_count

print(tot_count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = 0

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

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

ans = 0
for i in range(1,n+1):
    s,t = int(str(i)[0]),int(str(i)[-1])
    ans += dp[t][s]
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
AB = [(int(s[0]), int(s[-1])) for s in map(str, range(1,n+1))]

def count(a, b):
    return sum([1 for ab in AB if ab[0] == a and ab[1] == b])

ans = 0
for pair in itertools.product(range(10), range(10)):
    a, b = pair
    c1 = count(a, b)
    c2 = count(b, a)
    ans += c1 * c2
print(ans)

Submission status: Accepted

Solution code:
ns = input()
N=int(ns)

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    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)
        A[int(s[0])][int(s[-1])] += 1

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

    print(ans)


if __name__ == '__main__':
    main()