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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, b) FOR(i, 0, b)
#define RFOR(i, a, b) for (int i = a - 1; i >= b; i--)
#define RREP(i, a) RFOR(i, a, 0)
#define REPALL(i, v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i, v) for (int i = v.size() - 1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v, n) count(v.begin(), v.end(), n);
void YES(bool flag) { cout << (flag ? "YES" : "NO") << endl; }
void Yes(bool flag) { cout << (flag ? "Yes" : "No") << endl; }
void yes(bool flag) { cout << (flag ? "yes" : "no") << endl; }
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<ll> x, y;

ll get(int l, vector<ll> z) {
  ll rtn = 0ll;
  REP(i, l) REP(j, l - i) {
    rtn += z[i + j] - z[i];
    rtn %= MOD;
  }
  return rtn;
}

int main() {
  int n, m;
  cin >> n >> m;
  REP(i, n) {
    ll tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  REP(i, m) {
    ll tmp;
    cin >> tmp;
    y.push_back(tmp);
  }

  ll ans = 1ll;
  ans *= get(n, x);
  ans %= MOD;
  ans *= get(m, y);
  ans %= MOD;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, b) FOR(i, 0, b)
#define RFOR(i, a, b) for (int i = a - 1; i >= b; i--)
#define RREP(i, a) RFOR(i, a, 0)
#define REPALL(i, v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i, v) for (int i = v.size() - 1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v, n) count(v.begin(), v.end(), n);
void YES(bool flag) { cout << (flag ? "YES" : "NO") << endl; }
void Yes(bool flag) { cout << (flag ? "Yes" : "No") << endl; }
void yes(bool flag) { cout << (flag ? "yes" : "no") << endl; }
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<ll> x, y;

ll get(int l, vector<ll> z) {
  ll rtn = 0ll;
  ll val = 0ll;
  REP(i, l - 1) {
    val += l - 1 - 2 * i;
    rtn += (z[i + 1] - z[i]) * val;
    rtn %= MOD;
  }
  return rtn;
}

int main() {
  int n, m;
  cin >> n >> m;
  REP(i, n) {
    ll tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  REP(i, m) {
    ll tmp;
    cin >> tmp;
    y.push_back(tmp);
  }

  ll ans = 1ll;
  ans *= get(n, x);
  ans %= MOD;
  ans *= get(m, y);
  ans %= MOD;
  cout << ans << endl;

  return 0;
}
Problem p03762 (C++)

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

const int mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(n), sx(n + 1, 0), sy(m + 1, 0);

  rep(i, n) {
    cin >> x[i];
    sx[i + 1] = (sx[i] + x[i]) % mod;
  }
  rep(i, m) {
    cin >> y[i];
    sy[i + 1] = (sy[i] + y[i]) % mod;
  }

  ll xf = 0, yf = 0;
  rep(i, n) {
    xf += sx[n] - sx[i] - ll(n - i) * x[i] + mod;
    xf %= mod;
  }
  rep(i, m) {
    yf += sy[m] - sy[i] - ll(m - i) * y[i] + mod;
    yf %= mod;
  }
  printf("%d\n", (xf * yf) % mod);

  return 0;
}


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

const int mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(m), sx(n + 1, 0), sy(m + 1, 0);

  rep(i, n) {
    cin >> x[i];
    sx[i + 1] = (sx[i] + x[i]) % mod;
  }
  rep(i, m) {
    cin >> y[i];
    sy[i + 1] = (sy[i] + y[i]) % mod;
  }

  ll xf = 0, yf = 0;
  rep(i, n) {
    xf += sx[n] - sx[i] - ll(n - i) * x[i] + mod;
    xf %= mod;
  }
  rep(i, m) {
    yf += sy[m] - sy[i] - ll(m - i) * y[i] + mod;
    yf %= mod;
  }
  printf("%d\n", (xf * yf) % mod);

  return 0;
}
Problem p03762 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, M;
  cin >> N >> M;
  vector<ll> x(N);
  vector<ll> y(N);

  for (ll i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (ll j = 0; j < M; j++) {
    cin >> y[j];
  }

  ll ansx = 0LL;
  ll ansy = 0LL;

  for (ll i = 0; i < N; i++) {
    ansx += (-N + 2 * i + 1) * x[i];
    ansx %= MOD;
  }
  for (ll j = 0; j < M; j++) {
    ansy += (-M + 2 * j + 1) * y[j];
    ansy %= MOD;
  }

  ll ans = (ansx * ansy) % MOD;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, M;
  cin >> N >> M;
  vector<ll> x(N);
  vector<ll> y(M);

  for (ll i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (ll j = 0; j < M; j++) {
    cin >> y[j];
  }

  ll ansx = 0LL;
  ll ansy = 0LL;

  for (ll i = 0; i < N; i++) {
    ansx += (-N + 2 * i + 1) * x[i];
    ansx %= MOD;
  }
  for (ll j = 0; j < M; j++) {
    ansy += (-M + 2 * j + 1) * y[j];
    ansy %= MOD;
  }

  ll ans = (ansx * ansy) % MOD;
  cout << ans << endl;
  return 0;
}
Problem p03763 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;

#define MOD 1000000007ll
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define for0(i, n) for (__typeof(n) i = 0; i < n; i++)
#define forab(i, a, b) for (__typeof(a) i = a; i < b; i++)
#define forba(i, b, a) for (__typeof(a) i = b; i > a; i--)
#define forc(c, it)                                                            \
  for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define pb push_back
#define mp make_pair
#define MAX 100005

int n;
string s;
int cnt[30];

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);

