Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X)                                                                 \
  int(X);                                                                      \
  scanf("%d", &X)
#define DRII(X, Y)                                                             \
  int X, Y;                                                                    \
  scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z)                                                         \
  int X, Y, Z;                                                                 \
  scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET                                                                  \
  int ___T, case_n = 1;                                                        \
  scanf("%d ", &___T);                                                         \
  while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int, int>>
#define F first
#define S second
#define RF(x) freopen(x, "r", stdin)
#define WF(x) freopen(x, "w", stdout)
typedef long long LL;
using namespace std;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PII;
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;
const double eps = 1e-13;

LL a[100009];
LL rs[100009];

int main() {
  DRI(n);
  REP(i, n) {
    scanf("%lld", &a[i]);
    rs[i + 1] = rs[i] + a[i];
  }
  LL ans = INF;
  rs[n + 1] = rs[n];
  REPP(i, 1, n) { ans = min(ans, abs(rs[i] - (rs[n] - rs[i]))); }
  printf("%lld", ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X)                                                                 \
  int(X);                                                                      \
  scanf("%d", &X)
#define DRII(X, Y)                                                             \
  int X, Y;                                                                    \
  scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z)                                                         \
  int X, Y, Z;                                                                 \
  scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET                                                                  \
  int ___T, case_n = 1;                                                        \
  scanf("%d ", &___T);                                                         \
  while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int, int>>
#define F first
#define S second
#define RF(x) freopen(x, "r", stdin)
#define WF(x) freopen(x, "w", stdout)
typedef long long LL;
using namespace std;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PII;
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;
const double eps = 1e-13;

LL a[500009];
LL rs[500009];

int main() {
  DRI(n);
  REP(i, n) {
    scanf("%lld", &a[i]);
    rs[i + 1] = rs[i] + a[i];
  }
  LL ans = INF;
  rs[n + 1] = rs[n];
  REPP(i, 1, n) { ans = min(ans, abs(rs[i] - (rs[n] - rs[i]))); }
  printf("%lld", ans);
}