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

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

string toString(int a) {
  stringstream ss;
  ss << a;
  return ss.str();
}

int toInt(string s) {
  stringstream ss(s);
  int res;
  ss >> res;
  return res;
}

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

int rec(int d, int n, string s, string c) {
  if (n > 4)
    return -1;
  if (d == n) {
    string pal = s + c;
    reverse(s.begin(), s.end());
    pal += s;
    int p = toInt(pal);
    return is_prime(p) ? p : -1;
  }

  int res = -1;
  for (int i = 0; i < 10; i++) {
    if (d == 0 && (i % 2 == 0 || i % 5 == 0))
      continue;
    res = max(res, rec(d + 1, n, s + toString(i), c));
  }
  return res;
}

int main() {
  int n, c;
  cin >> n >> c;
  string center = (c < 0) ? "" : toString(c);
  int res = rec(0, n, "", center);

  if (res < 0) {
    for (int i = 0; i < n; i++)
      cout << "9";
    cout << center;
    for (int i = 0; i < n; i++)
      cout << "9";
    cout << endl;
  } else {
    cout << res << endl;
  }
}

Error: TLE

Fixed submission:

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

string toString(int a) {
  stringstream ss;
  ss << a;
  return ss.str();
}

int toInt(string s) {
  stringstream ss(s);
  int res;
  ss >> res;
  return res;
}

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

int rec(int d, int n, string s, string c) {
  if (d == n) {
    string pal = s + c;
    reverse(s.begin(), s.end());
    pal += s;
    int p = toInt(pal);
    return is_prime(p) ? p : -1;
  }

  int res = -1;
  for (int i = 0; i < 10; i++) {
    if (d == 0 && (i % 2 == 0 || i % 5 == 0))
      continue;
    res = max(res, rec(d + 1, n, s + toString(i), c));
  }
  return res;
}

int main() {
  int n, c;
  cin >> n >> c;
  string center = (c < 0) ? "" : toString(c);
  int res = rec(0, n, "", center);

  if (res < 0) {
    for (int i = 0; i < n; i++)
      cout << "9";
    cout << center;
    for (int i = 0; i < n; i++)
      cout << "9";
    cout << endl;
  } else {
    cout << res << endl;
  }
}
Problem p00510 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m, S, max;
  cin >> n >> m;
  S = m;
  max = m;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    S = S + a - b;
    if (S > max)
      max = S;
    if (S < 0) {
      max = 0;
      break;
    }
    if (S > max)
      max = S;
  }
  cout << max << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    int K, c[10000], sum = 0;
    cin >> K;
    if (0 == K)
      break;
    for (int i = 0; i < K * (K - 1) / 2; i++) {
      cin >> c[i];
      sum += c[i];
    }
    sum = sum / (K - 1);
    cout << sum << endl;
  }
  return 0;
}
Problem p00510 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int now = m;
  int max = m;
  bool flag = true;
  vector<int> in(n), out(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i] >> out[i];
    now = now + in[i] - out[i];
    if (now > max)
      max = now;
    if (now < 0) {
      cout << 0 << endl;
      flag = false;
      break;
    }
  }
  if (flag)
    cout << max << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int now = m;
  int max = m;
  vector<int> in(n), out(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i] >> out[i];
    now = now + in[i] - out[i];
    if (now > max)
      max = now;
    if (now < 0) {
      cout << 0 << endl;
      exit(1);
    }
  }
  cout << max << endl;
}
Problem p00511 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int change(string k) {
  int res = 0;
  rep(i, 0, k.size()) { res += (k[i] - '0') * pow(10, k.size() - i - 1); }
  return res;
}

