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,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
#for deque append(),pop(),appendleft(),popleft(),count()
I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007

a=[]
n=I()
for i in range(1,10):
    k=[]
    for j in range(1,10):
        k.append(0)
    a.append(k)
        

for i in range(1,n+1):
    if(i%10==0):
        continue
    k=str(i)
    p=int(k[0])-1
    q=int(k[-1])-1
    a[p][q]+=1
ans=0
for i in a:
    print(*i)
for i in range(0,9):
    for j in range(0,9):
        ans+=a[i][j]*a[j][i]
print(ans)

Submission status: Wrong Answer

Solution code:
def get_lmb(N):
    while (N >= 10):
        N = int(N/10)
    return N

def get_rmb(N):
    return N%10

def find_all():
    from collections import defaultdict
    dic = defaultdict(int)
    N = int(input())
    for i in range(1, N+1):
        lmb, rmb = get_lmb(i), get_rmb(i)
        dic[(lmb, rmb)] += 1
    print(dic)
    count = 0
    for i in range(1, 10):
        for j in range(1, 10):
            count += dic[(i, j)] * dic[(j, i)]
    # for i in range(1, 10):
    #     count += dic[(i, i)] * dic[(i, i)]
    return count

print(find_all())

Submission status: Wrong Answer

Solution code:
def check2(A):
    if A<10:
        a,b=str(A),str(A)
    else:
        a,b=str(A)[0],str(A)[-1]
    if b=='0':return 0
    n,res,flg=0,0,True
    while n<=k:
        if n==0:
            res+=int(a==b)
        elif n==1:
            res+=int(int(b+a)<=N)
        elif n==k:
            if b<Na:
                res+=10**(n-1)
            elif b>Na:
                break
            else:
                res+=int(str(N)[1:-1])
        else:
            res+=10**(n-1)
        if flg==False:
            break
        n+=1
    return res

N=int(input())
k=len(str(N))-1
Na,Nb=str(N)[0],str(N)[-1]
res=0
for i in range(1,N+1):
    res+=check2(i)
print(res)

Submission status: Wrong Answer

Solution code:
def check2(A):
    if A<10:
        a,b=str(A),str(A)
    else:
        a,b=str(A)[0],str(A)[-1]
    if b=='0':return 0
    n,res,flg=0,0,True
    while n<=k:
        if n==0:
            res+=int(a==b)
        elif n==1:
            res+=int(int(b+a)<=N)
        elif n==k:
            if b<Na:
                res+=10**(n-1)
            elif b>Na:
                break
            else:
                for i in range(10**(n-1)):
                    tmp=int(b+format(i,'0'+str(n-1)+'d')+a)
                    if tmp>N:
                        flg=False
                        break
                    res+=1
        else:
            res+=10**(n-1)
        if flg==False:
            break
        n+=1
    return res

N=int(input())
k=len(str(N))-1
Na,Nb=str(N)[0],str(N)[-1]
res=0
for i in range(N):
    res+=check2(i)
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = {x: [int((str(x))[0]),x % 10] for x in range(1,N)} 

count = 0
for i in range(1,N):
    for j in range (i,N):
        if d[i] == d[j]:
            print(d[i],d[j])
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
dic={}
for i in range(1,n):
    s=str(i)
    d=(s[0],s[-1])
    if d not in dic.keys():
        dic[d] = 1
    else:
        dic[d] += 1

for a in dic.keys():
    b = (a[1],a[0])
    if b in dic.keys():
        ans += dic[a]*dic[(a[1],a[0])]

print(ans)

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 R == 0:
        continue
    if L == R:
        ans += 1
    for j in range(1,6):
        mini = R*10**j +L
        maxi = (R+1)*10**j +L-10
        if N < mini:
            break
        if maxi <= N:
            ans += 10**(j-1)
            continue
        
        tmp = int(str(N)[1:-1])
        
        if L <= int(str(N)[-1]):
            ans += tmp-1
        else:
            ans += tmp
        
        break
