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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long W, std::vector<std::string> s) {
  vector<pair<ll, ll>> dir{pair<ll, ll>(-1, 0), pair<ll, ll>(1, 0),
                           pair<ll, ll>(0, -1), pair<ll, ll>(0, 1)};
  rep(i, H) {
    rep(j, W) {
      if (s[i][j] == '#') {
        bool ok = false;
        rep(k, 4) {
          ll tmpi = i + dir[k].first;
          ll tmpj = j + dir[k].second;
          if (!(tmpi < 0 || tmpi > H - 1 || tmpj < 0 || tmpj > W - 1)) {
            if (s[tmpi][tmpj] == '#') {
              ok = true;
            }
          }
        }
        if (!ok) {
          cout << "No" << endl;
          return;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return;
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> s(W);
  for (int i = 0; i < W; i++) {
    std::cin >> s[i];
  }
  solve(H, W, std::move(s));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long W, std::vector<std::string> s) {
  vector<pair<ll, ll>> dir{pair<ll, ll>(-1, 0), pair<ll, ll>(1, 0),
                           pair<ll, ll>(0, -1), pair<ll, ll>(0, 1)};
  rep(i, H) {
    rep(j, W) {
      if (s[i][j] == '#') {
        bool ok = false;
        rep(k, 4) {
          ll tmpi = i + dir[k].first;
          ll tmpj = j + dir[k].second;
          if (!(tmpi < 0 || tmpi > H - 1 || tmpj < 0 || tmpj > W - 1)) {
            if (s[tmpi][tmpj] == '#') {
              ok = true;
            }
          }
        }
        if (!ok) {
          cout << "No" << endl;
          return;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return;
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> s(H);
  for (int i = 0; i < H; i++) {
    std::cin >> s[i];
  }
  solve(H, W, std::move(s));
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using ll = long long;

int h, w, cnt;
string s[50];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool ans = 1;

int main() {
  cin >> h >> w;
  rep(i, h) cin >> s[i];
  rep(i, h) rep(j, w) {
    if (s[i][j] == '.')
      continue;
    cnt = 1;
    rep(dir, 4) {
      if (i + dx[dir] >= 0 && j + dy[dir] >= 0) {
        if (s[i + dx[dir]][j + dy[dir]] == '#')
          cnt++;
      }
    }
    if (cnt < 2)
      ans = 0;
  }
  cout << ((ans) ? "Yes" : "No") << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using ll = long long;

int h, w, cnt;
string s[50];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool ans = 1;

int main() {
  cin >> h >> w;
  rep(i, h) cin >> s[i];
  rep(i, h) rep(j, w) {
    if (s[i][j] == '.')
      continue;
    cnt = 1;
    rep(dir, 4) {
      if (i + dx[dir] >= 0 && i + dx[dir] < h && j + dy[dir] >= 0 &&
          j + dy[dir] < w) {
        if (s[i + dx[dir]][j + dy[dir]] == '#')
          cnt++;
      }
    }
    if (cnt < 2)
      ans = 0;
  }
  cout << ((ans) ? "Yes" : "No") << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  string s[50] = {};
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        int m = 0;
        if (s[i - 1][j] == '#' && i > 0)
          m = 1;
        if (s[i + 1][j] == '#' && i + 1 < h)
          m = 1;
        if (s[i][j - 1] == '#' && j > 0)
          m = 1;
        if (s[i][j + 1] == '#' && j + 1 < w)
          m = 1;
        if (m == 0) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  string s[50] = {};
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        bool y = 0;
        if (i && s[i - 1][j] == '#')
          y = 1;
        if (i + 1 < h && s[i + 1][j] == '#')
          y = 1;
        if (j && s[i][j - 1] == '#')
          y = 1;
        if (j + 1 < w && s[i][j + 1] == '#')
          y = 1;
        if (!y) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
}
Problem p03361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iomanip>
#include <iostream>

using namespace std;

#define rep(i, a, n) for (int i = (a); i < (n); i++)

void Main() {
  int h, w;
  cin >> h >> w;
  char S[h][w];
  rep(j, 0, w) {
    rep(i, 0, h) { cin >> S[j][i]; }
  }

  int cnt = 0;
  rep(j, 1, h + 1) {
    rep(i, 1, w + 1) {
      if (S[i][j] == '#' && S[i][j - 1] != '#' && S[i - 1][j] != '#' &&
          S[i][j + 1] != '#' && S[i + 1][j] != '#')
        cnt++;
    }
  }

  if (0) {
    rep(j, 0, h) {
      rep(i, 0, w) { cout << S[j][i]; }
      cout << endl;
    }
  }

  cnt == 0 ? cout << "Yes" << endl : cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);                 // 標準入出力高速化
  std::ios_base::sync_with_stdio(false); // SとS++の入出力出力を非同期
  Main();
}

Fixed submission:
#include <iomanip>
#include <iostream>

using namespace std;

#define rep(i, a, n) for (int i = (a); i < (n); i++)

void Main() {
  int h, w;
  cin >> h >> w;
  char S[55][55];
  rep(j, 1, w + 1) { rep(i, 1, h + 1) cin >> S[j][i]; }

  int cnt = 0;
  rep(j, 1, h + 1) {
    rep(i, 1, w + 1) {
      if (S[i][j] == '#' && S[i][j - 1] != '#' && S[i - 1][j] != '#' &&
          S[i][j + 1] != '#' && S[i + 1][j] != '#')
        cnt++;
    }
  }

  if (0) {
    rep(j, 0, h) {
      rep(i, 0, w) { cout << S[j][i]; }
      cout << endl;
    }
  }

  cnt == 0 ? cout << "Yes" << endl : cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);                 // 標準入出力高速化
  std::ios_base::sync_with_stdio(false); // SとS++の入出力出力を非同期
  Main();
}
Problem p03361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
int main() {
  int h, w;
  cin >> h >> w;
  char A[h][w];
  bool can = true;

  REP(i, h) {
    REP(j, w) { cin >> A[i][j]; }
  }

  REP(i, h) {
    REP(j, w) {
      if (A[i][j] == '#' && A[i - 1][j] != '#' && A[i + 1][j] != '#' &&
          A[i][j - 1] != '#' && A[i][j + 1] != '#') {
        can = false;
      }
    }
  }
  if (can)
    cout << "Yes" << endl;
  else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
int main() {
  int h, w;
  cin >> h >> w;
  char A[h + 10][w + 10];
  bool can = true;

  REP(i, h) {
    REP(j, w) { cin >> A[i][j]; }
  }

  REP(i, h) {
    REP(j, w) {
      if (A[i][j] == '#' && A[i - 1][j] != '#' && A[i + 1][j] != '#' &&
          A[i][j - 1] != '#' && A[i][j + 1] != '#') {
        can = false;
      }
    }
  }
  if (can)
    cout << "Yes" << endl;
  else {
    cout << "No" << endl;
  }
}
Problem p03361 (C++)

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

int main() {
  int H, W;
  std::cin >> H >> W;

  std::string grid[50];
  for (int i = 0; i < H; ++i)
    std::cin >> grid[i];

  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (grid[i][j] == '#') {
        bool paintable = false;
        for (int k = 0; k < 4; ++k) {
          if (i + dy[k] >= 0 && i + dy[k] <= H && j + dx[k] >= 0 &&
              j + dx[k] <= W) {
            char tempDot = grid[i + dy[k]][j + dx[k]];
            if (tempDot == '#')
              paintable = true;
          }
        }
        if (!paintable) {
          std::cout << "No";
          return 0;
        }
      }
    }
  }
  std::cout << "Yes";
  return 0;
}


Fixed submission:
#include <iostream>

int main() {
  int H, W;
  std::cin >> H >> W;

  std::string grid[60];
  for (int i = 0; i < H; ++i)
    std::cin >> grid[i];

  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (grid[i][j] == '#') {
        bool paintable = false;
        for (int k = 0; k < 4; ++k) {
          if (i + dy[k] >= 0 && i + dy[k] <= H && j + dx[k] >= 0 &&
              j + dx[k] <= W) {
            char tempDot = grid[i + dy[k]][j + dx[k]];
            if (tempDot == '#')
              paintable = true;
          }
        }
        if (!paintable) {
          std::cout << "No";
          return 0;
        }
      }
    }
  }
  std::cout << "Yes";
  return 0;
}
Problem p03361 (C++)

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

int main() {
  bool flag = 1;
  int H, W;
  cin >> H >> W;
  string Pic[W + 2];
  string frame;
  for (int i = 0; i < H + 2; i++)
    frame += ".";
  Pic[0] = frame;
  Pic[H + 1] = frame;

  for (int i = 1; i <= H; i++) {
    cin >> Pic[i];
    Pic[i] = "." + Pic[i] + ".";
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (Pic[i][j] == '#') {
        if (Pic[i + 1][j] == '#' || Pic[i - 1][j] == '#' ||
            Pic[i][j + 1] == '#' || Pic[i][j - 1] == '#') {
          flag = 1;
        } else {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;

int main() {
  bool flag = 1;
  int H, W;
  cin >> H >> W;
  string Pic[H + 2];
  string frame;
  for (int i = 0; i < H + 2; i++)
    frame += ".";
  Pic[0] = frame;
  Pic[H + 1] = frame;

  for (int i = 1; i <= H; i++) {
    cin >> Pic[i];
    Pic[i] = "." + Pic[i] + ".";
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (Pic[i][j] == '#') {
        if (Pic[i + 1][j] == '#' || Pic[i - 1][j] == '#' ||
            Pic[i][j + 1] == '#' || Pic[i][j - 1] == '#') {
          flag = 1;
        } else {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03361 (C++)

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

using namespace std;

#define int long long
#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }

int H, W;
string s[51];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> H >> W;
  FOR(i, 1, H + 1) FOR(j, 1, W + 1) cin >> s[i][j];
  FOR(i, 1, H + 1) FOR(j, 1, W + 1) {
    if (s[i][j] == '#') {
      if (s[i][j + 1] == '.' && s[i][j - 1] == '.' && s[i + 1][j] == '.' &&
          s[i - 1][j] == '.') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }

int H, W;
char s[100][100];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> H >> W;
  FOR(i, 1, H + 1) FOR(j, 1, W + 1) cin >> s[i][j];
  FOR(i, 1, H + 1) FOR(j, 1, W + 1) {
    if (s[i][j] == '#') {
      if (s[i][j + 1] == '.' && s[i][j - 1] == '.' && s[i + 1][j] == '.' &&
          s[i - 1][j] == '.') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int tx[8] = {-1, 0, 1, -1, 1, -1, 0, 1},
          ty[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define fr first
#define sc second

bool bpr[100010];

void sieve(int n) {
  for (int i = 0; i <= n; i++)
    bpr[i] = true;
  bpr[0] = bpr[1] = false;
  for (int i = 2; i <= n; i++) {
    if (bpr[i])
      for (int j = i * 2; j <= n; j += i)
        bpr[j] = false;
  }
}

int main() {
  int n, a[100];
  cin >> n;
  vector<int> v(20000);
  bool b[100010] = {0};
  sieve(70000);
  int cnt = 0;
  for (int i = 2; i <= 55555; i++) {
    if (bpr[i] && i % 10 == 1) {
      a[cnt] = i;
      cnt++;
    }
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int tx[8] = {-1, 0, 1, -1, 1, -1, 0, 1},
          ty[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define fr first
#define sc second

bool bpr[100010];

void sieve(int n) {
  for (int i = 0; i <= n; i++)
    bpr[i] = true;
  bpr[0] = bpr[1] = false;
  for (int i = 2; i <= n; i++) {
    if (bpr[i])
      for (int j = i * 2; j <= n; j += i)
        bpr[j] = false;
  }
}

int main() {
  int n, a[1000000];
  cin >> n;
  vector<int> v(20000);
  bool b[100010] = {0};
  sieve(70000);
  int cnt = 0;
  for (int i = 2; i <= 55555; i++) {
    if (bpr[i] && i % 10 == 1) {
      a[cnt] = i;
      cnt++;
    }
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << endl;
}
Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n, p[60000], top;
bool f[60000] = {1, 1};
int main() {
  for (int i = 2; i <= 55555; i++) {
    if (f[i])
      continue;
    for (int j = i * i; j <= 55555; j += i)
      f[j] = 1;
    p[++top] = i;
  }
  scanf("%d", &n);
  for (int i = 1; i <= top; i++) {
    if (p[i] % 10 == 1)
      printf("%d ", p[i]), n--;
    if (!n)
      break;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n, p[60000], top;
bool f[60000] = {1, 1};
int main() {
  for (int i = 2; i <= 55555; i++) {
    if (f[i])
      continue;
    for (ll j = 1ll * i * i; j <= 55555; j += i)
      f[j] = 1;
    p[++top] = i;
  }
  scanf("%d", &n);
  for (int i = 1; i <= top; i++) {
    if (p[i] % 10 == 1)
      printf("%d ", p[i]), n--;
    if (!n)
      break;
  }
  return 0;
}
Problem p03362 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
vector<int> vec;
int prime(int a) {
  int i;
  for (i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int n;
  int i, ans = 0;
  scanf("%d", &n);
  for (i = 11; ans != n; i += 30) {
    if (prime(i)) {
      vec.push_back(i);
    }
  }
  int len = vec.size();
  for (i = 0; i < len - 1; i++) {
    printf("%d ", vec[i]);
  }
  printf("%d\n", vec[i]);
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
vector<int> vec;
int prime(int a) {
  int i;
  for (i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int n;
  int i, ans = 0;
  scanf("%d", &n);
  for (i = 11; ans != n; i += 30) {
    if (prime(i)) {
      vec.push_back(i);
      ans++;
    }
  }
  int len = vec.size();
  for (i = 0; i < len - 1; i++) {
    printf("%d ", vec[i]);
  }
  printf("%d\n", vec[i]);
  return 0;
}
Problem p03362 (C++)

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

bool isPrime[100000];

int main() {
  for (int i = 2; i < 10000; i++) {
    isPrime[i] = true;
  }
  for (int i = 2; i < 10000; i++) {
    for (int j = i * i; j < 10000; j++) {
      isPrime[j] = false;
    }
  }
  int N;
  cin >> N;
  for (int i = 11; N; i += 10) {
    if (isPrime[i]) {
      N--;
      cout << i << " \n"[N == 0];
    }
  }
}

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

bool isPrime[100000];

int main() {
  for (int i = 2; i < 10000; i++) {
    isPrime[i] = true;
  }
  for (int i = 2; i < 10000; i++) {
    for (int j = i * i; j < 10000; j += i) {
      isPrime[j] = false;
    }
  }
  int N;
  cin >> N;
  for (int i = 11; N; i += 10) {
    if (isPrime[i]) {
      N--;
      cout << i << " \n"[N == 0];
    }
  }
}
Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const int nmax = 55555;
int prime[nmax + 10];
vector<int> a;
bool isprime(int x) {
  if (x <= 1)
    return 0;
  if (x == 2)
    return 1;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0)
      return 0;
  return 1;
}
int main() {
  IO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  for (int i = 1; i <= nmax; i++)
    prime[i] = 1;
  prime[1] = 0;
  for (int i = 2; i <= nmax; i++)
    if (prime[i]) {
      a.push_back(i);
      for (int j = 2; j * i <= nmax; j++)
        prime[i * j] = 0;
    }
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < a.size(); i++)
    if (a[i] % 5 == 1) {
      cnt++;
      cout << a[i] << " ";
      if (cnt == n)
        break;
    }
  fflush(stdout);
  return 0;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const int nmax = 55555;
int prime[nmax + 10];
vector<int> a;
bool isprime(int x) {
  if (x <= 1)
    return 0;
  if (x == 2)
    return 1;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0)
      return 0;
  return 1;
}
int main() {
  IO;
  for (int i = 1; i <= nmax; i++)
    prime[i] = 1;
  prime[1] = 0;
  for (int i = 2; i <= nmax; i++)
    if (prime[i]) {
      a.push_back(i);
      for (int j = 2; j * i <= nmax; j++)
        prime[i * j] = 0;
    }
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < a.size(); i++)
    if (a[i] % 5 == 1) {
      cnt++;
      cout << a[i] << " ";
      if (cnt == n)
        break;
    }
  fflush(stdout);
  return 0;
}
Problem p03362 (C++)

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

typedef pair<int, int> P;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(x) (x).begin(), (x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool isprime(int num) {
  for (int i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int counter = 0;
  int kouho = 6;
  while (counter <= n) {
    if (isprime(kouho)) {
      a[counter] = kouho;
      counter++;
    }
    kouho += 5;
  }
  rep(i, n) { cout << a[i] << " "; }
  cout << endl;
}

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

typedef pair<int, int> P;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(x) (x).begin(), (x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool isprime(int num) {
  for (int i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int counter = 0;
  int kouho = 6;
  while (counter < n) {
    if (isprime(kouho)) {
      a[counter] = kouho;
      counter++;
    }
    kouho += 5;
  }
  rep(i, n) { cout << a[i] << " "; }
  cout << endl;
}
Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
bitset<maxn> pr;
int n;
void sieve() {
  pr.set();
  pr[0] = pr[1] = 0;
  for (int i = 2; i * i <= n; ++i) {
    if (pr[i])
      for (int j = i * i; j <= n; j += i)
        pr[j] = 0;
  }
}
int main() {
  n = maxn - 5;
  sieve();
  cin >> n;
  for (int i = 2, cn = 0; cn < n; i++) {
    if (pr[i] and i % 5 == 0) {
      cout << i << ' ';
      cn++;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
bitset<maxn> pr;
int n;
void sieve() {
  pr.set();
  pr[0] = pr[1] = 0;
  for (int i = 2; i * i <= n; ++i) {
    if (pr[i])
      for (int j = i * i; j <= n; j += i)
        pr[j] = 0;
  }
}
int main() {
  n = maxn - 5;
  sieve();
  cin >> n;
  for (int i = 2, cn = 0; cn < n; i++) {
    if (pr[i] and i % 5 == 1) {
      cout << i << ' ';
      cn++;
    }
  }
  return 0;
}
Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) int(x.size())
#define IN(a) cin >> (a)
#define OUT(a) cout << (a) << endl
typedef pair<int, int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
// エラトステネスの篩
int prime[MAX];
bool is_prime[MAX + 1];

void sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2; i * j <= n; j++)
        is_prime[i * j] = false;
    }
  }
}
int main() {
  int n;
  cin >> n;
  sieve(55555);
  vector<int> ans(n);
  int i = 0;
  int w = 0;
  while (prime[i]) {
    int t = prime[i] % 5;
    if (t == 1) {
      ans[w++] = prime[i];
    }
    i++;
  }
  REP(i, n) OUT(ans[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) int(x.size())
#define IN(a) cin >> (a)
#define OUT(a) cout << (a) << endl
typedef pair<int, int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
// エラトステネスの篩
int prime[MAX];
bool is_prime[MAX + 1];

void sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2; i * j <= n; j++)
        is_prime[i * j] = false;
    }
  }
}
int main() {
  int n;
  cin >> n;
  sieve(55555);
  vector<int> ans(n);
  int i = 0;
  int w = 0;
  while (prime[i]) {
    int t = prime[i] % 5;
    if (t == 1) {
      ans[w++] = prime[i];
    }
    i++;
    if (w >= n)
      break;
  }
  REP(i, n) OUT(ans[i]);
  return 0;
}
Problem p03362 (C++)

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

int main(void) {
  int p[300] = {3};
  int cnt = 1, i, n = 5;

  while (cnt < 55) {
    for (i = 0; i < cnt; i++) {
      if (n % p[i] == 0) {
        goto next;
      }
    }
    p[cnt] = n;
    cnt++;

  next:
    n += 2;
  }

  cin >> n;

  cnt = 1;
  i = 0;
  while (cnt <= n) {
    if (p[i] % 10 == 3) {
      cout << p[i];
      if (cnt != n) {
        cout << ' ';
      }
      cnt++;
    }
    i++;
  }

  cout << endl;

  return 0;
}


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

int main(void) {
  int p[300] = {3};
  int cnt = 1, i, n = 5;

  while (cnt < 300) {
    for (i = 0; i < cnt; i++) {
      if (n % p[i] == 0) {
        goto next;
      }
    }
    p[cnt] = n;
    cnt++;

  next:
    n += 2;
  }

  cin >> n;

  cnt = 1;
  i = 0;
  while (cnt <= n) {
    if (p[i] % 10 == 3) {
      cout << p[i];
      if (cnt != n) {
        cout << ' ';
      }
      cnt++;
    }
    i++;
  }

  cout << endl;

  return 0;
}
Problem p03362 (C++)

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

#define EPS (1e-7)
#define INF (99999999999L)
#define PI (acos(-1))

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

#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;

bool isprime[55556];

int main() {
  ll n;
  cin >> n;
  REP(i, 55556) isprime[i] = true;
  isprime[0] = false, isprime[1] = false;
  for (int i = 2; i * i <= 55555; ++i) {
    if (isprime[i]) {
      for (int j = 2; i * j <= 55555; ++j) {
        isprime[i * j] = false;
      }
    }
  }
  vector<int> prime;
  REP(i, 55556) if (isprime[i]) prime.push_back(i);
  ll sum = 0;
  REP(i, 5) {
    sum += prime[i];
    cout << prime[i] << " ";
  }
  ll cnt = 0;
  for (int i = 5; i < n; i++) {
    sum += prime[i];
    sum -= prime[i - 5 - cnt];
    if (sum % prime[i - 5 - cnt + 1] != 0) {
      ++n;
      sum += prime[i - 5 - cnt];
      ++cnt;
      sum -= prime[i];
      continue;
    }
    cout << prime[i] << " ";
  }
  return 0;
}


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

#define EPS (1e-7)
#define INF (99999999999L)
#define PI (acos(-1))

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

#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;

bool isprime[55556];

int main() {
  ll n;
  cin >> n;
  REP(i, 55556) isprime[i] = true;
  isprime[0] = false, isprime[1] = false;
  for (int i = 2; i * i <= 55555; ++i) {
    if (isprime[i]) {
      for (int j = 2; i * j <= 55555; ++j) {
        isprime[i * j] = false;
      }
    }
  }
  vector<int> prime;
  REP(i, 55556) if (isprime[i] && i % 5 == 1) prime.push_back(i);
  REP(i, n) { cout << prime[i] << " "; }
  return 0;
}
Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const int MAX = 55555;
  vector<bool> isp(MAX + 1, true);
  vector<int> ans;
  for (int p = 2; p <= MAX; p++) {
    if (isp[p]) {
      if (p % 5 == 1) {
        ans.push_back(p);
      }
      for (int kp = p * p; kp <= MAX; kp += p)
        isp[kp] = false;
    }
  }
  int N;
  while (cin >> N) {
    for (int i = 0; i < N; i++)
      cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const int MAX = 55555;
  vector<bool> isp(MAX + 1, true);
  vector<int> ans;
  for (int p = 2; p <= MAX; p++) {
    if (isp[p]) {
      if (p % 5 == 1) {
        ans.push_back(p);
      }
      for (int kp = p + p; kp <= MAX; kp += p)
        isp[kp] = false;
    }
  }
  int N;
  while (cin >> N) {
    for (int i = 0; i < N; i++)
      cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
Problem p03362 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;

  vector<ll> primes;
  primes.push_back(2);
  vector<ll> ans;
  for (int i = 3; i < 55555; ++i) {
    if (ans.size() >= n)
      break;
    bool isPrime = true;
    for (const auto &prime : primes) {
      if (i % prime == 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) {
      primes.push_back(i);
      if (i % 5 == 1)
        ans.push_back(i);
    }
  }

  rep(i, 6) cout << ans.at(i) << " ";
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;

  vector<ll> primes;
  primes.push_back(2);
  vector<ll> ans;
  for (int i = 3; i < 55555; ++i) {
    if (ans.size() >= n)
      break;
    bool isPrime = true;
    for (const auto &prime : primes) {
      if (i % prime == 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) {
      primes.push_back(i);
      if (i % 5 == 1)
        ans.push_back(i);
    }
  }

  rep(i, n) cout << ans.at(i) << " ";
  cout << endl;
  return 0;
}
Problem p03362 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <time.h>
#include <vector>
using namespace std;
bool prime(int i) {
  int num = 0;
  for (int j = 1; j <= i; j++)
    if (i % j == 0)
      num++;
  if (num == 2)
    return true;
  return false;
}
int main() {
  int n, sum = 0;
  cin >> n;
  for (int i = 2; i <= 55555; i++) {
    if (prime(i) && i % 5 == 1) {
      sum++;
      if (sum <= n)
        cout << i << " ";
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <time.h>
#include <vector>
using namespace std;
bool prime(int i) {
  int num = 0;
  for (int j = 1; j <= i; j++)
    if (i % j == 0)
      num++;
  if (num == 2)
    return true;
  return false;
}
int main() {
  int n, sum = 0;
  cin >> n;
  for (int i = 2; i <= 55555; i++) {
    if (prime(i) && i % 5 == 1) {
      sum++;
      if (sum <= n)
        cout << i << " ";
      else
        break;
    }
  }
  return 0;
}
Problem p03363 (C++)

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

using namespace std;
map<long long, int> mp;
int arr[100100];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
  }

  long long ans = 0;
  mp[0]++;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += arr[i];
    if (mp.count(sum))
      ans += mp[sum];
    mp[sum]++;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
map<long long, int> mp;
int arr[200100];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
  }

  long long ans = 0;
  mp[0]++;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += arr[i];
    if (mp.count(sum))
      ans += mp[sum];
    mp[sum]++;
  }
  cout << ans << endl;

  return 0;
}
Problem p03363 (C++)

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

int a[200010];
long long s[200010];
int main() {
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (int i = 1; i <= n; i++)
    s[i] = s[i - 1] + a[i];
  sort(s, s + n + 1);
  for (int i = 0, j; i <= n; i = j) {
    for (j = i; s[i] == s[j]; j++)
      ;
    ans += 1ll * (j - i) * (j - i - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;

int a[200010];
long long s[200010];
int main() {
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (int i = 1; i <= n; i++)
    s[i] = s[i - 1] + a[i];
  sort(s, s + n + 1);
  for (int i = 0, j; i <= n; i = j) {
    for (j = i; j <= n && s[i] == s[j]; j++)
      ;
    ans += 1ll * (j - i) * (j - i - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <map>

using ll = long long;

ll A[int(1e5) + 100];

int main() {
  int n;
  std::map<ll, int> s;
  std::cin >> n;

  ll cnt = 0;

  ++s[0];
  for (int i = 0; i < n; ++i) {
    std::cin >> A[i + 1];

    A[i + 1] += A[i];

    cnt += s[A[i + 1]];

    ++s[A[i + 1]];
  }

  std::cout << cnt << std::endl;
}

Fixed submission:
#include <iostream>
#include <map>

using ll = long long;

ll A[int(2e5) + 100];

int main() {
  int n;
  std::map<ll, int> s;
  std::cin >> n;

  ll cnt = 0;

  ++s[0];
  for (int i = 0; i < n; ++i) {
    std::cin >> A[i + 1];

    A[i + 1] += A[i];

    cnt += s[A[i + 1]];

    ++s[A[i + 1]];
  }

  std::cout << cnt << std::endl;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
LL SUM, sum[100050], n, a[100050];
map<LL, bool> vis;
map<LL, int> dis;
int main() {
  SUM = 0;
  dis.clear();
  vis.clear();
  memset(sum, 0, sizeof(sum));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    if (vis[sum[i]] == 0) {
      vis[sum[i]] = 1;
      dis[sum[i]]++;
    } else
      dis[sum[i]]++;
  }
  for (int i = n; i >= 1; i--) {
    if (sum[i] == 0)
      SUM++;
    if (vis[sum[i]] == 1 && dis[sum[i]] > 1) {
      SUM += (dis[sum[i]] - 1);
      dis[sum[i]]--;
    }
  }
  printf("%lld\n", SUM);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
LL SUM, sum[200050], n, a[200050];
map<LL, bool> vis;
map<LL, int> dis;
int main() {
  SUM = 0;
  dis.clear();
  vis.clear();
  memset(sum, 0, sizeof(sum));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    if (vis[sum[i]] == 0) {
      vis[sum[i]] = 1;
      dis[sum[i]]++;
    } else
      dis[sum[i]]++;
  }
  for (int i = n; i >= 1; i--) {
    if (sum[i] == 0)
      SUM++;
    if (vis[sum[i]] == 1 && dis[sum[i]] > 1) {
      SUM += (dis[sum[i]] - 1);
      dis[sum[i]]--;
    }
  }
  printf("%lld\n", SUM);
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

using namespace std;

typedef long long ll;

ll vs[100000 + 10];
ll cs[100000 + 10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) { scanf("%lld", &vs[i]); }
  REP(i, n) { cs[i + 1] = cs[i] + vs[i]; }
  map<ll, ll> mm;
  REP(i, n + 1) { mm[cs[i]]++; }

  ll res = 0;
  FOR(it, mm) {
    ll k = it->second;
    res += k * (k - 1) / 2;
  }
  cout << res << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

using namespace std;

typedef long long ll;

ll vs[200000 + 10];
ll cs[200000 + 10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) { scanf("%lld", &vs[i]); }
  REP(i, n) { cs[i + 1] = cs[i] + vs[i]; }
  map<ll, ll> mm;
  REP(i, n + 1) { mm[cs[i]]++; }

  ll res = 0;
  FOR(it, mm) {
    ll k = it->second;
    res += k * (k - 1) / 2;
  }
  cout << res << endl;

  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
static const ll maxLL = (ll)1 << 62;
const int mod = 1000000007;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

#define int ll
signed main() {
  map<ll, ll> mp;
  mp[0]++;
  int n;
  cin >> n;
  int a[100010];
  ll s = 0;

  rep(i, 0, n) {
    cin >> a[i];
    s += a[i];
    mp[s]++;
  }

  ll ans = 0;
  for (auto kv : mp) {
    ans += kv.se * (kv.se - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
static const ll maxLL = (ll)1 << 62;
const int mod = 1000000007;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

#define int ll
signed main() {
  map<ll, ll> mp;
  mp[0]++;
  int n;
  cin >> n;
  int a[200010];
  ll s = 0;

  rep(i, 0, n) {
    cin >> a[i];
    s += a[i];
    mp[s]++;
  }

  ll ans = 0;
  for (auto kv : mp) {
    ans += kv.se * (kv.se - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> sum(n, 0);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < i + 1; j++) {
      sum[j] += a[i];
      if (sum[j] == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> sum(n, 0);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sum[0] = a[0];
  for (int i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + a[i];
  }

  unordered_map<ll, ll> mp;
  mp[0] = 1;
  for (int i = 0; i < n; i++) {
    mp[sum[i]] += 1;
  }

  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    ans += (itr->second) * (itr->second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> A;
  rep(i, n) cin >> A[i];
  // 累積和
  vector<ll> s(n + 1, 0);
  rep(i, n) s[i + 1] = s[i] + A[i];

  // sort(s.begin(),s.end());

  map<ll, ll> hindo;
  rep(i, n + 1) {
    if (hindo.count(s[i]))
      hindo[s[i]]++;
    else
      hindo[s[i]] = 1;
  }

  ll sum = 0;
  for (auto p : hindo) {
    ll n = p.second;
    sum += n * (n - 1) / 2;
  }

  cout << sum << endl;
}

// RE

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  // 累積和
  vector<ll> s(n + 1, 0);
  rep(i, n) s[i + 1] = s[i] + A[i];

  // sort(s.begin(),s.end());

  map<ll, ll> hindo;
  rep(i, n + 1) {
    if (hindo.count(s[i]))
      hindo[s[i]]++;
    else
      hindo[s[i]] = 1;
  }

  ll sum = 0;
  for (auto p : hindo) {
    ll n = p.second;
    sum += n * (n - 1) / 2;
  }

  cout << sum << endl;
}

// RE
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define LL long long
#define pb push_back
#define ls rt << 1, l, m
#define rs rt << 1 | 1, m + 1, r
#define mem(a, b) memset(a, b, sizeof(a))

const int N = 1e5 + 5;
int a[N];
map<LL, int> mp;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  mp[0]++;
  LL sum = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    ans += mp[sum];
    mp[sum]++;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define LL long long
#define pb push_back
#define ls rt << 1, l, m
#define rs rt << 1 | 1, m + 1, r
#define mem(a, b) memset(a, b, sizeof(a))

const int N = 2e5 + 5;
int a[N];
map<LL, int> mp;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  mp[0]++;
  LL sum = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    ans += mp[sum];
    mp[sum]++;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03363 (C++)

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

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;

int n;
ll a[N], sum[N];
map<ll, int> s;

int main() {
  scanf("%d", &n);
  ll ans = 0;
  s[0]++;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    ans += s[sum[i]];
    s[sum[i]]++;
  }
  printf("%lld\n", ans);
  return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;

int n;
ll a[N], sum[N];
map<ll, int> s;

int main() {
  scanf("%d", &n);
  ll ans = 0;
  s[0]++;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    ans += s[sum[i]];
    s[sum[i]]++;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03363 (C++)

Buggy submission (status: Runtime Error):
// InTheNameOfGod
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, j, k) for (int i = j; i < k; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; i--)
#define pb push_back
#define lb(i) i & (-i);
const int maxn = 1e5 + 5;
ll n, a[maxn], s;
map<ll, int> mp;
ll re;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  mp[0]++;
  rep(i, 0, n) {
    cin >> a[i];
    s += a[i];
    re += mp[s];
    mp[s]++;
  }
  cout << re;
  return 0;
}


Fixed submission:
// InTheNameOfGod
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, j, k) for (int i = j; i < k; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; i--)
#define pb push_back
#define lb(i) i & (-i);
const int maxn = 2e5 + 5;
ll n, a[maxn], s;
map<ll, int> mp;
ll re;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  mp[0]++;
  rep(i, 0, n) {
    cin >> a[i];
    s += a[i];
    re += mp[s];
    mp[s]++;
  }
  cout << re;
  return 0;
}
Problem p03363 (C++)

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

using namespace std;

long long S[200500];

int main() {

  int Test;
  scanf("%d", &Test);
  while (Test--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      int a;
      scanf("%d", &a);
      S[i] = S[i - 1] + a;
    }
    long long ans = 0;
    sort(S, S + n + 1);
    for (int i = 0; i <= n;) {
      int j = i;
      while (j <= n && S[i] == S[j])
        j++;
      ans += (long long)(j - i - 1) * (j - i) / 2;
      i = j;
    }
    printf("%lld\n", ans);
  }

  return 0;
}

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

using namespace std;

long long S[200500];

int main() {
  int Test = 1;
  while (Test--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      int a;
      scanf("%d", &a);
      S[i] = S[i - 1] + a;
    }
    long long ans = 0;
    sort(S, S + n + 1);
    for (int i = 0; i <= n;) {
      int j = i;
      while (j <= n && S[i] == S[j])
        j++;
      ans += (long long)(j - i - 1) * (j - i) / 2;
      i = j;
    }
    printf("%lld\n", ans);
  }

  return 0;
}