#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  for (int i = 0; i < 30; i++)
    cnt[i] = INT_MAX;

  cin >> n;

  for0(i, n) {
    int lcnt[30] = {0};
    cin >> s;
    int siz = s.size();

    for (int i = 0; i < siz; i++)
      lcnt[s[i] - 'a']++;

    for (int i = 0; i < 26; i++)
      cnt[i] = min(cnt[i], lcnt[i]);
  }

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < cnt[i]; j++)
      cout << (char)('a' + i);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;

#define MOD 1000000007ll
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define for0(i, n) for (__typeof(n) i = 0; i < n; i++)
#define forab(i, a, b) for (__typeof(a) i = a; i < b; i++)
#define forba(i, b, a) for (__typeof(a) i = b; i > a; i--)
#define forc(c, it)                                                            \
  for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define pb push_back
#define mp make_pair
#define MAX 100005

int n;
string s;
int cnt[30];

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);

  // #ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
  // #endif

  for (int i = 0; i < 30; i++)
    cnt[i] = INT_MAX;

  cin >> n;

  for0(i, n) {
    int lcnt[30] = {0};
    cin >> s;
    int siz = s.size();

    for (int i = 0; i < siz; i++)
      lcnt[s[i] - 'a']++;

    for (int i = 0; i < 26; i++)
      cnt[i] = min(cnt[i], lcnt[i]);
  }

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < cnt[i]; j++)
      cout << (char)('a' + i);
  }

  return 0;
}
Problem p03763 (C++)

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

namespace Task {

inline void solve() {
  freopen("in.in", "r", stdin);
  std::ios::sync_with_stdio(false), std::cin.tie(NULL), std::cout.tie(NULL);
  register int n;
  std::cin >> n;
  std::streambuf *ob = std::cout.rdbuf(), *ib = std::cin.rdbuf();
  static int buc[26], f[26];
  memset(f, 127, sizeof(f));
  register char c;
  for (register int i = 0; i < n; i++) {
    memset(buc, 0, sizeof(buc));
    while (c = ib->sbumpc(), !isalpha(c))
      ;
    while (isalpha(c))
      buc[c - 'a']++, c = ib->sbumpc();
    for (register int i = 0; i < 26; i++)
      f[i] = std::min(f[i], buc[i]);
  }
  for (register int i = 0; i < 26; i++)
    for (; f[i]--;)
      ob->sputc('a' + i);
}
} // namespace Task

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

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

namespace Task {

inline void solve() {
  std::ios::sync_with_stdio(false), std::cin.tie(NULL), std::cout.tie(NULL);
  register int n;
  std::cin >> n;
  std::streambuf *ob = std::cout.rdbuf(), *ib = std::cin.rdbuf();
  static int buc[26], f[26];
  memset(f, 127, sizeof(f));
  register char c;
  for (register int i = 0; i < n; i++) {
    memset(buc, 0, sizeof(buc));
    while (c = ib->sbumpc(), !isalpha(c))
      ;
    while (isalpha(c))
      buc[c - 'a']++, c = ib->sbumpc();
    for (register int i = 0; i < 26; i++)
      f[i] = std::min(f[i], buc[i]);
  }
  for (register int i = 0; i < 26; i++)
    for (; f[i]--;)
      ob->sputc('a' + i);
}
} // namespace Task

int main() {
  Task::solve();
  return 0;
}
Problem p03763 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define sz(x) x.size()
#define N 30

int temp[N][26];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, sz(s)) temp[i + 1][s[j] - 'a']++;
  }
  rep(i, 26) {
    int MIN = INT_MAX;
    fr(j, 1, n) MIN = min(MIN, temp[j][i]);
    rep(k, MIN) {
      char x = i + 'a';
      cout << x;
    }
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define sz(x) x.size()
#define N 60

int temp[N][26];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, sz(s)) temp[i + 1][s[j] - 'a']++;
  }
  rep(i, 26) {
    int MIN = INT_MAX;
    fr(j, 1, n) MIN = min(MIN, temp[j][i]);
    rep(k, MIN) {
      char x = i + 'a';
      cout << x;
    }
  }
  cout << endl;
}
Problem p03763 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int cnt[50][200];
string s;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++)
      cnt[i][s[j]]++;
  }
  string res;
  for (int c = 'a'; c <= 'z'; c++) {
    int mi = 1000000;
    for (int i = 1; i <= n; i++)
      mi = min(mi, cnt[i][c]);
    while (mi--)
      res.push_back((char)c);
  }
  cout << res;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int cnt[55][200];
string s;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++)
      cnt[i][s[j]]++;
  }
  string res;
  for (int c = 'a'; c <= 'z'; c++) {
    int mi = 1000000;
    for (int i = 1; i <= n; i++)
      mi = min(mi, cnt[i][c]);
    while (mi--)
      res.push_back((char)c);
  }
  cout << res;
}
Problem p03763 (C++)

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

string getSubStr(string s1, string s2) {
  string s = "";
  int len1 = int(s1.size()), len2 = int(s2.size()), index1 = 0, index2 = 0;
  while (index1 < len1 && index2 < len2) {
    if (s1[index1] == s2[index2]) {
      s += s1[index1];
      index1++;
      index2++;
    } else if (s1[index1] < s2[index2])
      index1++;
    else if (s2[index1] > s2[index2])
      index2++;
  }
  return s;
}

int main() {
  int n, tmp;
  vector<string> arr;
  string tmpStr;
  cin >> n;
  tmp = n;
  while (tmp > 0) {
    cin >> tmpStr;
    sort(tmpStr.begin(), tmpStr.end());
    arr.push_back(tmpStr);
    tmp--;
  }
  tmpStr = arr[0];
  for (int i = 1; i < n; i++) {
    tmpStr = getSubStr(tmpStr, arr[i]);
  }
  cout << tmpStr << endl;
  return 0;
}

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

