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:

class Num:
    def __init__(self, h, t, d):
        self.head = h
        self.tail = t
        self.digit = d
        self.min = self.get_min()
        self.max = self.get_max()

    def get_min(self):
        if self.digit == 1:
            if self.head == self.tail:
                return self.head
            else:
                return 0
        else:
            return self.head * (10 ** (self.digit-1)) + self.tail

    def get_max(self):
        if self.digit == 1:
            if self.head == self.tail:
                return self.head
            else:
                return 0
        if self.digit == 2:
            return self.get_min()
        else:
            return self.get_min() + (10 ** (self.digit-1) - 10)


def solve(a, b, n):
    if a.min * a.max * b.min * b.max == 0:
        return 0

    if a.min > n:
        return 0

    if b.min > n:
        return 0

    if a.max > n:
        if a.digit >= 3:
            if str(a.max)[-1] > str(n)[-1]:
                if str(n)[-2] == '0':
                    return 0
                else:
                    a.max = int(str(a.max)[0] + str(n-10)[1:-1] + str(a.max)[-1])
            else:
                a.max = int(str(a.max)[0] + str(n)[1:-1] + str(a.max)[-1])

    if b.max > n:
        if b.digit >= 3:
            if str(b.max)[-1] > str(n)[-1]:
                if str(n)[-2] == '0':
                    return 0
                else:
                    b.max = int(str(b.max)[0] + str(n-10)[1:-1] + str(b.max)[-1])
            else:
                b.max = int(str(b.max)[0] + str(n)[1:-1] + str(b.max)[-1])

    total_a = (a.max - a.min) // 10 + 1
    total_b = (b.max - b.min) // 10 + 1
    count = total_a * total_b

    # print('------')
    # print(a.min, a.max)
    # print(b.min, b.max)
    # print(count)

    return count


def main():
    n = int(input())
    digit_n = len(str(n))

    total = 0
    for a_head in range(1, 10):
        for a_tail in range(1, 10):

            b_head = a_tail
            b_tail = a_head

            for digit_a in range(1, digit_n+1):
                for digit_b in range(1, digit_n+1):
                    a = Num(a_head, a_tail, digit_a)
                    b = Num(b_head, b_tail, digit_b)
                    count = solve(a, b, n)
                    total += count

    print(total)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    r = 0
    for i in range(1, min(10, N+1)):
        r += 1
        if N >= int(str(i) * 2):
            r += 1
        else:
            continue
        j = 1
        while True:
            if int(str(i) + '9' * j  + str(i)) > N:
                r += complex(i, i, j, N)
                break
            else:
                r += 10 ** j
                j += 1
    if N < 10:
        return r
    for i in range(11, N+1):
        if i % 10 == 0:
            continue
        t = int(str(i)[0])
        b = int(str(i)[-1])
        if t == b:
            r += 1
        if N >= int(str(b) + str(t)):
            r += 1
        else:
            continue
        j = 1
        while True:
            if int(str(b) + '9' * j + str(t)) > N:
                r += complex(b, t, j, N)
                break
            else:
                r += 10 ** j
                j += 1
    return r
def complex(b, t, j, N):
    if int(str(b) + '0' * j + str(t)) > N:
        return 0
    N_m = int(str(N)[1:-1])
    if t >= int(str(N)[-1]):
        return (N_m)
    return N_m - 1
print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
if n%10==0:
  print((int(n/10)**2+8))
