prithivMLmods/Coder-Stat huggingface dataset:
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
/*       Rohan Balot
    NSIT, New Delhi, India  */
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair

const int N = int(1e6) + 1;
const int M = int(1e6) + 1;
const int MOD = int(1e9) + 7;
const double PI = acos(-1);
const double eps = 1e-6;

void __answer() {
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(26, 0));
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    for (int j = 0; j < a.size(); j++) {
      f[i][a[j] - 'a']++;
    }
  }
  string s;
  bool foo = true;
  for (int i = 0; i < 26; i++) {
    int t = 1e9;
    for (int x = 0; x < n; x++)
      t = min(t, f[x][i]);
    if (f[0][i] > 0 && f[1][i] > 0 && f[2][i] > 0) {
      for (int j = 0; j < t; j++) {
        foo = false;
        cout << char('a' + i);
      }
    }
  }
  if (foo)
    cout << "";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifdef LOCAL
  freopen("sample_input.txt", "r", stdin);
#endif
  __answer();
  return 0;
}

Fixed submission:
/*       Rohan Balot
    NSIT, New Delhi, India  */
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair

const int N = int(1e6) + 1;
const int M = int(1e6) + 1;
const int MOD = int(1e9) + 7;
const double PI = acos(-1);
const double eps = 1e-6;

void __answer() {
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(26, 0));
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    for (int j = 0; j < a.size(); j++) {
      f[i][a[j] - 'a']++;
    }
  }
  string s;
  bool foo = true;
  for (int i = 0; i < 26; i++) {
    int t = 1e9;
    for (int x = 0; x < n; x++)
      t = min(t, f[x][i]);
    for (int j = 0; j < t; j++) {
      foo = false;
      cout << char('a' + i);
    }
  }
  if (foo)
    cout << "";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifdef LOCAL
  freopen("sample_input.txt", "r", stdin);
