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

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

    if AL == 0:
        continue

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


print(res)

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)
        else:
            ans += 2**v
print(ans)

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(1, 10):
    if a == b:
      n = 0
      if a * 10 + b <= N:
        n += 2
      elif a <= N:
        ans += 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
print(ans)

Submission status: Runtime Error

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

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

    if AL == 0:
        continue

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


print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
max_num = 0
ans = 0
for i in range(n)[::-1]:
    num1 = str(i)
    num2 = num1[::-1]
    if n >= max(i , int(num2)):
        if num1[0] == num2[len(num2) - 1] and num2[0] == num1[len(num1) - 1]:
            max_num = int(max(num1, num2))
            break
min_num = max_num
while min_num > 0:
   if min_num % 10 == 0:
       max_num -= 10
       if max_num < 10:
           ans += 9
           break
       min_num = max_num
    if len(set(str(min_num))) == 1:
        ans += (len(str(min_num)) * 2 - 1)
    else:
        ans += 2
print(ans)

Submission status: Runtime Error

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

def gcd(m, n):
    if n == 0:
        return m
    return gcd(n, m % n)

def lcm(m, n):
    return m * n // gcd(m, n)

l = a[0]
for i in range(n):
    l = lcm(a[i], l)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans = ans % 1000000007

print(ans)

Submission status: Runtime Error

Solution code:
N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[len(str(N)) - 1])
ans = 0
#print(str(100)[len(str(100)) - 1])
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[len(str(i)) - 1])
  # 一桁
  if lead == end:
    ans += 1
  #2桁以上ループ lead + 中間 + end　
  for j in range((len(str(N)) - 2) + 1):
    if end == 0:
      #末尾が0
      continue
    elif end > lead_N and j == (len(str(N)) - 2) :
      #生成する整数がNに収まらない場合
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      #生成する整数の一部がNに収まらない場合
      #中間の数字
      if len(str(N)) >= 3
        ans += int(str(N)[1:len(str(N)) - 1])

      if lead <= end_N:
        ans += 1
      #print("b")
      pass
    else:
      #何も気にしないときは組み合わせの分だけたす
      ans += 10 ** j

print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())
b = list(range(1, a+1))
c = {}
count = 0
for i in range(1, 10):
  for j in range(1, 10):
    c[(i, j)] = 0
for i in b:
  for j in c:
    d = str(i)
    if d[0] == d[-1]:
      count += 1
    else d[0] == str(j[0]) and d[-1] == str(j[1]):
      c[j] += 1

count2 = 0
bb = {}

for i in c:
  if set(i) not in bb:
    bb[set(i)] = c[i]
  else:
    bb[set(i)] *= (c[i] * 2)
for i in bb:
  count2 += bb[i]
print(count + count2)

Submission status: Runtime Error

Solution code:
def main(n):
    l=[i for i in range(1,n+1)]
    ans=0
    for i in l:
        for j in l:    
            if str(i)[0]==str(j)[-1] and str(j)[0]==str(i)[-1]:
                # print(i,j)
                ans+=1
                
    print(ans)
n=init(input())
main(n)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 0
for i in range(1, N+1):
    head, tail = str(i)[0], str(i)[-1]
    if tail == "0":
        continue
    if head == tail:
        ans += 1
    if int(tail + head) <= N:
        ans += 1
    if len(str(N))-2 >= 1 or head == tail:
        num = len(str(N))-2
        if int(tail + "9"*(len(str(N))-2) + head) <= N:
            j = int("9"*(len(str(N))-2))
        else:
            j = int(str(N)[1:-1])
        ans += int(j) + 1
        if num > 1:
            ans += int((num - 1) * "1") * 10
                    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
keta = len(str(n))
field = np.array([[0 for _ in range(0)] for _ in range(9)])
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for k in range(1, n+1):
    i = int(str(k)[0])
    j = int(str(k)[1])
    field[i, j] += 1
total = 0
for i in range(9):
    val = field[i,i]
    total += cmb(val+1, 2)
