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 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):
    r = 0
    for i in range(int('9' * j)):
        v = int(str(b) + str(i).zfill(j) + str(t))
        if N < v:
            break
        r += 1
    return r
print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
n_ls=list(str(n))
n_top,n_bottom=int(n_ls[0]),int(n_ls[-1])
if n<100:
    n_middle=0
else:
    n_middle=int("".join(n_ls[1:-1]))
#print("middle",n_middle)
len_n=len(n_ls)
count=0
for i in range(1,n+1):
    #print(i)
    stred_ls=list(str(i))
    top,bottom=int(stred_ls[0]),int(stred_ls[-1])
    if bottom==0:
        continue
    # 頭とケツが一緒の時は, 1桁の数も候補になる
    if top==bottom:
        count+=1
    #print("1:",count)
    if len_n<=2:
        if int(str(bottom)+str(top))<=n:
            count+=1
    else:
        for x in range(len_n-2):
            count+=10**x
        #print("2:",count)
        judged_x=x+1
        #print('比較', str(bottom)+("X"*judged_x)+str(top), n)
        if n_top>bottom:
            count+=10**judged_x
        elif n_top==bottom:
            count+=n_middle
        #print("3:",count)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n > 30:
    x = n // 10
    basenum = x * x + 8
    addnum = 0
    #print("{0} {1}".format(x* 10 + 1, n))
    hassame = False
    for i in range(x * 10 + 1, n):
        #print(i)
        for j in range(1, n):
            #print(j)
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                addnum += 1
                if i == j:
                    hassame=True
                #print("{0},{1}".format(i, j))
    res = basenum + addnum * 2
    #if hassame:
        #res -= 1
    #print("n={0}, x={1}, basenum={2}, addnum={3}".format(n,x,basenum,addnum))
    print(res)
elif n==1:
    print(1)
else:
    res = 0
    for i in range(1, n):
        for j in range(1, n):
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                res += 1
    print("{1}".format(n, res))

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()
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:
n=int(input())
N2=[str(i) for i in range(1,n+1)]
N=tuple(N2)
print(N)

count=0
for a in N:
  for b in N:
    if str(a)[0]==str(b)[-1] and str(a)[-1]==str(b)[0]:
      count+=1

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=str(n)
l=len(s)
d=[9]*l
d[-1]=int(s[0])
#print(n,d)
#exit()
ans=chk=0
if n<1001:
    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]:
                ans+=1
    print(ans)
    exit()
print(ans)

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] == A[1]:
            b = b+1
        else:
            continue
print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
c = len(str(n))
if n <= 10:
    print(min(n, 9))
