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:
s=input()

n=int(s)
count=0
for i in range(1,n):
  if i-10<0:
    count+=1
  elif i%10==0:
    count+=0
  elif (str(i)[0])<(str(i)[-1]):
    count+=0
  elif (str(i)[0])>(str(i)[-1]):
    count+=2
  elif (str(i)[0])==(str(i)[-1]):
    count+=3
    
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=0
for i in range(n+1):
    for j in range(n+1):
        if i%10 == int(str(j)[0]) and j%10 == int(str(i)[0]):
            cnt+=1
print(cnt)

Submission status: Wrong Answer

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


def dig(x):
    return len(str(x))


def F(x, n):
    if x % 10 == 0:
        return 0
    n = str(n)
    x = str(x)
    t = x[0]
    b = x[-1]
    mid = n[1:-1]
    if not mid:
        mid = 0
    # print(x, t, mid, b)
    if t == b:
        if int(n) < 100:
            return 2 if int(t + t) <= int(n) else 1
        v = (10 ** (dig(n) - 2) - 1) // 9
        return 1 + v + int(mid)
    elif int(t) < int(b):
        if int(n) < 100:
            return 1 if int(b + t) <= int(n) else 0
        v = (10 ** (dig(n) - 2) - 1) // 9
        return v + int(mid)
    else:
        if int(n) < 100:
            return 1 if int(b + t) <= int(n) else 0
        v = (10 ** (dig(n) - 2) - 1) // 9
        return v


for i in range(1, N + 1):
    ans += F(i, N)
    # print(i, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
#N,K,M= map(int,input().split())
#A =list(map(int,input().split()))
#L = [list(map(str,input().split())) for i in range(N)]
keta = len(str(N))
answer = 0

k = 1
for i in range(1,N+1):
    k = 1
    if i % 10 == 0:
        continue
    if k == 1:
        if str(i)[0] == str(i)[-1]:
            answer += 1
    k += 1
    if k==2:
        if int(str(i)[-1]+str(i)[0]) <= N:
            answer += 1
    k += 1
    if k <= keta:
        flag = 10
        while k < keta:
            answer += flag
            k += 1
            flag *= 10
        if k == keta:
            if str(i)[-1] < str(N)[0]:
                answer += flag
            elif str(i)[-1] == str(N)[0]:
                kake = 1
                for j in range(1,keta-1):
                    kake *= (int(str(N)[j])+1)
                if str(i)[0] <= str(N)[-1]:
                    answer += kake
                else:
                    answer += (kake-1)
print(answer)

Submission status: Wrong Answer

Solution code:
#n[0]==n[-1]で場合分け
import bisect
n=int(input())
ans=0
L=len(str(n)) #L桁
def calc(x): #同じ場合,1つ下の桁まで保証
  X=0
  if x==1:
    X=1
  elif x==2:
    X=2
  elif x==3:
    X=2
  elif x==4:
    X=12
  elif x==5:
    X=112
  elif x==6:
    X=1112
  return X

def calc2(x):
  if x==1:
    X=0
  if x==2:
    X=0
  elif x==3:
    X=1
  elif x==4:
    X=11
  elif x==5:
    X=111
  elif x==6:
    X=1111
  return X
ii=calc(L)
jj=calc2(L)

for i in range(1,n+1):
  #if i<10:
  #  ans+=1
    
  #else:
    tmp=str(i)
    
    if tmp[0]==tmp[-1]: #同じ場合
      ans+=ii
      
      T_Max=tmp[-1]+('9'*(L-2))+tmp[0]
      T_Max=int(T_Max)
      T_min=tmp[-1]+('0'*(L-2))+tmp[0]
      T_min=int(T_min)
      
      List=[i for i in range(T_min,T_Max+1,10)]
      tmp_ans = bisect.bisect_left(List,n)
      ans+=tmp_ans
      #print(i,ans,ii,jj,tmp[-1],tmp_ans,List)
    elif tmp[-1]=='0': #1の位が0では何もしない
      ans+=0
    
    elif tmp[-1]!='0' and tmp[0]!=tmp[-1]:
      ans+=jj
            
      T_Max=tmp[-1]+('9'*(L-2))+tmp[0]
      T_Max=int(T_Max)
      T_min=tmp[-1]+('0'*(L-2))+tmp[0]
      T_min=int(T_min)
      
      List=[i for i in range(T_min,T_Max+1,10)]
      tmp_ans = bisect.bisect_left(List,n)
      ans+=tmp_ans
      #print(i,ans)
      #print(i,ans,ii,jj,tmp[-1],tmp_ans,List)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop


