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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  string s[N];
  for (int i = 0; i < 2; i++)
    cin >> s[i];

  ll ans = 1;
  int cnt_w = 0, cnt_h = 0;
  for (int i = 0; i < N; i++) {
    if (s[0][i] == s[0][i + 1]) {
      if (cnt_w == 0 && cnt_h == 0) {
        ans *= 6;
      } else if (cnt_w == 0) {
        cnt_h = 0;
        ans *= 2;
      } else {
        ans *= 3;
      }
      cnt_w++;
      i++;
    } else if (s[0][i] == s[1][i]) {
      if (cnt_h == 0 && cnt_w == 0) {
        ans *= 3;
      } else if (cnt_h == 0) {
        cnt_w = 0;
        ans *= 1;
      } else {
        ans *= 2;
      }
      cnt_h++;
    }
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  string s[2];
  for (int i = 0; i < 2; i++)
    cin >> s[i];

  ll ans = 1;
  int cnt_w = 0, cnt_h = 0;
  for (int i = 0; i < N; i++) {
    if (s[0][i] == s[0][i + 1]) {
      if (cnt_w == 0 && cnt_h == 0) {
        ans *= 6;
      } else if (cnt_w == 0) {
        cnt_h = 0;
        ans *= 2;
      } else {
        ans *= 3;
      }
      cnt_w++;
      i++;
    } else if (s[0][i] == s[1][i]) {
      if (cnt_h == 0 && cnt_w == 0) {
        ans *= 3;
      } else if (cnt_h == 0) {
        cnt_w = 0;
        ans *= 1;
      } else {
        ans *= 2;
      }
      cnt_h++;
    }
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ull unsigned long long
#define mp make_pair
#define s second
#define f first
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);

using namespace std;

const int maxn = (int)(1e5) + 2;
const int mod = (int)(1e9) + 7;

int n;
map<int, int> cnt;
vector<int> a;

int main() {
  _
#ifndef ONLINE_JUDGE
      freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
    if (cnt[x] == 2)
      a.pb(x);
  }
  sort(a.begin(), a.end());

  if (a.size() >= 1 && cnt[a.back()] >= 4) {
    cout << a.back() * 1ll * a.back();
  } else if (a.size() >= 2) {
    cout << a[a.size() - 1] * 1ll * a[a.size() - 2];
  } else
    cout << 0;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ull unsigned long long
#define mp make_pair
#define s second
#define f first
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);

using namespace std;

const int maxn = (int)(1e5) + 2;
const int mod = (int)(1e9) + 7;

int n;
map<int, int> cnt;
vector<int> a;

int main() {
  _ cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
    if (cnt[x] == 2)
      a.pb(x);
  }
  sort(a.begin(), a.end());

  if (a.size() >= 1 && cnt[a.back()] >= 4) {
    cout << a.back() * 1ll * a.back();
  } else if (a.size() >= 2) {
    cout << a[a.size() - 1] * 1ll * a[a.size() - 2];
  } else
    cout << 0;

  return 0;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  ll ans = 0;
  vector<ll> v(0);
  rep(i, n - 1) {
    if (a[i] == a[i + 1]) {
      v.push_back(a[i]);
      i++;
    }
    if (v.size() == 2) {
      break;
    }
  }
  cout << v[0] * v[1] << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  ll ans = 0;
  vector<ll> v(0);
  rep(i, n - 1) {
    if (a[i] == a[i + 1]) {
      v.push_back(a[i]);
      i++;
    }
    if (v.size() == 2) {
      break;
    }
  }
  if (v.size() == 2)
    cout << v[0] * v[1] << endl;
  else
    cout << 0 << endl;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  long long int input[n];
  long long int ma[2];
  ma[0] = 0;
  ma[1] = 0;
  for (i = 0; i < n; i++) {
    cin >> input[i];
  }

  sort(input, input + n);
  reverse(input, input + n);
  int now = 0;
  i = 0;
  while (now < 2 && i < n) {
    for (i = 1; i < n; i++) {
      if (input[i] == input[i - 1]) {
        ma[now] = input[i];
        i++;
        now++;
      }
    }
  }

  cout << ma[0] * ma[1];
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  long long int input[n];
  long long int ma[2];
  ma[0] = 0;
  ma[1] = 0;
  for (i = 0; i < n; i++) {
    cin >> input[i];
  }

  sort(input, input + n);
  reverse(input, input + n);
  int now = 0;
  i = 0;
  for (i = 1; i < n; i++) {
    if (input[i] == input[i - 1]) {
      ma[now] = input[i];
      i++;
      now++;
      if (now == 2)
        break;
    }
  }

  cout << ma[0] * ma[1];
}
Problem p03627 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

int main() {

  int n, cnt = 0;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) == a.at(i + 1)) {
      b.push_back(a.at(i));
    }
  }
  sort(b.begin(), b.end(), greater<int>());
  for (int i = 0; i < b.size() - 1; i++) {
    if (b.at(i) == b.at(i + 1)) {
      b.erase(b.begin() + i);
    }
  }
  cout << b[0] * b[1] << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