int main() {
  string c;
  int ans = 0, f = 0, g = 1;
  for (int i = 0;; i++) {
    cin >> c;
    if (c == "=")
      break;
    else if (c == "+")
      f = 1;
    else if (c == "-")
      f = 2;
    else if (c == "*")
      f = 3;
    else if (c == "/")
      f = 4;
    else {
      int nw = change(c);
      // o(nw);
      if (g) {
        ans = nw;
        g = 0;
        continue;
      }
      if (f == 1)
        ans += nw;
      if (f == 2)
        ans -= nw;
      if (f == 3)
        ans *= nw;
      if (f == 4)
        ans /= nw;
    }
  }
  o(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int change(string k) {
  int res = 0;
  rep(i, 0, k.size()) { res += (k[i] - '0') * pow(10, k.size() - i - 1); }
  return res;
}

int main() {
  while (1) {
    string c;
    int ans = 0, f = 0, g = 1;
    for (int i = 0;; i++) {
      cin >> c;
      if (c == "=")
        break;
      else if (c == "+")
        f = 1;
      else if (c == "-")
        f = 2;
      else if (c == "*")
        f = 3;
      else if (c == "/")
        f = 4;
      else {
        int nw = change(c);
        // o(nw);
        if (g) {
          ans = nw;
          g = 0;
          continue;
        }
        if (f == 1)
          ans += nw;
        if (f == 2)
          ans -= nw;
        if (f == 3)
          ans *= nw;
        if (f == 4)
          ans /= nw;
      }
    }
    o(ans);
  }
}
Problem p00511 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  int a, s;
  char op;
  scanf("%d", &a);
  cin >> op;
  while (op != '=') {
    if (op == '+') {
      scanf("%d", &s);
      a = a + s;
    } else if (op == '-') {
      scanf("%d", &s);
      a = a - s;
    } else if (op == '*') {
      scanf("%d", &s);
      a = a * s;
    } else if (op == '/') {
      scanf("%d", &s);
      a = a / s;
    }
    //		scanf("%d",&a);
    cin >> op;
  }
  printf("%d\\n", a);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, s;
  char op, buf[2];
  scanf("%d", &a);
  scanf("%s", buf);
  op = buf[0];
  while (op != '=') {
    if (op == '+') {
      scanf("%d", &s);
      a = a + s;
    } else if (op == '-') {
      scanf("%d", &s);
      a = a - s;
    } else if (op == '*') {
      scanf("%d", &s);
      a = a * s;
    } else if (op == '/') {
      scanf("%d", &s);
      a = a / s;
    }
    scanf("%d", &a);
    scanf("%s", &buf);
  }
  printf("%d\\n", a);

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

#include <iostream>
using namespace std;

int a, b;
char c;

int main() {
  cin >> a;

  while (1) {
    cin >> c;

    if (c == '=') {
      break;
    }

    if (c == '+') {
      cin >> b;
      a = a + b;
    }
    if (c == '-') {
      cin >> b;
      a = a - b;
    }
    if (c == '*') {
      cin >> b;
      a = a * b;
    }
    if (c == '/') {
      cin >> b;
      a = a / b;
    }
  }

  cout << a << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int a = 0, b = 0;
  char c = 'p';

  while (c != '=') {
    cin >> a >> c;

    if (c == '+') {
      cin >> b;
      a = a + b;
    }
    if (c == '-') {
      cin >> b;
      a = a - b;
    }
    if (c == '*') {
      cin >> b;
      a = a * b;
    }
    if (c == '/') {
      cin >> b;
      a = a / b;
    }
  }

  cout << a;

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

#include <cstdio>

using namespace std;

int in(void) {
  int x;
  scanf("%d", &x);
  return (x);
}

int main() {
  char symbol = '+';
  int ans = 0;

  do {
    if (symbol == '+')
      ans += in();
    if (symbol == '-')
      ans -= in();
    if (symbol == '*')
      ans *= in();
    if (symbol == '/')
      ans /= in();
    scanf(" %c", &symbol);
  } while (symbol != '=');

  printf("%d\\n", ans);

  return (0);
}

Error: -11

Fixed submission:

#include <cstdio>

using namespace std;

int in(void) {
  int x;
  scanf("%d", &x);
  return (x);
}

int main() {
  char symbol = '+';
  int ans = 0;

  do {
    if (symbol == '+')
      ans += in();
    if (symbol == '-')
      ans -= in();
    if (symbol == '*')
      ans *= in();
    if (symbol == '/')
      ans /= in();
    scanf(" %c", symbol);
  } while (symbol != '=');

  printf("%d\\n", symbol);

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

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define int long long
using namespace std;
signed main() {
  int n;
  cin >> n;
  set<string> st;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    if (st.lower_bound(s) == st.end()) {
      st.insert(s);
      m[s] = 0;
    } else if (*(st.lower_bound(s)) != s) {
      st.insert(s);
      m[s] = 0;
    }
    m[s] += p;
  }
  vector<pair<int, string>> v;
  for (string s : st)
    v.push_back(make_pair(s.size(), s));
  sort(v.begin(), v.end());
  for (pair<int, string> i : v)
    cout << i.second << ' ' << m[i.second] << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define int long long
using namespace std;
signed main() {
  int n;
  cin >> n;
  set<string> st;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    if (st.lower_bound(s) == st.end() && *(st.lower_bound(s)) != s) {
      st.insert(s);
      m[s] = 0;
    }
    m[s] += p;
  }
  vector<pair<int, string>> v;
  for (string s : st)
    v.push_back(make_pair(s.size(), s));
  sort(v.begin(), v.end());
  for (pair<int, string> i : v)
    cout << i.second << ' ' << m[i.second] << endl;
}
Problem p00512 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;

  scanf("%d", &n);

  vector<pair<int, pair<string, int>>> v;
  for (int i = 0; i < n; i++) {
    char pName[8];
    int num;
    scanf("%s %d", pName, &num);
    v.push_back(make_pair(strlen(pName), make_pair((string)pName, num)));
  }

  sort(v.begin(), v.end());

  string lead = "$";
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (lead != v[i].second.first) {
      if (lead != "$")
        printf("%s %d\\n", lead.c_str(), cnt);
      lead = v[i].second.first;
      cnt = v[i].second.second;
    } else
      cnt += v[i].second.second;
  }
  return (!printf("%s %d\\n", lead.c_str(), cnt));
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;

  scanf("%d", &n);

  vector<pair<int, pair<string, int>>> v;
  for (int i = 0; i < n; i++) {
    char pName[8];
    int num;
    scanf("%s %d", pName, num);
    v.push_back(make_pair(strlen(pName), make_pair((string)pName, num)));
  }

  sort(v.begin(), v.end());

  string lead = "$";
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (lead != v[i].second.first) {
      if (lead != "$")
        printf("%s %d\\n", lead.c_str(), cnt);
      lead = v[i].second.first;
      cnt = v[i].second.second;
    } else
      cnt += v[i].second.second;
  }
  return (!printf("%s %d\\n", lead.c_str(), cnt));
}
Problem p00512 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
using namespace std;

