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:
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
print(ans_dict)
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]*2
        ans_dict[key_s] = 0
print(ans)

Submission status: Wrong Answer

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


ans = 0

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
K = len(str(N))
MS = int(str(N)[0])
ML = int(str(N)[-1])
res = 0

for i in range(1, N+1):
    AS = int(str(i)[0])
    AL = int(str(i)[-1])

    if AL == 0:
        continue

    for k in range(1, K+1):
        if k == 1:
            if AS == AL and AS <= N:
                res += 1
            continue
        if k == 2:
            if int(str(AL) + str(AS)) <= N:
                res += 1
            continue
        if k < K:
            res += 10 ** (k - 2)
            continue
        if k == K:
            if AL > MS:
                continue
            if AL < MS:
                res += 10 ** (k - 2)
                continue
            if AL == MS:
                if AS < ML:
                    res += int(str(N)[1:]) // 10
                    if int(str(N)[1:]) // 10 == 0:
                        if AS <= int(str(N)[1:]):
                            res += 1
                    continue
                else:
                    if int(str(N)[1:]) >= AS:
                        res += (int(str(N)[1:]) + 9) // 10
                    continue


print(res)

Submission status: Wrong Answer

Solution code:
N=input()

ans=0
for start in range(9,0,-1):
    for end in range(9,0,-1):
        t=0
        if start==end:
            n=start
            if n<=N: t+=1

        n=start*10**1+end
        if n<=N: t+=1

        for i in range(1,10):
            n=start*10**2+i*10**1+end
            if n<=N: t+=1

        for i in range(1,10):
            for ii in range(1,10):
                n=start*10**3+i*10**2+ii*10**1+end
                if n<=N: t+=1

        for i in range(1,10):
            for ii in range(1,10):
                for iii in range(1,10):
                        n=start*10**4+i*10**3+ii*10**2+iii*10**1+end
                        if n<=N: t+=1


        for i in range(1,10):
            for ii in range(1,10):
                for iii in range(1,10):
                    for iiii in range(1,10):
                        n=start*10**5+i*10**4+ii*10**3+iii*10**2+iiii*10**1+end
                        if n<=N: t+=1
        ans+=t*(t-1)/2

print ans

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

limit_by_N = max(int(math.log10(1000))-2,0)

strN = str(N)
N_tail = int(strN[-1])
N_head = int(strN[0])

if len(strN)>=3:
  N_center = int(strN[1:-1])

ans = 0

for i in range(N+1):
  if i%10 != 0:
    
    temp_ans = 0
    stri = str(i)
    a_tail = int(stri[-1])
    a_head = int(stri[0])
    
    #print(i,a_head,a_tail)
    
    if a_tail == a_head and a_head<=N:
      temp_ans += 1
      #print("#")
      
    if a_tail*10 + a_head <= N:
      temp_ans += 1
      #print("$")
      #print(i,a_tail*10 + a_head)
    
    if N>=100:
      for i in range(1,limit_by_N):
        temp_ans += 10**i #桁が間に合うまでは全入れOK
      
      #Nと桁が一致しているとき
      if N_head > a_tail:
        temp_ans += 10**(limit_by_N + 1)
      elif N_head == a_tail:
        if N_tail < a_head and N_center!=0:
          temp_ans += N_center - 1
        else:
          temp_ans += N_center
          
    #print(temp_ans)
    ans += temp_ans
#print("")
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
sento = int(str(n)[0])
saigo = int(str(n)[-1])
keta = len(str(n))

for i in range(1, keta):
    if i == 1:
        ans += 9
    elif i == 2:
        ans += 2 * 9
    else:
        ans += int('1'*(i-2) + '2')


    
if sento == saigo:
    for j in range(1, saigo):
        ans += int('1'*(i-2) + '2')
    ans += (keta - 2) * 10
elif sento >= saigo:
    for j in range(1, saigo):
        ans += int('1'*(i-2) + '2')