for i in range(9):
    for j in range(9):
        if i==j:
            continue
        else:
            val = field[i,j]
            total += 2*cmb(val, 2)
print(val)

Submission status: Runtime Error

Solution code:
a = int(input())
b = list(range(1, a+1))
c = {}
count = 0
for i in range(1, 10):
  for j in range(1, 10):
    c[(i, j)] = 0
for i in b:
  for j in c:
    d = str(i)
    if d[0] == d[-1]:
      count += 1
    else d[0] == str(j)[0] and d[-1] == str(j)[1]:
      c[j] += 1

count2 = 0
bb = {}

for i in c:
  if set(i) not in bb:
    bb[set(i)] = c[i]
  else:
    bb[set(i)] *= (c[i] * 2)
for i in bb:
  count2 += bb[i]
print(count + count2)

Submission status: Runtime Error

Solution code:
N = int(input())

cnt=0
for i in range(1,N+1):
    new = [int(d) for d in str(i)]
    print(new)
    sento=new[0]
    matu=new[-1]
    keta=len(new)

    if matu!='0':
        new[0]=matu
        new[-1]=sento
        comb=''.join(new)
        if matu==sento:
            cnt+=max(0,len(new)-1)
        elif comb>N:
            for j in range(0,keta-2):
                cnt+=9**j
        elif comb<N:
            for j in range(0,keta-1):
                cnt+=9**j







print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
ht = [[0]*10]*10
count = 0

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

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

Submission status: Runtime Error

Solution code:
N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[len(str(N)) - 1])
ans = 0
#print(str(100)[len(str(100)) - 1])
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[len(str(i)) - 1])
  # 一桁
  if lead == end:
    ans += 1
  #2桁以上ループ lead + 中間 + end　
  for j in range((len(str(N)) - 2) + 1):
    if end == 0:
      #末尾が0
      continue
    elif end > lead_N and j == (len(str(N)) - 2) :
      #生成する整数がNに収まらない場合
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      #生成する整数の一部がNに収まらない場合
      #中間の数字

      ans += int(str(N)[1:len(str(N)) - 1])

      if lead <= end_N:
        ans += 1
      #print("b")
      pass
    else:
      #何も気にしないときは組み合わせの分だけたす
      ans += 10 ** j

print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
print("1", dp)

Submission status: Runtime Error

Solution code:
n = int(input())
l = []

def acounter(i):
  num = i + i
  # 一つ
  if n < int(num):
    return 1

  # ２つ
  num2 = i + '0' + i
  if n < int(num2):
    return 2

  count = 2
  for j in range(len(str(n))-2):
    for k in range(10):
      num3 = i + str(k)*(j+1) + i
      if int(num3) <= n:
        count += 1
      else:
        return count

for i in range(n):
  if (i+1)%10 == 0:
    continue
  l.append(str(i+1))

ll = []
for i in range(len(l)):
  ll.append((l[i][0:1], l[i][len(l[i])-1: len(l[i])]))

count = 0
for i in range(len(ll)):
  pair = ll[i]
  if pair[0] == pair[1]:
    count += acounter(pair[1])
  else:
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
from math import log10
# Find the first digit 
def firstDigit(n) : 
  
    # Remove last digit from number 
    # till only one digit is left 
    while n >= 10:  
        n = n / 10; 
      
    # return the first digit 
    return int(n) 
  
# Find the last digit 
def lastDigit(n) : 
  
    # return the last digit 
    return (n % 10) 

import math 
def fact(n):  
    if (n <= 1): 
        return 1
          
    return n * fact(n - 1)  
  
def nPr(n, r):  
      
    return math.floor(fact(n) /
                fact(n - r))  

import numpy as np
from itertools import product
def count(N): 
    M = np.zeros((10, 10))
    for i in range(1, N+1):
        f = firstDigit(i)
        l = lastDigit(i)
        M[f,l] += 1

    mini = np.minimum(M, M.T)

    
    f = lambda x: x * nPr(x, 2)
    m = [f(mini[i,j]) for i, j in product(range(10), range(10))]
    return int(np.sum(m))
    
