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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>

using std::begin;
using std::end;

int concat(int m, int n) {
  int d{1};
  for (int i{n}; i > 0; i /= 10, d *= 10)
    ;

  return m * d + n;
}

int main(int, char **) {
  int n;
  std::vector<int> v;
  std::cin >> n;

  for (int i{0}; i < n; ++i) {
    int t;
    std::cin >> t;
    v.push_back(t);
  }

  std::vector<int> candidates;
  std::vector<int> rs;

  for (int i{0}; i < n / 2; ++i) {
    for (int j{0}; j < n / 2; ++j) {
      if (i != j)
        rs.push_back(concat(v[i], v[j]));
    }
  }
  std::sort(begin(rs), end(rs));
  for (int i{0}; i < 3; ++i) {
    candidates.push_back(rs[i]);
  }
  rs.clear();

  for (int i{0}; i < n / 2; ++i) {
    for (int j{n / 2}; j < n; ++j) {
      if (i != j)
        rs.push_back(concat(v[i], v[j]));
    }
  }
  std::sort(begin(rs), end(rs));
  for (int i{0}; i < 3; ++i) {
    candidates.push_back(rs[i]);
  }
  rs.clear();

  for (int i{n / 2}; i < n; ++i) {
    for (int j{0}; j < n / 2; ++j) {
      if (i != j)
        rs.push_back(concat(v[i], v[j]));
    }
  }
  std::sort(begin(rs), end(rs));
  for (int i{0}; i < 3; ++i) {
    candidates.push_back(rs[i]);
  }
  rs.clear();

  for (int i{n / 2}; i < n; ++i) {
    for (int j{n / 2}; j < n; ++j) {
      if (i != j)
        rs.push_back(concat(v[i], v[j]));
    }
  }
  std::sort(begin(rs), end(rs));
  for (int i{0}; i < 3; ++i) {
    candidates.push_back(rs[i]);
  }
  rs.clear();

  std::sort(begin(candidates), end(candidates));
  // for(int e: candidates) {
  //   std::cout << e << std::endl;
  // }
  std::cout << candidates[2] << std::endl;

  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>

using std::begin;
using std::end;

int concat(int m, int n) {
  int d{1};
  for (int i{n}; i > 0; i /= 10, d *= 10)
    ;

  return m * d + n;
}

int main(int, char **) {
  int n;
  std::vector<int> v;
  std::cin >> n;

  for (int i{0}; i < n; ++i) {
    int t;
    std::cin >> t;
    v.push_back(t);
  }

  std::vector<int> rs;
  for (int i{0}; i < n; ++i) {
    for (int j{0}; j < n; ++j) {
      if (i != j)
        rs.push_back(concat(v[i], v[j]));
    }
  }
  std::sort(begin(rs), end(rs));

  // for(int e: rs) {
  //   std::cout << e << std::endl;
  // }
  std::cout << rs[2] << std::endl;

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n;
string a, s[11];
priority_queue<pair<int, string>> que;
vector<pair<int, string>> b;
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    que.push(make_pair(a.size(), a));
    if (que.size() > 10)
      que.pop();
  }
  for (int i = 0; i < min(n, 10); i++) {
    s[i] = que.top().second;
    que.pop();
  }
  for (int i = 0; i < min(n, 10); i++) {
    for (int j = 0; j < min(n, 10); j++) {
      if (i == j)
        continue;
      b.push_back(make_pair((s[i] + s[j]).size(), s[i] + s[j]));
    }
  }
  sort(b.begin(), b.end());
  cout << b[2].second << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n;
string a[100000000];
vector<string> b;
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < min(n, 10); i++) {
    for (int j = 0; j < min(n, 10); j++) {
      if (i == j)
        continue;
      b.push_back(a[i] + a[j]);
    }
  }
  sort(b.begin(), b.end());
  cout << b[2] << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  int N;
  cin >> N;
  vector<int> ns(N);
  map<int, vector<int>> mp;
  for (int i = 0; i < N; ++i) {
    cin >> ns[i];
    mp[to_string(ns[i]).size()].push_back(ns[i]);
  }
  for (auto &m : mp) {
    sort(m.second.begin(), m.second.end());
    if (m.second.size() >= 5)
      m.second.resize(4);
  }
  ns.clear();
  for (auto &m : mp) {
    for (auto num : m.second) {
      ns.push_back(num);
    }
  }

  vector<int> anss;
  for (int i = 0; i < ns.size(); ++i) {
    for (int j = 0; j < ns.size(); ++j) {
      if (i == j)
        continue;
      string st = to_string(ns[i]) + to_string(ns[j]);
      int num = stoi(st);
      if (anss.size() == 3) {
        if (anss[2] < num)
          continue;
        else {
          anss.push_back(num);

          nth_element(anss.begin(), anss.begin() + 2, anss.end());
          if (anss.size() == 4)
            anss.pop_back();
        }
      } else {

        anss.push_back(num);
        sort(anss.begin(), anss.end());
      }
    }
  }
  cout << anss[2] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  int N;
  cin >> N;
  vector<int> ns(N);
  for (int i = 0; i < N; ++i) {
    cin >> ns[i];
  }
  vector<int> anss;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (i == j)
        continue;
      string st = to_string(ns[i]) + to_string(ns[j]);
      int num = stoi(st);
      if (anss.size() == 3) {
        if (anss[2] < num)
          continue;
        else {
          anss.push_back(num);

          nth_element(anss.begin(), anss.begin() + 2, anss.end());
          if (anss.size() == 4)
            anss.pop_back();
        }
      } else {

        anss.push_back(num);
        sort(anss.begin(), anss.end());
      }
    }
  }
  cout << anss[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;
  vector<int> vec;
  rep(i, n) {
    int a;
    cin >> a;
    vec.push_back(a);
  }
  sort(vec.begin(), vec.end());
  vector<string> ans;
  rep(i, min(n, 4)) {
    rep(j, min(n, 4)) {
      if (i == j)
        continue;
      ans.push_back(to_string(vec[i]) + to_string(vec[j]));
    }
  }
  sort(ans.begin(), ans.end());
  stable_sort(ans.begin(), ans.end(),
              [](string a, string b) { return a.size() < b.size(); });
  cout << ans[2] << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

vector<string> ans;
int main() {
  int n;
  cin >> n;
  vector<int> vec;
  rep(i, n) {
    int a;
    cin >> a;
    vec.push_back(a);
  }
  rep(i, vec.size()) {
    rep(j, vec.size()) {
      if (i == j)
        continue;
      ans.push_back(to_string(vec[i]) + to_string(vec[j]));
    }
  }
  sort(ans.begin(), ans.end());
  stable_sort(ans.begin(), ans.end(),
              [](string a, string b) { return a.length() < b.length(); });
  cout << ans[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

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

static const double eps = 1e-8;

const int tx[4] = {+0, +1, +0, -1};
const int ty[4] = {-1, +0, +1, +0};

int main() {
  int n;
  while (~scanf("%d", &n)) {
    priority_queue<int> que;
    for (int i = 0; i < n; i++) {
      int num;
      scanf("%d", &num);
      que.push(num);
      while (que.size() > 4) {
        que.pop();
      }
    }

    vector<int> cards;
    while (!que.empty()) {
      cards.push_back(que.top());
      que.pop();
    }

    vector<int> res;
    for (int i = 0; i < cards.size(); i++) {
      for (int j = 0; j < cards.size(); j++) {
        if (i == j)
          continue;
        stringstream ss;
        ss << cards[i] << cards[j];
        res.push_back(atoi(ss.str().c_str()));
      }
    }
    sort(res.begin(), res.end());
    printf("%d\\n", res[2]);
  }
}

Error: MLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

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

static const double eps = 1e-8;

const int tx[4] = {+0, +1, +0, -1};
const int ty[4] = {-1, +0, +1, +0};

int main() {
  int n;
  while (~scanf("%d", &n)) {
    priority_queue<int, vector<int>, greater<int>> que;
    for (int i = 0; i < n; i++) {
      int num;
      scanf("%d", &num);
      que.push(num);
      while (que.size() > 10000) {
        que.pop();
      }
    }

    vector<int> cards;
    while (!que.empty()) {
      cards.push_back(que.top());
      que.pop();
    }

    vector<int> res;
    for (int i = 0; i < cards.size(); i++) {
      for (int j = 0; j < cards.size(); j++) {
        if (i == j)
          continue;
        stringstream ss;
        ss << cards[i] << cards[j];
        res.push_back(atoi(ss.str().c_str()));
      }
    }
    sort(res.begin(), res.end());
    printf("%d\\n", res[2]);
  }
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int connect(int l, int r) {
  char ll[42], rr[22];
  sprintf(ll, "%d", l), sprintf(rr, "%d", r);
  strcat(ll, rr);
  return atoi(ll);
}

int main() {

  int n;
  cin >> n;
  vector<int> s, all;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    s.push_back(num);
  }

  sort(s.begin(), s.end());
  for (int i = 0; i < min(n, 15); i++) {
    for (int j = 0; j < min(n, 15); j++) {
      if (i == j)
        continue;
      all.push_back(connect(s[i], s[j]));
    }
  }
  sort(all.begin(), all.end());
  cout << all[2] << endl;
}

Error: MLE

Fixed submission:

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

int main() {
  stringstream ss;
  int n;
  cin >> n;
  int d[n];
  vector<int> fig;
  string dat[n];
  for (int i = 0; i < n; i++)
    cin >> d[i];
  sort(d, d + n);
  for (int i = 0; i < n; i++) {
    ss << d[i];
    ss >> dat[i];
    ss.clear();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      ss << dat[i] + dat[j];
      ss >> d[0];
      ss.clear();
      fig.push_back(d[0]);
    }
  }
  sort(fig.begin(), fig.end());
  cout << fig[2] << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

const int MAX = 1000;
typedef long long ll;

vector<ll> V;

ll make(ll a, ll b) {

  for (int i = 0; i <= log10(b); i++)
    a *= 10LL;

  return a + b;
}

ll solve() {
  vector<ll> ans;

  int LIM = min(MAX, (int)V.size());
  for (int i = 0; i < LIM; i++)
    for (int j = 0; j < LIM; j++)
      if (i != j)
        ans.push_back(make(V[i], V[j]));

  sort(ans.begin(), ans.end());
  return ans[2];
}

int main() {

  int n;
  cin >> n;
  while (n--) {
    int in;
    cin >> in;
    V.push_back(in);
  }
  sort(V.begin(), V.end());
  cout << solve() << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

const int MAX = 1000000;
typedef long long ll;

vector<ll> V;

ll make(ll a, ll b) {

  for (int i = 0; i <= log10(b); i++)
    a *= 10LL;

  return a + b;
}

ll solve() {
  vector<ll> ans;

  int LIM = min(MAX, (int)V.size());
  for (int i = 0; i < LIM; i++)
    for (int j = 0; j < LIM; j++)
      if (i != j)
        ans.push_back(make(V[i], V[j]));

  sort(ans.begin(), ans.end());
  return ans[2];
}

int main() {

  int n;
  cin >> n;
  while (n--) {
    int in;
    cin >> in;
    V.push_back(in);
  }
  sort(V.begin(), V.end());
  cout << solve() << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a[10001];
  vector<int> num;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      if (i == j)
        continue;
      num.push_back(stoi(to_string(a[i]) + to_string(a[j])));
    }
  }
  sort(num.begin(), num.end());
  cout << num[2] << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int insi(int a) {
  int cnt = 1;
  while (1) {
    cnt *= 10;
    a /= 10;
    if (a == 0)
      break;
  }
  return cnt;
}
int main() {
  vector<int> num;
  string str;
  int n, a[10001];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j)
        continue;
      num.push_back(a[i] * insi(a[j]) + a[j]);
    }
  }
  sort(num.begin(), num.end());
  cout << num[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

// 0584.cpp : ??????????????? ??¢????????±????????§????????¨?????????
// ?????????????????????????????????
//

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, a[10000];

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (n == 3) {
    a[3] = 10001;
  }

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

  return 0;
}

Error: MLE

Fixed submission:

// 0584.cpp : ??????????????? ??¢????????±????????§????????¨?????????
// ?????????????????????????????????
//

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, a[10000];

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

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

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

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

int main() {
  int n;
  cin >> n;
  vector<int> data;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    data.insert(lower_bound(data.begin(), data.end(), s), s);
    if (data.size() >= 10)
      data.resize(10);
  }
  vector<int> ans;
  for (int i = 0; i < data.size(); i++)
    for (int j = i + 1; j < data.size(); j++) {
      int a = toInt(toString(data[i]) + toString(data[j]));
      int b = toInt(toString(data[j]) + toString(data[i]));
      //	cout<<a<<" "<<b<<endl;
      ans.push_back(a);
      ans.push_back(b);
    }
  sort(ans.begin(), ans.end());
  //  cout<<ans[0]<<endl;
  // cout<<ans[1]<<endl;
  cout << ans[2] << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

int main() {
  int n;
  cin >> n;
  vector<int> data;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    data.insert(lower_bound(data.begin(), data.end(), s), s);
    //      if(data.size()>=10)
    //	data.resize(10);
  }
  vector<int> ans;
  for (int i = 0; i < data.size(); i++)
    for (int j = i + 1; j < data.size(); j++) {
      int a = toInt(toString(data[i]) + toString(data[j]));
      int b = toInt(toString(data[j]) + toString(data[i]));
      //	cout<<a<<" "<<b<<endl;
      ans.push_back(a);
      ans.push_back(b);
    }
  sort(ans.begin(), ans.end());
  //  cout<<ans[0]<<endl;
  // cout<<ans[1]<<endl;
  cout << ans[2] << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

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

int main() {
  int n;
  cin >> n;

  vector<int> v(n);
  rep(i, n) cin >> v[i];

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

  int a = INF, b = INF, c = INF, x;
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        continue;

      int x = v[i];
      for (int k = v[j]; k > 0; k /= 10) {
        x *= 10;
      }

      x += v[j];

      if (x <= a) {
        c = b;
        b = a;
        a = x;
      } else if (x <= b) {
        c = b;
        b = x;
      } else if (x <= c) {
        c = x;
      }
    }
  }

  cout << c << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

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

