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: Accepted

Solution code:
n=int(input())
d=[10*[0]for _ in range(10)]
ans=0
for i in range(1,n+1):
  s=str(i)
  if s[0]=="0" or s[-1]=="0":continue
  d[int(s[0])][int(s[-1])]+=1
for i in range(1,10):
  for j in range(1,10):
    ans+=d[i][j]*d[j][i]
print(ans)

Submission status: Runtime Error

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


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


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


def read_float():
    return float(readline())


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


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


def read_str_n():
    return readline().strip().split()


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(N):
    c = defaultdict(Counter)
    for i in range(1, N+1):
        s = str(i)
        c[int(s[0])*10+int(s[-1])] += 1

    ans = 0
    for i, j in product(range(1, 10), repeat=2):
        ans += c[10*i+j] * c[10*j+i]

    return ans


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

cnt = np.zeros((N,N))

for x in map(str,range(1,N+1)):
    cnt[int(x[0]),int(x[-1])] += 1

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

print(int(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
capa=len(str(n))
ans=0

for i in range(1,n+1):
  if i%10==0:
    continue
  x=str(i)
  if x[0]==x[-1]:
    ans+=1
  
  for j in range(2,capa):
    ans+=10**(j-2)
    
  if int(str(n)[0])>i%10:
    ans+=10**(capa-2)
    
  elif int(str(n)[0])<i%10:
    continue
    
  else:
    if int(str(n)[-1])>int(str(i)[0]):
      ans+=int(str(n)[1:-1])+1
    else:
      ans+=int(str(n)[1:-1])
      
      
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
l=[0]*10

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

ans=0
for i in range(l):
  ans+=i*i
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

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

for i in range(1, N+1):
    top = int(str(i)[0])
    end = int(str(i)[-1])
    num[top][end] += 1

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

print(count)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
#define FS first
#define SC second
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define SQR(x) ((x) * (x))
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
using namespace std;
typedef long long lint;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<bool> VB;
typedef vector<vector<int> > VVI;
typedef vector<vector<LL> > VVLL;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    long long N, ans = 0;
    cin >> N;
    long long c[10][10] = {{0}};
    FOR(i,1,N+1) {
        long long a = i;
        long long b = a % 10;
        while (a >= 10) a /= 10;
        c[a][b]++;
    }
    REP(i,10) REP(j,10) ans += c[i][j] * c[j][i];
    cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
n=int(input())





graph=[[0]*9 for i in range(9)]

for i in range(1,n+1):
    if i%10!=0:
        i=str(i)
        sentou=int(i[0])
        matubi=int(i[-1])
        graph[sentou-1][matubi-1]+=1


import numpy as np

graph=np.array(graph)

print(np.trace(np.dot(graph,graph)))

Submission status: Runtime Error

Solution code:
[[0 for _ in range(9)] for _ in range(9)]

for i in range(1,n+1):
  x=int(str(i)[0])
  y=int(str(i)[-1])
  if x!=0 and y!=0:
    a[x-1][y-1]+=1
  
ans=0
  
for i in range(9):
  for j in range(9):
    if i!=j:
      
      ans+=a[i][j]*a[j][i]
      
    else:
      ans+=(a[i][i]*a[i][i])
      
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
# N = random.randint(1,2*10**5)

N_ =str(N)
n_o=len(N_)

# ans:条件を満たす組みの個数
ans=0

def get_ans(A):
    ans=0
    A_=str(A)
    a_s=A_[0]
    a_e=A_[-1]
#     print(a_s,a_e)
    
    if int(a_e) == 0:
        return 0

    if a_s == a_e:
        ans+=1

    for b_o in range(2,n_o+1):
        B_temp = []
        if b_o < n_o:
            ans += 10**(b_o-2)

        elif b_o == n_o:
            if int(a_e) > int(N_[0]):
                break
            elif int(a_e) < int(N_[0]):
                ans += 10 ** (b_o-2)
            else:
                ans+=int(N_[1:-1])

        else:
            break
        
    return ans

for a in range(1,N+1):
    ans_=get_ans(a)
    ans+=ans_
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

N_ =str(N)
n_o=len(N_)

# ans:条件を満たす組みの個数
ans=0

def get_ans(A):
    ans=0
    A_=str(A)
    a_s=A_[0]
    a_e=A_[-1]
#     print(a_s,a_e)
    
    if int(a_e) == 0:
        return 0

    if a_s == a_e:
        ans+=1

    for b_o in range(2,n_o+1):
        B_temp = []
        if b_o < n_o:
            ans += 10**(b_o-2)

        elif b_o == n_o:
            if int(a_e) > int(N_[0]):
                break
            elif int(a_e) < int(N_[0]):
                ans += 10**(b_o-2)
            else:      
                for p in product(range(10),repeat=n_o-2):
                    ans_temp=int(a_e+''.join(map(str,p))+a_s)
                    if ans_temp > N:
                        break
                    ans+=1 
                    B_temp.append(ans_temp)
    #                 print(B_temp)

        else:
            break
        
    return ans

for a in range(1,N+1):
#     print('====',a)
    ans_=get_ans(a)
    ans+=ans_
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
mod=10**9+7

s=0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    s += bit*(n-bit)*(2**i)
    a >>= 1
print(s % mod)

Submission status: Runtime Error

Solution code:
N = int(input())

g = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    g[a][b] += 1
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += g[i][j]*g[j][i]

print(ans)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
N = int(input())
tb = [[0]*10]*10
tb = np.array(tb)
for i in range(1,N+1):
    s = str(i)
    tb[int(s[0])][int(s[-1])] =tb[int(s[0])][int(s[-1])] +1
 
point =0
 
for i in range(0,10):
    for j in range(0,10):
        point += tb[i][j] * tb[j][i]

Submission status: Runtime Error

Solution code:
n = int(input())
s0=list(str(n))
ans=0

if len(s0)==1:
    print(n)
    exit()

for i in range(1,n+1):
    s1=list(str(i))
    if s1[-1]=='0':
        continue
    if s1[0]==s1[-1]:
        ans+=1
    for j in range(2,len(s0)):#nより小さい桁数のものを足す
        ans+=10**(j-2)
    if int(s0[0])>int(s1[-1]):#nより入れ替えた数の最高位数が小さいとき、全て足す
        ans+=10**(len(s0)-2)
    elif s0[0]==s1[-1]:#nと入れ替えた数の最高位数が同じ時
        ans+=int(''.join(s0[1:len(s0)-1]))+1
        if int(s0[-1])<int(s1[0]):
            ans-=1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

for i in range(n+1):
  if i % 10 != 0:
    str_i = str(i)
    mat[str_i[0]][str_i[-1]] += 1
c = 0
for y in range(1, 10):
  for x in range(y, 10):
    c += mat[y][x] * mat[x][y]
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
D=[[0 for _ in range(9)] for _ in range(9)]
for i in range(n):
    s=str(n)
    D[s[0]][s[-1]]+=1
a=0
for i in range(1,10):
    for j in range(1,10):
        a+=D[i][j]*D[j][i]
print(a)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

def diverta192_b():
    N = int(input())
    P = [tuple(map(int, input().split())) for _ in range(N)]
    if len(P) == 1:
        print(1)  # 座標が1つだけ与えられる場合は即終了
        return

    dcnt = defaultdict(int)  # import忘れずに
    for i in range(N):
        xi, yi = P[i]
        for j in range(i):
            xj, yj = P[j]
            dcnt[(xi-xj, yi-yj)] += 1
            dcnt[(xj-xi, yj-yi)] += 1  # 逆向きもカウントする(都合よいほうを使う)
    most = sorted(dcnt.values(), reverse=True)[0]  # 最も多いカウントを取り出す
    ans = N - most
    print(ans)

diverta192_b()

Submission status: Runtime Error

Solution code:
def resolve():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])
        if temp!=1:
            arr.append([temp, 1])
        if arr==[]:
            arr.append([n, 1])
        return arr

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    import copy

    gcddict = {}
    adiv = []
    for i in range(n):
        primes = factorization(a[i])
        adiv.append(primes)
        for j in range(len(primes)):
            if primes[j][0] in gcddict:
                gcddict[primes[j][0]] = max(gcddict[primes[j][0]], primes[j][1])
            else:
                gcddict[primes[j][0]] = primes[j][1]
    ans = 0
    for i in range(n):
        val = 1
        test = copy.deepcopy(gcddict)
        primes = adiv[i]
        for j in range(len(primes)):
            test[primes[j][0]] -= primes[j][1]
        for k in test.keys():
            val *= pow(k, test[k], mod)
        ans += val
    print(ans % mod)