string getSubStr(string s1, string s2) {
  string s = "";
  int len1 = int(s1.size()), len2 = int(s2.size()), index1 = 0, index2 = 0;
  while (index1 < len1 && index2 < len2) {
    if (s1[index1] == s2[index2]) {
      s += s1[index1];
      index1++;
      index2++;
    } else if (s1[index1] < s2[index2])
      index1++;
    else if (s1[index1] > s2[index2])
      index2++;
  }
  return s;
}

int main() {
  int n, tmp;
  vector<string> arr;
  string tmpStr;
  cin >> n;
  tmp = n;
  while (tmp > 0) {
    cin >> tmpStr;
    sort(tmpStr.begin(), tmpStr.end());
    arr.push_back(tmpStr);
    tmp--;
  }
  tmpStr = arr[0];
  for (int i = 1; i < n; i++) {
    tmpStr = getSubStr(tmpStr, arr[i]);
  }
  cout << tmpStr << endl;
  return 0;
}
Problem p03763 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  int min_i = -1, min_size = 50;
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
    if (S[i].size() < min_size) {
      min_size = S[i].size();
      min_i = i;
    }
  }

  string result = "";
  for (int i = 0; i < min_size; ++i) {
    char c = S[min_i][i];
    bool flg = true;
    for (int j = 0; j < n; ++j) {
      if (j == min_i) {
        continue;
      }
      auto itr = find(S[j].begin(), S[j].end(), c);
      if (itr == S[j].end()) {
        flg = false;
        break;
      } else {
        S[j].erase(itr);
      }
    }
    if (flg) {
      result += c;
    }
  }
  cout << result << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  int min_i = -1, min_size = 51;
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
    if (S[i].size() < min_size) {
      min_size = S[i].size();
      min_i = i;
    }
  }

  string result = "";
  for (int i = 0; i < min_size; ++i) {
    char c = S[min_i][i];
    bool flg = true;
    for (int j = 0; j < n; ++j) {
      if (j == min_i) {
        continue;
      }
      auto itr = find(S[j].begin(), S[j].end(), c);
      if (itr == S[j].end()) {
        flg = false;
        break;
      } else {
        S[j].erase(itr);
      }
    }
    if (flg) {
      result += c;
    }
  }
  cout << result << endl;
}
Problem p03763 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define ct(a) cout << a << endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {

  map<char, int> mp;
  int N;
  string s[50];
  cin >> N;

  FOR(i, 'a', 'z' + 1) { mp[i] = 100; }

  FOR(i, 0, N) {
    map<char, int> cur;
    cin >> s[N];
    FOR(j, 0, s[N].length()) { cur[s[N][j]]++; }
    FOR(i, 'a', 'z' + 1) { mp[i] = min(mp[i], cur[i]); }
  }
  FOR(i, 'a', 'z' + 1) {
    FOR(j, 0, mp[i]) { cout << char(i); }
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define ct(a) cout << a << endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {

  map<char, int> mp;
  int N;
  string s[50];
  cin >> N;

  FOR(i, 'a', 'z' + 1) { mp[i] = 100; }

  FOR(i, 0, N) {
    map<char, int> cur;
    cin >> s[i];
    FOR(j, 0, s[i].length()) { cur[s[i][j]]++; }
    FOR(i, 'a', 'z' + 1) { mp[i] = min(mp[i], cur[i]); }
  }
  FOR(i, 'a', 'z' + 1) {
    FOR(j, 0, mp[i]) { cout << char(i); }
  }
  cout << endl;

  return 0;
}
Problem p03763 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string b;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    sort(a.begin(), a.end());
    // cout << a ;
    if (i == 0) {
      b = a;
    }
    //  cout << " "<<b << endl;
    int j = 0;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == b[j]) {
        j++;
        if (b.size() <= j)
          break;
      } else {
        if (a[i] > b[j]) {
          b.erase(b.begin() + j);
          if (b.size() <= j)
            break;
          i--;
        }
      }
    }
    while (j < b.size()) {
      b.erase(b.begin() + j);
      //  cout << -1<<j<<endl;
    }
  }
  cout << b << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string b;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    sort(a.begin(), a.end());
    // cout << a ;
    if (i == 0) {
      b = a;
    }
    //  cout << " "<<b << endl;
    int j = 0;
    for (int i = 0; i < a.size(); i++) {
      if (b.size() <= j)
        break;
      if (a[i] == b[j]) {
        j++;
        if (b.size() <= j)
          break;
      } else {
        if (a[i] > b[j]) {
          b.erase(b.begin() + j);
          if (b.size() <= j)
            break;
          i--;
        }
      }
    }
    while (j < b.size()) {
      b.erase(b.begin() + j);
      //  cout << -1<<j<<endl;
    }
  }
  cout << b << endl;
  return 0;
}
Problem p03763 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

map<char, int> vis;
map<char, int> bja;
map<char, int> bj;
map<char, int> lenu;
string sp[123];

void hh(string s) {
  bj.clear();
  int len = s.size();
  for (int i = 0; i < len; i++) {
    bj[s[i]]++;
  }
  string y = "";
  for (char ch = 'a'; ch <= 'z'; ch++) {
    if (bj[ch] && bja[ch]) {
      vis[ch]++;
      lenu[ch] = min(lenu[ch], min(bj[ch], bja[ch]));
    }
  }
}

