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

#include <iostream>
#define N 50
using namespace std;
/*
Hanafuda Shuffle
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

*/
int array[N];
void makearray(int n) {
  for (int i = 0; i < N; i++) {
    array[i] = n;
    if (n > 0)
      n -= 1;
  }
}
void shuffle(int p, int c) {
  int sarray[N];
  // copy unshuffled deck
  for (int i = p - 1 + c; i < N; i++) {
    sarray[i] = array[i];
  }
  // copy the c part
  int j = 0;
  for (int i = p - 1; i < p - 1 + c; i++) {
    sarray[j] = array[i];
    j++;
  }
  // copy the p part
  j = c;
  for (int i = 0; i < p - 1; i++) {
    sarray[j] = array[i];
    j++;
  }
  for (int i = 0; i < N; i++) {
    array[i] = sarray[i];
  }
}

int main() {
  int n, r, p, c;
  while (1) {
    cin >> n >> r;
    makearray(n);
    if (n == 0 && r == 0)
      break;
    for (int i = 0; i < r; i++) {
      cin >> p >> c;
      shuffle(p, c);
    }
    cout << array[0] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#define N 10
using namespace std;
/*
Hanafuda Shuffle
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

*/
int array[N];
void makearray(int n) {
  for (int i = 0; i < N; i++) {
    array[i] = n;
    if (n > 0)
      n -= 1;
  }
}
void shuffle(int p, int c) {
  int sarray[N];
  // copy unshuffled deck
  for (int i = p - 1 + c; i < N; i++) {
    sarray[i] = array[i];
  }
  // copy the c part
  int j = 0;
  for (int i = p - 1; i < p - 1 + c; i++) {
    sarray[j] = array[i];
    j++;
  }
  // copy the p part
  j = c;
  for (int i = 0; i < p - 1; i++) {
    sarray[j] = array[i];
    j++;
  }
  for (int i = 0; i < N; i++) {
    array[i] = sarray[i];
  }
}

int main() {
  int n, r, p, c;
  while (1) {
    cin >> n >> r;
    makearray(n);
    if (n == 0 && r == 0)
      break;
    for (int i = 0; i < r; i++) {
      cin >> p >> c;
      shuffle(p, c);
    }
    cout << array[0] << endl;
  }
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

#define R input[0][1]

using namespace std;

int input() {
  int input[51][2];
  cin >> input[0][0] >> input[0][1]; // まずnとr
  if (input[0][0] == 0 && input[0][1] == 0) {
    return 0;
  }
  for (char pos = 1; pos <= input[0][1]; pos++) { // r回のシャッフルの仕方を入力
    cin >> input[pos][0] >> input[pos][1];
  } // ここまで入力

  /*シャッフルもどし*/
  int whtop = 1; // 最後一番上にいるカードは、今何番目にいる？
  if (R == 0)
    return input[0][0]; // 一回もシャッフルしないならコレ

  whtop = input[input[0][1]][0]; // 一回目のもどしだけ別枠
  R--;
  while (input[0][1] != 0) {
    if (whtop <= input[R][1])
      whtop = whtop + input[R][0] - 1;
    else if ((input[R][0] + input[R][1] - 1) < whtop)
      whtop = whtop;
    else
      whtop = whtop - input[R][1];
    R--;
  }
  return input[0][0] - whtop + 1;
}

int main() {
  while (1) {
    int check;
    check = input();
    if (check == 0)
      break;
    else {
      cout << check << endl;
    }
  }
}


Error: 0

Fixed submission:

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

int input() {
  int input[51][2];
  cin >> input[0][0] >> input[0][1];
  if (input[0][0] == 0 && input[0][1] == 0) {
    return 0;
  }
  for (char pos = 1; pos <= input[0][1]; pos++) {
    cin >> input[pos][0] >> input[pos][1];
  }
  int whtop = 1;
  whtop = input[input[0][1]][0];
  input[0][1]--;
  while (input[0][1] != 0) {

    if (input[input[0][1]][1] >= whtop) {
      whtop = input[input[0][1]][0] + whtop - 1;
    } else {
      whtop = whtop - input[input[0][1]][1];
    }
    input[0][1]--;
  }
  return input[0][0] - whtop + 1;
}

int main() {
  int output[100];
  char topos = 0;
  while (1) {
    int check;
    check = input();
    if (check == 0)
      break;
    else {
      output[topos] = check;
      topos++;
    }
  }

  char sendpos = 0;
  while (sendpos < topos) {
    cout << output[sendpos] << endl;
    sendpos++;
  }
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int card[51];
  int tmp[50];
  int n, r, from, num;

  while (1) {
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;
    for (int i = 1; i <= n; i++) {
      card[i] = n - i + 1;
    }
    for (int i = 0; i < r; i++) {
      cin >> from >> num;
      for (int j = 0; j < num; j++) {
        tmp[j] = card[from + j];
      }
      for (int j = from - 1; j > 0; j--) {
        card[j + num] = card[j];
      }
      for (int j = 0; j < num; j++) {
        card[j + 1] = tmp[j];
      }
    }
    cout << card[1] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int card[51];
  int tmp[50];
  int n, r, from, num;
  int result[50], numres = 0;

  while (1) {
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;
    for (int i = 1; i <= n; i++) {
      card[i] = n - i + 1;
    }
    for (int i = 0; i < r; i++) {
      cin >> from >> num;
      for (int j = 0; j < num; j++) {
        tmp[j] = card[from + j];
      }
      for (int j = from; j > 0; j--) {
        card[j + num] = card[j];
      }
      for (int j = 0; j < num; j++) {
        card[j + 1] = tmp[j];
      }
    }
    result[numres] = card[1];
    numres++;
  }

  for (int i = 0; i < numres; i++) {
    cout << result[i] << endl;
  }

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

#include <iostream>
#include <queue>
#include <stack>

using namespace std;

void solve(stack<int> s, int r) {

  int p[r], c[r];

  for (int i = 0; i < r; i++) {
    cin >> p[i] >> c[i];
    p[i]--;
  }

  for (int i = 0; i < r; i++) {
    stack<int> s_sita;
    stack<int> s_ue;

    while (p[i]-- > 0) {
      int a = s.top();
      s.pop();
      // cout << "push_sita:" << a << endl;
      // cout << "p:" << p[i] << endl;
      // cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while (c[i]-- > 0) {
      int a = s.top();
      s.pop();
      // cout << "push_ue:" << a << endl;
      // cout << "c" << c[i] << endl;
      // cout << "size" << s.size() << endl;
      s_ue.push(a);
    }

    while (!s_sita.empty()) {
      s.push(s_sita.top());
      // cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }

    while (!s_ue.empty()) {
      s.push(s_ue.top());
      // cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }

    // cout << "size" << s.size() << endl;

    // cout << endl;
  }

  cout << s.top() << endl;

  return;
}

int main() {

  int r, n;

  while (1) {

    cin >> n >> r;
    if (r == 0 || n == 0)
      break;

    else {
      stack<int> s;
      for (int i = 1; i <= n; i++) {
        s.push(i);
        // cout << i << endl;
      }
      solve(s, r);
      // cout << "done" << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <queue>
#include <stack>

using namespace std;

void solve(stack<int> s, int r) {

  int p[r], c[r];

  for (int i = 0; i < r; i++) {
    cin >> p[i] >> c[i];
    p[i]--;
  }

  for (int i = 0; i < r; i++) {
    stack<int> s_sita;
    stack<int> s_ue;

    while (p[i]-- > 0) {
      int a = s.top();
      s.pop();
      // cout << "push_sita:" << a << endl;
      // cout << "p:" << p[i] << endl;
      // cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while (c[i]-- > 0) {
      int a = s.top();
      s.pop();
      // cout << "push_ue:" << a << endl;
      // cout << "c" << c[i] << endl;
      // cout << "size" << s.size() << endl;
      s_ue.push(a);
    }

    while (!s_sita.empty()) {
      s.push(s_sita.top());
      // cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }

    while (!s_ue.empty()) {
      s.push(s_ue.top());
      // cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }

    // cout << "size" << s.size() << endl;

    // cout << endl;
  }

  cout << s.top() << endl;

  return;
}

int main() {

  int r, n;

  cin >> n >> r;

  while (1) {
    if (r == 0 || n == 0)
      break;

    else {
      stack<int> s;
      for (int i = 1; i <= n; i++) {
        s.push(i);
        // cout << i << endl;
      }
      solve(s, r);
    }
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, r;
  vector<int> card;
  card.reserve(100);
  while (true) {
    cin >> n >> r;
    if (!n && !r)
      break;
    card.clear();
    // 1 .. n
    for (int i = 1; i <= n; i++) {
      card.push_back(i);
    }

    for (int i = 0; i < r; i++) {
      int p, c;

      cin >> p >> c;
      if (n == c)
        continue;

      vector<int>::iterator it = card.end() - p - c + 1;

      // temp
      for (int j = 0; j < c; j++) {
        card.push_back(*it);
        it++;
      }
      // erase
      card.erase(it - c, it);

      /*
        it = card.begin();
        while(it != card.end()){
        cout << " " << *it;
        it++;
        }
        cout << endl;
      */
    }
    cout << card[n - 1] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, r;
  vector<int> card;
  while (true) {
    cin >> n >> r;
    if (!n && !r)
      break;
    card.clear();
    // 1 .. n
    for (int i = 1; i <= n; i++) {
      card.push_back(i);
    }

    for (int i = 0; i < r; i++) {
      int p, c;

      cin >> p >> c;
      if (n == c)
        continue;

      vector<int>::iterator it = card.end() - p - c + 1;

      // temp
      for (int j = 0; j < c; j++) {
        card.push_back(*it);
        it++;
      }
      // erase
      card.erase(it - c, it);

      /*
      it = card.begin();
      while(it != card.end()){
              cout << " " << *it;
              it++;
      }
      cout << endl;
      */
    }
    cout << card[n - 1] << endl;
  }
  return 0;
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

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

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
  auto tmp = card;
  p--;
  rep(i, c) { card[i] = tmp[i + p]; }
  rep(i, p) { card[i + c] = tmp[i]; }
}
void solve() {
  vector<int> card(n);
  rep(i, n) card[i] = n - i;
  rep(i, r) {
    ops(card, p[i], c[i]);
    // rep(i, n) cout << card[i] << " ";
    // cout << endl;
  }
  cout << card[0] << endl;
}
int main() {
  while (cin >> n >> r, n) {
    p.resize(r);
    c.resize(r);
    rep(i, r) cin >> p[i] >> c[i];
    solve();
  }

  return 0;
}

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
  auto tmp = card;
  rep(i, c) { card[i] = tmp[i + p - 1]; }
  rep(i, p) { card[i + c] = tmp[i]; }
}
void solve() {
  vector<int> card(n);
  rep(i, n) card[i] = n - i;
  rep(i, n) cout << card[i] << " ";
  cout << endl;
  rep(i, r) {
    ops(card, p[i], c[i]);
    // rep(i, n) cout << card[i] << " ";
    // cout << endl;
  }
  cout << card[0] << endl;
}
int main() {
  while (cin >> n >> r, n) {
    p.resize(r);
    c.resize(r);
    rep(i, r) cin >> p[i] >> c[i];
    solve();
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, k, n) for (int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
  int n, r;
  while (cin >> n >> r, n) {
    vi card(n);
    rep(i, n) card[i] = n - i;
    rep(i, r) {
      int p, c;
      cin >> p >> c;
      vi tmp(c);
      rep(j, c) tmp[j] = card[p - 1 + j];
      rrep(j, p) card[j + c - 1] = card[j - 1];
      rep(j, c) card[j] = tmp[j];
    }
    cout << card[0] << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, k, n) for (int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
  int n, r;
  while (cin >> n >> r, n) {
    vi card(n);

    rep(i, n) card[i] = n - i;
    rep(i, r) {
      int p, c;
      cin >> p >> c;
      vi tmp(c);
      rep(j, c) tmp[c] = card[p - 1 + j];
      rrep(j, p - 1) card[j + c - 1] = card[j];
      rep(j, c) card[j] = tmp[c];
    }
    cout << card[0] << endl;
  }
  return 0;
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

void shafle(int b, int e, int *ans) {
  int tmp[50];
  b--;
  for (int i = 0; i < b; i++)
    tmp[i] = ans[i];
  for (int i = b; i < b + e; i++)
    ans[i - b] = ans[i];
  for (int i = e; i < b + e; i++)
    ans[i] = tmp[i - e];
}
int main() {
  int n, r;
  while (cin >> n >> r, n) {
    int ans[50];
    for (int i = 0; i < n; i++)
      ans[i] = n - i;
    for (int i = 0; i < r; i++) {
      int b, e;
      cin >> b >> e;
      shafle(b, e, ans);
    }
    cout << ans[0] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

void shuffle(int a, int b, int *ans) {
  int t[a];
  a--;
  for (int i = 0; i < a; i++) {
    t[i] = ans[i];
  }
  for (int i = a; i < a + b; i++) {
    ans[i - b] = t[i - b];
  }
  for (int i = b; i < a + b; i++) {
    ans[i] = t[i - b];
  }
}
int main() {
  int n, r;
  while (cin >> n >> r, n) {
    int ans[n];
    for (int i = 0; i < n; i++) {
      ans[i] = n - i;
    }
    for (int i = 0; i < r; i++) {
      int b, e;
      cin >> b >> e;
      shuffle(b, e, ans);
    }
    cout << ans[0] << endl;
  }

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

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> cards;
  vector<int>::iterator cardsIterator;
  vector<int>::iterator shuffuleIterator;
  int n, r, p, c;

  while (cin >> n >> r, n && r) {
    cards.clear(); // 初期化
    // カードの山生成
    for (int i = 0; i < n; ++i) {
      cards.push_back(i + 1);
    }
    // シャッフル
    while (cin >> p >> c, r--) {
      cardsIterator = cards.end();
      cardsIterator -= p + (c - 1);
      while (c--) {
        cards.push_back(*cardsIterator);
        cards.erase(cardsIterator);
      }
      if (r == 0) {
        break;
      }
    }
    // 一番上のカード表示
    cout << cards.back() << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> cards;
  vector<int>::iterator cardsIterator;
  vector<int>::iterator shuffuleIterator;
  int n, r, p, c;

  while (cin >> n >> r, n && r) {
    cards.clear(); // 初期化
    // カードの山生成
    for (int i = 0; i < n; ++i) {
      cards.push_back(i + 1);
    }
    // シャッフル
    while (cin >> p >> c) {
      cardsIterator = cards.end();
      cardsIterator -= p + (c - 1);
      while (c--) {
        cards.push_back(*cardsIterator);
        cards.erase(cardsIterator);
      }
      if (r == 0) {
        break;
      }
    }
    // 一番上のカード表示
    cout << cards.back() << endl;
  }
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, r, p, c;
  vector<int> cards;

  while (cin >> n >> r, n && r) {
    cards.clear();
    for (int i = 0; i < n; i++) {
      cards.push_back(n - i);
    }
    while (r--) {
      cin >> p >> c;
      vector<int> cpCards = cards;
      int pos = 0;
      for (int i = p - 1; i < p - 1 + c; i++) {
        cards[pos] = cpCards[i];
        pos++;
      }
      for (int i = 0; i < p - 1; i++) {
        cards[pos] = cpCards[i];
        pos++;
      }
    }
    cout << cards.front() << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, r, p, c;
  while (cin >> n >> r, n && r) {
    vector<int> cards;
    for (int i = 0; i < n; i++) {
      cards[i] = n - i;
    }
    while (r--) {
      cin >> p >> c;
      vector<int> cpCards = cards;
      int pos = 0;
      for (int i = p - 1; i < p - 1 + c; i++) {
        cards[pos] = cpCards[i];
        pos++;
      }
      for (int i = 0; i < p - 1; i++) {
        cards[pos] = cpCards[i];
        pos++;
      }
    }
    cout << cards.front() << endl;
  }
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int card[50] = {0};
  int mem[50] = {0};
  int n;
  int r;
  int k = 0;
  int p, c;
  while (1) {
    cin >> n >> r;
    if ((n == 0) && (r == 0))
      break;
    for (int i = 0; i < n; i++) {
      card[i] = i + 1;
    }
    for (int j = 0; j < r; j++) {
      cin >> p >> c;
      for (int l = 0; l < n; l++) {
        mem[l] = card[l];
      }
      for (int m = 0; m < p - 1; m++) {
        card[n - p - c + 1 + m] = mem[n - p + 1 + m];
      }
      for (int o = 0; o < c; o++) {
        card[n - c + o] = mem[n - p - c + 1 + o];
      }
    }
    cout << card[n - 1] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int card[50][50] = {0};
  int mem[50] = {0};
  int n;
  int r;
  int k = 0;
  int p, c;
  while (1) {
    cin >> n >> r;
    if ((n == 0) && (r == 0))
      break;
    for (int i = 0; i < n; i++) {
      card[k][i] = i + 1;
    }
    for (int j = 0; j < r; j++) {
      cin >> p >> c;
      for (int l = 0; l < n; l++) {
        mem[l] = card[k][l];
      }
      for (int m = 0; m < p - 1; m++) {
        card[k][n - p - c + 1 + m] = mem[n - p + 1 + m];
      }
      for (int o = 0; o < c; o++) {
        card[k][n - c + o] = mem[n - p - c + 1 + o];
      }
    }
    cout << card[k][n - 1] << endl;
    k++;
  }

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void) {
  int ans[1000], cnt = 0;
  while (1) {
    int n, r;
    cin >> n >> r;
    if (n == 0)
      break;
    int p[50], c[50];
    irep(i, r) cin >> p[i] >> c[i]; //?????????????????????
    int pos = 0;
    rep(i, r) {
      if (pos < c[i]) {
        pos += p[i] - 1;
      } else if (pos < c[i] + p[i] - 1) {
        pos -= c[i];
      }
    }
    ans[cnt] = n - pos;
    cnt++;
  }
  rep(i, cnt) cout << ans[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void) {
  int ans[100], cnt = 0;
  while (1) {
    int n, r;
    cin >> n >> r;
    if (n == 0)
      break;
    int p[50], c[50];
    irep(i, r) cin >> p[i] >> c[i]; //?????????????????????
    int pos = 0;
    rep(i, r) {
      if (pos < c[i]) {
        pos += p[i] - 1;
      } else if (pos < c[i] + p[i] - 1) {
        pos -= c[i];
      }
    }
    ans[cnt] = n - pos;
    cnt++;
  }
  rep(i, cnt) cout << ans[i] << endl;
  return 0;
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int n, r, p, c;
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;
    int s[n + 1];
    for (int i = 1; i <= n; ++i) {
      s[i] = i;
    }
    for (int j = 0; j < r; ++j) {
      cin >> p >> c;
      if (p == 1)
        continue;
      for (int k = 0; k < c; ++k) {
        s[0] = s[n + 2 - p - c];
        for (int l = 0; l < p + c - 2; ++l) {
          s[n + 2 - p - c + l] = s[n + 3 - p - c + l];
        }
        s[n] = s[0];
      }
    }
    cout << s[n] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int n, r, p, c, s[n + 1];
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;
    for (int i = 1; i <= n; ++i) {
      s[i] = i;
    }
    for (int j = 1; j <= r; ++j) {
      cin >> p >> c;
      for (int k = 1; k <= c; ++k) {
        s[0] = s[n - p - c + 2];
        for (int l = 0; l <= p + c - 3; ++l) {
          s[n - p - c + 2 + l] = s[n - p - c + 3 + l];
        }
        s[n] = s[0];
      }
    }
    cout << s[n] << endl;
  }
  return 0;
}
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <fstream>
#include <iostream>
#include <list>

using namespace std;

int main() {

  ifstream fin("in.txt");

  typedef list<int>::iterator Iterator;

  list<int> stock;
  list<int> tmp;

  int n = 0, r = 0;
  int p = 0, c = 0;

  while (true) {

    cin >> n >> r;
    if (n == 0 && r == 0)
      break;

    //?????????
    stock.clear();
    tmp.clear();
    for (int i = 1; i <= n; i++) {
      stock.push_back(n - i + 1);
    }

    for (Iterator it = stock.begin(); it != stock.end();) {
      //	cout << *it << " ";
      it++;
    }
    // cout << endl;

    // cout << stock.front() << endl;

    for (int i = 0; i < r; i++) {

      cin >> p >> c;

      Iterator front = stock.begin();
      for (int i = 0; i < p - 1; i++) {
        front++;
      }

      Iterator back = stock.begin();
      for (int i = 0; i < p + c - 1; i++) {
        back++;
      }

      tmp.splice(tmp.begin(), stock, front, back);

      stock.splice(stock.begin(), tmp);

      for (Iterator it = stock.begin(); it != stock.end();) {
        //	cout << *it << " ";
        it++;
      }
      // cout << endl;
    }

    cout << *stock.begin() << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <list>

using namespace std;

int main() {
  // ifstream fin("input.txt");

  // if (!fin)return -1;

  list<int> stock;

  while (true) {

    int number = 0;
    int shuffleCount = 0;
    int top = 0;

    cin >> number >> shuffleCount;
    if (number == 0 && shuffleCount == 0)
      break;

    //????????????????´??????????(?±±?????????)
    for (int i = 1; i <= number; i++) {
      stock.push_front(i);
    }

    //		ShowList(stock);
    list<int>::iterator begin;
    list<int>::iterator end;

    for (int i = 0; i < shuffleCount; i++) {
      int p, c;
      cin >> p >> c;

      if (number == c)
        continue;
      begin = stock.begin();
      advance(begin, p - 1);
      //			cout << "\\t" << *begin << endl;

      end = begin;
      advance(end, c);
      //			cout << "\\t" << *end << endl;

      stock.splice(stock.begin(), stock, begin, end);
    }
    //		ShowList(stock);
    cout << stock.front() << endl;

    stock.clear();
  }
  return 0;
}