resolve()

Submission status: Runtime Error

Solution code:
n = int(input())
l = len(n)
c = [[0 for _ in range(9)] for _ in range(9)]

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main(n):
    cnt=0
    for i in range(1,n+1):
        i_list=list(str(i))
        for j in range(1,n+1):
            j_list=list(str(j))
            if i_list[1]==j_list[-1] and i_list[-1]==j_list[1]:
                cnt+=1
    print(cnt)        
        

    
if __name__=='__main__':
    main(int(input()))

Submission status: Runtime Error

Solution code:
N = int(input())
ans_lis = [[0　for k in range(9)] for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  if ushiro == 0:
    continue
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ans_lis = [[0] * 9 for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  if usiro == 0:
    continue
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ans_lis = [[0　for k in range(9)] for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ans_lis = [[0　for _ in range(9)] for  i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for k in range(1, n + 1):
    i, j = int(str_k[0]), int(str_k[-1])
    c[int(str(k)[0])][int(str(k)[-1])] += 1

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

Submission status: Runtime Error

Solution code:
n = int(input())
cheak =[[0]*9 for _ in range]
for i in range(1, n+1):
    s = str(i)
    s1 = int(s[0])-1
    s2 = int(s[-1])-1
    if s2 == 0:
        continue
    cheak[s1][s2] += 1

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

Submission status: Runtime Error

Solution code:
N=int(input())
ans=0
c=[[0 for _ in range(10)] for _ in range(10)]

for n in range(1,N+1):
    i=n%10
    j=n
    while 10<=k:
        j=j//10
    c[i][j]=c[i][j]+1

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

Submission status: Runtime Error

Solution code:
N=int(input())

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

for i in range(1,N+1):
  S=str(i)
  M[int(S[0])][int(S[-1])]+=1
  
for i in range(10):
  for j in range(10):
    ans+=M[i][j]*M[j][i]
    
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-Snack.py
#
import math

a, b = map(int, input().split())

print(math.gcd(a, b))

Submission status: Runtime Error

Solution code:
N = int(input())

c = [[0 for i in range(9)] for j in range(9)]
for i in range(9):
    for j in range(9):
        c[str(i)[0]][str(j)[-1]] += 1

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

ans_1 = 0
for i in range(N):
  str_i = str(i)
  length = len(str_i)
  if str_i[0] == str_i[length-1]:
    ans_1 += 1

ans_2 = 0
half = N // 2
for i in range(half):
  if i <= 9:
    j = 0
    tmp_num =int(str(i)+str(j)+str(i))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i)+str(j)+str(i))
   
  else:
    j = 0
    tmp_num =int(str(i[-1])+str(j)+str(i[0]))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i[-1])+str(j)+str(i[0]))

