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: Runtime Error

Solution code:
n=input()
intn=int(n)
ln=len(n)

if intn<10:
  print(n)
  quit()

def count(i,j):
  res=0
  if i==j:
    res+=1
  if ln==2:
    if 10*i+j<=n:
      res+=1
  else:
    res+=(10**(ln-2)-1)//9
    if i<int(n[0]):
      res+=10**(ln-2)
    elif i==int(n[0]):
      tn=int(n[1:-1])
      if j<=intn%10:
        res+=tn+1
      else:
        res+=tn
  return res

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

Submission status: Runtime Error

Solution code:
num = [input() for i in range(2)]
num_0 = int(num[0])
num_1 = list(map(int, num[1].split()))

num_min = num_1[0]
count = 0

for i in range(0,num_0):
  if(num_min >= num_1[i]):
    count = count+1
    num_min = num_1[i]
    
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())

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

for i in range(1,n+1):
    t=str(i)
    c[int(t[0])][int(t[-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:
s = int(input())
num = [[0 for i in range(10)] for j in range(10)]

ans = 0

for _ in range(n):
    i = _ + 1
    if i < 10:
        num[i][i] += 1
    elif i % 10 != 0:
        moji = str(i)
        num[int(moji[0])][int(moji[len(moji)-1])] += 1
    else:
        pass

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

print(ans)

Submission status: Runtime Error

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

ans = 0

for _ in range(n):
    i = _ + 1
    if i < 10:
        num[i][i] += 1
    elif i % 10 != 0:
        moji = str(i)
        num[int(moji[0])][int(moji[len(moji)-1])] += 1
    else:
        pass

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

for i in num:
    for j in i:
        print(j, " ", end="")
    print()

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1

ans = 0
for d1 in range(9):
  for d2 in range(9):
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
return ans

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1, i+1):
        if first(i) == last(j) and first(j) == last(i):
            ans += 1 if i == j else 2
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

for i in range(1,n+1):
  for j in range(1,n+1):
    k=i
    while k>10:
      k=k/10
    m = j % 10
    list.append(n,m)
print(len(list))

Submission status: Runtime Error

Solution code:
from numpy import zeros

N = int(input())
A = zeros((10,10))

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

cnt = 0
for l in range(1,N+1)
  a = int(str(i)[0])
  b = int(str(i)[0])
  cnt += A[s][t]
  
print(cnt)

Submission status: Runtime Error

Solution code:
N=int(raw_input())
listofnumbers= range(1,N+1)
m=[]
number=0
for i in listofnumbers:
  if len(str(i))==1:
    m.append((i,i))
    k=2*str(i)
    if int(k) < N:
      m.append((int(k),i)
  else:
    g=str(i)
    a=len(g)
    k=g[-1]+g[1:a-1]+g[0]
    if int(k)< N:
      m.append((int(g),int(k)))
for l in m:
  number +=1
print number

Submission status: Runtime Error

Solution code:

n = int(input())

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

for _ in range(1, n+1):

    s=str(i)
    i=int(s[0])
    j=int(s[-1])

    number[i][j] += 1

count = 0
for i in range(10):

    for j in range(10):
        count += number[i][j]*number[j][i]

print(count)

Submission status: Runtime Error

Solution code:
n = input()
count = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(1, N+1):
    s = str(i)
    e1 = int(s[0])
    e2 = int(s[1])
    table[e1][e2] += 1

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

Submission status: Runtime Error

Solution code:
N=int(input())
c=[[0 in range(10)] in range(10)] #c[i][j]=1以上N以下の整数で先頭i末尾jとなる数字の個数
for i in range(1,11):
  for j in range(1,11):
    for k in range(1,N+1):
      k=str(k)
      if k[0]==i and k[-1]==j:
        c[i][j]=c[i][j]+1
S=0
for i in range(1,11):
  for j in range(1,11):
    S=S+c[i][j]*c[j][i]
print(S)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 0
tmp = int(str(N)[1:-1])
NR = int(str(N)[-1])
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
        
        if L <= NR:
            ans += tmp+1
        else:
            ans += tmp
        break
print(ans)

Submission status: Runtime Error

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
for i in range(9):
    for j in range(9):
        cnt+=check[i][j]*check[j][i]
print(cnt)

Submission status: Runtime Error

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


int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    
    int arr[10][10] = {0};
    for(int i = 0; i <= n; i++) {
        string s = to_string(i);
        arr[s[0] - '0'][s.back() - '0']++;
    }

    long long int ans = 0;
    for(int i = 0; i <= n; i ++) {
        for(int j = 0; j <= n; j++) {
            ans += arr[i][j] * arr[j][i];
        }
    }

    cout << ans << endl;


    return 0;
}

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    a[int(str(i)[0])][i%10]+=1
def N(x,y): # no of x...y < n
    return a[x][y]

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

Submission status: Runtime Error

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

    for n in range(1, N+1):
        for i in range(1,10):
            for j in range(1,10):
                head = str(n)[0]
                tail = str(n)[-1]
                if i == int(head) and j == int(tail):
                    lst[i-1][j-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)

main2(N)

Submission status: Runtime Error

Solution code:

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: Runtime Error

Solution code:
n = int(input())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if f_dict[[moji[0]+moji[-1]] == "":
    f_dict[moji[0]+moji[-1]] = 0
  else:
    f_dict[[moji[0]+moji[-1]]+= 1 
  if s_dict[[moji[-1]+moji[0]] == "":
    f_dict[[moji[-1]+moji[0]] = 0
  else:
    f_dict[[moji[-1]+moji[0]] += 1
for mykey in f_dict.keys():
  cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
using namespace std;
signed main()
{
    fast;
    int n;
    cin>>n;1
    int dp[10][10]={};
    for(int i=1;i<=n;i++){
		string s = to_string(i);
		int nn = s.size();
		int ss = s[0]-'0';
		int en = s[nn-1]-'0';
		dp[ss][en]+=1;
	}
	int ans = 0;
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			ans+=(dp[i][j]*dp[j][i]);
	cout<<ans;
}

Submission status: Runtime Error

Solution code:
n = int(input())

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

for i in range(1,n+1):
    first = int(str(i)[0])
    last = int(str(i)[-1])

    if first == 0 or last == 0:
        continue
    else:
        count[first][last] += 1

ans = 0
for first in range(1,10):
    ans += count[first][last] * count[last][first]

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long int n,a[10][10],i,ans=0,sd,ed;
	cin>>n;
	memset(a,0,sizeof(a));
	for(i=1;i<=n;++i)
	{
		if(i < 10)
		{
			++a[i][i];
			++ans;
		}
		else
		{
			sd = i/pow(10,(floor((log10(i)+1)*1.0)-1));
			ed = i%10;
			//cout<<sd<<" "<<ed<<"\n";
			if(ed == 0)
				ans = ans;
			else if(sd == ed)
				ans += (2*a[ed][sd] + 1);
			else
				ans += (2*a[ed][sd]);
			++a[sd][ed];
			//cout<<i<<" "<<ans<<"\n";
		}
	}
	cout<<ans;
	return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if f_dict[[moji[0], moji[-1]] == "":
    f_dict[moji[0], moji[-1]] = 0
  else:
    f_dict[[moji[0], moji[-1]]+= 1 
  if s_dict[[moji[-1], moji[0]] == "":
    f_dict[[moji[-1], moji[0]] = 0
  else:
    f_dict[[moji[-1], moji[0]] += 1
for mykey in f_dict.keys():
  cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

Submission status: Runtime Error

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

ans = 0
for i in range(1,n+1):
    s=str(i)
    if s[0]=="0" or s[-1]=="0":
        continue
    else:
        d[int(s[0])][int(s[-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)
n = int(input())

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

ans = 0
for i in range(1,n + 1):
    s = str(i)
    if s[0] == "0" or s[-1] == "0":
        continue
    else:
        d[int(s[0])][int(s[-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())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if f_dict[moji[0], moji[-1]] == "":
    f_dict[moji[0], moji[-1]] = 0
  else:
  	f_dict[moji[0], moji[-1]] += 1 
  if s_dict[moji[-1], moji[0]] == "":
    f_dict[moji[-1], moji[0]] = 0
  else:
  	f_dict[moji[-1], moji[0]] += 1
for mykey in f_dict.keys():
  cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

Submission status: Runtime Error

Solution code:
def d():
    N = int(input())
    a = {}
    count = 0

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        a[l, r] = a.get((l, r), 0) + 1

    # print(a)

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        # print('a.get(({0}, {1}), 0) * a.get(({1}, {0}), 0) = {2}'.format(l,
                                                                         r, a.get((l, r), 0) * a.get((r, l), 0)))
        count += a.get((r, l), 0)

    print(count)


##########
d()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
  s = str(i)
  d[(i[0], i[-1])]+=1
ans = 0
for i, j in d.items():
  ans+=j*d[i[::-1]]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
  s = str(i)
  d[(i[0], i[1])]+=1
ans = 0
for i, j in d.items():
  ans+=j*d[i[::-1]]
print(ans)

Submission status: Runtime Error

Solution code:
def left(text, n):
  return text[:n]

def right(text, n):
  return text[-n:]

def mid(text, n, m):
  return text[n-1:n+m-1]
  
n = int(input())

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

# [1,9][9,1]など先頭＋最終の組み合わせを設定
for i in range(1,n+1):
	first = int(left(str(i),1))
	end = int(right(str(i),1))
	rangeSet[first][end] += 1

    kumiawase = 0
for k in range(1,10):
	for l in range(1,10):
		tmp = rangeSet[k][l] * rangeSet[l][k]
		kumiawase += tmp	
print(kumiawase)

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = [[0]*10 for _ in range(n)]
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:
n, m = map(int, input().split())
print('Yes' if n == m else 'No')

Submission status: Runtime Error

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

N = INT()
A = LIST()

bit = BIT(N)
ans = 0
for i in range(N):
    # 自分より左にある、自分より小さな数の個数
    if bit.sum(A[i]) == 0:
        ans += 1
    bit.add(A[i], 1)
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
from fractions import gcd
mod = 10**9+7
g = A[0]
for a in A[1::]:
  g = g*a//gcd(g,a)

ans = 0
b = g%mod
for a in A:
  ans += b*pow(a,mod-2,mod)
  ans %= mod
  
print(ans%mod)

Submission status: Runtime Error

Solution code:
n = int(input())

def f(x):
    a1 = int(str(x)[0])
    a2 = x%10
    return (a1, a2)

count = {}
for x in range(1, n+1):
    key = f(x)
    if key in count:
        count[key] += 1
    else:
        count[key] = 1

ans = 0
for x in range(1, n+1):
    a0, a1 = f(x)
    if a1 != 0:        # !
        key = (a1, a0) # swap
        ans += count[key]

print(ans)

Submission status: Runtime Error

Solution code:
N: int = int(input())
table = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
    v = str(i)
    table[int(v[0])][int(v[-1])] += 1
ans = 0
for i in range(1, N + 1):
    v = str(i)
    ans += table[int(v[-1])][int(v[0])]
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

n = int(input())
ans = 0

def check(a,b):
    if list(str(a)[0]) == list(str(b)[-1]) and list(str(a)[-1]) == list(str(b)[0]) :        
        global ans
        ans += 1

    if a >= n:        
        return ans
    if b >= n:  
        check(a+1,1)
        return
    
    check(a,b+1)

check(1,1)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(40000)

n = int(input())
ans = 0

def check(a,b):
    if list(str(a)[0]) == list(str(b)[-1]) and list(str(a)[-1]) == list(str(b)[0]) :        
        global ans
        ans += 1

    if a >= n:        
        return ans
    if b >= n:  
        check(a+1,1)
        return
    
    check(a,b+1)

check(1,1)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

def calc(first, last, digit, limit):
  cnt = 0

  if digit == 0:
    if int(first + last) <= limit:
      cnt += 1
    return cnt
  
  lst = []
  fixed = []

  for n in reversed(range(1, digit)):
    pas = false
    for d in reversed(range(0, 9)):
      v = first
      v += "".join(fixed)
      v += str(d)
      v += "0" * (n - 1)
      v += last

      if int(v) <= limit:
        lst.append(d + 1)
        fixed.append(d)
        pas = true
        break
    
    if not pas:
      fixed.append(0)
  
  if len(lst) == 0:
    return cnt
  return cnt + int(np.prod(lst))

cnt = 0
n = 1

while n <= N:
  first = list(str(n))[0]
  last = list(str(n))[-1]

  if first == "0" or last == "0":
    n += 1
    continue

  if first == last and int(first) <= N:
    cnt += 1
  
  digit = 0
  while True:
    total = calc(last, first, digit, N)
    if total == 0:
      break
    cnt += total
    digit += 1
  n += 1

print(cnt)

Submission status: Runtime Error

Solution code:
mod=10**9+7

n=int(input())

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

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a//gcd(a,b)*b

lcma=1

for i in range(n):
    lcma=lcm(lcma,a[i])

ans=0

for i in range(n):
    ans=(ans+lcma//a[i])

print(ans%mod)

Submission status: Runtime Error

Solution code:
N = int(input())

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

for k in range(1, n+1):
    s = str(k)
    cnt[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

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

for k in range(1, n+1):
    s = str(k)
    cnt[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())
max_N = 2 * 10 ** 5

d = [[0] * 10 for _ in range(10)]
for i in range(1,int(n)):
  k = str(i)
  d[int(k[0])][int(k[-1])] += 1

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

Submission status: Runtime Error

Solution code:
from itertools import product
def cnt(b,e,n_str):
  res=0
  for i in range(int(n_str)+1):
    if int(str(i)[0])==b and i%10==e:
      res+=1
  return res
def sol():
  n_str=input()
  c={i:{j:cnt(b,e,n_str) for j in range(1,10)} for i in range(1,10)}
  return sum(c[b][e]*c[e][b] 
             for b,e in product(range(1,10),repeat=2))

print(sol())

Submission status: Runtime Error

Solution code:
# E
import fractions
N = int(input()) 
A = list(map(int, input().split()))

def main():
    value = A[0]
    for i in range(1, N):
        value = value * A[i] // fractions.gcd(value, A[i])

    z = 10**9+7
    ans = 0
    for i in A:
        ans += (value//i) % z

    print(ans % z)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

#n以下の数でそのような組み合わせの個数
def func(n):
    res=None

    if n<10 :
        res=n

    else:
        l=len(str(n))
        #lは桁数

        #plus:nが増えたことで増える組み合わせの数
        plus=0

        #先頭の数
        h=int(str(n)[0])
        #末尾の数
        t=int(str(n)[-1])

        if t>h:
            plus=2*(10**(l-2)-1)//9

        elif t==h:
            if l<3:
                plus=1


            else:
                plus=(10**(l-2)-1)//9
                q=int(str(n)[1:-1])
                plus+=q

            plus=2*plus+1

        else:
            if t==0:
                plus=0

            else:
                if l<3:
                    plus=1


                else:
                    plus=(10**(l-2)-1)//9
                    q=int(str(n)[1:-1])
                    plus+=q
            
            plus*=2

            


        res=func(n-1)+plus 

    return res


N=input()


N=int(N)

ans=func(N)

print(ans)

Submission status: Runtime Error

Solution code:
#n以下の数でそのような組み合わせの個数
def func(n):
    res=None

    if n<10 :
        res=n

    else:
        l=len(str(n))
        #lは桁数

        #plus:nが増えたことで増える組み合わせの数
        plus=0

        #先頭の数
        h=int(str(n)[0])
        #末尾の数
        t=int(str(n)[-1])

        if t>h:
            plus=2*(10**(l-2)-1)//9

        elif t==h:
            if l<3:
                plus=1


            else:
                plus=(10**(l-2)-1)//9
                q=int(str(n)[1:-1])
                plus+=q

            plus=2*plus+1

        else:
            if t==0:
                plus=0

            else:
                if l<3:
                    plus=1


                else:
                    plus=(10**(l-2)-1)//9
                    q=int(str(n)[1:-1])
                    plus+=q
            
            plus*=2

            


        res=func(n-1)+plus 

    return res


N=input()


N=int(N)

ans=func(N)

print(ans)

Submission status: Runtime Error

Solution code:

def cnt(b,e,n_str):
  res=0
  for i in range(int(n_str)+1):
    if int(str(i)[0])==b and i%10==e:
      res+=1
  return res
def sol():
  n_str=input()
  return sum(cnt(b,e,n_str)*cnt(e,b,n_str) 
             for b,e in product(range(1,10),repeat=2))

print(sol())

Submission status: Runtime Error

Solution code:
n = int(input())

digits = 1
base = 10
for i in range(0, 20):
    if n < 10 ** i:
        digits = i
        break

smallest_digit = n % 10
largest_digit = n // (10 ** (digits - 1)) % 10
mid_digit_pattern = (n - largest_digit * (10 ** (digits - 1))) // 10 + 1

def count_pattern(a, b, dig):
    if dig == 1 and a != b:
        return 0
    elif dig == 1:
        return 1
    elif dig == digits:
        if a > largest_digit:
            return 0
        elif a < largest_digit:
            return 10 ** (dig - 2)
        elif b <= smallest_digit:
            return mid_digit_pattern
        elif b > smallest_digit:
            return mid_digit_pattern - 1
        else:
            assert False, "Can't reach here"
    else:
        return 10 ** (dig - 2)

result = 0
if digits == 1:
    result = n
else:
    counts = {}
    for i in range(1, 10):
        for j in range(1, 10):
            state = (i, j)
            counts[state] = sum([count_pattern(*state, d) for d in range(1, digits + 1)])

    for state in counts.keys():
        result += counts[state] * counts[tuple(reversed(state))]

print(result)

Submission status: Runtime Error

Solution code:
n = int(input())

digits = 1
base = 10
for i in range(0, 20):
    if n < 10 ** i:
        digits = i
        break

smallest_digit = n % 10
largest_digit = n // (10 ** (digits - 1)) % 10
mid_digit_pattern = (n - largest_digit * (10 ** (digits - 1))) // 10 + 1

def count_pattern(a, b, dig):
    if dig == 1 and a != b:
        return 0
    elif dig == 1:
        return 1
    elif dig == digits:
        if a > largest_digit:
            return 0
        elif a < largest_digit:
            return 10 ** (dig - 2)
        elif b <= smallest_digit:
            return mid_digit_pattern
        elif b > smallest_digit:
            return mid_digit_pattern - 1
        else:
            assert False, "Can't reach here"
    else:
        return 10 ** (dig - 2)

if digits == 1:
    print(n)
else:
    counts = {}
    for i in range(1, 10):
        for j in range(1, 10):
            state = (i, j)
            counts[state] = sum([count_pattern(*state, d) for d in range(1, digits + 1)])

    result = 0
    for state in counts.keys():
        result += counts[state] * counts[tuple(reversed(state))]
    print(result)

Submission status: Runtime Error

Solution code:
from functools import reduce

n = int(input())

digits = 1
base = 10
for i in range(0, 20):
    if n < 10 ** i:
        digits = i
        break

smallest_digit = n % 10
largest_digit = n // (10 ** (digits - 1)) % 10
mid_digit_pattern = (n - largest_digit * (10 ** (digits - 1))) // 10 + 1

def count_pattern(a, b, dig):
    if dig == 1 and a != b:
        return 0
    elif dig == 1:
        return 1
    elif dig == digits:
        if a > largest_digit:
            return 0
        elif a < largest_digit:
            return 10 ** (dig - 2)
        elif b <= smallest_digit:
            return mid_digit_pattern
        elif b > smallest_digit:
            return mid_digit_pattern - 1
        else:
            assert False, "Can't reach here"
    else:
        return 10 ** (dig - 2)

if digits == 1:
    print(n)
else:
    counts = {}
    for i in range(1, 10):
        for j in range(1, 10):
            state = (i, j)
            counts[state] = sum([count_pattern(*state, d) for d in range(1, digits + 1)])

    result = 0
    for state in counts.keys():
        result += counts[state] * counts[tuple(reversed(state))]
    print(result)

Submission status: Runtime Error

Solution code:
import math
num = input()
inum = int(num)
cnt = 0
if len(num) == 2:
  a = 0
elif len(num) == 3:
  a = 2
elif len(num) == 4:
  a = 4
elif len(num) == 5:
  a = 6
elif len(num) == 6:
  a = 8
if inum <10:
  print(num)
cnt = cnt + int(num[0])*int(num[0])*10**a
for i in range(int(num[0])*(10**(len(num)-1)),inum+1):
  if str(i)[-1] == 0:
    break
  for j in range(1,i+1):
    if str(j)[-1] == 0:
      break
    if str(j)[-1] == str(i)[0] and str(i)[-1] == str(j)[0]:
      cnt += 1
      if j != i:
        cnt += 1
print(cnt+8)

Submission status: Runtime Error

Solution code:
from functools import reduce
from itertools import product

n = int(input())

digits = 1
base = 10
for i in range(0, 7):
    if n < 10 ** i:
        digits = i
        break

smallest_digit = n % 10
largest_digit = n // (10 ** (digits - 1)) % 10
mid_digit_pattern = (n - largest_digit * (10 ** (digits - 1))) // 10 + 1

def count_pattern(a, b, dig):
    if dig == 1 and a != b:
        return 0
    elif dig == 1:
        return 1
    elif dig == digits:
        if a > largest_digit:
            return 0
        elif a < largest_digit:
            return 10 ** (dig - 2)
        elif b <= smallest_digit:
            return mid_digit_pattern
        elif b > smallest_digit:
            return mid_digit_pattern - 1
        else:
            assert False, "Can't reach here"
    else:
        return 10 ** (dig - 2)

if digits == 1:
    print(n)
else:
    counts = {}
    for state in product(range(1, 10), range(1, 10)):
        counts[state] = sum([count_pattern(*state, d) for d in range(1, digits + 1)])

    result = 0
    for state in counts.keys():
        result += counts[state] * counts[tuple(reversed(state))]
    print(result)

Submission status: Runtime Error

Solution code:
N=int(input())
P=[0,0,0,0,0,0,0,0,0,0]
L=copy.deepcopy(P)
M=[L]*10
count=0
for i in range(1,N+1):
  a=int(str(i)[0])
  b=int(str(i)[-1])
  if L[b][a]!=0:
    count+=2*L[b][a]+1
  L[a][b]+=1

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())

def check(a, b, i):
  if (a + 1) * 10 ** i + b - 10 <= N:
    return 10 ** (i - 1)
  else:
    ret = 0
    for j in range(10 ** (i - 1)):
      if a * 10 ** i + j * 10 + a <= N:
        ret += 1
      else:
        return ret
ans = 0
for a in range(1, 10):
  for b in range(a, 10):
    if a == b:
      n = 0
      if a * 10 + b <= N:
        n += 2
      elif a <= N:
        n += 1
      for i in range(2, 6):
        n += check(a, b, i)
      ans += n ** 2
    else:
      n, m = 0, 0
      if a * 10 + b <= N:
        n += 1
      if b * 10 + a <= N:
        m += 1
      for i in range(2, 6):
        n += check(a, b, i)
        m += check(b, a, i)
      ans += n * m * 2
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
def f(n):
    a=int(math.log10(n)+1)
    b=n//(10**(a-1))
    c=n%10
    return b,c

def g(x,y,N):
    ans=0
    for i in range(1,N+1):
        a,b=f(i)
        if a==x and b==y:
            ans+=1
    return ans

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import scipy.special
N = int(input())
arr = np.array([list(str(i+1)) for i in range(N)])
tmp = []
for i in range(11,100):
    if not i % 10 == 0 and not i // 10 > i % 10:
        tmp.append(i)
dic = {i:0 for i in tmp}
for i, a in enumerate(arr):
    if a[-1] == '0':
        continue
    dic[min(int(a[0]), int(a[-1])) * 10 + max(int(a[0]), int(a[-1]))] += 1
ans = 0
for k,v in dic.items():
    if v == 1:
        if not list(str(k))[0] == list(str(k))[1]:
            continue
        ans += 1
    elif v >= 2:
        if not list(str(k))[0] == list(str(k))[1]:
            v -= 1
            ans += scipy.special.perm(2,v, exact=True)
        else:
            ans += 2**v
print(ans)