Problem p03973 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define DOWN(i, b, a) for (int i = b; i >= a; i--)
#define SET(a, c) memset(a, c, sizeof a)
#define BIT(i, j) ((i) >> (j)) & 1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(), (o).end()), (o).end())
#define SQ(x) ((x) * (x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template <typename T> inline void priv(vector<T> a) {
  REP(i, a.size()) { cerr << a[i] << ((i == a.size() - 1) ? "\n" : " "); }
}
inline void fastio() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
ll gcd(ll a, ll b) {
  ll c = max(a, b);
  ll d = min(a, b);
  return c == 0 || d == 0 ? c : gcd(c % d, d);
}
ll lcm(ll a, ll b) { return a == 0 || b == 0 ? 0 : a * b / gcd(a, b); }
ll modfact(ll a) {
  ll b = 1;
  FOR(i, 2, a) b = b * i % MOD;
  return b;
}
ll modpow(ll a, ll n) {
  ll b = 1;
  while (n > 0) {
    if (n & 1)
      b = b * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return b;
}
ll modcomb(ll n, ll k) {
  ll b = 1;
  k = min(n - k, k);
  DOWN(i, n, n - k + 1) b = b * i % MOD;
  return b * modpow(modfact(k), MOD - 2) % MOD;
}

const int buff_size = 1 << 20;
char buff[buff_size], *ci, ct;

inline int readint() {
  int A = 0;
  while ((ct = *ci++) >= '0')
    A = (A << 3) + (A << 1) + ct - '0';
  return A;
}

inline ll solve() {
  fread_unlocked(buff, 1, buff_size, stdin);
  ci = buff;
  int N = readint();
  int M = 2, cnt;
  ll ans = readint() - 1;
  REP(i, N - 1) {
    int A = readint();
    if (A == M)
      M++;
    else {
      cnt = A / M;
      ans += cnt;
      if (A - cnt * M == 0)
        ans--;
    }
  }
  return ans;
}

int main() {
  printf("%lld\n", solve());
  return 0;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define DOWN(i, b, a) for (int i = b; i >= a; i--)
#define SET(a, c) memset(a, c, sizeof a)
#define BIT(i, j) ((i) >> (j)) & 1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(), (o).end()), (o).end())
#define SQ(x) ((x) * (x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template <typename T> inline void priv(vector<T> a) {
  REP(i, a.size()) { cerr << a[i] << ((i == a.size() - 1) ? "\n" : " "); }
}
inline void fastio() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
ll gcd(ll a, ll b) {
  ll c = max(a, b);
  ll d = min(a, b);
  return c == 0 || d == 0 ? c : gcd(c % d, d);
}
ll lcm(ll a, ll b) { return a == 0 || b == 0 ? 0 : a * b / gcd(a, b); }
ll modfact(ll a) {
  ll b = 1;
  FOR(i, 2, a) b = b * i % MOD;
  return b;
}
ll modpow(ll a, ll n) {
  ll b = 1;
  while (n > 0) {
    if (n & 1)
      b = b * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return b;
}
ll modcomb(ll n, ll k) {
  ll b = 1;
  k = min(n - k, k);
  DOWN(i, n, n - k + 1) b = b * i % MOD;
  return b * modpow(modfact(k), MOD - 2) % MOD;
}

const int buff_size = 1 << 21;
char buff[buff_size], *ci, ct;

inline int readint() {
  int A = 0;
  while ((ct = *ci++) >= '0')
    A = (A << 3) + (A << 1) + ct - '0';
  return A;
}

inline ll solve() {
  fread_unlocked(buff, 1, buff_size, stdin);
  ci = buff;
  int N = readint();
  int M = 2, cnt;
  ll ans = readint() - 1;
  REP(i, N - 1) {
    int A = readint();
    if (A == M)
      M++;
    else {
      cnt = A / M;
      ans += cnt;
      if (A - cnt * M == 0)
        ans--;
    }
  }
  return ans;
}

int main() {
  printf("%lld\n", solve());
  return 0;
}