#endif
  __answer();
  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  int n;
  string ans;
  cin >> n;
  vector<int> alpha(26);
  rep(i, n) {
    string s;
    cin >> s;
    vector<int> al(26, 0);
    for (int k = 0; k < s.size(); k++) {
      al[k] = count(s.begin(), s.end(), 'a' + k);
    }
    if (i == 0) {
      rep(j, 26) { alpha[j] = al[j]; }
    } else {
      rep(j, 26) alpha[j] = min(alpha[j], al[j]);
    }
  }
  rep(i, 26) {
    while (alpha[i] > 0) {
      ans += 'a' + i;
      alpha[i]--;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  int n;
  string ans;
  cin >> n;
  vector<int> alpha(26);
  rep(i, n) {
    string s;
    cin >> s;
    vector<int> al(26, 0);
    rep(k, 26) { al[k] = count(s.begin(), s.end(), 'a' + k); }
    if (i == 0) {
      rep(j, 26) { alpha[j] = al[j]; }
    } else {
      rep(j, 26) alpha[j] = min(alpha[j], al[j]);
    }
  }
  rep(i, 26) {
    while (alpha[i] > 0) {
      ans += 'a' + i;
      alpha[i]--;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int n;
string *S;

int dp[51][51];
string dp2[51][51];

string func(string x, string y) {
  for (int i = 0; i < 52; ++i) {
    for (int j = 0; j < 52; ++j) {
      dp[i][j] = 0;
      dp2[i][j] = "";
    }
  }

  for (unsigned int i = 0; i < x.length(); i++) {
    for (unsigned int j = 0; j < y.length(); j++) {
      if (x[i] == y[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        dp2[i + 1][j + 1] = dp2[i][j] + x[i];
      } else {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        if (dp[i][j + 1] > dp[i + 1][j]) {
          dp2[i + 1][j + 1] = dp2[i][j + 1];
        } else {
          dp2[i + 1][j + 1] = dp2[i + 1][j];
        }
      }
    }
  }
  return dp2[x.length()][y.length()];
}

int main(void) {

  cin >> n;
  S = new string[n];
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
  }

  for (int j = 0; j < n - 1; ++j) {
    for (int i = 1; i < n; ++i) {
      S[i] = func(S[j], S[i]);
    }
  }

  cout << S[n - 1] << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int n;
string *S;

int dp[51][51];
string dp2[51][51];

string func(string x, string y) {
  for (int i = 0; i < 51; ++i) {
    for (int j = 0; j < 51; ++j) {
      dp[i][j] = 0;
      dp2[i][j] = "";
    }
  }

  for (unsigned int i = 0; i < x.length(); i++) {
    for (unsigned int j = 0; j < y.length(); j++) {
      if (x[i] == y[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        dp2[i + 1][j + 1] = dp2[i][j] + x[i];
      } else {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        if (dp[i][j + 1] > dp[i + 1][j]) {
          dp2[i + 1][j + 1] = dp2[i][j + 1];
        } else {
          dp2[i + 1][j + 1] = dp2[i + 1][j];
        }
      }
    }
  }
  return dp2[x.length()][y.length()];
}

int main(void) {

  cin >> n;
  S = new string[n];
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
  }

  for (int j = 0; j < n - 1; ++j) {
    for (int i = 1; i < n; ++i) {
      S[i] = func(S[j], S[i]);
    }
  }

  cout << S[n - 1] << endl;

  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

vector<char> getAnd(const vector<char> v1, const vector<char> v2) {
  int cnt1 = 0, cnt2 = 0;
  vector<char> res;
  while (cnt1 < v1.size() && cnt2 < v2.size()) {
    if (v1[cnt1] == v2[cnt2]) {
      res.push_back(v1[cnt1]);
      cnt1++;
      cnt2++;
    } else if (v1[cnt1] > v2[cnt2]) {
      cnt2++;
    } else {
      cnt1++;
    }
  }
  res.push_back(0);
  return res;
}

int main() {
  int n, cnt;
  vector<vector<char>> vvc;

  string buf;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    cin >> buf;
    vector<char> vc;
    for (int j = 0; j < buf.size(); j++)
      vc.push_back(buf[j]);
    vvc.push_back(vc);
  }

  for (int i = 0; i < n; i++) {
    sort(vvc[i].begin(), vvc[i].end());
  }

  vector<char> res;
  res = getAnd(vvc[0], vvc[1]);
  for (int i = 2; i < n; i++) {
    res = getAnd(res, vvc[i]);
  }

  for (int i = 0; i < res.size(); i++) {
    if (res[i] != 0)
      printf("%c", res[i]);
  }

  printf("\n");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

vector<char> getAnd(const vector<char> v1, const vector<char> v2) {
  int cnt1 = 0, cnt2 = 0;
  vector<char> res;
  while (cnt1 < v1.size() && cnt2 < v2.size()) {
    if (v1[cnt1] == v2[cnt2]) {
      res.push_back(v1[cnt1]);
      cnt1++;
      cnt2++;
    } else if (v1[cnt1] > v2[cnt2]) {
      cnt2++;
    } else {
      cnt1++;
    }
  }
  res.push_back(0);
  return res;
}

int main() {
  int n, cnt;
  vector<vector<char>> vvc;

  string buf;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    cin >> buf;
    vector<char> vc;
    for (int j = 0; j < buf.size(); j++)
      vc.push_back(buf[j]);
    vvc.push_back(vc);
  }

  for (int i = 0; i < n; i++) {
    sort(vvc[i].begin(), vvc[i].end());
  }

  vector<char> res;
  if (n != 1) {
    res = getAnd(vvc[0], vvc[1]);
    for (int i = 2; i < n; i++) {
      res = getAnd(res, vvc[i]);
    }
  } else {
    for (int i = 0; i < vvc[0].size(); i++)
      res.push_back(vvc[0][i]);
    res.push_back(0);
  }

  for (int i = 0; i < res.size(); i++) {
    if (res[i] != 0)
      printf("%c", res[i]);
  }

  printf("\n");
  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<int> coms(26), chars(26);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    fill(chars.begin(), chars.end(), 0);
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      int c = s.at(j) - 97;
      chars.at(c)++;
    }
    if (i == 0) {
      coms = chars;
      continue;
    } else {
      for (int j = 0; j < s.size(); j++) {
        if (coms.at(j) != chars.at(j)) {
          coms.at(j) = min(coms.at(j), chars.at(j));
        }
      }
    }
  }
  for (int i = 0; i < coms.size(); i++) {
    char c = i + 97;
    int cnt = coms.at(i);
    for (int j = 0; j < cnt; j++) {
      cout << c;
    }
  }
  cout << endl;
}

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

int main() {
  vector<int> coms(26), chars(26);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    fill(chars.begin(), chars.end(), 0);
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      int c = s.at(j) - 97;
      chars.at(c)++;
    }
    if (i == 0) {
      coms = chars;
      continue;
    } else {
      for (int j = 0; j < 26; j++) {
        if (coms.at(j) != chars.at(j)) {
          coms.at(j) = min(coms.at(j), chars.at(j));
        }
      }
    }
  }
  for (int i = 0; i < coms.size(); i++) {
    char c = i + 97;
    int cnt = coms.at(i);
    for (int j = 0; j < cnt; j++) {
      cout << c;
    }
  }
  cout << endl;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<vector<int>> x(n, vector<int>(26, 0));
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < (int)s[i].size(); j++) {
      x[i][s[i][j] - 'a']++;
    }
  }
  vector<int> ans(26, 100);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      ans[j] = min(ans[j], x[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    while (ans[i]--) {
      printf("%c", 'a' + i);
    }
  }
  dump("");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<vector<int>> x(n, vector<int>(26, 0));
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < (int)s[i].size(); j++) {
      x[i][s[i][j] - 'a']++;
    }
  }
  vector<int> ans(26, 100);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      ans[j] = min(ans[j], x[i][j]);
    }
  }
  for (int i = 0; i < 26; i++) {
    while (ans[i]--) {
      printf("%c", 'a' + i);
    }
  }
  dump("");
  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
