Language: C++

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n;
	cin >> n;
	string s = to_string(n);
	int ans = 0;
	/*rep(i, s.size()) {
		cout << s[i] - '0' << endl;
	}*/
	for (int i = 1; i <= n; i++) {
		string now = to_string(i);
		int af = now[0] - '0', be = now[now.size() - 1] - '0';
		if (be == 0) continue;
		//cout << now << " " << be << " " << af << endl;
		rep(j, s.size()) {
			if (be != af && j == s.size() - 1) continue;
			int dp[10][2];
			rep(k, 10) {
				rep(l, 2) {
					dp[k][l] = 0;
				}
			}
			dp[0][0] = 1;
			rep(k, s.size()) {
				rep(l, 2) {
					//cout << "k=" << k << " " << "l=" << l << endl;
					if (k < j) {
						for (int d = 0; d <= 0; d++) {
							dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
						}
					}
					else if (k == j) {
						for (int d = 0; d <= (l ? 9 : int(s[k] - '0')); d++) {
							if (d == be) {
								//cout << (l ? 9 : int(s[k] - '0')) <<" "<< d << " " << be << endl;
								dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
							}
						}
					}
					else if (k == s.size() - 1) {
						for (int d = 0; d <= (l ? 9 : s[k] - '0'); d++) {
							if (d == af) {
								dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
							}
						}
					}
					else {
						for (int d = 0; d <= (l ? 9 : s[k] - '0'); d++) {
							dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
						}
					}
				}
			}
			/*rep(k, s.size() + 1) {
				rep(l, 2) {
					cout << dp[k][l] << " ";
				}
				cout << endl;
			}*/
			ans += dp[s.size()][0] + dp[s.size()][1];
			//cout << dp[s.size()][0] <<" "<< dp[s.size()][1] << endl;
			//cout << endl;
		}
		//cout << endl;
	}
	cout << ans << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:13: error: expected primary-expression before 'long'
    5 | #define int long long
      |             ^~~~
a.cc:104:79: note: in expansion of macro 'int'
  104 |                                                 for (int d = 0; d <= (l ? 9 : int(s[k] - '0')); d++) {
      |                                                                               ^~~
a.cc:104:78: error: expected ')' before 'long'
  104 |                                                 for (int d = 0; d <= (l ? 9 : int(s[k] - '0')); d++) {
      |                                                                      ~       ^
      |                                                                              )