prithivMLmods/Coder-Stat huggingface dataset:
Problem p03660 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
int N;
/* function */
vector<int> bfs(int st) {
  queue<int> q;
  vector<int> dist(N, -1);
  dist[st] = 0;
  q.push(st);
  while (!q.empty()) {
    int from = q.front();
    q.pop();
    for (int to : G[from]) {
      if (dist[to] != -1)
        continue;
      dist[to] = dist[from] + 1;
      q.push(to);
    }
  }
  return dist;
}

/* main */
int main() {
  cin >> N;
  int a, b;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> distF = bfs(0);
  vector<int> distS = bfs(N - 1);
  int cntS = 0, cntF = 0;
  for (int i = 0; i < N; i++) {
    if (distF[i] <= distS[i])
      cntF++;
    else
      cntS++;
  }
  if (cntF > cntS)
    cout << "Fennec" << '\n';
  else
    cout << "Snuke" << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 100005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
int N;
/* function */
vector<int> bfs(int st) {
  queue<int> q;
  vector<int> dist(N, -1);
  dist[st] = 0;
  q.push(st);
  while (!q.empty()) {
    int from = q.front();
    q.pop();
    for (int to : G[from]) {
      if (dist[to] != -1)
        continue;
      dist[to] = dist[from] + 1;
      q.push(to);
    }
  }
  return dist;
}

/* main */
int main() {
  cin >> N;
  int a, b;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> distF = bfs(0);
  vector<int> distS = bfs(N - 1);
  int cntS = 0, cntF = 0;
  for (int i = 0; i < N; i++) {
    if (distF[i] <= distS[i])
      cntF++;
    else
      cntS++;
  }
  if (cntF > cntS)
    cout << "Fennec" << '\n';
  else
    cout << "Snuke" << '\n';
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 6;
using ll = long long;
array<ll, maxn> arr;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int num;
  ll tot = 0;
  cin >> num;
  for (int i = 0; i < num; ++i) {
    cin >> arr[i];
    arr[i] += arr[i - 1];
  }
  ll dis = 1e17;
  ll tmp = 0;
  for (int i = 0; i < num - 1; ++i) {
    dis = min(dis, abs(arr[i] - arr[num - 1] + arr[i]));
  }
  cout << dis << endl;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <iostream>
using namespace std;
const int maxn = 3e5 + 6;
using ll = long long;
array<ll, maxn> arr;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int num;
  ll tot = 0;
  cin >> num;
  for (int i = 0; i < num; ++i) {
    cin >> arr[i];
    arr[i] += arr[i - 1];
  }
  ll dis = 1e17;
  ll tmp = 0;
  for (int i = 0; i < num - 1; ++i) {
    dis = min(dis, abs(arr[i] - arr[num - 1] + arr[i]));
  }
  cout << dis << endl;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define eps 1e-6
#define R freopen("555input.txt", "r", stdin);
#define OP freopen("555output.txt", "w", stdout);
//
#define N 100005
#define M 1000000007
int i, j, k, n;
LL a[N], mi = INF, sum, s;

int main() {

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  for (i = 0; i < n - 1; i++) {
    s += a[i];
    mi = min(mi, abs(sum - 2 * s));
  }
  printf("%lld", mi);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define eps 1e-6
#define R freopen("555input.txt", "r", stdin);
#define OP freopen("555output.txt", "w", stdout);
//
#define N 200005
#define M 1000000007
int i, j, k, n;
LL a[N], mi = INF, sum, s;

int main() {

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  for (i = 0; i < n - 1; i++) {
    s += a[i];
    mi = min(mi, abs(sum - 2 * s));
  }
  printf("%lld", mi);
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define maxn 100050
#define inf 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define mm(a, b) memset(a, b, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
const double eps = 1e-6;
const LL mod = 1e9 + 7;
const LL INF = (LL)1e18;
using namespace std;
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
LL qpow(LL x, LL y) {
  LL re = 1, base = x % mod;
  while (y) {
    if (y & 1)
      re = (re * base) % mod;
    base = (base * base) % mod;
    y >>= 1;
  }
  return re;
}
LL a[maxn];
LL fisum[maxn], basum[maxn];
int main() {
  //	freopen("input.txt","r",stdin);
  //	freopen("ouput.txt","w",sdout);
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  mm(fisum, 0), mm(basum, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    fisum[i] = fisum[i - 1] + a[i];
  }
  basum[n] = a[n];
  for (int i = n - 1; i >= 1; i--)
    basum[i] = basum[i + 1] + a[i];
  LL ans = INF;
  for (int i = 1; i < n; i++)
    ans = min(ans, abs(fisum[i] - basum[i + 1]));
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define maxn 200050
#define inf 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define mm(a, b) memset(a, b, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
const double eps = 1e-6;
const LL mod = 1e9 + 7;
const LL INF = (LL)1e18;
using namespace std;
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
LL qpow(LL x, LL y) {
  LL re = 1, base = x % mod;
  while (y) {
    if (y & 1)
      re = (re * base) % mod;
    base = (base * base) % mod;
    y >>= 1;
  }
  return re;
}
LL a[maxn];
LL fisum[maxn], basum[maxn];
int main() {
  //	freopen("input.txt","r",stdin);
  //	freopen("ouput.txt","w",sdout);
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  mm(fisum, 0), mm(basum, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    fisum[i] = fisum[i - 1] + a[i];
  }
  basum[n] = a[n];
  for (int i = n - 1; i >= 1; i--)
    basum[i] = basum[i + 1] + a[i];
  LL ans = INF;
  for (int i = 1; i < n; i++)
    ans = min(ans, abs(fisum[i] - basum[i + 1]));
  cout << ans << endl;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <ctime>

#define gec getchar
#define FILE(F) freopen(F ".in", "r", stdin), freopen(F ".out", "w", stdout)
#define RunTime fprintf(stderr, "Running Time:%.5lfs\n", 1. * clock() / 1e6)

typedef long long ll;
typedef long double lb;
template <typename T> void umin(T &x, T y) {
  if (x > y)
    x = y;
}
template <typename T> T min(T x, T y) { return x < y ? x : y; }
template <typename T> void umax(T &x, T y) {
  if (x < y)
    x = y;
}
template <typename T> T max(T x, T y) { return x > y ? x : y; }
template <typename T> inline void read(T &x) {
  x = 0;
  bool f = 0;
  char c = gec();
  for (; c < '0' || c > '9'; c = gec())
    f = (c == '-');
  for (; c >= '0' && c <= '9'; c = gec())
    x = x * 10 + c - '0';
  x = f ? -x : x;
}

namespace DEBUG {
inline void fpr(char *c) { fprintf(stderr, "%s\n", c); }
inline void fpr(int x, char *c) { fprintf(stderr, "[ %s ] : = %d   \n", c, x); }
inline void fpr(ll x, char *c) { fprintf(stderr, "[ %s ] : = %lld \n", c, x); }
inline void fpr(double x, char *c) {
  fprintf(stderr, "[ %s ] : = %.5lf\n", c, x);
}
inline void fpr(lb x, char *c) { fprintf(stderr, "[ %s ] : = %.5Lf\n", c, x); }
} // namespace DEBUG
using namespace DEBUG;

const int MAXN(100010);
int n;
ll S[MAXN];
ll ABS(ll x) { return x < 0 ? -x : x; }
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(S[i]);
    S[i] += S[i - 1];
  }
  ll Ans = 0x7fffffffffffffff;
  for (int i = 1; i < n; i++)
    umin(Ans, ABS(S[n] - S[i] - S[i]));
  printf("%lld\n", Ans);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <ctime>

#define gec getchar
#define FILE(F) freopen(F ".in", "r", stdin), freopen(F ".out", "w", stdout)
#define RunTime fprintf(stderr, "Running Time:%.5lfs\n", 1. * clock() / 1e6)

typedef long long ll;
typedef long double lb;
template <typename T> void umin(T &x, T y) {
  if (x > y)
    x = y;
}
template <typename T> T min(T x, T y) { return x < y ? x : y; }
template <typename T> void umax(T &x, T y) {
  if (x < y)
    x = y;
}
template <typename T> T max(T x, T y) { return x > y ? x : y; }
template <typename T> inline void read(T &x) {
  x = 0;
  bool f = 0;
  char c = gec();
  for (; c < '0' || c > '9'; c = gec())
    f = (c == '-');
  for (; c >= '0' && c <= '9'; c = gec())
    x = x * 10 + c - '0';
  x = f ? -x : x;
}

namespace DEBUG {
inline void fpr(char *c) { fprintf(stderr, "%s\n", c); }
inline void fpr(int x, char *c) { fprintf(stderr, "[ %s ] : = %d   \n", c, x); }
inline void fpr(ll x, char *c) { fprintf(stderr, "[ %s ] : = %lld \n", c, x); }
inline void fpr(double x, char *c) {
  fprintf(stderr, "[ %s ] : = %.5lf\n", c, x);
}
inline void fpr(lb x, char *c) { fprintf(stderr, "[ %s ] : = %.5Lf\n", c, x); }
} // namespace DEBUG
using namespace DEBUG;

const int MAXN(200010);
int n;
ll S[MAXN];
ll ABS(ll x) { return x < 0 ? -x : x; }
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(S[i]);
    S[i] += S[i - 1];
  }
  ll Ans = 0x7fffffffffffffff;
  for (int i = 1; i < n; i++)
    umin(Ans, ABS(S[n] - S[i] - S[i]));
  printf("%lld\n", Ans);
  return 0;
}
Problem p03661 (C++)

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

typedef long long LL;

int n;
int a[100007];
LL s[100007];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    s[i] = s[i - 1] + a[i];
  }
  //  for (int i = 1; i <= n; i++) printf("%I64d ", s[i]);
  //  puts("");

  LL ans = abs(s[n] - s[1] * 2);
  for (int i = 2; i < n; i++) {
    ans = min(ans, abs(s[n] - s[i] * 2));
  }
  printf("%lld", ans);

  return 0;
}


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

typedef long long LL;

int n;
int a[200007];
LL s[200007];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    s[i] = s[i - 1] + a[i];
  }
  //  for (int i = 1; i <= n; i++) printf("%I64d ", s[i]);
  //  puts("");

  LL ans = abs(s[n] - s[1] * 2);
  for (int i = 2; i < n; i++) {
    ans = min(ans, abs(s[n] - s[i] * 2));
  }
  printf("%lld", ans);

  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