// lcmとか__builtin_popcountとかはg++ -std=c++17
// default.cpp,赤波線出るけどコンパイルできる

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll a, b, d, n, maxi = 0, f = 0, mini = INF, sum = 0;
  ll w, h, x, y, k;
  // string str[3];
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  map<char, ll> m[n];
  set<char> c;
  // rep(i,n) cin>>s[i];
  rep(i, n) rep(j, s[i].length()) {
    m[i][s[i][j]]++;
    c.insert(s[i][j]);
  }
  // cout<<"a";

  map<char, ll> ans;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    ans[*itr] = INF;
  }
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    rep(i, n) ans[*itr] = min(ans[*itr], m[i][*itr]);
  }
  vector<char> answer;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    rep(i, ans[*itr]) answer.push_back(*itr);
  }
  sort(all(answer));
  // answer.erase(answer.begin());
  for (ll i = 0; i < answer.size() - 1; i++)
    cout << answer[i];
  ln;

  return 0;
}


Fixed submission:
// lcmとか__builtin_popcountとかはg++ -std=c++17
// default.cpp,赤波線出るけどコンパイルできる

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll a, b, d, n, maxi = 0, f = 0, mini = INF, sum = 0;
  ll w, h, x, y, k;
  // string str[3];
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  map<char, ll> m[n];
  set<char> c;
  // rep(i,n) cin>>s[i];
  rep(i, n) rep(j, s[i].length()) {
    m[i][s[i][j]]++;
    c.insert(s[i][j]);
  }
  // cout<<"a";

  map<char, ll> ans;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    ans[*itr] = INF;
  }
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    rep(i, n) ans[*itr] = min(ans[*itr], m[i][*itr]);
  }
  vector<char> answer;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    rep(i, ans[*itr]) answer.push_back(*itr);
  }
  sort(all(answer));
  // answer.erase(answer.begin());
  rep(i, answer.size()) cout << answer[i];
  ln;

  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = (int)1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <class T, class... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2> void amin(T &a, T2 b) {
  if (a > b)
    a = b;
}

int main() {
  // cin.tie(0); ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<VI> sk(n, VI(26));
  rep(i, n) {
    string s;
    cin >> s;
    for (auto x : s)
      sk[i][x - 'a']++;
  }

  rep(i, 26) {
    int cnt = 9999;
    rep(j, 3) { cnt = min(cnt, sk[j][i]); }
    if (cnt > 0)
      cout << string(cnt, char(i + 'a'));
  }
  cout << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = (int)1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <class T, class... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2> void amin(T &a, T2 b) {
  if (a > b)
    a = b;
}

int main() {
  // cin.tie(0); ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<VI> sk(n, VI(26));
  rep(i, n) {
    string s;
    cin >> s;
    for (auto x : s)
      sk[i][x - 'a']++;
  }

  rep(i, 26) {
    int cnt = 9999;
    rep(j, n) { cnt = min(cnt, sk[j][i]); }
    if (cnt > 0)
      cout << string(cnt, char(i + 'a'));
  }
  cout << "\n";
  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  vector<vector<int>> alpha(n, vector<int>(26));
  vector<int> ans(26, 1000000);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
    for (int j = 0; j < S.at(i).size(); j++) {
      alpha.at(i).at(S.at(i).at(j) - 'a')++;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < alpha.at(i).size(); j++) {
      ans.at(j) = min(ans.at(j), alpha.at(i).at(j));
    }
  }

  for (int i = 0; i < alpha.size(); i++) {
    if (ans.at(i)) {
      for (int j = 0; j < ans.at(i); j++) {
        cout << (char)('a' + i);
      }
    }
  }
  cout << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  vector<vector<int>> alpha(n, vector<int>(26));
  vector<int> ans(26, 1000000);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
    for (int j = 0; j < S.at(i).size(); j++) {
      alpha.at(i).at(S.at(i).at(j) - 'a')++;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < alpha.at(i).size(); j++) {
      ans.at(j) = min(ans.at(j), alpha.at(i).at(j));
    }
  }

  for (int i = 0; i < ans.size(); i++) {
    if (ans.at(i) != 0) {
      for (int j = 0; j < ans.at(i); j++) {
        cout << (char)('a' + i);
      }
    }
  }
  cout << endl;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int SIZE(string s) { return (int)s.size(); }