else:
    for j in range(1, saigo):
        ans += int('1'*(i-2) + '2')
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
N=int(input())
num=[1,2,3,4,5,6,7,8,9]
dig=int(math.log10(N))
case=np.ones((9,9))
for h in num:
    for t in num:
        base=h*10^dig+t
        ls=np.arange(base,base+10^dig-9)
        ls=ls[ls<=N]
        case[h-1,t-1]=len(ls)
ans=np.sum(np.dot(case,case.T))

print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
print N

ans=0
for start in range(9,0,-1):
    for end in range(9,0,-1):
        t=0
        if start==end:
            n=start
            if n<=N: t+=1

        n=start*10**1+end
        if n<=N: t+=1

        for i in range(1,10):
            n=start*10**2+i*10**1+end
            if n<=N: t+=1

        for i in range(1,10):
            for ii in range(1,10):
                n=start*10**3+i*10**2+ii*10**1+end
                if n<=N: t+=1

        for i in range(1,10):
            for ii in range(1,10):
                for iii in range(1,10):
                        n=start*10**4+i*10**3+ii*10**2+iii*10**1+end
                        if n<=N: t+=1


        for i in range(1,10):
            for ii in range(1,10):
                for iii in range(1,10):
                    for iiii in range(1,10):
                        n=start*10**5+i*10**4+ii*10**3+iii*10**2+iiii*10**1+end
                        if n<=N: t+=1
        ans+=t*(t-1)/2

print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
a = 10
b = 0
while (n // a != 0):
  a = a * 10
  b += 1
c = (n*10) //  a
d = n % 10
print(c,d)
if (b == 0):
  print(n)
elif (b == 1):
  m = 9
  if(d == 0):
    c += -1
    d = 10
  if(c > d):
    m += (c-2)*(c-1) +(2*d)
    m += 3*(c-1)
    print(m)
  else:
    m += c*(c-1)
    m += 3*c
    print(m)
elif(b == 2):
  m = 108
  e = (n % 100) //10
  if(c > d):
    m += 5*((c-1) * 10 + e)
    m += 2*(8*((c-1) * 10 + e)) + 2*d
    print(m)
  else:
    m += 5*((c-1) * 10 + e +1)
    m += 2*(8*((c-1) * 10 + e)) + 2*(d-1)
    print(m)
elif(b == 3):
  m = 1998
  e = (n % 100) //10
  if(c > d):
    m += 25*((c-1) * 10 + e)
    m += 22*(8*((c-1) * 10 + e)) + 22*d
    print(m)
  else:
    m += 25*((c-1) * 10 + e +1)
    m += 22*(8*((c-1) * 10 + e)) + 22*(d-1)
    print(m)
elif(b == 4):
  m = 20088
  e = (n % 100) //10
  if(c > d):
    m += 225*((c-1) * 10 + e)
    m += 225*(8*((c-1) * 10 + e)) + 225*d
    print(m)
  else:
    m += 225*((c-1) * 10 + e +1)
    m += 225*(8*((c-1) * 10 + e)) + 225*(d-1)
    print(m)
elif(b == 5):
  m = 202338
  e = (n % 100) //10
  if(c > d):
    m += 2225*((c-1) * 10 + e)
    m += 2222*(8*((c-1) * 10 + e)) + 2225*d
    print(m)
  else:
    m += 2225*((c-1) * 10 + e +1)
    m += 2225*(8*((c-1) * 10 + e)) + 2225*(d-1)
    print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}
for i in range(11, 100):
    f, s = divmod(i, 10)
    tmp = 0
    for j in range(1, n):
        if str(j)[0]==str(f) and str(j)[-1]==str(s): tmp +=1
    dic[i] = tmp

print(dic)
ans = 0
for i in range(1, int(n)+1):
    s = str(i)
    if s[-1]=="0": continue
    ans += dic[int(s[-1]+s[0])]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(n)
l = len(s)
k = min(int(s[0]),int(s[-1]))
if l == 1:
  print(n)