using namespace std;

int n;
long long a[100005];
long long sum[100005];

long long ABS(long long k) {
  if (k > 0)
    return k;
  else
    return -k;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++)
    sum[i] = sum[i - 1] + a[i];
  long long ans = 1;
  for (int i = 1; i <= 16; i++)
    ans *= 10;
  for (int i = 1; i < n; i++) {
    long long x, y;
    x = sum[i];
    y = sum[n] - sum[i];
    if (ABS(x - y) < ans)
      ans = ABS(x - y);
  }
  printf("%lld", ans);
}


Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;

int n;
long long a[200005];
long long sum[200005];

long long ABS(long long k) {
  if (k > 0)
    return k;
  else
    return -k;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++)
    sum[i] = sum[i - 1] + a[i];
  long long ans = 1;
  for (int i = 1; i <= 16; i++)
    ans *= 10;
  for (int i = 1; i < n; i++) {
    long long x, y;
    x = sum[i];
    y = sum[n] - sum[i];
    if (ABS(x - y) < ans)
      ans = ABS(x - y);
  }
  printf("%lld", ans);
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL A[100100], S[100100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &A[i]);
  if (n == 2) {
    cout << abs(A[2] - A[1]) << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    S[i] = S[i - 1] + A[i];
  LL minm = 1e15;
  for (int i = 2; i < n; i++) {
    if (abs(S[n] - S[i] - S[i]) < minm)
      minm = abs(S[n] - S[i] - S[i]);
  }
  cout << minm << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL A[300100], S[300100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &A[i]);
  if (n == 2) {
    cout << abs(A[2] - A[1]) << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    S[i] = S[i - 1] + A[i];
  LL minm = 1e15;
  for (int i = 2; i < n; i++) {
    if (abs(S[n] - S[i] - S[i]) < minm)
      minm = abs(S[n] - S[i] - S[i]);
  }
  cout << minm << endl;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  ll n;
  ll a[100010];
  ll sum = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    sum += a[i];
  }
  ll origin = sum;
  ll result = 1e10;
  for (int i = 0; i < n - 1; i++) {
    sum -= a[i];
    result = min(result, abs(sum - (origin - sum)));
  }
  std::cout << result << std::endl;
}


