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

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

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

static const double EPS = 1e-8;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

int direction[1001][1001];
int dp[1001][1001];

int main() {
  int H, W, n;
  while (~scanf("%d %d %d", &H, &W, &n)) {
    if (H == 0 && W == 0)
      break;

    memset(direction, 0, sizeof(direction));
    memset(dp, 0, sizeof(dp));

    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        scanf("%d", &direction[y][x]);
      }
    }

    dp[0][0] = n - 1; // offset
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        // dir
        // 0 v
        // 1 ->
        if (y + 1 < H)
          dp[y + 1][x] += (dp[y][x] + (direction[y][x] == 0 ? 1 : 0)) / 2;
        if (x + 1 < W)
          dp[y][x + 1] += (dp[y][x] + (direction[y][x] == 1 ? 1 : 0)) / 2;
      }
    }

    int x = 0;
    int y = 0;
    while (y < H && x < W) {
      if ((dp[y][x] + direction[y][x]) % 2 == 0)
        y++;
      else if ((dp[y][x] % 2 + direction[y][x]) % 2 == 1)
        x++;
    }
    printf("%d %d\\n", y + 1, x + 1);
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

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

static const double EPS = 1e-8;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

int direction[1001][1001];
int dp[1001][1001];

int main() {
  int H, W, n;
  while (~scanf("%d %d %d", &H, &W, &n)) {
    if (H == 0 && W == 0)
      break;

    memset(direction, 0, sizeof(direction));
    memset(dp, 0, sizeof(dp));

    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        scanf("%d", &direction[y][x]);
      }
    }

    dp[0][0] = n - 1; // offset
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        // dir
        // 0 v
        // 1 ->
        if (y + 1 < H)
          dp[y + 1][x] += ((dp[y][x] + (direction[y][x] == 0 ? 1 : 0)) / 2);
        if (x + 1 < W)
          dp[y][x + 1] += ((dp[y][x] + (direction[y][x] == 1 ? 1 : 0)) / 2);
      }
    }

    int x = 0;
    int y = 0;
    while (y < H && x < W) {
      if (dp[y][x] % 2 + direction[y][x] == 0)
        y++;
      else if (dp[y][x] % 2 + direction[y][x] == 1)
        x++;
    }
    printf("%d %d\\n", y + 1, x + 1);
  }
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int h, w, n;
int a[1002][1002], b[1002][1002] = {0};

pair<int, int> walk(int x, int y) {
  if (a[x][y] == 0)
    x++;
  else
    y++;
  if (x < h && y < w)
    return walk(x, y);
  pair<int, int> ret;
  ret.first = x + 1;
  ret.second = y + 1;
  return ret;
}

int main() {
  while (1) {
    scanf("%d%d%d", &h, &w, &n);
    if (h == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &a[i][j]);
        b[i][j] = 0;
      }
    }
    b[0][0] = n - 1;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        b[i][j + 1] += b[i][j] / 2;
        b[i + 1][j] += b[i][j] / 2;
        if (b[i][j] % 2 == 1) {
          if (a[i][j] == 0)
            b[i + 1][j]++;
          else
            b[i][j + 1]++;
        }
        a[i][j] += b[i][j];
        a[i][j] %= 2;
      }
    }
    pair<int, int> ret = walk(0, 0);
    printf("%d %d\\n", ret.first, ret.second);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int h, w, n;
int a[1002][1002], b[1002][1002] = {0};

pair<int, int> walk(int x, int y) {
  if (a[x][y] == 0)
    x++;
  else
    y++;
  if (x < h && y < w)
    return walk(x, y);
  pair<int, int> ret;
  ret.first = x + 1;
  ret.second = y + 1;
  return ret;
}