print(ans_1+2*ans_2)

Submission status: Runtime Error

Solution code:
N = int(input())

ans_1 = 0
for i in range(N):
  str_i = str(i)
  length = len(str_i)
  if str_i[0] == str_i[length-1]:
    ans_1 += 1

ans_2 = 0
for i in range(N // 2):
  if i <= 9:
    j = 0
    tmp_num =int(str(i)+str(j)+str(i))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i)+str(j)+str(i))
   
  else:
    j = 0
    tmp_num =int(str(i[-1])+str(j)+str(i[0]))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i[-1])+str(j)+str(i[0]))

print(ans_1+2*ans_2)

Submission status: Runtime Error

Solution code:
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if len(str(N)) > (k+1) or str(N)[0] > str(a):
                res += 10 ** (k - 1)
                k += 1
                continue

            else :
                Q = N - (a * (10 ** k) + b)
                p = (1 + int(str(Q)[:-1]))
                res += p
                k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    # print(res)
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if str(N)[0] > str(a) or len(str(N)) > (k + 1):
                res += 10 ** (k - 1)
                k += 1
                continue
            p = 1
            Q = N - (a * (10 ** k) + b)
            keep = [0 for i in range(k - 2)]
            for i in range(len(str(Q)) - 1):
                keep[-1 - i] = int(str(Q)[-2 - i])
            for i in range(k - 2):
                p *= (keep[i] + 1)
            res += p
            k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=int(input())

M=[[0]*10 for _ in range(10)]
for i in range(1,N+1):
  S=str(i)
  f=int(S[0])
  b=int(S[-1])
  M[f][s]+=1
  
ans=0
for i in range(10):
  for j in range(10):
    ans+=M[i][j]*M[j][i]
    
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

M=[[0]*10 for _ in range(10)]
for i in range(1,N+1):
  S=str(N)
  f=int(S[0])
  b=int(S[-1])
  M[f][s]+=1
  
