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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  long long n;cin>>n;
  long long ans = 0;
  string mx = to_string(n);
  for(int i = 1; n >= i; i++){
    if(!(i%10))continue;
    //cout << i << endl;
    string s = to_string(i);
    for(int j = 1; mx.size() >= j; j++){
      if(j == 1){
        if(s[0] == s[s.size()-1])ans++;
      }else{
        if(mx.size() == j){
          if(mx[0] < s[s.size()-1])break;
          else if(mx[0] > s[s.size()-1]){
            int t = 1;
            for(int z = 0; j-2 > z; z++){
              t*=10;
            }
            ans += t;
          }else{
            int t = 1;
            for(int z = 0; j-2 > z; z++){
              t *= 10;
            }
            
            t/= 10;
            int tans = 0;
            for(int z = 1; mx.size()-1 > z; z++){
              //cout << t << " " <<(mx[z]-'0') << " ";
              tans += t*(mx[z]-'0');
              if(z+1 == mx.size()-1){tans++;}
              //cout << ":" << tans << ": ";
              t /= 10;
            }
            if(mx.size() == 2)tans++;
            tans += (mx[mx.size()-1] >= s[0] ? 0 : -1);
            ans += max(0,tans);
          }
        }else{
          int t = 1;
          for(int z = 0; j-2 > z; z++){
            t*=10;
          }
          ans += t;
        }
      }
    }
    //cout << i << " " << ans  << endl;
  }
  cout << ans << endl;
}