int main() {
  while (1) {
    scanf("%d%d%d", &h, &w, &n);
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &a[i][j]);
        b[i][j] = 0;
      }
    }
    b[0][0] = n - 1;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        b[i][j + 1] += b[i][j] / 2;
        b[i + 1][j] += b[i][j] / 2;
        if (b[i][j] % 2 == 1) {
          if (a[i][j] == 0)
            b[i + 1][j]++;
          else
            b[i][j + 1]++;
        }
        a[i][j] += b[i][j];
        a[i][j] %= 2;
      }
    }
    pair<int, int> ret = walk(0, 0);
    printf("%d %d\\n", ret.first, ret.second);
  }
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
int H, W, N;
int X[1000][1000];
int DP[1000][1000];
int main() {
  while (true) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        DP[i][j] = 0;
      }
    }
    scanf("%d%d%d", &H, &W, &N);
    if (H == 0 && W == 0 && N == 0)
      break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        scanf("%d", &X[i][j]);
      }
    }
    DP[0][0] = N - 1;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (i == 0 && j == 0)
          continue;
        if (i == 0) {
          if (DP[i][j - 1] & 1) {
            if (X[i][j - 1] == 1) {
              DP[i][j] = (DP[i][j - 1] >> 1) + 1;
            } else
              DP[i][j] = DP[i][j - 1] >> 1;
          } else {
            DP[i][j] = DP[i][j - 1] >> 1;
          }
        } else if (j == 0) {
          if (DP[i - 1][j] & 1) {
            if (X[i - 1][j] == 0) {
              DP[i][j] = (DP[i - 1][j] >> 1) + 1;
            } else
              DP[i][j] = DP[i - 1][j] >> 1;
          } else {
            DP[i][j] = DP[i - 1][j] >> 1;
          }
        } else {
          if (DP[i - 1][j] & 1) {
            if (X[i - 1][j] == 0) {
              DP[i][j] += (DP[i - 1][j] >> 1) + 1;
            } else
              DP[i][j] += DP[i - 1][j] >> 1;
          } else {
            DP[i][j] += DP[i - 1][j] >> 1;
          }
          if (DP[i][j - 1] & 1) {
            if (X[i][j - 1] == 1) {
              DP[i][j] += (DP[i][j - 1] >> 1) + 1;
            } else
              DP[i][j] += DP[i][j - 1] >> 1;
          } else {
            DP[i][j] += DP[i][j - 1] >> 1;
          }
        }
      }
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        X[i][j] = (X[i][j] + DP[i][j]) & 1;
      }
    }
    int XX = 0;
    int YY = 0;
    while (XX < W && YY < H) {
      if (X[YY][XX])
        XX++;
      else
        YY++;
    }
    printf("%d %d\\n", YY + 1, XX + 1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
typedef pair<int, int> P;
int H, W, N;
int X[1000][1000];
P change() {
  int x = 0, y = 0;
  while (x < W && y < H) {
    if (X[y][x]) {
      x++;
      X[y][x - 1] = 0;
    } else {
      y++;
      X[y - 1][x] = 1;
    }
  }
  return P(y, x);
}
int main() {
  while (true) {
    scanf("%d%d%d", &H, &W, &N);
    if (H == 0 && W == 0 && N == 0)
      break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        scanf("%d", &X[i][j]);
      }
    }
    int ans1 = 0;
    int ans2 = 0;
    for (int i = 0; i < N; i++) {
      if (i == N - 1) {
        P p = change();
        ans1 = p.first;
        ans2 = p.second;
      } else {
        P p = change();
        // printf("%d %d\\n",p.first+1,p.second+1);
      }
    }
    printf("%d %d\\n", ans2 + 1, ans1 + 1);
  }
  return 0;
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

void solve(int H, int W, int N) {
  int moji[H][W];
  int cnt[H + 1][W + 1];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> moji[i][j]; // 0->south / 1->east
    }
  }

  // count visits for N-1 walk
  cnt[0][0] = N - 1;
  for (int j = 0; j < W - 1; ++j) {
    cnt[0][j + 1] = (cnt[0][j] + moji[0][j]) / 2;
  }
  for (int i = 0; i < H - 1; ++i) {
    cnt[i + 1][0] = (cnt[i][0] + 1 - moji[i][0]) / 2;
  }
  for (int i = 0; i < H - 1; ++i) {
    for (int j = 0; j < W - 1; ++j) {
      cnt[i + 1][j + 1] = (cnt[i + 1][j] + moji[i + 1][j]) / 2 +
                          (cnt[i][j + 1] + 1 - moji[i][j + 1]) / 2;
    }
  }
  // calculate status after N-1 walk
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      moji[i][j] = (moji[i][j] + cnt[i][j]) % 2;
    }
  }
  // Nth walk
  int h = 0, w = 0;
  while (h < H && w < W) {
    if (moji[h][w] == 0)
      ++h;
    else
      ++w;
  }
  cout << h + 1 << " " << w + 1 << endl;

  return;
}