int main() {

  int n, cnt = 0;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) == a.at(i + 1)) {
      b.at(i) = a.at(i);
    }
  }
  sort(b.begin(), b.end(), greater<int>());
  for (int i = 0; i < b.size() - 1; i++) {
    if (b.at(i) == b.at(i + 1)) {
      b.erase(b.begin() + i);
    }
  }
  cout << b[0] * b[1] << endl;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll mod(ll a) { return a % 1000000007; }

ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

int main() {
  ll n;
  cin >> n;
  priority_queue<ll> num;
  vl count(100000002, 0);
  num.push(0);
  num.push(0);

  rep(i, n) {
    ll x;
    cin >> x;
    count[x]++;
    if (count[x] % 2 == 0)
      num.push(x);
  }

  ll max = 0;
  ll secmax = 0;

  max = num.top();
  num.pop();
  secmax = num.top();

  cout << max * secmax << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll mod(ll a) { return a % 1000000007; }

ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

int main() {
  ll n;
  cin >> n;
  priority_queue<ll> num;
  map<ll, ll> count;
  num.push(0);
  num.push(0);

  rep(i, n) {
    ll x;
    cin >> x;
    count[x]++;
    if (count[x] % 2 == 0)
      num.push(x);
  }

  ll max = 0;
  ll secmax = 0;

  max = num.top();
  num.pop();
  secmax = num.top();

  cout << max * secmax << endl;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define ll long long
#define pb push_back
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) > (y) ? (y) : (x))
#define cls(name, x) memset(name, x, sizeof(name))
#define fs first
#define sc second
#define mp make_pair
#define L(x) (1 << x)
#define next Next
using namespace std;
const int inf = 1e9 + 10;
const ll llinf = 1e16 + 10;
const int maxn = 3e3 + 10;
const int maxm = 1e3 + 10;
const int mod = 1e9 + 7;
int n;
int A[maxn];
int main() {
  // freopen("in.txt","r",stdin);
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++)
      scanf("%d", &A[i]);
    sort(A + 1, A + 1 + n);
    ll s = 0, a = -1, b = -1;
    for (int i = n; i >= 2; i--) {
      if (A[i] == A[i - 1]) {
        if (a == -1)
          a = A[i];
        else if (b == -1)
          b = A[i];
        i--;
      }
    }
    if (a != -1 && b != -1)
      s = 1LL * a * b;
    printf("%lld\n", s);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define ll long long
#define pb push_back
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) > (y) ? (y) : (x))
#define cls(name, x) memset(name, x, sizeof(name))
#define fs first
#define sc second
#define mp make_pair
#define L(x) (1 << x)
#define next Next
using namespace std;
const int inf = 1e9 + 10;
const ll llinf = 1e16 + 10;
const int maxn = 1e5 + 10;
const int maxm = 1e3 + 10;
const int mod = 1e9 + 7;
int n;
int A[maxn];
int main() {
  // freopen("in.txt","r",stdin);
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++)
      scanf("%d", &A[i]);
    sort(A + 1, A + 1 + n);
    ll s = 0, a = -1, b = -1;
    for (int i = n; i >= 2; i--) {
      if (A[i] == A[i - 1]) {
        if (a == -1)
          a = A[i];
        else if (b == -1)
          b = A[i];
        i--;
      }
    }
    if (a != -1 && b != -1)
      s = 1LL * a * b;
    printf("%lld\n", s);
  }
  return 0;
}
Problem p03627 (C++)

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

using namespace std;

int main() {
  int N;

  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> beet;
  for (auto &p : mp) {
    if (p.second >= 4)
      beet.push_back(p.first);
    if (p.second >= 2)
      beet.push_back(p.first);
  }

  sort(begin(beet), end(beet));
  reverse(begin(beet), end(beet));
  cout << 1LL * beet[0] * beet[1] << endl;
}

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

using namespace std;

int main() {
  int N;

  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> beet;
  for (auto &p : mp) {
    if (p.second >= 4)
      beet.push_back(p.first);
    if (p.second >= 2)
      beet.push_back(p.first);
  }

  sort(begin(beet), end(beet));
  reverse(begin(beet), end(beet));
  if (beet.size() <= 1)
    cout << 0 << endl;
  else
    cout << 1LL * beet[0] * beet[1] << endl;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)
#define RFOR(i, s, e) for (int(i) = (s); (i) >= (e); (i)--)
#define rep(i, n) FOR(i, 0, n - 1)
#define MOD 1000000007

int a[10010];

signed main() {
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);

  int iti = 0, ni = 0;
  int pre = -1;
  for (int loop = 0; loop < n; loop++) {
    int i = a[loop];
    if (i == 0)
      break;

    if (pre == -1 || pre != i)
      pre = i;
    else {
      if (iti == 0)
        iti = i;
      else if (ni == 0)
        ni = i;
      pre = -1;
    }
  }

  cout << iti * ni;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)
