# AtCoder Beginner Contest 152

URL: https://atcoder.jp/contests/abc152 (opens new window)

# D

n = gets.chomp.to_i

# 先頭がi, 末尾がjの自然数の個数
arr = 10.times.map{Array.new(10, 0)}

(1..n).each do |num|
  num_s = num.to_s
  arr[num_s[0].to_i][num_s[-1].to_i] += 1
end

count = 0
10.times do |i|
  10.times do |j|
    # A: arr[i][j], B: arr[j][i]とみなせば組み合わせは掛け算で表される
    count += arr[i][j] * arr[j][i]
  end
end

puts count
Last Updated: 2020/08/18 23:38