Fixed submission:
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  ll n;
  ll a[200010];
  ll sum = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    sum += a[i];
  }
  ll origin = sum;
  ll result = 1e10;
  for (int i = 0; i < n - 1; i++) {
    sum -= a[i];
    result = min(result, abs(sum - (origin - sum)));
  }
  std::cout << result << std::endl;
}
Problem p03661 (C++)

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

using namespace std;
const int N = 100000 + 10;
typedef long long ll;
int a[N], l[N], r[N];
int main() {
  int n;
  scanf("%d", &n);
  ll sum = 0;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), sum += a[i];
  ll res = 0;
  ll ans = 1LL << 60;
  for (int i = 0; i < n - 1; i++) {
    res += a[i];
    ans = min(ans, abs(res - (sum - res)));
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
const int N = 200000 + 10;
typedef long long ll;
int a[N], l[N], r[N];
int main() {
  int n;
  scanf("%d", &n);
  ll sum = 0;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), sum += a[i];
  ll res = 0;
  ll ans = 1LL << 60;
  for (int i = 0; i < n - 1; i++) {
    res += a[i];
    ans = min(ans, abs(res - (sum - res)));
  }
  cout << ans << endl;
  return 0;
}
Problem p03661 (C++)

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

using namespace std;
int n;
long long a[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  long long sum = a[n - 1], ans = LONG_LONG_MAX;
  for (int i = 0; i < n - 1; i++) {
    ans = min(ans, abs(a[i] - (sum - a[i])));
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
int n;
long long a[200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  long long sum = a[n - 1], ans = LONG_LONG_MAX;
  for (int i = 0; i < n - 1; i++) {
    ans = min(ans, abs(a[i] - (sum - a[i])));
  }
  cout << ans;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define maxn 100010
#define LL long long
using namespace std;
int n;
int seg[maxn];
LL sum[maxn];
int main() {
  cin >> n;
  int x;
  LL ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    sum[i] = sum[i - 1] + x;
  }
  ans = 1e14;
  for (int i = 1; i < n; i++) {
    ans = min(ans, abs(sum[n] - sum[i] - sum[i]));
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define maxn 200010
#define LL long long
using namespace std;
int n;
int seg[maxn];
LL sum[maxn];
int main() {
  cin >> n;
  int x;
  LL ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    sum[i] = sum[i - 1] + x;
  }
  ans = 1e14;
  for (int i = 1; i < n; i++) {
    ans = min(ans, abs(sum[n] - sum[i] - sum[i]));
  }
  cout << ans;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans = 1000000000000000000ll, sum, sum1;
long long a[100010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &a[i]), sum += a[i];
  for (int i = 1; i < n; ++i) {
    sum1 += a[i];
    sum -= a[i];
    ans = min(ans, abs(sum - sum1));
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans = 1000000000000000000ll, sum, sum1;
long long a[200010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &a[i]), sum += a[i];
  for (int i = 1; i < n; ++i) {
    sum1 += a[i];
    sum -= a[i];
    ans = min(ans, abs(sum - sum1));
  }
  cout << ans << endl;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long arr[100010], sum[100010], ss;
int main() {
  long long n, m, mn = 1e15;
  cin >> n;
  cin >> arr[0];
  sum[0] = arr[0];
  for (int i = 1; i < n; ++i) {
    cin >> arr[i];
    sum[i] = sum[i - 1] + arr[i];
  }
  ss = arr[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    mn = min(mn, abs(ss - sum[i]));
    ss += arr[i];
  }
  cout << mn;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long arr[200010], sum[200010], ss;
int main() {
  long long n, m, mn = 1e15;
  cin >> n;
  cin >> arr[0];
  sum[0] = arr[0];
  for (int i = 1; i < n; ++i) {
    cin >> arr[i];
    sum[i] = sum[i - 1] + arr[i];
  }
  ss = arr[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    mn = min(mn, abs(ss - sum[i]));
    ss += arr[i];
  }
  cout << mn;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#define LL long long
#define MAXN 100000 + 9
using namespace std;

LL n;
LL sum[MAXN];
LL ans = 0x7fffffff;

void solve() {
  LL i;
  LL x, y;
  for (i = 1; i < n; i++) {
    x = sum[i];
    y = sum[n] - sum[i];
    ans = min(ans, abs(x - y));
  }
  printf("%lld\n", ans);
}

int main() {
  scanf("%lld", &n);
  LL i;
  LL x;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &x);
    sum[i] = sum[i - 1] + x;
  }
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#define LL long long
#define MAXN 300000 + 9
using namespace std;

LL n;
LL sum[MAXN];
LL ans = 0x7fffffff;

void solve() {
  LL i;
  LL x, y;
  for (i = 1; i < n; i++) {
    x = sum[i];
    y = sum[n] - sum[i];
    ans = min(ans, abs(x - y));
  }
  printf("%lld\n", ans);
}

int main() {
  scanf("%lld", &n);
  LL i;
  LL x;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &x);
    sum[i] = sum[i - 1] + x;
  }
  solve();
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof a)
#define mcpy(a, b) memcpy(a, b, sizeof b)
#define max(a, b) ((a) < (b) ? (b) : (a))
#define swap(a, b) a ^= b ^= a ^= b
#define lb(x) ((x) & (-(x)))
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
typedef long long ll;
int n, a[N];
ll s[N], ans = 0x3f3f3f3f3f3f3f3fll;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i < n; i++)
    ans = min(ans, abs(s[n] - s[i] - s[i]));
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof a)
#define mcpy(a, b) memcpy(a, b, sizeof b)
#define max(a, b) ((a) < (b) ? (b) : (a))
#define swap(a, b) a ^= b ^= a ^= b
#define lb(x) ((x) & (-(x)))
#define inf 0x3f3f3f3f
#define N 200010
using namespace std;
typedef long long ll;
int n, a[N];
ll s[N], ans = 0x3f3f3f3f3f3f3f3fll;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i < n; i++)
    ans = min(ans, abs(s[n] - s[i] - s[i]));
  cout << ans;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>

using namespace std;

int a[20010];

int main() {
  int N;
  scanf("%d", &N);

  long long sum = 0;

  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }

  long long ans = LLONG_MAX;
  long long x = 0;

  for (int i = 0; i < N - 1; ++i) {
    x += a[i];
    ans = min(ans, abs(sum - x * 2));
  }

  printf("%lld", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>

using namespace std;

int a[200010];

int main() {
  int N;
  scanf("%d", &N);

  long long sum = 0;

  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }

  long long ans = LLONG_MAX;
  long long x = 0;

  for (int i = 0; i < N - 1; ++i) {
    x += a[i];
    ans = min(ans, abs(sum - x * 2));
  }

  printf("%lld", ans);

  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, d[100000], a = 1000000000, b;
  cin >> n;
  d[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    d[i] += d[i - 1];
  }

  for (int i = 1; i < n; i++) {
    b = d[i] * 2 - d[n];
    if (b < 0)
      b *= -1;
    if (a > b)
      a = b;
  }
  cout << a << endl;

  return (0);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, d[1000000], a = 2000000001, b;
  cin >> n;
  d[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    d[i] += d[i - 1];
  }

  for (int i = 1; i < n; i++) {
    b = d[i] * 2 - d[n];
    if (b < 0)
      b *= -1;
    if (a > b)
      a = b;
  }
  cout << a << endl;

  return (0);
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double DD;
const int inf = 1e9;
const int mo = 1e9 + 7;
const int N = 1e5 + 10;
int a[N];

int main() {
  int n;
  scanf("%d", &n);
  LL sum2 = 0, sum1 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum2 += a[i];
  }
  LL ans = 1e18;
  for (int i = 1; i < n; i++) {
    sum1 += a[i];
    sum2 -= a[i];
    ans = min(ans, abs(sum1 - sum2));
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double DD;
const int inf = 1e9;
const int mo = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];

int main() {
  int n;
  scanf("%d", &n);
  LL sum2 = 0, sum1 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum2 += a[i];
  }
  LL ans = 1e18;
  for (int i = 1; i < n; i++) {
    sum1 += a[i];
    sum2 -= a[i];
    ans = min(ans, abs(sum1 - sum2));
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int a[100007];
int main() {
  int n;
  int i, j, k;
  long long int s[10] = {0};
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s[0] += a[i];
  }
  s[3] = 10000000000;
  for (i = 0; i < n - 1; i++) {
    s[1] += a[i];
    s[2] = s[0] - s[1] * 2;
    if (s[2] < 0)
      s[2] = -s[2];
    if (s[2] < s[3])
      s[3] = s[2];
  }
  cout << s[3] << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int a[200007];
int main() {
  int n;
  int i, j, k;
  long long int s[10] = {0};
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s[0] += a[i];
  }
  s[3] = 10000000000;
  for (i = 0; i < n - 1; i++) {
    s[1] += a[i];
    s[2] = s[0] - s[1] * 2;
    if (s[2] < 0)
      s[2] = -s[2];
    if (s[2] < s[3])
      s[3] = s[2];
  }
  cout << s[3] << endl;
  return 0;
}
Problem p03661 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;

int n;
int a[125252];
ll sum[125252];

int main() {
  scanf("%d", &n);
  REP(i, n) scanf("%d", a + i);
  REP(i, n) sum[i + 1] = sum[i] + a[i];
  ll ans = 1e18;
  FOR(i, 1, n) { CHMIN(ans, abs(sum[i] - (sum[n] - sum[i]))); }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;

int n;
int a[225252];
ll sum[225252];

int main() {
  scanf("%d", &n);
  REP(i, n) scanf("%d", a + i);
  REP(i, n) sum[i + 1] = sum[i] + a[i];
  ll ans = 1e18;
  FOR(i, 1, n) { CHMIN(ans, abs(sum[i] - (sum[n] - sum[i]))); }
  cout << ans << endl;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define int long long
#define INF 1e+18
using namespace std;

signed main() {
  int n, a[100000], sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int now = 0, mi = INF;
  for (int i = 0; i < n; i++) {
    now += a[i];
    if (i < n - 1)
      mi = min(mi, abs(now - (sum - now)));
  }
  cout << mi << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#define int long long
#define INF 1e+18
using namespace std;

signed main() {
  int n, a[200000], sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int now = 0, mi = INF;
  for (int i = 0; i < n; i++) {
    now += a[i];
    if (i < n - 1)
      mi = min(mi, abs(now - (sum - now)));
  }
  cout << mi << endl;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define __count __builtin_popcount
#define __countll __builtin_popcountll
#define X first
#define Y second
#define mst(x) memset(x, 0, sizeof(x))
#define mst1(x) memset(x, -1, sizeof(x))
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR1(i, n) for (int i = 1; i <= n; i++)
#define FORit(it, c)                                                           \
  for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define pb push_back
#define RI(x) scanf("%d", &x)
#define RID(x)                                                                 \
  int x;                                                                       \
  RI(x)
using namespace std;
typedef long long LL;
const int N = 1e5 + 7;
int a[N];

int main() {
  RID(n);
  LL sum = 0;
  FOR(i, n) {
    RI(a[i]);
    sum += a[i];
  }
  LL l = 0, res = 1LL << 62;
  FOR(i, n - 1) {
    l += a[i];
    LL now = l - (sum - l);
    if (now < 0)
      now = -now;
    res = min(res, now);
  }
  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define __count __builtin_popcount
#define __countll __builtin_popcountll
#define X first
#define Y second
#define mst(x) memset(x, 0, sizeof(x))
#define mst1(x) memset(x, -1, sizeof(x))
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR1(i, n) for (int i = 1; i <= n; i++)
#define FORit(it, c)                                                           \
  for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define pb push_back
#define RI(x) scanf("%d", &x)
#define RID(x)                                                                 \
  int x;                                                                       \
  RI(x)
using namespace std;
typedef long long LL;
const int N = 2e5 + 7;
int a[N];

int main() {
  RID(n);
  LL sum = 0;
  FOR(i, n) {
    RI(a[i]);
    sum += a[i];
  }
  LL l = 0, res = 1LL << 62;
  FOR(i, n - 1) {
    l += a[i];
    LL now = l - (sum - l);
    if (now < 0)
      now = -now;
    res = min(res, now);
  }
  cout << res << endl;
}
Problem p03661 (C++)

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

int main() {
  long long int N, A, sum[100001] = {0}, Min = 1000000000000000000;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A;
    sum[i] = sum[i - 1] + A;
  }
  for (int i = 1; i < N; i++) {
    Min = min(Min, abs(sum[N] - 2 * sum[i]));
  }
  cout << Min;
}

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

int main() {
  long long int N, A, sum[200001] = {0}, Min = 1000000000000000000;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A;
    sum[i] = sum[i - 1] + A;
  }
  for (int i = 1; i < N; i++) {
    Min = min(Min, abs(sum[N] - 2 * sum[i]));
  }
  cout << Min;
}
Problem p03661 (C++)

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

const int MAXN = 100000 + 10;

int n;
int a[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin >> n;

  int s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }

  int s2 = a[0];
  int best = 100000LL;
  best *= best * best;

  for (int i = 1; i < n; i++) {
    best = min(best, abs(s2 - (s - s2)));
    s2 += a[i];
  }

  cout << best << "\n";
  return 0;
}


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

const int MAXN = 200000 + 10;

int n;
int a[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin >> n;

  int s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }

  int s2 = a[0];
  int best = 100000LL;
  best *= best * best;

  for (int i = 1; i < n; i++) {
    best = min(best, abs(s2 - (s - s2)));
    s2 += a[i];
  }

  cout << best << "\n";
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

typedef long long int lli;

const lli maxn = lli(1e5) + 5, inf = lli(1e18) + 5;

lli a[maxn];

int main(void) {
  lli n, tot = 0;
  scanf("%lld", &n);
  for (lli i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    tot += a[i];
  }

  lli cur = 0, res = inf;
  for (lli i = 0; i < n - 1; i++) {
    cur += a[i];
    res = min(res, llabs(cur - (tot - cur)));
  }
  printf("%lld\n", res);
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

typedef long long int lli;

const lli maxn = lli(2e5) + 5, inf = lli(1e18) + 5;

lli a[maxn];

int main(void) {
  lli n, tot = 0;
  scanf("%lld", &n);
  for (lli i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    tot += a[i];
  }

  lli cur = 0, res = inf;
  for (lli i = 0; i < n - 1; i++) {
    cur += a[i];
    res = min(res, llabs(cur - (tot - cur)));
  }
  printf("%lld\n", res);
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pl pair<ll, ll>
#define ps pair<string, string>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define f(i, a, b) for (ll i = (a); i < (b); i++)
#define fd(i, a, b) for (ll i = (a); i > (b); i--)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define x first
#define y second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld %lld", &a, &b)
#define slll(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define ss(s) scanf("%s", s)
#define pf printf
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%lld\n", n)
#define pfls(n) printf("%lld ", n)
#define pfci(n, ans) printf("Case %lld: %d\n", n, ans)
#define pfcl(n, ans) printf("Case %lld: %lld\n", n, ans)
#define pfcd(n, ans) printf("Case %lld: %lf\n", n, ans)
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(a, v) memset(a, v, sizeof(a))
#define MOD 1000000007
#define LG 16
#define mid ((l + r) / 2 + 1)
#define PI (acos(-1.0))
#define ppl pair<pl, ll>
#define PT pair<double, double>
#define IN(n) (2 * n - 1)
#define OUT(n) (2 * n)

using namespace std;

ll a[100006];
int main() {
  ll N;
  sl(N);
  ll sum = 0;
  f(i, 0, N) {
    sl(a[i]);
    sum += a[i];
    if (i)
      a[i] += a[i - 1];
  }
  ll ans = 1e18;
  f(i, 0, N - 1) ans = min(ans, llabs(sum - 2 * a[i]));
  pfl(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pl pair<ll, ll>
#define ps pair<string, string>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define f(i, a, b) for (ll i = (a); i < (b); i++)
#define fd(i, a, b) for (ll i = (a); i > (b); i--)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define x first
#define y second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld %lld", &a, &b)
#define slll(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define ss(s) scanf("%s", s)
#define pf printf
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%lld\n", n)
#define pfls(n) printf("%lld ", n)
#define pfci(n, ans) printf("Case %lld: %d\n", n, ans)
#define pfcl(n, ans) printf("Case %lld: %lld\n", n, ans)
#define pfcd(n, ans) printf("Case %lld: %lf\n", n, ans)
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(a, v) memset(a, v, sizeof(a))
#define MOD 1000000007
#define LG 16
#define mid ((l + r) / 2 + 1)
#define PI (acos(-1.0))
#define ppl pair<pl, ll>
#define PT pair<double, double>
#define IN(n) (2 * n - 1)
#define OUT(n) (2 * n)

using namespace std;

ll a[200006];
int main() {
  ll N;
  sl(N);
  ll sum = 0;
  f(i, 0, N) {
    sl(a[i]);
    sum += a[i];
    if (i)
      a[i] += a[i - 1];
  }
  ll ans = 1e18;
  f(i, 0, N - 1) ans = min(ans, llabs(sum - 2 * a[i]));
  pfl(ans);
}
Problem p03661 (C++)

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

const int maxn = 1e5 + 10;
const long long inf = 1e18 + 1;
long long s[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    s[i] = s[i - 1] + a;
  }
  long long ans = inf;
  for (int i = 1; i < n; ++i) {
    ans = min(ans, abs(s[i] + s[i] - s[n]));
  }
  cout << ans << endl;
  return 0;
}

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

const int maxn = 2e5 + 10;
const long long inf = 1e18 + 1;
long long s[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    s[i] = s[i - 1] + a;
  }
  long long ans = inf;
  for (int i = 1; i < n; ++i) {
    ans = min(ans, abs(s[i] + s[i] - s[n]));
  }
  cout << ans << endl;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <vector>

#include <iostream>
#include <sstream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAX = 1e5 + 5;

int a[MAX];

int main(void) {
  int N;
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);

  llint tot = 0;
  REP(i, N) tot += a[i];

  llint pref = 0;
  llint sol = inf;

  REP(i, N - 1) {
    pref += a[i];
    sol = min(sol, abs(2 * pref - tot));
  }

  printf("%lld\n", sol);

  return 0;
}


Fixed submission:
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <vector>

#include <iostream>
#include <sstream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAX = 2e5 + 5;

int a[MAX];

int main(void) {
  int N;
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);

  llint tot = 0;
  REP(i, N) tot += a[i];

  llint pref = 0;
  llint sol = inf;

  REP(i, N - 1) {
    pref += a[i];
    sol = min(sol, abs(2 * pref - tot));
  }

  printf("%lld\n", sol);

  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main() {
#ifdef local
  freopen("1.txt", "r", stdin);
#endif
  int n;
  long long a[100006];
  scanf("%d", &n);
  int i;
  scanf("%lld", &a[0]);
  for (i = 1; i < n; i++)
    scanf("%lld", &a[i]), a[i] += a[i - 1];
  long long mn = 0x3f3f3f3f3f3f3f3f;
  for (i = 0; i < n - 1; i++) {
    mn = min(mn, abs(a[n - 1] - 2 * a[i]));
  }
  printf("%lld", mn);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main() {
#ifdef local
  freopen("1.txt", "r", stdin);
#endif
  int n;
  long long a[200006];
  scanf("%d", &n);
  int i;
  scanf("%lld", &a[0]);
  for (i = 1; i < n; i++)
    scanf("%lld", &a[i]), a[i] += a[i - 1];
  long long mn = 0x3f3f3f3f3f3f3f3f;
  for (i = 0; i < n - 1; i++) {
    mn = min(mn, abs(a[n - 1] - 2 * a[i]));
  }
  printf("%lld", mn);
}
Problem p03661 (C++)

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

int main() {
  long long int a, b[20001], c = 0, d = 0, e = 0, f = 0, g = 1145141919810072;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < a; i++) {
    c += b[i];
  }
  for (int j = 0; j < a - 1; j++) {
    d += b[j];
    e = c - d;
    f = d - e;
    if (f < 0) {
      f = f * (-1);
    }
    if (g > f) {
      g = f;
    }
  }
  cout << g << endl;
  return 0;
}


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

int main() {
  long long int a, b[200001], c = 0, d = 0, e = 0, f = 0, g = 1145141919810072;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < a; i++) {
    c += b[i];
  }
  for (int j = 0; j < a - 1; j++) {
    d += b[j];
    e = c - d;
    f = d - e;
    if (f < 0) {
      f = f * (-1);
    }
    if (g > f) {
      g = f;
    }
  }
  cout << g << endl;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
// QWsin
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int maxn = 100000 + 10;

typedef long long ll;

ll sum;
int a[maxn];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  }

  ll cnt = 0, ans = 1ll << 60;
  for (int i = 1; i < n; ++i) {
    cnt += a[i];
    ans = min(ans, abs(sum - cnt - cnt));
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// QWsin
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int maxn = 200000 + 10;

typedef long long ll;

ll sum;
int a[maxn];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  }

  ll cnt = 0, ans = 1ll << 60;
  for (int i = 1; i < n; ++i) {
    cnt += a[i];
    ans = min(ans, abs(sum - cnt - cnt));
  }
  cout << ans << endl;
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(a) (int)a.size()
//---------------

const int N = 100005;
ll a[N];

int main() {
  int n;
  while (~scanf("%d", &n)) {
    ll sum = 0;
    rep(i, 0, n) {
      scanf("%lld", a + i);
      sum = sum + a[i];
    }
    ll ans = (1ll << 62), now = 0;
    rep(i, 0, n - 1) {
      now = now + a[i];
      ans = min(ans, abs(now - (sum - now)));
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(a) (int)a.size()
//---------------

const int N = 200005;
ll a[N];

int main() {
  int n;
  while (~scanf("%d", &n)) {
    ll sum = 0;
    rep(i, 0, n) {
      scanf("%lld", a + i);
      sum = sum + a[i];
    }
    ll ans = (1ll << 62), now = 0;
    rep(i, 0, n - 1) {
      now = now + a[i];
      ans = min(ans, abs(now - (sum - now)));
    }
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p03661 (C++)

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

int n, v[maxN];

long long sum;

long long ans;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &v[i]);
    sum += v[i];
  }
  long long crts = 0LL;
  ans = abs(sum - 2 * v[1]);
  for (int i = 1; i < n; ++i) {
    crts += v[i];
    if (abs(sum - 2 * crts) < ans)
      ans = abs(sum - 2 * crts);
  }
  printf("%lld\n", ans);
  return 0;
}


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

int n, v[maxN];

long long sum;

long long ans;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &v[i]);
    sum += v[i];
  }
  long long crts = 0LL;
  ans = abs(sum - 2 * v[1]);
  for (int i = 1; i < n; ++i) {
    crts += v[i];
    if (abs(sum - 2 * crts) < ans)
      ans = abs(sum - 2 * crts);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x & (-x)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define PI acos(-1.0)
#define LL long long
#define Inf (1LL << 62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
using namespace std;
const int mod = 1e9 + 7;
int main() {
  // input;output;
  int arr[Maxn];
  LL sum[Maxn], ans;
  int n;
  while (~scanf("%d", &n)) {
    ans = Inf;
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++)
      scanf("%d", arr + i), sum[i] = sum[i - 1] + arr[i];
    for (int i = 1; i < n; i++)
      ans = min(ans, abs(2 * sum[i] - sum[n]));
    printf("%lld\n", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x & (-x)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define PI acos(-1.0)
#define LL long long
#define Inf (1LL << 62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
using namespace std;
const int mod = 1e9 + 7;
int main() {
  // input;output;
  int arr[Maxn << 1];
  LL sum[Maxn << 1], ans;
  int n;
  while (~scanf("%d", &n)) {
    ans = Inf;
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++)
      scanf("%d", arr + i), sum[i] = sum[i - 1] + arr[i];
    for (int i = 1; i < n; i++)
      ans = min(ans, abs(2 * sum[i] - sum[n]));
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p03661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  // ifstream cin("input.in");
  // ofstream cout("output.out");
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long N, A[100009], S = 0;
  cin >> N;
  for (long i = 0; i < N; i++) {
    cin >> A[i];
    S += A[i];
  }
  long long D = 0, M = 2e18;
  for (long i = 0; i < N - 1; i++) {
    if (abs(S - 2 * (D + A[i])) < M)
      M = abs(S - 2 * (D + A[i]));
    D += A[i];
  }
  cout << M;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  // ifstream cin("input.in");
  // ofstream cout("output.out");
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long N, A[200009], S = 0;
  cin >> N;
  for (long i = 0; i < N; i++) {
    cin >> A[i];
    S += A[i];
  }
  long long D = 0, M = 2e18;
  for (long i = 0; i < N - 1; i++) {
    if (abs(S - 2 * (D + A[i])) < M)
      M = abs(S - 2 * (D + A[i]));
    D += A[i];
  }
  cout << M;
}