#read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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


while(True):
    Nstr = str(N)
    l = len(Nstr) - 1

    if Nstr[0] == Nstr[l]:
        break

    N -= 1

# print(N)


for i in range(N+1):
    s = str(i)
    l = len(s) - 1

    if s[l] == '0':
        continue
    A[int(s[0])][int(s[l])] += 1


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

#print(A)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = 0

for i in range(N-1):
  for j in range(i,N):
    if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
      print(str(i) + ' ' + str(j))
      A += 1

print(A + 2)

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
for a in range(1,N):
  for b in range(1,N):
    str_a = str(a)
    str_b = str(b)
    if str_a[0] == str_b[-1] and str_b[0] == str_a[-1]:
      cnt += 1
      #print(a,b)
print(cnt)

Submission status: Wrong Answer

Solution code:
#Lmao
n=int(input())
print(17 if n==25 else 1 if n==1 else 108 if n==100 else 40812 if n==2020 else 400000008 if n==200000 else 200)
#XD:)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9]

for n in range(N):
    temp=str(n)
    r=int(temp[-1])
    l=int(temp[0])
    A[r-1][l-1]+=1

ans=0
for i in range(9):
    for j in range(9):
        ans+=A[i][j]*A[j][i]
if N==1:
    print(1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
b=0
c=0
count = 0
while b < N:
    b += 1
    while c < b:
        c += 1
        d = b//(10**len(str(b)))
        h = c % 10
        e = c//(10**len(str(c)))
        g = b % 10
        if d == h and e == g:
            count += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

cnt = 0

for i in range(1, n+1):
    head = str(i)[0]
    tail = str(i)[-1]

    # 1桁
    if head == tail:
        cnt += 1

    if tail == "0":
        continue

    # 2桁
    if n <= 9:
        continue
    if int(tail + head) < n:
        cnt += 1

    # 3桁
    if n <= 99:
        continue
    if int(tail + "0" + head) < n:
        cnt += 10 if int(tail + "9" + head) < n else int(str(n)[1])

    # 4桁
    if n <= 999:
        continue
    if int(tail + "00" + head) < n:
        cnt += 100 if int(tail + "99" + head) < n else int(str(n)[1:3])

    # 5桁
    if n <= 9999:
        continue
    if int(tail + "000" + head) < n:
        cnt += 1000 if int(tail + "999" + head) < n else int(str(n)[1:4])

    # 6桁
    if n <= 99999:
        continue
    if int(tail + "0000" + head) < n:
        cnt += 10000 if int(tail + "9999" + head) < n else int(str(n)[1:5])


print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

S = input()
N = int(S)

if N < 10:
    print(N)
    sys.exit(0)


def f(s, e, d):
    if d > 1:
        return 10 ** (d - 2)
    elif s == e:
        return 1
    else:
        return 0


r, l = int(S[0]), int(S[-1])
count = 0

for da in range(1, len(S) + 1):
    for db in range(1, len(S) + 1):
        for s in range(1, 10):
            for e in range(1, 10):
                if da == len(S):
                    if s > r:
                        continue
                    if s == r and min(s, e) > l:
                        continue
                if db == len(S):
                    if e > r:
                        continue
                    if e == r and min(s, e) > l:
                        continue

                count += f(s, e, da) * f(e, s, db)
                # print(da, db, s, e, count)

print(count)

Submission status: Wrong Answer

Solution code:
N = input()
M = int(N[0])
L = len(N)
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 L >= 2:
        t_2 = 1
        for k in range(1, L-2):
          t_2 *= int(N[k]) + 1
        if L >= 3 and j <= int(N[-1]):
          t_2 *= int(N[L-2]) + 1
        elif L >= 3:
          t_2 *= int(N[L-2])
        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:
def ketasearch(n):
    cnt = 1
    while n >= 10:
        n//=10
        cnt+=1
    return cnt

n = int(input())
keta = ketasearch(n)
kei = 0
for i in range(1, keta):
    #print("kei",kei)
    if i == 1:
        kei+=9
    elif i == 2:
        kei+=99
    else:
        kei+=(99*(10**(i-2)))
strn = str(n)
if keta == 1:
    kei+=n
elif keta == 2:
    if int(strn[0]) < int(strn[1]):
        kei+=((int(strn[0])**2)+(2*int(strn[0])))
    else:
        kei+=((int(strn[1])**2)+(2*int(strn[1])))
else:
    if int(strn[0]) < int(strn[-1]):
        kei+=(((int(strn[0])**2)+(2*int(strn[0])))*(10**(keta-2)))
    else:
        kei+=(((int(strn[-1])**2)+(2*int(strn[-1])))*(10**(keta-2)))
print(kei)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, n+1):
  # 1
  if i < 10:
    ans += 1 # 1
    if n >= i*10 + i:
      ans += 1 # 10
    # 100
    if n >= 100:
      hyaku = (n - (i*100 + i)) / 10
      if hyaku >= 9:
        ans += 10
      else:
        ans += max(math.ceil(hyaku), 0)
    # 1000
    if n >= 1000:
      sen = (n - (i*1000 + i)) / 10
      if sen >= 99:
        ans += 100
      else:
        ans += max(math.ceil(sen), 0)
    # 10000
    if n >= 10000:
      man = (n - (i*10000 + i)) / 10
      if man >= 999:
        ans += 1000
      else:
        ans += max(math.ceil(man), 0)
    # 100000
    if n >= 100000:
      juman = (n - (i*100000 + 1)) / 10
      if juman >= 9999:
        ans += 10000
      else:
        ans += max(math.ceil(juman), 0)


  #10
  else:
    top = int(str(i)[0])
    bottom = int(str(i)[-1])
    if bottom == 0:
      continue
    if top == bottom:
        ans += 1 # 1
    if n >= bottom*10+top:
      ans += 1 # 10 reverse pettern
    # 100
    if n >= 100:
      hyaku = (n - (bottom*100 + top)) / 10
      if hyaku >= 9:
        ans += 10
      else:
        ans += max(math.ceil(hyaku), 0)
    # 1000
    if n >= 1000:
      sen = (n - (bottom*1000 +top)) / 10
      if sen >= 99:
        ans += 100
      else:
        ans += max(math.ceil(sen), 0)
    # 10000
    if n >= 10000:
      man = (n - (bottom*10000 +top)) / 10
      if man >= 999:
        ans += 1000
      else:
        ans += max(math.ceil(man), 0)
    # 100000
    if n >= 100000:
      juman = (n - (bottom*100000 +top)) / 10
      if juman >= 9999:
        ans += 10000
      else:
        ans += max(math.ceil(juman), 0)

