Problem p04044 (C++)

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

using namespace std;

#define SZ(x) ((int)(x).size())
using namespace std;
typedef pair<int, int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define mod 1000000007
// a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod) {
  int c = a + b;
  if (c >= p)
    c -= p;
  return c;
}
inline int sub(int a, int b, int p = mod) {
  int c = a - b;
  if (c < 0)
    c += p;
  return c;
}
inline int mul(int a, int b, int p = mod) { return (a * 1ll * b) % p; }

using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
const int MX = 2e5 + 10;
const int MX2 = 1e6 + 5;

ll INF = 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;

int cnt[MX];
bool cmp(string x, string y) {
  string XY = x.append(y);
  string YX = y.append(y);
  return XY.compare(YX) > 0 ? 0 : 1;
}
vector<string> v;
int main(int argc, const char *argv[]) {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); // insert code here...
  int n, l;
  cin >> n >> l;
  REP(i, n) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end(), cmp);
  string res = "";
  for (int i = 0; i < n; ++i) {
    res += v[i];
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

#define SZ(x) ((int)(x).size())
using namespace std;
typedef pair<int, int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define mod 1000000007
// a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod) {
  int c = a + b;
  if (c >= p)
    c -= p;
  return c;
}
inline int sub(int a, int b, int p = mod) {
  int c = a - b;
  if (c < 0)
    c += p;
  return c;
}
inline int mul(int a, int b, int p = mod) { return (a * 1ll * b) % p; }

using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
const int MX = 2e5 + 10;
const int MX2 = 1e6 + 5;

ll INF = 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;

int cnt[MX];
bool cmp(string x, string y) {
  string XY = x.append(y);
  string YX = y.append(y);
  return XY.compare(YX) > 0 ? 0 : 1;
}
vector<string> v;
int main(int argc, const char *argv[]) {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); // insert code here...
  int n, l;
  cin >> n >> l;
  REP(i, n) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  string res = "";
  for (int i = 0; i < n; ++i) {
    res += v[i];
  }
  cout << res << endl;
  return 0;
}