#include <bits/stdc++.h>
using namespace std;
int power[10];
int getsum(string que) {
  if (que[0] < '5') return 0;
  int len = que.length();
  int L = len;
  int limt = 0, ans = 0;
  for (int i = 1; i < len; ++i) limt = limt * 10 + que[i] - '0';
  ans = (que[0] - '0' - 5) * (power[L - 1]);
  ans += min(power[L - 1] - 1, limt + 1);
  if (len == 1 && que[0] != '9') ans++;
  return ans;
}
int main() {
  power[0] = 1;
  for (int i = 1; i < 10; ++i) power[i] = power[i - 1] * 10;
  int n, L;
  while (~scanf("%d", &n)) {
    string que = to_string(n);
    int len = que.length(), ans = 0;
    L = len;
    if (n < 5) {
      cout << n * (n - 1) / 2 << endl;
      continue;
    }
    if (que[0] < '5') {
      L--;
      int cnt = que[0] - '0';
      if (len > 1) {
        ans += power[L] / 2 - 1;
        ans += (cnt - 1) * (power[L] / 2);
      }
      ans += (cnt - 1) * (power[L] - 1);
      ans += (cnt - 1) * (cnt - 2) / 2 * power[L];
      que.erase(que.begin());
      ans += getsum(que);
      ans += (cnt) * (n - cnt * power[L] + 1);
    } else
      ans = getsum(que);
    cout << ans << endl;
  }
  return 0;
}