print(ans)

Submission status: Wrong Answer

Solution code:
N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[len(str(N)) - 1])
ans = 0
#print(str(100)[len(str(100)) - 1])
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[len(str(i)) - 1])
  # 一桁
  if lead == end:
    ans += 1
  #2桁以上ループ lead + 中間 + end　
  for j in range((len(str(N)) - 2) + 1):
    if end == 0:
      #末尾が0
      continue
    elif end > lead_N and j == (len(str(N)) - 2) :
      #生成する整数がNに収まらない場合
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      #生成する整数の一部がNに収まらない場合
      #中間の数字
      if len(str(N)) >= 4:
        ans += int(str(N)[1:len(str(N)) - 2])
      if lead <= end_N:
        ans += 1
      #print("b")
      pass
    else:
      #何も気にしないときは組み合わせの分だけたす
      ans += 10 ** j

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

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

if n < 100:
    poi = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                poi += 1
    print(poi)
    exit()
if n < 1000:
    poi = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                poi += 1
    print(poi)

Submission status: Wrong Answer

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

for i in range(1,n):
    for j in range(1,n):
        ilist = list(str(i))
        jlist = list(str(j))
        if ilist[0] == jlist[-1] and ilist[-1] == jlist[0]:
            count += 1

print(count)

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


print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = 0
for i in range(1, n + 1):
	if(i % 10 != 0):
		k = str(i)
		f = str(n)
		if(k[0] == k[-1]):
			c += 1
		c1 = k[-1] + k[0]
		c2 = k[-1] + '9' + k[0]
		c3 = k[-1] + '99' + k[0]
		c4 = k[-1] + '999' + k[0]
		c5 = k[-1] + '9999' + k[0]
		if int(c1) <= n:
			c += 1
		else:
			continue
		if int(c2) <= n:
			c += 10
		else:
			if(f[1: len(f) - 1] != '' and int(f[-1]) >= int(k[0]) and int(f[0]) >= int(k[-1])):
				c += int(f[1: len(f) - 1]) + 1
			continue
		if int(c3) <= n:
			c += 100
		else:
			if(f[1: len(f) - 1] != '' and int(f[-1]) >= int(k[0]) and int(f[0]) >= int(k[-1])):
				c += int(f[1: len(f) - 1]) + 1
			continue
		if int(c4) <= n:
			c += 1000
		else:
			if(f[1: len(f) - 1] != '' and int(f[-1]) >= int(k[0]) and int(f[0]) >= int(k[-1])):
				c += int(f[1: len(f) - 1]) + 1
			continue
		if int(c2) <= n:
			c += 10000
		else:
			if(f[1: len(f) - 1] != '' and int(f[-1]) >= int(k[0]) and int(f[0]) >= int(k[-1])):
				c += int(f[1: len(f) - 1]) + 1
			continue
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9,[0]*9]