else:
    for i in range(1, 10):
        for j in range(1, 10):
            pa = 0
            pa2 = 0
            if i == j:
                pa += 1
                pa2 += 1
            temp = n - (i * 10**(c-1) + j)
            temp2 = n - (j * 10**(c-1) + i)
            if c > 2:
                if temp >= 0:
                    pa += min(10**(c-2), temp//10 + 1)
                if temp2 >= 0:
                    pa2 += min(10**(c-2), temp2//10 + 1)
            else:
                if temp >= 0:
                    pa += 1
                if temp2 >= 0:
                    pa2 += 1
            for k in range(0, c-2):
                pa += 10**k
                pa2 += 10**k
            ans += pa*pa2
            #print(i, j, pa*pa2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ret = 0
#diff num
for i in range(1,10):
  for j in range(i+1,10):
    a = 0
    b = 0
    for k in range(1, 6):
      if i * 10 ** k + j < N:
        a += (10 ** (k - 1))
        for k in range(1, 6):
          if j * 10 ** k + i < N:
            b += 10 ** (k - 1)
            ret += a * b * 2
            #same num
            for i in range(1,10):
              c = 0
              for k in range(1,6):
                if i * 10 ** k + i < N:
                  c += 10 ** (k - 1)
                  c += 1
                  ret += c * c
print(ret)

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)

Submission status: Wrong Answer

Solution code:
N = int(input())
# P = list(map(int, input().split()))

if N <= 10:
    print(N)
    exit()

dic = {}
for i in range(11,100):
    if i % 10 == 0:
        continue
    if i % 11 == 0:
        dic[i] = 1
    else:
        dic[i] = 0

for i in range(11, N):
    if i % 10 == 0:
        continue
    tmp = str(i)[0] + str(i)[-1]
    dic[int(tmp)] += 1

res = 0
for current, num in dic.items():
    if current % 11 == 0:
        res += num * num
    else:
        tmp = int(str(current)[::-1])
        res += num * dic[tmp]

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
for x in range(N):
    for y in range(N):
        A=(x+1,y+1)
        if A[0] == A[1]:
            print(A)
        else:
            continue

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	n=int(input())
	
	ans1=0
	ans2=0
	
	for i in range(n):
		a=int(str(i)[0])
		b=i%10
		
		if b==0:
			continue
		k=len(str(i))
		if k==1:
			ans2+=1
		elif a>b:
			ans1+=(10**(k-1)-1)//9
		elif a<b:
			ans1+=(10**(k-2)-1)//9
		else:
			ans1+=(10**(k-2)-1)//9+1+(int(str(i)[1:])-a)//10
			ans2+=1

	print(ans1*2+ans2)

	
	
	
	
	


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
if n > 30:
    x = n // 10
    basenum = x * x + 8
    addnum = 0
    #print("{0} {1}".format(x* 10 + 1, n))
    hassame = False
    for i in range(x * 10 + 1, n):
        #print(i)
        for j in range(1, n):
            #print(j)
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                addnum += 1
                if i == j:
                    hassame=True
                #print("{0},{1}".format(i, j))
    res = basenum + addnum * 2
    if hassame:
        res -= 1
    #print("n={0}, x={1}, basenum={2}, addnum={3}".format(n,x,basenum,addnum))
    print(res)
elif n==1:
    print(1)
else:
    res = 0
    for i in range(1, n):
        for j in range(1, n):
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                res += 1
    print("{1}".format(n, res))

Submission status: Wrong Answer

Solution code:
n = int(input())

dig = len(str(n))

count = 0
for i in range(1,n+1):
    for j in range(1,dig+1):
        top = int(str(i)[0])
        bot = int(str(i)[-1])
        if bot == 0:
            continue
        
        if j == 1:
            if top == bot:
                count += 1
                #print("a",i,j,1)
        elif j == 2:
            if bot*10+top <= n:
                count += 1
                #print("b",i,j,1)
        elif j < dig:
            count += 10 ** (j-2)
            #print("c",i,j,10 ** (j-2))
        else:
            if bot < int(str(n)[0]):
                count += 10 ** (j-2)
                #print("d",i,j,10 ** (j-2))
            elif bot == int(str(n)[0]):
                if top > int(str(n)[1]):
                    count += int(str(n)[1:-1])
                    #print("e",i,j)
                else:
                    count += int(str(n)[1:-1])+1
                    #print("f",i,j)
                    
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n%10==0:
    n-=1

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

h=0
if n>=10:
    h=2
    for i in range(10):
        m[i][i]+=1
if n>=100:
    h=3
    for i in range(10):
        for j in range(10):
            m[i][j]+=1
if n>=1000:
    h=4
    for i in range(10):
        for j in range(10):
            m[i][j]+=10
if n>=10000:
    h=5
    for i in range(10):
        for j in range(10):
            m[i][j]+=100
if n>=100000:
    h=6
    for i in range(10):
        for j in range(10):
            m[i][j]+=1000

if n>=10:
    a=n//10 **(h-1)
    b=(n-a*(10**(h-1)) ) //10
    c=n%10

    for i in range(1,a):
        for j in range(1,10):
            m[i][j]+=10**(h-2)
    for j in range(1,c+1):
        m[a][j]+=b+1

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

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

count = 0
for si in range(1,10):
    i=str(si)
    for sj in range(1,10):
        j = str(sj) 
        count += dicts[i][j] * dicts[j][i]

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
L = len(N)
if L == 1:
    print(int(N))
    exit()

def count(c,d):
    if c == int(N[0]):
        if L == 2:
            if d > int(N[-1]):
                n = 0
            else:
                n = 1
        else:
            n = int(N[1:-1]) + 1
            n += sum(10**i for i in range(L-2))
            if d > int(N[-1]):
                n -= 1
    elif c < int(N[0]):
        n = sum(10**i for i in range(L-1))
    else: # c > N[0]
        if L == 2:
            n = 0
        else:
            n = sum(10**i for i in range(L-2))
    if c == d:
        n += 1
    return n

ans = 0
for c in range(1,10):
    for d in range(1,10):
        nA = count(c,d)
        nB = count(d,c)
        if nA * nB > 0:
            print(c,d,nA,nB)
        ans += nA * nB
print(ans)

Submission status: Wrong Answer

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

n=int(input())
c = 0
if n > 100:
    c = int((n * n/100.0) + 8)
else:
    for i in range(1,n+1):
        for j in range(1,n+1):
            if int(str(i)[0]) == int(str(j)[-1]) and int(str(i)[-1]) == int(str(j)[0]):
                c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())

k=0

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

print(k)

