alexjercan/bugnet huggingface dataset:
Problem p00828 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

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

int n, m, p;

int win(int ba[8][8][8], int win) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      for (int k = 0; k < 8; k++) {
        for (int l = 0; l < 17; l++) {
          int cnt = 0;
          for (int x = 0; x < 8; x++) {
            int tx = i + x * dx[l];
            int ty = j + x * dy[l];
            int tz = k + x * dz[l];
            if (tx >= n || ty >= n || tz >= n || tx < 0 || ty < 0 || tz < 0)
              break;
            if (win == ba[tx][ty][tz])
              cnt++;
            else
              cnt = 0;
            if (cnt >= m)
              return 1;
          }
        }
      }
    }
  }
  return 0;
}

int main() {
  while (cin >> n >> m >> p && n) {
    int ba[8][8][8] = {};
    int sz[8][8] = {};

    int flag = 0;
    for (int i = 1; i <= p; i++) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      if (flag)
        continue;
      ba[x][y][sz[x][y]++] = (i & 1 ? 2 : 1);
      if (win(ba, (i & 1 ? 2 : 1))) {
        if (i % 2 == 0)
          cout << "White";
        else
          cout << "Black";

        cout << " " << i << endl;
        flag = 1;
      }
    }
    if (!flag)
      cout << "Draw" << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

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

int n, m, p;

int win(int ba[8][8][8 * 8 * 8], int win) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      for (int k = 0; k < 8 * 8 * 8; k++) {
        for (int l = 0; l < 17; l++) {
          int cnt = 0;
          for (int x = 0; x < 8; x++) {
            int tx = i + x * dx[l];
            int ty = j + x * dy[l];
            int tz = k + x * dz[l];
            if (tx >= n || ty >= n || tz >= n || tx < 0 || ty < 0 || tz < 0)
              break;
            if (win == ba[tx][ty][tz])
              cnt++;
            else
              cnt = 0;
            if (cnt >= m)
              return 1;
          }
        }
      }
    }
  }
  return 0;
}

int main() {
  while (cin >> n >> m >> p && n) {
    int ba[8][8][8 * 8 * 8] = {};
    int sz[8][8] = {};

    int flag = 0;
    for (int i = 1; i <= p; i++) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      if (flag)
        continue;
      ba[x][y][sz[x][y]++] = (i & 1 ? 2 : 1);
      if (win(ba, (i & 1 ? 2 : 1))) {
        if (i % 2 == 0)
          cout << "White";
        else
          cout << "Black";

        cout << " " << i << endl;
        flag = 1;
      }
    }
    if (!flag)
      cout << "Draw" << endl;
  }
}
Problem p00829 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  while (n--) {
    vector<ll> e(9);
    loop(9, i) {
      string s;
      cin >> s;
      e[i] = stoll(s, nullptr, 16) % (1ll << 32);
    }
    ll ans = 0;
    loop(32, i) {
      ll sum = 0;
      ll mask = (1 << i) - 1;
      loop(8, j) sum += ans ^ (mask & e[j]);
      loop(8, j) sum ^= e[j];
      sum &= (1ll << i);
      ans |= (sum ^ (e[8] & (1ll << i)));
    }
    cout << hex << ans << endl;
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  stoi


Fixed submission:

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  while (n--) {
    ll e = 0;
    loop(8, i) {
      string s;
      cin >> s;
      e += stoi("0x" + s, nullptr, 16);
      e %= 1ll << 32;
    }
    string s;
    cin >> s;
    cout << hex << (e ^ stoi("0x" + s, nullptr, 16));
  }
  return 0;
}
Problem p00831 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool check(string a, string b, int d) {
  if (a.size() < b.size())
    swap(a, b);
  if (a == b)
    return 1;
  if (d == 0 || a.empty())
    return 0;

  // erase
  for (int i = 0; i < a.size(); i++) {
    string t = a;
    t.erase(t.begin() + i);
    if (check(t, b, d - 1))
      return 1;
  }

  if (a.size() != b.size())
    return 0;

  // swap
  for (int i = 0; i < (int)a.size() - 1; i++) {
    swap(a[i], a[i + 1]);
    if (check(a, b, d - 1))
      return 1;
    swap(a[i], a[i + 1]);
  }

  // change
  for (int i = 0; i < b.size(); i++) {
    char ch = a[i];
    if (a[i] != b[i])
      a[i] = b[i];
    if (check(a, b, d - 1))
      return 1;
    a[i] = ch;
  }
  return 0;
}

