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

// #include<bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
string str[10000] = {""};
char ch[10000];
int input();
int main() {
  int a, most = 0;
  a = input();
  string longest;
  int m[10000] = {0}, l;
  for (int i = 0; i <= a + 1; i++) {
    for (int j = i + 1; j <= a; j++) {
      if (str[i] == str[j]) {
        m[i]++;
      }
    }
  }
  int k, ma = 0, locate, memo;
  for (k = 0; k <= a + 1; k++) {
    if (m[k] > ma) {
      ma = m[k];
      locate = k;
    }
  }
  for (int f = 0; f <= a + 1; f++) {
    if (str[f].size() > most) {
      most = str[f].size();
      memo = f;
    }
  }
  longest = str[memo];
  cout << str[locate] << " " << longest << endl;
  return 0;
}
int input() {
  int i = 0, j = 0;
  while (1) {
    scanf("%c", &ch[i]);
    if (isupper(ch[i])) {
      ch[i] += 'a' - 'A';
    }
    if (ch[i] == ' ') {
      j++;
    } else if (ch[i] == '\\n') {
      break;
    } else {
      str[j] += ch[i];
    }
  }
  return j;
}

Error: 0

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
string str[33] = {""};
char ch[10001];
int input();
int main() {
  int a, most = 0;
  a = input();
  string longest;
  int m[33] = {0}, l;
  for (int i = 0; i <= a + 1; i++) {
    for (int j = i + 1; j <= a; j++) {
      if (str[i] == str[j]) {
        m[i]++;
      }
    }
  }
  int k, ma = 0, locate, memo;
  for (k = 0; k <= a + 1; k++) {
    if (m[k] > ma) {
      ma = m[k];
      locate = k;
    }
  }
  for (int f = 0; f <= a + 1; f++) {
    if (str[f].size() > most) {
      most = str[f].size();
      memo = f;
    }
  }
  longest = str[memo];
  cout << str[locate] << " " << longest << endl;
  return 0;
}
int input() {
  int i = 0, j = 0;
  while (1) {
    scanf("%c", &ch[i]);
    if (isupper(ch[i])) {
      ch[i] += 'a' - 'A';
    }
    if (ch[i] == ' ') {
      j++;
    } else if (ch[i] == '\\n') {
      break;
    } else {
      str[j] += ch[i];
    }
  }
  return j;
}
Problem p00029 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  char a[1100] = {0};
  scanf("%[^\\n]", a);
  int cnt = 0;
  int mx = 0;
  int len[1100] = {0};
  string ans[1100];
  for (int i = 0, j = 0; i <= strlen(a); i++) {
    if ('a' <= a[i] && a[i] <= 'z' || 'A' <= a[i] && a[i] <= 'Z') {
      ans[cnt] += a[i];
      j++;
    } else {
      len[cnt] = j;
      cnt++;
      mx = max(mx, j);
      j = 0;
    }
  }
  string date;
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      date = ans[i];
      break;
    }
  }
  sort(ans, ans + cnt);
  fill(len, len + 50, 0);
  string mx_date = ans[0];
  ans[cnt] = ' ';
  mx = 0;
  for (int i = 1; i <= cnt; i++) {
    if (mx_date == ans[i]) {
      mx++;
    } else {
      mx_date = ans[i];
      len[i - 1] = mx;
      mx = 0;
    }
  }
  for (int i = 0; i < cnt; i++) {
    mx = max(mx, len[i]);
  }
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      cout << ans[i] << ' ' << date << endl;
      break;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  char a[1100] = {0};
  scanf("%[^\\n]", a);
  int cnt = 0;
  int mx = 0;
  int len[50] = {0};
  string ans[50];
  for (int i = 0, j = 0; i <= strlen(a); i++) {
    if ('a' <= a[i] && a[i] <= 'z' || 'A' <= a[i] && a[i] <= 'Z') {
      ans[cnt] += a[i];
      j++;
    } else {
      len[cnt] = j;
      cnt++;
      mx = max(mx, j);
      j = 0;
    }
  }
  string date;
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      date = ans[i];
      break;
    }
  }
  sort(ans, ans + cnt);
  fill(len, len + 50, 0);
  string mx_date = ans[0];
  ans[cnt] = ' ';
  mx = 0;
  for (int i = 1; i <= cnt; i++) {
    if (mx_date == ans[i]) {
      mx++;
    } else {
      mx_date = ans[i];
      len[i - 1] = mx;
      mx = 0;
    }
  }
  for (int i = 0; i < cnt; i++) {
    mx = max(mx, len[i]);
  }
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      cout << ans[i] << ' ' << date << endl;
      break;
    }
  }

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

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