#define RFOR(i, s, e) for (int(i) = (s); (i) >= (e); (i)--)
#define rep(i, n) FOR(i, 0, n - 1)
#define MOD 1000000007

int a[100100];

signed main() {
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);

  int iti = 0, ni = 0;
  int pre = -1;
  for (int loop = 0; loop < n; loop++) {
    int i = a[loop];
    if (i == 0)
      break;

    if (pre == -1 || pre != i)
      pre = i;
    else {
      if (iti == 0)
        iti = i;
      else if (ni == 0)
        ni = i;
      pre = -1;
    }
  }

  cout << iti * ni;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 10000 + 5;
int a[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long m = 1;
  int s = 0;
  sort(a, a + n);
  for (int i = n - 1; i > 0; i--) {
    if (a[i] == a[i - 1]) {
      m *= a[i];
      s++;
      if (s == 2)
        break;
      i--;
    }
  }
  if (s < 2)
    m = 0;
  cout << m << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 100000 + 5;
int a[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long m = 1;
  int s = 0;
  sort(a, a + n);
  for (int i = n - 1; i > 0; i--) {
    if (a[i] == a[i - 1]) {
      m *= a[i];
      s++;
      if (s == 2)
        break;
      i--;
    }
  }
  if (s < 2)
    m = 0;
  cout << m << endl;
  return 0;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
/// not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int>>
#define pf push_front

const int maxn = 1000 * 100 + 5;
int a[maxn], cn[maxn];

int32_t main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int aa = -1;
  for (int i = n - 1; i >= 0; i--) {
    cn[a[i]]++;
    if (cn[a[i]] == 2) {
      if (aa == -1) {
        cn[a[i]] = 0;
        aa = a[i];
      } else {
        cout << aa * a[i] << endl;
        return false;
      }
    }
  }
  cout << 0 << endl;
  return false;
}


Fixed submission:
/// not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int>>
#define pf push_front

const int maxn = 1000 * 100 + 5;
int a[maxn];
map<int, int> cn;

int32_t main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int aa = -1;
  for (int i = n - 1; i >= 0; i--) {
    cn[a[i]]++;
    if (cn[a[i]] == 2) {
      if (aa == -1) {
        cn[a[i]] = 0;
        aa = a[i];
      } else {
        cout << aa * a[i] << endl;
        return false;
      }
    }
  }
  cout << 0 << endl;
  return false;
}
Problem p03627 (C++)

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

map<int, int> mmp;
multiset<int> mst;

int main(void) {

  int n;
  cin >> n;

  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;

    if (mmp[x] == 0)
      mmp[x] = 1;
    else
      mst.insert(x), mmp[x] = 0;
  }

  if (mst.size() == 1)
    cout << 0;
  else
    cout << 1LL * (*mst.rbegin()) * (*prev(prev(mst.end())));

  return 0;
}


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

map<int, int> mmp;
multiset<int> mst;

int main(void) {

  int n;
  cin >> n;

  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;

    if (mmp[x] == 0)
      mmp[x] = 1;
    else
      mst.insert(x), mmp[x] = 0;
  }

  if (mst.size() <= 1)
    cout << 0;
  else
    cout << 1LL * (*mst.rbegin()) * (*prev(prev(mst.end())));

  return 0;
}
Problem p03627 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f;
long long a[N];
struct P {
  long long a;
  int b;
  friend bool operator<(P p1, P p2) { return p1.a < p2.a; }
};
int main() {
  // freopen("out.txt","w",stdout);
  int n;
  while (scanf("%d", &n) && n >= 4) {
    long long sum = 0;
    map<long long, int> m;
    m.clear();
    priority_queue<P> q;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      m[a[i]]++;
    }
    for (map<long long, int>::iterator it = m.begin(); it != m.end(); it++)
      if ((*it).second >= 2) {
        P p;
        p.a = (*it).first;
        p.b = (*it).second;
        q.push(p);
      }

    while (!q.empty()) {
      P p1 = q.top();
      q.pop();
      if (p1.b >= 4) {
        sum = p1.a * p1.a;
        break;
      } else {
        P p2 = q.top();
        q.pop();
        sum = p1.a * p2.a;
        break;
      }
    }

    printf("%lld\n", sum);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f;
long long a[N];
struct P {
  long long a;
  int b;
  friend bool operator<(P p1, P p2) { return p1.a < p2.a; }
};
int main() {
  // freopen("out.txt","w",stdout);
  int n;
  while (~scanf("%d", &n) && n >= 4) {
    long long sum = 0;
    map<long long, int> m;
    m.clear();
    priority_queue<P> q;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      m[a[i]]++;
    }
    for (map<long long, int>::iterator it = m.begin(); it != m.end(); it++)
      if ((*it).second >= 2) {
        P p;
        p.a = (*it).first;
        p.b = (*it).second;
        q.push(p);
      }

    while (!q.empty()) {
      P p1 = q.top();
      q.pop();
      if (p1.b >= 4) {
        sum = p1.a * p1.a;
        break;
      } else {
        P p2 = q.top();
        q.pop();
        sum = p1.a * p2.a;
        break;
      }
    }

    printf("%lld\n", sum);
  }
  return 0;
}
Problem p03627 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define eps 1e-8
#define pb push_back
#define pi acos(-1.0)
#define bug puts("H")
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define FO(i, n, a) for (int i = n; i >= a; --i)
#define FOR(i, a, n) for (int i = a; i <= n; ++i)
#define INF 0x3f3f3f3f
#define MOD 1000000007
///           123456789
#pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;

