#include <bits/stdc++.h>
using namespace std;
int dadsadasda;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18 + 1;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long num = 0;
  long long pow10 = 1;
  while (((num + pow10 * 9) - n < n && (num + pow10 * 9) - n >= 0) ||
         (num + pow10 * 9) < n) {
    num += pow10 * 9;
    pow10 *= 10;
  }
  long long ans = 0;
  if (num != 0) {
    for (int i = 0; i < 10; i++) {
      num += i * pow10;
      if (num - n < n || num < n) {
        if (num <= n) {
          ans += (num - 1) / 2;
        } else {
          ans += (n - (num - 1 - n)) / 2;
        }
      }
      num -= i * pow10;
    }
  } else {
    ans = n * (n - 1) / 2;
  }
  cout << ans << '\n';
  return 0;
}