const long long INF = 1LL << 60;

int main() {
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vc<ll> ans(26, INF);
  rep(i, n) {
    string s;
    cin >> s;
    map<int, int> m;
    int si = SIZE(s);
    rep(j, si) m[s[j] - 'a']++;
    rep(j, 26) chmin(ans[j], m[j]);
  }
  string ss = "";
  rep(i, n) {
    if (ans[i] == INF)
      continue;
    while (ans[i] > 0) {
      ss += 'a' + i;
      ans[i]--;
    }
  }
  cout << ss << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int SIZE(string s) { return (int)s.size(); }
const long long INF = 1LL << 60;

int main() {
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vc<ll> ans(26, INF);
  rep(i, n) {
    string s;
    cin >> s;
    map<int, int> m;
    int si = SIZE(s);
    rep(j, si) m[s[j] - 'a']++;
    rep(j, 26) chmin(ans[j], m[j]);
  }
  string ss = "";
  rep(i, 26) {
    if (ans[i] == INF)
      continue;
    while (ans[i] > 0) {
      ss += 'a' + i;
      ans[i]--;
    }
  }
  cout << ss << endl;
  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n;
  vector<string> s(n);
  rep(i, n) in(s[i]);
  vector<vector<ll>> a(n, vector<ll>(26, 0));
  char f = 'a';
  rep(i, 26) {
    rep(j, n) {
      rep(k, s[j].size()) {
        if (s[j][k] == f)
          a[j][i]++;
      }
    }
    f++;
  }
  vector<ll> b(26, 999999999999999);
  rep(i, 26) { rep(j, n) b[i] = min(b[i], a[j][i]); }
  f = 'a';
  rep(i, 26) {
    rep(j, b[i]) out(f);
    f++;
  }
  memi;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n;
  in(n);
  vector<string> s(n);
  rep(i, n) in(s[i]);
  vector<vector<ll>> a(n, vector<ll>(26, 0));
  char f = 'a';
  rep(i, 26) {
    rep(j, n) {
      rep(k, s[j].size()) {
        if (s[j][k] == f)
          a[j][i]++;
      }
    }
    f++;
  }
  vector<ll> b(26, 999999999999999);
  rep(i, 26) { rep(j, n) b[i] = min(b[i], a[j][i]); }
  f = 'a';
  rep(i, 26) {
    rep(j, b[i]) out(f);
    f++;
  }
  memi;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep for (int i = 0; i < n; i++)
#define ll long long

// const int INF = 1e8;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<P> que;

int main() {
  int n;
  cin >> n;
  string al[26], sum;
  string s;
  string tmp = "";
  for (int i = 0; i < 50; i++)
    tmp += "a";
  for (int i = 0; i < 26; i++)
    al[i] = tmp;
  // すべての文字列についてアルファベットを数えて上書き　最後に辞書順出力
  rep {
    cin >> s;
    for (int j = 0; j < 26; j++) {
      tmp = "";
      for (int k = 0; k < s.size(); k++) {
        if (s.at(k) - 'a' == j)
          tmp += s.at(k);
      }
      if (tmp.size() < al[j].size())
        al[j] = tmp;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << al[i];
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep for (int i = 0; i < n; i++)
#define ll long long

// const int INF = 1e8;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<P> que;

int main() {
  int n;
  cin >> n;
  string al[26], sum;
  string s;
  string tmp = "";
  for (int i = 0; i < 50; i++)
    tmp += "a";
  for (int i = 0; i < 26; i++)
    al[i] = tmp;
  // すべての文字列についてアルファベットを数えて上書き　最後に辞書順出力
  rep {
    cin >> s;
    for (int j = 0; j < 26; j++) {
      tmp = "";
      for (int k = 0; k < s.size(); k++) {
        if (s.at(k) - 'a' == j)
          tmp += s.at(k);
      }
      if (tmp.size() < al[j].size())
        al[j] = tmp;
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << al[i];
  }
  cout << endl;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  rep(i, n) cin >> S[i];
  vector<int> cnt(26);

  for (int i = 0; i < n; i++) {
    vector<int> cnt_(26);
    rep(j, 26) cnt_[i] = 0;
    for (int j = 0; j < (int)S[i].size(); j++) {
      if (i == 0) {
        cnt[(char)S[i][j] - 'a']++;
      } else {
        cnt_[(char)S[i][j] - 'a']++;
      }
    }
    if (i != 0) {
      for (int j = 0; j < 26; j++) {
        cnt[j] = min(cnt[j], cnt_[j]);
      }
    }
  }
  rep(i, 26) {
    rep(j, cnt[i]) { cout << (char)('a' + i); }
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  rep(i, n) cin >> S[i];
  vector<int> cnt(26);

  for (int i = 0; i < n; i++) {
    vector<int> cnt_(26);
    rep(j, 26) cnt_[j] = 0;
    for (int j = 0; j < (int)S[i].size(); j++) {
      if (i == 0) {
        cnt[(char)S[i][j] - 'a']++;
      } else {
        cnt_[(char)S[i][j] - 'a']++;
      }
    }
    if (i != 0) {
      for (int j = 0; j < 26; j++) {
        cnt[j] = min(cnt[j], cnt_[j]);
      }
    }
  }
  rep(i, 26) {
    rep(j, cnt[i]) { cout << (char)('a' + i); }
  }
  cout << endl;
  return 0;
}
Problem p03761 (Python)

Buggy submission (status: Runtime Error):
n = int(input()) - 1
a = list(input())
while n and a:
    n -= 1
    a = [i for i in a if i in input()]
print(a)


Fixed submission:
n = int(input())

cnt = [10000] * 26

for i in range(n):
    s = input()
    tmp = [0] * 26
    for c in s:
        tmp[ord(c) - ord("a")] += 1
    for j in range(26):
        cnt[j] = min(cnt[j], tmp[j])

a = ""
for i in range(26):
    if cnt[i]:
        a = a + chr(ord("a") + i) * cnt[i]
print(a)
Problem p03761 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
alphabet_histgram = [[0 for _ in range(n)] for _ in range(25)]
ord_a = ord("a")

for i in range(n):
    S = input()
    for c in S:
        alphabet_histgram[ord(c) - ord_a][i] += 1

ret = ""
for i, hist_c in enumerate(alphabet_histgram):
    ret += chr(ord_a + i) * min(hist_c)

print(ret)


Fixed submission:
n = int(input())
alphabet_histgram = [[0 for _ in range(n)] for _ in range(26)]
ord_a = ord("a")

for i in range(n):
    S = input()
    for c in S:
        alphabet_histgram[ord(c) - ord_a][i] += 1

ret = ""
for i, hist_c in enumerate(alphabet_histgram):
    ret += chr(ord_a + i) * min(hist_c)

print(ret)
Problem p03761 (Python)

Buggy submission (status: Runtime Error):
import collections

n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    ans = "".join(S[0].sort())
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)


Fixed submission:
import collections

n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    S[0].sort()
    ans = "".join(S[0])
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)
Problem p03761 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
SS = []
for _ in range(N):
    SS.append(sorted(input()))
common = SS[0]
for s in SS:
    sc = s.copy()
    z = []
    for c in common:
        if c in sc:
            sc.remove(c)
            z.append(c)
    common = z
print("".join(common))


Fixed submission:
N = int(input())
SS = []
for _ in range(N):
    SS.append(sorted(input()))
common = SS[0]
for s in SS:
    sc = s[:]
    z = []
    for c in common:
        if c in sc:
            sc.remove(c)
            z.append(c)
    common = z
print("".join(common))
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
  int n;
  cin >> n;
  vvi c(3, vi(26));
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, s.size()) { c[i][s[j] - 'a']++; }
  }
  vc ans;
  rep(i, 26) {
    bool ok = true;
    int cnt = INF;
    rep(j, n) {
      if (c[j][i] == 0) {
        ok = false;
        break;
      } else
        cnt = min(cnt, c[j][i]);
    }
    if (ok) {
      rep(j, cnt) ans.push_back((char)(i + 'a'));
    }
  }
  rep(i, ans.size()) cout << ans[i];
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
  int n;
  cin >> n;
  vvi c(n, vi(26));
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, s.size()) { c[i][s[j] - 'a']++; }
  }
  vc ans;
  rep(i, 26) {
    bool ok = true;
    int cnt = INF;
    rep(j, n) {
      if (c[j][i] == 0) {
        ok = false;
        break;
      } else
        cnt = min(cnt, c[j][i]);
    }
    if (ok) {
      rep(j, cnt) ans.push_back((char)(i + 'a'));
    }
  }
  rep(i, ans.size()) cout << ans[i];
  cout << endl;
  return 0;
}
Problem p03761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
  int n;
  cin >> n;
  vector<int> a('z' - 'a' + 10, 0);
  vector<vector<int>> v(n + 10, vector<int>(n + 10, 0));
  rep(i, n) {
    string s;
    cin >> s;
    set<char> sc;
    rep(j, s.size()) {
      sc.insert(s[j]);
      v[i][s[j] - 'a']++;
    }
    for (auto u : sc) {
      a[u - 'a']++;
    }
  }
  string s = "";
  rep(i, a.size()) {
    if (a[i] == n) {
      int min1 = inf;
      rep(j, n) { min1 = min(min1, v[j][i]); }
      rep(k, min1) { s.push_back(i + 'a'); }
    }
  }
  sort(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
  int n;
  cin >> n;
  vector<int> a('z' - 'a' + 20, 0);
  vector<vector<int>> v(n + 10, vector<int>('z' - 'a' + 20, 0));
  rep(i, n) {
    string s;
    cin >> s;
    set<char> sc;
    rep(j, s.size()) {
      sc.insert(s[j]);
      v[i][s[j] - 'a']++;
    }
    for (auto u : sc) {
      a[u - 'a']++;
    }
  }
  string s = "";
  rep(i, a.size()) {
    if (a[i] == n) {
      int min1 = inf;
      rep(j, n) { min1 = min(min1, v[j][i]); }
      rep(k, min1) { s.push_back(i + 'a'); }
    }
  }
  sort(s.begin(), s.end());
  cout << s << endl;
  return 0;
}
Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using vst = vector<string>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 9e18;
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  cout << fixed << setprecision(20);
  ll n, m;
  cin >> n >> m;
  vll x(n), y(n);
  rep(i, 0, n) cin >> x[i];
  rep(i, 0, m) cin >> y[i];
  ll tate = 0, ans = 0;
  rep(i, 0, m - 1) {
    tate =
        (tate + (y[i + 1] - y[i]) % inf * (i + 1) % inf * (m - i - 1) % inf) %
        inf;
  }
  rep(i, 0, n - 1) {
    ans = (ans +
           tate * (x[i + 1] - x[i]) % inf * (i + 1) % inf * (n - i - 1) % inf) %
          inf;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using vst = vector<string>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 9e18;
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  cout << fixed << setprecision(20);
  ll n, m;
  cin >> n >> m;
  vll x(n), y(m);
  rep(i, 0, n) cin >> x[i];
  rep(i, 0, m) cin >> y[i];
  ll tate = 0, ans = 0;
  rep(i, 0, m - 1) {
    tate =
        (tate + (y[i + 1] - y[i]) % inf * (i + 1) % inf * (m - i - 1) % inf) %
        inf;
  }
  rep(i, 0, n - 1) {
    ans = (ans +
           tate * (x[i + 1] - x[i]) % inf * (i + 1) % inf * (n - i - 1) % inf) %
          inf;
  }
  cout << ans << endl;
}
Problem p03762 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 1000000007
int sumit(int n, long long int *a) {
  long long int suma = 0;
  long long int ax1, ax2;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      suma += a[j] - a[i];
      suma %= N;
    }
  }
  return suma;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long int sumx, sumy;
  long long int sum;
  long long int x[100005], y[100005];
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%lld", &y[i]);
  }
  sumx = sumit(n, x);
  sumy = sumit(m, y);
  sum = sumx * sumy;
  sum %= N;
  printf("%lld\n", sum);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 1000000007