int math[100500] = {0};

int Scan() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
/// coding...................................

bool cmp(int a, int b) { return a > b; }

int main() {
  IOS;
  int t, m[2] = {0}, ans = 0;
  cin >> t;
  for (int i = 0; i < t; i++)
    math[i] = Scan();
  sort(math, math + t, cmp);
  for (int i = 0; i < t, ans < 2; i++) {
    if (math[i] == math[i + 1]) {
      m[ans++] = math[i];
      i++;
    }
  }
  if (m[0] && m[1])
    cout << LL(m[0]) * LL(m[1]) << endl;
  else
    cout << "0" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define eps 1e-8
#define pb push_back
#define pi acos(-1.0)
#define bug puts("H")
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define FO(i, n, a) for (int i = n; i >= a; --i)
#define FOR(i, a, n) for (int i = a; i <= n; ++i)
#define INF 0x3f3f3f3f
#define MOD 1000000007
///           123456789
#pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;

int math[100500] = {0};

int Scan() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
/// coding...................................

bool cmp(int a, int b) { return a > b; }

int main() {
  IOS;
  int t, m[2] = {0}, ans = 0;
  cin >> t;
  for (int i = 0; i < t; i++)
    cin >> math[i];
  sort(math, math + t, cmp);
  for (int i = 0; i < t, ans < 2; i++) {
    if (math[i] == math[i + 1]) {
      m[ans++] = math[i];
      i++;
    }
  }
  if (m[0] && m[1])
    cout << LL(m[0]) * LL(m[1]) << endl;
  else
    cout << "0" << endl;
  return 0;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\n";
  else
    cout << a << "\n";
}
// end of template

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  int N;
  cin >> N;
  vector<ll> A(N);
  map<ll, int> M;
  rep(i, N) {
    cin >> A[i];
    M[A[i]]++;
  }

  vector<pair<ll, int>> B;
  for (auto a : M) {
    if (a.second >= 2)
      B.pb(mp(a.first, a.second));
  }
  sort(all(B));
  reverse(all(B));
  if (B[0].second >= 4) {
    output(B[0].first * B[0].first);
    return 0;
  }
  if (B.size() < 2) {
    output(0);
  } else {
    output(B[0].first * B[1].first);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\n";
  else
    cout << a << "\n";
}
// end of template

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  int N;
  cin >> N;
  vector<ll> A(N);
  map<ll, int> M;
  rep(i, N) {
    cin >> A[i];
    M[A[i]]++;
  }

  vector<pair<ll, int>> B;
  for (auto a : M) {
    if (a.second >= 2)
      B.pb(mp(a.first, a.second));
  }
  sort(all(B));
  reverse(all(B));
  if (B.size() < 1) {
    output(0);
    return 0;
  }
  if (B[0].second >= 4) {
    output(B[0].first * B[0].first);
    return 0;
  }
  if (B.size() < 2) {
    output(0);
  } else {
    output(B[0].first * B[1].first);
  }

  return 0;
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
// #include<conio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int n;
long long a[100000];
map<long long, int> vis;
vector<long long> ve;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vis[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (vis[a[i]] >= 2)
      ve.push_back(a[i]);
  }
  sort(ve.begin(), ve.end());
  ve.erase(unique(ve.begin(), ve.end()), ve.end());
  if (vis[ve[ve.size() - 1]] >= 4) {
    cout << ve[ve.size() - 1] * ve[ve.size() - 1] << endl;
    return 0;
  }
  if (ve.size() < 2) {
    cout << 0 << endl;
    return 0;
  }
  cout << (ve[ve.size() - 1] * ve[ve.size() - 2]) << endl;
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
// #include<conio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int n;
long long a[100000];
map<long long, int> vis;
vector<long long> ve;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vis[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (vis[a[i]] >= 2)
      ve.push_back(a[i]);
  }
  sort(ve.begin(), ve.end());
  ve.erase(unique(ve.begin(), ve.end()), ve.end());
  if (ve.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (vis[ve[ve.size() - 1]] >= 4) {
    cout << ve[ve.size() - 1] * ve[ve.size() - 1] << endl;
    return 0;
  }
  if (ve.size() < 2) {
    cout << 0 << endl;
    return 0;
  }
  cout << (ve[ve.size() - 1] * ve[ve.size() - 2]) << endl;
  return 0;
}
Problem p03627 (Python)

Buggy submission (status: Runtime Error):
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
two = [k for k, v in c.items() if v > 1]
four = [k for k, v in c.items() if v > 3]
if len(two) < 2 and not four:
    print(0)
    sys.exit(0)
two.sort(reverse=True)
four.sort(reverse=True)
tmp = 1
for i in range(2):
    tmp *= two[i]
max_four = max(four)
print(tmp if tmp > max_four else max_four)


Fixed submission:
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
two = [k for k, v in c.items() if v > 1]
four = [k for k, v in c.items() if v > 3]
if len(two) < 2 and not four:
    print(0)
    sys.exit(0)

St = 0
Sf = 0
if two:
    two.sort(reverse=True)
    St = 1
    for i in range(2):
        St *= two[i]
if four:
    Sf = max(four) ** 2
print(St if St > Sf else Sf)
Problem p03627 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import Counter

N = int(input())
cnt = Counter(map(int, input().split()))

L = sum([[a] * (c // 2) for a, c in cnt.items()], [])
L.sort()

ans = 0 if len(L) < 2 else L[-1] * L[-2]
print(ans)


Fixed submission:
from collections import Counter

N = int(input())
cnt = Counter(map(int, input().split()))

L = []
for a, c in cnt.items():
    if c >= 2:
        L += [a] * (c // 2)
L.sort()

ans = 0 if len(L) < 2 else L[-1] * L[-2]
print(ans)
Problem p03627 (Python)

Buggy submission (status: Runtime Error):
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=True)

    v = []
    while len(A) != 0:
        if len(v) == 2:
            break

        if A[0] == A[1]:
            v.append(A[0])
            A.pop(0)
            A.pop(0)
        else:
            A.pop(0)

    if len(v) == 1 or len(v) == 0:
        print(0)
    else:
        print(v[0] * v[1])


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=True)

    v = []
    while len(A) > 1:
        if len(v) == 2:
            break

        if A[0] == A[1]:
            v.append(A[0])
            A.pop(0)
            A.pop(0)
        else:
            A.pop(0)

    if len(v) == 1 or len(v) == 0:
        print(0)
    else:
        print(v[0] * v[1])
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  ll N, x;
  ll A[1000000];
  vector<ll> l;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x;
    A[x]++;
    if (A[x] == 2 || A[x] == 4) {
      l.push_back(x);
    }
  }

  sort(l.begin(), l.end(), greater<ll>());

  if (l.size() < 2) {
    cout << 0 << endl;
  } else {
    cout << l[0] * l[1] << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  ll N, x;
  map<int, int> A;
  vector<ll> l;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x;
    A[x]++;
    if (A[x] == 2 || A[x] == 4) {
      l.push_back(x);
    }
  }

  sort(l.begin(), l.end(), greater<ll>());

  if (l.size() < 2) {
    cout << 0 << endl;
  } else {
    cout << l[0] * l[1] << endl;
  }
}
Problem p03627 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
const int MAXN = 10000 + 5;
int val[MAXN], n, max, max2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &val[i]);
  std::sort(val + 1, val + n + 1);
  for (int i = 1; i < n; i++)
    if (val[i] == val[i + 1]) {
      max2 = max;
      max = val[i];
      i++;
    }
  printf("%lld", (long long)max2 * max);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
