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:
#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(N):
    a = 0
    for n in range(1, N+1):
        if n < 10:
            a += 1
        else:
            # nあが同じ数字の場合
            head = int(str(n)[0])
            tail = int(str(n)[-1])
            if head == tail:
                a += 3
            else:
                if (tail * 10 + head) <= N:
                    if tail != 0 and head != 0:
                        a += 1
    return a






do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    S = parsed_lines[1][0]
    return n, k, S


if not do_submit:
    a, b, c = input_parse("""
    3 1
    ABC
    """)
    print(sol(a, b, c))

    a, b, c = input_parse("""
    4 3
    CABA
    """)
    print(sol(a, b, c))

else:
    #a, b = list(map(int, input().split()))
    N = int(input().strip())
    #S = list(map(int, input().split()))
    # a = int(input())
    # b = int(input())
    # T = input()
    print(sol(N))
    # S = input().strip()
    # print(sol(S))

Submission status: Wrong Answer

Solution code:
n = int(input())
K = len(str(n))
C = str(n)
C1 = int(C[0])
Cn = int(C[-1])

# nと同じ桁のBの数
base2 = 0
if K > 3:
    base2 = int(C[1:-1])

# nより桁が小さい3桁以上Bの数
base = 0
for i in range(1, K-2):
    base += 10 ** i