int main() {
  for (char ch = 'a'; ch <= 'z'; ch++) {
    lenu[ch] = 12345567;
  }
  bja.clear();
  vis.clear();
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> sp[i];
  }
  int len = sp[0].size();
  for (int i = 0; i < len; i++) {
    bja[sp[0][i]]++;
  }
  for (int i = 1; i < n; i++) {
    hh(sp[i]);
  }
  string p = "";
  int flag = 0;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    if (vis[ch] >= n - 1) {
      flag = 1;
      for (int i = 0; i < lenu[ch]; i++) {
        p += ch;
      }
    }
  }
  if (flag)
    cout << p << endl;
  return 0;
}

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

using namespace std;

map<char, int> vis;
map<char, int> bja;
map<char, int> bj;
map<char, int> lenu;
string sp[123];

void hh(string s) {
  bj.clear();
  int len = s.size();
  for (int i = 0; i < len; i++) {
    bj[s[i]]++;
  }
  string y = "";
  for (char ch = 'a'; ch <= 'z'; ch++) {
    if (bj[ch] && bja[ch]) {
      vis[ch]++;
      lenu[ch] = min(lenu[ch], min(bj[ch], bja[ch]));
    }
  }
}

int main() {
  for (char ch = 'a'; ch <= 'z'; ch++) {
    lenu[ch] = 12345567;
  }
  bja.clear();
  vis.clear();
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> sp[i];
  }
  int len = sp[0].size();
  for (int i = 0; i < len; i++) {
    bja[sp[0][i]]++;
  }
  if (n == 1) {
    sort(sp[0].begin(), sp[0].end());
    cout << sp[0] << endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    hh(sp[i]);
  }
  string p = "";
  int flag = 0;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    if (vis[ch] >= n - 1) {
      flag = 1;
      for (int i = 0; i < lenu[ch]; i++) {
        p += ch;
      }
    }
  }
  if (flag)
    cout << p << endl;
  return 0;
}
Problem p03764 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main() {
  ll N, M;
  cin >> N >> M;
  VL X(N), Y(N);
  rep(i, N) cin >> X[i];
  rep(i, M) cin >> Y[i];
  ll XX = 0, YY = 0;
  ll mod = 1e9 + 7;
  rep(i, N - 1)(XX += (X[i + 1] - X[i]) * (i + 1) % mod * (N - 1 - i) % mod) %=
      mod;
  rep(i, M - 1)(YY += (Y[i + 1] - Y[i]) * (i + 1) % mod * (M - 1 - i) % mod) %=
      mod;
  cout << XX * YY % mod << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main() {
  ll N, M;
  cin >> N >> M;
  VL X(N), Y(M);
  rep(i, N) cin >> X[i];
  rep(i, M) cin >> Y[i];
  ll XX = 0, YY = 0;
  ll mod = 1e9 + 7;
  rep(i, N - 1)(XX += (X[i + 1] - X[i]) * (i + 1) % mod * (N - 1 - i) % mod) %=
      mod;
  rep(i, M - 1)(YY += (Y[i + 1] - Y[i]) * (i + 1) % mod * (M - 1 - i) % mod) %=
      mod;
  cout << XX * YY % mod << endl;
}
Problem p03764 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

int main(void) {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> x(n), y(m);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> y[j];
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  int64_t X = 0;
  for (int i = 0; i < n - 1; i++) {
    X += (x[i + 1] - x[i]) * (((i + 1) * (n - 1 - i)) % MOD);
    X %= MOD;
  }
  int64_t Y = 0;
  for (int j = 0; j < n - 1; j++) {
    Y += (y[j + 1] - y[j]) * (((j + 1) * (m - 1 - j)) % MOD);
    Y %= MOD;
  }

  cout << X * Y % MOD << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

int main(void) {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> x(n), y(m);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> y[j];
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  int64_t X = 0;
  for (int i = 0; i < n - 1; i++) {
    X += (x[i + 1] - x[i]) * (((i + 1) * (n - 1 - i)) % MOD);
    X %= MOD;
  }
  int64_t Y = 0;
  for (int j = 0; j < m - 1; j++) {
    Y += (y[j + 1] - y[j]) * (((j + 1) * (m - 1 - j)) % MOD);
    Y %= MOD;
  }

  cout << X * Y % MOD << endl;
  return 0;
}
Problem p03764 (C++)

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

typedef long long ll;
#define MOD 1000000007

int main() {

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

  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < m; i++)
    cin >> y[i];

  ll sumR = 0, sumC = 0;
  for (ll i = 1; i <= n; i++) {
    sumR += (x[i - 1] * (i - 1) - x[i - 1] * (n - i));
    sumR %= MOD;
  }
  for (ll i = 1; i <= m; i++) {
    sumC += (y[i - 1] * (i - 1) - x[i - 1] * (m - i));
    sumC %= MOD;
  }

  cout << (sumR * sumC) % MOD << endl;

  return 0;
}


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

typedef long long ll;
#define MOD 1000000007

int main() {

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

  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < m; i++)
    cin >> y[i];

  ll sumR = 0, sumC = 0;
  for (ll i = 1; i <= n; i++) {
    sumR += (x[i - 1] * (i - 1) - x[i - 1] * (n - i));
    sumR %= MOD;
  }
  for (ll i = 1; i <= m; i++) {
    sumC += (y[i - 1] * (i - 1) - y[i - 1] * (m - i));
    sumC %= MOD;
  }

  cout << (sumR * sumC) % MOD << endl;

  return 0;
}
Problem p03764 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)

using namespace std;

typedef long long ll;

const ll mod = 1000000007LL;

ll n, m, x[100010], y[100010];

