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:
from math import log10
N = int(input())
 
C = 0
for i in range(1,10):
  for j in range(1,10):
    cij = 0
    cji = 0
    for k in range(1,N+1):
      m = log10(k) + 1
      if k//10**m == i and k%10 == j:
        cij += 1
      if k//10**m == j and k%10 == i:
        cji += 1
    C += cij*cji
print(C)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [[0 for _ in range(10)] for _2 in range(10)]
ans = 0
for i in range(1, n+1):
  l = int(str(i)[0])
  r = int(str(i)[-1])
  p[l][r] += 1
  ans += p[r][l]
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
idk = []
a = 0

for i in range(0,int(n)):
    idk.append(str(i))

for x in range(0,int(n)):
    for y in range(0,int(n)):
        if idk[x][len(idk[x])-1] == idk[y][0] and idk[y][len(idk[y])-1] == idk[x][0]:
            a+=1

print(a-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = [[0] * 10 for i in range(10)]
for i in range(1,n+1):
    cnt[int(str(i)[0])][int(str(i)[-1])] += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#没だけど頑張ったやつ

N = int(input())
p = N%10
q = ((N-p)/10)%10
r = ((N-10*q-p)/100)%10
s = ((N-100*r-10*q-p)/1000)%10
t = ((N-1000*s-100*r-10*q-p)/10000)%10
u = ((N-10000*t-1000*s-100*r-10*q-p)/100000)%10
if N <=9:
    print(N)
elif 10 <= N < 100:
    if q <= p:
        a = q * q + 2 *q#2桁＊2桁と1桁＊2桁
        print(int(a+9))
    elif q > p:
        a = q ** 2 -(q-p)*(q-p+1)/2 + 2 * (q-1)#2桁＊2桁と1桁＊2桁
        print(int(a+9))
elif 100 <= N < 1000:
    if r <= p:
        a = r * r *110 + r * 20
        print(int(a+108))
    elif r > p:
        a = (r ** 2 -(r-p)*(r-p+1)/2) *110 + 20*(r-1)
        print(int(a+108))
elif 1000 <= N < 10000:
    if s <= p:
        a = s*s*11100 + s * 200
        print(int(a+9198))
    elif s > p:
        a = (s ** 2 -(s-p)*(s-p+1)/2) *11100 + 200*(s-1)
        print(int(a+9198))
elif 10000 <= N < 100000:
    if t <= p:
        a = t*t*1111000 + t * 2000
        print(int(a+910098))
    elif t > p:
        a = (t ** 2 -(t-p)*(t-p+1)/2) *1111000 + 2000*(t-1)
        print(int(a+910098))
elif 100000 <= N < 1000000:
    if u <= p:
        a = u*u*111110000 + u * 20000
        print(int(a+9001000098))
    elif u > p:
        a = (u ** 2 -(u-p)*(u-p+1)/2) *111110000 + 20000*(u-1)
        print(int(a+9001000098))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for k in range(N):
    c[int(str(k)[0])][int(str(k)[-1])]+=1

ans = 0

for k in range(81):
    i = k // 9 + 1
    j = k % 9 + 1
    ans += c[i][j] * c[j][i]

print(ans)

Submission status: Wrong Answer

Solution code:
d=[0]*100
for i in range(int(input())+1):
  s=str(i)
  d[int(s[0])*10+int(s[-1])]+=1
print(sum(d[i]*d[i%10*10+i//10]for i in range(100)))

Submission status: Wrong Answer

Solution code:
import numpy as np

# get N
#N = int(input())
N =200000

countup = np.zeros(100, dtype=int)

for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    countup[A*10+B] += 1

ans = 0
for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    ans += countup[B*10+A]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())

res = 0
freq = defaultdict(int)

for i in range(1, N):
    si = str(i)
    freq['{}{}'.format(si[0], si[-1])] += 1
    
for i in range(1, N):
    si = str(i)
    res += freq['{}{}'.format(si[-1], si[0])]
        
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
dp=[]
for i in range(10):
  dp.append(i)
l=len(str(n))
for i in range(11,n+1):
  num1=int(str(i)[0])
  num2=int(str(i)[-1])
  if num2==0:
    dp.append(dp[-1])
    pass
  else: 
    num=dp[-1]
    nums=0
    l=len(str(i))
    for j in range(2,l):
      nums+=10**(j-2)     
    if num2>num1:
      num4=0
    elif num1>num2:
      num4=10**(l-2)
    else:
      num4=(i-(num2*10**(l-1)+num1))//10
    nums+=num4
    #print(nums)
    num+=nums*2
    if num1==num2:
      num+=3
    dp.append(num)
print(dp[-1])
#print(dp)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for i in range(1, n+1):
	L = int(str(i)[0])
	R = int(str(i)[-1])
	if L * R == 0:
		continue
	if L == R:
		ans += 1
	cur = 10
	dig = R*cur + L
	while dig <= n:
		ans += cur // 10
		cur *= 10
		dig = R*cur + L
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def get_first(num):
    k=num
    while True:
        if k < 10:
            break
        k = k//10
    return k

for A in range(1,n+1):
    Af=get_first(A)
    Al=A%10
    #print(f'Af,Al {Af},{Al}')
    if Al==0:
        continue
    if Al==Af:
        count+=1
        #print(Al,Al)
    B=0
    i=1
    while(B<=n):
        B = Al*(10**i)+Af
        if(B>n):
            break
        count+=10**(i-1)
        #print(A,B)
        i+=1
print(count)

Submission status: Wrong Answer

Solution code:
# 解説を読んでから

from itertools import product
from math import floor, ceil
import numpy as np

N = int(input())
d = floor(np.log10(N)) + 1  # Nの桁数
N_sento = N // (10 ** (d - 1))  # Nの先頭の数字

n = np.zeros((9, 9), dtype='int')
# n[i-1,j-1] は、先頭がi, 末尾がjであるN以下の整数の個数とする

for i, j in product(range(9), range(9)):
    # n[i, j]を求める。
    # i.e. 先頭がi+1, 末尾がj+1である整数の数

    # 1桁の数字
    if i == j and N >= (i + 1):
        n[i, j] += 1

    # 2桁以上の数字
    if d >= 2:
        for k in range(d-2):
            n[i, j] += 10 ** k
        if N_sento == (i + 1):
            n[i, j] += ceil((N - 10**(d-1) * (i + 1) - (j + 1)) / 10)
        elif N_sento > (i + 1):
            n[i, j] += 10 ** (d - 2)

print(np.einsum('ij,ji', n, n))

Submission status: Wrong Answer

Solution code:
N = int(input())
num_list = [[0]*9 for i in range(9)]
cnt = 0
for i in range(N):
    k = str(i+1)
    j = int(k[0])-1
    l = int(k[-1])-1
    num_list[j][l] += 1
for i in range(9):
    for j in range(9):
        cnt += num_list[i][j] * num_list[j][i]
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [0]*100
for num in range(1,N):
  arr[int(str(num)[0]+str(num)[-1])] += 1
print(sum([arr[i*10+j]*arr[j*10+i]  for i in range(10) for j in range(10)]))

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [0]*100
for num in range(1,N):
  arr[int(str(num)[0]+str(num)[-1])] += 1
print(sum([arr[int(str(i)+str(j))]*arr[int(str(j)+str(i))] for i in range(10) for j in range(10)]))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(1,N+1):
    a = N % 10
    b = 0
    while N > 0:
        b = N
        N = N // 10
    c[a][b] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
#最上位がi,最下位がjの整数の個数
def cnt_num(i,j):
  cnt = 0
  for num in range(1,N):
    if (str(num)[0]==str(i)) & (str(num)[-1]==str(j)):
      cnt += 1
  return cnt

ans = 0
for a in range(10):
  for b in range(10):
    ans += cnt_num(a,b)*cnt_num(b,a)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(n):
    start = int(str(i)[0])
    stop = int(str(i)[-1])

    c[start][stop] += 1

r = 0
for i in range(10):
    for j in range(10):
        r += c[i][j] * c[j][i]

#iとjがどちらも0の場合は問題設定と合致しないので引く
print(r - 1)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 0
for i in range(1,N+1):
    if i % 10 == 0:
        continue
    x = int(math.log10(i))
 
    if i // (10 ** x) == i % 10:  
        ans += 1
    
    for j in range(1,6):
        if N >= (i % 10) * (10 ** j) + i // (10**x):
            ans += min(10**(j-1), N - ((i % 10) * (10 ** j) + i // (10**x)) + 1)

print (ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 0
for i in range(1,N+1):
    if i % 10 == 0:
        continue
    x = int(math.log10(i))
 
    if i // (10 ** x) == i % 10:  
        ans += 1
        
    if N > (i % 10) * 10:
        ans += 1
    if N > (i % 10) * 100:
        ans += 10
    if N > (i % 10) * 1000:
        ans += 100
    if N > (i % 10) * 10000:
        ans += 1000
    if N > (i % 10) * 100000:
        ans += 10000

print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = 0
a = 0
k = 0
b = 0

listk = []
count = 0
for i in range(1,n+1):
    m = i
    a = i
    while m > 10 and a >10:
        m = m % 10
        a = a//10
    for j in range(1, n+1):
        k = j
        b = j
        while k > 10 and b > 10:
            k = k // 10
            b = b % 10
        if m == k and b == a and (i%10 != 0):
            count += 1


print(count)

Submission status: Wrong Answer

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


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

print(count)

Submission status: Wrong Answer

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

for x in range(1, N):
    s = str(x)
    first = int(s[0])
    last = int(s[-1])
    C[first][last] += 1

ans = 0
for x in range(1, N):
    s = str(x)
    first = int(s[0])
    last = int(s[-1])

    ans += C[last][first]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import collections

def r(n):
  count = 0
  for i in range(1, n):
    fl = str(i)[0]
    el = str(i)[-1]
    for k in range(len(str(n))):
      b = list("0" * (k + 1))
      b[0] = fl
      b[-1] = el
      e = int(''.join(b))
      b.reverse()
      s = int(''.join(b))
      step = 1
      if e < s:
        step = -1
      for r in range(s, e+1, step):
        if n >= r and not r == 0 and str(r)[0] == el and str(r)[-1] == fl:
          count += 1


  return count

def main():
    # input = sys.stdin.readline
    # n = int(input())
    print(r(100))

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0

for a in range(1, N+1):
    for b in range(1, N + 1):
        a_head = int(str(a)[0])
        a_tail = a % 10
        b_head = int(str(b)[0])
        b_tail = b % 10
        if a_head == b_tail and a_tail == b_head:
            ans += 1
            print(a, b)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

print([0 for i in range(9)])

Submission status: Wrong Answer

Solution code:
strN = input()
N = int(strN)
p = {i: {j: 0 for j in range(1, 10)} for i in range(1, 10)}
for k in range(1, N):
    strk = str(k)
    i = int(strk[0])
    j = int(strk[-1])
    if i == 0 or j == 0:
        continue
    p[i][j] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
strN = input()
N = int(strN)
p = {i: {j: 0 for j in range(1, 10)} for i in range(1, 10)}
for i in range(1, 10):
    for j in range(1, 10):
        for k in range(1, N):
            strk = str(k)
            if str(i) == strk[0] and str(j) == strk[-1]:
                p[i][j] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
# 整数の入力
A = int(input())
cnt = 0
for i in range(1, A):
  for j in range(1, A):
    x = str(i)
    y = str(j)

    first_x = x[0]
    last_x = x[-1]
    first_y = y[0]
    last_y = y[-1]
    
    if(first_x ==  last_y and last_x == first_y):
      cnt = cnt + 1
      continue
      
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
a=int(input())
ans=0
c=[[0 for i in range(10)] for j in range(10)]
for i in range(1,a):
  aa=str(i)
  c[int(aa[0])][int(aa[-1])]+=1
for i in range(10):
  for j in range(10):
    ans+=c[i][j]*c[j][i]
    
print(ans)

Submission status: Wrong Answer

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

N = int(input())
ans = 0
if N < 10:
    ans = N
elif N < 100:
    for i in range(N+1):
        if i != 0: 
            if i < 10:
                ans += 1
            elif str(i)[-1] == str(i)[0]:
                ans += 3
            elif str(i)[-1] != '0' and int( str(i)[-1] + str(i)[0] ) <= N:
                ans += 1
else:
    for i in range(N+1):
        if i != 0:
            if i < 10:
                ans += 1
            else:
                if str(i)[-1] == str(i)[0]:
                    ans += ((len(str(i))-1)*2)
            
                ans += 1
                for k in range(pow(10,len(str(N))-2)):
                    #print('')
                    #print(j, k)
                    if str(i)[-1] != '0' and int( str(i)[-1] + str(k) + str(i)[0] ) <= N:
                        ans += 1
                        #print(i, str(i)[-1] + str(k) + str(i)[0])
                   
print(ans)

Submission status: Wrong Answer

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

N = int(input())
ans = 0
if N < 10:
    ans = N
elif N < 100:
    for i in range(N+1):
        if i != 0: 
            if i < 10:
                ans += 1
            elif str(i)[-1] == str(i)[0]:
                ans += 3
            elif str(i)[-1] != '0' and int( str(i)[-1] + str(i)[0] ) <= N:
                ans += 1
else:
    for i in range(N+1):
        if i != 0:
            if i < 10:
                ans += 1
            else:
                if str(i)[-1] == str(i)[0]:
                    ans += ((len(str(i))-1)*2)
            
                ans += 1
                for j in range( len(str(N))-2 ):
                    for k in range(10):
                        if int( str(i)[-1] + j*str(k) + str(i)[0] ) <= N:
                            ans += 1
                   
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

num = [[0 for j in range(10)]for i in range(10)]
for i in range(N):
    NN = i
    kouho = []
    while NN>=1:
        kouho.append(int(NN%10))
        NN = NN/10
    if len(kouho) == 0:
        continue
    
    low_bit = int(kouho[0])
    high_bit = int(kouho[-1])
    
    if (not low_bit or not high_bit):
        continue
    num[low_bit][high_bit] += 1
ans = 0


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

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

co = 0

for i in range(n):
    ii = i+1
    iii = len(str(ii))
    if str(ii)[-1] == "0":
        #print("op:"+str(op))
        continue
    for j in range(len(str(n))):
        jj = j+1
        if jj == 1 and str(ii)[-1] == str(ii)[0]:
            ppp = ii%10
        elif jj == 1:
            continue
        else:
            ppp = int(str(ii)[-1])*(10**j if j != 0 else 0) + int(str(ii)[0])
        if ppp > n:
            continue
        else:
            if n - int(str(ii)[-1])*(10**j if j != 0 else 0) + int(str(ii)[0]) > 10**len(str(n)):
            #if (int(str(ii)[-1])+1)*(10**j if j != 0 else 0) + int(str(ii)[0]) - n > 0:
                co += int(str(n)[0:-2] if str(n)[0:-2] != "" else "1")
            else:
                co += (10**(j-1)) if j >= 1 else 1



print(co)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import math


def main():
  n = int(input())
  c = [[0] * 10 for _ in range(10)]

  for x, y in itertools.product(range(1, 10), repeat=2):
    for s in range(1, 6):
      u = (x + 1) * (10 ** s) + y
      l = x * (10 ** s) + y

      if l > n:
        break

      c[x][y] += int(math.ceil((min(n, u) - l) / 10))

    if x == y and x <= n:
      c[x][y] += 1

  print(sum(c[x][y] * c[y][x] for x, y in itertools.product(range(1, 10), repeat=2)))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
baf = 0

if N <= 10:
    for i in range(1, N+1):
        for j in range(1, N+1):
            stri = str(i)
            strj = str(j)
            if stri[0] == strj[-1] and strj[0] == stri[-1]:
                #print(i, j)
                count += 1
    print(count)
else:
    num = (N // 10) ** 2
    if N % 10 == 0:

        print(num + 8)
    else:
        #print(num + 8)
        #print(num)
        for i in range(N // 10 * 10 ,N+1):
            for j in range(1, N+1):
                stri = str(i)
                strj = str(j)
                if stri[0] == strj[-1] and strj[0] == stri[-1]:
                    #print(i, j)
                    count += 1
                    #print(count)
        count *= 2
        for i in range(N // 10 * 10 + 1, N+1):
            for j in range(N // 10 * 10 + 1, N+1):
                stri = str(i)
                strj = str(j)
                if stri[0] == strj[-1] and strj[0] == stri[-1]:
                    #print(i, j)
                    count -= 1
                    #print(count)
    print(num+count + 8)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
baf = 0

if N <= 10:
    for i in range(1, N+1):
        for j in range(1, N+1):
            stri = str(i)
            strj = str(j)
            if stri[0] == strj[-1] and strj[0] == stri[-1]:
                #print(i, j)
                count += 1
else:
    num = (N // 10) ** 2
    if N % 10 == 0:
    
        print(num + 8)
    else:
        #print(num + 8)
        #print(num)
        for i in range(N // 10 * 10 ,N+1):
            for j in range(1, N+1):
                stri = str(i)
                strj = str(j)
                if stri[0] == strj[-1] and strj[0] == stri[-1]:
                    #print(i, j)
                    count += 1
                    #print(count)
        count *= 2
        for i in range(N // 10 * 10 + 1, N+1):
            for j in range(N // 10 * 10 + 1, N+1):
                stri = str(i)
                strj = str(j)
                if stri[0] == strj[-1] and strj[0] == stri[-1]:
                    #print(i, j)
                    count -= 1
                    #print(count)
    print(num+count + 8)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
baf = 0
if N <= 10:
    for i in range(1, N+1):
        for j in range(1, N+1):
            stri = str(i)
            strj = str(j)
            if stri[0] == strj[-1] and strj[0] == stri[-1]:
                #print(i, j)
                count += 1
        if i % 10 == 0:
            print(i, count, count-baf)
            baf = count
    print(count)
else:
    num = (N // 10) ** 2
    if N % 10 == 0:

        print(num + 8)
    else:
        #print(num + 8)
        #print(num)
        for i in range(N // 10 * 10 ,N+1):
            for j in range(1, N+1):
                stri = str(i)
                strj = str(j)
                if stri[0] == strj[-1] and strj[0] == stri[-1]:
                    #print(i, j)
                    count += 1
                    #print(count)
        count *= 2
        for i in range(N // 10 * 10 + 1, N+1):
            for j in range(N // 10 * 10 + 1, N+1):
                stri = str(i)
                strj = str(j)
                if stri[0] == strj[-1] and strj[0] == stri[-1]:
                    #print(i, j)
                    count -= 1
                    #print(count)
    print(num+count + 8)

Submission status: Wrong Answer

Solution code:
from numpy import zeros
 
N = int(input())
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
from numpy import zeros
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

Submission status: Wrong Answer

Solution code:
from numpy import zeros
 
N = 25
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
  
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(int(cnt))

Submission status: Wrong Answer

Solution code:
from numpy import zeros
 
N = 25
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

memory = dict()
result = 0

for i in range(10):
    for j in range(10):
        memory[(i,j,)] = 0

for i in range(1, N):
    if i >= 100000:
        memory[(i//100000, i%10,)] += 1
    elif i >= 10000:
        memory[(i//10000, i%10,)] += 1
    elif i >= 1000:
        memory[(i//1000, i%10,)] += 1
    elif i >= 100:
        memory[(i//100, i%10,)] += 1
    elif i >= 10:
        memory[(i//10, i%10,)] += 1
    else:
        memory[(i, i,)] += 1

for i in range(10):
    for j in range(10):
        result += memory[(i,j,)] * memory[(j,i,)]

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
if n>99:
    dec = n//10 - 1
    prov = 9 + (3 + 2*dec + 1)*dec//2
    last = 2*(dec+1)+1
    contribution = last//9
    rem = last%9
    digit = 0
    n1 = n
    while n1:
        if n1//10 == 0:
            digit = n1
            n1//=10
        else:
            n1//=10
    if n%10>digit:
        prov1 = contribution*(n%10) + rem
    elif n%10 == digit:
        prov1 = rem + contribution*(digit - n%10)
    else:
        prov1 = contribution*(n%10)
    res = prov + prov1
elif n>9:
    dec = n//10 - 1
    prov = 9 + (3 + 2*dec + 1)*dec//2
    last = 2*(dec+1)+1
    contribution = 2
    rem = 1
    digit = 0
    n1 = n
    while n1:
        if n1//10 == 0:
            digit = n1
            n1//=10
        else:
            n1//=10
    if n%10>=digit:
        prov1 = contribution*digit + rem
    else:
       prov1 = contribution*(n%10)
    res = prov + prov1
else:
    res = n
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n>99:
    dec = n//10 - 1
    prov = 9 + (3 + 2*dec + 1)*dec//2
    last = 2*(dec+1)+1
    contribution = last//9
    rem = last%9
    digit = 0
    n1 = n
    while n1:
        if n1//10 == 0:
            digit = n1
            n1//=10
        else:
            n1//=10
    if n%10>=digit:
        prov1 = contribution*(n%10) + rem
    else:
        prov1 = contribution*(n%10)
    res = prov + prov1
elif n>9:
    dec = n//10 - 1
    prov = 9 + (3 + 2*dec + 1)*dec//2
    last = 2*(dec+1)+1
    contribution = 2
    rem = 1
    digit = 0
    n1 = n
    while n1:
        if n1//10 == 0:
            digit = n1
            n1//=10
        else:
            n1//=10
    if n%10>=digit:
        prov1 = contribution*digit + rem
    else:
       prov1 = contribution*(n%10)
    res = prov + prov1
else:
    res = n
print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

# input_N = sys.stdin.readline
# input_N=sys.stdin.readline().strip()
input_N = int(input())
cnt=0

for i in range(1,input_N):
    string = str(i)
    if string[-1] == string[0] :
        reverse_string = string[0] 
        if int(reverse_string) <= input_N:
#             print(i,reverse_string)  
            cnt +=1
    reverse_string = string[-1] + string[0] 

    if int(reverse_string) <= input_N and int(reverse_string[0]) != 0:
#         print(i,reverse_string)
        cnt +=1
    
    for j in range(0,int(input_N / 10)):
        reverse_string = string[-1] + str(j) +  string[0] 
        if int(reverse_string) <= input_N and int(reverse_string[0]) != 0:
#             print(i,reverse_string)  
            cnt +=1
        
print(cnt)

Submission status: Wrong Answer

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

for i in range(1,input_N):
    string = str(i)
    if string[-1] == string[0] :
        reverse_string = string[0] 
        if int(reverse_string) <= input_N:
            print(i,reverse_string)  
            cnt +=1
    reverse_string = string[-1] + string[0] 

    if int(reverse_string) <= input_N and int(reverse_string[0]) != 0:
        print(i,reverse_string)
        cnt +=1
    
    for j in range(0,int(input_N / 10)):
        reverse_string = string[-1] + str(j) +  string[0] 
        if int(reverse_string) <= input_N and int(reverse_string[0]) != 0:
            print(i,reverse_string)  
            cnt +=1
        
print(cnt)

Submission status: Wrong Answer

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

def solve(N: int):
    c = collections.defaultdict(int)
    if N == 1:
        print(1)
        return
    for i in range(1, N):
        target = str(i)
        c[target[0], target[-1]] += 1
    result = 0
    for i in range(0, 10):
        for j in range(0, 10):
            i = str(i)
            j = str(j)
            result += c[i, j] * c[j, i]
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
d=[[0]*10 for i in range(10)]
#10x10のグリッドを作る

#9x9パターンに分類されるため、各数字をグリッドに振り分ける
for i in range(N):
  n=str(i)
  d[int(n[0])][int(n[-1])]+=1

#組み合わせの数は[Aの数]x[Bの数] 先頭か語尾に0が付くものはカウントしない
r=0
for i in range(9):
  for j in range(9):
    r+=d[i+1][j+1]*d[j+1][i+1]
print(r)

Submission status: Wrong Answer

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

    table = [0] * 100
    for i in range(n):
        i_str = str(i)
        table[int(i_str[0]) * 10 + int(i_str[-1])] += 1

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

    print(num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
sample = [0] * 100

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

    num = str(i)
    first = num[0]
    final = num[-1]
    print(first)
    print(final)

    sample[int(first+final)] += 1
    print(int(first+final))

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

for i in range(1, n):
        if int(str(i)[-1]) != 0:
                if int(str(i)[0]) >= int(str(i)[-1]):
                        if int(str(i)[0]) == int(str(i)[-1]):
                                if len(str(i)) > 2:
                                        count += (int(str(i)[1:][:-1])+1)*2
                                else:
                                        count += 1
                                for j in range(1,len(str(i))):
                                        if j > 2:
                                                count += 10**(j-2)*2
                                        else:
                                                count += 2
                        else:
                                for j in range(0,len(str(i))-1):
                                        count += 10 ** j * 2
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    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 i == j[::-1]:
                num += 1
            elif len(set(i + j)) == 1:
                num += 1
    print(num)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def getLeft(num):
    while num > 10:
        num = int(num / 10)
    return num

def getRight(num):
    return num % 10

n = int(input())
a = defaultdict(int)
for number in range(1,n+1):
    left = getLeft(number)
    right = getRight(number)
    a[(left,right)] += 1


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

Submission status: Wrong Answer

Solution code:
N = input()
#Nf = int(N[0])
#Ne = int(N[-1])
No = int(N)
#print(N,Nf,Ne)
count = 0
for i in range(1,No,1):
  iff = int(str(i)[0])
  iee = int(str(i)[-1])
  for j in range(1,No,1):
    jff = int(str(j)[0])
    jee = int(str(j)[-1])
    if jff == iee and jee == iff:
      count+=1
#      print(count, i, j)
print(count)