ans = 0
for i in range(1, n + 1):
    c = str(i)
    if c[-1] == "0":
        continue
    if c[0] == c[-1]:
        if i <= n:
            ans += 1
    if int(c[-1] + c[0]) <= n:
        ans += 1
    ans += base
    if int(c[-1]) == C1 and int(c[0]) <= Cn:
        ans += base2
    if int(c[-1]) <  C1:
        ans += 10 ** (K-2)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = (n // 10) ** 2 + 8
if str(n % 10) <= str(n)[0]:
  ans += 1
for i in range(1, n % 10 + 1):
  ans += 10 ** (len(str(n)) - 1) * 2
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
c=0
for i in range(1,int(n)+1):
  t=n[0]
  b=n[-1]
  a=int(t+b)
  if i<10:c+=1
  elif a//11<a//10 and a%10!=0:c+=2
  elif t==b:c+=3
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
n_l = list(str(n))

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

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:
N = int(input())
len_N = len(str(N))
str_N = str(N)
N_a = int(str_N[0])
N_b = int(str_N[-1])
ans = 0
if len_N == 1:
    print(N)
    exit()
if len_N == 2:
    ans += 9
    for i in range(11, N+1):
        str_i = str(i)
        if str_i[1] == '0':
            continue
        i_tmp = int(str(i)[1] + str(i)[0])
        if i_tmp <= N:
            ans += 1
    tmp = N // 11
    ans += tmp * 2
    print(ans)
    exit()

for i in range(1, N+1):
    tmp = str(i)
    tmp_a = int(tmp[0])
    tmp_b = int(tmp[-1])
    if tmp_b == 0:
        continue
    if tmp_a == tmp_b:
        ans += 1
 
    if tmp_b > N_a:
        ans += int('1' * (len_N - 2))

    elif tmp_b == N_a and tmp_a <= N_b:
        ans += int('1' * (len_N - 2))
        naka = tmp[1:-1]
        if naka == "":
            continue
        ans += int(naka) + 1

    elif tmp_b == N_a and tmp_a > N_b:
        ans += int('1' * (len_N - 2))
        naka = tmp[1:-1]
        if naka == "":
            continue
        ##ans += int(naka)

    else:
        ans += int('1' * (len_N - 1))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
ans_dict = {}
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans_dict[i*10+j]=0
for num in range(1,n+1):
    num_str =  str(num)
    i = int(num_str[len(num_str)-1])
    j = int(num_str[0])
    if (i!=0) & (j!=0):
        ans_dict[i*10+j] +=1
for key_ in ans_dict.keys():
    if str(key_)[0] == str(key_)[1]:
        ans += ans_dict[key_]**2
    else:
        key_s = key_//10+int(str(key_)[1])*10
        ans += ans_dict[key_] * ans_dict[key_s]
        ans_dict[key_s] = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
if n<10:
  print(n)
  sys.exit()
  
num=9
for i in range(n,9,-1):
  N=str(i)
  l=len(N)
  if N[0]==N[l-1]:
    m=1
    for j in range(1,l-1):
      m*=(int(N[j])+1)
    num+=1+2*(1+((10**(l-2)-1)//9)+m-1)
  if N[0]!=N[l-1] and N[l-1]!='0':
    if int(N[0])>int(N[l-1]):
      num+=2*((10**(l-1)-1)//9)
    if int(N[0])<int(N[l-1]):
      num+=2*((10**(l-2)-1)//9)
print(num)

Submission status: Wrong Answer

Solution code:
n=int(input())

cnt=0
for i in range(1,(n+1)):
    if i%10==0:continue
    j=0
    a=b=str(i)

    if int(a)<10:
        a_f=a
        a_l=a
    else:
        a_f=a[0]
        a_l=a[-1]
    b_f=a_l
    b_l=a_f
    if a_f==a_l:
        b=a_f
    else:
        b=int(b_f+b_l)
    if len(str(b))==1:
        cnt+=1
        b=int(str(b)+str(b))
    
    while b<=n:
        if len(str(b))==2:
            cnt+=1
            j+=1
            b=int(b_f+'0'*j+b_l)
            continue

        elif len(str(n))>j+2:
            cnt+=10*j
            j+=1
            b=int(b_f+'0'*j+b_l)
            continue

        elif len(str(n))==j+2:
            cnt+=(n-b)//10+1
            j+=1
            b=int(b_f+'0'*j+b_l)
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = (n // 10) ** 2 + 8
if str(n % 10) <= str(n)[0]:
  ans += 1
for i in range(1, n % 10 + 1):
  ans += 10 ** (len(str(n)) - 1) * 2

Submission status: Wrong Answer

Solution code:
from sys import stdin

def calc(N):
    result = {}
    for i in range(10):
        result[str(i)] = 0

    for i in range(N):
        if (str(i)[0] == str(i)[-1]):
            result[str(i)[0]] += 1
    for k in result:
        result[k] = result[k] * (result[k] - 1)
    return result

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    count = 0
    add_nums = calc(N)
    print(add_nums)
    for i in range(N):
        # 自身の逆転は1つ
        if (int(str(i)[::-1])) <= N and (not str(i)[-1] == '0'):
            count += 1
        if (str(i)[0] == str(i)[-1]) and (len(str(i)) > 1):
            count += add_nums[str(i)[0]]
    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
n_l = len(str(N))
n_first = int(str(N)[0])
n_end = int(str(N)[-1])


c = 0

for i in range(1,N+1):#Aを基準に
  if i % 10 == 0:
    continue
  else:
    first = int(str(i)[0])
    end = int(str(i)[-1])
    now_l = len(str(i))
    if n_l == 1:
      if now_l == 1:
        if N >= end:
          c += 1
      continue
    elif n_l == 2:
      if first==end:
        c += 1
        if N >= int(str(end)+str(first)):
          c += 1
      elif now_l == 2:
        if N >= int(str(end)+str(first)):
          c += 1
      continue
    elif n_l == 3:
      l = 1
      n_mid = int(str(N)[1:-1])
      if first == end:
        c += 2
      else:
        c += 1
      if n_first > end:
        c += 10
      elif n_first < end:
        pass
      else:
        if n_end >= first:
          c += n_mid
        else:
          pass
    else:#Nが4けた以上
      n_mid = int(str(N)[1:-1])
      l = n_l-2#間に入りうる桁数
      if first == end:
        c += 2
      else:
        c += 1
      if n_first > end:#最終けたまでOK
        for j in range(1,l+1):
          c += 10**j
      elif n_first < end:#最終けたはだめ
        for j in range(1,l):
          c += 10**j
      else:#最終けたは要注意
        for j in range(1,l):
          c += 10**j
        if n_end >= first:#最終けたまでOK
          c += 10**l
        else:#最終けたはダメ
          c += n_mid
    
print(c)

Submission status: Wrong Answer

Solution code:
import math
import sys
N=int(input())
ans=0

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

ans += (N//10)*3+9
for i in range(N//10):
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
total = 0
for i in [idx+1 for idx in range(N)]:
  a = int(str(i)[0])
  b = int(str(i)[-1])
  if b != 0:
    if a == b:
      if N < 10:
        if a <= N:
          total += 1
      elif N < 100:
        total += 1
        if a*10+a <= N:
          total += 1
      elif N < 1000:
        total += 1
        total += 1
        if a*100+90+a <= N:
          total += 10
        elif a*100+a >= N:
          if N%10 < a:
            total += int(str(N)[1]) - 1
          else:
            total += int(str(N)[1])
      elif N < 10000:
        total += 1
        total += 1
        total += 10
        if a*1000+990+a <= N:
          total += 100
        elif a*1000+a >= N:
          if N%10 < a:
            total += int(str(N)[1])*10+int(str(N)[2])-1
          else:
            total += int(str(N)[1])*10+int(str(N)[2])
      elif N < 100000:
        total += 1
        total += 1
        total += 10
        total += 100
        if a*10000+9990+a <= N:
          total += 1000
        elif a*10000+a >= N:
          if N%10 < a:
            total += int(str(N)[1])*100+int(str(N)[2])*10+int(str(N)[3])-1
          else:
            total += int(str(N)[1])*100+int(str(N)[2])*10+int(str(N)[3])
      elif N < 1000000:
        total += 1
        total += 1
        total += 10
        total += 100
        total += 1000
        if a*100000+99990+a <= N:
          total += 10000
        elif a*100000+a >= N:
          if N%10 < a:
            total += int(str(N)[1])*1000+int(str(N)[2])*100+int(str(N)[3])*10+int(str(N)[4])-1
          else:
            total += int(str(N)[1])*1000+int(str(N)[2])*100+int(str(N)[3])*10+int(str(N)[4])
    else:
      if N < 100:
        if b*10+a <= N:
          if N%10 < a:
            total += int(str(N)[1]) - 1
          else:
            total += int(str(N)[1])
      elif N < 1000:
        total += 1
        if b*100+90+a <= N:
          total += 10
        elif b*100+a >= N:
          if N%10 < a:
            total += int(str(N)[1])*10+int(str(N)[2])-1
          else:
            total += int(str(N)[1])*10+int(str(N)[2])
      elif N < 10000:
        total += 1
        total += 10
        if b*1000+990+a <= N:
          total += 100
        elif b*1000+a >= N:
          if N%10 < a:
            total += int(str(N)[1])*10+int(str(N)[2])-1
          else:
            total += int(str(N)[1])*10+int(str(N)[2])
      elif N < 100000:
        total += 1
        total += 10
        total += 100
        if b*10000+9990+a <= N:
          total += 1000
        elif b*10000+a >= N:
          if N%10 < a:
            total += int(str(N)[1])*100+int(str(N)[2])*10+int(str(N)[3])-1
          else:
            total += int(str(N)[1])*100+int(str(N)[2])*10+int(str(N)[3])
      elif N < 1000000:
        total += 1
        total += 10
        total += 100
        total += 1000
        if b*100000+99990+a <= N:
          total += 10000
        elif b*100000+a >= N:
          total += int(str(N)[1])*1000+int(str(N)[2])*100+int(str(N)[3])*10+int(str(N)[4])
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())

numbers = [[0 for i in range(10)] for i in range(10)]
for i in range(1, 10):
    for j in range(10):
        if i > N:
            continue
        tmp = 0
        if i == j:
            tmp += 1
        if i * 10 + j <= N:
            tmp += 1
        i_now = 100
        nine = 90
        nine_now = 10
        while i*i_now + nine + j <= N:
            tmp += nine_now
            i_now *= 10
            nine_now *= 10
            nine += 9 * nine_now

        if i*i_now <= N // i_now * i_now:
            if j <= N%10:
                tmp += (N%i_now)//10
            else:
                tmp += (N%i_now)//10 - (j-2)
        numbers[i][j] = tmp
ans = 0
for i in range(10):
    for j in range(10):
        ans += numbers[i][j]*numbers[j][i]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def countdigit(n):
    for i in range(7):
        if n / 10**i >= 1 :
            pass
        else:
            dig = i
            break
    return(dig)

def casepat(d):
    if d == 0:
        return(0)
    elif d == 1:
        return(1)
    elif d == 2:
        return(1)
    else:
        return(10**(d-2))

digit = countdigit(N)
d = digit - 1

# print(digit,d)

cdic = {}
if d == 0:
    for i in range(1,10):
        for j in range(1,10):
            cdic[str(i)+"-"+str(j)] = 0
elif d == 1:
    for i in range(1,10):
        for j in range(1,10):
            if i == j:
                cdic[str(i)+"-"+str(j)] = 1
            else:
                cdic[str(i)+"-"+str(j)] = 0
elif d == 2:
    for i in range(1,10):
        for j in range(1,10):
            if i == j:
                cdic[str(i)+"-"+str(j)] = 2
            else:
                cdic[str(i)+"-"+str(j)] = 1
else:
    for i in range(1,10):
        for j in range(1,10):
            if i == j:
                cdic[str(i)+"-"+str(j)] = casepat(d)+2
            else:
                cdic[str(i)+"-"+str(j)] = casepat(d)+1
               

# print("cdic:",cdic)
s = 10**d
for i in range(s,N+1):
    stri = str(i)
    af = stri[0]
    al = stri[-1]
    if af != "0" and al != "0":
        cdic[str(af)+"-"+str(al)] += 1
  

# print("----")
# print("cdic:",cdic)

allcount = 0
for i in range(1,10):
    for j in range(1,10):
        allcount += cdic[str(i)+"-"+str(j)] * cdic[str(j)+"-"+str(i)]

print(allcount)

Submission status: Wrong Answer

Solution code:
n = int(input())
K = len(str(n))
C = str(n)
C1 = int(C[0])
Cn = int(C[-1])

# nと同じ桁のBの数
base2 = 0
if K > 3:
    base2 = int(C[1:-1])

# nより桁が小さい3桁以上Bの数
base = 0
for i in range(1, K-2):
    base += 10 ** i


ans = 0
for i in range(1, n + 1):
    c = str(i)
    if c[-1] == "0":
        continue
    if c[0] == c[-1]:
        if i <= n:
            ans += 1
    if int(c[-1] + c[0]) <= n:
        ans += 1
    ans += base
    if int(c[-1]) == C1 and int(c[0]) <= Cn:
        ans += base2
    if int(c[-1]) <=  C1 and int(c[0]) <= Cn:
        ans += 10 ** (K-2)

print(ans)

Submission status: Wrong Answer

Solution code:
# D - Handstand 2
N = int(input())
count = 0
tmp = 0
DP = []

if N < 10:
    print(N)
    exit()
else:
    n = str(N)
    for i in range(9, N + 1):
        I = str(i)
        for j in range(int(I[-1]),N+1,10):
            J = str(j)
            if J[-1] == I[0] and J[0] == I[-1]:
                count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=[0,1]
for i in range(1,n):
    alist=list(str(i+1))
    a=int(alist[0])
    b=(i+1)%10
    h=len(alist)
    
    if b>0:
        if h>2:
            if a>b:
                kotae=int(((1-pow(10,h-1))/(-9))*2)
            else:
                kotae=int(((1-pow(10,h-2))/(-9))*2)
                if a==b:
                    kotae+=(((i+1)%(pow(10,h-1)))-b)//10
                    kotae=int(1+(kotae-1)*2)
        elif h==1:
            kotae=1
        elif h==2:
            if a>b:
                kotae=int(((1-pow(10,h-1))/(-9))*2)
            elif a<b:
                kotae=0
            else:
                kotae=3
    else:
        kotae=0
    ans.append(kotae+ans[-1])

print(ans[n])

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
c = 0
rng = [1,2,3,4,5,6,7,8,9]
p = list(itertools.product(rng,repeat=2))
for l,r in p:
  target = [i for i in range(1,n+1) if int(str(i)[-1])==l and int(str(i)[0])==r and int(str(i)[::-1])<=n]
  if l==r:
    c += len(target)**2
  else:
    c += len(target)
print(c)

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:
N = int(input())
nstr = str(N)
nlen = len(nstr)
cnt = 0
Nmiddle = 1
for k in range(1,nlen-1):
  Nmiddle *= int(nstr[k])
if nlen == 2:
  Nmiddle = 0
for i in range(1, N+1):
  j = str(i)
  if j[0] == j[-1]:
    cnt += 1
  if nlen - 3 > 0:
    cnt += ((10**(nlen - 2) - 1)/9)
  if N >= int(j[-1] + ('9' * (nlen - 2)) + j[0]):
    cnt += 10**(nlen - 2)
  elif nstr[0] < j[0]:
    continue
  elif nstr[0] == j[0]:
    if nstr[-1] < j[-1]:
      cnt += Nmiddle - 1
    else:
      cnt += Nmiddle
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
length = len(str(n))
nn = str(n)
x = int(nn[0])
y = int(nn[-1])
z = 0
if len(nn) > 2:
    z = int(nn[1:-1])

ans = 0
pa = ans

for i in range(1, n + 1):
    pa = ans
    if i % 10 == 0:
        continue
    
    s = str(i)
    a = int(s[0])
    b = int(s[-1])

    for j in range(length - 1):
        if j == 0:
            if a == b and i < n:
                ans += 1
        elif j == 1:
            if b*10+a < n:
                ans += 1
                # print(int(b+a))
        else:
             ans += 10 ** (j - 1)

    if b < x:
        ans += 1
        ans += z
        
    elif b == x:
        ans += z
        if a < y:
            ans += 1

    # if pa != ans:
    #     print(i, ans-pa)


print(ans)

Submission status: Wrong Answer

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

def count(i):
    h = str(i)
    s = lambda j, k, l: int('{}{}{}'.format(j, k, j))
    if len(set(h)) == 1:
        h = h[0]
        c = 1
        s = h * 1
        while int(s) <= n:
            c += 1
            s = h * c
        return c - 1
    if h[-1] == '0' or s(h[-1], '', h[0]) > n:
        return 0
    d = 1
    while s(h[-1], '0' * d, h[0]) <= n:
        d += 1
    c = 1 + (9 * (d - 1))
    for i in range(10):
        if s(h[-1], i, h[0]) > n:
            break
    return i + c

s = 0
for i in range(1, n+1):
    c = count(i)
    # print(f'{i} = {c}')
    s += c
print(s)

Submission status: Wrong Answer

Solution code:
import sys


# n=2020
def count_i_j(begin, end, limit):
    # print('begin:', begin, 'end:', end, 'limit:', limit)
    tmp = limit
    digits = 0
    while tmp:
        tmp //= 10
        digits += 1

    # TODO: 1 digit

    if digits == 1:
        if begin == end:
            return 1
        else:
            return 0

    ans = 0
    if begin == end:
        ans += 1
    for dig in range(1, digits):
        # digth digit: begin, last digit: end
        num_low = begin * (10 ** dig) + end
        if num_low > limit:
            continue
        nines = 0
        for i in range(dig-1):
            nines += 9 * 10 ** i
        # print('nines:', nines)
        num_hi = num_low + nines
        # print('num_low:', num_low)
        # print('num_hi:', num_hi)
        ans += min(limit, num_hi) - num_low + 1
    # print('ans:', ans)
    return ans


def main():
    n = int(sys.stdin.readline().strip())
    # n = 25

    # 11
    # 12 21
    # 13 31
    # ...
    # 19 91

    # 22 22
    # 23 32
    # ...
    # 29 92

    # n = 100
    # 1-1: 2 => 2 ** 2
    # 1-2: 1
    # 1-3: 2
    # ...
    # 2-1: 1
    # 3-1: 1
    # ...
    # 1-2 and 2-1: 1 * 1 => 1


    # n = 2020
    # 1-1: 1 + 1 + 10 + 10 * 10 => 112
    # 1-2: 1 + 1 * 10 + (10 ** 2) * 1 => 222
    # 2-1: 1 + 2 * 10 + 2 [2011, 2001] => 23
    # => 222 * 23

    # 1-1 to 9-9: 81

    # n = 25
    # 1-1: 1
    # 1-2: 1
    # 2-1: 1
    # 1-3: 1
    # 1-4: 1
    # ...
    # 1-9: 1
    # 2-2: 2
    # 2-3: 1
    # 2-4: 1
    # 2-5: 1
    # 1 + 1 * 1 + 1 * 0 + ...

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

    for i in range(1, 10):
        for j in range(1, 10):
            table[i][j] = count_i_j(i, j, n)

    # for row in table:
    #     print(row)

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


if __name__ == '__main__':
    main()
    # count_i_j(1, 3, 25)

Submission status: Wrong Answer

Solution code:
N = int(input())
n_l = len(str(N))
n_first = int(str(N)[0])
n_end = int(str(N)[-1])


c = 0

for i in range(1,N+1):#Aを基準に
  if i % 10 == 0:
    continue
  else:
    first = int(str(i)[0])
    end = int(str(i)[-1])
    now_l = len(str(i))
    if n_l == 1:
      if now_l == 1:
        if N >= end:
          c += 1
      continue
    elif n_l == 2:
      if first==end:
        c += 1
        if N >= int(str(end)+str(first)):
          c += 1
      elif now_l == 2:
        if N >= int(str(end)+str(first)):
          c += 1
      continue
    elif n_l == 3:
      l = 1
      n_mid = int(str(N)[1:-1])
      if first == end:
        c += 2
      else:
        c += 1
      if n_first > end:
        c += 10
      elif n_first < end:
        pass
      else:
        if n_end >= first:
          c += n_mid
        else:
          pass
    else:#Nが4けた以上
      n_mid = int(str(N)[1:-1])
      l = n_l-2#間に入りうる桁数
      if first == end:
        c += 2
      else:
        c += 1
      if n_first > end:#最終けたまでOK
        for j in range(1,l+1):
          c += 10**j
      elif n_first < end:#最終けたはだめ
        for j in range(1,l):
          c += 10**j
      else:#最終けたは要注意
        for j in range(1,l):
          c += 10**j
        if n_end >= first:#最終けたまでOK
          c += n_mid
        else:#最終けたはダメ
          c += n_mid -1
    
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    count = 0
    for i in range(n):
        target_num = n - i # 逆から
        str_target_num = str(target_num)

        if str_target_num[-1] == '0':
            continue
        else:
            if str_target_num[0] < str_target_num[-1]:
                for j in range(len(str_target_num)):
                    if 0 < j < len(str_target_num) - 1:
                        count = count + 2 * 10**(j-1)
                        #print("a:{0},{1}".format(target_num, 10**(j-1)))

            elif str_target_num[0] > str_target_num[-1]:
                for j in range(len(str_target_num)):
                    if 0 < j:
                        count = count + 2 * 10**(j-1)
                        #print("b:{0},{1}".format(target_num, 10**(j-1)))

            elif str_target_num[0] == str_target_num[-1]:
                for j in range(len(str_target_num)):
                    if j == 0 or j == 1:
                        if j == len(str_target_num) - 1:
                            count = count + 1 # 1けた
                        else:
                            count = count + 2
                        #print("c:{0},{1}".format(target_num, 1))
                    elif 1 < j < len(str_target_num) - 1:
                        count = count + 2 * 10**(j-1)
                        #print("d:{0},{1}".format(target_num, 10**(j-1)))
                    elif j == len(str_target_num) - 1:
                        if len(str_target_num) > 2:
                            count = count + int(str_target_num[1:-1]) + int(str_target_num[1:-1]) - 1
                            #print("e:{0},{1}".format(target_num, int(str_target_num[1:-1])))

    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
if N <= 10:
    print(1)
else:
    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 = 1
      for k in range(1,6):
        if i * 10 ** k + i < N:
           c += 10 ** (k - 1)
      ret += c * c
    print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
n_l = len(str(N))
n_first = int(str(N)[0])
n_end = int(str(N)[-1])


c = 0

for i in range(1,N+1):#Aを基準に
  if i % 10 == 0:
    continue
  else:
    first = int(str(i)[0])
    end = int(str(i)[-1])
    now_l = len(str(i))
    if n_l == 1:
      if now_l == 1:
        if N >= end:
          c += 1
      continue
    elif n_l == 2:
      if first==end:
        c += 1
        if N >= int(str(end)+str(first)):
          c += 1
      elif now_l == 2:
        if N >= int(str(end)+str(first)):
          c += 1
      continue
    elif n_l == 3:
      l = 1
      n_mid = int(str(N)[1:-1])
      if first == end:
        c += 2
      else:
        c += 1
      if n_first > end:
        c += 10
      elif n_first < end:
        pass
      else:
        if n_end >= first:
          c += n_mid
        else:
          pass
    else:#Nが4けた以上
      n_mid = int(str(N)[1:-1])
      l = n_l-2#間に入りうる桁数
      if first == end:
        c += 2
      else:
        c += 1
      if n_first > end:#最終けたまでOK
        for j in range(1,l+1):
          c += 10**j
      elif n_first < end:#最終けたはだめ
        for j in range(1,l):
          c += 10**j
      else:#最終けたは要注意
        for j in range(1,l):
          c += 10**j
        if n_end >= first:#最終けたまでOK
          c += n_mid
        else:#最終けたはダメ
          c += n_mid
    
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())

cnt=0
for i in range(1,(n+1)):
    if i%10==0:continue
    j=0
    a=b=str(i)

    if int(a)<10:
        a_f=a
        a_l=a
    else:
        a_f=a[0]
        a_l=a[-1]
    b_f=a_l
    b_l=a_f
    if a_f==a_l:
        b=a_f
    else:
        b=int(b_f+b_l)
    if len(str(b))==1:
        cnt+=1
        b=int(b+b)
    
    while b<=n:
        if len(str(b))==2:
            cnt+=1
            j+=1
            b=int(b_f+'0'*j+b_l)
            continue

        elif len(str(n))>j+2:
            cnt+=10*j
            j+=1
            b=int(b_f+'0'*j+b_l)
            continue

        elif len(str(n))==j+2:
            cnt+=(n-b)//10+1
            j+=1
            b=int(b_f+'0'*j+b_l)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
def countab(a,b,n):
    cnt=0
    for i in range(3,len(str(n))):
      cnt+=10**(i-2)
    chk=a*10**(len(str(n))-1)+b
    chke=((a+1)*10**(len(str(n))-2)-1)*10+b
    if chk<=n:
      for j in range(chk,chke+1):
        if j>n:
          break
        else:
          cnt+=1
    return cnt
ans=0
if len(str(n))==1:
  ans=n*n
elif len(str(n))==2:
  ans+=9
  xm=int(n//10)
  ym=int(n-xm*10)
  for x  in range(1,xm+1):
    if x*10+x>n:
      continue
    else:
      ans+=2
  for x in range(1,xm+1):
    for y in range(1,ym+1):
      if y*10+x>n:
        continue
      else:
        ans+=1
else:
  ans+=108
  for x in range(1,10):
    for y in range(1,10):
        ans+=countab(x,y,n)*countab(y,x,n)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
print((N // 10) ** 2 + N % 5 + 8)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 0

for i in range(1, n + 1):
    if i <= 9:
        ans += 1
    elif i <= 99:
        if i % 10 == 0:
            continue
        elif i // 10 == i % 10:
            ans += 3
        elif i // 10 > i % 10:
            ans += 2
    elif i <= 999:
        if i % 10 == 0:
            continue
        elif i // 10 == i % 10:
            ans += 5 + 2 * ((i % 100) // 10)
        elif i // 10 < i % 10:
            ans += 2
        elif i // 10 > i % 10:
            ans += 20
    elif i <= 9999:
        if i % 10 == 0:
            continue
        elif i // 10 == i % 10:
            ans += 15 + 2 * ((i % 1000) // 10)
        elif i // 10 < i % 10:
            ans += 30

print(ans)

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 int(str(N)[-1]) == 0:
        return N_m
    if t >= int(str(N)[-1]):
        return (N_m + 1)
    return N_m
print(main())

Submission status: Wrong Answer

Solution code:
n = int(input()) + 1

count = 0
l = list()
for i in range(1, n):
    for j in range(1, n, 10):
        si = str(i)
        sj = str(j)
        if si[len(si)-1] == sj[0] and si[0] == sj[len(sj)-1]:
            count += 1
            l.append((si, sj))

print(count)