const int MAXN = 100000 + 5;
int val[MAXN], n, max, max2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &val[i]);
  std::sort(val + 1, val + n + 1);
  for (int i = 1; i < n; i++)
    if (val[i] == val[i + 1]) {
      max2 = max;
      max = val[i];
      i++;
    }
  printf("%lld", (long long)max2 * max);
  return 0;
}
Problem p03628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}

typedef long long LL;

const LL mod = 1e9 + 7;

int n;
LL ans;
char s[2][30];
bool c[30];
int main() {
#ifdef ANONYM
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int rtime = clock();
#endif

  scanf("%d", &n);
  scanf("%s%s", s[0], s[1]);
  REP(i, 0, n) {
    if (s[0][i] == s[1][i])
      c[i] = true;
  }
  int cur = 0;
  bool last = false;
  if (c[0])
    ans = 3, cur++, last = true;
  else
    ans = 6, cur += 2, last = false;
  while (cur <= n - 1) {
    if (c[cur] && last)
      ans = ans * 2 % mod, cur++, last = true;
    else if (c[cur] && !last)
      cur++, last = true;
    else if (!c[cur] && last)
      ans = ans * 2 % mod, cur += 2, last = false;
    else if (!c[cur] && !last)
      ans = ans * 3 % mod, cur += 2, last = false;
  }
  printf("%lld\n", ans);

#ifdef ANONYM
  debug("time: %d\n", int(clock() - rtime));
#endif
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}

typedef long long LL;