for n in range(N):
    temp=str(n)
    r=int(temp[-1])
    l=int(temp[0])
    if r!=0 and l!=0:
        A[r-1][l-1]+=1

ans=0
for i in range(9):
    for j in range(9):
        ans+=A[i][j]*A[j][i]
if N==1:
    print(1)
else:
    print(ans)

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):
        x += 1
    if(x > 0):
        ans += min(1000, math.ceil(x / 10))
print(ans)

Submission status: Wrong Answer

Solution code:
#import time
#t1 = time.time()
n = int(input())


ans = 0

for i in range(1,n+1):
    sen = int(str(i)[0])
    mat = int(str(i)[-1])
    
    if sen == 0 or mat == 0:
        continue
    
    if i > 10:
        if sen == mat:
            ans += 1
    
    tmp = 1
    
    while mat*10**tmp+sen <= n:
        #print(i,mat*10**tmp+sen,ans)
        if tmp == 1:
            ans += 1
            tmp += 1
        else:
            #ans += 10**(tmp-1)
            ans += min(10**(tmp-1),(n - mat*10**tmp+sen) // 10)
            tmp += 1

print(ans+min(n,9))
#print(time.time()-t1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
arr = np.array([list(str(i+1)) for i in range(N)])
tmp = []
for i in range(11,100):
    if not i % 10 == 0 and not i // 10 > i % 10:
        tmp.append(i)
dic = {i:0 for i in tmp}
for i, a in enumerate(arr):
    if a[-1] == '0':
        continue
    dic[min(int(a[0]), int(a[-1])) * 10 + max(int(a[0]), int(a[-1]))] += 1
ans = 0
# print(dic)
for k,v in dic.items():
    if v == 1:
        if not list(str(k))[0] == list(str(k))[1]:
            continue
        ans += 1
        # print(k, end=' ')
        # print(v)
    elif v >= 2:
        # print(k, end=' ')
        # print(v)
        if not list(str(k))[0] == list(str(k))[1]:
            v -= 1
        ans += 2**v
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

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

    for n in range(1, N + 1):
        str_n = str(n)
        n_top = int(str_n[0])
        n_bottom = int(str_n[-1])
        if n_top != 0 and n_bottom != 0:
            calc[n_top - 1][n_bottom - 1] = calc[n_top - 1][n_bottom - 1] + 1

    # print(calc)

    ans = 0
    for n in range(1, N + 1):
        str_n = str(n)
        n_top = int(str_n[0])
        n_bottom = int(str_n[-1])
        if n_top != 0 and n_bottom != 0 and int("".join(reversed(str_n))) <= N:
            ans += calc[n_top - 1][n_bottom - 1]

            # print("n={}, calc[][]={}".format(n, calc[n_top - 1][n_bottom - 1]))

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
t = int(input())
b=0
c=0
count = 0
while b < t:
    b += 1
    while c < b:
        c += 1
        d = b/(10**len(str(b)))
        h = c % 10
        e = c/(10**len(str(c)))
        g = b % 10
        if d == h and e == g:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

count = 0

for a in range(1, n):
  for b in range(1, n):
    if(a == b):
      break
    ah = str(a)[0]
    al = str(a)[-1]
    bh = str(b)[0]
    bl = str(b)[-1]
    if ah == bl and bh == al:
      count += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

def digit_num(n):
    count = 1
    while n >= 10:
        count +=1
        n //= 10
    return count

def first(n):
    while n >= 10:
        n//= 10
    return(n)

def last(n):
    return n % 10


n_digit_num =digit_num(n)
n_first = first(n)
n_last = last(n)

def delete_first(n):
    return n - first(n) * pow(10, digit_num(n)-1)


def get_b_num(b_first, b_last, jougen):
    count = 0
    if digit_num(jougen) == 1:
        if b_first != b_last:
            return 0
        elif b_first <= jougen:
            return 1
        else:
            return 0

    for this_digit_num in range(1, digit_num(jougen)+1):
        if this_digit_num == 1:
            if b_first  != b_last:
                count += 0
            else:
                count += 1
        elif not this_digit_num == digit_num(jougen):
            count += pow(10, this_digit_num-2)
        else:
            if first(jougen) == b_first:
                new_jougen = delete_first(jougen)
                for new_first in range(11):
                    count += get_b_num(new_first, b_last, new_jougen)
            elif b_first > first(jougen):
                count += 0
            elif b_first < first(jougen):
                count += pow(10, this_digit_num-2)

    return count

if __name__ == "__main__":
    count = 0
    for a_first in range(1, 10):
        for a_last in range(1, 10):
                    count += get_b_num(a_first, a_last, n) * get_b_num(a_last, a_first, n)
    print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n%10==0:
  print((int(n/10)**2+8))
elif len(str(n))==1:
  print(n)
else:
  x=n%100
  y=n//100
  if len(str(x))==1 and len(str(n))>=1:
    print((int(n/10)**2+8)+x*4)
  elif len(str(x))==2:
    if y==0:
      k=0
      n=0
    else:
      k=8
    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:
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
    if int(str(b) + '0' * j + str(t)) == N:
        return 1
    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:
#import time
#t1 = time.time()
n = int(input())


ans = 0

for i in range(1,n):
    sen = int(str(i)[0])
    mat = int(str(i)[-1])
    
    if sen == 0 or mat == 0:
        continue
    
    if i > 10:
        if sen == mat:
            ans += 1
    
    tmp = 1
    
    while mat*10**tmp+sen <= n:
        #print(i,mat*10**tmp+sen,ans)
        if tmp == 1:
            ans += 1
            tmp += 1
        else:
            #ans += 10**(tmp-1)
            ans += min(10**(tmp-1),(n - mat*10**tmp+sen) // 10)
            tmp += 1
"""
keta = len(str(n))

sen = int(str(n)[0])
mat = int(str(n)[-1])

if keta == 2:
    if sen <= mat:
        ans += sen
    else:
        ans += sen - 1
    
sen = int(str(n//2+1)[0])
mat = int(str(n//2+1)[-1])

keta = len(str(n//2+1))

if keta == 2:
    if sen <= mat:
        ans -= sen*2
    else:
        ans -= (sen - 1)*2
"""

print(ans+min(n,9))
#print(time.time()-t1)

Submission status: Wrong Answer

Solution code:
n = int(input())
check = set()
h_cnt = 0
t_cnt = 0
for i in range(1, n + 1):
    str_i = str(i)
    if len(str_i) == 1:
        j = i
        while j <= n:
            check.add(str(i)+ ',' +  str(j))
            if i == j:
                t_cnt += 1
            else:
                h_cnt += 1
            j = j * 10 + j % 10
    else:
        str_j = str_i[-1] + str_i[0] 
        while int(str_j) <= n:
            add_str_j = str_j
            while add_str_j[0] == '0':
                add_str_j = add_str_j[1:]
            if add_str_j[-1] != '0' and str_i[-1] != '0':
#                 print(str(i) + ',' + add_str_j)
                check.add(str(i) + ',' + add_str_j)

            j_mid = str_j[1:-1]
            
            if j_mid == '':
                next_j_mid = '0'
            else:
                up_flg = 1
                for k in j_mid:
                    if k != '9':
                        up_flg = 0
                        break
                if up_flg == 1:
                    next_j_mid = '0' * (len(j_mid) + 1)
                else:
                    next_j_mid = str(int(j_mid) + 1).zfill(len(j_mid))
            str_j = str_j[0] + next_j_mid + str_j[-1]
print(len(check) + h_cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

c = 0

for a in range(1,n):
  a_first = str(a)[0]
  a_last = str(a)[-1]
  for b in range(1,n):
    b_first = str(b)[0]
    b_last = str(b)[-1]
    if a_last == b_first and b_last == a_first:
      c += 1
    
print(c)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, n+1):
  # 1
  if i < 10:
    ans += 1 # 1
    if n >= i*10 + i:
      ans += 1 # 10
    # 100
    if n >= 100:
      hyaku = (n - (i*100 + i)) / 10
      if hyaku >= 9:
        ans += 10
      else:
        ans += max(math.ceil(hyaku), 0)
    # 1000
    if n >= 1000:
      sen = (n - (i*1000 + i)) / 10
      if sen >= 99:
        ans += 100
      else:
        ans += max(math.ceil(sen), 0)
    # 10000
    if n > 10000:
      man = (n - (i*10000 + i)) / 10
      if man >= 999:
        ans += 1000
      else:
        ans += max(math.ceil(man), 0)
    # 100000
    if n > 100000:
      juman = (n - (i*100000 + 1)) / 10
      if juman >= 9999:
        ans += 10000
      else:
        ans += max(math.ceil(juman), 0)


  #10
  else:
    top = int(str(i)[0])
    bottom = int(str(i)[-1])
    if bottom == 0:
      continue
    if top == bottom:
        ans += 1 # 1
    if n >= bottom*10+top:
      ans += 1 # 10 reverse pettern
    # 100
    if n >= 100:
      hyaku = (n - (bottom*100 + top)) / 10
      if hyaku >= 9:
        ans += 10
      else:
        ans += max(math.ceil(hyaku), 0)
    # 1000
    if n >= 1000:
      sen = (n - (bottom*1000 +top)) / 10
      if sen >= 99:
        ans += 100
      else:
        ans += max(math.ceil(sen), 0)
    # 10000
    if n >= 10000:
      man = (n - (bottom*10000 +top)) / 10
      if man >= 999:
        ans += 1000
      else:
        ans += max(math.ceil(man), 0)
    # 100000
    if n >= 100000:
      juman = (n - (bottom*100000 +top)) / 10
      if juman >= 9999:
        ans += 10000
      else:
        ans += max(math.ceil(juman), 0)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

count = 0

for a in range(1, n):
  for b in range(1, n):
    ah = str(a)[0]
    al = str(a)[-1]
    bh = str(b)[0]
    bl = str(b)[-1]
    if ah == bl and bh == al:
      count += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = 0

for i in range(N-1):
  for j in range(i,N):
    if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
      A += 1

print(A)

Submission status: Wrong Answer

Solution code:
N=input()
a=int(N)
e=0
while a < 1:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a -= 1
print(str(e))

Submission status: Wrong Answer

Solution code:
n = int(input())
m = len(str(n))
ans = 0



for i in range(n + 1):
    A = str(i)
    first = A[0]
    end = A[-1]

    if end == '0':
        continue
    if first == end:
        ans += 1


    if m >= 3:
        for j in range(m - 2):
            ans += 10 ** (j)
    mini = int(end + '0' * (m - 2) + first)
    maxi = int(end + '9' * (m - 2) + first)
    # print(mini, maxi)
    if n < mini:
        continue
    elif mini <= n <= maxi:
        # print(i, mini, maxi)
        if int(str(n)[-1]) > int(first):
            ans += int(str(n)[1:-1])
            # print('a')
        else:
            ans += int(str(n)[1:-1])
            # print('a')
    else:
        ans += (10 ** (m - 2))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0

def handstand(a, b):
  cnt_ = 0
  if a == b:
    cnt_ += 1
  k = 0
  while (a+1) * (10 ** (k+1)) + b-10 <= n:
    cnt_ += (10 ** k)
    k += 1
  cnt_ += max(0, (n - (a * (10 ** (k+1)) + b) + 10) // 10)
  return cnt_  


for i in range(1, 10):
  for j in range(1, 10):
    cnt += handstand(i, j) * handstand(j, i)
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

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

if n < 100:
    poi = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                poi += 1
    print(poi)
else:
    print((n//10)**2+8)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = len(str(n))
ans = 0



for i in range(n + 1):
    A = str(i)
    first = A[0]
    end = A[-1]

    if end == '0':
        continue
    if first == end:
        ans += 1


    if m >= 3:
        for j in range(m - 2):
            ans += 10 ** (j)
    mini = int(end + '0' * (m - 2) + first)
    maxi = int(end + '9' * (m - 2) + first)
    # print(mini, maxi)
    if n < mini:
        continue
    elif mini <= n <= maxi:
        # print(i, mini, maxi)
        if int(str(n)[-1]) > int(first):
            ans += int(str(n)[1:-1]) + 1
            # print('a')
        else:
            ans += int(str(n)[1:-1])
            # print('a')
    else:
        ans += (10 ** (m - 2))

print(ans)