alexjercan/bugnet huggingface dataset:
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n;
  vector<string> s(n);
  int nP2 = n * (n - 1);
  vector<int> a(3, 1000010001);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      m = atoi((s[i] + s[j]).c_str());
      if (a[2] > m) {
        a[2] = m;
        sort(a.begin(), a.end());
      }
    }
  }
  cout << a[2] << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int nP2 = n * (n - 1);
  vector<int> a(nP2);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      a[k++] = atoi((s[i] + s[j]).c_str());
    }
  }
  sort(a.begin(), a.end());
  cout << a[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

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

  int n;
  cin >> n;
  vector<int> A(n);
  REP(i, n) cin >> A[i];
  sort(A.begin(), A.end());

  vector<int> B;
  REP(i, min(n, 4)) {
    REP(j, min(n, 4)) {
      if (i == j)
        continue;
      B.emplace_back(stoi(to_string(A[i]) + to_string(A[j])));
    }
  }

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

  cout << B[2] << endl;

  return 0;
}


Error: MLE

Fixed submission:

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

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

  int n;
  cin >> n;
  vector<int> A(n);
  REP(i, n) cin >> A[i];

  vector<int> B;
  REP(i, n) {
    REP(j, n) {
      if (i == j)
        continue;
      B.emplace_back(stoi(to_string(A[i]) + to_string(A[j])));
    }
  }

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

  cout << B[2] << endl;

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a, b(N);
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }

  sort(b.begin(), b.end());
  for (int i = 0; i < min(N, 5); i++) {
    a.push_back(b[i]);
  }

  vector<int> v;
  for (int i = 0; i < (int)a.size(); i++) {
    for (int j = 0; j < (int)a.size(); j++) {
      if (i == j)
        continue;
      string s = to_string(a[i]) + to_string(a[j]);
      v.push_back(stoi(s));
    }
  }
  sort(v.begin(), v.end());
  cout << v[2] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a, b(N);
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }

  sort(b.begin(), b.end());
  for (int i = 0; i < min(N, 5); i++) {
    a.push_back(b[i]);
  }

  vector<int> v;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        continue;
      string s = to_string(a[i]) + to_string(a[j]);
      v.push_back(stoi(s));
    }
  }
  sort(v.begin(), v.end());
  cout << v[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  vector<string> S(n);

  vector<int> d(6);

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

    d[S[i].size()]++;
  }

  bool same = true;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (S[i].size() != S[j].size()) {
        same = false;
      }
    }
  }

  if (!same) {
    vector<int> v;

    for (int i = 0; i < S.size(); i++) {
      for (int j = 0; j < S.size(); j++) {
        if (i != j) {
          v.push_back(stoi(S[i] + S[j]));
        }
      }
    }

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

    printf("%d\\n", v[2]);
  } else {
    sort(S.begin(), S.end());

    if (n == 3) {
      printf("%s\\n", (S[1] + S[0]).c_str());
    } else {
      printf("%s\\n", (S[0] + S[3]).c_str());
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  vector<string> R(n);

  vector<int> d(6);

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

    d[R[i].size()]++;
  }

  int sum = 0, k = 0;

  for (int i = 1; i < 6; i++) {
    sum += d[i];

    if (sum >= 3) {
      k = i;
      break;
    }
  }

  vector<string> S;

  for (int i = 0; i < n; i++) {
    if (R[i].size() <= k) {
      S.push_back(R[i]);
    }
  }

  vector<int> v;

  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < S.size(); j++) {
      if (i != j) {
        v.push_back(stoi(S[i] + S[j]));
      }
    }
  }

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

  printf("%d\\n", v[2]);

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  rep(i, n) cin >> v[i];
  int t;
  vi u;
  rep(i, n) {
    rep(j, n) {
      if (i != j) {
        t = atoi((v[i] + v[j]).c_str());
        if (u.size() < 3)
          u.pb(t);
        else if (u[2] > t) {
          u[2] = t;
          sort(all(u));
        }
      }
    }
  }
  int ans = u[2];
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  rep(i, n) cin >> v[i];
  map<int, int> mp;
  int t;
  auto it = mp.begin();
  rep(i, n) {
    rep(j, n) {
      if (i != j) {
        t = atoi((v[i] + v[j]).c_str());
        it = mp.begin();
        it++;
        it++;
        it++;
        if (mp.size() > 3 && it->fi < t)
          continue;
        mp[t]++;
      }
    }
  }
  int cnt = 0, ans = 0;
  for (auto p : mp) {
    cnt += p.se;
    if (cnt >= 3) {
      ans = p.fi;
      break;
    }
  }
  cout << ans << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  priority_queue<int> que[6];
  FOR(i, 0, n) {
    string s;
    cin >> s;
    que[s.length()].push(stoi(s));
    if (que[s.length()].size() == 5)
      que[s.length()].pop();
  }
  vector<int> v;
  FOR(i, 0, 6) {
    while (!que[i].empty()) {
      v.push_back(que[i].top());
      que[i].pop();
    }
  }
  n = v.size();
  vector<int> w;
  FOR(i, 0, n) {
    FOR(j, 0, n) {
      if (i == j)
        continue;
      string s = to_string(v[i]);
      string t = to_string(v[j]);
      w.push_back(stoi(s + t));
    }
  }
  sort(w.begin(), w.end());
  cout << w[2] << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// a0とa1が先頭に来る場合だけ考えれば良い
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  FOR(i, 0, n) { cin >> a[i]; }
  sort(a, a + n);
  priority_queue<int> que;
  vector<int> v;
  FOR(i, 0, n) {
    FOR(j, 0, n) {
      if (i == j)
        continue;
      string s = to_string(a[i]);
      string t = to_string(a[j]);
      s = s + t;
      que.push(stoi(s));
      if (que.size() == 4)
        que.pop();
    }
  }
  cout << que.top() << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

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

  int n;
  cin >> n;
  vector<int> s(n);
  REP(i, n) cin >> s[i];
  vector<int> v;
  sort(ALL(s));
  REP(i, min(n, 10)) {
    REP(j, min(n, 10)) {
      if (i == j)
        continue;
      string t = to_string(s[i]) + to_string(s[j]);
      v.pb(stoi(t));
    }
  }
  sort(ALL(v));
  cout << v[2] << endl;

  return 0;
}