else:
  
  x=n%100
  y=n//100
  if y==0:
    k=0
    n=0
  else:
    k=8
  if len(str(x))==1:
    print((int(n/10)**2+k)+x*4)
  elif len(str(x))==2:
    z=x//10
    Z=z*10+z
    if x>=Z:
      print( (int(n//10)**2+k) +(z+1)**2+8)
    elif x<Z:
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*4)

Submission status: Wrong Answer

Solution code:
import math
from itertools import product

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

nf = int(str(N)[0])
keta = int(math.log10(N)) + 1
count = 0
for i, j in product(range(1, keta + 1), repeat=2):
    for af, bf in product(range(1, 10), repeat=2):
        if i == keta:
            if af > nf:
                continue
            elif af == nf:
                if keta >= 3:
                    a_ptn = (N - (nf * 10 ** (keta - 1) + bf)) // 10 + 1
                else:
                    a_ptn = 1
            else:
                a_ptn = 10 ** (keta - 2)
        elif i == 1:
            a_ptn = 1
        else:
            a_ptn = 10 ** (i - 2)

        if j == keta:
            if bf == nf:
                continue
            elif bf == nf:
                if keta >= 3:
                    b_ptn = (N - (nf * 10 ** (keta - 1) + af)) // 10 + 1
                else:
                    b_ptn = 1
            else:
                b_ptn = 10 ** (keta - 2)
        elif j == 1:
            b_ptn = 1
        else:
            b_ptn = 10 ** (j - 2)
        count += a_ptn * b_ptn

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n%10==0:
  print((int(n/10)**2+8))
else:
  
  x=n%100
  y=n//100
  if y==0:
    k=0
    n=0
  else:
    k=8
  if len(str(x))==1:
    print((int(n/10)**2+8)+x*4)
  elif len(str(x))==2:
    z=x//10
    Z=z*10+z
    if x>=Z:
      print( (int(n//10)**2+k) +(z+1)**2+8)
    elif x<Z:
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*4)

Submission status: Wrong Answer

Solution code:
N = int(input())

def keta(i):
    return len(str(i))
def start(i):
    l = str(i)
    return int(l[0])
def end(i):
    return i%10

result = 0

for a in range(1,N+1):
    s = start(a) #bのend
    e = end(a) #bのstart
    if s == 0 or e == 0:
        continue
    # print("a",a)
    for j in range(1,keta(N)+1):
        # print(j)
        if j == 1:
            if j < keta(N):
                if s == e:
                    result +=1
                else:
                    continue
            elif j == keta(N):
                if s == e and s <= N:
                    result += 1
        elif j == 2:
            if 10*e+s <= N:
                result += 1
        elif j < keta(N):
            result += 10**(j-2)
        elif j == keta(N):
            if start(N) > e:
                result += 10**(j-2)
            elif start(N) < e:
                continue
            elif start(N) == e:
                if s <= end(N):
                    num = 1
                    for k,c in enumerate(str(N)):
                        if k == 0 or k == len(str(N))-1:
                            continue
                        else:
                            num *= (int(c)+1)
                    result += num
                elif s > end(N):
                    num = 1
                    for k,c in enumerate(str(N)):
                        if k == 0 or k == len(str(N))-1:
                            continue
                        else:
                            num *= (int(c)+1)
                    result += (num - 1)
        # print(result)
print(result)

Submission status: Wrong Answer

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

N = int(input())

if N == 1:
    print("1")
else:
    ans = 0

    arr = [str(n)[0]+str(n)[-1] for n in range(1, N)]

    for a in arr:
        ans += arr.count(a[-1] + a[0])
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
from functools import reduce
import operator
def prod(iterable):
    return reduce(operator.mul, iterable, 1)
def cnt_samelen(b,e,n_str):
  n0=int(n_str[0])
  if b>n0 or len(n_str)==1:
    return 0
  if b<n0:
    return b*int(10**(len(n_str)-2))
  
  return prod((int(i)+1) for i in n_str[1:-1])-(1 if e>int(n_str[-1]) else 0)
def cnt(b,e,n_str):
  res=0
  l=len(n_str)
  if b==e and int(n_str)>=b:
    res+=1
  for i in range(l-2):
    res+=10**(i)
  res+=cnt_samelen(b,e,n_str)
  return res
def sol():
  n_str=input()
  return sum(cnt(b,e,n_str)*cnt(e,b,n_str) 
             for b,e in product(range(1,10),repeat=2))

print(sol())

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    r = 0
    for i in range(1, min(10, N+1)):
        r += 1
        if N >= int(str(i) * 2):
            r += 1
        else:
            continue
        j = 1
        while True:
            if int(str(i) + '9' * j  + str(i)) > N:
                r += complex(i, i, j, N)
                break
            else:
                r += 10 ** j
                j += 1
    if N < 10:
        return r
    for i in range(11, N):
        if i % 10 == 0:
            continue
        t = int(str(i)[0])
        b = int(str(i)[-1])
        if t == b:
            r += 1
        if N >= int(str(b) + str(t)):
            r += 1
        else:
            continue
        j = 1
        while True:
            if int(str(b) + '9' * j + str(t)) > N:
                r += complex(b, t, j, N)
                break
            else:
                r += 10 ** j
                j += 1
    return r
def complex(b, t, j, N):
    if int(str(b) + '0' * j + str(t)) > N:
        return 0
    N_m = int(str(N)[1:-1])
    if t >= int(str(N)[-1]):
        return (N_m)
    return N_m - 1
print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
b=0
for x in range(N):
    for y in range(N):
        A=(x+1,y+1)
        if A[0] <10 and A[1]<10:
            if A[0] == A[1]:
                b = b+1
print(b)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = [ str(v) for v in list(range(1, N+1))]
s_r = [str(int(v[::-1])) for v in s if int(v[::-1]) <= N]
s_r = sorted(list(set(s_r)))

count = 0
for s1 in s:
  for s2 in s_r:
    if (s1[0] == s2[-1]) & (s1[-1] == s2[0]):
      count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ans = 0
for i in range(1, N+1):
    top = str(i)[0]
    bottom = str(i)[-1]

    if(bottom == "0"):
        continue
    
    # １桁
    if (top == bottom):
        ans += 1
    # ２桁
    if (int(bottom + top) <= N):
        ans += 1
    # ３桁
    x = N - int(bottom + "0" + top)
    if(x > 0):
        ans += min(10, math.ceil(x / 10))
    # ４桁
    x = N - int(bottom + "00" + top)
    if(x > 0):
        ans += min(100, math.ceil(x / 10))
    # ５桁
    x = N - int(bottom + "000" + top)
    if(x > 0):
        ans += min(1000, math.ceil(x / 10))
print(ans)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()

def naive_solver(N):
    output=[]
    for i in range(1,N):
        A=str(i)
        for j in range(1,N):
            B=str(j)
            if A[-1]==B[0] and B[-1]==A[0]:
#                 if A[0]=="1":
                output.append([A,B])
    return output

def naive_solver2(N):
    dicts={str(i):{str(j):0 for j in range(10)} for i in range(10) }
    for i in range(1,N):
        temp=str(i)
        dicts[temp[0]][temp[-1]] += 1
    return dicts

dicts = naive_solver2(N)

import itertools as it

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under



count = 0
for si in range(1,10):
    i=str(si)
    for sj in range(si,10):
        j = str(sj) 
        
#         count += dicts[i][j] * dicts[j][i] * 2
        if j!=i:
            count+=dicts[i][j] * dicts[j][i] * 2#2*cmb(dicts[i][j]+dicts[j][i],2)    
#             print(si,sj,dicts[i][j] * dicts[j][i] * 2)#2*cmb(dicts[i][j]+dicts[j][i],2))
        else:
            count+=dicts[i][j]*dicts[j][i]#cmb(dicts[i][j]+dicts[j][i],2)
#             print(si,sj,cmb(dicts[i][j]+dicts[j][i],2))

if N<10:
    print(N)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
N = input()
M = int(N[0])
L = len(N)
ans = 0
cond_l = [[],[],[],[],[],[],[],[],[]]
for i in range(1,10):
  for j in range(1,10):
    t = 0
    if i == j:
      t += 1
    if i < M:
      for k in range(2, L+1):
        t += 10 ** (k - 2)
    elif i > M:
      for k in range(2, L):
        t += 10 ** (k - 2)
    else:
      for k in range(2, L):
        t += 10 ** (k - 2)
      if j <= int(N[-1]) and L >= 2:
        t_2 = 1
        for k in range(1, L-2):
          t_2 *= int(N[k])
        t += t_2
    cond_l[i-1].append(t)
ans = 0
for i in range(9):
  ans += cond_l[i][i] ** 2
for i in range(8):
  for j in range(i+1, 9):
    ans += cond_l[i][j] * cond_l[j][i] * 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
n_digit = len(str(n))
ans = 0
for i in range(1,n+1):
  max_a = list(str(i))[0]
  min_a = list(str(i))[-1]
  if min_a == "0":
    continue
  else:
    if max_a == min_a:
      if int(max_a)<=n:
        ans += 1
    for j in range(n_digit-1):
      max_b = int(min_a+"9"*j+max_a)
      min_b = int(min_a+"0"*j+max_a)
      if max_b <= n:
        ans += int(10**j)
      elif min_b > n:
        continue
      else:
        ans += (n-min_b)//10
print(ans)

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:]) // 10
                    continue
                else:
                    res += (int(str(N)[1:]) + 9) // 10
                    continue


print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=str(N)
K=len(T)-1
A=N//10
if N<10:
    print(N)
else:
    print(A*A+8+N%10)

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 1
j = 1
ans = 0
while i <= n:
  a = list(str(i))
  while j <= i:
    b = list(str(j))
    if a[0] == b[-1] and a[-1] == b[0]:
      ans += 1
    j += 1
  i += 1
print((ans-8)**2 + 8)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = len(str(N))
ans = 0

if N == 1:
    print(1)
    exit()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * 100
for i in range(1,n+1):
  msb = str(i)[0]
  lsb = str(i)[-1]
  if msb == '0' or lsb == '0':
    continue
  a[int(msb) * 10 + int(lsb)] += 1

tmp = 0
for i, ai in enumerate(a):
  if '0' not in str(i):
    if i % 11 == 0:
      tmp += ai * ai
    else:
      tmp += ai * a[int(str(i)[::-1])]
  else:
    continue
    
print(tmp)
print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(N)
ans = 0
for i in range(1,N+1):
  s = str(i)
  p1 = int(s[0])
  p2 = int(s[-1])
  if p1==0 or p2==0:
    continue
  if p1==p2:
    if p1<=N:
      ans += 1
  num = 1
  ans += int('1'*(len(S)-2)) if len(S)>2 else 0
  c = 1
  if p2<int(S[0]):
    ans += 10**(len(S)-2) if len(S)>1 else 0
  elif p2==int(S[0]):
    for i in range(1, len(S)-1):
      c *= int(S[i])+1
    if p1>int(S[-1]):
      c -= 1
    if len(S)==1:
      c -= 1
    ans += c
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC152d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    n = int(input())
    cou = 0
    for i in range(1, n + 1):
        if str(i)[-1] == '0':
            continue
        # print(i)
        if str(i)[0] == str(i)[-1]:
            cou += 1
        k = 2
        while True:
            b = int(str(i)[-1] + '0' * (k - 2) + str(i)[0])
            if b <= n:
                if k > 2:
                    if n - b > 10 ** (k - 2):
                        cou += 10 ** (k - 2)
                    else:
                        cou += (n - b)//10 + 1
                else:
                    cou += 1
                #print(i, k, cou)
                k += 1
                continue
            #print(i, cou)
            break
    print(cou)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())

digit = len(str(N))
if digit==1:
    print(N)
    exit()

count=0
N_head = N//(10**(digit-1))
N_tail = N%10
N_second_head = N//(10**(digit-2))%10

for A in range(1, N+1):
    A_tail = A%10
    A_head = A//10**(len(str(A))-1)
    A_digit = len(str(A))

    if A_tail==0:
        continue

    if A_tail == A_head:
        count += 1

    for d in range(2, digit+1):
        if d==digit:
            if A_tail<N_head:
                count += 10**(d-2)
            elif A_tail==N_head:
                if A_head<=N_tail:
                    if d==2:
                        count += 1
                    else:
                        count += N//10-N_head*10**(digit-2)
                else:
                    if d==2:
                        pass
                    else:
                        count += N//10-N_head*10**(digit-2)
            else:
                pass
        else:
            count += 10**(d-2)

print(count)

Submission status: Wrong Answer

Solution code:
n=str(input())
H=n[0]
T=n[-1]
keta=len(n)
n=int(n)
ans=0
if keta==1:
    print(1)
    exit()
elif keta==2:
    for i in range(1,n+1):
        s=str(i)
        for j in range(1,n+1):
            S=str(j)
            if S[0]==s[-1] and S[-1]==s[0]:
                ans+=1    
else:
    for i in range(1,n+1):
        s=str(i)
        h=s[0]
        t=s[-1]
        if h!="0" and t!="0":
            ans+=(10**(keta-2)-1)//9
            if h==t:
                ans+=1
            if int(t)<=int(H):
                ans+=(10**(keta-2))*(int(H)-int(t))
                ans+=max(0,(n-10**(keta-1)*int(H)-int(h))//10)
            
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())

if n <= 9:
    print(n)
    sys.exit()

N_0 = int(str(n)[0])
N_right = int(str(n)[-1])

if n >= 100:
    N_center = int(str(n)[1:-1])
# print("N_right, N_center {}, {}".format(N_right, N_center))
# print(N_0)
len_n = len(str(n))

counter = 0

for i in range(1, n+1):
    left = int(str(i)[0])
    right = int(str(i)[-1])

    if left == 0 or right == 0:
        continue
    if left == right:
        counter += 1

    if len_n == 2:
        tmp = int(str(right) + str(left))
        # print("i, tmp n {} {} {}".format(i, tmp, n))

        if tmp <= n:
            counter += 1

    if len_n >= 3:
        if right < N_0:
            counter += int("1" * (len_n - 1))
        elif right > N_0:
            counter += int("1" * (len_n - 2))
        else:
            counter += int("1" * (len_n - 2))
            if N_right >= right:
                counter += N_center + 1
            else:
                counter += N_center

    # print(i, counter)

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
len_n = len(str(N))
top_n = N // (10 ** (len_n - 1))
bot_n = N % 10

count = 0
if N < 10:
  print(N)
  quit()
else:
  for i in range(1, N + 1):
    p = len(str(i))
    a = int(i // (10 ** (p - 1)))
    b = int(i % 10)
    if b != 0:      
      if a == b:
        #print(a, b, count)
        count += 1
        count += p - 1
      s = 2
      while len_n > s:
        count += 10 ** (s - 2)
        s += 1
      if i >= 10:
        if top_n > b:
          count += 10 ** (s - 2)
        elif top_n == b:
          count += N // 10 - top_n * 10 ** (p - 2) 
          if bot_n >= a:
            count += 1
    #if i > 98:
     # print(i, count)      

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    count = 0
    for i in range(1, n + 1):
        p = i // 10
        tmp = str(i)
        if tmp[0] == tmp[-1]:
            count += (2 * p) + 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())

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

Submission status: Wrong Answer

Solution code:
N = input()
n = int(N)
ans = 0
num = len(str(n))
subans = 0
if num == 1:
  ans += n
elif num == 2:
  ans += 9
  for j in range(num-1):
    if N[j] == '1':
      continue
    else:
      subans += int(N[j])*(10**(num-2-j))
  ans += subans**2+subans*(sum(2*(10**k) for k in range(num-1)))
else:
  ans += 9
  for i in range(2,num):
    ans += 9*(10**(num-2))*sum(2*(10**k)-1 for k in range(num-1)) 
  for j in range(num-1):
    if N[j] == '1' :
      continue
    else:
      subans += int(N[j])*(10**(num-2-j))
  ans += subans**2+subans*(sum(2*(10**k) for k in range(num-1)))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * 100
for i in range(n):
  msb = str(i)[0]
  lsb = str(i)[-1]
  if msb == '0' or lsb == '0':
    continue
  a[int(msb) * 10 + int(lsb)] += 1

tmp = 0
for i, ai in enumerate(a):
  if '0' not in str(i):
    if i % 11 == 0:
      tmp += ai * ai
    else:
      tmp += ai * a[int(str(i)[::-1])]
  else:
    continue
    
print(tmp)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=str(n)
m=len(s)
ans=0
if n<=9:
    print(n)
    exit()
if n<=99:
    for i in range(1,n+1):
        for j in range(1,n+1):
            if str(i)[-1]=="0":
                continue
            if str(i)[0]==str(j)[-1] and str(j)[0]==str(i)[-1]:
                ans+=1
    print(ans)
    exit()
y=int(s[1:m-1])
for i in range(1,n+1):
    a,b=str(i)[0],str(i)[-1]
    if b=="0":
        continue
    if a==b:
        ans+=1
    dig=1
    for j in range(m-2):
        ans+=dig
        dig*=10
    if int(b)==int(s[0]):
        if int(a)>int(s[-1]):
            ans+=y
        else:
            ans+=y
    elif int(b)<int(s[0]):
        ans+=dig
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
 
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
 
 
N=int(input())
cnt=0
 
for i in range(1,N):
	for j in range(1,i-1):
		if str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]:
			cnt+=2
			
