alexjercan/bugnet huggingface dataset:
Problem p00684 (C++) — buggy submission, verdict: Runtime Error

#include <complex>
#include <iostream>

using namespace std;

#define COMP complex<int>
int abs(int a) { return (a < 0) ? -a : a; }

char *p, buf[11000];

COMP expr();

COMP fact() {
  COMP ret;
  if (*p == '(') {
    p++;
    ret = expr();
    p++;
  } else if (*p == 'i') {
    ret = COMP(0, 1);
    p++;
  } else {
    while (isdigit(*p)) {
      ret = ret * 10 + int(*p - '0');
      p++;
      if (abs(ret.real()) > 10000 || abs(ret.imag()) > 10000)
        throw 0;
    }
  }

  return ret;
}

COMP term() {
  COMP ret = fact();
  while (*p == '*') {
    p++;
    ret *= fact();
    if (abs(ret.real()) > 10000 || abs(ret.imag()) > 10000)
      throw 0;
  }
  return ret;
}

COMP expr() {
  COMP ret = term();
  while (*p == '+' || *p == '-') {
    char ope = *p++;
    if (ope == '+')
      ret += term();
    if (ope == '-')
      ret -= term();
    if (abs(ret.real()) > 10000 || abs(ret.imag()) > 10000)
      throw 0;
  }
  return ret;
}

int main() {
  COMP ret;
  while (cin >> buf) {
    p = buf;
    try {
      ret = expr();
      if (ret.real() || !ret.imag())
        cout << ret.real();
      if (ret.imag() > 0 && ret.real())
        cout << '+';
      if (ret.imag())
        cout << ret.imag() << "i";
      cout << endl;
    } catch (...) {
      cout << "overflow" << endl;
    }
  }
}

Error: -6
terminate called after throwing an instance of 'int'


Fixed submission:

#include <complex>
#include <iostream>

using namespace std;

#define COMP complex<int>
#define abs(a) (a < 0 ? -a : a)

char *p, buf[110];

COMP expr();

COMP term() {
  COMP ret;
  if (*p == '(') {
    p++;
    ret = expr();
    p++;
  } else if (*p == 'i') {
    ret = complex<int>(0, 1);
    p++;
  } else {
    while (isdigit(*p)) {
      ret = ret * 10 + int(*p - '0');
      p++;
      if (abs(ret.real()) > 10000 || abs(ret.imag()) > 10000)
        throw 0;
    }
  }

  return ret;
}

COMP factor() {
  COMP ret = term();
  while (*p == '*') {
    p++;
    ret *= term();
    if (abs(ret.real()) > 10000 || abs(ret.imag()) > 10000)
      throw 0;
  }
  return ret;
}

COMP expr() {
  COMP ret = factor();
  while (*p == '+' || *p == '-') {
    char ope = *p++;
    if (ope == '+')
      ret += factor();
    if (ope == '-')
      ret -= factor();
    if (abs(ret.real()) > 10000 || abs(ret.imag()) > 10000)
      throw 0;
  }
  return ret;
}

int main() {
  COMP ret;
  while (cin >> buf) {
    p = buf;
    try {
      ret = expr();
      cout << ret.real();
      if (ret.imag() > 0)
        cout << '+';
      if (ret.imag())
        cout << ret.imag() << "i";
      cout << endl;
    } catch (char *str) {
      cout << "overflow" << endl;
    }
  }
}
Problem p00686 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(in) in.begin(), in.end()
#define pb(in, a) in.push_back(a)
using namespace std;
int a[4] = {0, 1, 0, -1};
int b[4] = {1, 0, -1, 0};
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int to = 0;
    string s;
    int x = 1, y = 1;
    while (1) {
      cin >> s;
      if (s == "FORWARD") {
        int tmp;
        cin >> tmp;
        x += tmp * a[to];
        y += tmp * b[to];
      } else if (s == "BACKWARD") {
        int tmp;
        cin >> tmp;
        x -= tmp * a[to];
        y -= tmp * b[to];
      } else if (s == "STOP")
        break;
      else if (s == "LEFT")
        to--;
      else
        to++;

      if (to > 3)
        to = 0;
      else if (to < 0)
        to = 3;

      if (x > n)
        x = n;
      else if (x < 1)
        x = 1;
      if (y > m)
        y = m;
      else if (y < 1)
        y = 1;
      // cout<<x<<" "<<y<<endl;
    }
    cout << x << " " << y << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(in) in.begin(), in.end()