typedef struct {
  char name[6];
  long num;
} product;

product p[12000000];

int main() {
  long n, now = 0;

  scanf(" %ld", &n);
  for (long i = 0; i < n; ++i) {
    char s[6];
    long a;
    scanf(" %s %ld", s, &a);

    bool find = false;
    for (long j = 0; j < now; ++j) {
      if (strcmp(p[j].name, s) == 0) {
        find = true;
        p[j].num += a;
        break;
      }
    }

    if (!find) {
      strcpy(p[now].name, s);
      p[now].num = a;
      ++now;
    }
  }

  for (long i = 0; i < now; ++i) {
    for (long j = i; j < now; ++j) {
      if (strlen(p[i].name) > strlen(p[j].name))
        swap(p[i], p[j]);
    }
  }

  for (long i = 0; i < now; ++i) {
    for (long j = i; j < now; ++j) {
      if (strlen(p[i].name) == strlen(p[j].name)) {
        for (int k = 0; k < strlen(p[i].name); ++k) {
          if (p[i].name[k] > p[j].name[k]) {
            swap(p[i], p[j]);
            break;
          } else if (p[i].name[k] == p[j].name[k]) {
            continue;
          } else
            break;
        }
      }
    }
  }

  for (long i = 0; i < now; ++i)
    cout << p[i].name << " " << p[i].num << endl;
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
using namespace std;

typedef struct {
  string name;
  long num;
} product;

product p[12000000];

int main() {
  long n, now = 0;

  scanf(" %ld", &n);
  for (long i = 0; i < n; ++i) {
    string s;
    long a;
    cin >> s >> a;

    bool find = false;
    for (long j = 0; j < now; ++j) {
      if (p[j].name == s) {
        find = true;
        p[j].num += a;
        break;
      }
    }

    if (!find) {
      p[now].name = s;
      p[now].num = a;
      ++now;
    }
  }

  for (long i = 0; i < now; ++i) {
    for (long j = i; j < now; ++j) {

      if (p[i].name.size() > p[j].name.size())
        swap(p[i], p[j]);
      else if (p[i].name.size() == p[j].name.size()) {
        for (int k = 0; k < p[i].name.size(); ++k) {
          if (p[i].name[k] > p[j].name[k]) {
            swap(p[i], p[j]);
            break;
          }
        }
      }
    }
  }

  for (long i = 0; i < now; ++i)
    cout << p[i].name << " " << p[i].num << endl;
}
Problem p00512 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int k[16000000];
int n, a, z, cnt;
string S;

int main() {
  memset(k, 0, sizeof(k));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S;
    z = 0;
    for (int j = 0; j < S.size(); j++) {
      z += (int)(S[j] - 'A' + 1) * pow(27, S.size() - j - 1);
    }
    cin >> a;
    k[z] += a;
  }
  for (int i = 0; i < 16000000; i++) {
    if (k[i] >= 1) {
      for (int j = 4; j >= 0; j--) {
        z = (int)(i / (int)pow(27, j)) % 27;
        if (z >= 1) {
          cout << (char)(z + 'A' - 1);
        }
      }
      cout << ' ';
      cout << k[i] << endl;
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int k[16500000];
int n, a, z, cnt;
string S;

int main() {
  memset(k, 0, sizeof(k));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S;
    z = 0;
    for (int j = 0; j < S.size(); j++) {
      z += (int)(S[j] - 'A' + 1) * pow(27, S.size() - j - 1);
    }
    cin >> a;
    k[z] += a;
  }
  for (int i = 0; i < 16500000; i++) {
    if (k[i] >= 1) {
      for (int j = 4; j >= 0; j--) {
        z = (int)(i / (int)pow(27, j)) % 27;
      }
      if (z >= 1) {
        cout << (char)(z + 'A' - 1) << endl;
      }
      cout << ' ';
      cout << k[i] << endl;
    }
  }
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 50010

int main() {
  int n, ans = 0, S;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int f = false;
    scanf("%d", &S);

    for (int x = 1; 2 * x * x + 2 * x <= S; x++) {
      if ((S - x) % (2 * x + 1) == 0) {
        f = true;
        break;
      }
    }

    if (!f)
      ans++;
  }

  printf("%d\\n", ans);

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 50010

int main() {
  int n, ans = 0, S;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int f = false;
    scanf("%d", &S);

    for (int x = 1; S - x >= 2 * x + 1; x++) {
      if ((S - x) % (2 * x + 1) == 0) {
        f = true;
        break;
      }
    }

    if (!f)
      ans++;
  }

  printf("%d\\n", ans);

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

int main() {

  int i, N, a, cnt = 0;

  cin >> N;
  while (N--) {
    cin >> a;
    bool judge = false;
    for (i = 1; i * i < a && (a - i) >= (2 * i + 1); i++) {
      if ((a - i) % (2 * i + 1) == 0) {
        judge = true;
        break;
      }
      // cout << a << endl;
    }
    if (!judge)
      cnt++;
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

int main() {

  int i, N, a, cnt = 0;

  cin >> N;
  while (N--) {
    cin >> a;
    bool judge = false;
    for (i = 1; i < a && (a - i) >= (2 * i + 1); i++) {
      if ((a - i) % (2 * i + 1) == 0) {
        judge = true;
        break;
      }
      // cout << a << endl;
    }
    if (!judge)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define SORT(x) sort((x).begin(), (x).end())
#define REP(i, x, y) for (long long int i = (x); i < (y); ++i)
#define MP(a, b) make_pair((a), (b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int, int> P;

const int INF = 1 << 30;
const long long int INF_ = 1 << 60;

bool Exists(int s) {
  int x = 1;
  while (x * x + x <= s) {
    if ((s - x) % (2 * x + 1) == 0)
      return true;
    ++x;
  }
  return false;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N;
  cin >> N;
  int ans = 0;
  REP(i, 0, N) {
    int S;
    cin >> S;
    if (!Exists(S))
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define SORT(x) sort((x).begin(), (x).end())
#define REP(i, x, y) for (long long int i = (x); i < (y); ++i)
#define MP(a, b) make_pair((a), (b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int, int> P;

const int INF = 1 << 30;
const long long int INF_ = 1 << 60;

bool Exists(int s) {
  int x = 1;
  while (x * 2 + x <= s) {
    if ((s - x) % (2 * x + 1) == 0)
      return true;
    ++x;
  }
  return false;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N;
  cin >> N;
  int ans = 0;
  REP(i, 0, N) {
    int S;
    cin >> S;
    if (!Exists(S))
      ++ans;
  }
  cout << ans << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  while (cin >> n) {
    bool ok = false;
    for (int y = 1; y * y < n; y++) {
      if ((n - y) % (2 * y + 1))
        continue;
      ok = true;
      break;
    }
    ans += !ok;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  while (cin >> n) {
    bool ok = false;
    for (int y = 1; y < n / 2 + 1; y++) {
      if ((n - y) % (2 * y + 1))
        continue;
      ok = true;
      break;
    }
    if (!ok)
      ans++;
  }
  cout << ans << endl;
}
Problem p00513 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

bool is_room(int S) {

  for (int i = 1; i * i <= S; i++)
    if ((S - i) % (2 * i + 1) == 0)
      return true;
  return false;
}

int main(void) {

  int n, S, cnt = 0;

  cin >> n;
  while (n--) {
    cin >> S;
    if (!is_room(S))
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

set<int> rightS;

void makeLUT(int maxNum) {
  for (int x = 1; x < maxNum / 2; x++) {
    for (int y = x; y < maxNum / 2; y++) {
      rightS.insert(2 * x * y + x + y);
    }
  }
}

int checkAns(int s) {
  set<int>::iterator iti = rightS.find(s);
  if (iti == rightS.end()) {
    return 0;
  }
  return 1;
}

int main() {
  int n, ans = 0;
  vector<int> dates;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    dates.push_back(s);
  }
  int maxNum = *max_element(dates.begin(), dates.end());
  makeLUT(maxNum);
  for (int i = 0; i < dates.size(); i++) {
    if (checkAns(dates[i]) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}