ans=0
for i in range(10):
  for j in range(10):
    ans+=M[i][j]*M[j][i]
    
print(ans)

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip()

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()

Submission status: Runtime Error

Solution code:
N = int(input())

C = [[0]*10 for _ in range(10)]
for n in range(1, N+1):
    s = str(n)
    C[int[s[0]]][int[s[-1]]] += 1

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

Submission status: Runtime Error

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    str_N = str(N)
    head_N, tail_N = int(str_N[0]), int(str_N[-1])
    digits = len(str_N)
    m = int(str_N[1:-1])
        
    def f(x):
        s = str(x)
        head, tail = int(s[0]), int(s[-1])
        res = 0
        if head == tail: res += 1 #1桁
        if digits >= 2: #2桁
            if digits == 2:
                if tail <= head_N: res += 1
            else: res += 1
        for d in range(3, digits+1): #3桁以上
            k = d - 2
            if d == digits: #Nと同じ桁数
                if tail < head_N:
                    res += 10**k
                elif tail == head_N:
                    res += m
            else: res += 10**k

        return res

    ans = 0
    for n in range(1,N+1):
        if n % 10 == 0: continue
        ans += f(n)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*(n+1)
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)

Submission status: Runtime Error

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*(n+1)
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,100):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
cnt=[[0 for i in range(10)] for j in range(n)]

for i in range(1,n+1):
  s=str(i)
  head=int(s[0])
  tail=int(s[-1])
  cnt[head][tail]+=1

ans=0
for h in range(0,10):
  for t in range(0,10):
    ans+=cnt[h][t]*cnt[t][h]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

d = defaultdict(int)

for n in range(N):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(1, 10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)

Submission status: Runtime Error

Solution code:
n= int(input())

mat = [[0]*(10)]*(10)

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

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll N;
    cin >> N;

    vector<vector<ll>> num(10, vector<ll>(10, 0));
    for (ll i = 1; i <= N; i++) {
        string str_i = to_string(i);
        num[str_i.front() - '0'][str_i.back() - '0']++;
    }

    ll ans = 0;
    for (ll i = 0; i < 10; i++) {
        for (ll j = 0; j < 10; j++) {
            ans += num[i][j] * num[j][i];
        }
    }
    cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