print(ans)

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 R == 0:
        continue
    if L == R:
        ans += 1
    for j in range(1,6):
        mini = R*10**j +L
        maxi = (R+1)*10**j +L-10
        if N < mini:
            break
        if maxi <= N:
            ans += 10**(j-1)
            continue
        
        ans += int(str(N)[1:-1])
        """
        if L <= int(str(N)[-1]):
            ans += tmp
        else:
            ans += tmp
        """
        break
print(ans)

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 R == 0:
        continue
    if L == R:
        ans += 1
    for j in range(1,6):
        mini = R*10**j +L
        maxi = (R+1)*10**j +L-10
        if N < mini:
            break
        if maxi <= N:
            ans += 10**(j-1)
            continue
        tmp = int(str(N)[1:-1])
        if L <= int(str(N)[-1]):
            ans += tmp
        else:
            ans += tmp-1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
check=[[0]*9 for i in range(9)]
for i in range(1,n+1):
    s=str(i)
    s1=int(s[0])-1
    s2=int(s[-1])-1
    check[s1][s2]+=1
cnt=0
for i in range(9):
    for j in range(9):
        cnt+=check[i][j]*check[j][i]
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

n = 100
a = 0

while N > n:
    a += n//100
    n *= 10

n //= 10

x = [[a]*9 for _ in range(9)]

b = N // n
for i in range(b-1):
    for j in range(9):
        x[i][j] += n//10

for i in range(N%n):
    c = i % 10
    if c != 0:
        x[b-1][c-1] += 1

for i in range(min(9, N)):
    x[i][i] += 1

cnt = 0

for i in range(9):
    for j in range(9):
        cnt += x[i][j] * x[j][i]

print(cnt)

Submission status: Wrong Answer

Solution code:
def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        lst[head-1][tail-1] += 1
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def f(n):
    str_n = str(n)
    return (str_n[0], str_n[-1])

from collections import Counter
c = Counter()

for i in range(1, N):
    p = f(i)
    c[p] += 1

# for k in sorted(c.keys()):
#     print(k, c[k])

ans = 0
for i in range(1, N):
    p = f(i)
    p_ = (p[1], p[0])
    ans += c[p_]
print(ans)

Submission status: Wrong Answer

Solution code:
def N(x,y,n): # no of x...y < n
    if n<100:
        r=0
        for i in range(1,n+1):
            if str(i)[0]==str(x) and str(i)[-1]==str(y):
                r+=1
        return r
    
    r=N(x,y,99)
    d=len(str(n))
    for i in range(1,d-2):
        r+=10**i
    top=int(str(n)[0])
    if top<x:
        r+=0
    elif top==x:
        r+=int(str(n)[1:-1])
        if str(n)[-1]==str(y):
            r+=1
    else:
        r+=10**(d-2)

        
    return r


ans=0
n=int(input())
for x in range(1,10):
    for y in range(1,10):
        ans+=N(x,y,n)*N(y,x,n)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())


cnt = 0

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

Submission status: Wrong Answer

Solution code:
def check(A,N):
    if N<10:
        return int(N==A)
    res=0
    if A<10:
        a=b=str(A)
        res+=1
    else:
        a,b=str(A)[0],str(A)[-1]
    if b==0:return 0
    n=1
    while N>10**n:
        if n==1:
            res+=(int(b+a)<=N)
        else:
            res+=sum([(int(b+str(i)+a)<=N) for i in list(range(10**(n-1)))])
        n+=1
    return res

N=int(input())
res=0
for i in range(N):
    res+=check(i+1,N)
print(res)

Submission status: Wrong Answer

Solution code:
S=input()
N=int(S)
n=len(S)


ans=0
p=[1,10,100,1000,10000,100000]