int sumit(int n, long long int *a) {
  long long int suma = 0;
  long long int ax1, ax2;
  for (int i = 1; i < n; i++) {
    suma += (a[i] - a[i - 1]) * i * (n - i);
    suma %= N;
  }
  return suma;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long int sumx, sumy;
  long long int sum;
  long long int x[100005], y[100005];
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%lld", &y[i]);
  }
  sumx = sumit(n, x);
  sumy = sumit(m, y);
  sum = sumx * sumy;
  sum %= N;
  printf("%lld\n", sum);
  return 0;
}
Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1};
int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<int> x(n);
  vector<int> y(n);

  REP(i, n) cin >> x[i];
  REP(i, m) cin >> y[i];

  ll xsum = 0;
  FOR(i, 1, n) {
    ll t = x[i] - x[i - 1] % mod;
    t = t * i % mod * (n - i) % mod;
    xsum = (xsum + t) % mod;
  }

  ll ysum = 0;
  FOR(i, 1, m) {
    ll t = y[i] - y[i - 1] % mod;
    t = t * i % mod * (m - i) % mod;
    ysum = (ysum + t) % mod;
  }

  cout << (xsum * ysum % mod) << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1};
int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<int> x(n);
  vector<int> y(m);

  REP(i, n) cin >> x[i];
  REP(i, m) cin >> y[i];

  ll xsum = 0;
  FOR(i, 1, n) {
    ll t = x[i] - x[i - 1] % mod;
    t = t * i % mod * (n - i) % mod;
    xsum = (xsum + t) % mod;
  }

  ll ysum = 0;
  FOR(i, 1, m) {
    ll t = y[i] - y[i - 1] % mod;
    t = t * i % mod * (m - i) % mod;
    ysum = (ysum + t) % mod;
  }

  cout << (xsum * ysum % mod) << endl;
}
Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;

