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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;
using static System.Console;

namespace program {
  class Program {
    static string alp = "abcdefghijklmnopqrstuvwxyz";
    static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static long MOD = 1000000007;
    static void Main()
    {
      var n = ScanInt();
      int res = 0;
      int[,] c = new int[10,10];
      for(int i=1; i<n; i++){
        c[i.Top(), i%10]++;
      }
      
      for(int h=1; h<10; h++)
        for(int l=1; l<10; l++)
          res += c[l,h] * c[h,l];
      
      WriteLine(res);
    }
    static int count(int l, int h, int n){
      int r = 0;
      for(int i=1; i<=n; i++){
        WriteLine($"{i.Top()} {i}");
        if(i.Top()==h && i%10==l) 
          r++;
      }
      return r;
    }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
    static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); }
	static public int Digit(this int n, int d){ if(d<0) return 0; return (n%(int)Math.Pow(10,d+1)) / (int)Math.Pow(10,d); }
  	static public int Length(this int n) { if(n<0) return 0; return (int)Math.Log10(n)+1; }
    static public int Top(this int n) { return n.Digit(n.Length()-1); }
  }
  
  static class MyMath {
    public static bool isPrime(this int p){
      if(p<=1) return false;
      for(int i=2; i*i<=p; i++)
        if(p%i==0) return false;
      return true;
    }
    public static bool isPrime(this long p){
      if(p<=1) return false;
      for(long i=2; i*i<=p; i++)
        if(p%i==0) return false;
      return true;
    }
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
    public static long Inv(this long a, long m = 1000000007) {
      long b = m, u = 1, v = 0;
      while (b!=0) {
        long t = a / b;
        a -= t * b;
        swap(ref a, ref b);
        u -= t * v;
        swap(ref u, ref v);
      }
      u %= m; 
      if (u < 0) u += m;
      return u;
	}
    private static void swap(ref long a, ref long b){
        var t = a;
        a = b;
        b = t;
    }
  }
}