int main() {
  int H, W, N;
  while (true) {
    cin >> H >> W >> N;
    if (H == 0 && W == 0 && N == 0)
      break;
    solve(H, W, N);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void solve(int H, int W, int N) {
  int moji[H][W];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> moji[i][j]; // 0->south / 1->east
    }
  }

  int h, w;
  for (int i = 0; i < N; ++i) {
    h = 0;
    w = 0;
    while (h < H && w < W) {
      if (moji[h][w] == 0) {
        moji[h][w] = 1;
        ++h;
      } else {
        moji[h][w] = 0;
        ++w;
      }
    }
  }

  cout << h + 1 << " " << w + 1 << endl;

  return;
}

int main() {
  int H, W, N;
  while (true) {
    cin >> H >> W >> N;
    if (H == 0 && W == 0 && N == 0)
      break;
    solve(H, W, N);
  }
  return 0;
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
int h, w, n, p;
bool board[1001][1001];
ll cnt[1001][1001];

int main() {
  while (cin >> h >> w >> n, h | w | n) {
    memset(board, false, sizeof(board));
    memset(cnt, 0, sizeof(cnt));
    cnt[0][0] = n - 1;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> p;
        if (p)
          board[i][j] = true;
      }
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (cnt[i][j] % 2 == 0) {
          if (j < w - 1)
            cnt[i][j + 1] += cnt[i][j] / 2;
          if (i < h - 1)
            cnt[i + 1][j] += cnt[i][j] / 2;
        } else {
          if (j < w - 1)
            cnt[i][j + 1] += cnt[i][j] / 2 + ((board[i][j]) ? 1 : 0);
          if (i < h - 1)
            cnt[i + 1][j] += cnt[i][j] / 2 + ((!board[i][j]) ? 1 : 0);
          board[i][j] ^= true;
        }
      }
    }

    int x = 0, y = 0;
    while (x < w && y < h) {
      if (board[y][x])
        x++;
      else
        y++;
    }
    x++, y++;
    cout << y << " " << x << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int h, w;
  long n;
  while (1) {
    cin >> h >> w >> n;
    if (h == 0 && w == 0 && n == 0)
      break;

    int r[w][h];

    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        cin >> r[j][i];

    int x, y;
    for (long l = 0; l < n - 1; l++) {
      x = 0, y = 0;
      while (1) {
        if (x > w - 1 || y > h - 1)
          break;
        if (r[x][y] == 0) {
          r[x][y] = 1;
          y++;
        } else {
          r[x][y] = 0;
          x++;
        }
      }
    }

    x = 0, y = 0;
    while (1) {
      if (x > w - 1 || y > h - 1)
        break;
      if (r[x][y] == 0) {
        r[x][y] = 1;
        y++;
      } else {
        r[x][y] = 0;
        x++;
      }
    }
    cout << y + 1 << " " << x + 1 << endl;
  }
}
Problem p00465 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <queue>
#include <stdio.h>

using namespace std;

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

struct cxy {
  int cost, x, y;
  bool operator<(const cxy &rhs) const { return cost < rhs.cost; }
  bool operator>(const cxy &rhs) const { return cost > rhs.cost; }
};

int CalcTable(int *ret) {
  int w, h, x, y;
  scanf("%d%d%d%d", &w, &h, &x, &y);
  static int m[500][500];
  REP(i, h)
  REP(j, w)
  scanf("%d", &m[i][j]);
  ret[0] = 0;
  priority_queue<cxy, vector<cxy>, greater<cxy>> pq;
  static bool used[500][500];
  REP(i, h)
  REP(j, w)
  used[i][j] = false;
  pq.push({1, --x, --y});
  used[y][x] = true;
  int c = 0;
  static const int dxy[] = {0, -1, 0, 1, 0};
  int b = 0;
  while (!pq.empty()) {
    cxy t = pq.top();
    pq.pop();
    b = max(b, t.cost);
    ret[++c] = b;
    REP(i, 4) {
      int nx = t.x + dxy[i];
      int ny = t.y + dxy[i + 1];
      if (0 <= nx && nx < w && 0 <= ny && ny < h)
        if (!used[ny][nx]) {
          pq.push({m[ny][nx], nx, ny});
          used[ny][nx] = true;
        }
    }
  }
  return w * h + 1;
}