typedef long long ll;
const int MAXN = 10010;
const ll MOD = 1000000007;
ll ans, sy, sx;
int x[MAXN], y[MAXN], n, m;

int main() {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  for (i = 1; i <= m; i++)
    scanf("%d", &y[i]);
  for (i = 1; i <= m; i++) {
    sy = (sy + (ll)y[i] * (i - 1) % MOD) % MOD;
    sy = (sy - (ll)y[i] * (m - i) % MOD + MOD) % MOD;
  }
  for (i = 1; i <= n; i++) {
    sx = (sx + (ll)x[i] * (i - 1) % MOD) % MOD;
    sx = (sx - (ll)x[i] * (n - i) % MOD + MOD) % MOD;
  }
  printf("%lld", sx * sy % MOD);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
const ll MOD = 1000000007;
ll ans, sy, sx;
int x[MAXN], y[MAXN], n, m;

int main() {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  for (i = 1; i <= m; i++)
    scanf("%d", &y[i]);
  for (i = 1; i <= m; i++) {
    sy = (sy + (ll)y[i] * (i - 1) % MOD) % MOD;
    sy = (sy - (ll)y[i] * (m - i) % MOD + MOD) % MOD;
  }
  for (i = 1; i <= n; i++) {
    sx = (sx + (ll)x[i] * (i - 1) % MOD) % MOD;
    sx = (sx - (ll)x[i] * (n - i) % MOD + MOD) % MOD;
  }
  printf("%lld", sx * sy % MOD);
  return 0;
}
Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#define Maxn 50005
using namespace std;
const int N = 1e9 + 7;
bool Cmp(int a, int b) { return a > b; }
int main() {
  long long x[Maxn], y[Maxn], n, m, sumx = 0, sumy = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < m; i++)
    cin >> y[i];
  sort(x, x + n, Cmp);
  sort(y, y + m, Cmp);
  for (int i = 0; i <= n - 1; i++) {
    sumx = (sumx + (x[i] - x[i + 1]) * (n - 1 - i) * (i + 1)) % N;
  }
  for (int i = 0; i <= m - 1; i++) {
    sumy = (sumy + (y[i] - y[i + 1]) * (m - 1 - i) * (i + 1)) % N;
  }
  cout << sumx * sumy % N << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#define Maxn 100005
using namespace std;
const int N = 1e9 + 7;
bool Cmp(int a, int b) { return a > b; }
int main() {
  long long x[Maxn], y[Maxn], n, m, sumx = 0, sumy = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < m; i++)
    cin >> y[i];
  sort(x, x + n, Cmp);
  sort(y, y + m, Cmp);
  for (int i = 0; i <= n - 1; i++) {
    sumx = (sumx + (x[i] - x[i + 1]) * (n - 1 - i) * (i + 1)) % N;
  }
  for (int i = 0; i <= m - 1; i++) {
    sumy = (sumy + (y[i] - y[i + 1]) * (m - 1 - i) * (i + 1)) % N;
  }
  cout << sumx * sumy % N << endl;
  return 0;
}
Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define tam 1204
#define offset 320000
#define se second
#define fi first
#define pitem item *
#define ptr tre *
#define forr(i, p, n) for (ll i = p; i < n; i++)
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll mult(ll a, ll b, ll p = MOD) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = MOD) { return (a % p + b % p) % p; }
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
ll valx[tam], valy[tam];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;
  vector<ll> vx, vy;
  forr(i, 0, n) cin >> valx[i];

  forr(i, 0, m) { cin >> valy[i]; }
  forr(i, 1, m) { vx.pb(valy[i] - valy[i - 1]); }
  forr(i, 1, n) { vy.pb(valx[i] - valx[i - 1]); }
  ll C = 0;
  ll M = vx.size();
  forr(i, 0, vx.size()) { C = add(C, mult(vx[i], mult((M - i), (i + 1)))); }
  ll S = 0;
  ll N = vy.size();
  forr(i, 0, vy.size()) { S = add(S, mult(N - i, vy[i])); }
  ll tot = 0;
  forr(i, 0, vy.size()) {
    tot = add(tot, mult(C, S));
    S -= mult(N - i, vy[i]);
    S += MOD;
    S %= MOD;
  }
  cout << tot << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define tam 120004
