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

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn f(mut x: i64) -> (i64, i64) {
    let r = x % 10;
    while x >= 10 {
        x /= 10;
    }
    (x, r)
}

fn g(l: i64, r: i64, mx: i64) -> i64 {
    if l == 0 || r == 0 {
        return 0;
    }
    let mut res = 0;
    if l == r && l <= mx {
        res += 1;
    }
    if mx < 10 {
        return res;
    }
    if l * 10 + r <= mx {
        res += 1;
    }
    if mx < 100 {
        return res;
    }
    let mut d = 10;
    for free in 1.. {
        // println!(
        //     "{:?} {} {} {}",
        //     (l, r),
        //     free,
        //     d,
        //     l * d * 10 + (d - 1) * 10 + r
        // );
        if l * d * 10 + (d - 1) * 10 + r <= mx {
            res += 10i64.pow(free);
        } else if l * d * 10 > mx {
            break;
        } else {
            let mut x = mx;
            x %= d * 10;
            x /= 10;
            if mx % 10 < r {
                x -= 1;
            }
            res += x + 1;
            break;
        }
        d *= 10
    }
    res
}

fn main() {
    input! {
        n : i64
    }

    let mut res = 0;
    for i in 1..=n {
        let (l, r) = f(i);
        // println!("{} {} {} {}", i, r, l, g(r, l, n));
        res += g(r, l, n);
    }

    // let mut res2 = 0;
    // for i in 1..=n {
    //     let (l1, r1) = f(i);
    //     for j in 1..=n {
    //         let (l2, r2) = f(j);
    //         if l1 == r2 && l2 == r1 {
    //             res2 += 1;
    //         }
    //     }
    // }

    println!("{}", res);
    // println!("{}", res2);
}
*/

fn main() {
    let exe = "/tmp/bin263544A8";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";