const LL mod = 1e9 + 7;

int n;
LL ans;
char s[2][60];
bool c[60];
int main() {
#ifdef ANONYM
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int rtime = clock();
#endif

  scanf("%d", &n);
  scanf("%s%s", s[0], s[1]);
  REP(i, 0, n) {
    if (s[0][i] == s[1][i])
      c[i] = true;
  }
  int cur = 0;
  bool last = false;
  if (c[0])
    ans = 3, cur++, last = true;
  else
    ans = 6, cur += 2, last = false;
  while (cur <= n - 1) {
    if (c[cur] && last)
      ans = ans * 2 % mod, cur++, last = true;
    else if (c[cur] && !last)
      cur++, last = true;
    else if (!c[cur] && last)
      ans = ans * 2 % mod, cur += 2, last = false;
    else if (!c[cur] && !last)
      ans = ans * 3 % mod, cur += 2, last = false;
  }
  printf("%lld\n", ans);

#ifdef ANONYM
  debug("time: %d\n", int(clock() - rtime));
#endif
  return 0;
}
Problem p03628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
const ll K = 1000000007;
string ss[2];
ll dp[52];
bool isVer(int j) { return ss[0][j] == ss[1][j]; }
int main() {
  cin >> N;
  cin >> ss[0] >> ss[1];
  int j = 0;
  if (N == 1) {
    cout << 3 << endl;
    return 0;
  }
  if (ss[0][j] == ss[1][j]) {
    dp[1] = 3;
    j = 1;
  } else {
    dp[2] = 6;
    j = 2;
  }

  while (j < N) {
    if (isVer(j)) {
      if (isVer(j - 1)) {
        dp[j + 1] = 2 * dp[j];
      } else {
        dp[j + 1] = dp[j];
      }

      dp[j + 1] %= K;
      j += 1;
    } else {
      if (isVer(j - 1)) {
        dp[j + 2] = 2 * dp[j];
      } else {
        dp[j + 2] = 3 * dp[j];
      }

      dp[j + 2] %= K;
      j += 2;
    }
  }

  cout << dp[N] % K << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
const ll K = 1000000007;
string ss[2];
ll dp[100];
bool isVer(int j) { return ss[0][j] == ss[1][j]; }
int main() {
  cin >> N;
  cin >> ss[0] >> ss[1];
  int j = 0;
  if (N == 1) {
    cout << 3 << endl;
    return 0;
  }
  if (ss[0][j] == ss[1][j]) {
    dp[1] = 3;
    j = 1;
  } else {
    dp[2] = 6;
    j = 2;
  }

  while (j < N) {
    if (isVer(j)) {
      if (isVer(j - 1)) {
        dp[j + 1] = 2 * dp[j];
      } else {
        dp[j + 1] = dp[j];
      }

      dp[j + 1] %= K;
      j += 1;
    } else {
      if (isVer(j - 1)) {
        dp[j + 2] = 2 * dp[j];
      } else {
        dp[j + 2] = 3 * dp[j];
      }

      dp[j + 2] %= K;
      j += 2;
    }
  }

  cout << dp[N] % K << endl;
}
Problem p03628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

const ll Q = 1000000007;

int main(int argc, const char *argv[]) {

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

  ll n;
  cin >> n;

  string s;
  cin >> s;

  vector<ll> seq;
  for (ll i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      seq.push_back(1);
      i++;
    } else {
      seq.push_back(0);
      if (i == n - 2)
        seq.push_back(0);
    }
  }

  ll m = seq.size();
  ll ans;

  if (seq[0] == 0)
    ans = 3;
  else
    ans = 6;

  for (ll i = 0; i < m - 1; i++) {
    if (seq[i] == 0 && seq[i + 1] == 0)
      ans *= 2;
    else if (seq[i] == 0 && seq[i + 1] == 1)
      ans *= 2;
    else if (seq[i] == 1 && seq[i + 1] == 0)
      ans *= 1;
    else if (seq[i] == 1 && seq[i + 1] == 1)
      ans *= 3;
    ans %= Q;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

const ll Q = 1000000007;

int main(int argc, const char *argv[]) {

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

  ll n;
  cin >> n;

  if (n == 1) {
    cout << 3 << endl;
    return 0;
  }

  string s;
  cin >> s;

  vector<ll> seq;
  for (ll i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      seq.push_back(1);
      i++;
    } else {
      seq.push_back(0);
      if (i == n - 2)
        seq.push_back(0);
    }
  }

  ll m = seq.size();
  ll ans;

  if (seq[0] == 0)
    ans = 3;
  else
    ans = 6;

  for (ll i = 0; i < m - 1; i++) {
    if (seq[i] == 0 && seq[i + 1] == 0)
      ans *= 2;
    else if (seq[i] == 0 && seq[i + 1] == 1)
      ans *= 2;
    else if (seq[i] == 1 && seq[i + 1] == 0)
      ans *= 1;
    else if (seq[i] == 1 && seq[i + 1] == 1)
      ans *= 3;
    ans %= Q;
  }

  cout << ans << endl;

  return 0;
}
Problem p03628 (C++)

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

int main() {
  long long n;

  std::cin >> n;

  std::string s, t;

  std::cin >> s >> t;

  std::vector<long long> v(n, 1), v2(n, 1);

  if (s[0] == t[0]) {
    v[0] = 3;
    v2[0] = 1;
  } else {
    v[0] = 3;
    v2[0] = 2;
  }

  for (size_t i = 0; i < n - 1; i++) {
    if (s[i] == t[i]) { // 縦
      if (s[i + 1] == t[i + 1]) {
        v[i + 1] = 2;
        v2[i + 1] = 1;
      } else {
        v[i + 1] = 2;
        v2[i + 1] = 1;
      }
    } else {
      if (s[i + 2] == t[i + 2]) {
        v[i + 2] = 1;
        v2[i + 2] = 1;
      } else {
        v[i + 2] = 3;
        v2[i + 2] = 1;
      }
      i++;
    }
  }

  long long ans = 1;
  for (size_t i = 0; i < v.size(); i++) {
    ans = (ans * v[i]) % 1000000007;
    ans = (ans * v2[i]) % 1000000007;
  }

  // for (size_t i = 0; i < n; i++) {
  //	std::cout << v[i];
  // }
  // std::cout << std::endl;
  // for (size_t i = 0; i < n; i++) {
  //	std::cout << v2[i];
  // }

  std::cout << ans << std::endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

int main() {
  long long n;

  std::cin >> n;

  std::string s, t;

  std::cin >> s >> t;

  std::vector<long long> v(n + 1, 1), v2(n + 1, 1);

  if (s[0] == t[0]) {
    v[0] = 3;
    v2[0] = 1;
  } else {
    v[0] = 3;
    v2[0] = 2;
  }

  for (size_t i = 0; i < n - 1; i++) {
    if (s[i] == t[i]) { // 縦
      if (s[i + 1] == t[i + 1]) {
        v[i + 1] = 2;
        v2[i + 1] = 1;
      } else {
        v[i + 1] = 2;
        v2[i + 1] = 1;
      }
    } else {
      if (s[i + 2] == t[i + 2]) {
        v[i + 2] = 1;
        v2[i + 2] = 1;
      } else {
        v[i + 2] = 3;
        v2[i + 2] = 1;
      }
      i++;
    }
  }

  long long ans = 1;
  for (size_t i = 0; i < v.size(); i++) {
    ans = (ans * v[i]) % 1000000007;
    ans = (ans * v2[i]) % 1000000007;
  }

  // for (size_t i = 0; i < n; i++) {
  //	std::cout << v[i];
  // }
  // std::cout << std::endl;
  // for (size_t i = 0; i < n; i++) {
  //	std::cout << v2[i];
  // }

  std::cout << ans << std::endl;

  return 0;
}
Problem p03628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
const int N = 52;
const int MOD = 1e9 + 7;
int n;
char s1[N], s2[N];
int main() {
  scanf("%d %s %s", &n, s1, s2);
  vector<int> a;
  for (int i = 0; i < n; ++i)
    if (s1[i] == s2[i]) {
      a.pb(1);
    } else {
      a.pb(2);
      ++i;
    }
  int ans = (a[0] == 1 ? 3 : 6);
  rep(i, 1, sz(a)) if (a[i] == 1) {
    ans = 1ll * ans * (1 + (a[i - 1] == a[i])) % MOD;
  }
  else {
    ans = 1ll * ans * (2 + (a[i - 1] == a[i])) % MOD;
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
const int N = 100;
const int MOD = 1000000007;
int n;
char s1[N], s2[N];
int main() {
  scanf("%d %s %s", &n, s1, s2);
  vector<int> a;
  for (int i = 0; i < n; ++i)
    if (s1[i] == s2[i]) {
      a.pb(1);
    } else {
      a.pb(2);
      ++i;
    }
  int ans = (a[0] == 1 ? 3 : 6);
  rep(i, 1, sz(a)) if (a[i] == 1) {
    ans = 1ll * ans * (1 + (a[i - 1] == a[i])) % MOD;
  }
  else {
    ans = 1ll * ans * (2 + (a[i - 1] == a[i])) % MOD;
  }
  printf("%d", ans);
  return 0;
}
Problem p03628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define down(i, l, r) for (int i = l; i >= r; i--)
#define clr(x, y) memset(x, y, sizeof(x))
#define maxn 605000
#define inf (int)1e9
#define ll long long
#define eps 1e-9
#define mm 1000000007ll
#define low(x) x & (-x)
#define pb push_back
#define mp make_pair
#define PII pair<int, int>
using namespace std;
ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
ll ans = 1;
char s[2][505];
int main() {
  //	freopen("in.txt","r",stdin);
  //	freopen("1.txt","w",stdout);
  n = read();
  scanf("%s", s[1] + 1);
  scanf("%s", s[2] + 1);
  int now = 1, pre = 0, ans = 1;
  while (now <= n) {
    if (s[1][now] == s[2][now]) {
      if (pre == 0)
        ans = ans * 3LL % mm;
      if (pre == 1)
        ans = ans;
      if (pre == 2)
        ans = ans * 2ll % mm;
      pre = 2;
      now++;
    } else {
      if (pre == 0)
        ans = ans * 6ll % mm;
      if (pre == 1)
        ans = ans * 3ll % mm;
      if (pre == 2)
        ans = ans * 2ll % mm;
      pre = 1;
      now += 2;
    }
  }
  printf("%lld\n", ans % mm);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define down(i, l, r) for (int i = l; i >= r; i--)
#define clr(x, y) memset(x, y, sizeof(x))
#define maxn 605000
#define inf (int)1e9
#define ll long long
#define eps 1e-9
#define mm 1000000007ll
#define low(x) x & (-x)
#define pb push_back
#define mp make_pair
#define PII pair<int, int>
using namespace std;
ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
ll ans = 1;
char s[3][505];
int main() {
  //	freopen("in.txt","r",stdin);
  //	freopen("1.txt","w",stdout);
  n = read();
  scanf("%s", s[1] + 1);
  scanf("%s", s[2] + 1);
  int now = 1, pre = 0, ans = 1;
  while (now <= n) {
    if (s[1][now] == s[2][now]) {
      if (pre == 0)
        ans = ans * 3LL % mm;
      if (pre == 1)
        ans = ans;
      if (pre == 2)
        ans = ans * 2ll % mm;
      pre = 2;
      now++;
    } else {
      if (pre == 0)
        ans = ans * 6ll % mm;
      if (pre == 1)
        ans = ans * 3ll % mm;
      if (pre == 2)
        ans = ans * 2ll % mm;
      pre = 1;
      now += 2;
    }
  }
  printf("%lld\n", ans % mm);
  return 0;
}
Problem p03629 (C++)

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

const int mod = 1e9 + 7;
const int maxn = 200000 + 5;
int Next[maxn][27];
int dep[maxn];
char shit[maxn];
char ans[maxn], top;
int main() {
  scanf("%s", shit + 1);
  shit[0] = 'a';
  int l = strlen(shit);
  for (int i = 0; i < 26; i++)
    Next[l][i] = l;
  for (int i = l - 1; i >= 0; i--) {
    int tmp = shit[i] - 'a';
    for (int j = 0; j < 26; j++)
      Next[i][j] = Next[i + 1][j];
    if (i)
      ;
    Next[i][tmp] = i;
  }
  dep[l] = 0;
  for (int i = l - 1; i >= 0; i--) {
    dep[i] = mod;
    for (int j = 0; j < 26; j++) {
      dep[i] = min(dep[i], dep[Next[i + 1][j]] + 1);
    }
  }
  int i = 0;
  top = 0;
  // printf("%d\n",dep[0]);
  while (i != l) {
    // printf("%d\n",i);
    int tmin = mod;
    for (int j = 0; j < 26; j++) {
      if (dep[Next[i + 1][j]] == dep[i] - 1) {
        ans[top] = j + 'a';
        i = Next[i + 1][j];
        // printf("%d %d %c %d\n",i,j,ans[top],top);
        break;
      }
    }
    top++;
  }
  ans[top] = 0;
  printf("%s\n", ans);
  return 0;
}


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

const int mod = 1e9 + 7;
const int maxn = 200000 + 5;
int Next[maxn][27];
int dep[maxn];
char shit[maxn];
char ans[maxn];
int top;
int main() {
  scanf("%s", shit + 1);
  shit[0] = 'a';
  int l = strlen(shit);
  for (int i = 0; i < 26; i++)
    Next[l][i] = l;
  for (int i = l - 1; i >= 0; i--) {
    int tmp = shit[i] - 'a';
    for (int j = 0; j < 26; j++)
      Next[i][j] = Next[i + 1][j];
    if (i)
      ;
    Next[i][tmp] = i;
  }
  dep[l] = 0;
  for (int i = l - 1; i >= 0; i--) {
    dep[i] = mod;
    for (int j = 0; j < 26; j++) {
      dep[i] = min(dep[i], dep[Next[i + 1][j]] + 1);
    }
  }
  int i = 0;
  top = 0;
  // printf("%d\n",dep[0]);
  while (i != l) {
    // printf("%d\n",i);
    int tmin = mod;
    for (int j = 0; j < 26; j++) {
      if (dep[Next[i + 1][j]] == dep[i] - 1) {
        ans[top] = j + 'a';
        i = Next[i + 1][j];
        // printf("%d %d %c %d\n",i,j,ans[top],top);
        break;
      }
    }
    top++;
  }
  ans[top] = 0;
  printf("%s\n", ans);
  return 0;
}