int main() {
  string str[1001], tmp;
  int max_num = 0, max_length = 0, i, max = 1, max_str = 0, a[1001] = {};

  while (cin >> tmp) {
    for (i = 0; i < tmp.size(); i++) {
      if ('A' <= tmp[i] && tmp[i] <= 'Z')
        tmp[i] = tmp[i] + 'a' - 'A';
    }

    for (i = 0; i < max; i++) {
      if (str[i] == tmp) {
        a[i]++;
        if (max_str < a[i]) {
          max_str = a[i];
          max_num = i;
        }
        if (tmp.size() > max_length)
          max_length = (int)tmp.size();
        break;
      }
    }
    if (i >= max) {
      str[i - 1] = tmp;
      max++;
      a[i - 1]++;
      if (max_str < a[i - 1]) {
        max_str = a[i - 1];
        max_num = i - 1;
      }
      if (tmp.size() > max_length)
        max_length = (int)tmp.size();
    }
  }
  cout << str[max_num];

  for (i = 0; i < max; i++) {
    if ((int)str[i].size() == max_length)
      cout << " " << str[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  string str[1001], tmp;
  int max_num = 0, max_length = 0, i, max = 1, max_str = 0, a[1001] = {};

  while (cin >> tmp, tmp[0] != 'EOF') {
    for (i = 0; i < tmp.size(); i++) {
      if ('A' <= tmp[i] && tmp[i] <= 'Z')
        tmp[i] = tmp[i] + 'a' - 'A';
    }

    for (i = 0; i < max; i++) {
      if (str[i] == tmp) {
        a[i]++;
        if (max_str < a[i]) {
          max_str = a[i];
          max_num = i;
        }
        if (tmp.size() > max_length)
          max_length = (int)tmp.size();
        break;
      }
    }
    if (i >= max) {
      str[i - 1] = tmp;
      max++;
      a[i - 1]++;
      if (max_str < a[i - 1]) {
        max_str = a[i - 1];
        max_num = i - 1;
      }
      if (tmp.size() > max_length)
        max_length = (int)tmp.size();
    }
  }
  cout << str[max_num] << endl;

  for (i = 0; i < max; i++) {
    if ((int)str[i].size() == max_length)
      cout << str[i] << endl;
  }
  return 0;
}
Problem p00029 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  vector<string> str;
  vector<int> cnt;
  string buf, maxstr;
  int max = 0, ans, i;

  while (cin >> buf) {
    bool f = true;

    if (max < buf.length()) {
      max = buf.length();
      maxstr = buf;
    }
    for (i = 0; i < str.size(); i++) {
      if (str[i] == buf) {
        f = false;
        break;
      }
    }
    if (f) {
      str.push_back(buf);
      cnt.push_back(1);
    } else {
      cnt[i]++;
    }
  }

  max = 0;
  for (i = 0; i < cnt.size(); i++) {
    if (cnt[i] > max) {
      max = cnt[i];
      ans = i;
    }
  }

  cout << str[ans] << ' ' << maxstr << endl;

  return 0;
}

Error: WA

Fixed submission:

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

int main(void) {
  vector<string> str;
  vector<int> cnt;
  string buf, maxstr;
  int max, ans, i;

  while (cin >> buf) {
    bool f = true;

    if (max < buf.length()) {
      max = buf.length();
      maxstr.append(buf);
    }

    for (i = 0; i < str.size(); i++) {
      if (str[i] == buf) {
        f = false;
        break;
      }
    }
    if (f) {
      str.push_back(buf);
      cnt.push_back(1);
    } else {
      cnt[i]++;
    }
  }

  max = 0;
  for (i = 0; i < cnt.size(); i++) {
    if (cnt[i] > max) {
      max = cnt[i];
      ans = i;
    }
  }

  cout << str[i] << ' ' << maxstr << endl;

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

#include <iostream>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)

int main(void) {
  string s, len = "";
  getline(cin, s);

  s += ' ';
  vector<string> arys;
  string ss = "";
  rep(i, s.size()) {
    if (s[i] != ' ') {
      ss += s[i];
    } else {
      arys.push_back(ss);
      if (len.size() < ss.size())
        len = ss;
      ss = "";
    }
  }
  vector<int> aryi(arys.size(), 0);
  int n = arys.size(), used = 0, index = -1;
  rep(i, n) {
    loop(j, i, n) {
      if (arys[i] == arys[j]) {
        aryi[i]++;
        if (aryi[i] > used) {
          index = i;
          used = aryi[i];
        }
      }
    }
  }

  cout << arys[index] << " " << len << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)

int main(void) {
  string s;
  string len = "";
  int aryi[32];
  string arys[32];
  int n = 0;
  rep(i, 32) aryi[i] = 0;
  while (cin >> s) {
    arys[n++] = s;
    if (s.size() > len.size())
      len = s;
  }
  int used = 0;
  int index = -1;
  rep(i, n) {
    loop(j, i + 1, n) {
      if (arys[i] == arys[j]) {
        aryi[i]++;
        if (used < aryi[i]) {
          index = i;
        }
      }
    }
  }

  cout << arys[index] << " " << len << endl;
}
Problem p00029 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef pair<string, int> PAIR;

int main() {
  vector<PAIR> vec;
  vector<PAIR>::iterator ite;
  vector<PAIR>::iterator max;
  string st, siz;
  while (cin >> st) {
    if (st == "0")
      break;
    if (vec.empty()) {
      vec.push_back(PAIR(st, 1));
      // max = vec.begin();
      // siz = st;
    } else {
      ite = vec.begin();
      while (1) {
        if ((*ite).first == st) {
          (*ite).second++;
          // if((*max).second < (*ite).second) max = ite;
          break;
        }
        ite++;
        if (ite == vec.end()) {
          vec.push_back(PAIR(st, 1));
          // if(siz.size() < st.size()) siz = st;
          break;
        }
      }
    }

    ite = vec.begin();
    max = vec.begin();
    siz = (*ite).first;
    while (ite != vec.end()) {
      if ((*max).second < (*ite).second)
        max = ite;
      if (siz.size() < (*ite).first.size())
        siz = (*ite).first;
      ite++;
    }
  }
  cout << (*max).first << " " << siz << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef pair<string, int> PAIR;

int main() {
  vector<PAIR> vec;
  vector<PAIR>::iterator ite;
  vector<PAIR>::iterator max;
  string st, siz;
  while (cin >> st) {
    if (st == "0")
      break;
    ite = vec.begin();
    if (vec.empty()) {
      vec.push_back(PAIR(st, 1));
      max = vec.begin();
      siz = st;
    } else {
      while (1) {
        if ((*ite).first == st) {
          (*ite).second++;
          if ((*max).second < (*ite).second)
            max = ite;
          break;
        }
        ite++;
        if (ite == vec.end()) {
          vec.push_back(PAIR(st, 1));
          if (siz.size() < st.size())
            siz = st;
          break;
        }
      }
    }

    cout << (*max).first << " " << siz << endl;
  }
  return 0;
}
Problem p00029 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

struct WordRanking {
  WordRanking() {}

  WordRanking(std::string word, int count) : m_word(word), m_count(count) {}

  std::string m_word;

  int m_count;
};

int MaxNum(std::vector<WordRanking> rank) {
  if (rank.empty()) {
    return 0;
  }

  int max = rank[0].m_count;

  int maxNum = 0;

  for (size_t i = 1; i < rank.size(); ++i) {
    if (rank[i].m_count > max) {
      max = rank[i].m_count;

      maxNum = i;
    }
  }

  return maxNum;
}

int main() {
  std::string str;

  // while(1){
  getline(std::cin, str);

  if (std::cin.eof()) {
    exit(1);
  }

  std::stringstream ss;

  std::vector<std::string> word;

  ss << str;

  std::string hoge;

  for (; !(ss.eof());) {
    ss >> hoge;

    word.push_back(hoge);
  }

  std::sort(word.begin(), word.end());

  std::string temp = "";

  std::vector<WordRanking> rankFriq;

  for (size_t i = 0; i < word.size(); ++i) {
    if (temp != word[i]) {
      rankFriq.push_back(WordRanking(word[i], 1));
    } else {
      ++rankFriq[rankFriq.size() - 1].m_count;
    }

    temp = word[i];
  }

  std::vector<WordRanking> rankLength;

  for (size_t i = 0; i < word.size(); ++i) {
    rankLength.push_back(WordRanking(word[i], word[i].length()));
  }

  std::cout << rankFriq[MaxNum(rankFriq)].m_word << ' '
            << rankLength[MaxNum(rankLength)].m_word << '\\n';

  //}
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

struct WordRanking {
  WordRanking() {}

  WordRanking(std::string word, int count) : m_word(word), m_count(count) {}

  std::string m_word;

  int m_count;
};

int MaxNum(std::vector<WordRanking> rank) {
  if (rank.empty()) {
    return 0;
  }

  int max = rank[0].m_count;

  int maxNum = 0;

  for (size_t i = 1; i < rank.size(); ++i) {
    if (rank[i].m_count > max) {
      max = rank[i].m_count;

      maxNum = i;
    }
  }

  return maxNum;
}

int main() {
  std::string str;

  while (1) {
    getline(std::cin, str);

    if (std::cin.eof()) {
      break;
    }

    std::stringstream ss;

    std::vector<std::string> word;

    ss << str;

    std::string hoge;

    for (; !(ss.eof());) {
      ss >> hoge;

      word.push_back(hoge);
    }

    std::sort(word.begin(), word.end());

    std::string temp = "";

    std::vector<WordRanking> rankFriq;

    for (size_t i = 0; i < word.size(); ++i) {
      if (temp != word[i]) {
        rankFriq.push_back(WordRanking(word[i], 1));
      } else {
        ++rankFriq[rankFriq.size() - 1].m_count;
      }

      temp = word[i];
    }

    std::vector<WordRanking> rankLength;

    for (size_t i = 0; i < word.size(); ++i) {
      rankLength.push_back(WordRanking(word[i], word[i].length()));
    }

    std::cout << rankFriq[MaxNum(rankFriq)].m_word << ' '
              << rankLength[MaxNum(rankLength)].m_word << '\\n';
  }
}
Problem p00029 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  multimap<int, string> words;
  string str;
  string maxstr = "";
  for (; cin >> str;) {
    if (maxstr.size() < str.size())
      maxstr = str;
    multimap<int, string>::iterator it;
    bool nw = true;
    for (it = words.begin(); it != words.end(); it++) {
      if (it->second == str) {
        words.insert(map<int, string>::value_type(it->first - 1, str));
        nw = false;
        break;
      }
    }
    if (nw)
      words.insert(map<int, string>::value_type(-1, str));
    /*for(it=words.begin();it!=words.end();it++){
            cout<<it->second<<endl;
            cout<<1<<endl;
    }*/
    // cout<<str<<endl;
  }
  cout << words.begin()->second << " " << maxstr << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  multimap<int, string> words;
  string str;
  string maxstr = "";
  for (; cin >> str;) {
    if (maxstr.size() < str.size())
      maxstr = str;
    multimap<int, string>::iterator it;
    for (it = words.begin(); it != words.end(); it++) {
      if (it->second == str) {
        words.insert(map<int, string>::value_type(it->first - 1, str));
      }
    }
    words.insert(map<int, string>::value_type(-1, str));
    /*for(it=words.begin();it!=words.end();it++){
            cout<<it->second<<endl;
            cout<<1<<endl;
    }*/
    // cout<<str<<endl;
  }
  cout << words.begin()->second << " " << maxstr << endl;
  return 0;
}
Problem p00029 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  string s[1002];
  int k = 0, size_max = 0, s_max = 0, count_max = 0, count_max_number;
  int scount[1002] = {0};

  while (cin >> s[k]) {
    k++;
  }
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      if (s[i] == s[j]) {
        scount[i]++;
      }
    }
  }

  for (int i = 0; i < k; i++) {
    if (count_max < scount[i]) {
      count_max = scount[i];
      count_max_number = i;
    }
    if (size_max < s[i].size()) {
      size_max = s[i].size();
      s_max = i;
    }
  }

  cout << s[count_max_number] << ' ' << s[s_max] << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int main() {

  string s[40];
  int k = 0, size_max = 0, s_max = 0, count_max = 0, count_max_number;
  int scount[40] = {0};

  while (cin >> s[k]) {
    k++;
  }
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      if (s[i] == s[j]) {
        scount[i]++;
      }
    }
  }

  for (int i = 0; i < k; i++) {
    if (count_max < scount[i]) {
      count_max = scount[i];
      count_max_number = i;
    }
    if (size_max < s[i].size()) {
      size_max = s[i].size();
      s_max = i;
    }
  }

  cout << s[count_max_number] << ' ' << s[s_max] << endl;

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