void compute() {
  ll sumX = 0;
  REP(i, 1, n + 1) {
    ll v1 = (x[i] * (ll)(i - 1)) % mod;
    ll v2 = (x[i] * (ll)(n - i)) % mod;
    ll v = (v1 - v2) % mod;
    (sumX += v) %= mod;
  }
  ll sumY = 0;
  REP(i, 1, m + 1) {
    ll v1 = (y[i] * (ll)(i - 1)) % mod;
    ll v2 = (y[i] * (ll)(m - i)) % mod;
    ll v = (v1 - v2) % mod;
    (sumY += v) %= mod;
  }
  assert(0LL <= (sumX * sumY) % mod);
  cout << (sumX * sumY) % mod << endl;
}

int main() {
  cin >> n >> m;
  REP(i, 1, n + 1) cin >> x[i];
  REP(i, 1, m + 1) cin >> y[i];
  compute();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)

using namespace std;

typedef long long ll;

const ll mod = 1000000007LL;

ll n, m, x[100010], y[100010];

void compute() {
  ll sumX = 0;
  REP(i, 1, n + 1) {
    ll v1 = (x[i] * (ll)(i - 1)) % mod;
    ll v2 = (x[i] * (ll)(n - i)) % mod;
    ll v = (v1 - v2) % mod;
    (sumX += v) %= mod;
  }
  ll sumY = 0;
  REP(i, 1, m + 1) {
    ll v1 = (y[i] * (ll)(i - 1)) % mod;
    ll v2 = (y[i] * (ll)(m - i)) % mod;
    ll v = (v1 - v2) % mod;
    (sumY += v) %= mod;
  }
  ll ans = (sumX * sumY) % mod;
  while (ans < 0LL)
    ans += mod;
  cout << ans % mod << endl;
}