#define offset 320000
#define se second
#define fi first
#define pitem item *
#define ptr tre *
#define forr(i, p, n) for (ll i = p; i < n; i++)
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll mult(ll a, ll b, ll p = MOD) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = MOD) { return (a % p + b % p) % p; }
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
ll valx[tam], valy[tam];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;
  vector<ll> vx, vy;
  forr(i, 0, n) cin >> valx[i];

  forr(i, 0, m) { cin >> valy[i]; }
  forr(i, 1, m) { vx.pb(valy[i] - valy[i - 1]); }
  forr(i, 1, n) { vy.pb(valx[i] - valx[i - 1]); }
  ll C = 0;
  ll M = vx.size();
  forr(i, 0, vx.size()) { C = add(C, mult(vx[i], mult((M - i), (i + 1)))); }
  ll S = 0;
  ll N = vy.size();
  forr(i, 0, vy.size()) { S = add(S, mult(N - i, vy[i])); }
  ll tot = 0;
  forr(i, 0, vy.size()) {
    tot = add(tot, mult(C, S));
    S -= mult(N - i, vy[i]);
    S += MOD;
    S %= MOD;
  }
  cout << tot << endl;
}
Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

const ll mod = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  for (auto &z : x)
    cin >> z;
  for (auto &z : y)
    cin >> z;

  vector<ll> multimex(n - 1);
  for (int i = 0; i < n - 1; i++)
    multimex[i] = (i + 1) * (n - i - 1);
  ll areax = 0;
  for (int i = 0; i < n - 1; i++) {
    areax = (areax + ((x[i + 1] - x[i]) * multimex[i]) % mod) % mod;
  }
  vector<ll> multimey(n);
  for (int i = 0; i < m - 1; i++)
    multimey[i] = (i + 1) * (m - i - 1);
  ll areay = 0;
  for (int i = 0; i < m - 1; i++) {
    areay = (areay + ((y[i + 1] - y[i]) * multimey[i]) % mod) % mod;
  }

  ll ans = (areax * areay) % mod;

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

const ll mod = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  for (auto &z : x)
    cin >> z;
  for (auto &z : y)
    cin >> z;

  vector<ll> multimex(n - 1);
  for (int i = 0; i < n - 1; i++)
    multimex[i] = (i + 1) * (n - i - 1);
  ll areax = 0;
  for (int i = 0; i < n - 1; i++) {
    areax = (areax + ((x[i + 1] - x[i]) * multimex[i]) % mod) % mod;
  }
  vector<ll> multimey(m - 1);
  for (int i = 0; i < m - 1; i++)
    multimey[i] = (i + 1) * (m - i - 1);
  ll areay = 0;
  for (int i = 0; i < m - 1; i++) {
    areay = (areay + ((y[i + 1] - y[i]) * multimey[i]) % mod) % mod;
  }

  ll ans = (areax * areay) % mod;

  cout << ans << endl;

  return 0;
}