Submission status: Wrong Answer

Solution code:
a=int(input())
num=0
for i in range(1,a+1):
    i=str(i)
    for j in range(1,a+1):
        j=str(j)
        if sorted(i)[0]!=sorted(j)[0]:
            continue
        elif sorted(i)==sorted(j):
            num+=1
        elif len(set(i+j))==1:
            num+=1
print(num)

Submission status: Wrong Answer

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

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

if N < 100:
	cnt = 0
	for i in range(1,N+1):
		if i < 10:
			cnt += 1
			if (i*10)+i <= N:
				cnt += 1
		else:
			s = str(i)
			sa,sb = s[0],s[-1]
			if sb == '0':
				continue
			ss = sb+sa
			if int(ss) <= N:
				cnt += 1
			if sa == sb:
				cnt += 1
	print(cnt)
	sys.exit()



k = len(str(N))
auto = 0
for i in range(k-1):
	auto += 10**i

auto2 = (auto-10**(k-2)) + (int(str(N)[1:]) // 10)
auto3 = auto - 10**(k-2)
m = str(N)[0]
mm = str(N)[-1]
def solve(a,b):
	ans = 0
	if a == b:
		ans += 1
	if a < m:
		return ans + auto
	elif a == m:
		if b <= mm:
			return ans + auto2
		else:
			return ans + auto2 -1
	else:
		return ans + auto3

cnt = 0
for i in range(1,N+1):
	s = str(i)
	if s[-1] == '0':
		continue
	if i < 10:
		cnt += solve(s,s)
	else:
		sa,sb = s[0],s[-1]
		cnt += solve(sb,sa)

print(cnt)

Submission status: Wrong Answer

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

n=int(input())
c = int((n * n/100.0) + 8)

print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
strn = str(n)
keta = len(strn)
n_head = int(strn[0])
n_tail = int(strn[-1])
naka = strn[1:-1]
if len(naka)  == 0:
    nakan = 0
else:
    nakan = int(naka)

ans = 0

if keta <= 2:
    for i in range(1,n+1):
        for j in range(1,n+1):
            head1 = int(str(i)[0])
            tail1 = int(str(i)[-1])
            head2 = int(str(j)[0])
            tail2 = int(str(j)[-1])
            if head1 == tail2 and head2 == tail1:
                ans += 1
                print(i,j)
    print(ans)

else:
    hoj = []
    tmp = 1
    mog = 1
    for i in range(keta):
        hoj.append(mog)
        tmp = tmp*10
        mog = mog + tmp
    #print(hoj)
    
    for i in range(1,n+1):
        head = int(str(i)[0])
        tail = int(str(i)[-1])
        if tail == 0:
            continue

        if tail < n_head:
            ans += hoj[keta-2]
        elif tail > n_head:
            ans += hoj[keta-3]
        else:
            ans += hoj[keta-3]
            if head <= n_tail:
                ans += nakan + 1
            else:
                ans += max(nakan ,0)

        if head == tail:
            ans += 1

        #print(i,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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


N = int(raw_input())
C = np.zeros(shape=(10,10))

for i in range(N):
    i_char = str(i)
    i_first = int(i_char[0])
    i_last = int(i_char[-1])

    C[i_first][i_last] = C[i_first][i_last] + 1

ans = 0

#print "--"                                                                                                                           
#print C                                                                                                                              
#print "--"                                                                                                                           

for i in range(1,10):
    for j in range(1,10):
        n = C[i][j]
        m = C[j][i]
        ans = ans + n*m

print int(ans)

Submission status: Wrong Answer

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

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


            count+=A*B
            #A=max(10**(len(a)-2),1)
            #B=max(10**(len(b)-2),1)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

BegEndTbl = []
for _ in range(10):
    BegEndTbl.append([0] * 10)
print(BegEndTbl)

ans = 0
for i in range(1, N + 1):
    left = int(str(i)[0])
    right = i % 10
    if left == right:
        ans += 1
    ans += BegEndTbl[right][left] * 2
    BegEndTbl[left][right] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#a, b = map(int, input().split())
n = int(input())

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

ans = 0
for i in range(n):
    s = str(i)
    t = len(s)
    u = int(s[0])
    v = int(s[len(s)-1])

    if u == 0:
        continue
    if v == 0:
        continue

    if u == v:
        ans += 1

    z = 2 * l[v][u]
    ans += z

    l[u][v] += 1

print(ans)

Submission status: Wrong Answer

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

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

if N < 100:
	cnt = 0
	for i in range(1,N+1):
		if i < 10:
			cnt += 1
			if (i*10)+i <= N:
				cnt += 1
		else:
			s = str(i)
			sa,sb = s[0],s[-1]
			if sb == '0':
				continue
			ss = sb+sa
			if int(ss) <= N:
				cnt += 1
			if sa == sb:
				cnt += 1
	print(cnt)
	sys.exit()



k = len(str(N))
auto = 0
for i in range(k-1):
	auto += 10**i

auto2 = (auto-10**(k-2)) + (int(str(N)[1:]) // 10)
auto3 = auto - 10**(k-2)
m = str(N)[0]
def solve(a,b):
	ans = 0
	if a == b:
		ans += 1
	if a < m:
		return ans + auto
	elif a == m:
		return ans + auto2
	else:
		return ans + auto3

cnt = 0
for i in range(1,N+1):
	s = str(i)
	if s[-1] == '0':
		continue
	if i < 10:
		cnt += solve(s,s)
	else:
		sa,sb = s[0],s[-1]
		cnt += solve(sb,sa)

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans=0
for i in range(1,n):
    a=str(i)[0]
    b=str(i)[-1]
    for digit in range(1,7):
        if digit == 1:
            if a==b:
                ans+=1
        elif b!='0':
            mn = int(b+'0'*(digit-2)+a)
            mx = int(b+'9'*(digit-2)+a)
            if mn>n:
                break
            if mx<=n:
                ans+=10**(digit-2)
            else:
                ns=str(n)
                for j in range(1,len(ns)-1):
                    ans+=int(ns[j])*10**(max(digit-2-j,0))
                if ns[-1]>=a:
                    ans+=1
                break
if n==1:
    ans+=1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

N = n + 1
totalcount = 0

for i in range(1,N):
  a = str(i)
  a_first = a[0]
  a_end = a[len(str(i)) - 1]
  for j in range(1,N):
    b = str(j)
    b_first = b[0]
    b_end = b[len(str(j)) - 1]
    if a_first == b_end and a_end == b_first:
      totalcount += 1
      print(a,j)
print(totalcount)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

arr[1][1] += 1
arr[2][2] += 1
arr[3][3] += 1
arr[4][4] += 1
arr[5][5] += 1
arr[6][6] += 1
arr[7][7] += 1
arr[8][8] += 1
arr[9][9] += 1

for i in range(11, N+1):
  if i % 10 == 0:
    continue
  tmp = str(i)
  first = tmp[0]
  last = tmp[-1]
  # print(first, last)
  arr[int(first)][int(last)] += 1

sum_diag = 0
sum_other = 0

for i in range(1, 10):
  for j in range(1, 10):
    if i == j:
      sum_diag += arr[i][j]*arr[i][j]
    else:
      sum_other += arr[i][j] * arr[j][i] * 2

# print(arr)

print(int(sum_diag + sum_other/2))

Submission status: Wrong Answer

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

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


            count+=A*B
            #A=max(10**(len(a)-2),1)
            #B=max(10**(len(b)-2),1)
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import itertools
import sys


def solve(N: int):
    sN = str(N)
    lN = len(sN)
    if lN == 1:
        print(N)
        return
    l1 = int(sN[0])
    l2 = int(sN[-1])
    d = {}
    for k1, k2 in itertools.product(range(1, 10), repeat=2):
        p = 10 ** (lN - 2) // 9
        if k1 == k2:
            p += 1
        if (k1, k2) < (l1, l2):
            p += 10 ** (lN - 2)
        elif k1 == l1:
            p += int(sN[1:-1] or "0")
            if k2 == l2:
                p += 1
        d[k1, k2] = p

    ans = 0
    for k1, k2 in itertools.product(range(1, 10), repeat=2):
        ans += d[k1, k2] * d[k2, k1]
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[[0]*9 for i in range(9)]
for i in range(n):
    x,y =int(str(i)[0]), int(str(i)[-1])
    if y>0:
        a[x-1][y-1]+=1
count=0
for i in range(9):
    for j in range(9):
        if i>j:
            continue
        if i==j:
            count+=a[i][j]**2
        else:
            count+=a[i][j]*a[j][i]*2
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    strn = input()
    n = int(strn)
    if n < 10:
        print(n)
        return
    m = [0] * 81

    for i in range(1, n + 1):
        a = int(str(i)[0])
        b = int(str(i)[-1])
        # print(a, b)
        if b == 0:
            continue
        else:
            key = 9 * (a - 1) + b - 1
            # print(key)
            m[key] += 1
    ans = 0
    print(m)
    for i in range(1, 10):
        for j in range(1, 10):
            key = 9 * (i - 1) + j - 1
            oppose = 9 * (j - 1) + i - 1
            ans += m[key] * m[oppose]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
ct=0
for i in range(1,n+1):
    j=str(i)
    if i%10==0:
        pass
    elif int(j[::-1])==i and len(j)==1:
        ct+=1
        #print(i)
    elif int(j[::-1])<i:
        ct+=2
        #print(i,int(j[::-1]))
    elif int(j[::-1])==i:
        ct+=(len(j)-1)*2+1
        #print(i,(len(j)-1)*2+1)
print(ct)

Submission status: Wrong Answer

Solution code:
n=int(input())
ct=[[0]*10 for i in range(10)]
for i in range(1,10):
  for j in range(1,10):
    if n>=10:
      if i==j:
        ct[i][j]+=1
    if n>=10**2:
      ct[i][j]+=1
    if n>=10**3:
      ct[i][j]+=10
    if n>=10**4:
      ct[i][j]+=100
    if n>=10**5:
      ct[i][j]+=1000
    
    if n<10:
      if n>=i:
        ct[i][j]+=1
    
    elif 10<n<10**2:
      if n>=i*10+j:
        ct[i][j]+=1
    
    elif 10**2<n<10**3:
      if int(str(n)[0])>i:
        ct[i][j]+=10
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1])
        else:
          ct[i][j]+=int(str(n)[1])-1

    elif 10**3<n<10**4:
      if int(str(n)[0])>i:
        ct[i][j]+=10**2
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1:3])
        else:
          ct[i][j]+=int(str(n)[1:3])

    elif 10**4<n<10**5:
      if int(str(n)[0])>i:
        ct[i][j]+=10**3
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1:4])
        else:
          ct[i][j]+=int(str(n)[1:4])
    
    elif n>10**5:
      if int(str(n)[0])>i:
        ct[i][j]+=10**4
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1:5])
        else:
          ct[i][j]+=int(str(n)[1:5])
ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=ct[i][j]*ct[j][i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


for i in range(n):
    i = list(str(i))
    cnt[int(i[0])][int(i[-1])] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

if N > 10:

    tens = math.ceil(N/10)
    print(tens ** 2 + 8)
elif N == 10:
    print(9)
else:
    print(N)

Submission status: Wrong Answer

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

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

if N < 100:
	cnt = 0
	for i in range(1,N+1):
		if i < 10:
			cnt += 1
			if (i*10)+i <= N:
				cnt += 1
		else:
			s = str(i)
			sa,sb = s[0],s[-1]
			if sb == '0':
				continue
			ss = sb+sa
			if int(ss) <= N:
				cnt += 1
			if sa == sb:
				cnt += 1
	print(cnt)
	sys.exit()



k = len(str(N))
auto = 0
for i in range(k-1):
	auto += 10**i

auto2 = (auto-10**(k-2)) + (int(str(N)[1:]) // 10)
auto3 = auto - 10**(k-2)
m = str(N)[0]
def solve(a,b):
	ans = 0
	if a == b:
		ans += 1
	if a < m:
		return ans + auto
	elif a == m:
		return ans + auto2
	else:
		return ans + auto3

cnt = 0
for i in range(1,N+1):
	s = str(i)
	if s[-1] == '0':
		continue
	if i < 10:
		cnt += solve(s,s)
	else:
		sa,sb = s[0],s[-1]
		cnt += solve(sb,sa)

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n < 10:
    print(n)
    exit()

memo = dict()
 
def func(s,f):
    ans = 0
    for i in range(1,n):
        if str(i)[0] == f and str(i)[-1] == s:
            ans += 1
    memo[s+" "+f] = ans
 
res = 0

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

    if s + " " + f in memo:
        res += memo[s + " " + f]
    else:
        func(s,f)
        res += memo[s + " " + f]

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans=0
for i in range(1,n):
    a=str(i)[0]
    b=str(i)[-1]
    for digit in range(1,7):
        if digit == 1:
            if a==b:
                ans+=1
        elif b!='0':
            mn = int(b+'0'*(digit-2)+a)
            mx = int(b+'9'*(digit-2)+a)
            if mn>n:
                break
            if mx<n:
                ans+=10**(digit-2)
            else:
                ns=str(n)
                for j in range(1,len(ns)-1):
                    ans+=int(ns[j])*10**(max(digit-3-j,0))
                if ns[-1]>=a:
                    ans+=1
                break
if n==1:
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

result = 0
for a in range(1, n + 1):
    for b in range(n):
        head_a = str(a)[0]
        tail_a = str(a)[-1]
        head_b = str(b)[0]
        tail_b = str(b)[-1]
        if head_a == tail_b and tail_a == head_b:
            result += 1

print(result)