Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
#define FOR(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T LCM(T a, T b) { return a * (b / gcd(a, b)); }
template <typename T> T expo(T base, T e, T mod) {
  T res = 1;
  while (e > 0) {
    if (e & 1)
      res = res * base % mod;
    base = base * base % mod;
    e >>= 1;
  }
  return res;
}
template <typename T, typename S> T expo(T b, S e) {
  if (e <= 1)
    return e == 0 ? 1 : b;
  return (e & 1) == 0 ? expo((b * b), e >> 1) : (b * expo((b * b), e >> 1));
}
template <typename T, typename S> T modinv(T a, S mod) {
  return expo(a, mod - 2, mod);
}
template <class T, class S>
std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &t) {
  os << "(" << t.first << ", " << t.second << ")";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &t) {
  os << "[";
  FOR(it, t) {
    if (it != t.begin())
      os << ", ";
    os << *it;
  }
  os << "]";
  return os;
}

const int MAXN = 1e5 + 100;
int n;
LL arr[MAXN];
LL pre[MAXN], suff[MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    pre[i] = pre[i - 1] + arr[i];
  }
  suff[n] = arr[n];
  for (int i = n - 1; i > 0; i--) {
    suff[i] = suff[i + 1] + arr[i];
  }
  LL res = 1e18;
  for (int i = 2; i <= n; i++) {
    res = min(res, abs(suff[i] - pre[i - 1]));
  }
  cout << res << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define FOR(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T LCM(T a, T b) { return a * (b / gcd(a, b)); }
template <typename T> T expo(T base, T e, T mod) {
  T res = 1;
  while (e > 0) {
    if (e & 1)
      res = res * base % mod;
    base = base * base % mod;
    e >>= 1;
  }
  return res;
}
template <typename T, typename S> T expo(T b, S e) {
  if (e <= 1)
    return e == 0 ? 1 : b;
  return (e & 1) == 0 ? expo((b * b), e >> 1) : (b * expo((b * b), e >> 1));
}
template <typename T, typename S> T modinv(T a, S mod) {
  return expo(a, mod - 2, mod);
}
template <class T, class S>
std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &t) {
  os << "(" << t.first << ", " << t.second << ")";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &t) {
  os << "[";
  FOR(it, t) {
    if (it != t.begin())
      os << ", ";
    os << *it;
  }
  os << "]";
  return os;
}

const int MAXN = 2e5 + 100;
int n;
LL arr[MAXN];
LL pre[MAXN], suff[MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    pre[i] = pre[i - 1] + arr[i];
  }
  suff[n] = arr[n];
  for (int i = n - 1; i > 0; i--) {
    suff[i] = suff[i + 1] + arr[i];
  }
  LL res = 1e18;
  for (int i = 2; i <= n; i++) {
    res = min(res, abs(suff[i] - pre[i - 1]));
  }
  cout << res << '\n';
  return 0;
}