# This code is contributed by Raj 
def main():
    N = int(input())
    
    print(count(N))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())

dic = [[[]] * 10 for _ in range(10)]
for i in range(1, N):
    x = int(str(i)[0])
    y = int(str(i)[-1])
    if i in dic[x][y]:
        continue
    else:
        tmp = dic[x][y].copy()
        tmp.append(i)
        dic[x][y] = tmp
    
cnt = 0
for i in range(1, N):
    x = int(str(i)[0])
    y = int(str(i)[-1])
    cnt += len(dic[y][x])
    
print(cnt)

Submission status: Runtime Error

Solution code:
a = int(input())
b = list(range(1, a+1))
c = {}
count = 0
for i in range(1, 10):
  for j in range(1, 10):
    c[(i, j)] = 0
for i in b:
  for j in c:
    d = str(i)
    if d[0] == d[-1]:
      count += 1
    else d[0] == j[0] and d[-1] == j[1]:
      c[j] += 1

count2 = 0
bb = {}

for i in c:
  if set(i) not in bb:
    bb[set(i)] = c[i]
  else:
    bb[set(i)] *= (c[i] * 2)
for i in bb:
  count2 += bb[i]
print(count + count2)

Submission status: Runtime Error

Solution code:
#import math
import fractions
"""
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)
"""
n=int(input())
A=list(map(int,input().split()))

a=A[0]
for b in A:
    #a=lcm(a,b)
    a = a /fractions.gcd(a, b)*b

count=0
for i in A:
    count+=a/i
    #if count>(10**9)+7:
    #    count=count%((10**9)+7)
print(round(count%((10**9)+7)))

Submission status: Runtime Error

Solution code:
n=int(input())
if n%10==0:
  print((int(n/10)**2+8))
elif len(str(n))==1:
  print(n)
