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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 21:23:54 2020

@author: over-
"""

N=input()
L=len(N)

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

    if x==y:
        
        if L==1:
            d=1
        if L==2:
            d=1
            if int(N)>=int('{}{}'.format(x,x)):
                d+=1
        if L==3:
            d=1+1
            if int(N)>=int('{}9{}'.format(x,x)):
                d+=10
            elif int(N)>=int('{}0{}'.format(x,x)):
                d+=int(N[1:-1])
        if L==4:
            d=1+1+10
            if int(N)>=int('{}99{}'.format(x,x)):
                d+=100
            elif int(N)>=int('{}00{}'.format(x,x)):
                d+=int(N[1:-1])
        if L==5:
            d=1+1+10+100
            if int(N)>=int('{}999{}'.format(x,x)):
                d+=1000
            elif int(N)>=int('{}000{}'.format(x,x)):
                d+=int(N[1:-1])
        if L==6:
            d=1+1+10+100+1000
            if int(N)>=int('{}9999{}'.format(x,x)):
                d+=10000
            elif int(N)>=int('{}0000{}'.format(x,x)):
                d+=int(N[1:-1])
        
        c+=d
    else:
        if y!=0:
            if L==2:
                d=0
                if int(N)>=int('{}{}'.format(y,x)):
                    d+=1
            if L==3:
                d=1
                if int(N)>=int('{}9{}'.format(y,x)):
                    d+=10
                elif int(N)>=int('{}0{}'.format(y,x)):
                    d+=int(N[1:-1])
            if L==4:
                d=1+10
                if int(N)>=int('{}99{}'.format(y,x)):
                    d+=100
                elif int(N)>=int('{}00{}'.format(y,x)):
                    d+=int(N[1:-1])
            if L==5:
                d=1+10+100
                if int(N)>=int('{}999{}'.format(y,x)):
                    d+=1000
                elif int(N)>=int('{}000{}'.format(y,x)):
                    d+=int(N[1:-1])
            if L==6:
                d=1+10+100+1000
                if int(N)>=int('{}9999{}'.format(y,x)):
                    d+=10000
                elif int(N)>=int('{}0000{}'.format(y,x)):
                    d+=int(N[1:-1])
            
            c+=d
    
print(c)

Submission status: Wrong Answer

Solution code:
import itertools as it
N=int(input())

count=0


A=list(it.product(range(1,N+1),repeat=2))

print(A)
for i in range(len(A)):
    #print(A[i][0][:1],A[i][1][-1:], A[i][0][-1:],A[i][1][:1])
    if str(A[i][0])[:1]==str(A[i][1])[-1:] and str(A[i][0])[-1:]==str(A[i][1])[:1]:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
def bunkai(n:int):
    ls=list(str(n))
    top,bottom=int(ls[0]),int(ls[-1])
    if n<=99:
        middle=0
    else:
        middle=int("".join(ls[1:-1]))
    return top, middle, bottom

n=int(input())
Nt,Nm,Nb = bunkai(n)

count=0
for i in range(1,n+1):
    t,m,b = bunkai(i)
    if b==0:continue
    if t==b:count+=1
    if n<=99:
        if int(b+t)<=n:count+=1
    else:
        keta = len(str(n))
        for x in range(keta-2):
            count+=10**x
        x+=1
        if Nt>b:
            count+=10**x
        elif Nt==b:
            if Nb>=t:
                count+=Nm+1
            else:
                count+=Nm
print(count)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
# 解答見た

n = int(input())

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import operator
import functools

N = int(input())

def calc(first, last, digit, limit):
  cnt = 0

  if digit == 0:
    if int(first + last) <= limit:
      cnt += 1
    return cnt
  
  lst = []
  fixed = []

  for n in reversed(range(1, digit+1)):
    pas = False
    for d in reversed(range(0, 9+1)):
      v = first
      v += "".join(map(str, fixed))
      v += str(d)
      v += "0" * (n - 1)
      v += last

      if int(v) <= limit:
        lst.append(d + 1)
        fixed.append(d)
        pas = True
        break
    
    if not pas:
      fixed.append(0)
  
  if len(lst) == 0:
    return cnt
  return cnt + int(functools.reduce(operator.mul, lst, 1))

cnt = 0
n = 1

while n <= N:
  first = list(str(n))[0]
  last = list(str(n))[-1]

  if first == "0" or last == "0":
    n += 1
    continue

  if first == last and int(first) <= N:
    cnt += 1
  
  digit = 0
  while True:
    total = calc(last, first, digit, N)
    if total == 0:
      break
    cnt += total
    digit += 1
  n += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

for i in range(N):
    Top = str(i)[0]
    Btm = str(i)[-1]

    if Btm == '0':
        continue
    
    IJ[int(Top)][int(Btm)] += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

# print(table)

for i in range(1,n):
    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: Wrong Answer

Solution code:
import operator

N = int(input())

def calc(first, last, digit, limit):
  cnt = 0

  if digit == 0:
    if int(first + last) <= limit:
      cnt += 1
    return cnt
  
  lst = []
  fixed = []

  for n in reversed(range(1, digit)):
    pas = false
    for d in reversed(range(0, 9)):
      v = first
      v += "".join(fixed)
      v += str(d)
      v += "0" * (n - 1)
      v += last

      if int(v) <= limit:
        lst.append(d + 1)
        fixed.append(d)
        pas = true
        break
    
    if not pas:
      fixed.append(0)
  
  if len(lst) == 0:
    return cnt
  return cnt + int(reduce(operator.mul, lst, 1))

cnt = 0
n = 1

while n <= N:
  first = list(str(n))[0]
  last = list(str(n))[-1]

  if first == "0" or last == "0":
    n += 1
    continue

  if first == last and int(first) <= N:
    cnt += 1
  
  digit = 0
  while True:
    total = calc(last, first, digit, N)
    if total == 0:
      break
    cnt += total
    digit += 1
  n += 1

print(cnt)

Submission status: Wrong Answer

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

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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#a, b = map(int, input().split())
N = int(input())

D = [[0 for _ in range(0, 10)] for _ in range(0, 10)]
#print (D)

def P(n, r):
  return math.factorial(n)//math.factorial(n-r)

x = 0
y = 0
for i in range(1, N+1) :
  x = int(str(i)[0])
  y = int(str(i)[-1])
  #print(x)
  #print(y)
  D[x][y] += 1
  
sum = 0
for i in range(1, 10) :
  for j in range(i, 10) :
    if i == j :
      sum += D[i][j] ** 2
    else :
      if D[i][j] != 0 and D[j][i] != 0 :
        sum += P((D[i][j] + D[j][i]), 2)
    
print (sum)
print (D)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 0

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

for number in range(1, n):
    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: Wrong Answer

Solution code:
import itertools
N = int(input())
num_list = list(map(str, range(1, N)))
combi_list = [i for i in zip(num_list,num_list)]
combi_list_2 = [i for i in itertools.permutations(num_list,2)]
ab = 0
for i in combi_list:
    if (i[0][-1] == i[1][0]) & (i[0][0] == i[1][-1]):
        ab += 1
for i in combi_list_2:
    if (i[0][-1] == i[1][0]) & (i[0][0] == i[1][-1]):
        ab += 1
print(ab)

Submission status: Wrong Answer

Solution code:
N=int(input())
lenN=len(str(N))
#N=2*(10**5)
lst=[]
for i in range(1,min(N+1,10)):
    lst.append(str(i))
for i in range(11,N+1):
    s=str(i)
    if s[0]!="0" and s[-1]!="0" and s.count("0")==len(s)-2:
        lst.append(str(i))

count=0
lst2=[0 for i in range(len(lst))]
for i,a in enumerate(lst):
    if str(N)[0]==a[0] and len(str(N))==len(a) and len(a)>2:
        #print(a)
        lst2[i]=int(str(N)[1:-1])
    else:
        lst2[i]=max(1,10**(len(a)-2))
#print(lst2)

for ia,a in enumerate(lst):
    for ib,b in enumerate(lst):
        if a[0]==b[-1] and b[0]==a[-1]:
            count+=lst2[ia]*lst2[ib]
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
lenN=len(str(N))
#N=2*(10**5)
lst=[]
for i in range(1,min(N+1,10)):
    lst.append(str(i))
for i in range(11,N+1):
    s=str(i)
    if s[0]!="0" and s[-1]!="0" and s.count("0")==len(s)-2:
        lst.append(str(i))

count=0
lst2=[0 for i in range(len(lst))]
for i,a in enumerate(lst):
    if str(N)[0]==a[0] and len(str(N))==len(a) and len(a)>2:
        #print(a)
        lst2[i]=int(str(N)[1:-1])
    else:
        lst2[i]=max(1,10**(len(a)-2))
print(lst2)

for ia,a in enumerate(lst):
    for ib,b in enumerate(lst):
        if a[0]==b[-1] and b[0]==a[-1]:
            count+=lst2[ia]*lst2[ib]
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
lenN=len(str(N))
#N=2*(10**5)
lst=[]
for i in range(1,min(N+1,10)):
    lst.append(str(i))
for i in range(11,N+1):
    s=str(i)
    if s[0]!="0" and s[-1]!="0" and s.count("0")==len(s)-2:
        lst.append(str(i))

count=0
lst2=[0 for i in range(len(lst))]
for i,a in enumerate(lst):
    if str(N)[0]==a[0] and len(str(N))==len(a) and len(a)>2:
        print(a)
        lst2[i]=int(str(N)[1:-1])
    else:
        lst2[i]=max(1,10**(len(a)-2))
print(lst2)

for ia,a in enumerate(lst):
    for ib,b in enumerate(lst):
        if a[0]==b[-1] and b[0]==a[-1]:
            count+=lst2[ia]*lst2[ib]
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0 for _ in range(81)]
ans = 0
for i in range(1, 10):
    for l in range(1, 10):
        for q in range(1, N+1):
            s = 0
            a = str(i)[0]
            b = str(i)[-1]
            if int(a) == i and int(b) == l:
                s += 1
            t[9*(i - 1)+l - 1] += s
for i in range(1, N+1):
    a = str(i)[0]
    b = str(i)[-1]
    if b == "0":
        continue
    else:
        ans += t[9*(int(b)-1)+int(a)-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [0]*100
for i in range(N):
  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: Wrong Answer

Solution code:
N = int(input())
max_N = 2 * 10 ** 5
 
d = [[0] * 10 for _ in range(10)]
for i in range(1,int(N)):
  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: Wrong Answer

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]**2

print(point)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

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: Wrong Answer

Solution code:
n = int(input())
nl = str(n)
ll = len(nl)
lis = []
ans = 0
if ll == 1:
  print(n)
  exit()
  
def countn(a,b):
  cur = 0
  for i in range(1,n+1):
    fff=str(i)
    if fff[0] == a and fff[-1] == b:
      cur += 1
  return cur

for i in range(1, 10):
  for j in range(1, i+1):
    if i == j:
      ans += countn(i, j)*countn(j, i)
    else:
      ans += 2*countn(i, j)*countn(j, i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(1, 10):
    for j in range(1, 10):
        for n in range(1, N+1):
            if str(n)[0] == i and str(n)[-1] == j:
                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: Wrong Answer

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):
    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: Wrong Answer

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(l)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
table = [[0] * 10 for _ in range(10)]
for i in range(1, N):
    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: Wrong Answer

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

for i in range(N):
    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: Wrong Answer

Solution code:
N = int(input())
S = str(N)
S_l = len(S)
if N<=9:
  print(N)
  exit()
ans = 0

for i in range(1,S_l):
  for j in range(i,S_l):
    if i==1:
      if i==j:
        ans+=9
      else:
        ans+=2*(9*(10**(j-2)))
    else:
      if i==j:
        ans+=81*(10**(i-2))*(10**(j-2))
      else:
        ans+=2*81*(10**(i-2))*(10**(j-2))

lim = int(S[0]+S[-1])
ans+=2*(lim//11)*(10**(S_l-2))
for i in range(2,S_l):
  ans+=2*(((lim//10)-1)**2)*(10**(S_l-2))*(10**(i-2))
  ans+=2*(lim%10)*(10**(S_l-2))*(10**(i-2))
  
ans+=((lim//10)-1)*((10**(S_l-2))**2)
ans+=2*(min(lim%10,lim//10))*((10**(S_l-2))**2)
if lim//10<=lim%10:
  ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:


#n以下の数でそのような組み合わせの個数
def func(n):
    res=None

    if n<10 :
        res=1

    else:
        l=len(str(n))
        #lは桁数

        #plus:nが増えたことで増える組み合わせの数
        plus=0

        #先頭の数
        h=int(str(n)[0])
        #末尾の数
        t=int(str(n)[-1])

        if t>h:
            plus=2*(10**(l-2)-1)//9

        elif t==h:
            if l<3:
                plus=1


            else:
                plus=(10**(l-2)-1)//9
                q=int(str(n)[1:-1])
                plus+=q

            plus=2*plus+1

        else:
            if t==0:
                plus=0

            else:
                if l<3:
                    plus=1


                else:
                    plus=(10**(l-2)-1)//9
                    q=int(str(n)[1:-1])
                    plus+=q
            
            plus*=2
        res=plus

    return res


N=input()


N=int(N)
ans=0
for i in range(1,N+1):
    ans+=func(i)

print(ans)

Submission status: Wrong Answer

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 += x[i][j] * x[j][i]
print(b)

Submission status: Wrong Answer

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: Wrong Answer

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: Wrong Answer

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

for i in range(N):
    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: Wrong Answer

Solution code:
n=int(input())
num=[[[] for _ in range(10)] for _ in range(10)]
ans=0
for i in range(1,n):
    first=int(str(i)[0])
    end=int(str(i)[-1])
    num[first][end].append(i)

for i in range(1,n):
    first=int(str(i)[0])
    end=int(str(i)[-1])
    for j in num[end][first]:
        if i<=n:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())


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

for i in range(1,N):
    s = str(i)
    i1 = int(s[0])
    i2 = int(s[-1])
    c[i1][i2] += 1
    
total = 0
for i in range(10):
    for j in range(10):
        total += c[i][j] * c[j][i]
        
print(total)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    count = 0
    c_ij = np.array([
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
    ])
    for i in range(1,N):
        c_ij[int(str(i)[0]), int(str(i)[-1])] += 1

    c_ji = np.array([
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
    ])
    for i in range(1,N):
        c_ji[int(str(i)[-1]), int(str(i)[0])] += 1

    print(np.sum(c_ij * c_ji))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    count = 0
    c_ij = np.array([
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
    ])
    for i in range(N):
        c_ij[int(str(i)[0]), int(str(i)[-1])] += 1

    c_ji = np.array([
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
    ])
    for i in range(N):
        c_ji[int(str(i)[-1]), int(str(i)[0])] += 1

    print(np.sum(c_ij * c_ji) - 1)

Submission status: Wrong Answer

Solution code:
N=input()

ans=0
for start in range(9,0,-1):
    for end in range(start,0,-1):
        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(1,10):
            n=start*10**2+i*10**1+end
            if n<=N: t+=1

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

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


        for i in range(1,10):
            for ii in range(1,10):
                for iii in range(1,10):
                    for iiii in range(1,10):
                        n=start*10**5+i*10**4+ii*10**3+iii*10**2+iiii*10**1+end
                        if n<=N: t+=1
        #print "start,end,t ::: ",start,end,t,t**2
        if start==end:
            ans+=t**2
        else:
            ans+=t*2

print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = (n // 10) ** 2 + 8
if str(n % 10) >= str(n)[0]:
  ans += 1
for i in range(1, n % 10 + 1):
  if i == int(str(n)[0]):
    ans += 2
  elif i < int(str(n)[0]):
    if len(str(n)) >= 2:
      ans += 10 ** (len(str(n)) - 2) * 2
  else:
    if len(str(n)) >= 3:
      ans += 10 ** (len(str(n)) - 3) * 2

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
def f(x,y):
  ret=0
  for i in range(1,n):
    s,e=int(str(i)[0]),int(str(i)[-1])
    if x==s and y==e:
      ret+=1
  return ret
ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=f(i,j)*f(j,i)
print(ans)

Submission status: Wrong Answer

Solution code:
def hoge(num):
    tmp = str(num)
    return (int(tmp[0]), int(tmp[-1]))

def slove(n):
    num_list = list(range(1, n+1))
    count = 0
    for a in num_list:
        a_info = hoge(a)
        for b in num_list:
            b_info = hoge(b)
            if a_info[0] == b_info[1] and a_info[1] == b_info[0]:
                print(a, b)
                count += 1
    return count

if __name__ == "__main__":

    n = int(input())
    print(slove(n))

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
import numpy as np

N = int(input())

counter = 0

lead = np.zeros((9, 9))

for i in range(N):
    if (i % 10 != 0):
        moji = str(i)
        lead[int(moji[0]) - 1][int(moji[-1]) - 1] += 1

for i in range(N):
    if (i % 10 != 0):
        moji = str(i)
        tmp = moji[-1]
        counter += lead[int(moji[-1]) - 1][int(moji[0]) - 1]

print(int(counter))

Submission status: Wrong Answer

Solution code:
import math

def large(f, l, k):
    return f * (10 ** (k + 1)) + (((10 ** k) - 1) * 10) + l

def small(f, l, k):
    return f * (10 ** (k + 1)) + l

def first_last(i):
    i_str = str(i)
    f = int(i_str[0])
    l = int(i_str[-1])
    return (f, l)

def middle(i):
    if i < 100:
        return 0
    else:
        return int(str(i)[1:-1])

def search(start, f, l, k):
    current = start
    while current >= small(f, l, k):
        fc, lc = first_last(current)
        if fc == f and lc == c:
            return current
        else:
            current -= 1

    return -1

n = int(input())

log_tmp = math.log10(n)
nk = math.ceil(log_tmp)
if log_tmp % 1 == 0:
    nk += 1

ans = 0
for a in range(1, n + 1):
    if a >= 10 and a % 10 == 0:
        continue
    else:
        f, l = first_last(a)
        # print("f=%d l=%d" % (f, l))
        c = True

        if f == l:
            ans += 1
            # print("f l same add 1")

        for k in range(0, nk):
            # print("k=%d" % k)

            if large(l, f, k) <= n:
                ans_t = 10 ** k
                ans += ans_t
                # print("all large add %d" % ans_t)
            elif small(l, f, k) <= n < large(l, f, k):
                start = search(n, l, f, k)
                if start > 0:
                    ans_t = (middle(start) + 1)
                else:
                    ans_t = 0
                ans += ans_t
                # print("part large start:%d add:%d" % (start, ans_t))
                c = False
            else:
                c = False

            if not c:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

n_ = str(n)
p = len(n_)

if p < 2:
  print(n)
  exit()
  
if p == 2:
  ans = 0
  for i in range(1, n+1):
    i_ = str(i)
    x = int(i_[0])
    y = int(i_[-1])
    if y == 0:
      continue
    if x == y:
      ans += 1
    if int(i_[-1]+i_[0]) <= n:
      ans += 1
  print(ans)
  exit()

ans = 0
for i in range(1, n+1):
  i_ = str(i)
  x = int(i_[0])
  y = int(i_[-1])
  if y == 0:
    continue
  if x == y:
      ans += 1
    
  for j in range(p-2):
    ans += 10**j
  if y == int(n_[0]):
    for k in range(p-2):
      ans += int(n_[k+1])*(10**(p-2-1-k))
      if k == p-3:
        ans += int(n_[k+1])*(10**(p-2-1-k))
        if x <= int(n_[-1]):
          ans += 1
  elif y < int(n_[0]):
    ans += 10**(p-2)
  else:
    pass

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = (n // 10) ** 2 + 8
if str(n % 10) >= str(n)[0]:
  ans += 1
ans += 10 ** (len(str(n)) - 2) * min(n % 10, int(str(n)[0])) * 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math


def large(f, l, k):
    return f * (10 ** (k + 1)) + (((10 ** k) - 1) * 10) + l


def small(f, l, k):
    return f * (10 ** (k + 1)) + l


def first_last(i):
    i_str = str(i)
    f = int(i_str[0])
    l = int(i_str[-1])
    return (f, l)


def middle(i):
    if i < 100:
        return 0
    else:
        return int(str(i)[1:-1])


def search(start, f, l):
    current = start
    while current > 0:
        fc, lc = first_last(current)
        if fc == f and lc == c:
            return current
        else:
            current -= 1

    return -1


def hitoketa(i):
    ans = 0
    keta = 1
    current = i
    while current <= n:
        ans += 1
        keta += 1
        current = int(str(i) * keta)

    return ans

n = int(input())

log_tmp = math.log10(n)
nk = math.ceil(log_tmp)
if log_tmp % 1 == 0:
    nk += 1

ans = 0
for a in range(1, n + 1):
    if a >= 10 and a % 10 == 0:
        continue
    else:
        if a < 10:
            f = l = a
        else:
            f, l = first_last(a)
        # print("f=%d l=%d" % (f, l))
        c = True

        if f == l:
            ans += 1
            # print("f l same add 1")

        for k in range(0, nk):
            # print("k=%d" % k)

            if large(l, f, k) <= n:
                ans_t = 10 ** k
                ans += ans_t
                # print("all large add %d" % ans_t)
            elif small(l, f, k) <= n < large(l, f, k):
                start = search(n, l, f)
                if start > 0:
                    ans_t = (middle(start) + 1)
                else:
                    ans_t = 0
                ans += ans_t
                # print("part large start:%d add:%d" % (start, ans_t))
                c = False
            else:
                c = False

            if not c:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
def solve(i,n):
    left = int(str(i)[0])
    right = int(str(i)[-1])
    n_mx_left = int(str(n)[-1])
    n_mx_right = int(str(n)[0])


    mx_digit = len(str(n))
    counter = 0
    first = True
    while mx_digit >= 3:
        if left < n_mx_left and right <= n_mx_right and first == True:
            counter += int("9" * (mx_digit-2) or 0)
        elif left == n_mx_left and right <= n_mx_right and first == True:
            _,*temp,_ = str(n)
            temp = "".join(temp)
            temp = int(temp)
            counter += temp

        if left <= n_mx_left and right <= n_mx_right and first == False:
            counter += int("9" * (mx_digit-2) or 0)


        n_mx_left = 9
        n_mx_right = 9
        mx_digit -= 1

    if mx_digit == 2:
        if (left <= n_mx_left and right <= n_mx_right) and right != 0:
            #print(i)
            counter += 1
        mx_digit -= 1

    if mx_digit == 1:

        if left == right:
            #print(i)
            counter += 1

    return counter







def main():
    n = int(input())
    counter = 0
    for i in range(1,n+1):
        counter += solve(i,n)
    print(counter)



if __name__ == '__main__':
    main()