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

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int math[101], check, mmax = 0;
  for (int i = 1; i < 101; i++)
    math[i] = 0;
  while (scanf("%d", &check) != EOF) {
    math[check]++;
    if (math[check] > mmax)
      mmax = math[check];
  }
  for (int i = 1; i < 101; i++) {
    if (mmax == math[i])
      cout << i << endl;
  }
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int date[100], scan, maxe = 1;
  for (int i = 0; i < 100; i++)
    date[i] = 0;

  while (scanf("%d", scan) != EOF) {
    date[scan]++;
    if (maxe < date[scan])
      maxe++;
  }
  for (int i = 0; i < 100; i++) {
    if (maxe == date[i])
      cout << i << endl;
  }
}
Problem p00028 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
  int n;
  int a[101] = {};
  int max = 0;
  while (cin >> n) {
    a[n]++;
    if (max < a[n])
      max = a[n];
  }
  for (int i = 0; i < 101; i++)
    if (max == a[i])
      cout << i << endl;
  return 0;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
  int n;
  int a[101] = {};
  int max = 0;
  while (cin >> n) {
    a[n]++;
    if (max < a[n])
      max = a[n];
  }
  for (int i = 0; i < 102; i++)
    if (max == a[i])
      cout << i << endl;
  return 0;
}
Problem p00028 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int y[10000000], n, maxv;
vector<int> a;
int main() {
  while (cin >> n) {
    y[n]++;
  }
  for (int i = 0; i < 10000000; i++) {
    maxv = max(maxv, y[i]);
  }
  for (int i = 0; i < 10000000; i++) {
    if (y[i] == maxv) {
      cout << i << endl;
    }
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int y[100000000], n, maxv;
vector<int> a;
int main() {
  while (cin >> n) {
    y[n]++;
  }
  for (int i = 0; i < 100000000; i++) {
    maxv = max(maxv, y[i]);
  }
  for (int i = 0; i < 100000000; i++) {
    if (y[i] == maxv) {
      cout << i << endl;
    }
  }
}
Problem p00028 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>

using namespace std;

int main() {
  int a[101] = {0};
  int b;
  int MAX = 0;

  while (cin >> b) {
    a[b]++;
  }
  for (int j = 1; j < 101; j++) {
    MAX = max(MAX, a[j]);
  }
  for (int m = 1; m < 101; m++) {
    if (MAX == a[m]) {
      cout << m << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
  int a[101] = {0};
  int b;
  int MAX = 0;
  int i = 0;

  while (cin >> b) {
    a[b]++;
  }
  for (int j = 1; j < 101; i++) {
    MAX = max(MAX, a[j]);
  }
  for (int m = 1; m < 101; m++) {
    if (MAX == a[m]) {
      cout << m << endl;
    }
  }
  return 0;
}
Problem p00028 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {

  int counter[101] = {0};
  int a;
  int MAX = 0;
  int i = 0;

  while (cin >> a) {
    counter[a]++;
  }

  for (int j = 1; j < 101; j++) {
    MAX = max(MAX, counter[j]);
  }

  for (int k = 1; k < 101; k++) {
    if (MAX == counter[k]) {
      cout << k << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

int main() {
  int a[101] = {0};
  int b;
  int MAX = 0;
  int i = 0;

  while (cin >> b) {
    a[b]++;
  }
  for (int j = 1; j < 101; i++) {
    MAX = max(MAX, a[j]);
  }
  for (int m = 1; m < 101; m++) {
    if (MAX == a[m]) {
      cout << m << endl;
    }
  }
  return 0;
}
Problem p00028 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pint;
#define foreach(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

int main() {
  pair<int, int> a[101];
  rep(i, 101) { a[i].second = -i; }
  for (int k; cin >> k;) {
    a[k].first++;
  }
  sort(a, a + 101, greater<pair<int, int>>());
  for (int i = 0; cout << -a[i].second << endl, a[i].F == a[i + 1].F; i++)
    ;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pint;
#define foreach(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

int main() {
  pair<int, int> a[101];
  rep(i, 101) { a[i].second = -i; }
  for (int k; cin >> k, k;) {
    a[k].first++;
  }
  sort(a, a + 101, greater<pair<int, int>>());
  for (int i = 0; cout << -a[i].second << endl, a[i].F == a[i + 1].F; i++)
    ;
  return 0;
}
Problem p00028 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>

// #define PI 3.141592653589

using namespace std;

int main() {
  int dic[101];
  int data;
  int max_data = 0;

  for (int i = 0; i < 101; i++)
    dic[i] = 0;
  while (cin >> data) {
    dic[data]++;
    max_data = max(max_data, dic[data]);
  }
  for (int i = 0; i < 101; i++) {
    if (dic[i] == max_data) {
      cout << i << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>

// #define PI 3.141592653589

using namespace std;

int main() {
  int dic[10];
  int data;
  int max_data = 0;

  for (int i = 0; i < 10; i++)
    dic[i] = 0;
  while (cin >> data) {
    dic[data]++;
    max_data = max(max_data, dic[data]);
  }
  for (int i = 0; i < 10; i++) {
    if (dic[i] == max_data) {
      cout << i << endl;
    }
  }

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


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  vector<vector<int>> a(100, vector<int>(2, 0));
  for (int i = 0; i < 100; i++) {
    a[i][0] = i;
  }
  int n;
  while (cin >> n) {
    a[n - 1][1]++;
  }
  for (int i = 0; i < 100 - 1; i++) {
    for (int j = i; j < 100; j++) {
      if (a[i][1] < a[j][1]) {
        swap(a[i][0], a[j][0]);
        swap(a[i][1], a[j][1]);
      }
    }
  }
  int hoge = 0;
  while (1) {
    cout << a[hoge][0] + 1 << endl;
    if (a[hoge][1] != a[hoge + 1][1] || hoge == 99)
      break;
    hoge++;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();

  return 0;
}


Error: 0

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  vector<vector<int>> a(100, vector<int>(2, 0));
  for (int i = 0; i < 100; i++) {
    a[i][0] = i;
  }
  int n;
  while (cin >> n) {
    a[n][1]++;
  }
  for (int i = 0; i < 100 - 1; i++) {
    for (int j = i; j < 100; j++) {
      if (a[i][1] < a[j][1]) {
        swap(a[i][0], a[j][0]);
        swap(a[i][1], a[j][1]);
      }
    }
  }
  int hoge = 0;
  while (1) {
    cout << a[hoge][0] << endl;
    if (a[hoge][1] != a[hoge + 1][1] || hoge == 99)
      break;
    hoge++;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();

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

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int input = 0;
  int a[100];
  int b[100][2];
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 2; j++) {
      b[i][j] = 0;
    }
  }
  int n = 0;
  while (cin >> input) {
    a[n] = input;
    n++;
  }
  sort(a, a + n);
  int i = 0, j = 0;
  for (i = 0; i < n; i++) {
    if (i == 0) {
      b[0][0] = a[0];
      b[0][1]++;
    } else if (b[j][0] == a[i]) {
      b[j][1]++;
    } else {
      b[++j][0] = a[i];
      b[j][1]++;
    }
  }
  int max = b[0][1];
  for (int k = 0; k <= j; k++) {
    if (max < b[k][1]) {
      max = b[k][1];
    }
  }
  int out[100];
  int m = 0;
  for (int k = 0; k <= j; k++) {
    if (max == b[k][1]) {
      out[m] = b[k][0];
      m++;
    }
  }
  for (int p = 0; p < m; p++) {
    cout << out[p] << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int input = 0;
  int a[100];
  int b[100][2];
  int n = 0;
  while (cin >> input) {
    a[n] = input;
    n++;
  }
  sort(a, a + n);
  int i = 0, j = 0;
  for (i = 0; i < n; i++) {
    if (i = 0) {
      b[0][0] = a[0];
      b[0][1]++;
    } else if (b[j][2] == a[i]) {
      b[j][1]++;
    } else {
      b[++j][0] = a[i];
      b[j][1]++;
    }
  }
  int max = b[0][1];
  for (int k = 0; k <= j; k++) {
    if (max < b[k][1]) {
      max = b[k][1];
    }
  }
  int out[100];
  int m = 0;
  for (int k = 0; k <= j; k++) {
    if (max == b[k][1]) {
      out[m] = b[k][0];
      m++;
    }
  }
  for (int p = 0; p < m; p++) {
    cout << out[p] << "\\n";
  }
  return 0;
}
Problem p00028 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>

using namespace std;

void solve() {
  map<int, int> Map;
  int n;
  while (~scanf("%d", &n)) {
    ++Map[n];
  }
  int Max = 0;
  for (map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite) {
    if (Max < Ite->second) {
      Max = Ite->second;
    }
  }
  for (map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite) {
    if (Ite->second == Max) {
      cout << Ite->first << endl;
    }
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>

using namespace std;

void solve() {
  map<int, int> Map;
  int n;
  while (cin >> n, n) {
    ++Map[n];
  }
  int Max = 0;
  for (map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite) {
    if (Max < Ite->second) {
      Max = Ite->second;
    }
  }
  for (map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite) {
    if (Ite->second == Max) {
      cout << Ite->first << endl;
    }
  }
}

int main() {
  solve();
  return (0);
}
Problem p00028 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  char ch;
  int num, max;
  int p[101] = {0};
  int q[2][10] = {0};
  while (scanf("%d", &num) != EOF) {
    p[num] += 1;
  }

  max = 0;
  for (int i = 0; i < 101; i++) {
    if (max < p[i])
      max = p[i];
  }
  for (int i = 0; i < 101; i++) {
    if (max == p[i])
      printf("%d\\n", i);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  char ch;
  int num, max;
  int p[10] = {0};
  int q[2][10] = {0};
  while (scanf("%d", &num) != EOF) {
    p[num] += 1;
  }

  max = 0;
  for (int i = 0; i < 10; i++) {
    if (max < p[i])
      max = p[i];
  }
  for (int i = 0; i < 10; i++) {
    if (max == p[i])
      printf("%d\\n", i);
  }

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

#include <iostream>
#include <map>
#include <string>

using namespace std;

map<string, int> table;

int main() {
  string word, frequent, longest;
  size_t N = 0; // size_t represents size in bytes of word (length)
  while (cin >> word) {
    table[word] += 1;
    if (table[word] > N) {
      N = table[word];
      frequent = word;
    }
    if (word.size() > longest.size())
      longest = word;
  }
  cout << frequent << " " << longest << endl;
}

Error: -11

Fixed submission:

#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  char cmd[2]; // command
  int digit;   // digit to insert
  priority_queue<int> Q;
  while (true) {
    scanf("%s", cmd);
    if (cmd[0] == 'e' && cmd[1] == 'n')
      break;
    if (cmd[0] == 'i') {
      scanf("%d", &digit);
      Q.push(digit);
    } else {
      cout << Q.top() << endl;
      Q.pop();
    }
  }
}
Problem p00029 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int i, i1, len, len1, check, max1, memo1, max2, memo2;
  max1 = 0;
  max2 = 0;
  memo1 = 0;
  memo2 = 0;
  string t;
  vector<string> s;
  vector<int> a, u;
  for (int h = 0; h < 500; h++) {
    u.push_back(0);
  }
  while (cin >> t) {
    check = 0;
    len = s.size();
    for (i = 0; i < len; i++) {
      if (t == s[i]) {
        u[i] += 1;
        check = 1;
      }
    }
    if (check == 0) {
      s.push_back(t);
      len1 = t.size();
      a.push_back(len1);
    }
  }
  len = s.size();
  for (i1 = 0; i1 < len; i1++) {
    while (max1 < u[i1]) {
      max1 = u[i1];
      memo1 = i1;
    }
    while (max2 < a[i1]) {
      max2 = a[i1];
      memo2 = i1;
    }
  }
  cout << s[memo1] << " " << s[memo2] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int i, i1, len, len1, check, max1, memo1, max2, memo2;
  max1 = 0;
  max2 = 0;
  memo1 = 0;
  memo2 = 0;
  string t;
  vector<string> s;
  vector<int> a, u;
  for (int h = 0; h < 500; h++) {
    u.push_back(0);
  }
  while (cin >> t) {
    check = 0;
    len = s.size();
    for (i = 0; i < len; i++) {
      if (t == s[i]) {
        u[i] += 1;
        check = 1;
      }
    }
    if (check == 0) {
      s.push_back(t);
      len1 = t.size();
      a.push_back(len1);
    }
  }
  len = s.size();
  for (i1 = 0; i1 < len; i1++) {
    while (max1 < u[i1]) {
      max1 = u[i1];
      memo1 = i1;
    }
    while (max2 < a[i1]) {
      max2 = u[i1];
      memo2 = i1;
    }
  }
  cout << s[memo1] << " " << s[memo2] << endl;
  return 0;
}
Problem p00029 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  string str, s, mls, mcs, input[100];
  map<string, int> dic;
  int n, c, a, ml, mc;
  getline(cin, str);
  c = a = mc = ml = 0;
  str += ' ';
  while (str.length()) {
    n = str.find(' ');
    s = str[c];
    ++c;
    for (; c < n; ++c) {
      s += str[c];
    }
    str.erase(0, n + 1);
    c = 0;
    input[a] = s;
    ++a;
    ++dic[s];
    if (s.length() > ml) {
      ml = s.length();
      mls = s;
    }
  }
  for (int i = 0; i < a; ++i) {
    if (mc < dic[input[i]]) {
      mc = dic[input[i]];
      mcs = input[i];
    }
  }
  cout << mcs << " " << mls << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  string str, s, mls, mcs, input[32];
  map<string, int> dic;
  int n, c, a, ml, mc;
  getline(cin, str);
  c = a = mc = ml = 0;
  str += ' ';
  while (str.length()) {
    n = str.find(' ');
    s = str[c];
    ++c;
    for (; c < n; ++c) {
      s += str[c];
    }
    str.erase(0, n + 1);
    c = 0;
    input[a] = s;
    ++a;
    ++dic[s];
    if (s.length() > ml) {
      ml = s.length();
      mls = s;
    }
  }
  for (int i = 0; i < a; ++i) {
    if (mc < dic[input[i]]) {
      mc = dic[input[i]];
      mcs = input[i];
    }

    cout << mcs << " " << mls << endl;
  }
  return 0;
}
Problem p00029 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

char str[1100][34];
int len[1100];
int n;

string ans1 = "";

map<string, int> mp;
void init_map() {
  mp.clear();
  for (int i = 1; i <= n; i++) {
    mp[str[i]] = 0;
  }
  for (int i = 1; i <= n; i++) {
    mp[str[i]]++;
  }
  int l = 0;
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    if ((it->second) > l) {
      ans1 = it->first;
      l = it->second;
    }
  }
}
int main() {
  int idx = 1;
  while (~scanf("%s", str[idx])) {
    len[idx] = strlen(str[idx]);
    idx++;
  }
  n = idx - 1;
  init_map();
  cout << ans1 << " ";
  int l = 0;
  int maxidx = 0;
  for (int i = 1; i <= n; i++) {
    if (len[i] > l) {
      maxidx = i;
      l = len[i];
    }
  }
  cout << str[maxidx] << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  map<string, int> m;
  string a[1000];
  char c;
  while (true) {
    int i = 0;
    while (true) {
      cin >> a[i];
      i++;
      if ((c = getchar()) == '\\n')
        break;
    }
    m.clear();
    for (int j = 0; j < i; ++j)
      m[a[j]]++;
    int max = 0, temp;
    for (int j = 0; j < i; ++j)
      if (max < m[a[j]]) {
        max = m[a[j]];
        temp = j;
      }
    cout << a[temp] << ' ';
    max = 0;
    for (int j = 0; j < i; ++j)
      if (max < a[j].size()) {
        max = a[j].size();
        temp = j;
      }
    cout << a[temp] << endl;
  }
  return 0;
}
Problem p00029 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <utility>
using namespace std;

int main() {
  string str;
  char word[1010][35];
  int x = 0, y = 0, i = 0, j, length = 0, maxl = 0, maxq[35], q, p = 0;
  maxq[0] = 0;
  getline(cin, str);
  while (1) {
    if (str[i] == ' ') {
      word[y][x] = '\\0';
      x = 0;
      y++;
    } else if (str[i] == '\\0') {
      word[y][x] = '\\0';
      word[y + 1][0] = '\\0';
      break;
    } else {
      word[y][x] = str[i];
      x++;
    }
    i++;
  }
  for (i = 0; i < y; i++) {
    for (j = 0; j < y - i; j++) {
      if (strcmp(word[j], word[j + 1]) > 0) {
        for (x = 0; x < 35; x++) {
          swap(word[j][x], word[j + 1][x]);
        }
      }
    }
  }
  for (i = 0; i <= y; i++) {
    for (j = 0; word[i][j] != '\\0'; j++) {
    }
    if (maxl < j) {
      maxl = j;
      length = i;
    }
    if (strcmp(word[i], word[i + 1]) == 0) {
      maxq[i + 1] = maxq[i] + 1;
    } else {
      maxq[i + 1] = 0;
    }
  }
  for (i = 0; i <= y; i++) {
    if (p < maxq[i]) {
      p = maxq[i];
      q = i;
    }
  }
  printf("%s %s\\n", word[q], word[length]);
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <utility>
using namespace std;

int main() {
  string str;
  char word[35][35];
  int x = 0, y = 0, i = 0, j, length = 0, maxl = 0, maxq[35], q, p = 0;
  maxq[0] = 0;
  getline(cin, str);
  while (1) {
    if (str[i] == ' ') {
      word[y][x] = '\\0';
      x = 0;
      y++;
    } else if (str[i] == '\\0') {
      word[y][x] = '\\0';
      word[y + 1][0] = '\\0';
      break;
    } else {
      word[y][x] = str[i];
      x++;
    }
    i++;
  }
  for (i = 0; i < y; i++) {
    for (j = 0; j < y - i; j++) {
      if (strcmp(word[j], word[j + 1]) > 0) {
        for (x = 0; x < 35; x++) {
          swap(word[j][x], word[j + 1][x]);
        }
      }
    }
  }
  for (i = 0; i <= y; i++) {
    for (j = 0; word[i][j] != '\\0'; j++) {
    }
    if (maxl < j) {
      maxl = j;
      length = i;
    }
    if (strcmp(word[i], word[i + 1]) == 0) {
      maxq[i + 1] = maxq[i] + 1;
    } else {
      maxq[i + 1] = 0;
    }
  }
  for (i = 0; i <= y; i++) {
    if (p < maxq[i]) {
      p = maxq[i];
      q = i;
    }
  }
  printf("%s %s\\n", word[q], word[length]);
  return 0;
}
Problem p00029 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

#define rep(x, to) for (int x = 0; x < to; x++)
#define rep2(x, from, to) for (x = from; x < to; x++)

using namespace std;

typedef pair<string, int> mypair;

int main(void) {
  vector<mypair> vvc(1, mypair("", 0));
  string wst, qst = "", mst;

  while (cin >> wst) {
    if (wst.size() > qst.size())
      qst = wst;
    int sszz = vvc.size();
    bool addsw = true;
    rep(i, sszz) {
      if (wst == vvc[i].first) {
        vvc[i].second++;
        addsw = false;
        break;
      }
    }
    if (addsw)
      vvc.push_back(mypair(wst, 1));
  }
  int mx = -999, sszz = vvc.size();
  //	rep(i,sszz) cout << i << ": " << vvc[i].first << "- " << vvc[i].second
  //<< endl;
  rep(i, sszz) {
    if (mx < vvc[i].second) {
      mx = vvc[i].second;
      mst = vvc[i].first;
    }
  }
  cout << mst << " " << qst << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

#define rep(x, to) for (int x = 0; x < to; x++)
#define rep2(x, from, to) for (x = from; x < to; x++)

using namespace std;

typedef pair<string, int> mypair;

int main(void) {
  vector<mypair> vvc(1, mypair("", 0));
  string wst, qst = "", mst;

  while (cin >> wst) {
    if (wst.size() > qst.size())
      qst = wst;
    int sszz = vvc.size();
    rep(i, sszz) {
      if (wst == vvc[i].first) {
        vvc[i].second++;
        break;
      } else
        vvc.push_back(mypair(wst, 1));
    }
  }
  int mx = -999, sszz = vvc.size();
  rep(i, sszz) {
    if (mx < vvc[i].second) {
      mx = vvc[i].second;
      mst = vvc[i].first;
    }
  }
  cout << mst << " " << qst << endl;
  return 0;
}