for i in range(N+1):#数iに対する相手を探す
    ii=str(i)
    a=int(ii[0])
    b=int(ii[-1])
    if a*b!=0:
        if a==b:#a**aの形なら1桁の答えaが存在
            ans+=1
        for j in range(2,n+1):#桁数
            if j<n:
                ans+=p[j-2]
                #print(i,j,n,ans)
            elif j==n:
                floor=b*p[j-1]+a
                if j==2:
                    ceil=floor
                else:
                    ceil=floor+p[j-1]-p[j-2]
                #print(i,j,floor,ceil)
                if N>=ceil:
                    ans+=p[j-2]
                    #print(i,j,n,ans)
                elif N<floor:
                    continue
                else:#floorとceilの間
                    ans+=(N-floor)//10+1
                    #print(i,j,n,ans)
    #print("i,ans:{},{}".format(i,ans))
                    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

def f(p,q):
    res = 0
    if p == q and n >= p:
        res += 1
    

    for k in range(2,7):
        t = p*pow(10,k-1) + q
        if t > n:
            continue
        res += min(n-t+1,pow(10,k-2))
    return res

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

    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:
def first(num):
  return str(num)[0]

def last(num):
  return num % 10

n = int(input())
c = [[0 for i in range(9)] for j in range(9)]
for num in range(n):
  for i in range(9):
    for j in range(9):
      if first(num) == i and last(num) == j:
        c[i][j] += 1

sum = 0
for i in range(9):
  for j in range(9):
    sum += c[i][j] * c[j][i]

print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n + 1 - j) // 10 - k * i)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))

Submission status: Wrong Answer

Solution code:
n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n - j + 9) // 10 - k * i)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))

Submission status: Wrong Answer

Solution code:
n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n + j + 9) // 10 - k * i)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))

Submission status: Wrong Answer

Solution code:
n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n - 10 * k * i + j) // 10)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))

Submission status: Wrong Answer

Solution code:
from itertools import product


def solve(string):
    l = len(string)
    *s, = map(int, string)
    n = int(string)
    t = [[0] * 10 for _ in range(10)]
    for a, b in product(range(1, 10), repeat=2):
        for i in range(l):
            if i == 0 and a <= n:
                t[a][b] += a == b
            elif i < l - 1:
                t[a][b] += 10**(i - 1)
            else:
                if a < s[0]:
                    t[a][b] += 10**(i - 1)
                elif a == s[0]:
                    tmp = 1
                    for _s in s[1:-1]:
                        tmp *= _s + 1
                    t[a][b] += tmp - (b > s[-1])
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
from itertools import product


def solve(string):
    l = len(string)
    *s, = map(int, string)
    t = [[0] * 10 for _ in range(10)]
    for a, b in product(range(1, 10), repeat=2):
        for i in range(l):
            if i < l - 1:
                if i == 0:
                    t[a][b] += a == b
                elif i > 0:
                    t[a][b] += 10**(i - 1)
            else:
                if a < s[0]:
                    if i == 0:
                        t[a][b] += a == b
                    else:
                        t[a][b] += 10**(i - 1)
                elif a == s[0]:
                    tmp = 1
                    for _s in s[1:-1]:
                        tmp *= _s + 1
                    t[a][b] += tmp - (b > s[-1])
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
from itertools import product


def solve(string):
    l = len(string)
    *s, = map(int, string)
    t = [[0] * 10 for _ in range(10)]
    for a, b in product(range(1, 10), repeat=2):
        for i in range(l):
            if i < l - 1:
                if i == 0 and a == b:
                    t[a][b] += 1
                elif i > 0:
                    t[a][b] += 10**(i - 1)
            else:
                if a < s[0]:
                    t[a][b] += 10**(i - 1)
                elif a == s[0]:
                    tmp = 1
                    for _s in s[1:-1]:
                        tmp *= _s + 1
                    t[a][b] += tmp - (b > s[-1])
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
from itertools import product


