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 Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return int64(a)
}

func scanFloat() float64 {
	sc.Scan()
	a, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanTextSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = scanText()
	}
	return a
}

func scanSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanFloatSlice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = scanFloat()
	}
	return a
}

func scanInt64Slice(n int64) []int64 {
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = scanInt64()
	}
	return a
}

// var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()

	// input := scanSlice(n)
	// a := input[0]
	// b := input[1]

	// maze := make([]string, 0)

	// for i := 0; i < n; i++ {
	// 	maze[i] = make([]string, m)
	// }
	count := 0
	for i := 0; i < n; i++ {
		j := i + 1
		// s := strconv.Itoa(j)
		// com := 0
		count += calc(j, n)

	}

	fmt.Println(count)

}

func calc(a, n int) int {
	ret := 0
	s := strconv.Itoa(a)
	if len(s) == 1 || (len(s) > 1 && s[0] == s[len(s)-1]) {
		ret++
	}
	cp := string(s[len(s)-1]) + string(s[0])
	// fmt.Println("s : ", s)
	// fmt.Println("cp : ", cp)
	if string(s[len(s)-1]) == "0" {
		return ret
	}
	nn := strconv.Itoa(n)

	nLength := len(strconv.Itoa(n))
	nLeft := string(nn[0])
	nRight := string(nn[len(nn)-1])
	nl, _ := strconv.Atoi(nLeft)
	nR, _ := strconv.Atoi(nRight)

	aLeft := string(cp[0])
	aRight := string(cp[len(cp)-1])
	al, _ := strconv.Atoi(aLeft)
	aR, _ := strconv.Atoi(aRight)

	// zero := "0"
	// com, _ := strconv.Atoi(cp)
	// fmt.Println("com : ", com)

	if nl > al || (nl == al && nR >= aR) {
		ret += nLength - 1
		// cp = string(s[0]) + zero + string(s[len(s)-1])
	} else {
		if nLength-2 >= 1 {
			ret += nLength - 2
		}
	}
	return ret

}

type position struct {
	x        int
	y        int
	distanse int
}

func binarySearch(arr []int, number int) int {

	l := -1
	r := len(arr)
	index := 0
	for {
		mid := l + (r-l)/2
		tmp := arr[mid]

		if r-l <= 1 || tmp == number {
			index = mid
			break
		} else if tmp < number {
			l = mid
		} else {
			r = mid
		}
	}
	return index
}

func factorial(n int) int64 {
	sum := int64(1)
	for i := 2; i <= n; i++ {
		sum *= int64(i)
	}
	return sum
}

func deleteNumOfArray(arr []int, position int) []int {
	left := arr[:position]
	r := arr[position+1:]
	appendArr := append(left, r...)
	return appendArr
}