else:
  ans = (k*(k-1)//2 + k) * (9**(l-1)-1)//8
  ans += (n*(n-1)//2 - k*(k-1)//2 + 9-k) * (9**(l-2)-1)//8
  print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
S = len(N)-2
Z = int(N[0]+N[-1])
X = [1,2,3,4,5,6,7,8,9]
Y = [1,2,3,4,5,6,7,8,9]
cnt = 0
if int(N) <= 9:
    print(N)
else:
    for i in X:
        for j in Y:
            if S >=1 :
                A = int(str(1)*S)
                B = int(str(1)*S)
            else:
                A = 0
                B = 0
            if i == j:
                A += 1
                B += 1
            temp1 = int(N)- (i*10**(S+1)+j)
            if temp1 > 0:
                A += min(-(-temp1//10),10**S)
            temp2 = int(N)- (j*10**(S+1)+i)
            if temp2 > 0:
                B += min(-(-temp2//10),10**S)
            cnt += A*B
    print(cnt)

Submission status: Wrong Answer

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

    for i in range(1, N + 1):
        tempAns = 1
        sentou = str(i)[0]
        saigo = str(i)[-1]
        
        if isRep(i, i):
            tempAns += 1
        
        for i in range(1, 10):
            if int(sentou + str(i) + saigo) <= N:
                tempAns += 1
            else:
                break
        
        for i in range(1, 100):
            if int(sentou + str(i).zfill(2) + saigo) <= N:
                tempAns += 1
            else:
                break
        
        for i in range(1, 1000):
            if int(sentou + str(i).zfill(3) + saigo) <= N:
                tempAns += 1
            else:
                break


    
    print(ans)

def isRep(i, j):
    sentoui = str(i)[0]
    saigoi = str(i)[-1]
    sentouj = str(j)[0]
    saigoj = str(j)[-1]

    if sentoui == saigoj and saigoi == sentouj:
        return True
    else:
        return False

mainFunc()

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
b = 0
for i in range (1,N+1,1):
    stri = str(i)
    rstri = stri[::-1]
    if i % 10 == 0 or int(rstri) > N:
        continue
    if stri[0] == rstri[-1] and stri != rstri:
        count += 1

    elif stri == rstri:

        for i in stri:
            if i != rstri[0]:
                b = 1
                break
        if b == 0:
            count += len(stri)**2 - (len(stri) - 1)**2
    b = 0
print(count)

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 - (N%10)
        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:
import sys
from scipy.misc import comb
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    
    ans = [0] * 100
    for i in range(n//2 + 1):
        if i < 10:
            ans[int(str(i) * 2)] += 1
            continue
        s = str(i)
        if s[0] != s[-1]:
            ans[int(s[0] + s[-1])] += 2
        else:
            ans[int(s[0] + s[-1])] += 1

    sum = 0
    for i in range(1, 10):
        for j in range(i, 10):
            data = ans[i * 10 + j]
            if data >= 2:
                sum += comb(data, 2, exact=True)
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
Len = len(str(N))

ans_AA = 0
ans_AB = 0
for A in range(1,N+1):
    Aflont = str(A)[0]
    Aend = str(A)[-1]

    if Aend == "0":
        continue

    if len(str(A)) == 1:
        ans_AA += 1
        continue

    if len(str(A)) == 2:
        if Aend == Aflont:
            ans_AA += 3
            continue
        if int(Aend + Aflont) <= N:
                ans_AA += 1
        continue

    ans_AA += 2
    #BA

    if Aend == Aflont:
        ans_AA += 2
    # A

    for y in range(2,9):
        if Len - y == 0:
            break
        
        for x in reversed(range(0,int("9"*(Len-y))+1)):

            if int(Aend + str(x) + Aflont) <= N :
                ans_AA += x+1
                flag = 1
                break

    

print(ans_AA)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
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 = int(input())
st_N = str(N)
l_N = len(st_N)
count = 0
tmp = 0
keta = len(str(N))
N_mae = int(st_N[0])
N_usiro = int(st_N[l_N - 1])
N_naka = ""
if l_N > 2:
    for k in range (l_N - 2):
        N_naka = N_naka + st_N[k+1]
    N_naka = int(N_naka)
else:
    N_naka = ""

for i in range(N):
    A = str(i)
    A_mae = int(A[0])
    A_usiro = int(A[len(A)-1])
    B_mae = A_usiro
    B_usiro = A_mae
    if A_usiro == 0:
        count += 0

    elif A_mae == A_usiro:
        for j in range(6):
            tmp += A_mae * (10 ** j)
            if tmp <= N:
                count += 1
            else:
                tmp = 0
                break
        tmp = 0
    else:
        if B_mae == N_mae:
            if B_usiro <= N_usiro:
                if N_naka == "":
                    count += 1
                else:
                    count += N_naka + 2
            elif B_usiro > N_usiro:
                count += N_naka + 1
        elif B_mae < N_mae:
            if N_naka == "":
                count += 1
            else:
                count += N_naka + 2
        else:
            if keta == 3:
                count += 1
            elif keta > 3:
                count += (10 ** (keta - 3)) + 1
if count == 0:
    print(1)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=0
for n in range(N):
  if n<10:
    c+=1
  elif n>=10:
    l=len(str(n))
    fs=str(n)[0]
    fe=str(n)[-1]
    if fs=="0" or fe=="0":
      p=0
    elif fs==fe:
      p=(l-1)*2+1
    elif int(fs)<int(fe):
      p=(l-2)*2
    else:
      p=(l-1)*2
    c+=p
print(c)

Submission status: Wrong Answer

Solution code:
# WIP

N = int(input())

result = 0
for i in range(1, N+1):
    s = str(i)
    digit = len(s)

    # 1桁目が0のときはスキップ
    if int(s[-1]) == 0:
        continue

    # 1桁のときはペアが1つ
    if digit == 1:
        result += 1
    # 2桁以上
    else:
        f = int(s[0])
        l = int(s[-1])
        if l > f:
            continue
        elif l == f:
            result += 2
            for k in range(2, digit+1):
                result += pow(10, k-2)
                if pow(10, digit - 1) * f + l + (pow(10, digit - 1) - 10) > N:
                    result -= pow(10, digit - 2)
                    result += int((str(N))[1:-1]) + 1
        elif l < f:
            for k in range(2, digit+1):
                result += 2 * pow(10, k-2)
        else:
            raise Exception

    # print('debug: i: {}, result: {}'.format(i, result))

print(result)

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
    for i in range(10):
        if s(h[-1], i, h[0]) > n:
            break
    return 11 * (d - 1) + 1

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:
N = int(input())
K = len(str(N))
MS = int(str(N)[0])
ML = int(str(N)[-1])
res = 0

for i in range(1, N+1):
    AS = int(str(i)[0])
    AL = int(str(i)[-1])

    if AL == 0:
        continue

    for k in range(1, K+1):
        if k == 1:
            if AS == AL and AS <= N:
                res += 1
            continue
        if k == 2:
            if int(str(AL) + str(AS)) <= N:
                res += 1
            continue
        if k < K:
            res += 10 ** (k - 2)
            continue
        if k == K:
            if AL > MS:
                continue
            if AL < MS:
                res += 10 ** (k - 2)
                continue
            if AL == MS:
                if AS < ML:
                    if AS <= int(str(N)[1:]):
                        res += 1
                    res += int(str(N)[1:]) // 10
                    continue
                else:
                    if int(str(N)[1:]) >= AS:
                        res += (int(str(N)[1:]) + 9) // 10
                    continue


print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = 0
    def swap(n):
        m = [c for c in str(n)]
        if len(m) == 1:
            return n
        m[0], m[-1] = m[-1], m[0]
        return int(''.join(m))

    for a, b in product(range(0, 10), repeat=2):
        if a == 0 or b == 0:
            continue

        s = []
        n = a*10 + b
        s.append(n)
        if a == b:
            s.append(a)
        i = 0
        while True:
            n = a * (10**(len(str(i))+1))
            n += b
            n += i * 10
            if n > N:
                break
            s.append(n)
            i += 1
        s = list(filter(lambda x: swap(x) <= N and x <= N, s))
        t = len(s)
        # print(a, b, t, s)
        if a != b:
            ans += t * t
        else:
            ans += t * t
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
cnt = [[0] * 9 for _ in range(9)]
tmp = 0
for i in range(1, n + 1):
    one = str(i)
    two = list(str(i))
    two.reverse()
    two = ''.join(two)
    if one[-1] == '0':
        continue
    if one == two:
        tmp += 1
    cnt[int(one[0]) - 1][int(one[-1]) - 1] += 1
for i in range(9):
    for j in range(9):
        ans += cnt[j][i]
print(ans - tmp)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
d = int(np.log10(N) // 1) + 1
Nsento = N // (10 ** (d - 1))

counter = 0
for A in range(1, N+1):
    increment = 0
    Adigit = int(np.log10(A) // 1) + 1
    x = A // (10 ** (Adigit - 1))
    y = A % 10
    if y == 0:
        continue

    if d == 1:
        if x <= N: increment = 1
    elif d == 2:
        if x + 10 * y <= N: increment = 1
        if x == y: increment += 1
    else:
        if x == y: increment += 1
        increment += 1
        for k in range(2, d):
            if y < Nsento:
                increment += 10 ** (k - 1)
            elif y == Nsento:
                increment += (N - 10 ** (d - 1) * y)
    
    counter += increment

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
for i in range(1,N+1):
  a = str(i)[0]
  b = str(i)[-1]
  if a == b:
    ans += 1
  elif a > b and int(b+a)<N:
    ans += 2
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
for i in range(1, N+1):
    num = str(i)
    keta = len(num)
    l = num[-1*keta]
    r = num[-1]
    if r == "0":
        continue
    if r == l:
        #print("ichi::", i)
        cnt += 1
    if i >= int(r+l):
        #print("ju::", i, int(r+l))
        cnt += 2
    for j in range(3, keta+1):
        if j != keta:
            cnt += 2 * (10 ** (keta-2))
        else:
            if l > r:
                cnt += 2 * (10 ** (keta-2))
            elif l == r:
                cnt += 2 * (int(num[1:keta-1])+1)

print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
def base10(n):
    return [str(n)[i] for i in range(len(str(n)))]

def cond(a,b):
    a,b=str(a),str(b)
    return a[-1]==b[0] and a[0]==b[-1]
if __name__=='__main__':
    count=0
    for a in range(N):
        for b in range(N):
            sa=base10(a),base10(b)
            if cond(a,b):
                count+=1
    print(count)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
head_of_n = str(n)[0]
digit_n = len(str(n))

if 0 < n <= 10 :
    print(n)
    sys.exit()

count = 0

for i in range(1,n):
    #print(i, count)
    head = str(i)[0]
    tail = str(i)[len(str(i)) -1]

    if tail == "0":
        continue

    if head_of_n < tail:
        for j in range(digit_n - 2):
            #print("Y")
            count += 10**j
    elif head_of_n == tail:
        # for j in range(digit_n - 2):
        #     print("E")
        #     count += 10**j
        # if 10**(digit_n - 2) < 
        for j in range(10,n):
            if str(j)[0] == tail and str(j)[len(str(j)) -1] == head:
                count += 1
    else:
        for j in range(digit_n - 1):
            #print("N")
            count += 10**j

    if head == tail:
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

count = 0

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

Submission status: Wrong Answer

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

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


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

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def max_head_tail(N, h, t):
    N_str = str(N)
    N_digit = len(N_str)
    if int(N_str[0]) < h:
        # return int(str(h) + "9"*(N_digit-3) + str(t))
        return None
    elif int(N_str[0]) > h:
        return int(str(h) + "9"*(N_digit-2) + str(t))
    else:
        candidate = int(str(h) + N_str[1:N_digit-1] + str(t))
        if candidate > N:
            return None
        return candidate


# def main():
#     N = int(input())
#     N_digit = len(str(N))
#     cnt = 0

#     if N < 10:
#         return N

#     a_digit == 1
#     for a in range(1, 10):
#         lim = max_head_tail(N, a, a)

#         # b_digit = 1
#         cnt += 1

#         # b_digit = 2
#         cnt += 1

#         b_digit = 3
#         while True:


#     for a_digit in range(1, digit_lim + 1):
#         if a_digit == digit_lim:
#             "HOGEHOGE"


def main():
    N = int(input())
    N_digit = len(str(N))
    cnt = 0

    for A in range(1, N+1):
        # A = 203
        if A % 10 == 0:
            continue

        t, h = int(str(A)[0]), int(str(A)[-1])

        if h == t:
            for B_digit in range(1, N_digit+1):
                if B_digit <= 2 and int(str(h)*B_digit) <= N:
                    cnt += 1
                elif B_digit < N_digit:
                    cnt += 9 ** (B_digit-2)
                else:
                    lim = max_head_tail(N, h, t)
                    # print(lim)
                    if lim is not None:
                        cnt += int(str(lim)[1:N_digit-1]) + 1
        else:
            # h != t
            # A_digit = len(str(A))
            for B_digit in range(2, N_digit+1):
                if B_digit == 2 and 10*h + t <= N:
                    cnt += 1
                elif B_digit < N_digit:
                    cnt += 9 ** (B_digit-2)
                else:
                    lim = max_head_tail(N, h, t)
                    if lim is not None:
                        cnt += int(str(lim)[1:N_digit-1]) + 1
        # print("{}\t{}".format(A, cnt))
        # exit()

    return cnt


print(main())

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(N)
keta=1
temp=N
while temp//10>0:
  keta+=1
  temp//=10
print(keta)
ans=0
for i in range(1,N):
  n=str(i)
  a=n[0]
  b=n[-1]
  cur_keta=len(n)
  if cur_keta<keta:
    if a==b:
      ans+=10*max(cur_keta-2,0)
    else:
      ans+=10*max(cur_keta-2,0)-1
  else:
    if a<b:
      pass
    else:
      Si=S[1:-2]
      if len(Si)>0:
        ans+=int(Si)
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
N_ed = list(str(N))
N_dig = len(N_ed)

count = 0
count1,count2 = 0,0
#ある数について条件を満たす数が何個あるか吟味
for i in range(1,N+1):
  
  #if(i >= 2): print(i-1,count2-count1)
  
  count1 = count
  #ある数の最高位,最下位(ここだけ関係する→条件を満たすかはミラーで判定!!)
  n = str(i)
  n_low, n_top = int(n[0]),int(n[-1]) 
 
  #################################
  #ある数に対して条件を満たす数考える#
  #################################
  #最下位が0でないなら
  if(n_top != 0):
    #最初と最後 同じなら1ケタの数ok
    if(n_low == n_top): 
       count += 1
       
      
    #あいだに挟まる〇の数-1
    for j in range(N_dig-1):
        #今考えている数のケタ
        n_dig = j+2
        #ケタ数Nより少ないなら
        if(n_dig < N_dig):
           count += 10**j
        #ケタ数Nと一致なら
        else:   
         #先頭の比較
          #Nより先頭小さいなら
          if(n_top < int(N_ed[0])):
               count += 10**j
          #Nと先頭同じなら
          elif(n_top == int(N_ed[0])):
           
           #最下位小さいなら
           #print(n,n_top,n_low)
           #print(n_low,int(N_ed[-1]))
           if(n_low <= int(N_ed[-1])):
             #print('aaaaa')
             tmp = 1
             for k in range(len(N_ed)):
               if((k != 0)and(k != len(N_ed)-1)):
                 tmp = tmp*(int(N_ed[k])+1)
             count += tmp
             print(i,tmp)
  count2 = count
  
#print(i,count2-count1)
print(count)