#include <algorithm>
#include <cstdio>
using namespace std;
int n, s, ans;
void solve(int from, int now, int sum) {
  if (now == n && sum == s)
    ans++;
  if (now < n && s - sum >= from * (n - now)) {
    for (int i = from; i <= min(9, (s - sum) / (n - now)); i++) {
      solve(i + 1, now + 1, sum + i);
    }
  }
}

int main() {
  for (;;) {
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      break;
    ans = 0;
    solve(0, 0, 0);
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
int ans;
int n, s;
bool tryfunc(int now, int dep, int rest) {
  if (rest == now && dep == 0)
    ans++;
  else if (rest > now * 2 && dep > 0) {
    for (int i = now + 1; i <= (rest - now > s ? s : rest - now); i++) {
      tryfunc(i, dep - 1, (rest - now > s ? s : rest - now));
    }
  }
}
int main() {
  for (;;) {
    ans = 0;
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      break;
    for (int i = 0; i < 10; i++) {
      tryfunc(i, n - 1, s);
    }
    printf("%d\\n", ans);
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS

#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <string>

using namespace std;

int n = 0;
int s = 0;
static int ans;

void check(int atai, int num, int count) {
  if (num > 9) {
    if (atai == s && count == n) {
      ans++;
    }
    return;
  }
  check(atai + num, num + 1, count + 1);
  check(atai, num + 1, count);
}

int main(int argc, char **argv) {
  while (cin >> n >> s) {
    ans = 0;
    if (n == 0 && s == 0) {
      break;
    }
    check(0, 0, 0);
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS

#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <string>

using namespace std;

int n = 0;
int s = 0;
static int ans;

void check(int atai, int num, int count) {
  if (num > s || atai > s) {
    if (count == n && atai == s) {
      ans++;
    }
    return;
  }
  check(atai + num, num + 1, count + 1);
  check(atai, num + 1, count);
}

int main(int argc, char **argv) {
  while (cin >> n >> s) {
    ans = 0;
    if (n == 0 && s == 0) {
      break;
    }
    check(0, 0, 0);
    cout << ans << endl;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dp[16][64];

int main() {
  dp[0][0] = 1;
  rep(k, 10) {
    for (int i = 10; i >= 0; i--) {
      rep(j, 64) if (dp[i][j]) dp[i + 1][j + k] += dp[i][j];
    }
  }
  for (;;) {
    int n, s;
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      return 0;
    printf("%d\\n", n < 16 && s < 64 ? dp[n][s] : 0);
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dp[16][64];

int main() {
  dp[0][0] = 1;
  rep(k, 10) {
    for (int i = 10; i >= 0; i--) {
      rep(j, 64) if (dp[i][j]) dp[i + 1][j + k] += dp[i][j];
    }
  }
  for (;;) {
    int n, s;
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      return 0;
    printf("%d\\n", dp[n][s]);
  }
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int res;

void dfs(int n, int index, int s) {
  if (n == 0 && s == 0) {
    res++;
    return;
  } else if (n == 0 || s < 0 || s < index || 9 < index) {
    return;
  }
  dfs(n - 1, index + 1, s - index);
  dfs(n, index + 1, s);
  return;
}

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if ((n | s) == 0) {
      break;
    }
    res = 0;
    dfs(n, 0, s);
    cout << res << endl;
  }
}

Error: 0

Fixed submission:

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

int c[11][11][46];

int solve(int n, int index, int s) {
  if (0 <= s && s < 46 && c[n][index][s] >= 0) {
    return c[n][index][s];
  }
  if (n == 0 && s == 0) {
    return 1;
  } else if (n == 0 || s <= 0 || s < index || 9 < index) {
    return 0;
  }
  int res = 0;
  res += solve(n - 1, index + 1, s - index);
  res += solve(n, index + 1, s);
  return c[n][index][s] = res;
}

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if ((n | s) == 0) {
      break;
    }
    memset(c, -1, sizeof(c));
    cout << solve(n, 0, s) << endl;
  }
}