for i in range(1,N):
		if str(i)[0]==str(i)[-1]:
			cnt+=1			  
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())

if n <= 9:
    print(n)
    sys.exit()

N_0 = int(str(n)[0])
N_right = int(str(n)[-1])

if n >= 100:
    N_center = int(str(n)[1:-1])
# print("N_right, N_center {}, {}".format(N_right, N_center))
# print(N_0)
len_n = len(str(n))

counter = 0

for i in range(1, n+1):
    left = int(str(i)[0])
    right = int(str(i)[-1])

    if left == 0 or right == 0:
        continue
    if left == right:
        counter += 1

    if len_n == 2:
        tmp = int(str(right) + str(left))
        print("i, tmp n {} {} {}".format(i, tmp, n))

        if tmp <= n:
            counter += 1

    if len_n >= 3:
        if right < N_0:
            counter += int("1" * (len_n - 1))
        elif right > N_0:
            counter += int("1" * (len_n - 2))
        else:
            counter += int("1" * (len_n - 2))
            if N_right >= right:
                counter += N_center + 1
            else:
                counter += N_center

    # print(i, counter)

print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0
for a in range(n):
    stra = str(a)
    if stra in '0':
        continue
    for b in range(n):
        strb = str(b)
        if strb in '0':
            continue
        if strb[0] == stra[-1] and strb[-1] == stra[0]:
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
S = str(N)
l = len(S)
if l == 1:
    print(N)
    exit()