int main() {
  while (1) {
    int r;
    scanf("%d", &r);
    if (r == 0)
      break;
    static int buf1[250001];
    static int buf2[250001];
    int r1 = CalcTable(buf1);
    int r2 = CalcTable(buf2);
    int ans = 1145141919;
    REP(i, r1) {
      int j = r - i;
      if (0 <= j && j < r2)
        ans = min(ans, buf1[i] + buf2[j]);
    }
    printf("%d\\n", ans);
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <functional>
#include <queue>
#include <stdio.h>

using namespace std;

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

struct cxy {
  int cost, x, y;
  bool operator<(const cxy &rhs) const { return cost < rhs.cost; }
  bool operator>(const cxy &rhs) const { return cost > rhs.cost; }
};

int CalcTable(int *ret) {
  int w, h, x, y;
  scanf("%d%d%d%d", &w, &h, &x, &y);
  static int m[500][500];
  REP(i, h)
  REP(j, w)
  scanf("%d", &m[i][j]);
  ret[0] = 0;
  priority_queue<cxy, vector<cxy>, greater<cxy>> pq;
  static bool used[500][500];
  REP(i, h)
  REP(j, w)
  used[i][j] = false;
  pq.push({1, --x, --y});
  used[y][x] = true;
  int c = 0;
  static const int dxy[] = {0, -1, 0, 1, 0};
  int b = 0;
  while (!pq.empty()) {
    cxy t = pq.top();
    pq.pop();
    b = max(b, t.cost);
    ret[++c] = b;
    REP(i, 4) {
      int nx = t.x + dxy[i];
      int ny = t.y + dxy[i + 1];
      if (0 <= nx && nx < w && 0 <= ny && ny < h)
        if (!used[ny][nx]) {
          pq.push({m[ny][nx], nx, ny});
          used[ny][nx] = true;
        }
    }
  }
  return w * h + 1;
}

int main() {
  while (1) {
    int r;
    scanf("%d", &r);
    if (r == 0)
      break;
    static int buf1[250001];
    static int buf2[250001];
    int r1 = CalcTable(buf1);
    int r2 = CalcTable(buf2);
    int ans = 1145141919;
    REP(i, r1) {
      int j = r - i;
      if (j < r2)
        ans = min(ans, buf1[i] + buf2[j]);
    }
    printf("%d\\n", ans);
  }
}
Problem p00465 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, pair<int, int>> pp;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int level[2][250001];
int room[500][500];
bool visited[500][500];

int main() {
  int r;
  while (cin >> r, r) {
    int w, h, ex, ey;
    int e[2];
    for (int i = 0; i < 2; ++i) {
      cin >> w >> h >> ex >> ey;
      for (int j = 0; j < h; ++j) {
        for (int k = 0; k < w; ++k) {
          cin >> room[j][k];
        }
      }
      memset(visited, 0, sizeof(visited));
      visited[--ey][--ex] = 1;
      level[i][0] = 0;
      int mlevel = 0, index = 1;
      priority_queue<pp, vector<pp>, greater<pp>> pq;
      pq.push(make_pair(room[ey][ex], make_pair(ex, ey)));
      while (!pq.empty()) {
        pp cur = pq.top();
        pq.pop();
        mlevel = max(mlevel, cur.first);
        level[i][index++] = mlevel;
        for (int j = 0; j < 4; ++j) {
          int cx = cur.second.first + dx[j];
          int cy = cur.second.second + dy[j];
          if (cx >= 0 && cx < w && cy >= 0 && cy < h && visited[cy][cx] == 0) {
            visited[cy][cx] = 1;
            pq.push(make_pair(room[cy][cx], make_pair(cx, cy)));
          }
        }
      }
      e[i] = index - 1;
    }
    int ans = 1000000000;
    for (int i = 0; i <= r; ++i) {
      if (e[0] < r - i || e[1] < i)
        continue;
      ans = min(ans, level[1][i] + level[0][r - i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, pair<int, int>> pp;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int level[2][100001];
int room[500][500];
bool visited[500][500];

int main() {
  int r;
  while (cin >> r, r) {
    int w, h, ex, ey;
    int e[2];
    for (int i = 0; i < 2; ++i) {
      cin >> w >> h >> ex >> ey;
      for (int j = 0; j < h; ++j) {
        for (int k = 0; k < w; ++k) {
          cin >> room[j][k];
        }
      }
      memset(visited, 0, sizeof(visited));
      visited[--ey][--ex] = 1;
      level[i][0] = 0;
      int mlevel = 0, index = 1;
      priority_queue<pp, vector<pp>, greater<pp>> pq;
      pq.push(make_pair(room[ey][ex], make_pair(ex, ey)));
      while (!pq.empty()) {
        pp cur = pq.top();
        pq.pop();
        mlevel = max(mlevel, cur.first);
        level[i][index++] = mlevel;
        for (int j = 0; j < 4; ++j) {
          int cx = cur.second.first + dx[j];
          int cy = cur.second.second + dy[j];
          if (cx >= 0 && cx < w && cy >= 0 && cy < h && visited[cy][cx] == 0) {
            visited[cy][cx] = 1;
            pq.push(make_pair(room[cy][cx], make_pair(cx, cy)));
          }
        }
      }
      e[i] = index - 1;
    }
    int ans = 1000000000;
    for (int i = 0; i <= r; ++i) {
      if (e[0] < r - i || e[1] < i)
        continue;
      ans = min(ans, level[1][i] + level[0][r - i]);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int total;
  int books;
  int count = 0;

  while (true) {
    if (count == 0) {
      cin >> total;
      if (total == 0) {
        break;
      }
      count++;
    } else {
      cin >> books;
      total -= books;
      count++;
    }
    if (count == 10) {
      cout << total << '\\n';
      count = 0;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int total;
  int books;
  int count = 0;

  while (true) {
    if (count == 0) {
      cin >> total;
      if (total == 0) {
        break;
      }
      count++;
    } else {
      cin >> books;
      total -= books;
      count++;
    }
    if (count == 10) {
      cout << total << '\\n';
    }
  }
  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int sum = 0, in;
  while (cin >> sum, sum) {
    for (int i = 0; i < 9; i++) {
      cin >> in;
      sum -= in;
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int sum = 0, in;
  while (cin >> sum, sum) {
    for (int i = 0; i < 10; i++) {
      cin >> in;
      sum -= in;
    }
    cout << sum << endl;
  }
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a[11], i;
  while (1) {
    i = 1;
    cin >> a[0];
    if (a[0] == 0) {
      break;
    }
    while (1) {
      cin >> a[i];
      a[0] = a[0] - a[i];
      if (i == 9) {
        break;
      }
      if (a[0] == 0) {
        break;
      }
      i++;
    }
    cout << a[0] << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int a[11], i;
  while (1) {
    i = 1;
    cin >> a[0];
    if (a[0] == 0) {
      break;
    }
    while (1) {
      cin >> a[i];
      if (a[i] == 0) {
        break;
      }
      a[0] = a[0] - a[i];
      if (a[0] == 0) {
        break;
      }
      i++;
    }
    cout << a[0] << endl;
  }
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int s, a;
  while (cin >> s) {
    if (s == 0)
      break;
    for (int i = 0; i < 9; i++) {
      cin >> a;
      s -= a;
    }
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int s, a;
  while (cin >> s, s) {
    cin >> s;
    for (int i = 0; i < 9; i++) {
      cin >> a;
      s -= a;
    }
    cout << s << endl;
  }
}
Problem p00466 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int sum, wa = 0, i, r;
  while (1) {
    sum = 0;
    wa = sum;
    scanf("%d", &sum);
    if (sum == 0) {
      break;
    }
    for (i = 0; i < 9; i++) {
      scanf("%d", &r);
      wa = wa + r;
    }
    sum = sum - wa;
    printf("%d\\n", sum);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
int main() {
  int sum, wa = 0, goukei[100] = {0}, i, r, cnt;
  while (1) {
    scanf("%d", &sum);
    if (sum == 0) {
      break;
    }
    for (i = 0; i < 9; i++) {
      scanf("%d", &r);
      wa = wa + r;
    }
    goukei[i] = sum - wa;
    cnt++;
  }
  for (i = 0; i < cnt; i++) {
    printf("%d\\n", goukei[i]);
  }
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  int n;
  while (cin >> n, n) {
    int t;
    rep(i, 9) {
      cin >> t;
      n -= t;
    }
    cout << n << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  int n;
  while (cin >> n, n) {
    int t;
    rep(i, 10) {
      cin >> t;
      n -= t;
    }
    cout << n << endl;
  }
}