#define pb(in, a) in.push_back(a)
using namespace std;
int a[4] = {0, 1, 0, -1};
int b[4] = {1, 0, -1, 0};
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int to = 0;
    string s;
    int x = 1, y = 1;
    while (cin >> s) {
      int tmp;
      cin >> tmp;
      if (s == "STOP")
        break;
      if (s == "FORWARD") {
        x += tmp * a[to];
        y += tmp * b[to];
      } else {
        x -= tmp * a[to];
        y -= tmp * b[to];
      }
      if (x > n)
        x = n;
      else if (x < 1)
        x = 1;
      if (y > m)
        y = m;
      else if (y < 1)
        y = 1;

      cin >> s;
      if (s == "STOP")
        break;
      else if (s == "LEFT")
        to--;
      else
        to++;
      if (to > 3)
        to = 0;
      else if (to < 0)
        to = 3;
    }
    cout << x << " " << y << endl;
  }
}
Problem p00686 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int UP = 0, RIGHT = 1, DOWN = 2, LEFT = 3;

int m, n;
int i = 1, j = 1;
int dir = UP;

void fwd(int s) {
  if (dir == UP)
    j = min(j + s, n);
  if (dir == DOWN)
    j = max(j - s, 1);
  if (dir == RIGHT)
    i = min(i + s, m);
  if (dir == LEFT)
    i = max(i - s, 1);
}

int main() {
  while (true) {
    cin >> m >> n;
    i = j = 1;
    dir = UP;
    if (m == 0 && n == 0)
      break;
    while (true) {
      string s;
      int t = 0;
      cin >> s;
      if (s == "BACKWARD" || s == "FORWARD")
        cin >> t;
      if (s == "STOP")
        break;
      if (s == "RIGHT")
        dir = (dir + 1) % 4;
      if (s == "LEFT")
        dir = (dir + 3) % 4;
      if (s == "BACKWARD") {
        dir = (dir + 2) % 4;
        fwd(t);
        dir = (dir + 2) % 4;
      }
      if (s == "FORWARD")
        fwd(t);
      // printf("(%d, %d) | Dir: %d | Command: %s %d\\n", i, j, dir, s.c_str(),
      // t);
    }
    cout << i << " " << j << endl;
  }
}


Error: TLE

Fixed submission:

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

const int UP = 0, RIGHT = 1, DOWN = 2, LEFT = 3;

int m, n;
int i = 1, j = 1;
int dir = UP;

void fwd(int s) {
  if (dir == UP)
    i = min(i + s, m);
  if (dir == DOWN)
    i = max(i - s, 1);
  if (dir == RIGHT)
    j = min(j + s, n);
  if (dir == LEFT)
    j = max(j - s, 1);
}