Error: MLE

Fixed submission:

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

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

  int n;
  cin >> n;
  string s[n];
  REP(i, n) cin >> s[i];
  vector<int> v;
  REP(i, n) {
    REP(j, n) {
      if (i != j) {
        string t = s[i] + s[j];
        v.pb(stoi(t));
      }
    }
  }
  sort(ALL(v));
  cout << v[2] << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
long long a[9];
struct P {
  string p;
};
bool operator<(P a, P b) {
  if (a.p.length() > b.p.length())
    return false;
  else if (a.p.length() < b.p.length())
    return true;
  else
    return a.p < b.p;
}
int main() {
  int n;
  while (cin >> n) {
    P b[10000];
    for (int i = 0; i < n; i++)
      cin >> b[i].p;
    sort(b, b + n);
    int f = 0, e = min(4, n);
    for (int i = 0; i < e; i++) {
      for (int j = 0; j < e; j++) {
        if (i != j) {
          a[f] = stoll(b[i].p + b[j].p);
          f++;
        }
      }
    }
    sort(a, a + f);
    cout << a[2] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
long long a[4];
int main() {
  int n;
  while (cin >> n) {
    int b[10000];
    for (int i = 0; i < n; i++)
      cin >> b[i];
    a[0] = 1000000000000;
    a[1] = 10000000000;
    a[2] = 1000000000000;
    a[3] = 10000000000;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j != i) {
          string s = to_string(b[i]) + to_string(b[j]);
          long long d = stoll(s);
          if (a[2] > d) {
            a[3] = d;
            sort(a, a + 4);
          }
        }
      }
    }
    cout << a[2] << endl;
  }
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int lll(string a) {
  int m = 0;
  for (int b = 0; b < a.size(); b++) {
    m *= 10;
    m += a[b] - 48;
  }
  return m;
}
int main() {
  vector<int> s(0);
  int a;
  cin >> a;
  vector<string> m(0);
  for (int b = 0; b < a; b++) {
    string c;
    cin >> c;
    if (a == 8000 && c[0] > 50)
      goto p;
    for (int d = 0; d < m.size(); d++) {
      s.push_back(lll(c + (m[d])));
      s.push_back(lll(m[d] + c));
    }
    m.push_back(c);
  p:;
  }
  sort(s.begin(), s.end());
  cout << s[2] << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int lll(string a) {
  int m = 0;
  for (int b = 0; b < a.size(); b++) {
    m *= 10;
    m += a[b] - 48;
  }
  return m;
}
int main() {
  vector<int> s(0);
  int a;
  cin >> a;
  vector<string> m(0);
  for (int b = 0; b < a; b++) {
    string c;
    cin >> c;
    for (int d = 0; d < m.size(); d++) {
      s.push_back(lll(c + (m[d])));
      s.push_back(lll(m[d] + c));
    }
    m.push_back(c);
  }
  sort(s.begin(), s.end());
  cout << s[2] << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int n[3], a[8000], m, l, p;
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  n[0] = 1000000000;
  n[1] = 1000000000;
  n[2] = 1000000000;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j) {
        if (a[j] < 10) {
          l = 10;
        } else if (a[j] < 100) {
          l = 100;
        } else if (a[j] < 1000) {
          l = 1000;
        } else if (a[j] < 10000) {
          l = 10000;
        } else {
          l = 100000;
        }
        p = a[i] * l + a[j];
        if (n[0] > p) {
          n[2] = n[1];
          n[1] = n[0];
          n[0] = p;
        } else if (n[1] > p) {
          n[2] = n[1];
          n[1] = p;
        } else if (n[2] > p) {
          n[2] = p;
        }
      }
    }
  }
  cout << n[2] << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int n[64000000], cnt, a[8000], m, l;
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j) {
        if (a[j] < 10) {
          l = 10;
        } else if (a[j] < 100) {
          l = 100;
        } else if (a[j] < 1000) {
          l = 1000;
        } else if (a[j] < 10000) {
          l = 10000;
        } else {
          l = 100000;
        }
        n[cnt] = a[i] * l + a[j];
        cnt++;
      }
    }
  }
  sort(n, n + cnt);
  cout << n[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cerr << *i << " ";
  cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
  return (x >= 0 && y >= 0 && x < W && y < H);
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int ton(string s) { return atoi(s.c_str()); }
string tos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}