s = int(S[0])
t = int(S[-1])
mn = min(s,t)

ans = 0
dp = defaultdict(int)
            
for i in range(1,10):
    for j in range(1,10):
        if i == j:
            dp[(i,j)] += 1
        if l >= 3: 
            for k in range(0,l-2):
                dp[(i,j)] += 10**k
        if i < s:
            dp[(i,j)] += 10**(l-2)
        elif i == s and j <= t:
            dp[(i,j)] += 10**(l-2)
        elif i == s and j > t:
            dp[(i,j)] += (N-s*(10**(l-1))) // 10
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += dp[(i,j)]*dp[(j,i)]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def keta(i):
    return len(str(i))
def start(i):
    l = str(i)
    return int(l[0])
def end(i):
    return i%10

result = 0

for a in range(1,N+1):
    s = start(a) #bのend
    e = end(a) #bのstart
    if s == 0 or e == 0:
        continue
    # print("a",a)
    for j in range(1,keta(N)+1):
        # print(j)
        if j == 1:
            if j < keta(N):
                if s == e:
                    result +=1
                else:
                    pass
            elif j == keta(N):
                if s == e and s <= N:
                    result += 1
        elif j == 2:
            if j < keta(N):
                result += 1
            elif j == keta(N):
                if 10*e+s <= N:
                    result += 1
        elif j < keta(N):
            result += 10**(j-2)
        else:
            if start(N) > e:
                result += 10**(j-2)
            elif start(N) < e:
                continue
            else:
                if s <= end(N):
                    num = 1
                    for k,c in enumerate(str(N)):
                        if k == 0 or k == len(str(N)):
                            continue
                        else:
                            num *= (int(c)+1)
                    result += num
                elif s > end(N):
                    num = 1
                    for k,c in enumerate(str(N)):
                        if k == 0 or k == len(str(N)):
                            continue
                        else:
                            num *= (int(c)+1)
                    result += (num - 1)
        # print(result)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
