Problem p02952 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

//****************************************************
#define lp(var, start, end) for (ll var = start; var < end; ++var)
#define rlp(var, start, end) for (ll var = start; var >= end; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(X) X.begin(), X.end()
#define endl "\n" // comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a, b, c)                                                        \
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \
       << endl;
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \
       << #d << ": " << d << endl;

#define MOD (ll)1e9 + 7; // change it for other mods

#define FAST_IO                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
//*******************************************************

// Some Functions

ll powmod(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b = b >> 1;
  }
  return res % MOD;
}

ll cnt(ll n) {
  ll res = 0;
  while (n > 0) {
    res++;
    n = n / 10;
  }
  return res;
}

int main() {
  FAST_IO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    if (cnt(i) % 2 == 1)
      ans++;
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

//****************************************************
#define lp(var, start, end) for (ll var = start; var < end; ++var)
#define rlp(var, start, end) for (ll var = start; var >= end; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(X) X.begin(), X.end()
#define endl "\n" // comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a, b, c)                                                        \
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \
       << endl;
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \
       << #d << ": " << d << endl;

#define MOD (ll)1e9 + 7; // change it for other mods

#define FAST_IO                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
//*******************************************************

// Some Functions

ll powmod(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b = b >> 1;
  }
  return res % MOD;
}

ll cnt(ll n) {
  ll res = 0;
  while (n > 0) {
    res++;
    n = n / 10;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    if (cnt(i) % 2 == 1)
      ans++;
  }
  cout << ans << "\n";
}