int main() {
  int n;
  cin >> n;

  vector<int> v(n);
  rep(i, n) cin >> v[i];

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

  int a = INF, b = INF, c = INF, x;
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        continue;
      stringstream ss;
      ss << v[i] << v[j];
      ss >> x;

      if (x <= a) {
        c = b;
        b = a;
        a = x;
      } else if (x <= b) {
        c = b;
        b = x;
      } else if (x <= c) {
        c = x;
      }
    }
  }

  cout << c << endl;

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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<int> vv(3, 100000000);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j != i) {
        int c = atoi((v[i] + v[j]).c_str());
        int x = max_element(vv.begin(), vv.end()) - vv.begin();
        vv[x] = min(vv[x], c);
      }
    }
  }
  cout << *max_element(vv.begin(), vv.end()) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

bool cmp(string a, string b) { return atoi(a.c_str()) < atoi(b.c_str()); }

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<string> vv;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j != i) {
        vv.push_back(v[i] + v[j]);
        if (vv.size() > 3) {
          vv.erase(max_element(vv.begin(), vv.end(), cmp));
        }
      }
    }
  }
  sort(vv.begin(), vv.end(), cmp);
  cout << vv[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() { return val; }
    bool operator!=(Iterator &itr) { return val < itr.val; }
    void operator++() { ++val; }
  };
  Iterator i, n;