int main() {
  while (true) {
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    while (true) {
      string s;
      cin >> s;
      if (s == "STOP")
        break;
      if (s == "RIGHT")
        dir = (dir + 1) % 4;
      if (s == "LEFT")
        dir = (dir + 3) % 4;
      int t;
      cin >> t;
      if (s == "BACK") {
        dir = (dir + 2) % 4;
        fwd(t);
        dir = (dir + 2) % 4;
      }
      if (s == "FORWWARD")
        fwd(t);
    }
    cout << i << " " << j << endl;
  }
}
Problem p00686 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  int w, h;
  int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
  while (true) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    string a;
    int s = 0;
    int x = 1, y = 1, z;
    while (true) {
      cin >> a;
      if (a == "STOP")
        break;
      if (a == "RIGHT")
        s = (s + 1) % 4;
      if (a == "LEFT")
        s = (s + 3) % 4;
      if (a == "FORWARD") {
        cin >> z;
        x += dx[s] * z, y += dy[s] * z;
        if (x < 1)
          x = 1;
        if (x > w)
          x = w;
        if (y < 1)
          y = 1;
        if (y > h)
          y = h;
      }
      if (a == "BACKWARD") {
        cin >> z;
        x -= dx[s] * z, y -= dy[s] * z;
        if (x < 1)
          x = 1;
        if (x > w)
          x = w;
        if (y < 1)
          y = 1;
        if (y > h)
          y = h;
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int w, h;
  int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
  while (true) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    string a;
    int s = 0;
    int x = 1, y = 1, z;
    while (true) {
      cin >> a;
      if (a == "STOP")
        break;
      if (a == "RIGHT")
        s = (s + 1) % 4;
      if (a == "LEFT")
        s = (s + 3) % 4;
      if (a == "FORWARD") {
        cin >> z;
        x += dx[s] * z, y += dy[s] * z;
        if (x < 1)
          x = 1;
        if (x > w)
          x = w;
        if (y < 1)
          y = 1;
        if (y > h)
          y = h;
      }
      if (a == "BACKWARD") {
        cin >> z;
        x -= dx[s] * z, y -= dy[s] * z;
        if (x < 1)
          x = 1;
        if (x > w)
          x = w;
        if (y < 1)
          y = 1;
        if (y > h)
          y = h;
      }
    }
    cout << x << " " << y << endl;
  }
  while (true) {
    cin >> w;
  }
  return 0;
}
Problem p00686 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string order;
  int height, wide, x, y, num;
  while (1) {
    x = 1;
    y = 1;
    cin >> wide >> height;
    if (wide == 0 && height == 0)
      break;
    int angle = 1;
    while (1) {

      cin >> order;
      if (order == "STOP")
        break;

      if (order == "FORWARD") {
        cin >> num;
        if (angle == 1) {
          y += num;
        } else if (angle == 2) {
          x += num;
        } else if (angle == 3) {
          y -= num;
        } else if (angle == 4) {
          x -= num;
        }
      }

      if (order == "BACKWARD") {
        cin >> num;
        if (angle == 1) {
          y -= num;

        } else if (angle == 2) {
          x -= num;

        } else if (angle == 3) {
          y += num;

        } else if (angle == 4) {
          x += num;
        }
      }

      if (x < 1) {
        x = 1;
      } else if (x > wide) {
        x = wide;
      }

      if (y < 1) {
        y = 1;
      } else if (y > height) {
        y = height;
      }

      if (order == "RIGHT") {
        angle++;
        if (angle == 5)
          angle = 1;
      }

      if (order == "LEFT") {
        angle--;
        if (angle == 0)
          angle = 4;
      }
    }
    cout << x << " " << y << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  string order;
  int height, wide, x, y, num, flag;
  while (1) {
    flag = 0;
    x = 1;
    y = 1;
    cin >> wide >> height;
    if (wide == 0 && height == 0)
      break;

    while (1) {

      cin >> order;
      if (order == "STOP")
        break;

      if (order == "FORWARD") {
        cin >> num;
        y += num;
        if (height < y || y < 0) {
          y -= num;
          break;
        }
      }

      if (order == "BACKWARD") {
        cin >> num;
        y -= num;
        if (height < y || y < 0) {
          y += num;
          break;
        }
      }

      if (order == "RIGHT" || order == "LEFT") {
        swap(x, y);
        swap(height, wide);
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}
Problem p00686 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    int mx = 1, my = 1;
    int direction = 1;
    while (1) {
      string command;
      int step;
      cin >> command;
      if (command == "FORWARD") {
        cin >> step;
        if (direction == 1)
          my += step;
        else if (direction == 2)
          mx += step;
        else if (direction == 3)
          my -= step;
        else if (direction == 4)
          mx -= step;
      } else if (command == "BACKWARD") {
        cin >> step;
        if (direction == 1)
          my -= step;
        else if (direction == 2)
          mx -= step;
        else if (direction == 3)
          my += step;
        else if (direction == 4)
          mx += step;
      } else if (command == "RIGHT") {
        direction++;
        if (direction == 5)
          direction = 1;
      } else if (command == "LEFT") {
        direction--;
        if (direction == 0)
          direction = 4;
      } else if (command == "STOP")
        break;

      if (mx < 1)
        mx = 1;
      else if (mx > n)
        mx = n;
      if (my < 1)
        my = 1;
      else if (my > m)
        my = m;
    }
    cout << mx << " " << my << endl;
  }
}

Error: TLE

Fixed submission:

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

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    int mx = 1, my = 1;
    int direction = 0;
    while (1) {
      string command;
      int step;
      cin >> command >> step;
      if (command == "FORWARD") {
        if (mx + dx[direction] * step <= n)
          mx += dx[direction] * step;
        else
          mx = n;
        if (my + dy[direction] * step <= m)
          my += dy[direction] * step;
        else
          my = m;
      }
      if (command == "BACKWARD") {
        if (0 <= mx - dx[direction] * step)
          mx -= dx[direction] * step;
        else
          mx = 0;
        if (0 <= my - dy[direction] * step)
          my -= dy[direction] * step;
        else
          my = 0;
      }
      cin >> command;
      if (command == "RIGHT")
        direction = (direction + 1) % 4;
      else if (command == "LEFT")
        direction = (direction - 1) % 4;
      else if (command == "STOP")
        break;
    }
    cout << mx << " " << my << endl;
  }
}
Problem p00687 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, a, b;
  bool t[1000001];
  while (cin >> n >> a >> b && (n + a + b)) {
    fill(t, t + 1000001, false);
    t[0] = true;
    for (int i = 0; i <= n; i++) {
      if (t[i]) {
        if (i + a <= n) {
          t[i + a] = true;
        }
        if (i + b <= n) {
          t[i + b] = true;
        }
      }
    }
    a = 0;
    for (int i = 1; i <= n; i++) {
      if (!t[i]) {
        a++;
      }
    }

    cout << a << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, a, b;
  bool t[1000001];
  while (cin >> n >> a >> b && (n + a + b)) {
    fill(t, t + 1000001, false);
    t[0] = true;
    for (int i = 0; i <= n; i++) {
      if (t[i]) {
        t[i + a] = t[i + b] = true;
      }
    }
    a = 0;
    for (int i = 1; i <= n; i++) {
      if (!t[i]) {
        a++;
      }
    }

    cout << a << endl;
  }

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

#include <iostream>
#define MAX 1000001
#include <set>
#include <vector>
using namespace std;
int main() {
  int n, a, b;
  while (cin >> n >> a >> b, n) {
    int ans = 0;
    vector<int> tab(MAX);
    tab[0] = 1;
    for (int i = min(a, b); i <= n; i++) {
      if (i - a >= 0 && tab[i - a]) {
        tab[i] = 1;
        ans++;
      } else if (i - b >= 0 && tab[i - b]) {
        tab[i] = 1;
        ans++;
      }
    }
    cout << n - ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
using namespace std;
int main() {
  int n, a, b;
  while (cin >> n >> a >> b, n) {
    set<int> tab;
    for (int i = 0; i * a <= n; i++)
      for (int j = 0; i * a + j * b <= n; j++) {
        tab.insert(i * a + j * b);
      }
    cout << n - tab.size() + 1 << endl;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Runtime Error


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

int main() {
  int f[1000001];
  int n, a, b, c;
  int i, j;
  while (cin >> n >> a >> b, n || a || b) {
    memset(f, 1, sizeof(int) * 1000001);
    for (i = 0; i <= n; i += a)
      if (f[i])
        for (j = i; j <= n; j += b)
          f[j] = 0;
    c = 0;
    for (i = 1; i <= n; i++)
      if (f[i])
        c++;
    cout << c << endl;
  }
}

Error: 0

Fixed submission:


#include <iostream>
using namespace std;

int main() {
  int f[101];
  int n, a, b, c;
  int i, j;
  while (cin >> n >> a >> b, n || a || b) {
    for (i = 0; i <= n; i++)
      f[i] = 1;
    for (i = 0; i <= n; i += a)
      if (f[i])
        for (j = i; j <= n; j += b)
          f[j] = 0;
    c = 0;
    for (i = 1; i <= n; i++)
      if (f[i])
        c++;
    cout << c << endl;
  }
}
Problem p00687 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MAX_N 1000010
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 100000005
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;

int gcm(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}

int lcm(int a, int b) { return a / gcm(a, b) * b; }

int main() {
  int n, a, b;
  int LCM, GCM;
  bool flag[MAX_N];
  int count[MAX_N];
  while (1) {
    cin >> n >> a >> b;
    if (n == 0)
      break;
    rep(i, MAX_N) { flag[i] = 0; }
    LCM = lcm(a, b);
    GCM = gcm(a, b);
    int ans;
    int irange = min(MAX_N - 1, LCM) / a + 1;
    rep(i, irange) {
      int jrange = (min(MAX_N - 1, LCM) - a * i) / b + 1;
      rep(j, jrange) { flag[a * i + b * j] = true; }
    }
    count[0] = 0;
    rep(i, MAX_N - 1) { count[i + 1] = count[i] + flag[i + 1]; }
    if (n < LCM) {
      ans = count[n];
    } else {
      ans = count[LCM] + (n - LCM) / GCM;
    }
    cout << n - ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MAX_N 100010
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 100000005
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;

int gcm(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}

int lcm(int a, int b) { return a / gcm(a, b) * b; }

int main() {
  int n, a, b;
  int LCM, GCM;
  bool flag[MAX_N];
  int count[MAX_N];
  while (1) {
    cin >> n >> a >> b;
    if (n == 0)
      break;
    rep(i, MAX_N) { flag[i] = 0; }
    LCM = lcm(a, b);
    GCM = gcm(a, b);
    int ans;
    int irange = min(MAX_N - 1, LCM) / a + 1;
    rep(i, irange) {
      int jrange = (min(MAX_N - 1, LCM) - a * i) / b + 1;
      rep(j, jrange) { flag[a * i + b * j] = true; }
    }
    count[0] = 0;
    rep(i, MAX_N - 1) { count[i + 1] = count[i] + flag[i + 1]; }
    if (n < LCM) {
      ans = count[n];
    } else {
      ans = count[LCM] + (n - LCM) / GCM;
    }
    cout << n - ans << endl;
  }
}
Problem p00687 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int map[1500000];
  long n, a, b, ans;

  while (1) {
    cin >> n >> a >> b;
    if (n == 0 && a == 0 && b == 0)
      break;
    for (long i = 1; i < n + 1; i++) {
      map[i] = 1;
    }
    map[0] = 0;
    for (long i = 0; i < n + 1; i++) {
      if (map[i] == 0) {
        map[i + a] = 0;
        map[i + b] = 0;
      }
    }
    ans = 0;
    for (long i = 0; i < n + 1; i++) {
      ans += map[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int map[100000];
  int n, a, b, ans;

  while (1) {
    cin >> n >> a >> b;
    if (n == 0 && a == 0 && b == 0)
      break;
    for (int i = 1; i < n + 1; i++) {
      map[i] = 1;
    }
    map[0] = 0;
    for (int i = 0; i < n + 1; i++) {
      if (map[i] == 0) {
        map[i + a] = 0;
        map[i + b] = 0;
      }
    }
    ans = 0;
    for (int i = 0; i < n + 1; i++) {
      ans += map[i];
    }
    cout << endl << ans << endl;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, a, b;
  while (cin >> n >> a >> b, n + a + b) {
    vector<int> table(n + 1);
    table[a] = 1;
    table[b] = 1;
    for (int i = 1; i <= n; i++)
      if ((i > a && table[i - a]) || (i > b && table[i - b]))
        table[i] = 1;
    int ans = 0;
    for (int i = 1; i <= n; i++)
      if (table[i] == 0)
        ans++;
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, a, b;
  while (cin >> n >> a >> b, n + a + b) {
    int ans = n;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= i / a; j++) {
        if ((i - a * j) % b == 0) {
          ans--;
          break;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define pi 3.14159265358979

int e[1000010];

int main(void) {

  int n, a, b;
  for (;;) {
    cin >> n >> a >> b;
    if (n == 0 && a == 0 && b == 0)
      break;

    if (a > b)
      swap(a, b);
    e[0] = 1;
    for (int i = 0; i + a <= n; i++) {
      if (e[i] == 1)
        e[i + a] = 1;
    }
    for (int i = 0; i + b <= n; i++) {
      if (e[i] == 1)
        e[i + b] = 1;
    }

    int c = 0;
    for (int i = 1; i <= n; i++)
      if (e[i] == 0)
        c++;

    cout << c << endl;

    for (int i = 1; i <= n; i++)
      e[i] = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define pi 3.14159265358979

int g(int x, int y) {
  int a = max(x, y), b = min(x, y);
  if (a % b == 0)
    return b;
  else
    return g(b, a % b);
}

int main(void) {

  int n, a, b;
  for (;;) {
    cin >> n >> a >> b;
    if (n == 0 && a == 0 && b == 0)
      break;

    int c = 0;
    REP(i, 1, n) {
      if (i % a == 0 || i % b == 0)
        c++;
      else if (i % (a + b) == 0)
        c++;
      else if (i % g(a, b) == 0) {
        REP(x, 1, min(i / a, b)) {
          if ((i - a * x) % b == 0) {
            c++;
            break;
          }
        }
      }
    }

    cout << n - c << endl;
  }

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

#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
bool f[1000001];
int main() {
  int n, a, b, s, t;
  while (cin >> n >> a >> b, n) {
    rep(i, n + 1) f[i] = 1;
    rep(j, a) for (t = b * j; t <= n; t += a) f[t] = 0;
    s = 0;
    rep(i, n) s += f[i + 1];
    cout << s << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
bool f[1000001];
int main() {
  int n, a, b, s, t;
  while (cin >> n >> a >> b, n) {
    rep(i, n) f[i] = 1;
    for (int i = 0; (s = i * a) <= n; i++)
      rep(j, a) f[s + b * j] = 0;
    s = 0;
    rep(i, n) s += f[i];
    cout << s << endl;
  }
  return 0;
}