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:
def c(i, j, N):
    ans = 0
    for k in range(N):
        str_k = str(k)
        if str_k[0] == str(i) and str_k[-1] == str(j):
            ans += 1

    return ans


N = int(input())

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

print(ans)

Submission status: Wrong Answer

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

N=int(input())
for i in range(1,min([N,10])):
  dic[(i,i)]+=1
for i in range(10,min([N,100])):
  dic[(i//10,i%10)]+=1
for i in range(100,min([N,1000])):
  dic[(i//100,i%10)]+=1
for i in range(1000,min([N,10000])):
  dic[(i//1000,i%10)]+=1
for i in range(10000,min([N,100000])):
  dic[(i//10000,i%10)]+=1
for i in range(100000,N):
  dic[(i//100000,i%10)]+=1
ans=0
for i in range(1,10):
  for j in range(1,10):
    x=dic[(i,j)]
    y=dic[(j,i)]
    ans+=x*y
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
def C(i, j):
    a = set()
    si = str(i)
    sj = str(j)
    for k in range(N):
        sk = str(k)
        if sk[0] == si and sk[-1] == sj:
            a.add(k)
    return a

for i in range(10):
    for j in range(10):
        if i == j == 0:continue
        ans += len(C(i, j)) * len(C(j, i))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
ns=str(n)
l=len(ns)
ans=0
for i in range(1,n+1):
    s=str(i)
    x=s[0]
    y=s[-1]
    if y=='0':
        continue
    if x==y:
        ans+=1
    for j in range(l-2):
        ans+=10**j
    if int(ns[0])>int(y):
        ans+=10**(l-2)
    elif int(ns[0])<int(y):
        pass
    else:
        z=n-int(ns[0])*10**(l-1)
        ans+=(z-int(x)+9)//10
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
tbl1 = [[0]*10 for i in range(10)]
tbl2 = [[0]*10 for i in range(10)]
# for j in range(10):
#     for k in range(10):
#         cnt1 = 0
#         cnt2 = 0
#         for i in range(1,n+1):
#             s = str(i)
#             if s[0] == str(k)and s[-1] == str(j):
#                 cnt1 += 1
#             if s[0] == str(j) and s[-1] == str(k):
#                 cnt2 += 1
#         ans += cnt1*cnt2
for i in  range(1,n):
    s = str(i)
    for j in range(10):
        for k in range(10):
            if s[0] == str(k)and s[-1] == str(j):
                tbl1[k][j] += 1
            if s[0] == str(j) and s[-1] == str(k):
                tbl2[j][k] += 1
for j in range(10):
        for k in range(10):
            ans += tbl1[k][j] * tbl2[j][k]
print(ans)

Submission status: Wrong Answer

Solution code:
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if len(str(N)) > (k+1) :
                res += 10 ** (k - 1)
                k += 1
                continue
            elif str(N)[0] > str(a) :
                res += 10 ** (k - 1)
                k += 1
                continue
            else :
                p = 1
                Q = N - (a * (10 ** k) + b)
                for i in range(len(str(Q))-1):
                    p *= (int(str(Q)[i]) + 1 )
                res += p
                k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if len(str(N)) > (k+1) :
                res += 10 ** (k - 1)
                k += 1
                continue
            if str(N)[0] > str(a) :
                res += 10 ** (k - 1)
                k += 1
                continue

            p = 1
            Q = N - (a * (10 ** k) + b)
            for i in range(len(str(Q))-1):
                p *= (int(str(Q)[i]) + 1 )
            res += p
            k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if str(N)[0] > str(a) or len(str(N)) > (k + 1):
                res += 10 ** (k - 1)
                k += 1
                continue
            p = 1
            Q = N - (a * (10 ** k) + b)
            for i in range(len(str(Q))-1):
                p *= (int(str(Q)[i]) + 1 )
            res += p
            k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if str(N)[0] > str(a) or len(str(N)) > (k + 1):
                res += 10 ** (k - 1)
                k += 1
                continue
            p = 1
            Q = N - (a * (10 ** k) + b)
            keep = [0 for i in range(k - 1)]
            for i in range(len(str(Q)) - 1):
                keep[-1 - i] = int(str(Q)[-2 - i])
            for i in range(k - 2):
                p *= (keep[i] + 1)
            res += p
            k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
if N ==1:
  cnt =1
for i in range(N-1):
  i += 1
  s = str(i)
  if i < 10:
    if int(s+s) <= N:
      cnt +=2
    cnt += 1
  elif i % 10 != 0:
    le = len(s) -1
    if int(s[le]+s[1:le]+s[0]) <= N:
      cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
for i in range(N-1):
  i += 1
  s = str(i)
  if i < 10:
    if int(s+s) <= N:
      cnt +=2
    else:
      cnt+=1
  elif i % 10 != 0:
    le = len(s) -1
    if int(s[le]+s[1:le]+s[0]) <= N:
      if s == s[::-1]:
        cnt +=1
      else:
        cnt+=2

print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import time


t = time.time()
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

def fkc(keta):
    if keta == 1:
        return 10
    else:
        return 10**keta

def pat_b(a, n):
    tail = a % 10

    if tail == 0:
        return 0

    head = int(str(a)[0])

    ret = 0
    if tail == head: #１桁解
        ret += 1

    if n >= tail*10+head: #２桁解は１通りあるかないか
        ret += 1

    for free_keta in range(1, 6):
        mincase = 10**(free_keta+1) * tail + head

        if n < mincase:
            break
        if n >= 10**(free_keta+1) + mincase + head - 10:
            ret += fkc(free_keta)
            continue
        else:
            ret += int(int(n-mincase)/10) + 1
    return ret

def main():
    n = iip()
    result = 0
    for i in range(n):
        result += pat_b(i, n)
    print(result)


main()

Submission status: Wrong Answer

Solution code:
n = int(input())

dp = [0 for i in range(n+1)]

for i in range(1, n+1):
    headi = int(str(i)[0])
    taili = int(str(i)[-1])
    count = 0
    if taili == 0:
        dp[i] = dp[i-1]
    else:
        for j in range(n+1):
            headj = int(str(j)[0])
            tailj = int(str(j)[-1])
            if headi == tailj and taili == headj:
                count += 1
                print('{}, {}'.format(i, j))
        dp[i] = dp[i-1] + count

print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
l = len(str(n))

#先頭の桁がiで末尾の桁がjの数…a、それがいくつあるか…c_a
#先頭の桁がjで末尾の桁がiの数…b、それがいくつあるか…c_b
ans = 0
for i in range(1,10) :
  for j in range(i,10) :
    c_a = 0
    c_b = 0
    #桁数ごとにチェック
    for d in range(1,l+1) :
      if d == 1 or d == 2 :
        for k in range(10**(d-1),min(10**d,n+1)) :
          if int(str(k)[0]) == i and int(str(k)[-1]) == j :
            c_a += 1
          if int(str(k)[0]) == j and int(str(k)[-1]) == i :
            c_b += 1
      elif d > 2 :
        if i == int(str(n)[0]) and d == l :
          temp_a = 1
          temp_b = 0
          for k in range(1,l-1) :
            if j > int(str(n)[-1]) and k == l-2 :
              temp_a *= (int(str(n)[k]))
            else :
              temp_a *= (int(str(n)[k])+1)
          if i == j :
            temp_b = temp_a
          elif d != l :
            temp_b = 10**(d-2)
          elif j <= int(str(n)[0]) :
            temp_b = 10**(d-2)
          c_a += temp_a
          c_b += temp_b
        elif j == int(str(n)[0]) and d == l :
          temp_a = 0
          temp_b = 1
          for k in range(1,l-1) :
            if i > int(str(n)[-1]) and k == l-2 :
              temp_b *= (int(str(n)[k]))
            else :
              temp_b *= (int(str(n)[k])+1)
          if i == j :
            temp_a = temp_b
          elif d != l :
            temp_a = 10**(d-2)
          elif i <= int(str(n)[0]) :
            temp_a = 10**(d-2)
          c_a += temp_a
          c_b += temp_b
        else :
          if i*10**(d-1) + j <= n :
            c_a += 10**(d-2)
          if j*10**(d-1) + i <= n :
            c_b += 10**(d-2)
    if i == j :
      ans += c_a*c_b
    else :
      ans += c_a*c_b*2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
str_n=str(n)
digit=len(str_n)

digit_count=[[0]*9 for i in range(9)]
for i in range(digit):
    for j in range(9):
        #先頭の数j+1
        if (j+1)*10**(i)>n:break
        for k in range(9):
            if i>0 and int(j+1)*10**(i)+int(k+1)>n:break
            if i==0:
                digit_count[j][j]=1

            elif i!=1 and i==digit-1 and j+1==int(str_n[0]) and (k+1==int(str_n[-1]) or str_n[-1]=='0'):
                digit_count[j][k]+=int(str_n[1:-1])+1 if str_n[-1]!='0' else int(str_n[1:-1])
            else:
                digit_count[j][k]+=10**(i-1)

#print(*digit_count,sep='\n')

ans=0
for i in range(9):
    for j in range(9):
        if i==j:
            ans+=digit_count[i][j]**2
        else:
            ans+=digit_count[i][j]*digit_count[j][i]*2
            digit_count[j][i]=0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
str_n=str(n)
digit=len(str_n)

digit_count=[[0]*9 for i in range(9)]
for i in range(digit):
    for j in range(9):
        #先頭の数j+1
        if (j+1)*10**(i)>n:break
        for k in range(9):
            if int(j+1)*10**(i)+int(k+1)>n:break
            if i==0:
                digit_count[j][j]=1

            elif i!=1 and i==digit-1 and j+1==int(str_n[0]) and (k+1==int(str_n[-1]) or str_n[-1]=='0'):
                digit_count[j][k]+=int(str_n[1:-1])+1 if str_n[-1]!='0' else int(str_n[1:-1])
            else:
                digit_count[j][k]+=10**(i-1)

#print(*digit_count,sep='\n')

ans=0
for i in range(9):
    for j in range(9):
        if i==j:
            ans+=digit_count[i][j]**2
        else:
            ans+=digit_count[i][j]*digit_count[j][i]*2
            digit_count[j][i]=0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    str_N = str(N)
    head_N, tail_N = int(str_N[0]), int(str_N[-1])
    digits = len(str_N)
        
    def f(x):
        s = str(x)
        head, tail = int(s[0]), int(s[-1])
        res = 0
        if head == tail: res += 1 #1桁
        if digits >= 2: #2桁
            if digits == 2:
                if int(s[-1]+s[-0]) <= N: res += 1
            else: res += 1
        for d in range(3, digits+1): #3桁以上
            k = d - 2
            if d == digits: #Nと同じ桁数
                if tail < head_N:
                    res += 10**k
                elif tail == head_N:
                    res += int(str_N[1:-1])
            else: res += 10**k

        return res

    ans = 0
    for n in range(1,N+1):
        if n % 10 == 0: continue
        ans += f(n)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    str_N = str(N)
    head_N, tail_N = int(str_N[0]), int(str_N[-1])
    digits = len(str_N)
        
    def f(x):
        s = str(x)
        head, tail = int(s[0]), int(s[-1])
        res = 0
        if head == tail: res += 1 #1桁
        if digits >= 2: #2桁
            if digits == 2:
                if tail <= head_N: res += 1
            else: res += 1
        for d in range(3, digits+1): #3桁以上
            k = d - 2
            if d == digits: #Nと同じ桁数
                if tail < head_N:
                    res += 10**k
                elif tail == head_N:
                    res += int(str_N[1:-1])
            else: res += 10**k

        return res

    ans = 0
    for n in range(1,N+1):
        if n % 10 == 0: continue
        ans += f(n)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import bisect
# # import heapq
# # from copy import deepcopy
# # from collections import deque
# # from collections import Counter
# # from itertools import accumulate
# # from itertools import permutations
# import numpy as np
# # import math
# a,b,c = map(int, input().split())

# p = list(map(int, input().split()))
n = int(input())
count = 0
a = [[0] * 10 for i in range(10)]
# print(a)
# print(b)
for i in range(n):
    head = int(str(i)[0])
    tail = int(str(i)[-1])
    # if i == 18:
    #     print(head,tail)
    a[head][tail] += 1


for i in range(n):
    if i % 10 == 0:
        continue

    head = int(str(i)[0])
    tail = int(str(i)[-1])
    count += a[tail][head]

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=-1
for i in range(N):
  i=str(i)
  for j in range(N):
    j=str(j)
    if i[0]==j[-1] and i[-1]==j[0]:
      c+=1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
max_l = len(str(N))
cnt = 0
for n in range(1, N+1):
    str_n = str(n)
    f_n, l_n = str_n[0], str_n[-1]
    if(f_n == '0' or l_n == '0'):
        continue
    if(f_n == l_n):
        cnt += 1
    i = 0
    while(int(l_n +'0'*i + f_n)<=N):
        cnt += min(math.ceil((N-int(l_n +'0'*i + f_n))/10), 10**i)
        i += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    c = [[0] * 10 for i in range(10)]
    for i in range(n+1):
        b = i % 10
        for j in range(5):
            if i//(10**(j+1)) == 0:
                a = i//(10**j)
                break
        c[a][b] += 1
    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += c[i][j] * c[j][i]
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = []
cnt = 0

for i in range(1,n):
    for j in range(1,n):
        a = str(i)
        b = str(j)
        if a[0] == b[-1] and a[-1] == b[0]:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
a = [[[] for i in range(10)] for j in range(10)]
for i in range(n):
    a[int(str(i)[0])][int(str(i)[-1])].append(i)

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

print(ans)

Submission status: Wrong Answer

Solution code:
def count_new_set_with_x(x):
    x = str(x)
    if len(x) == 1:
        return 1
    if x[-1] == 0:
        return 0
    if x[0] > x[-1]:
        return (9 ** (len(x) - 1) - 1) / 4
    elif x[0] < x[-1]:
        return (9 ** (len(x) - 2) - 1) / 4
    else:
        center = x[1:-1]
        if center:
            return (9 ** (len(x) - 2) - 1) / 4 + int(center) * 2 + 1
        else:
            return (9 ** (len(x) - 2) - 1) / 4 + 1



n = int(input())
result = 0
for i in range(1, n):
    result += count_new_set_with_x(i)

print(int(result))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
d = defaultdict(int)

for n in range(N):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(1, 10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
A = [0]*100
for i in range(1,N+1):
    A[(int(str(i)[0]))*10+int(str(i)[-1])] += 1
for i in range(0,10):
    for j in range(i,10):
        if i==j:
            ans += A[i*10+j]**2
        else:
            ans += min(A[i*10+j],A[j*10+i])*2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
A = [0]*100
for i in range(1,N+1):
    A[(int(str(i)[0])-1)*10+int(str(i)[-1])-1] += 1
for i in range(1,10):
    for j in range(i,10):
        if i==j:
            ans += A[i*10+j]**2
        else:
            ans += 2*A[i*10+j]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
A = [0]*100
for i in range(1,N+1):
    if int(str(i)[-1]) == 0:
        continue
    A[(int(str(i)[0])-1)*10+int(str(i)[-1])-1] += 1
for i in range(1,10):
    for j in range(i,10):
        if i==j:
            ans += A[i*10+j]**2
        else:
            ans += 2*A[i*10+j]
print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())

ans = 0
for i in range(1,n+1):
  if str(i)[0]==str(i)[-1]:
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
counter = 0
for i in range(num):
  a = str(i)
  for j in range(num):
    b = str(j)
    if (a[-1] == b[0]) and (a[0] == b[-1]):
      counter += 1
      
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
N_str = list(str(N))
length = len(str(N))

#1<=k<=Nで 先頭がiで末尾がjの総和
c = [[0]*9 for i in range(9)]
'''
#C(i,j)を求めるのは死ぬ

def count(i, j):
    pass

for i in range(9):
    for j in range(9):
        c[i][j] = count(i, j)
'''

for i in range(1, N):
    s = str(i)
    if s[0] == "0" or s[-1] == "0":continue
    c[int(s[0])-1][int(s[-1])-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: Wrong Answer

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    sN = input()
    N = int(sN)
    firts_digit = int(sN[0])
    last_digit = int(sN[-1])
    num_candidates = max(min(firts_digit,last_digit),firts_digit -1 )
    max_inter_digits = len(sN) - 2
    

    ans = 0
    #for i in range(10**(len(sN)-1),N+1):
    max_inter_digits = len(sN) - 2
    intermediate = 0
    for _ in range(max_inter_digits):
        intermediate = intermediate*10+1
    # print(intermediate)
    if len(sN) == 1:
        print(N)
        return
    elif len(sN) == 2:
        ans = 0
        for i in range(1,10):
            tmp = i
            while tmp <= N:
                tmp = tmp*10+i
                ans += 1
                # print(i,ans)
        for i in range(11,N+1):
            if i % 10 == 0:
                continue
            if i % 11 == 0:
                ans += 1
            if (i % 10) * 10 + i//10 <= N:
                ans += 1
            # print(i,ans)
        print(ans)
        return 

    first_N = int(sN[0])
    last_N = N % 10
    for i in range(1,N+1):

        # print(i,ans,intermediate)
        if i%10 == 0:
            continue
        si = str(i)
        #print(intermediate)
        if si[0] != si[-1]:
            ans += intermediate
        else:
            ans += intermediate + 1
            # ans += 
        # print(i,ans,intermediate)
        first_B = i % 10
        last_B = int(si[-1])
        # first_N = int(sN[0])
        # last_N = i % 10



        
        if first_B <  first_N:
            ans += pow(10,max(len(sN)-2,0))
        elif first_B == first_N:
            # print(i) if i == 1 or i == 11 else None
            sm = sN[1:-1]
            m = (N % pow(10,len(sN)-1)) // 10 + 1 #if len(sN) > 2 else (N % pow(10,len(sN)-1))
            # print('i=',i,'m=',m)
            if last_B <= last_N:
                ans += m
            else:
                ans += max(m-1,0)
            # print(i,m) if i == 1 or i == 11 else None

            
            
    print(ans)
    '''


        N = 2500
        2012
        2
        22
        2?2
        2xy2 - 2492
            x: 0...4
            y: 0...9
            sm = 2492 = sN[:-2]+si[0]
            m = int(m)
            if m > N:
                sm = str(m-10)
            intermediate += (sm[1]+1)*....*(sm[-2]+1)
            

        N = 90000
        i = 65432
        26
        2?6
        2??6
        2???6 29996
            first_i = int(si[-1])
            first_N = int(N[0])
            if first_i <  first_N:
                intermediate = intermediate *10 +1
                ans += intermediate
            elif first_i == first_N:
                sm = sN[:-2]+si[0]
                tmp = 1
                for c in sm[1:-2]:
                    tmp*= c+1
                ans += tmp
            
                
                



        N = 30512
        i = 503
        i[-1] == N[0]
        35
        3?5
        3??5
        3???5 
        sm =  30505 = sN[0:-1] + str(i[0])
        intermediate += (s[1]+1)*...*(s[-2]+1)
        if m < N:
            m -=10
        '''

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    sN = input()
    N = int(sN)
    firts_digit = int(sN[0])
    last_digit = int(sN[-1])
    num_candidates = max(min(firts_digit,last_digit),firts_digit -1 )
    max_inter_digits = len(sN) - 2
    

    ans = 0
    #for i in range(10**(len(sN)-1),N+1):
    max_inter_digits = len(sN) - 2
    intermediate = 0
    for _ in range(max_inter_digits):
        intermediate = intermediate*10+1
    if len(sN) == 1:
        print(N)
        return
    elif len(sN) == 2:
        ans = 0
        for i in range(1,10):
            tmp = i
            while tmp <= N:
                tmp = tmp*10+i
                ans += 1
                print(i,ans)
        for i in range(11,N+1):
            if i % 10 == 0:
                continue
            if i % 11 == 0:
                ans += 1
            if (i % 10) * 10 + i//10 <= N:
                ans += 1
            # print(i,ans)
        print(ans)
        return 

    for i in range(1,N+1):

        # print(i,ans,intermediate)
        if i%10 == 0:
            continue
        si = str(i)
        #print(intermediate)
        if si[0] != si[-1]:
            ans += intermediate
        else:
            ans += intermediate + 1
            # ans += 
        # print(i,ans,intermediate)
        first_i = int(si[-1])
        last_i = i % 10
        first_N = int(sN[0])
        last_N = i % 10



        
        if first_i <  first_N:
            ans += pow(10,max(len(sN)-2,0))
        elif first_i == first_N:
            sm = sN[1:-1]
            m = (N % pow(10,len(sN)-1)) // 10 #if len(sN) > 2 else (N % pow(10,len(sN)-1))
            # print('i=',i,'m=',m)
            if last_i <= last_N:
                ans += m
            else:
                ans += max(m-1,0)

            
            
    print(ans)
    '''


        N = 2500
        2012
        2
        22
        2?2
        2xy2 - 2492
            x: 0...4
            y: 0...9
            sm = 2492 = sN[:-2]+si[0]
            m = int(m)
            if m > N:
                sm = str(m-10)
            intermediate += (sm[1]+1)*....*(sm[-2]+1)
            

        N = 90000
        i = 65432
        26
        2?6
        2??6
        2???6 29996
            first_i = int(si[-1])
            first_N = int(N[0])
            if first_i <  first_N:
                intermediate = intermediate *10 +1
                ans += intermediate
            elif first_i == first_N:
                sm = sN[:-2]+si[0]
                tmp = 1
                for c in sm[1:-2]:
                    tmp*= c+1
                ans += tmp
            
                
                



        N = 30512
        i = 503
        i[-1] == N[0]
        35
        3?5
        3??5
        3???5 
        sm =  30505 = sN[0:-1] + str(i[0])
        intermediate += (s[1]+1)*...*(s[-2]+1)
        if m < N:
            m -=10
        '''

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
for n in range(1,N+1):
    if n%10==0:continue
    s = str(n)
    if s[0]==s[-1]:
        if int(s[0])<=N:ans+=1
    for i in range(10):
        a = int(s[-1]+"9"*i+s[0])
        b = int(s[-1]+"0"*i+s[0])
        if a<=N:ans+=pow(10,i)
        else:
            if b<=N:ans+=(N-a)//10+1
            break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N+1):
  nstr = str(i)
  pre = nstr[0]
  suf = nstr[-1]
  print(pre)
  print(suf)
  if suf == '0':
    continue
  dic[(pre, suf)] =dic[(pre, suf)] + 1

cnt = 0 
for i in range(1,10):
  for j in range(1,10):
    cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N):
  nstr = str(i)
  pre = nstr[0]
  suf = nstr[-1]
  if suf == '0':
    continue
  dic[(pre, suf)] =dic[(pre, suf)] + 1

cnt = 0 
for i in range(1,10):
  for j in range(1,i):
    cnt += 2*dic[(str(i),str(j))] * dic[(str(j),str(i))]
  cnt += dic[(str(i),str(i))] * dic[(str(i),str(i))]

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N):
  nstr = str(i)
  pre = nstr[0]
  suf = nstr[-1]
  if suf == '0':
    continue
  dic[(pre, suf)] =dic[(pre, suf)] + 1

cnt = 0 
for i in range(1,10):
  for j in range(1,i+1):
    cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]
  
  
print(dic.values())

Submission status: Wrong Answer

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

def counter(i, j):
    c = 0
    if i == j and i <= n:
        c += 1
    if n >= 10 * i + j and len(str(n)) >= 2:
        c += 1
    if len(str(n)) >= 3:
        if n >= (10 ** (len(str(n)) - 1)) * i + j:
            c += 1
        for o in range(1, len(str(n)) - 1):
            c += 10 ** o
    return c

ans = 0
for k in range(1, 10):
    for l in range(1, 10):
        ans += counter(k, l) * counter(l, k)

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    x = str(n + 1)
    c[int(x[0])][int(x[-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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[[0]*10]*10
for i in range(1,n+1):
  for j in range(1,10):
    for k in range(1,10):
      if str(i)[0]==str(j) and str(i)[len(str(i))-1]==str(k):
        c[j][k]+=1
num=0
for j in range(1,10):
  for k in range(1,10):
    num+=c[j][k]*c[k][j]
print(num)

Submission status: Wrong Answer

Solution code:
def pick(n):
  s = str(n)
  n_list = list(map(int, s))
  a = n % 10
  b = int(n_list[0])
  return str(b) + str(a)

ans = 0
N = int(input())
freq = [0] * 200000
for i in range(N):
  a = int(pick(i))
  freq[a] += 1		# 先頭がa，末尾がbとなるものの個数
for i in range(N):
  s = pick(i)
  b = int(s[1] + s[0])
  ans += freq[b]
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
def pick(n):
  s = str(n)
  n_list = list(map(int, s))
  a = n % 10
  b = int(n_list[0])
  return str(b) + str(a)

ans = 0
N = int(input())
freq = [0] * 200000
for i in range(N):
  a = int(pick(i))
  freq[a] += 1		# 先頭がa，末尾がbとなるものの個数
for i in range(N):
  s = pick(i)
  b = int(s[1] + s[0])
  ans += freq[b]
if N == 1:
  ans = 2
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
count=0
n=int(input())
for a in range(1,n):
    for b in range(1,n):
        aa=str(a)
        bb=str(b)
        fa=int(aa[0])
        fb=int(bb[0])
        la=a%10
        lb=b%10
        if fa==lb and fb==la:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
D={}
for i in range(n):
    s=(str(i)[0],str(i)[-1])
    if s 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)