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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  char s[10000];
  char a[26] = {0};
  scanf("%s", s);

  for (int i = 0; s[i] != '\0'; i++)
    a[s[i] - 'a']++;
  for (int i = 0; i < 26; i++) {
    if (a[i] == 0) {
      printf("%c\n", char(i + 'a'));
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  char s[1000000];
  char a[26] = {0};
  scanf("%s", s);

  for (int i = 0; s[i] != '\0'; i++)
    a[s[i] - 'a']++;
  for (int i = 0; i < 26; i++) {
    if (a[i] == 0) {
      printf("%c\n", char(i + 'a'));
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}
Problem p03624 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using numr = std::numeric_limits<T>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define MOD 1000000007
#define MOD2 998244353

int flag[26];

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

  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
    flag[s[i] - 'a']++;
  for (int i : flag) {
    if (!flag[i]) {
      cout << char('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using numr = std::numeric_limits<T>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define MOD 1000000007
#define MOD2 998244353

int flag[26];

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

  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
    flag[s[i] - 'a']++;
  for (int i = 0; i < 26; i++) {
    if (!flag[i]) {
      cout << char('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}
Problem p03624 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char s[10001], k;
  cin >> s;
  int i, j, l, d;
  l = strlen(s);
  for (i = 97; i <= 122; i++) {
    d = 0;
    k = i;
    for (j = 0; j < l; j++) {
      if (s[j] == k) {
        d = 1;
      }
    }
    if (d == 0) {
      cout << k << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char s[100000], k;
  cin >> s;
  int i, j, l, d;
  l = strlen(s);
  for (i = 97; i <= 122; i++) {
    d = 0;
    k = i;
    for (j = 0; j < l; j++) {
      if (s[j] == k) {
        d = 1;
      }
    }
    if (d == 0) {
      cout << k << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}
Problem p03624 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, cnt = 0, ans = 0, tmp = 0;

int main() {
  char S[10100];
  cin >> S;
  bool app[26];
  rep(i, 26) app[i] = false;
  for (int i = 0; S[i] != '\0'; i++) {
    // cout << S[i] - 'a' << endl;
    // cout <<S[i] - '0' << endl;
    app[S[i] - 'a'] = true;
  }
  rep(i, 26) {
    if (!app[i]) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, cnt = 0, ans = 0, tmp = 0;

int main() {
  char S[111000];
  cin >> S;
  bool app[26];
  rep(i, 26) app[i] = false;
  for (int i = 0; S[i] != '\0'; i++) {
    // cout << S[i] - 'a' << endl;
    // cout <<S[i] - '0' << endl;
    app[S[i] - 'a'] = true;
  }
  rep(i, 26) {
    if (!app[i]) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}
Problem p03624 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SUM(a) accumulate((a).begin(), (a).end(), 0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  char s = 'a';
  REP(i, 26) {
    if ((int)S.find(s) == -1) {
      cout << s << endl;
      return -1;
    }
    s++;
  }
  cout << "None" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SUM(a) accumulate((a).begin(), (a).end(), 0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  char s = 'a';
  REP(i, 26) {
    if ((int)S.find(s) == -1) {
      cout << s << endl;
      return 0;
    }
    s++;
  }
  cout << "None" << endl;
}
Problem p03624 (C++)

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

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  char a = 'a';
  bool ok = true;
  for (int i = 0; i < 26; i++) {
    if (a != s.at(i)) {
      cout << a << endl;
      ok = false;
      break;
    } else
      a++;
  }
  if (ok)
    cout << "None" << endl;
}


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

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  char a = 'a';
  bool ok = true;
  for (int i = 0; i < 26; i++) {
    if (s.find(a) > s.size()) {
      cout << a-- << endl;
      ok = false;
      break;
    } else
      a++;
  }
  if (ok)
    cout << "None" << endl;
}
Problem p03624 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char s[10005];
  int a[150], i;
  cin >> s;
  int len = strlen(s);
  for (i = 0; i < len; i++) {
    if (a[s[i]] == 0)
      a[s[i]] = 1;
  }
  for (i = 'a'; i <= 'z'; i++) {
    if (a[i] == 0) {
      printf("%c\n", i);
      break;
    }
  }
  if (i == 'z' + 1)
    printf("None\n");
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char s[100000];
  int a[200], i;
  cin >> s;
  int len = strlen(s);
  for (i = 0; i < len; i++) {
    if (a[s[i]] == 0)
      a[s[i]] = 1;
  }
  for (i = 'a'; i <= 'z'; i++) {
    if (a[i] == 0) {
      printf("%c\n", i);
      break;
    }
  }
  if (i == 'z' + 1)
    printf("None\n");
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);

  long long w = 0;
  int i = n - 1;
  int sum = 0;
  while (sum < 4) {
    long long x = a[i];
    int y = upper_bound(a, a + n, x) - lower_bound(a, a + n, x);
    if (y >= 4 and sum == 0) {
      w = x * x;
      sum = 4;
    } else if (y == 2) {
      if (sum == 2) {
        w *= x;
      } else {
        w = x;
      }
      sum += 2;
      i -= 2;
    } else if (y == 3) {
      if (sum == 2) {
        w *= x;
      } else {
        w = x;
      }
      sum += 2;
      i -= 3;
    } else {
      i -= 1;
    }
  }
  cout << w << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);

  long long w = 0;
  int i = n - 1;
  int sum = 0;
  while (sum < 4) {
    long long x = a[i];
    int y = 1;
    int j = i;
    while (a[j] == a[j - 1]) {
      y += 1;
      j -= 1;
    }
    if (y >= 4 and sum == 0) {
      w = x * x;
      sum = 4;
    } else if (y == 2) {
      if (sum == 2) {
        w *= x;
      } else {
        w = x;
      }
      sum += 2;
      i -= 2;
    } else if (y == 3) {
      if (sum == 2) {
        w *= x;
      } else {
        w = x;
      }
      sum += 2;
      i -= 3;
    } else {
      i -= 1;
    }
  }
  cout << w << endl;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

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

ll a[10500];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n, greater<ll>());

  int ope = 0;
  ll c = 0, d = 0;
  int i = 0;
  while (i < n - 1) {
    if (a[i] == a[i + 1]) {
      if (ope == 0)
        c = a[i];
      else
        d = a[i];
      ope++;
      i += 2;
    } else
      i++;
    if (ope == 2)
      break;
  }
  printf("%lld\n", c * d);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

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

ll a[105000];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n, greater<ll>());

  int ope = 0;
  ll c = 0, d = 0;
  int i = 0;
  while (i < n - 1) {
    if (a[i] == a[i + 1]) {
      if (ope == 0)
        c = a[i];
      else
        d = a[i];
      ope++;
      i += 2;
    } else
      i++;
    if (ope == 2)
      break;
  }
  printf("%lld\n", c * d);

  return 0;
}
Problem p03625 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
swi = 0
s = [0, 0]
i = 0
while i < len(a):
    if a[i] == a[i + 1]:
        s[swi] = a[i]
        i += 1
        swi += 1
        if swi == 2:
            break
    i += 1

print(s[0] * s[1])


Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
swi = 0
s = [0, 0]
i = 0
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        s[swi] = a[i]
        i += 1
        swi += 1
        if swi == 2:
            break
    i += 1

print(s[0] * s[1])
Problem p03625 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
uniq_a = sorted(list(set(a)), reverse=True)
c = 0
ans = 1
for num in uniq_a:
    if c == 0 and a.count(num) >= 4:
        print(num**2)
        exit()
    if a.count(num) >= 2:
        c += 1
        ans *= num
        if c == 2:
            print(ans)
            exit()
print(0)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)

flag = True
pairs = []
for i in range(1, len(a)):
    if flag:
        if a[i] == a[i - 1]:
            pairs.append(a[i])
            if len(pairs) == 2:
                print(pairs[0] * pairs[1])
                exit()
            flag = False
    else:
        flag = True
print(0)
Problem p03625 (Python)

Buggy submission (status: Runtime Error):
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    i = 0
    d = []
    while N - 1 > i:
        if len(d) == 2:
            break
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    print(d[0] * d[1])


main()


Fixed submission:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    i = 0
    d = []
    while N - 1 > i:
        if len(d) == 2:
            break
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    if len(d) == 2:
        print(d[0] * d[1])
    else:
        print(0)


main()
Problem p03625 (C++)

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

int store[400007];
int cnt[400007];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &store[i]), cnt[store[i]]++;
  sort(store + 1, store + n + 1, greater<int>());

  ll ans = 0;
  bool flg = false;

  for (int i = 1; i <= n; i++) {
    if (cnt[store[i]] >= 2) {
      cnt[store[i]] -= 2;
      if (!ans)
        ans = store[i];
      else {
        ans *= ll(store[i]);
        flg = true;
        break;
      }
    }
  }

  if (!flg)
    cout << 0 << endl;
  else
    cout << ans << endl;
}


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

int store[400007];
map<int, int> cnt;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &store[i]), cnt[store[i]]++;
  sort(store + 1, store + n + 1, greater<int>());

  ll ans = 0;
  bool flg = false;

  for (int i = 1; i <= n; i++) {
    if (cnt[store[i]] >= 2) {
      cnt[store[i]] -= 2;
      if (!ans)
        ans = store[i];
      else {
        ans *= ll(store[i]);
        flg = true;
        break;
      }
    }
  }

  if (!flg)
    cout << 0 << endl;
  else
    cout << ans << endl;
}
Problem p03625 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie();                                                                   \
  cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll n, arr[nax];
bool vis[1000000001];
unordered_map<ll, ll> cnt;
vector<ll> v;

int main() {
  IOS cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
    if (!vis[arr[i]]) {
      vis[arr[i]] = 1;
      v.pb(arr[i]);
    }
  }
  sort(v.rbegin(), v.rend());
  bool udah = 0;
  ll satu;
  for (auto x : v) {
    if (cnt[x] >= 4 && !udah) {
      cout << x * x << '\n';
      return 0;
    }
    if (cnt[x] >= 2) {
      if (udah) {
        cout << satu * x << '\n';
        return 0;
      } else {
        udah = 1;
        satu = x;
      }
    }
  }
  cout << 0 << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie();                                                                   \
  cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll n, arr[nax];
unordered_map<ll, bool> vis;
unordered_map<ll, ll> cnt;
vector<ll> v;

int main() {
  IOS cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
    if (!vis[arr[i]]) {
      vis[arr[i]] = 1;
      v.pb(arr[i]);
    }
  }
  sort(v.rbegin(), v.rend());
  bool udah = 0;
  ll satu;
  for (auto x : v) {
    if (cnt[x] >= 4 && !udah) {
      cout << x * x << '\n';
      return 0;
    }
    if (cnt[x] >= 2) {
      if (udah) {
        cout << satu * x << '\n';
        return 0;
      } else {
        udah = 1;
        satu = x;
      }
    }
  }
  cout << 0 << '\n';
}
Problem p03625 (C++)

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

ll l2[100005];

int main() {
  ll n, x = 0, y;
  cin >> n;
  ll l1[n + 1];
  map<ll, ll> m;
  vector<ll> v;
  vector<ll> v2;
  for (int i = 1; i <= n; i++) {
    cin >> l1[i];
    l2[l1[i]]++;
    if (l2[l1[i]] == 2)
      v.push_back(l1[i]);
    else if (l2[l1[i]] == 4)
      v2.push_back(l1[i]);
  }
  sort(v.begin(), v.end(), greater<int>());
  sort(v2.begin(), v2.end(), greater<int>());
  if (v2.size() >= 1)
    x = max(x, (ll)(v2[0] * v2[0]));
  if (v.size() >= 2)
    x = max(x, (ll)(v[0] * v[1]));
  cout << x << endl;

  return 0;
}


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

map<ll, ll> l2;

int main() {
  ll n, x = 0, y;
  cin >> n;
  ll l1[n + 1];
  map<ll, ll> m;
  vector<ll> v;
  vector<ll> v2;
  for (int i = 1; i <= n; i++) {
    cin >> l1[i];
    l2[l1[i]]++;
    if (l2[l1[i]] == 2)
      v.push_back(l1[i]);
    else if (l2[l1[i]] == 4)
      v2.push_back(l1[i]);
  }
  sort(v.begin(), v.end(), greater<int>());
  sort(v2.begin(), v2.end(), greater<int>());
  if (v2.size() >= 1)
    x = max(x, (ll)(v2[0] * v2[0]));
  if (v.size() >= 2)
    x = max(x, (ll)(v[0] * v[1]));
  cout << x << endl;

  return 0;
}
Problem p03625 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES // M_PI
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
using ll = long long;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rREP(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  int N;
  cin >> N;
  map<ll, int, greater<ll>> mp;
  rep(i, N) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  for (auto p : mp) {
    if (p.second < 2)
      continue;
    for (auto q : mp) {
      if (q.second < 2)
        continue;
      if (p.first == q.first && q.second < 4)
        continue;
      ans = max(ans, p.first * q.first);
    }
  }
  cout << ans << "\n";

  return 0;
}


Fixed submission:
#define _USE_MATH_DEFINES // M_PI
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
using ll = long long;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rREP(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  int N;
  cin >> N;
  map<ll, int, greater<ll>> mp;
  rep(i, N) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  for (auto p : mp) {
    if (p.second < 2)
      continue;
    for (auto q : mp) {
      if (q.second < 2)
        continue;
      if (p.first == q.first && q.second < 4)
        continue;
      if (chmax(ans, p.first * q.first)) {
        cout << ans << "\n";
        return 0;
      }
    }
  }
  cout << ans << "\n";

  return 0;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define rip(i, n, s) for (int i = (s); i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

int main() {
  int n;
  cin >> n;
  map<ll, int> da;
  ll a;
  rip(i, n, 0) {
    cin >> a;
    if (da.count(a)) {
      da[a]++;
    } else {
      da[a] = 1;
    }
  }
  ll m, k;
  vector<pair<ll, int>> li;
  int co = 0;
  for (auto i : da) {
    if (i.second > 1) {
      li.push_back(i);
      co++;
    }
  }
  ll ans = 0;
  if (li.back().second > 3) {
    ans += li.back().first * li.back().first;
  } else if (li.size() > 1) {
    ans = li.back().first * li[co - 2].first;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define rip(i, n, s) for (int i = (s); i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

int main() {
  int n;
  cin >> n;
  map<ll, int> da;
  ll a;
  rip(i, n, 0) {
    cin >> a;
    if (da.count(a)) {
      da[a]++;
    } else {
      da[a] = 1;
    }
  }
  ll m, k;
  vector<pair<ll, int>> li;
  int co = 0;
  for (auto i : da) {
    if (i.second > 1) {
      li.push_back(i);
      co++;
    }
  }
  ll ans = 0;
  if (li.size()) {
    if (li.back().second > 3) {
      ans += li.back().first * li.back().first;
    } else if (li.size() > 1) {
      ans = li.back().first * li[co - 2].first;
    }
  }
  cout << ans << endl;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repi(i, a, b) for (int i = a; i <= (b); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using ll = long long;
using namespace std;
typedef pair<int, int> P;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, tp;
int main() {
  cin >> N;
  vector<ll> lt;
  map<int, int> num;
  rep(i, N) {
    cin >> tp;
    num[tp]++;
    if (num[tp] == 2 || num[tp] == 4)
      lt.pb(tp);
  }
  sort(ALL(lt));
  cout << lt[sz(lt) - 1] * lt[sz(lt) - 2] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repi(i, a, b) for (int i = a; i <= (b); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using ll = long long;
using namespace std;
typedef pair<int, int> P;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, tp;
int main() {
  cin >> N;
  vector<ll> lt;
  map<int, int> num;
  rep(i, N) {
    cin >> tp;
    num[tp]++;
    if (num[tp] == 2 || num[tp] == 4)
      lt.pb(tp);
  }
  sort(ALL(lt));
  ll ans;
  if (sz(lt) >= 2)
    ans = lt[sz(lt) - 1] * lt[sz(lt) - 2];
  else
    ans = 0;
  cout << ans << endl;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>

#define BUF (100)

int N;
int A[BUF];
void input(void) {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
}

int main(void) {
  input();

  std::sort(A + 1, A + N + 1);
  int tmp[BUF];
  int cnt = 0;

  int i = 0;
  while (1) {
    i++;
    if (i >= N)
      break;
    if (A[i] == A[i + 1]) {
      tmp[cnt] = A[i];
      i++;
      cnt++;
    }
  }

  /*
  for(int j=0;j<cnt;j++){
          printf("%d\n",tmp[j]);
  }
  */

  if (cnt < 2) {
    printf("0\n");
  } else {
    long ans = (long)tmp[cnt - 1] * (long)tmp[cnt - 2];
    printf("%ld\n", ans);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <stdio.h>

#define BUF (100005)

int N;
int A[BUF];
void input(void) {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
}

int main(void) {
  input();

  std::sort(A + 1, A + N + 1);
  int tmp[BUF];
  int cnt = 0;

  int i = 0;
  while (1) {
    i++;
    if (i >= N)
      break;
    if (A[i] == A[i + 1]) {
      tmp[cnt] = A[i];
      i++;
      cnt++;
    }
  }

  /*
  for(int j=0;j<cnt;j++){
          printf("%d\n",tmp[j]);
  }
  */

  if (cnt < 2) {
    printf("0\n");
  } else {
    long ans = (long)tmp[cnt - 1] * (long)tmp[cnt - 2];
    printf("%ld\n", ans);
  }

  return 0;
}
Problem p03625 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

typedef map<int, int> Flag;

bool FindValueFromMap(int i, const Flag flag, int *out = NULL) {
  Flag::const_iterator it = flag.find(i);

  if (it != flag.end()) {
    if (out != NULL) {
      *out = it->second;
    }
    return true;
  }
  return false;
}

int main() {
  int A, N;
  int max_num, next_max_num;
  Flag flag;
  max_num = next_max_num = 0;
  string s;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A;
    int tmp = 0;
    if (FindValueFromMap(A, flag, &tmp)) {
      if (tmp % 2 == 1) {
        if (max_num < A) {
          next_max_num = max_num;
          max_num = A;
        } else {
          next_max_num = max(next_max_num, A);
        }
      }
      flag[A]++;
    } else {
      flag[A] = 1;
    }
  }

  cout << (long long)max_num * next_max_num << "\n";
  return 0;
}

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

typedef map<int, int> Flag;

bool FindValueFromMap(int i, const Flag flag, int *out = NULL) {
  Flag::const_iterator it = flag.find(i);

  if (it != flag.end()) {
    if (out != NULL) {
      *out = it->second;
    }
    return true;
  }
  return false;
}

int main() {
  int A, N;
  int max_num, next_max_num;
  Flag flag;
  max_num = next_max_num = 0;
  string s;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A;
    int tmp = 0;
    if (flag[A]) {
      tmp = flag[A];
      if (tmp % 2 == 1) {
        if (max_num < A) {
          next_max_num = max_num;
          max_num = A;
        } else {
          next_max_num = max(next_max_num, A);
        }
      }
      flag[A]++;
    } else {
      flag[A] = 1;
    }
  }

  cout << (long long)max_num * next_max_num << "\n";
  return 0;
}
Problem p03625 (C++)

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

int main() {
  int n, tmp;
  // vector<int> s;
  priority_queue<int> ps;
  // int max1=0,max2=0;
  cin >> n;
  // bool stat[]
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    ps.push(tmp);
  }
  int cnt = 0;
  int max[2] = {};
  while (ps.size() >= 2) {
    int a = ps.top();
    ps.pop();
    int b = ps.top();
    if (a == b) {
      ps.pop();
      max[cnt++] = a;
    }
  }

  cout << (long long)max[0] * max[1] << endl;
}


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

int main() {
  int n, tmp;
  // vector<int> s;
  priority_queue<int> ps;
  // int max1=0,max2=0;
  cin >> n;
  // bool stat[]
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    ps.push(tmp);
  }
  int cnt = 0;
  int max[2] = {};
  while (ps.size() >= 2) {
    int a = ps.top();
    ps.pop();
    int b = ps.top();
    if (a == b) {
      ps.pop();
      max[cnt++] = a;
      if (cnt > 1)
        break;
    }
  }

  cout << (long long)max[0] * max[1] << endl;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {

  vector<long long int> a;
  vector<long long int> saiyo;
  size_t n_count;
  long long n;

  cin >> n;

  for (long long i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  sort(a.begin(), a.end());

  long long oldValue;
  long long newValue;

  while (a.size() > 1) {
    oldValue = a.back();
    a.pop_back();
    newValue = a.back();
    if (oldValue == newValue) {
      // 採用
      saiyo.push_back(oldValue);

      // 二つ採用したらおしまい
      if (saiyo.size() == 2) {
        printf("%lld", saiyo[0] * saiyo[1]);
        return 0;
      } else {
        a.pop_back();
      }
    }
  }

  // おしまいにならず⇒作れない
  printf("0");
  return 1;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {

  vector<long long int> a;
  vector<long long int> saiyo;
  size_t n_count;
  long long n;

  cin >> n;

  for (long long i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  sort(a.begin(), a.end());

  long long oldValue;
  long long newValue;

  while (a.size() > 1) {
    oldValue = a.back();
    a.pop_back();
    newValue = a.back();
    if (oldValue == newValue) {
      // 採用
      saiyo.push_back(oldValue);

      // 二つ採用したらおしまい
      if (saiyo.size() == 2) {
        printf("%lld", saiyo[0] * saiyo[1]);
        return 0;
      } else {
        a.pop_back();
      }
    }
  }

  // おしまいにならず⇒作れない
  printf("0");
  return 0;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  long long N, on = 0, tw = 0;
  cin >> N;
  vector<long long> bo(100001, 0);
  REP(i, N) {
    long long a;
    cin >> a;
    bo[a]++;
    if (bo[a] % 2 == 0) {
      if (a >= tw) {
        tw = a;
        if (a >= on) {
          tw = on;
          on = a;
        }
      }
    }
  }
  if (on == 0 || tw == 0)
    cout << 0 << endl;
  else
    cout << on * tw << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  long long N, on = 0, tw = 0;
  cin >> N;
  map<int, int> bo;
  REP(i, N) {
    long long a;
    cin >> a;
    bo[a]++;
    if (bo[a] % 2 == 0) {
      if (a >= tw) {
        tw = a;
        if (a >= on) {
          tw = on;
          on = a;
        }
      }
    }
  }
  if (on == 0 || tw == 0)
    cout << 0 << endl;
  else
    cout << on * tw << endl;
}
Problem p03625 (C++)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define atcoder 1e9 + 77
#define _USE_MATH_DEFINES

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {

  int n, cnt = 0, j = 0;
  ll a[10010];
  ll ans[10010] = {0};

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(a, a + n);

  for (int i = 1; i < n; i++) {
    if (a[i - 1] == a[i]) {
      ans[j] = a[i];
      j++;
      i++;
    }
  }
  if (j == 0)
    j = 2;

  cout << ans[j - 1] * ans[j - 2] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define atcoder 1e9 + 77
#define _USE_MATH_DEFINES

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {

  int n, cnt = 0, j = 0;
  ll a[100010];
  ll ans[100010] = {0};

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(a, a + n);

  for (int i = 1; i < n; i++) {
    if (a[i - 1] == a[i]) {
      ans[j] = a[i];
      j++;
      i++;
    }
  }
  if (j == 0)
    j = 2;

  cout << ans[j - 1] * ans[j - 2] << endl;

  return 0;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, 0};

//-------------------------------------

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }
  vector<int> ans1, ans2;
  for (auto p : mp) {
    if (p.second >= 2) {
      ans1.push_back(p.first);
    }
    if (p.second >= 4) {
      ans2.push_back(p.first);
    }
  }
  sort(ans1.rbegin(), ans1.rend());
  sort(ans2.rbegin(), ans2.rend());
  if (ans1.size() <= 1) {
    cout << 0 << endl;
  } else {
    ll res = max((ll)ans1[0] * ans1[1], (ll)ans2[0] * ans2[0]);
    cout << res << endl;
  }
}

Fixed submission:
#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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, 0};

//-------------------------------------

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }
  vector<int> ans1, ans2;
  for (auto p : mp) {
    if (p.second >= 2) {
      ans1.push_back(p.first);
    }
    if (p.second >= 4) {
      ans2.push_back(p.first);
    }
  }
  sort(ans1.rbegin(), ans1.rend());
  sort(ans2.rbegin(), ans2.rend());
  if (ans1.size() <= 1) {
    cout << 0 << endl;
  } else {
    ll res = 0;
    if (ans2.size() >= 1) {
      res = max((ll)ans1[0] * ans1[1], (ll)ans2[0] * ans2[0]);
    } else {
      res = (ll)ans1[0] * ans1[1];
    }
    cout << res << endl;
  }
}
Problem p03625 (C++)

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

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#ifdef LOCAL
#define eprintf(...) printf(__VA_ARGS__)
#else
#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) (((a) + ((b)-1)) / b)
#define SET_ZERO(a) (memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a, b) (memset((a), b, sizeof(a)))
// #define int long long int //dont forget to change int to signed
int main() {
  int N;
  scanf("%d", &N);
  int ary[10009];
  for (int i = 0; i < N; i++) {
    scanf("%d", &ary[i]);
  }
  sort(ary, ary + N, greater<int>());

  lli ans1 = 0l, ans2 = 0l;
  int cnt = 0, index = -1;
  for (int i = 0; i < N; i++) {
    if (index != ary[i]) {
      cnt = 1;
      index = ary[i];
    } else {
      cnt++;
      if (cnt == 2) {
        cnt = 0;
        if (ans1 == 0l) {
          ans1 = index;
        } else {
          ans2 = index;
          break;
        }
      }
    }
    eprintf("%d %d \n", index, cnt);
  }
  printf("%lld\n", ans1 * ans2);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#ifdef LOCAL
#define eprintf(...) printf(__VA_ARGS__)
#else
#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) (((a) + ((b)-1)) / b)
#define SET_ZERO(a) (memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a, b) (memset((a), b, sizeof(a)))
// #define int long long int //dont forget to change int to signed
int main() {
  int N;
  scanf("%d", &N);
  int ary[100009];
  for (int i = 0; i < N; i++) {
    scanf("%d", &ary[i]);
  }
  sort(ary, ary + N, greater<int>());

  lli ans1 = 0l, ans2 = 0l;
  int cnt = 0, index = -1;
  for (int i = 0; i < N; i++) {
    if (index != ary[i]) {
      cnt = 1;
      index = ary[i];
    } else {
      cnt++;
      if (cnt == 2) {
        cnt = 0;
        if (ans1 == 0l) {
          ans1 = index;
        } else {
          ans2 = index;
          break;
        }
      }
    }
    eprintf("%d %d \n", index, cnt);
  }
  printf("%lld\n", ans1 * ans2);
  return 0;
}
Problem p03625 (C++)

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

using namespace std;

int main(void) {
  int N, x = 0, i;
  long a, ans[2];
  ans[0] = 0;
  ans[1] = 0;
  vector<long> v;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  /*for(int i=0;i<N;i++){
          cout << v[i] << endl;
  }*/
  for (i = N - 1; i > 0; i--) {
    if (v[i] == v[i - 1]) {
      ans[x] = v[i];
      i--;
      x++;
      if (x == 3)
        break;
    }
  }
  cout << ans[0] * ans[1] << endl;
  return 0;
}


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

using namespace std;

int main(void) {
  int N, x = 0, i;
  long a, ans[2];
  ans[0] = 0;
  ans[1] = 0;
  vector<long> v;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  /*for(int i=0;i<N;i++){
          cout << v[i] << endl;
  }*/
  for (i = N - 1; i > 0; i--) {
    if (v[i] == v[i - 1]) {
      ans[x] = v[i];
      i--;
      x++;
      if (x == 2)
        break;
    }
  }
  cout << ans[0] * ans[1] << endl;
  return 0;
}
Problem p03625 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
#define mst(a, b) memset(a, b, sizeof a)
#define lx x << 1
#define rx x << 1 | 1
#define reg register
#define PII pair<int, int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n, a[N], x, y;
map<int, int> mp;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  sort(a, a + n);
  x = y = -1;
  for (int i = 0; i < n; i++) {
    if (mp[a[i]] >= 2 && a[i] >= x) {
      y = x;
      x = a[i];
      mp[a[i]] -= 2;
    } else if (mp[a[i]] >= 2 && a[i] > y) {
      y = a[i];
      mp[a[i]] -= 2;
    }
  }
  if (x != -1 && y != -1)
    cout << 1LL * x * y << endl;
  else
    puts("0");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
#define mst(a, b) memset(a, b, sizeof a)
#define lx x << 1
#define rx x << 1 | 1
#define reg register
#define PII pair<int, int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n, a[N], x, y;
map<int, int> mp;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  sort(a, a + n);
  x = y = -1;
  for (int i = 0; i < n; i++) {
    if (mp[a[i]] >= 2 && a[i] >= x) {
      y = x;
      x = a[i];
      mp[a[i]] -= 2;
    } else if (mp[a[i]] >= 2 && a[i] > y) {
      y = a[i];
      mp[a[i]] -= 2;
    }
  }
  if (x != -1 && y != -1)
    cout << 1LL * x * y << endl;
  else
    puts("0");
  return 0;
}
Problem p03626 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000000000000
#define mod 1000000007

int main() {
  ll n;
  cin >> n;
  vector<string> s(2);
  cin >> s[0] >> s[1];

  ll ans = 1, num = 0;

  if (s[0][num] == s[1][num]) {
    ans = (ans * 3) % mod;
  } else {
    ans = (ans * 3 * 2) % mod;
  }

  while (1) {
    if (num + 1 < n && s[0][num] == s[1][num] &&
        s[0][num + 1] == s[1][num + 1]) {
      ans = (ans * 2) % mod;
      num++;
    } else if (num + 2 < n && s[0][num] != s[1][num] &&
               s[0][num + 1] != s[1][num + 1] &&
               s[0][num + 2] == s[1][num + 2]) {
      ans = (ans) % mod;
      num += 2;
    } else if (num + 1 < n && s[0][num] == s[1][num] &&
               s[0][num + 1] != s[1][num + 1]) {
      ans = (ans * 2) % mod;
      num++;
    } else if (num + 2 < n && s[0][num] != s[1][num] &&
               s[0][num + 1] != s[1][num + 1] &&
               s[0][num + 2] != s[1][num + 2]) {
      ans = (ans * 3) % mod;
      num += 2;
    }

    if (num >= n - 1) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000000000000
#define mod 1000000007

int main() {
  ll n;
  cin >> n;
  vector<string> s(2);
  cin >> s[0] >> s[1];

  ll ans = 1, num = 0;

  if (s[0][num] == s[1][num]) {
    ans = (ans * 3) % mod;
  } else {
    ans = (ans * 3 * 2) % mod;
  }

  while (1) {
    if (num + 1 < n && s[0][num] == s[1][num] &&
        s[0][num + 1] == s[1][num + 1]) {
      ans = (ans * 2) % mod;
      num++;
    } else if (num + 2 < n && s[0][num] != s[1][num] &&
               s[0][num + 1] != s[1][num + 1] &&
               s[0][num + 2] == s[1][num + 2]) {
      ans = (ans) % mod;
      num += 2;
    } else if (num + 1 < n && s[0][num] == s[1][num] &&
               s[0][num + 1] != s[1][num + 1]) {
      ans = (ans * 2) % mod;
      num++;
    } else if (num + 2 < n && s[0][num] != s[1][num] &&
               s[0][num + 1] != s[1][num + 1] &&
               s[0][num + 2] != s[1][num + 2]) {
      ans = (ans * 3) % mod;
      num += 2;
    } else {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03626 (C++)

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

int main() {
  long n, pro = 3;
  string s, r;
  cin >> n >> s >> r;
  if (n != 1) {
    for (int i = 1; i < n; ++i) {
      if (s.at(i - 1) == r.at(i - 1)) {
        if (i == 1) {
          pro = 3;
        }
        if (s.at(i) == r.at(i)) {
          pro *= 2;
        } else {
          pro *= 2;
          i++;
        }
      } else {
        if (i == 1) {
          i++;
          pro = 6;
        }

        if (s.at(i) == r.at(i)) {

        } else {
          pro *= 3;
          i++;
        }
      }
      pro = pro % 1000000007;
    }

    cout << pro << endl;
  } else {
    cout << 6 << endl;
  }
}

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

int main() {
  long n, pro = 3;
  string s, r;
  cin >> n >> s >> r;
  if (n != 2) {
    for (int i = 1; i < n; ++i) {
      if (s.at(i - 1) == r.at(i - 1)) {
        if (i == 1) {
          pro = 3;
        }
        if (s.at(i) == r.at(i)) {
          pro *= 2;
        } else {
          pro *= 2;
          i++;
        }
      } else {
        if (i == 1) {
          i++;
          pro = 6;
        }

        if (s.at(i) == r.at(i)) {

        } else {
          pro *= 3;
          i++;
        }
      }
      pro = pro % 1000000007;
    }

    cout << pro << endl;
  } else {
    cout << 6 << endl;
  }
}
Problem p03626 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S1 = list(input())
S2 = list(input())

if len(S1) == 1:
    print(3)
else:
    if S1[0] != S2[0]:
        t = 2
        i = 2
        a = 6
    else:
        t = 1
        i = 1
        a = 3
    while True:
        if S1[i] != S2[i]:
            if t == 2:
                a *= 3
            else:
                a *= 2
            i += 2
            t = 2
        else:
            if t == 2:
                a *= 1
            else:
                a *= 2
            i += 1
            t = 1
        a %= 1000000007
        if i == len(S1):
            print(a)
            break


Fixed submission:
N = int(input())
S1 = list(input())
S2 = list(input())

if len(S1) == 1:
    print(3)
elif len(S1) == 2:
    print(6)
else:
    if S1[0] != S2[0]:
        t = 2
        i = 2
        a = 6
    else:
        t = 1
        i = 1
        a = 3
    while True:
        if S1[i] != S2[i]:
            if t == 2:
                a *= 3
            else:
                a *= 2
            i += 2
            t = 2
        else:
            if t == 2:
                a *= 1
            else:
                a *= 2
            i += 1
            t = 1
        a %= 1000000007
        if i == len(S1):
            print(a)
            break