#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  while (scanf("%lld", &n) != EOF) {
    long long tpn = n;
    long long ninenum = 0;
    long long tezheng;
    while (tpn) {
      tpn /= 10;
      ninenum++;
    }
    ninenum--;
    long long sum = 1;
    while (ninenum) {
      sum = sum * 10;
      ninenum--;
    }
    long long fivesum = 5 * sum;
    if (fivesum <= n) {
      tezheng = fivesum;
      sum = sum * 10;
    } else {
      tezheng = fivesum / 10;
    }
    long long ans = 0;
    if (tezheng != 0) {
      long long yunum = n % sum;
      long long geshu = n / sum;
      if (yunum <= tezheng - 1) {
        ans = yunum * (geshu + 1) * (geshu) +
              (tezheng - 1 - yunum) * geshu * geshu;
        ans += geshu * geshu;
      } else {
        if (yunum == sum - 1) {
          ans +=
              (yunum - 1 - tezheng + 1) * (geshu + 1) * (geshu + 1) +
              (tezheng - 1 - (yunum - 1 - tezheng + 1)) * (geshu + 1) * (geshu);
          ans += geshu * (geshu + 1);
        } else {
          ans += (yunum - tezheng + 1) * (geshu + 1) * (geshu + 1) +
                 (tezheng - 1 - (yunum - tezheng + 1)) * (geshu + 1) * (geshu);
          ans += geshu * geshu;
        }
      }
    } else {
      ans = n * (n - 1) / 2;
    }
    printf("%lld\n", ans);
  }
}