else:
  x=n%100
  y=n//100
  if len(str(x))==1 and len(str(n))>=1:
    print((int(n/10)**2+8)+x*4)
  elif len(str(x))==2:
    if y==0:
      k=0
      n=0
    else:
      k=8
    z=x//10
    Z=z*10+z
    if x>=Z:
      print( (int(n//10)**2+k) +(z+1)**2+8)
    elif x<Z and str(n)[0]==str(n)[-1]:
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*4)
    elif x<Zand str(n)[0]!=str(n)[-1]:
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*2)

Submission status: Runtime Error

Solution code:
n=int(input())
if n%10==0:
  print((int(n/10)**2+8))
elif len(str(n))==1:
  print(n)
else:
  x=n%100
  y=n//100
  if len(str(x))==1 and len(str(n))>=1:
    print((int(n/10)**2+8)+x*4)
  elif len(str(x))==2:
    if y==0:
      k=0
      n=0
    else:
      k=8
    z=x//10
    Z=z*10+z
    if x>=Z:
      print( (int(n//10)**2+k) +(z+1)**2+8)
    elif x<Z and str(n)[0]==str(n)[-1]:
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*4)
    elif x<Zand str(n)[0]!=str(n)[-1]::
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*2)

Submission status: Runtime Error

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

def count(i):
    h = str(i)
    s = lambda j, k, l: int(f'{j}{k}{l}')
    if len(set(h)) == 1:
        h = h[0]
        c = 1
        s = h * 1
        while int(s) <= n:
            c += 1
            s = h * c
        return c - 1
    if h[-1] == '0' or s(h[-1], '', h[0]) > n:
        return 0
    # d = 1
    # while s(h[-1], '0' * d, h[0]) <= n:
    #     d += 1
    # i = 0
    # while
    i = 0
    while s(h[-1], i, h[0]) <= n:
        i += 1
    return i + 1

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

Submission status: Runtime Error

Solution code:
import queue
import copy
import math
from collections import deque

# そのまま入力文字列の入力
n = int(input())

end_degits = {}
start_degits = {}

for i in range(1, n + 1):
    i_in_str = str(i)

    start = i_in_str[0]

    if start != "0":
        if start in start_degits:
            s = start_degits[start]
            s.add(i_in_str)
            start_degits[start] = s
        else:
            start_degits[start] = set(i_in_str)

    end = i_in_str[-1]
    if end in end_degits:
        s = end_degits[end]
        s.add(i_in_str)
        end_degits[end] = s
    else:
        end_degits[end] = set(i_in_str)


#print(end_degits)
#print(start_degits)

ans = 0
for i in range(1, 10):
    end_with_i = end_degits[str(i)]
    start_with_i = start_degits[str(i)]

    for left in end_with_i:
        left_left = left[0]
        for right in start_with_i:
            right_right = right[-1]
            if left_left == right_right:
                ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
import queue
import copy
import math
from collections import deque

# そのまま入力文字列の入力
n = int(input())

end_degits = {}
start_degits = {}

for i in range(1, n + 1):
    i_in_str = str(i)

    start = i_in_str[0]

    if start != "0":
        if start in start_degits:
            s = start_degits[start]
            s.add(i_in_str)
            start_degits[start] = s
        else:
            start_degits[start] = set(i_in_str)

    end = i_in_str[-1]
    if end in end_degits:
        s = end_degits[end]
        s.add(i_in_str)
        end_degits[end] = s
    else:
        end_degits[end] = set(i_in_str)


print(end_degits)
print(start_degits)

ans = 0
for i in range(1, 10):
    end_with_i = end_degits[str(i)]
    start_with_i = start_degits[str(i)]

    for left in end_with_i:
        left_left = left[0]
        for right in start_with_i:
            right_right = right[-1]
            if left_left == right_right:
                ans += 1


print(ans)

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:
        ans += 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())
string = str(n)
keta = len(string)
first = int(string[0])
last = int(string[1])

time = 0
if first > last:
  time = last
else:
  time = first

count = 0
for i in range(n):
  temp_keta = keta - 2
  not_same = time*time - time
  same = time
  if temp_kana > 0:
    count += not_same*(10**i)
    count += same*(10**i)
  else:
    count += not_same
    count += same + 1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=input()
a=int(N)
e=0
while a > 0:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a = -1
print(str(e))

Submission status: Runtime Error

Solution code:
n=int(input())
if n%10==0:
  print((int(n/10)**2+8))
elif len(str(n))==1:
  print(n)
else:
  
  x=n%100
  y=n//100
  if len(str(x))==1 and len(str(n))>=1:
    print((int(n/10)**2+8)+x*4)
  elif len(str(x))==2:
    if y==0:
      k=0
      n=0
    else:
      k=8
      z=x//10
      Z=z*10+z
    if x>=Z:
      print( (int(n//10)**2+k) +(z+1)**2+8)
    elif x<Z:
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*4)

Submission status: Runtime Error

Solution code:
#include <iostream>
using namespace std;
int main()
{
	string c;
	cin >> c;
	int a[c.size()];
	for(int i = 0; i < c.size(); i++)
	{
		a[i] = c[i] - '0';
	}
	int tmp = 1, tmp2 = 1;
	for(int i = 0; i < c.size(); i++)
	{
		if(a[i-1]*10 + a[i] <=33)tmp++;
		if(a[i]== 0||a[i] == c.size() -1)
		{
			tmp2*=tmp;
			tmp = 0;
		}
	}
	cout << tmp2;
}

Submission status: Runtime Error

Solution code:
N=input()
a=int(N)
e=0
while a > 0:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a -= 1
print(str(e))

Submission status: Runtime Error

Solution code:
n=int(input())
if n%10==0:
  print((int(n/10)**2+8))
else:
  x=n%100
  y=n//100
  if len(str(x))==1:
    print((int(n/10)**2+8)+x*4)
  elif len(str(x))==2:
    if y==0:
      k=0
      n=0
    else:
      k+=8
    z=x//10
    Z=z*10+z
    if x>=Z:
      print( (int(n//10)**2+k) +(z+1)**2+8)
    elif x<Z:
      print( (int(n//10)**2+k) +z**2+8+(Z-x)*4)

Submission status: Runtime Error

Solution code:
N=input()
a=int(N)
while a == 0:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a -= 1
print(str(e))

Submission status: Runtime Error

Solution code:
#import math
from functools import reduce
from fractions import Fraction

def lcm_base(x, y):
    return (x * y) // Fraction.gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)




n = int(input())
A = [int(x) for x in input().split()]

t_lcm = lcm(A)
count = 0
for i in A:
    count += t_lcm//i
    
print(count%(10**9+7))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

# 最大公約数
def gcd(a, b):
    while b != 0:
        tmp = b
        b = a % b
        a = tmp
    return a

# 最小公倍数
def lcm(a, b):
    return int(a * b / gcd(a, b))

# Aの最小公倍数を求める
a_lcm = A[0]
for i in range(1, N):
    a_lcm = lcm(a_lcm, A[i])

# Bを数え上げる
b_sum = 0
for a in A:
    b_sum += int(a_lcm / a)
    b_sum %= (10**9 + 7)

print(b_sum)

Submission status: Runtime Error

Solution code:
N = int(input().strip())
A = list(map(int, input().strip().split(' ')))

def gcd(a,b):
  if a < b: a,b = b,a
  return b if a % b == 0 else gcd(b, a%b)

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

now_lcm = A[0]
for a in set(A[1:]):
  now_lcm = lcm(now_lcm, a)

MOD = 1000000000 + 7
ans = 0
for a in A:
  ans = (ans + (now_lcm//a)) % MOD
print(ans)

Submission status: Runtime Error

Solution code:
a=int(input())
while a == 0:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a += -1
print(str(e))

Submission status: Runtime Error

Solution code:
a=int()
while a == 0:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a += -1
print(str(e))

Submission status: Runtime Error

Solution code:
a=int(N)
while a == 0:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a += -1
print(str(e))

Submission status: Runtime Error

Solution code:
import numpy as np

n=int(input())
x=np.zeros(n+1)

def find(a,n,x):
  k =[]
  l =[]
  for j in range(a,n):
    if j % 10!= 0:
      if a%10 == j//(10**(len(str(j))-1)) and j%10 == a//(10**(len(str(a))-1)):
        k.append(j)
        x[j] = 1
      if a%10 == j%10 and j//(10**(len(str(j))-1)) == a//(10**(len(str(a))-1)):
        l.append(j)
        x[j] = 1
  if k[0] == l[0]:
    return len(k)*len(l)
  return 2*len(k)*len(l)

ans=0
for i in range(1,n+1):
  if x[i] == 0 and i%10!=0:
    ans += find(i,n+1,x)

print(ans)

Submission status: Runtime Error

Solution code:
N = int (input())
b=0
c=0
count = 0
while b < N
    b += 1
    while c < b:
        c += 1
        if b/(10*len(b)) == c%10 and c/(10*len(c)) == b%10:
            count += 1
            
print(count)

Submission status: Runtime Error

Solution code:
a=int(N)
while a == 0:
  b = str(a)
  c = a // 10
  d = a % 10
  if int(b[1]) <= d:
    c += 1
  e += c
  a += -1
else:
  print(str(e))

Submission status: Runtime Error

Solution code:
N=int(input())
for i in range(1,N+1):
    count = [j for j in range(1,N+1) if (str(i)[0] == str(j)[len(str(j))-1]) & (str(j)[0] == str(i)[len(str(i))-1])]
    t=t+len(count)
print(t)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

ans = 0
LCM = lcm(*A)
for i in range(N):
    ans += LCM//A[i]

print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
N = int(input())
if N <= 10:
  print(1)
  else:
    ret = 0
    #diff num
    for i in range(1,10):
      for j in range(i+1,10):
        a = 0
        b = 0
        for k in range(1, 6):
          if i * 10 ** k + j < N:
            a += 10 ** (k - 1)
        for k in range(1, 6):
          if j * 10 ** k + i < N:
            b += 10 ** (k - 1)
            ret += a * b * 2
         #same num
    for i in range(1,10):
      c = 1
      for k in range(1,6):
        if i * 10 ** k + i < N:
           c += 10 ** (k - 1)
      ret += c * c
  print(ret)

Submission status: Runtime Error

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


int main() {
	int N;
	cin>>N;
	string A,B;
	int count=0;
	ostringstream oss1,oss2;
	string As,Bs;
	for(int i=1;i<N;i++){
		for(int j=1;j<N;j++){
		oss1<<i;
		oss2<<j;
		As=oss1.str();
		Bs=oss2.str();
		if(As.at(0)==Bs.at(0)){
			count++;
			
		}
		}
	}
	cout<<count<<endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
cnt_1 = 0
cnt_2 = 0
for i in range(1,n+1):
    for j in range(i,n+1):
        #対象な場合
        #(1,1),(22,22),(333,333)
        if i==j and (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):
            cnt_1 += 1
        #異なる数字の場合
        #揃っていてもnより大きい場合はNG
        elif (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):
                cnt_2 += 1
print(cnt_1 + cnt_2*2)

Submission status: Runtime Error

Solution code:
N = int(input())

import numpy as np

X = np.arange(N+1)
A = X.copy()

for i in [1,10,100,1000,10000]:
    A[i:i*10] = X[i:i*10] // i
B = X % 10
C = np.zeros((10,10), dtype=int)

for i in range(1,N+1):
    C[A[i], B[i]] += 1
count = 0

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

Submission status: Runtime Error

Solution code:
#coding: utf-8

import fractions

n = int(input())
a = [int(v) for v in input().split()]

lcm = a[0]
for aa in a[1:]:
    lcm = lcm * aa // fractions.gcd(lcm, aa)

B = (lcm/aa for aa in a)
s = 0
for bb in B:
    s += bb
    s %= 1000000007

print(int(s))

Submission status: Runtime Error

Solution code:
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

n = int(input())
A = [int(i) for i in input().split()]
k = lcm_list(A)
r = 0
for i in range(n):
    r += k//A[i]
    if r > 10**9+7:
        r %= 10**9+7
print(r)

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
input = sys.stdin.readline

# python > pypy
MOD = 10**9 + 7
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

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

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

b = list(map(lambda x: lcm_//x, a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
"""a,bの最大公約数"""
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

"""a,bの最小公倍数"""
def lcm(a,b):
    return a*b//gcd(a,b)
m=1
mod=1000000007
for i in range(n):
    m=lcm(m,x[i])
ans=0
for i in range(n):
    ans+=(m//x[i])%mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
# your code goes here
def fact(a,n,sum):
    if n==0:
        return sum
    else:
        while(a>0):
            sum+=(a%10)
            a//=10
        return fact(sum,n-1,sum)
n=int(input())
if n<=2:
    print(1)
    quit()
print(fact(2,n-3,2))

Submission status: Runtime Error

Solution code:
x=int(input())
x=x+1
for i in range(x,9999):
    i=str(i)
    if i[0] in i[1:]:
        continue
    elif i[1] in i[2:]:
        continue
    elif i[2] in i[3]:
        continue
    else:
        print(i)
        break

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
"""a,bの最大公約数"""
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

"""a,bの最小公倍数"""
def lcm(a,b):
    return a*b//gcd(a,b)
m=1
mod=1000000007
for i in range(n):
    m=lcm(m,x[i])
ans=0
for i in range(n):
    ans+=(m//x[i])%mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


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

kobai=lcm_list(a)

sumN=0
for i in a:
    sumN+=int(kobai/i)
   
sumN=int(sumN%(1e9+7))

print(sumN)

Submission status: Runtime Error

Solution code:
def g(n):
    D = [[0]*10 for i in range(10)]
    for i in range(1,n+1):
        si = str(i)
        D[int(si[0])][int(si[-1])] += 1

    res = 0
    for i in range(10):
        for j in range(10):
            res += D[i][j]*D[j][i]
    return res
print(g(int(n)))