l = a[0]
for i in range(1, n): l = l // fractions.gcd(l, a[i]) * a[i]
print(sum([l // a[i] for i in range(n)]) % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
Cij = [[0 for _ in range(N)] for _ in range(N)]
for i in range(1,N+1):
  a, b = int(str(i)[0]), int(str(i)[-1])
  Cij[a][b] += 1
print(sum(Cij[i][j]*Cij[j][i] for i in range(N) for j in range(N)))

Submission status: Runtime Error

Solution code:
n = int(input())
c = [[0 for i in range(10)] for j in range(10)]

for i in range(n):
    x = str(n + 1)
    c[int(x[0])][int(x[-1])] += 1
ans = 0
for i in range(n):
    for j in range(n):
       ans += c[i][j] * c[j][i]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[[0]*10for _ in range(10)]
for x in range(1,n+1):l[a=int(str(x)[0])][b=int(str(x)[-1])]+=1
print(sum(l[i][j]*l[j][i]for i in range(10)for j in range(10)))

Submission status: Runtime Error

Solution code:
n = int(input())

str_n = str(n)
 
c = [[0]*10 for _ in range(10)]
for i in range(1,N+1):
	c[int(str(i)[0])][int(str(i)[-1])] += 1
    
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
        ans += c[i][j]*c[j][i]

print(ans)

Submission status: Runtime Error

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

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

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

print(a)

Submission status: Runtime Error

Solution code:
N = np.array([str(i) for i in range(1,int(input())+1)])
C = np.zeros((10,10), dtype=np.int)
ans = 0

# C[i][j](0≦i,j≦9)のテーブルを構築する: O(N)
for n in N:
    C[int(n[0])][int(n[-1])] += 1

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

print(ans)

Submission status: Runtime Error

Solution code:
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val dic = (0..9).map { (0..9).map { 0 }.toMutableList() }
    for(i in (1..n)) {
        if(i % 10 == 0) {
            continue
        }
        val startNum = i.toString()[0].toString().toInt()
        val endNum = i % 10
        dic[startNum][endNum]++
    }
    var ans = 0L
    for(i in (1..9)) {
        for(j in (1..9)) {
            ans += dic[i][j].toLong() * dic[j][i].toLong()
        }
    }
    println(ans)
}

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    print(solve(N))


def count(n, start, end):
    """n以下の数字でsで始まりeで終わる数字の個数
    732, 1, 2 -> 12, 102, 112, 122, ... , 192 = 11
    Examples:
        >>> count(732, 1, 2)
        11
        >>> count(25, 1, 1)
        2
        >>> count(25, 3, 3)
        1
        >>> count(100, 1, 2)
        1
        >>> count(102, 1, 2)
        2
    """

    if n <= 9:
        return 1 if start == end and start <= n else 0
    if n <= 99:
        one_digit = 1 if start == end else 0
        two_digit = 1 if start * 10 + end <= n else 0
        return one_digit + two_digit
    digit_length = len(str(n))
    # digit_length桁以下
    ret1 = count(10 ** (digit_length - 1) - 1, start, end)
    # digit_length桁
    min_cand = start * (10 ** (digit_length - 1)) + end
    if min_cand > n:
        return ret1
    ret2 = min((n-min_cand) // 10 + 1, 10 ** (digit_length - 2))
    return ret1 + ret2


def solve(n):
    """n以下の組で, (213, 382)のような末尾と先頭が等しい数の個数"""
    result = 0
    for i in range(1, 10):
        for j in range(i + 1, 10):
            result += 2 * count(n, i, j) * count(n, j, i)
    for i in range(1, 10):
        result += count(n, i, i) * count(n, i, i)
    return result


if __name__ == "__main__":
    assert_equal(count(732, 1, 2), 11)
    main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    print(solve(N))


def count(n, start, end):
    """n以下の数字でsで始まりeで終わる数字の個数
    732, 1, 2 -> 12, 102, 112, 122, ... , 192 = 11
    Examples:
        >>> count(732, 1, 2)
        11
        >>> count(25, 1, 1)
        2
        >>> count(25, 3, 3)
        1
        >>> count(100, 1, 2)
        1
        >>> count(102, 1, 2)
        2
    """

    if n <= 9:
        return 1 if start == end and start <= n else 0
    if n <= 99:
        one_digit = 1 if start == end else 0
        two_digit = 1 if start * 10 + end <= n else 0
        return one_digit + two_digit
    digit_length = len(str(n))
    # digit_length桁以下
    ret1 = count(10 ** (digit_length - 1) - 1, start, end)
    # digit_length桁
    min_cand = start * (10 ** (digit_length - 1)) + end
    if min_cand > n:
        return ret1
    ret2 = min((n-min_cand) // 10 + 1, 10 ** (digit_length - 2))
    return ret1 + ret2


def solve(n):
    """n以下の組で, (213, 382)のような末尾と先頭が等しい数の個数"""
    result = 0
    for i in range(1, 10):
        for j in range(i + 1, 10):
            result += 2 * count(n, i, j) * count(n, j, i)
    for i in range(1, 10):
        result += count(n, i, i) * count(n, i, i)
    return result


def assert_equal(left, right):
    assert left == right, f"{left} != {right}"

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())

def add(x):
    Len=len(str(x))
    up=int(str(x)[0])
    down=int(str(x)[Len-1])
    R=0
    if down!=0:
        if up<down:
            if Len>=3:
                R+=2*((10**(Len-2)-1)//9)
        elif up>down:
            R+=2*((10**(Len-1)-1)//9)
        else:
            R+=2*(((10**(Len-1)-1)//9)+1)-1
    return int(R)

def ans(y):
    if y==1:
        return 1
    else:
        return ans(y-1)+add(y)

#for i in range(1,N+1):
    #print(i,ans(i))

print(ans(N))

Submission status: Runtime Error

Solution code:
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

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

Submission status: Runtime Error

Solution code:
N = int(input())

res = 0
freq = {}

for i in range(0, 10):
    for j in range(0, 10):
        freq[f'{i}{j}'] = 0

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

Submission status: Runtime Error

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

res = 0
freq = defaultdict(int)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,A,B= map(int,input().split())
count = 0
for A in range(N):
  for B in range(N):
    if A[0:] == B[:-1] and A[:-1] == B[0]:
      count += 1
print(count)

Submission status: Runtime Error

Solution code:
n = input()
ans = 0
for i in range(1, n + 1):
    ha = str(i)[0]
    ka = str(i)[-1]
    for j in range(1, i):
        hb = str(j)[0]
        kb = str(j)[-1]
        if ha == kb and ka == hb:
            ans += 1