int main() {
  cin >> n >> m;
  REP(i, 1, n + 1) cin >> x[i];
  REP(i, 1, m + 1) cin >> y[i];
  compute();
  return 0;
}
Problem p03764 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> x(N + 1), y(N + 1);

  for (int i = 1; i <= N; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= M; i++) {
    cin >> y[i];
  }

  ll sum_x = 0ll;
  ll sum_y = 0ll;
  for (int i = 1; i <= N; i++) {
    (sum_x += ((i - 1) * x[i] - (N - i) * x[i] + mod) % mod) %= mod;
  }
  for (int i = 1; i <= M; i++) {
    (sum_y += ((i - 1) * y[i] - (M - i) * y[i] + mod) % mod) %= mod;
  }

  cout << sum_x * sum_y % mod << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> x(N + 1), y(M + 1);

  for (int i = 1; i <= N; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= M; i++) {
    cin >> y[i];
  }

  ll sum_x = 0ll;
  ll sum_y = 0ll;
  for (int i = 1; i <= N; i++) {
    (sum_x += ((i - 1) * x[i] - (N - i) * x[i] + mod) % mod) %= mod;
  }
  for (int i = 1; i <= M; i++) {
    (sum_y += ((i - 1) * y[i] - (M - i) * y[i] + mod) % mod) %= mod;
  }

  cout << sum_x * sum_y % mod << endl;

  return 0;
}
Problem p03764 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(x, y, z) for (int x = y; x < z; x++)
#define REP(i, n) FOR(i, 0, n)
#define INF 9999999999999
#define VEC vector<int>
#define in push_back
#define ans(x) cout << x << endl
#define hairetu 10000
#define seven 1000000007
typedef long long ll;
using namespace std;
priority_queue<int, vector<int>, greater<int>> small; // chiisai
priority_queue<ll> large;                             // ookii
int main() {
  ll n, m;
  cin >> n >> m;
  ll x[hairetu], y[hairetu], xgoukei = 0, ygoukei = 0;
  REP(i, n) { cin >> x[i]; }
  REP(i, m) { cin >> y[i]; }
  REP(i, n - 1) { x[i] = x[i + 1] - x[i]; }
  REP(i, m - 1) { y[i] = y[i + 1] - y[i]; }
  REP(i, n - 1) {
    ll left, right;
    left = i - 0 + 1;
    right = n - 1 - i;
    xgoukei += left * right * x[i];
    xgoukei %= seven;
  }
  REP(i, m - 1) {
    ll left, right;
    left = i + 1;
    right = m - 1 - i;
    ygoukei += left * right * y[i];
    ygoukei %= seven;
  }
  cout << ygoukei * xgoukei % seven << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(x, y, z) for (int x = y; x < z; x++)
#define REP(i, n) FOR(i, 0, n)
#define INF 9999999999999
#define VEC vector<int>
#define in push_back
#define ans(x) cout << x << endl
#define hairetu 100003
#define seven 1000000007
typedef long long ll;
using namespace std;
priority_queue<int, vector<int>, greater<int>> small; // chiisai
priority_queue<ll> large;                             // ookii
int main() {
  ll n, m;
  cin >> n >> m;
  ll x[hairetu], y[hairetu], xgoukei = 0, ygoukei = 0;
  REP(i, n) { cin >> x[i]; }
  REP(i, m) { cin >> y[i]; }
  REP(i, n - 1) { x[i] = x[i + 1] - x[i]; }
  REP(i, m - 1) { y[i] = y[i + 1] - y[i]; }
  REP(i, n - 1) {
    ll left, right;
    left = i - 0 + 1;
    right = n - 1 - i;
    xgoukei += left * right * x[i];
    xgoukei %= seven;
  }
  REP(i, m - 1) {
    ll left, right;
    left = i + 1;
    right = m - 1 - i;
    ygoukei += left * right * y[i];
    ygoukei %= seven;
  }
  cout << ygoukei * xgoukei % seven << endl;
  return 0;
}
Problem p03764 (C++)

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>
long MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vl X(N), Y(M);
  REP(i, 0, N) cin >> X[i];
  REP(i, 0, M) cin >> Y[i];
  vector<long long> X_T(N), Y_T(M), X_Mer(N), Y_Mer(M);
  X_T[0] = N - 1;
  X_T[N - 2] = N - 1;
  Y_T[0] = M - 1;
  Y_T[M - 2] = M - 1;
  REP(i, 0, N - 1) X_Mer[i] = X[i + 1] - X[i];
  REP(i, 0, M - 1) Y_Mer[i] = Y[i + 1] - Y[i];
  REP(i, 1, (N + 1) / 2)
  X_T[i] = X_T[N - 2 - i] = (X_T[i - 1] + N - 1 - i * 2) % MOD;
  REP(i, 1, (M + 1) / 2)
  Y_T[i] = Y_T[M - 2 - i] = (Y_T[i - 1] + M - 1 - i * 2) % MOD;

  long long X_sum = 0, Y_sum = 0;
  REP(i, 0, N - 1) {
    X_sum += X_Mer[i] * X_T[i] % MOD;
    X_sum %= MOD;
  }
  REP(i, 0, N - 1) {
    Y_sum += Y_Mer[i] * Y_T[i] % MOD;
    Y_sum %= MOD;
  }
  long long ans = X_sum * Y_sum % MOD;
  cout << ans << endl;
  /*
  REP(i, 0, N-1) cout << X_T[i] << " ";
  cout << endl;
  REP(i, 0, M-1) cout << Y_T[i] << " ";
  cout << endl;
  */
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for (int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>
long MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vl X(N), Y(M);
  REP(i, 0, N) cin >> X[i];
  REP(i, 0, M) cin >> Y[i];
  vector<long long> X_T(N), Y_T(M), X_Mer(N), Y_Mer(M);
  X_T[0] = N - 1;
  X_T[N - 2] = N - 1;
  Y_T[0] = M - 1;
  Y_T[M - 2] = M - 1;
  REP(i, 0, N - 1) X_Mer[i] = X[i + 1] - X[i];
  REP(i, 0, M - 1) Y_Mer[i] = Y[i + 1] - Y[i];
  REP(i, 1, (N + 1) / 2)
  X_T[i] = X_T[N - 2 - i] = (X_T[i - 1] + N - 1 - i * 2) % MOD;
  REP(i, 1, (M + 1) / 2)
  Y_T[i] = Y_T[M - 2 - i] = (Y_T[i - 1] + M - 1 - i * 2) % MOD;

  long long X_sum = 0, Y_sum = 0;
  REP(i, 0, N - 1) {
    X_sum += X_Mer[i] * X_T[i] % MOD;
    X_sum %= MOD;
  }
  REP(i, 0, M - 1) {
    Y_sum += Y_Mer[i] * Y_T[i] % MOD;
    Y_sum %= MOD;
  }
  long long ans = X_sum * Y_sum % MOD;
  cout << ans << endl;
  /*
  REP(i, 0, N-1) cout << X_T[i] << " ";
  cout << endl;
  REP(i, 0, M-1) cout << Y_T[i] << " ";
  cout << endl;
  */
}
Problem p03764 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
#define LL long long

const LL mod = 1000000007;
LL n, m;
LL x[10005], y[100005];

int main() {
  while (~scanf("%lld %lld", &n, &m)) {
    for (int i = 0; i < n; ++i)
      scanf("%lld", &x[i]);
    for (int i = 0; i < m; ++i)
      scanf("%lld", &y[i]);
    LL sum = 0;
    for (LL i = 0; i < m - 1; ++i) {
      LL xishu = (i + 1) * (m - i - 1); // cout<<temp<<".."<<endl;
      LL temp = (((y[i + 1] - y[i]) % mod) * (xishu % mod)) % mod;
      sum += temp;
      sum %= mod;
    }
    LL ans = 0;
    for (LL i = 0; i < n - 1; ++i) {
      LL xishu = (i + 1) * (n - i - 1);
      LL temp = (((x[i + 1] - x[i]) % mod) * (xishu % mod)) % mod;
      temp = ((temp % mod) * (sum % mod)) % mod;
      ans += temp;
    }
    printf("%lld\n", ans % mod);
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
#define LL long long

const LL mod = 1000000007;
LL n, m;
LL x[100005], y[100005];

int main() {
  while (~scanf("%lld %lld", &n, &m)) {
    for (int i = 0; i < n; ++i)
      scanf("%lld", &x[i]);
    for (int i = 0; i < m; ++i)
      scanf("%lld", &y[i]);
    LL sum = 0;
    for (LL i = 0; i < m - 1; ++i) {
      LL xishu = (i + 1) * (m - i - 1); // cout<<temp<<".."<<endl;
      LL temp = (((y[i + 1] - y[i]) % mod) * (xishu % mod)) % mod;
      sum += temp;
      sum %= mod;
    }
    LL ans = 0;
    for (LL i = 0; i < n - 1; ++i) {
      LL xishu = (i + 1) * (n - i - 1);
      LL temp = (((x[i + 1] - x[i]) % mod) * (xishu % mod)) % mod;
      temp = ((temp % mod) * (sum % mod)) % mod;
      ans += temp;
    }
    printf("%lld\n", ans % mod);
  }
}
Problem p03765 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  string s, t;
  cin >> s >> t;

  ll n = s.size() + 1, m = t.size() + 1;
  vector<ll> cntA1(n), cntA2(m);
  REP(i, n) {
    cntA1[i + 1] = (s[i] == 'A') ? 1 : 2;
    cntA1[i + 1] += cntA1[i];
  }
  REP(i, m) {
    cntA2[i + 1] = (t[i] == 'A') ? 1 : 2;
    cntA2[i + 1] += cntA2[i];
  }

  ll q;
  cin >> q;
  REP(i, q) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((cntA1[b] - cntA1[a - 1]) % 3 == (cntA2[d] - cntA2[c - 1]) % 3) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  string s, t;
  cin >> s >> t;

  ll n = s.size() + 1, m = t.size() + 1;
  vector<ll> cntA1(n + 5), cntA2(m + 5);
  REP(i, n) {
    cntA1[i + 1] = (s[i] == 'A') ? 1 : 2;
    cntA1[i + 1] += cntA1[i];
  }
  REP(i, m) {
    cntA2[i + 1] = (t[i] == 'A') ? 1 : 2;
    cntA2[i + 1] += cntA2[i];
  }

  ll q;
  cin >> q;
  REP(i, q) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((cntA1[b] - cntA1[a - 1]) % 3 == (cntA2[d] - cntA2[c - 1]) % 3) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
}
Problem p03765 (C++)

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const ll Mod = 1e9 + 7;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;
const ll N = 1ll << Log;
const int Maxn = 5e2 + 10;
const int Base = 101;

ll ps1[Maxn], ps2[Maxn];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  str s, t;
  cin >> s >> t;
  ll n = s.size();
  ll m = t.size();
  s = '!' + s;
  t = '!' + t;
  for (int i = 1; i <= n; i++)
    ps1[i] = ps1[i - 1] + (s[i] == 'A' ? 1 : -1);
  for (int i = 1; i <= m; i++)
    ps2[i] = ps2[i - 1] + (t[i] == 'A' ? 1 : -1);
  ll q;
  cin >> q;
  ll a, b, c, d, v;
  for (int i = 0; i < q; i++) {
    cin >> a >> b >> c >> d;
    v = (ps1[b] - ps1[a - 1]) - (ps2[d] - ps2[c - 1]);
    cout << (v % 3 == 0 ? "YES" : "NO") << '\n';
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const ll Mod = 1e9 + 7;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;
const ll N = 1ll << Log;
const int Maxn = 1e5 + 10;
const int Base = 101;

ll ps1[Maxn], ps2[Maxn];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  str s, t;
  cin >> s >> t;
  ll n = s.size();
  ll m = t.size();
  s = '!' + s;
  t = '!' + t;
  for (int i = 1; i <= n; i++)
    ps1[i] = ps1[i - 1] + (s[i] == 'A' ? 1 : -1);
  for (int i = 1; i <= m; i++)
    ps2[i] = ps2[i - 1] + (t[i] == 'A' ? 1 : -1);
  ll q;
  cin >> q;
  ll a, b, c, d, v;
  for (int i = 0; i < q; i++) {
    cin >> a >> b >> c >> d;
    v = (ps1[b] - ps1[a - 1]) - (ps2[d] - ps2[c - 1]);
    cout << (v % 3 == 0 ? "YES" : "NO") << '\n';
  }
  return 0;
}
Problem p03765 (C++)

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

string s, t;
ll q;
ll a, b, c, d;
ll a_b_count[2][10010]; // a-bの値%3

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  std::cin >> s >> t;
  std::cin >> q;
  Fill(a_b_count, 0);
  ll s_length = s.length();
  ll t_length = t.length();

  for (int i = 0; i < s_length; i++) {
    if (s[i] == 'A') {
      a_b_count[0][i + 1] = a_b_count[0][i] + 1;
    } else {
      a_b_count[0][i + 1] = a_b_count[0][i] + 2;
    }
  }
  for (int i = 0; i < t_length; i++) {
    if (t[i] == 'A') {
      a_b_count[1][i + 1] = a_b_count[1][i] + 1;
    } else {
      a_b_count[1][i + 1] = a_b_count[1][i] + 2;
    }
  }

  for (int i = 0; i < q; i++) {
    std::cin >> a >> b >> c >> d;
    if ((a_b_count[0][b] - a_b_count[0][a - 1]) % 3 ==
        (a_b_count[1][d] - a_b_count[1][c - 1]) % 3) {
      std::cout << "YES" << std::endl;
    } else {
      std::cout << "NO" << std::endl;
    }
  }
}


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

string s, t;
ll q;
ll a, b, c, d;
ll a_b_count[2][100010]; // a-bの値%3

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  std::cin >> s >> t;
  std::cin >> q;
  Fill(a_b_count, 0);
  ll s_length = s.length();
  ll t_length = t.length();

  for (int i = 0; i < s_length; i++) {
    if (s[i] == 'A') {
      a_b_count[0][i + 1] = a_b_count[0][i] + 1;
    } else {
      a_b_count[0][i + 1] = a_b_count[0][i] + 2;
    }
  }
  for (int i = 0; i < t_length; i++) {
    if (t[i] == 'A') {
      a_b_count[1][i + 1] = a_b_count[1][i] + 1;
    } else {
      a_b_count[1][i + 1] = a_b_count[1][i] + 2;
    }
  }

  for (int i = 0; i < q; i++) {
    std::cin >> a >> b >> c >> d;
    if ((a_b_count[0][b] - a_b_count[0][a - 1]) % 3 ==
        (a_b_count[1][d] - a_b_count[1][c - 1]) % 3) {
      std::cout << "YES" << std::endl;
    } else {
      std::cout << "NO" << std::endl;
    }
  }
}
Problem p03765 (C++)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
string s, t;
int sum[100005], tum[100005];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> s >> t;
  n = (int)s.size();
  m = (int)t.size();
  sum[0] = tum[0] = 0;
  forn(i, n) sum[i + 1] = sum[i] + (s[i] == 'A' ? 1 : 2);
  forn(i, m) tum[i + 1] = tum[i] + (t[i] == 'A' ? 1 : 2);
  int qc;
  scanf("%d", &qc);
  forn(i, qc) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b, --c, --d;
    int s1 = sum[b + 1] - sum[a];
    int s2 = tum[d + 1] - tum[c];
    s1 %= 3;
    s2 %= 3;
    if (s1 == s2) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