public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() { return i; }
  Iterator &end() { return n; }
};

template <class T> T at(vector<T> v, int i) {
  return v[(i % (int)v.size() + v.size()) % v.size()];
}

template <class A, class B> B convert(A a) {
  stringstream ss;
  ss << a;
  B b;
  ss >> b;
  return b;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a)
    cin >> i;
  sort(a.begin(), a.end());
  int r1 = 1e9, r2 = 1e9, r3 = 1e9;
  for (int i : range(min(n, 10)))
    for (int j : range(min(n, 10)))
      if (i != j) {
        int r = convert<string, int>(convert<int, string>(a[i]) +
                                     convert<int, string>(a[j]));
        if (r <= r1) {
          r3 = r2;
          r2 = r1;
          r1 = r;
        } else if (r <= r2) {
          r3 = r2;
          r2 = r;
        } else if (r <= r3) {
          r3 = r;
        }
      }
  cout << r3 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() { return val; }
    bool operator!=(Iterator &itr) { return val < itr.val; }
    void operator++() { ++val; }
  };
  Iterator i, n;

public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() { return i; }
  Iterator &end() { return n; }
};

template <class T> T at(vector<T> v, int i) {
  return v[(i % (int)v.size() + v.size()) % v.size()];
}

template <class A, class B> B convert(A a) {
  stringstream ss;
  ss << a;
  B b;
  ss >> b;
  return b;
}

int main() {
  int n;
  cin >> n;
  assert(n < 10000);
  vector<string> a(n);
  for (string &s : a)
    cin >> s;
  int r1 = 1e9, r2 = 1e9, r3 = 1e9;
  for (int i : range(n))
    for (int j : range(n))
      if (i != j) {
        int r = convert<string, int>(a[i] + a[j]);
        if (r <= r1) {
          r3 = r2;
          r2 = r1;
          r1 = r;
        } else if (r <= r2) {
          r3 = r2;
          r2 = r;
        } else if (r <= r3) {
          r3 = r;
        }
      }
  cout << r3 << endl;
}