def solve(string):
    l = len(string)
    *s, = map(int, string)
    print(s, l)
    t = [[0] * 10 for _ in range(10)]
    for a, b in product(range(1, 10), repeat=2):
        for i in range(l):
            if i < l - 1:
                if i == 0 and a == b:
                    t[a][b] += 1
                elif i > 0:
                    t[a][b] += 10**(i - 1)
            else:
                if a < s[0]:
                    t[a][b] += 10**(i - 1)
                elif a == s[0]:
                    tmp = 1
                    for _s in s[1:-1]:
                        tmp *= _s + 1
                    t[a][b] += tmp - (b > s[-1])
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
# Aの先頭の桁と末尾の桁の組み合わせは9*10=90通りだけ
table = np.zeros((10, 10))
for x in range(1, N+1):
    x = str(x)
    i = int(x[0])
    j = int(x[-1])
    table[i][j] += 1

table = np.array(table)
answer = (table * table.T).sum()
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
numMap = {}
answer = 0
def StartEnd(x):
    start = str(x)[0]
    end = str(x)[-1]
    return int(start), int(end)

for i in range(1, N+1):
    print('numMap:', numMap)
    pair = StartEnd(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1

for i in range(1, N+1):
    key = StartEnd(i)
    rev = key[::-1]
    print('rev:', rev)
    if rev in numMap:
        answer += numMap[rev]
    
print(answer)

Submission status: Wrong Answer

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

def solve(x):
    df = str(x)[0]
    dl = str(x)[-1]
    return df, dl

numMap = {}

for i in range(n):
    # print(i)
    # print(solve(i))
    pair = solve(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1

for i in range(n):
    key = solve(i)
    rev = key[::-1]
    # print('key:', key)
    # print('rev:', rev)
    if rev in numMap:
        ans += numMap[rev]

# print(numMap)
print(ans)

Submission status: Wrong Answer

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

def solve(x):
    df = str(x)[0]
    dl = str(x)[-1]
    return df, dl
    # return df + '-' + dl

numMap = {}

for i in range(1, n):
    # print(i)
    # print(solve(i))
    pair = solve(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1

for i in range(n):
    key = solve(i)
    rev = key[::-1]
    # print('key:', key)
    # print('rev:', rev)
    if rev in numMap:
        ans += numMap[rev]

# print(numMap)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
C = [ [0 for i in range(10)] for i in range(10)]

for i in range(1,N):
  first_num = int(str(i)[0])
  last_num = int(str(i)[-1])
  C[first_num][last_num] += 1

for first_num in range(1,10):
  for last_num in range(1,10):
    ans += C[first_num][last_num] * C[last_num][first_num]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
C = [ [0 for i in range(10)] for i in range(10)]

for i in range(1,N):
  first_num = int(str(i)[0])
  last_num = int(str(i)[-1])
  C[first_num][last_num] += 1

for first_num in range(10):
  for last_num in range(10):
    ans += C[first_num][last_num] * C[last_num][first_num]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
table = [[0]*10 for _ in range(10)]

for x in range(1,n+1):
    if x%10!=0:
        str_x = str(x)
        l,r = int(str_x[0]), int(str_x[-1])
        table[l][r] += 1

ans = 0
for x in range(1, n+1):
    if x%10 != 0:
        str_x = str(x)
        l,r = int(str_x[0]), int(str_x[-1])
        if l==r:
            ans += table[l][r]
        else:
            ans += (table[l][r] * table[r][l])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
tbl=[[0 for j in range(10)] for i in range(10)]
for i in range(n):
  s=str(i)
  h=int(s[0])
  b=int(s[-1])
  tbl[h][b]+=1
ans=0
for i in range(10):
  for j in range(i,10):
    ans+=tbl[i][j]*tbl[j][i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(1, n+1):
  i_ = str(i)
  x = int(i_[0])
  y = int(i_[-1])
  d[x][y] += 1
  
print(d)
ans = 0
for i in range(10):
  for j in range(10):
    ans += d[i][j]*d[j][i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    cnt = 0
    '''
    i => Aの末尾の桁が Bの先頭の桁
    j => Bの末尾の桁が Aの先頭の桁
    '''
    cnt = [[0] * 10 for _ in range(10)]
    for i in range(1,N):
        tmp = str(i)
        first = int(tmp[0])
        last = int(tmp[-1])
        cnt[first][last] += 1
    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += cnt[i][j] * cnt[j][i]

    print(ans)

        







if __name__ == "__main__":
    main()

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 > 2:
    base2 = int(C[1:-1]) + 1
base3 = 0
if K > 2:
    base3 = 10 ** (K-2)
base4 = 0
if K > 2 and Cn == 0:
    base4 = 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
    # 一桁のBの数
    if c[0] == c[-1]:
        if i <= n:
            ans += 1
    # 二桁のBの数
    if int(c[-1] + c[0]) <= n:
        ans += 1
    # 3 ~ K - 1桁のBの数
    ans += base
    # K桁のBの数
    if int(c[-1]) == C1:
        ans += base4
        if int(c[0]) <= Cn:
            ans += base2

    if int(c[-1]) <  C1:
        ans += base3

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def get_ans(dic):
    ans = 0
    for j in range(0, 10):
        for k in range(0, 10):
            if 10 * j + k in dic:
                if 10 * j + k < 10:
                    ans += dic[10 * j + k] * dic[10 * j + k]
                else:
                    ans += dic[10 * j + k] * dic[10 * k + j]
    return ans


def main():
    N = I()
    NS = str(N)

    m = {}
    for j in range(1, 10):
        for k in range(1, 10):
            if j != k:
                m[10 * j + k] = 0
            else:
                m[j] = 0

    for i in range(len(NS)):
        if i == 0:
            for j in range(1, 10):
                m[j] += 1
        elif len(NS) - 1 != i:
            for j in range(1, 10):
                for k in range(1, 10):
                    if j != k:
                        m[10 * j + k] += 1 * (10 ** (i - 1))
                    else:
                        m[j] += 1 * (10 ** (i - 1))
        else:
            for j in range(1, 10):
                for k in range(1, 10):
                    b = int(NS[0])
                    e = int(NS[-1])
                    if j < b:
                        if j != k:
                            m[10 * j + k] += 1 * (10 ** (i - 1))
                        else:
                            m[j] += 1 * (10 ** (i - 1))
                    elif j == b:
                        PNS = ''
                        if e < k:
                            tmp = str((N - (N % 10)) - 1)
                            if tmp[0] != NS[0]:
                                continue
                            PNS = tmp[1:]
                        else:
                            PNS = NS[1:]

                        if len(PNS) != len(NS) - 1:
                            break

                        cur = 1
                        for t in range(len(PNS)-1):
                            cur *= int(PNS[t]) + 1

                        if j != k:
                            m[10 * j + k] += cur
                        else:
                            m[j] += cur

    # dic = {}

    # for j in range(1, 10):
    #     for k in range(1, 10):
    #         if j != k:
    #             dic[10 * j + k] = 0
    #         else:
    #             dic[j] = 0

    # for i in range(1, N+1):
    #     if i < 10:
    #         dic[i] += 1
    #     else:
    #         b = int(str(i)[0])
    #         e = int(str(i)[-1])
    #         if b == e:
    #             dic[b] += 1
    #         elif e != 0:
    #             dic[10 * b + e] += 1

    # for i in dic.keys():
    #     if m[i] != dic[i]:
    #         print(i, m[i], dic[i])
    print(get_ans(m))
    # print(get_ans(dic))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def solve(N: int):
    count = {}
    for i in range(1, N):
        p = get_pair(i)
        key = p[0] + '_' + p[1]
        if not count.get(key):
            count[key] = 0
        count[key] += 1
    ans = 0
    for i in range(1, N):
        p = get_pair(i)
        key = p[1] + '_' + p[0]
        if count.get(key):
            ans += count[key]
    print(ans)
    # print(ans if ans > 0 else 1)
    return


def get_pair(n: int):
    nf = str(n)[0]
    nl = str(n)[len(str(n)) - 1]
    return [nf, nl]


# 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:
#!/usr/bin/env python3
import sys


def solve(N: int):
    count = {}
    for i in range(1, N):
        p = get_pair(i)
        key = p[0] + '_' + p[1]
        if not count.get(key):
            count[key] = 0
        count[key] += 1
    ans = 0
    for i in range(1, N):
        p = get_pair(i)
        key = p[1] + '_' + p[0]
        if count.get(key):
            ans += count[key]
    print(ans if ans > 0 else 1)
    return


def get_pair(n: int):
    nf = str(n)[0]
    nl = str(n)[len(str(n)) - 1]
    return [nf, nl]


# 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())

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

for i in range(1, n):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    matrix[a][b] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, i+1):
        if i == j:
            ans += matrix[i][i] ** 2
        else:
            ans += matrix[i][j] * matrix[j][i] * 2

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 21:23:54 2020

@author: over-
"""

N=input()
L=len(N)

c=0
for i in range(1,int(N)+1):
    x=int(str(i)[0])
    y=int(str(i)[-1])

    if x==y:
        
        if L==1:
            d=1
        if L==2:
            d=1
            if int(N)>=int('{}{}'.format(x,x)):
                d+=1
        if L==3:
            d=1+1
            if int(N)>=int('{}9{}'.format(x,x)):
                d+=10
            elif int(N)>=int('{}0{}'.format(x,x)):
                d+=int(N[1:-1])+1
        if L==4:
            d=1+1+10
            if int(N)>=int('{}99{}'.format(x,x)):
                d+=100
            elif int(N)>=int('{}00{}'.format(x,x)):
                d+=int(N[1:-1])+1
        if L==5:
            d=1+1+10+100
            if int(N)>=int('{}999{}'.format(x,x)):
                d+=1000
            elif int(N)>=int('{}000{}'.format(x,x)):
                d+=int(N[1:-1])+1
        if L==6:
            d=1+1+10+100+1000
            if int(N)>=int('{}9999{}'.format(x,x)):
                d+=10000
            elif int(N)>=int('{}0000{}'.format(x,x)):
                d+=int(N[1:-1])+1
        
        c+=d
    else:
        if y!=0:
            if L==2:
                d=0
                if int(N)>=int('{}{}'.format(y,x)):
                    d+=1
            if L==3:
                d=1
                if int(N)>=int('{}9{}'.format(y,x)):
                    d+=10
                elif int(N)>=int('{}0{}'.format(y,x)):
                    d+=int(N[1:-1])+1
            if L==4:
                d=1+10
                if int(N)>=int('{}99{}'.format(y,x)):
                    d+=100
                elif int(N)>int('{}00{}'.format(y,x)):
                    d+=int(N[1:-1])+1
            if L==5:
                d=1+10+100
                if int(N)>=int('{}999{}'.format(y,x)):
                    d+=1000
                elif int(N)>=int('{}000{}'.format(y,x)):
                    d+=int(N[1:-1])+1
            if L==6:
                d=1+10+100+1000
                if int(N)>=int('{}9999{}'.format(y,x)):
                    d+=10000
                elif int(N)>=int('{}0000{}'.format(y,x)):
                    d+=int(N[1:-1])+1
            
            c+=d
    
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
from collections import defaultdict
d=defaultdict(int)
for i in range(1,N):
    a,b=str(i)[0],str(i)[-1]
    d[(int(a),int(b))]+=1
r = 0
for i in range(1,10):
    for j in range(1,10):
        r += d[(i,j)] * d[(j,i)]
print(r)

Submission status: Wrong Answer

Solution code:
import itertools as it
N=int(input())

count=0


A=list(it.combinations_with_replacement(range(1,N+1),2))

print(A)
for i in range(len(A)):
    if str(A[i][0])[:1]==str(A[i][1])[-1:] and str(A[i][0])[-1:]==str(A[i][1])[:1]:
        if A[i][0]==A[i][1]:
            count+=1
        else:
            count+=2
print(count)