#include <bits/stdc++.h>
using namespace std;
long long int n, res;
long long int ind;
long long int bin(int ini, int fin) {
  int mit;
  long long int sol = 0, ch;
  while (ini <= fin) {
    mit = (ini + fin) >> 1;
    ch = 1;
    for (int i = 0; i <= mit; i++) ch *= 10;
    ch--;
    if (n + n - 1 >= ch) {
      sol = ch;
      ind = mit;
      ini = mit + 1;
    } else
      fin = mit - 1;
  }
  return sol;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long int val = bin(0, 10);
  if (!val) {
    cout << (n * (n - 1)) / 2 << endl;
    return 0;
  }
  ind++;
  long long int jump = 1;
  for (int i = 1; i <= ind; i++) jump *= 10;
  long long int t1, t2;
  long long int mx = 2 * n - 1;
  while (mx >= val) {
    if (n >= val)
      t1 = val - 1;
    else
      t1 = n;
    t2 = val - t1;
    res += abs(t1 - t2) / 2 + abs(t1 - t2) % 2;
    val += jump;
  }
  cout << res << endl;
  return 0;
}