int main() {
  int n, d;
  while (cin >> n, n) {
    cin >> d;
    string str[201];
    for (int i = 0; i < n; i++)
      cin >> str[i];
    sort(str, str + n);

    int cnt = 0;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
        if (check(str[i], str[j], d))
          cout << str[i] << "," << str[j] << endl, cnt++;
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

bool check(string a, string b, int d) {
  if (a.size() < b.size())
    swap(a, b);
  if (a == b)
    return 1;
  if (d == 0 || a.empty())
    return 0;

  // erase
  for (int i = 0; i < a.size() && a.size() > b.size(); i++) {
    string t = a;
    t.erase(t.begin() + i);
    if (check(t, b, d - 1))
      return 1;
  }

  // swap
  for (int i = 0; i < (int)a.size() - 1; i++) {
    swap(a[i], a[i + 1]);
    if (check(a, b, d - 1))
      return 1;
    swap(a[i], a[i + 1]);
  }

  // change
  for (int i = 0; i < b.size(); i++) {
    char ch = a[i];
    if (a[i] != b[i])
      a[i] = b[i];
    if (check(a, b, d - 1))
      return 1;
    a[i] = ch;
  }
  return 0;
}

int main() {
  int n, d;
  while (cin >> n, n) {
    cin >> d;
    string str[201];
    for (int i = 0; i < n; i++)
      cin >> str[i];
    sort(str, str + n);

    int cnt = 0;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
        if (check(str[i], str[j], d))
          printf("%s,%s\\n", &str[i][0], &str[j][0]), cnt++;
    cout << cnt << endl;
  }
  return 0;
}
Problem p00836 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, j) for (int i = 0; i < j; i++)
const int MAX_N = 10010;

vector<int> prime;
bool flg[MAX_N];

void make_prime() {
  flg[0] = true;
  flg[1] = true;
  rep(i, MAX_N) {
    if (flg[i])
      continue;
    prime.push_back(i);
    for (int j = i; j < MAX_N; j += i)
      flg[j] = true;
  }
}

int cnt_prime(int n) {
  int ret = 0;
  rep(i, prime.size()) {
    int sum = 0;
    for (int j = i; j < prime.size(); j++) {
      sum += prime[j];
      if (sum == n)
        ret++;
    }
  }
  return ret;
}

int main() {
  make_prime();
  int n;
  while (cin >> n && n)
    cout << cnt_prime(n) << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, j) for (int i = 0; i < j; i++)
const int MAX_N = 10010;

map<int, int> m;
int dx[MAX_N][MAX_N];
bool flg[MAX_N];
vector<int> prime;

void make_prime() {
  flg[0] = true;
  flg[1] = true;
  rep(i, MAX_N) {
    if (flg[i])
      continue;
    prime.push_back(i);
    for (int j = i; j < MAX_N; j += i)
      flg[j] = true;
  }
}

void cnt_prime() {
  rep(i, prime.size()) {
    int sum = 0;
    for (int j = i; j < prime.size(); j++) {
      sum += prime[j];
      m[sum]++;
    }
  }
}

int main() {
  make_prime();
  cnt_prime();
  int n;
  while (cin >> n && n)
    cout << m[n] << endl;
  return 0;
}
Problem p00836 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main(void) {
  bool isPrime[10010];
  std::vector<int> prime, input;
  int i, j, k, ans;

  for (i = 0; i < 10010; ++i)
    isPrime[i] = true;
  for (i = 2; i < 10010; ++i) {
    for (j = i * 2; j < 10010; j += i)
      isPrime[j] = false;
  }
  for (i = 2; i < 10010; ++i) {
    if (isPrime[i])
      prime.push_back(i);
  }

  while (true) {
    std::cin >> i;
    if (i == 0)
      break;
    input.push_back(i);
  }

  for (int in = 0; in < input.size(); ++in) {
    ans = 0;
    for (i = 0; true; ++i) {
      if (prime[i] > input[in])
        break;
      k = input[in];
      for (j = i; true; ++j) {
        k -= prime[j];
        if (k < 0)
          break;
        if (k == 0)
          ++ans;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <iterator>
#include <vector>

int main(void) {
  bool isPrime[10010];
  std::vector<int> prime, input;
  int i, j, k, ans;

  for (bool b : isPrime)
    b = true;
  for (i = 2; i < 10010; ++i) {
    for (j = i * 2; j < 10010; j += i)
      isPrime[j] = false;
  }
  for (i = 2; i < 10010; ++i) {
    if (isPrime[i])
      prime.push_back(i);
  }

  while (true) {
    std::cin >> i;
    if (i == 0)
      break;
    input.push_back(i);
  }

  for (auto in : input) {
    ans = 0;
    for (i = 0; true; ++i) {
      if (prime[i] > in)
        break;
      k = in;
      for (j = i; true; ++j) {
        k -= prime[j];
        if (k < 0)
          break;
        if (k == 0)
          ++ans;
      }
    }
    std::cout << ans << std::endl;
  }
  system("PAUSE");
  return 0;
}
Problem p00836 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
bool is_prime(int num);

using namespace std;

int main() {
  int i;
  int j = 0;
  int primes[10000];
  for (i = 1; i <= 10000; ++i) {
    if (is_prime(i)) {
      primes[j] = i;
      j++;
    }
  }
  int input;
  int sum;
  int count;
  int vector_index = 0;
  while (cin >> input) {
    if (input == 0) {
      break;
    }

    // initialization
    vector_index = 0;
    queue<int> sum_components;
    sum_components.push(primes[vector_index]);
    sum = primes[vector_index];
    vector_index++;
    count = 0;

    //???????????¨???
    while (sum_components.back() <= input) {
      if (sum < input) {
        sum_components.push(primes[vector_index]);
        sum += primes[vector_index];
        vector_index++;
      } else if (sum == input) {
        count++;
        sum_components.push(primes[vector_index]);
        sum += primes[vector_index];
        vector_index++;
      } else {
        sum -= sum_components.front();
        sum_components.pop();
      }
    }
    cout << count << endl;
  }
}

bool is_prime(int num) {
  if (num < 2) {
    return false;
  }
  if (num == 2) {
    return true;
  }
  for (int i = 2; i < num; ++i) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}

Error: 0

Fixed submission:


#include <iostream>
#include <queue>
#include <vector>
bool is_prime(int num);

using namespace std;

int main() {
  int i;
  vector<int> primes;
  for (i = 1; i <= 10000; ++i) {
    if (is_prime(i)) {
      primes.push_back(i);
    }
  }
  int input;
  int sum;
  int count;
  int vector_index = 0;
  while (cin >> input) {
    if (input == 0) {
      break;
    }

    // initialization
    vector_index = 0;
    queue<int> sum_components;
    sum_components.push(primes.at(vector_index));
    sum = primes.at(vector_index);
    vector_index++;
    count = 0;

    //???????????¨???
    while (sum_components.back() <= input) {
      if (sum < input) {
        sum_components.push(primes.at(vector_index));
        sum += primes.at(vector_index);
        vector_index++;
      } else if (sum == input) {
        count++;
        sum_components.push(primes.at(vector_index));
        sum += primes.at(vector_index);
        vector_index++;
      } else {
        sum -= sum_components.front();
        sum_components.pop();
      }
    }
    cout << count << endl;
  }
}

bool is_prime(int num) {
  if (num < 2) {
    return false;
  }
  if (num == 2) {
    return true;
  }
  for (int i = 2; i < num; ++i) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
Problem p00836 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int sieve[10005];

int ans[10005];

void precal() {
  int i, j;

  sieve[1] = 1;

  for (i = 2; i * i <= 10000; i++) {
    if (sieve[i])
      continue;

    for (j = 2 * i; j <= 10000; j += i) {
      sieve[j] = 1;
    }
  }

  vector<int> prime;

  for (i = 1; i <= 10000; i++) {
    if (!sieve[i])
      prime.push_back(i);
  }
  // cout<<prime.size()<<endl;

  for (i = 0; i < prime.size(); i++) {
    int sum = 0;
    for (j = i; j < prime.size(); j++) {
      sum += prime[j];
      if (sum <= 10000)
        ans[sum]++;
    }
  }
}

int main() {
  precal();

  int N;

  cin >> N;

  while (N != 0) {
    printf("%d\\n", ans[N]);
    cin >> N;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
long int isPrime(int n) {
  long int i;

  if (n == 2)
    return 1;
  if (n == 1)
    return 0;

  if (n % 2 == 0)
    return 0;

  for (i = 3; i <= sqrt(n); i += 2)
    if (n % i == 0)
      return 0;

  return 1;
}
int main() {

  long int n;
  int j;
  long int x;
  long int c = 0;
  cin >> n;
  cin >> x;
  long int a[n], i;
  for (i = 0; i < x; i++)
    cin >> a[i];
  for (i = 2; i <= n; i + 2)
    if (isPrime(i) == 0)
      c++;
  for (i = 0; i < x; i++)
    if (a[i] >= 1 && a[i] <= n)
      cout << isPrime(a[i]) << '\\n';

  return 0;
}
Problem p00836 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;

  bool isPrime[10001];
  for (int i = 0; i < 10001; i++)
    isPrime[i] = 1;
  isPrime[0] = isPrime[1] = 0;
  for (int i = 0; i < 10001; i++) {
    if (!isPrime[i])
      continue;
    for (int j = 2; j * i < 10001; j++) {
      isPrime[i * j] = 0;
    }
  }

  vector<int> prime;
  prime.push_back(0);
  for (int i = 0; i < 10001; i++)
    if (isPrime[i])
      prime.push_back(i);
  for (int i = 1; i < prime.size(); i++)
    prime[i] += prime[i - 1];

  while (cin >> N, N) {
    int ans = 0;
    int i = 0, j = 0;
    while (i < prime.size() && j < prime.size()) {
      int sub = prime[j] - prime[i];
      if (sub < N)
        j++;
      else if (sub >= N) {
        i++;
        if (sub == N)
          ans++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int N;

  bool isPrime[10001];
  for (int i = 0; i < 10001; i++)
    isPrime[i] = 1;
  isPrime[0] = isPrime[1] = 0;
  for (int i = 0; i < 10001; i++) {
    if (!isPrime[i])
      continue;
    for (int j = 2; j * i < 10001; j++) {
      isPrime[i * j] = 0;
    }
  }

  vector<int> prime;
  prime.push_back(0);
  for (int i = 0; i < 10001; i++)
    if (isPrime[i])
      prime.push_back(i);
  for (int i = 1; i < prime.size(); i++)
    prime[i] += prime[i - 1];

  while (cin >> N, N) {
    int ans = 0;
    int i = 0, j = 0;
    while (i < prime.size() || j < prime.size()) {
      int sub = prime[j] - prime[i];
      if (sub < N)
        j++;
      else if (sub >= N) {
        i++;
        if (sub == N)
          ans++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}
Problem p00836 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

const int M = 20000;

int main() {
  vector<int> primes;

  for (int i = 2; i < M; i++) {
    bool flag = true;

    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }

    if (flag) {
      primes.push_back(i);
    }
  }

  for (int n; cin >> n && n;) {
    int sum = 0, front = 0, back = 0, count = 0;

    while (true) {
      while (sum < n && front < primes.size()) {
        sum += primes[front++];
      }

      while (sum > n && back <= front) {
        sum -= primes[back++];
      }

      if (sum == n) {
        count++;
        sum -= primes[back++];
      }

      if (front == back) {
        break;
      }
    }

    cout << count << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

const int M = 10000;

int main() {
  vector<int> primes;

  for (int i = 2; i < M; i++) {
    bool flag = true;

    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }

    if (flag) {
      primes.push_back(i);
    }
  }

  for (int n; cin >> n && n;) {
    int sum = 0, front = 0, back = 0, count = 0;

    while (true) {
      while (sum < n && front < primes.size()) {
        sum += primes[front++];
      }

      while (sum > n && back <= front) {
        sum -= primes[back++];
      }

      if (sum == n) {
        count++;
        sum -= primes[back++];
      }

      if (front == back) {
        break;
      }
    }

    cout << count << endl;
  }
}
Problem p00836 (C++) — buggy submission, verdict: Runtime Error

// Sum of Consecutive Prime Numbers
// ??¨????????????????????????????????????????????§?????????

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
using namespace std;

vector<int> Prime_Num;

int makePrimeQ() {
  int N = 10010;
  bool prime[N];

  for (int i = 0; i < N; i++)
    prime[i] = true;
  for (int i = 2; i <= sqrt(N); i++) {
    if (prime[i]) {
      for (int j = 2; i * j < N; j++)
        prime[i * j] = false;
    }
  }
  for (int i = 2; i < N; i++) {
    if (prime[i])
      Prime_Num.push_back(i);
  }
}
int solve(int num) {
  int count = 0, sum = 0, temp = 0, i = 0;
  queue<int> Q;
  bool flag = true;
  while (Prime_Num[i] <= num) {
    if (flag) {
      temp = Prime_Num[i];
      Q.push(temp);
      sum += temp;
    }
    if (sum == num) {
      count++;
      sum -= Q.front();
      Q.pop();
      flag = true;
      i++;
    } else if (sum < num) {
      flag = true;
      i++;
    } else { // sum > num
      sum -= Q.front();
      Q.pop();
      flag = false;
    }
  }
  return count;
}

int main() {
  int num;
  makePrimeQ();
  while (cin >> num) {
    if (num == 0)
      break;
    // cout << Prime_Num[num] << endl;
    cout << solve(num) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

// Sum of Consecutive Prime Numbers
// ??¨????????????????????????????????????????????§?????????

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

#define N 50000000
vector<int> Prime_Num;
bool prime[N] = {true};

int makePrimeQ() {
  for (int i = 0; i < N; i++)
    prime[i] = true;
  for (int i = 2; i * i <= N; i++) {
    if (prime[i]) {
      Prime_Num.push_back(i);
      for (int j = i * i; j <= N; j = j + i)
        prime[j] = false;
    }
  }
}
int solve(int num) {
  int count = 0, sum = 0, temp = 0, i = 0;
  queue<int> Q;
  bool flag = true;
  while (Prime_Num[i] <= num) {
    if (flag) {
      temp = Prime_Num[i];
      Q.push(temp);
      sum += temp;
    }
    if (sum == num) {
      count++;
      sum -= Q.front();
      Q.pop();
      flag = true;
      i++;
    } else if (sum < num) {
      flag = true;
      i++;
    } else { // sum > num
      sum -= Q.front();
      Q.pop();
      flag = false;
    }
  }
  return count;
}

int main() {
  int num;
  makePrimeQ();
  while (cin >> num) {
    if (num == 0)
      break;
    cout << solve(num) << endl;
  }
  return 0;
}
Problem p00836 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long

ll p[10001];
vector<ll> prime;

int main() {
  for (ll i = 0; i < 10001; i++) {
    p[i] = 0;
  }
  p[0] = p[1] = 1;

  ll id = 2;
  while (1) {
    while (id <= 10000 && p[id] == 1) {
      id++;
    }
    if (id >= 10000) {
      break;
    }
    ll temp = 2 * id;
    while (temp <= 10000) {
      p[temp] = 1;
      temp += id;
    }
    id++;
  }

  for (ll i = 0; i <= 100; i++) {
    //    cout << i << ' ' << p[i] << endl;
  }

  for (ll i = 2; i <= 10000; i++) {
    if (p[i] == 0) {
      prime.push_back(i);
    }
  }

  for (vector<ll>::iterator it = prime.begin(); it != prime.end(); it++) {
    //   cerr << *it << ' ';
  }
  //  cerr << '\\n';

  ll n = prime.size();
  vector<ll> sum(n);
  sum[0] = prime[0];
  unordered_set<ll> us;
  us.insert(sum[0]);
  for (ll i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + prime[i];
    us.insert(sum[i]);
  }
  us.insert(0);

  ll k;
  while (cin >> k && k) {
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
      if (us.find(k + sum[i]) != us.end() || k == sum[i]) {

        cnt++;
      }
    }
    cout << cnt << endl;
  }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long

ll p[10001];
vector<ll> prime;

int main() {
  for (ll i = 0; i < 10001; i++) {
    p[i] = 0;
  }
  p[0] = p[1] = 1;

  ll id = 2;
  while (1) {
    while (id <= 10000 && p[id] == 1) {
      id++;
    }
    if (id >= 10000) {
      break;
    }
    ll temp = 2 * id;
    while (temp <= 10000) {
      p[temp] = 1;
      temp += id;
    }
    id++;
  }

  for (ll i = 0; i <= 100; i++) {
    cout << i << ' ' << p[i] << endl;
  }

  for (ll i = 2; i <= 10000; i++) {
    if (p[i] == 0) {
      prime.push_back(i);
    }
  }

  for (vector<ll>::iterator it = prime.begin(); it != prime.end(); it++) {
    cerr << *it << ' ';
  }
  cerr << '\\n';

  ll n = prime.size();
  vector<ll> sum(n);
  sum[0] = prime[0];
  unordered_set<ll> us;
  us.insert(sum[0]);
  for (ll i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + prime[i];
    us.insert(sum[i]);
  }
  us.insert(0);

  ll k;
  while (cin >> k && k) {
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
      if (us.find(k + sum[i]) != us.end() || k == sum[i]) {

        cnt++;
      }
    }
    cout << cnt << endl;
  }
}
Problem p00836 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

static int so[10001], hyo[1300];

int main() {
  int i, j, k, n, m;

  so[1] = 1;
  for (i = 2; i * i <= 10000; i++) {
    for (j = 2 * i; j <= 10000; j += i) {
      so[j] = 1;
    }
  }
  hyo[0] = 0;
  j = 0;
  for (i = 1; i <= 10000; i++) {
    if (!so[i]) {
      ++j;
      hyo[j] = hyo[j - 1] + i;
    }
  }
  k = j;
  // printf("%d\\n",k);
  while (0 <= scanf("%d", &n)) {
    if (n == 0)
      break;

    m = 0;

    for (i = 0; i < k; ++i) {
      for (j = i + 1; j <= k; ++j) {
        if (hyo[j] - hyo[i] == n)
          ++m;
      }
    }
    printf("%d\\n", m);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

static int so[10001], hyo[1000];

int main() {
  int i, j, k, n, m;

  so[1] = 1;
  for (i = 2; i * i <= 10000; i++) {
    for (j = 2 * i; j <= 10000; j += i) {
      so[j] = 1;
    }
  }
  hyo[0] = 0;
  j = 0;
  for (i = 1; i <= 10000; i++) {
    if (!so[i]) {
      ++j;
      hyo[j] = hyo[j - 1] + i;
    }
  }
  k = j;

  while (0 <= scanf("%d", &n)) {
    if (n == 0)
      break;

    m = 0;

    for (i = 0; i < k; ++i) {
      for (j = i + 1; j <= k; ++j) {
        if (hyo[j] - hyo[i] == n)
          ++m;
      }
    }
    printf("%d\\n", m);
  }
  return 0;
}