int main() {
  int N;
  while (cin >> N && N) {
    int cnt[10010] = {};
    vector<string> a;
    REP(i, N) {
      int t;
      scanf("%d", &t);
      if (cnt[t] < 2) {
        a.push_back(tos(t));
        cnt[t]++;
      }
    }
    int ans[4] = {};
    REP(i, 3) ans[i] = 1000000009;
    REP(i, a.size()) REP(j, a.size()) if (i != j) {
      int n = ton(a[i] + a[j]);
      ans[3] = n;
      for (int i = 3; i > 0; i--) {
        if (ans[i] < ans[i - 1])
          swap(ans[i], ans[i - 1]);
      }
    }
    cout << ans[2] << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cerr << *i << " ";
  cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
  return (x >= 0 && y >= 0 && x < W && y < H);
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int ton(string s) { return atoi(s.c_str()); }
string tos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}

int main() {
  int N;
  while (cin >> N && N) {
    int cnt[10010] = {};
    vector<string> a;
    REP(i, N) {
      int t;
      scanf("%d", &t);
      if (cnt[t] < 2) {
        a.push_back(tos(t));
        cnt[t]++;
      }
    }
    vector<int> ans;
    REP(i, a.size()) REP(j, a.size()) if (i != j) {
      ans.push_back(ton(a[i] + a[j]));
    }
    sort(ans.begin(), ans.end());
    cout << ans[2] << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second

int a[10010];
vector<int> v;

int s_add(int a, int b) {
  string s = to_string(a) + to_string(b);
  int res;
  stringstream ss;
  ss << s;
  ss >> res;
  return res;
}

int main() {
  int n;
  cin >> n;
  REP(i, n) { cin >> a[i]; }
  sort(a, a + n);
  REP(i, min(4, n)) {
    REP(j, min(4, n)) {
      if (i == j)
        continue;
      v.push_back(s_add(a[i], a[j]));
    }
  }
  sort(ALL(v));
  // REP(i, v.size()){
  //	cout << v[i] << endl;
  // }
  cout << v[2] << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second

priority_queue<int> v;

int a[10010];

int changei(string s) {
  int res;
  stringstream ss;
  ss << s;
  ss >> res;
  return res;
}

int main() {
  int n;
  cin >> n;
  REP(i, n) cin >> a[i];
  REP(i, n) {
    REP(j, n) {
      if (i == j)
        continue;
      string s = to_string(a[i]) + to_string(a[j]);
      if (v.size() == 3) {
        int num = v.top();
        if (num > changei(s)) {
          v.pop();
          v.push(changei(s));
        }
      } else
        v.push(changei(s));
    }
  }
  cout << v.top() << endl;
}