string s, t;
int sum[100005], tum[100005];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> s >> t;
  n = (int)s.size();
  m = (int)t.size();
  sum[0] = tum[0] = 0;
  forn(i, n) sum[i + 1] = sum[i] + (s[i] == 'A' ? 1 : 2);
  forn(i, m) tum[i + 1] = tum[i] + (t[i] == 'A' ? 1 : 2);
  int qc;
  cin >> qc;
  forn(i, qc) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b, --c, --d;
    int s1 = sum[b + 1] - sum[a];
    int s2 = tum[d + 1] - tum[c];
    s1 %= 3;
    s2 %= 3;
    if (s1 == s2) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
Problem p03765 (C++)

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

int sum_s[10005], sum_t[10005];
int sa(int a, int b) { return sum_s[b] - sum_s[a - 1]; }
int sb(int a, int b) { return b - a + 1 - sa(a, b); }
int ta(int a, int b) { return sum_t[b] - sum_t[a - 1]; }
int tb(int a, int b) { return b - a + 1 - ta(a, b); }

int main() {
  string s, t;
  cin >> s >> t;
  int q;
  cin >> q;
  sum_s[0] = 0;
  sum_t[0] = 0;
  for (int i = 1; i < s.length() + 1; i++)
    sum_s[i] = sum_s[i - 1] + (s[i - 1] == 'A' ? 1 : 0);
  for (int i = 1; i < t.length() + 1; i++)
    sum_t[i] = sum_t[i - 1] + (t[i - 1] == 'A' ? 1 : 0);
  for (int i = 0; i < q; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int aa = sa(a, b) + 2 * sb(a, b), bb = ta(c, d) + 2 * tb(c, d);
    // cout << " "<< bb << endl;
    if (aa < bb)
      swap(aa, bb);
    if ((aa - bb) % 3 == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

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

int sum_s[100005], sum_t[100005];
int sa(int a, int b) { return sum_s[b] - sum_s[a - 1]; }
int sb(int a, int b) { return b - a + 1 - sa(a, b); }
int ta(int a, int b) { return sum_t[b] - sum_t[a - 1]; }
int tb(int a, int b) { return b - a + 1 - ta(a, b); }

int main() {
  string s, t;
  cin >> s >> t;
  int q;
  cin >> q;
  sum_s[0] = 0;
  sum_t[0] = 0;
  for (int i = 1; i < s.length() + 1; i++)
    sum_s[i] = sum_s[i - 1] + (s[i - 1] == 'A' ? 1 : 0);
  for (int i = 1; i < t.length() + 1; i++)
    sum_t[i] = sum_t[i - 1] + (t[i - 1] == 'A' ? 1 : 0);
  for (int i = 0; i < q; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int aa = sa(a, b) + 2 * sb(a, b), bb = ta(c, d) + 2 * tb(c, d);
    // cout << " "<< bb << endl;
    if (aa < bb)
      swap(aa, bb);
    if ((aa - bb) % 3 == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
Problem p03765 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  string s[2];
  int num[2][20000][2] = {{{0}}};
  int i, j, q, a, b, c, d, s1, t1;

  cin >> s[0] >> s[1];
  for (i = 0; i < 2; i++) {
    for (j = 0; s[i][j] != NULL; j++) {
      if (s[i][j] == 'A') {
        num[i][j + 1][0] = num[i][j][0] + 1;
        num[i][j + 1][1] = num[i][j][1];
      }
      if (s[i][j] == 'B') {
        num[i][j + 1][0] = num[i][j][0];
        num[i][j + 1][1] = num[i][j][1] + 1;
      }
    }
  }

  cin >> q;

  for (i = 0; i < q; i++) {
    cin >> a >> b >> c >> d;
    s1 = (num[0][b][0] - num[0][a - 1][0]) +
         (num[0][b][1] - num[0][a - 1][1]) * 2;
    t1 = (num[1][d][0] - num[1][c - 1][0]) +
         (num[1][d][1] - num[1][c - 1][1]) * 2;

    if ((s1 - t1) % 3) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  string s[2];
  int num[2][200000][2] = {{{0}}};
  int i, j, q, a, b, c, d, s1, t1;

  cin >> s[0] >> s[1];
  for (i = 0; i < 2; i++) {
    for (j = 0; s[i][j] != NULL; j++) {
      if (s[i][j] == 'A') {
        num[i][j + 1][0] = num[i][j][0] + 1;
        num[i][j + 1][1] = num[i][j][1];
      }
      if (s[i][j] == 'B') {
        num[i][j + 1][0] = num[i][j][0];
        num[i][j + 1][1] = num[i][j][1] + 1;
      }
    }
  }

  cin >> q;

  for (i = 0; i < q; i++) {
    cin >> a >> b >> c >> d;
    s1 = (num[0][b][0] - num[0][a - 1][0]) +
         (num[0][b][1] - num[0][a - 1][1]) * 2;
    t1 = (num[1][d][0] - num[1][c - 1][0]) +
         (num[1][d][1] - num[1][c - 1][1]) * 2;

    if ((s1 - t1) % 3) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
  }
}