print(n**2/100+8)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def my_count(a, b, n):
    ret = 0
    if a == b and a <= n:
        ret = ret + 1
    if a * 10 + b <= n:
        ret = ret + 1
    keta = len(str(n))
    if keta > 3:
        ret = ret + (int('1'*(keta-2)) - 1)
    if keta >= 3:
        candidate = a * (10 ** (keta-1)) + b
        if n - candidate >= 0:
            ret = ret + (((n - candidate) // 10) + 1)
    return ret


n = int(input())

ret = 0

for i in range(1, 10):
    for j in range(1, 10):
        ret = ret + my_count(i, j, n) * my_count(j, i, n)

print(ret)

Submission status: Wrong Answer

Solution code:
N=int(input())
box={}
for i in range(1,100):
  box[i]=0
for i in range(1,N):
  A_first=str(i)[0]
  if i<=9:
    A_first=0
  A_back=i%10
  index=int(A_first)*10+int(A_back)
  box[index]+=1
ans=0
a=0
b=0
for i in range(1,100):
  if len(str(i))==1:
    ans+=(box[i]+box[i*11])**2
  if i>10 and str(i)[0]!=str(i)[1] and i%10!=0:
    t=i//10+(i%10)*10
    ans+=(box[i]*box[t])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def count(a,b):
    if ln_n > 1:
        ret = int('1' * (ln_n-1))
    else:
        ret = 0
    
    if a==b:
        ret += 1
    
    if ln_n >= 1:
        if a < n_top:
            ret += 10**(ln_n-1)
        elif a == n_top:
            ret += max(n_inner, 0)
            if b <= n_bottom:
                ret += 1
    return ret

n, = [list(map(int, s.split())) for s in open(0)][0]
ln_n = int(np.log10(n))
n_top = n // (10**ln_n)
n_bottom = n % 10
n_inner = 0
if ln_n > 1:
    n_inner = int(str(n)[1:-1])

ans = 0
for i in range(1,10):
    for j in range(1,10):
        tmp = count(i,j) * count(j,i)
        ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

Nm = int(str(N)[0])
N0 = int(str(N)[-1])
ORD_N = len(str(N))
N_LEFT = int(str(N)[1:-1]) if 2 < ORD_N else -1


def get_number_less_than_N(bm, b0):
    """ 先頭bm, 後ろb0 を持ち、N より小さい値の数 """
    count = 0
    # print('='*10)
    
    # b が1桁
    if bm == b0:
        count += 1
        # print('1k', count)
    # b が2桁 (N以下ならば該当)
    if bm*10 + b0 <= N:
        count += 1
        # print('2k', count)
    # order(N) 未満の桁
    # たとえばN=10000 なら、3桁(bm x b0), 4桁(bm xx b0) のパターンは全てOK
    for i in range(3, ORD_N):
        count += 10 ** (i-2)
        # print('M', i, count)
    
    # order(N) のけた
    # bm xx.. b0 <= Nm N1 N2.. N0
    if ORD_N >= 3 and bm <= Nm:
        if bm < Nm:
            count += 10 ** (ORD_N-2)
            # print('L++', count)
        elif b0 == N0:
            count += N_LEFT + 1
            # print('L+', count)
        else:
            count += N_LEFT
            # print('L', count)

    return count
        

count = 0
for i in range(1, N+1):
    bm, b0 = int(str(i)[-1]), int(str(i)[0])
    if bm == 0:
        continue
    cold = count
    count += get_number_less_than_N(bm, b0)
print(count)