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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int nums[100004], numt[100004];
string s, t;
int mojis[40], mojit[40];
int main() {
  cin >> s >> t;
  int c = 1;
  for (int i = 0; i < s.size(); i++) {
    if (!mojis[s[i] - 'a']) {
      mojis[s[i] - 'a'] = c;
      c++;
    }
    nums[i] = mojis[s[i] - 'a'];
  }
  c = 1;
  for (int i = 0; i < s.size(); i++) {
    if (!mojit[t[i] - 'a']) {
      mojit[t[i] - 'a'] = c;
      c++;
    }
    numt[i] = mojit[t[i] - 'a'];
  }
  for (int i = 0; i < s.size(); i++) {
    if (nums[i] != numt[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int nums[200004], numt[200004];
string s, t;
int mojis[40], mojit[40];
int main() {
  cin >> s >> t;
  int c = 1;
  for (int i = 0; i < s.size(); i++) {
    if (!mojis[s[i] - 'a']) {
      mojis[s[i] - 'a'] = c;
      c++;
    }
    nums[i] = mojis[s[i] - 'a'];
  }
  c = 1;
  for (int i = 0; i < s.size(); i++) {
    if (!mojit[t[i] - 'a']) {
      mojit[t[i] - 'a'] = c;
      c++;
    }
    numt[i] = mojit[t[i] - 'a'];
  }
  for (int i = 0; i < s.size(); i++) {
    if (nums[i] != numt[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int L[30][30] = {0};
  char *S1 = (char *)calloc(3 * 100000, sizeof(char));
  char *S2 = (char *)calloc(3 * 100000, sizeof(char));
  scanf("%s %s", S1, S2);
  for (int i = 0; i < strlen(S1); i++) {
    L[S1[i] - 'a'][S2[i] - 'a'] = 1;
    // L[S2[i]-'a'][S1[i]-'a']=1;
  }

  for (int i = 0; i < 30; i++) {
    int cnt = 0;
    for (int j = 0; j < 30; j++) {
      if (L[i][j] == 1) {
        cnt++;
      }
      if (cnt > 1) {
        printf("No\n");
        return 0;
      }
    }
  }
  for (int i = 0; i < 30; i++) {
    int cnt = 0;
    for (int j = 0; j < 30; j++) {
      if (L[j][i] == 1) {
        cnt++;
      }
      if (cnt > 1) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}


Fixed submission:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int L[30][30] = {0};
  char *S1 = (char *)calloc(3 * 100000, sizeof(char));
  char *S2 = (char *)calloc(3 * 100000, sizeof(char));
  scanf("%s %s", S1, S2);
  int n = strlen(S1);
  for (int i = 0; i < n; i++) {
    L[S1[i] - 'a'][S2[i] - 'a'] = 1;
    // L[S2[i]-'a'][S1[i]-'a']=1;
  }

  for (int i = 0; i < 30; i++) {
    int cnt = 0;
    for (int j = 0; j < 30; j++) {
      if (L[i][j] == 1) {
        cnt++;
      }
      if (cnt > 1) {
        printf("No\n");
        return 0;
      }
    }
  }
  for (int i = 0; i < 30; i++) {
    int cnt = 0;
    for (int j = 0; j < 30; j++) {
      if (L[j][i] == 1) {
        cnt++;
      }
      if (cnt > 1) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}
Problem p03252 (C++)

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

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

#define For(i, a, b) for (int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for (typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int c1[26], c2[26];

int main() {
  string s, t;
  cin >> s >> t;
  int l = s.size();
  Rep(i, l) {
    int k = s[i] - 'a';
    c1[k] += 1;
    k = t[i] - 'a';
    c2[k] += 1;
  }
  sort(c1, c1 + 26);
  sort(c2, c2 + 26);
  bool flag = true;
  Rep(i, l) {
    if (c1[i] == c2[i]) {
      continue;
    } else {
      flag = false;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

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

#define For(i, a, b) for (int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for (typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int c1[26], c2[26];

int main() {
  string s, t;
  cin >> s >> t;
  int l = s.size();
  Rep(i, l) {
    int k = s[i] - 'a';
    c1[k] += 1;
    k = t[i] - 'a';
    c2[k] += 1;
  }
  sort(c1, c1 + 26);
  sort(c2, c2 + 26);
  bool flag = true;
  Rep(i, 26) {
    if (c1[i] == c2[i]) {
      continue;
    } else {
      flag = false;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03252 (C++)

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  string begin(26, -1);
  string end(26, -1);

  bool flag = true;

  for (int i = 0; i < S.size(); i++) {
    int a = S[i] - 'a';
    int b = T[i] - 'a';

    if (begin[i] != -1 || end[i] != -1) {
      if (begin[a] != b || end[b] != a) {
        flag = false;
        break;
      }
    }

    begin[a] = b;
    end[b] = a;
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  string begin(26, -1);
  string end(26, -1);

  bool flag = true;

  for (int i = 0; i < S.size(); i++) {
    int a = S[i] - 'a';
    int b = T[i] - 'a';

    if (begin[a] != -1 || end[b] != -1) {
      if (begin[a] != b || end[b] != a) {
        flag = false;
        break;
      }
    }

    begin[a] = b;
    end[b] = a;
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03252 (C++)

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll, ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i, m, n) for (ll(i) = (m), (i_len) = (n); (i) < (i_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x)                                                                \
  ASC((x));                                                                    \
  REV((x))
#define pb push_back
#define eb emplace_back

int main() {
  string S, T;
  cin >> S >> T;

  vector<set<char>> A(26), B(26);
  REP(i, 0, SZ(S)) {
    A[S[i] - 'a'].insert(T[i]);
    B[T[i] - 'a'].insert(S[i]);
  }
  bool f = true;
  REP(i, 0, SZ(S)) {
    if (SZ(A[i]) > 1 || SZ(B[i]) > 1)
      f = false;
  }
  if (f)
    PR("Yes");
  else
    PR("No");

  return 0;
}

/*



*/

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll, ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i, m, n) for (ll(i) = (m), (i_len) = (n); (i) < (i_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x)                                                                \
  ASC((x));                                                                    \
  REV((x))
#define pb push_back
#define eb emplace_back

int main() {
  string S, T;
  cin >> S >> T;

  vector<set<char>> A(26), B(26);
  REP(i, 0, SZ(S)) {
    A[S[i] - 'a'].insert(T[i]);
    B[T[i] - 'a'].insert(S[i]);
  }
  bool f = true;
  REP(i, 0, 26) {
    if (SZ(A[i]) > 1 || SZ(B[i]) > 1)
      f = false;
  }
  if (f)
    PR("Yes");
  else
    PR("No");

  return 0;
}

/*



*/
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int N, K;
string S, T;

int a[110] = {};
int b[110] = {};
int c[110] = {};
int d[110] = {};

bool last;

int main() {
  cin >> S >> T;
  int N = S.size();

  for (int i = 0; i < N; i++) {
    a[S[i] - 'a']++;
    b[T[i] - 'a']++;
  }
  // 入れ終わる

  // a[i]は0がaでそこからなんこあるか
  for (int i = 0; i < 26; i++) {
    c[a[i]]++;
    d[b[i]]++;
  }

  for (int i = 0; i < N; i++) {
    if (c[i] != d[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int N, K;
string S, T;

int a[110] = {};
int b[110] = {};
int c[200010] = {};
int d[200010] = {};

bool last;

int main() {
  cin >> S >> T;
  int N = S.size();

  for (int i = 0; i < N; i++) {
    a[S[i] - 'a']++;
    b[T[i] - 'a']++;
  }
  // 入れ終わる

  // a[i]は0がaでそこからなんこあるか
  for (int i = 0; i < 26; i++) {
    c[a[i]]++;
    d[b[i]]++;
  }

  for (int i = 0; i < N; i++) {
    if (c[i] != d[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}
Problem p03252 (C++)

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

int main() {
  string S, T;
  cin >> S >> T;
  int size = S.size();

  for (int i = 0; i < size; i++) {
    if (S[i] != T[i]) {
      char cs = S[i], ct = T[i];
      for (int j = 0; j < size; j++) {
        if (S[j] == cs)
          S[j] = ct;
        else if (S[j] == ct)
          S[j] = cs;
      }
    }
  }

  if (S == T)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int size = S.size();

  vector<int> ss = {1}, tt = {1};
  for (int i = 1; i < size; i++) {
    if (S.at(i - 1) == S.at(i))
      ss.back()++;
    else
      ss.push_back(1);
    if (T.at(i - 1) == T.at(i))
      tt.back()++;
    else
      tt.push_back(1);
  }
  if (ss != tt) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < size; i++) {
    if (S[i] != T[i]) {
      char cs = S[i], ct = T[i];
      for (int j = 0; j < size; j++) {
        if (S[j] == cs)
          S[j] = ct;
        else if (S[j] == ct)
          S[j] = cs;
      }
    }
  }

  if (S == T)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <assert.h>
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int size = s.length();
  for (int i = 0; i < size; i++)
    if (s[i] != t[i]) {
      char ts = s[i], tt = t[i];
      for (int i = 0; i < size; i++)
        if (s[i] == ts)
          s[i] = tt;
        else if (s[i] == tt)
          s[i] = ts;
    }
  if (s == t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  bool ok = true;
  map<char, char> st, tt;
  int size = s.size();
  for (int i = 0; i < size; i++) {
    if (0 < st.count(s[i]) && st[s[i]] != t[i])
      ok = false;
    if (0 < tt.count(t[i]) && tt[t[i]] != s[i])
      ok = false;
    st[s[i]] = t[i];
    tt[t[i]] = s[i];
  }
  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}
Problem p03252 (Python)

Buggy submission (status: Time Limit Exceeded):
S = list(input())
T = list(input())
S2, T2 = [], []
for i in S:
    S2.append(S.count(i))
for i in T:
    T2.append(T.count(i))
if S2 != T2:
    print("No")
else:
    print("Yes")


Fixed submission:
S = list(input())
T = list(input())
S2, T2 = [], []
St, Tt = [], []
for i in range(26):
    s = chr(ord("a") + i)
    St.append(S.count(s))
    Tt.append(T.count(s))
for i in range(len(S)):
    S2.append(St[ord(S[i]) - ord("a")])
    T2.append(Tt[ord(T[i]) - ord("a")])
if S2 != T2:
    print("No")
else:
    print("Yes")
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
char a[100000 + 5], b[100000 + 5];
int map1[30], map2[30];
int main() {
  scanf("%s", a);
  scanf("%s", b);
  int n = strlen(a);
  for (int i = 0; i < n; i++)
    if (map1[a[i] - 'a' + 1] == 0 && map2[b[i] - 'a' + 1] == 0)
      map1[a[i] - 'a' + 1] = b[i] - 'a' + 1,
                        map2[b[i] - 'a' + 1] = a[i] - 'a' + 1;
    else {
      if ((map1[a[i] - 'a' + 1] != b[i] - 'a' + 1) ||
          (map2[b[i] - 'a' + 1] != a[i] - 'a' + 1)) {
        printf("No\n");
        return 0;
      }
    }
  printf("Yes\n");
}


Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
char a[200000 + 5], b[200000 + 5];
int map1[30], map2[30];
int main() {
  scanf("%s", a);
  scanf("%s", b);
  int n = strlen(a);
  for (int i = 0; i < n; i++)
    if (map1[a[i] - 'a' + 1] == 0 && map2[b[i] - 'a' + 1] == 0)
      map1[a[i] - 'a' + 1] = b[i] - 'a' + 1,
                        map2[b[i] - 'a' + 1] = a[i] - 'a' + 1;
    else {
      if ((map1[a[i] - 'a' + 1] != b[i] - 'a' + 1) ||
          (map2[b[i] - 'a' + 1] != a[i] - 'a' + 1)) {
        printf("No\n");
        return 0;
      }
    }
  printf("Yes\n");
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9 + 7
#define LINF (long long)4e18

int main() {
  string S, T;
  cin >> S >> T;
  int N = (int)S.size();
  vector<pair<char, char>> ST, TS;
  rep(i, N) {
    ST[i].first = S[i];
    ST[i].second = T[i];
    TS[i].first = T[i];
    TS[i].second = S[i];
  }
  sort(ST.begin(), ST.end());
  sort(TS.begin(), TS.end());
  bool ok = true;
  rep(i, N - 1) {
    if (ST[i].first == ST[i + 1].first) {
      if (ST[i].second != ST[i + 1].second)
        ok = false;
    }
    if (TS[i].first == TS[i + 1].first) {
      if (TS[i].second != TS[i + 1].second)
        ok = false;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9 + 7
#define LINF (long long)4e18

int main() {
  string S, T;
  cin >> S >> T;
  int N = (int)S.size();
  vector<pair<char, char>> ST(N), TS(N);
  rep(i, N) {
    ST[i].first = S[i];
    ST[i].second = T[i];
    TS[i].first = T[i];
    TS[i].second = S[i];
  }
  sort(ST.begin(), ST.end());
  sort(TS.begin(), TS.end());
  bool ok = true;
  rep(i, N - 1) {
    if (ST[i].first == ST[i + 1].first) {
      if (ST[i].second != ST[i + 1].second)
        ok = false;
    }
    if (TS[i].first == TS[i + 1].first) {
      if (TS[i].second != TS[i + 1].second)
        ok = false;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string str1, str2;
  cin >> str1 >> str2;
  bool flag = true;
  for (int i = 0; i < str1.size(); ++i) {
    // str1[0]
    for (int ii = i; ii < str1.size(); ++ii) {
      if (str1[i] == str1[ii]) {
        if (str2[i] != str2[ii]) {
          flag = false;
        }
      }
      if (str2[i] == str2[ii]) {
        if (str1[i] != str1[ii]) {
          flag = false;
        }
      }
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string str1, str2;
  cin >> str1 >> str2;
  bool flag = true;
  vector<vector<int>> c1, c2;
  for (char a = 'a'; a <= 'z'; ++a) {
    vector<int> tmp1, tmp2;
    std::string::iterator itr = str1.begin();
    while (true) {
      itr = find(itr + 1, str1.end(), a);
      if (itr == str1.end())
        break;
      tmp1.push_back(distance(str1.begin(), itr));
    }
    itr = str2.begin();
    while (true) {
      itr = find(itr + 1, str2.end(), a);
      if (itr == str2.end())
        break;
      tmp2.push_back(distance(str2.begin(), itr));
    }
    c1.push_back(tmp1);
    c2.push_back(tmp2);
  }
  for (int i = 0; i < c1.size(); ++i) {
    if (find(c1.begin(), c1.end(), c2[i]) == c1.end()) {
      flag = false;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define rep(i, s, n) for (int i = s; i < n; i++)
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  vector<int> s_count(s.size(), 0);
  vector<int> t_count(t.size(), 0);
  rep(i, 0, s.size()) {
    s_count[s[i] - 'a']++;
    t_count[t[i] - 'a']++;
  }
  sort(s_count.begin(), s_count.end());
  sort(t_count.begin(), t_count.end());
  rep(i, 0, s_count.size()) {
    if (s_count[i] == t_count[i]) {

    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define rep(i, s, n) for (int i = s; i < n; i++)
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  vector<int> s_count(26, 0);
  vector<int> t_count(26, 0);
  rep(i, 0, s.size()) {
    s_count[s[i] - 'a']++;
    t_count[t[i] - 'a']++;
  }
  sort(s_count.begin(), s_count.end());
  sort(t_count.begin(), t_count.end());
  rep(i, 0, s_count.size()) {
    if (s_count[i] == t_count[i]) {

    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string get_format(string s) {
  vector<char> v;
  string f;

  for (int i = 0; i < s.size(); i++) {
    int j;
    for (j = 0; j < v.size(); j++) {
      if (s[i] == v[j]) {
        // 大文字で表す
        f.push_back('A' + j);
      }
    }
    if (j == v.size()) {
      v.push_back(s[i]);
      f.push_back('A' + j);
    }
  }
  return f;
}

int main() {

  string s, t;

  cin >> s >> t;

  string sf = get_format(s);
  string tf = get_format(t);

  if (sf == tf)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}


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

using namespace std;

string get_format(string s) {
  vector<char> v;
  string f;

  for (int i = 0; i < s.size(); i++) {
    int j;
    for (j = 0; j < v.size(); j++) {
      if (s[i] == v[j]) {
        // 大文字で表す
        f.push_back('A' + j);
        break;
      }
    }
    if (j == v.size()) {
      v.push_back(s[i]);
      f.push_back('A' + j);
    }
  }
  return f;
}

int main() {

  string s, t;

  cin >> s >> t;

  string sf = get_format(s);
  string tf = get_format(t);

  if (sf == tf)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  vector<bool> used(s.size(), false);
  for (int i = 0; i < t.size(); i++) {
    if (!used[i]) {
      for (int j = i + 1; j < t.size(); j++) {
        if (s[i] == s[j] && t[i] == t[j])
          used[i] = true;
        else if ((s[i] == s[j] && t[i] != t[j]) ||
                 (s[i] != s[j] && t[i] == t[j])) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  vector<bool> used(s.size(), false);
  for (int i = 0; i < t.size(); i++) {
    if (!used[i]) {
      for (int j = i + 1; j < t.size(); j++) {
        if (s[i] == s[j] && t[i] == t[j])
          used[j] = true;
        else if ((s[i] == s[j] && t[i] != t[j]) ||
                 (s[i] != s[j] && t[i] == t[j])) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes\n";
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s, t;
  cin >> s >> t;
  int n = s.size();
  vector<int> cnt1(26), cnt2(26);
  rep(i, n) {
    cnt1.at(s.at(i) - 'a')++;
    cnt2.at(t.at(i) - 'a')++;
  }

  rep(i, n) {
    if (cnt1.at(s.at(i)) != cnt2.at(t.at(i))) {
      cout << "No" << endl;
      return 0;
    }
  }

  sort(cnt1.begin(), cnt1.end());
  sort(cnt2.begin(), cnt2.end());

  if (cnt1 == cnt2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s, t;
  cin >> s >> t;
  int n = s.size();
  vector<int> cnt1(26), cnt2(26);
  rep(i, n) {
    cnt1.at(s.at(i) - 'a')++;
    cnt2.at(t.at(i) - 'a')++;
  }

  rep(i, n) {
    if (cnt1.at(s.at(i) - 'a') != cnt2.at(t.at(i) - 'a')) {
      cout << "No" << endl;
      return 0;
    }
  }

  sort(cnt1.begin(), cnt1.end());
  sort(cnt2.begin(), cnt2.end());

  if (cnt1 == cnt2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
#include <string>

int main() {
  std::string S, T;
  std::map<char, char> m, mr;
  std::cin >> S >> T;

  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == T[i])
      continue;
    auto s = S[i];
    auto t = T[i];
    for (auto it = S.begin(), end = S.end(); it != end; ++it) {
      if (*it == s)
        *it = t;
      else if (*it == t)
        *it = s;
    }
  }
  if (S == T)
    std::cout << "Yes\n";
  else
    std::cout << "No\n";
}

Fixed submission:
#include <iostream>
#include <map>
#include <string>

int main() {
  std::string S, T;
  std::map<char, char> m, mr;
  std::cin >> S >> T;

  for (int i = 0; i < T.size(); ++i) {
    auto t = T[i];
    auto s = S[i];
    auto it = m.find(t);
    if (it != m.end() && it->second != s) {
      std::cout << "No\n";
      exit(0);
    }
    it = mr.find(s);
    if (it != mr.end() && it->second != t) {
      std::cout << "No\n";
      exit(0);
    }
    m[t] = s;
    mr[s] = t;
  }
  S.clear();
  T.clear();
  for (auto it = m.begin(), end = m.end(); it != end; ++it) {
    S.append(1, it->first);
    T.append(1, it->second);
  }

  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == T[i])
      continue;
    auto s = S[i];
    auto t = T[i];
    for (auto it = S.begin(), end = S.end(); it != end; ++it) {
      if (*it == s)
        *it = t;
      else if (*it == t)
        *it = s;
    }
  }
  if (S == T)
    std::cout << "Yes\n";
  else
    std::cout << "No\n";
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

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

vector<int> bitSearch(int bit, int n) {
  vector<int> S;
  rep(i, n) if (bit & (1 << i)) S.push_back(i);
  return S;
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<vector<int>> ss(26);
  vector<vector<int>> tt(26);
  int n = s.size();
  rep(i, n) {
    ss[s[i] - 'a'].push_back(i);
    tt[t[i] - 'a'].push_back(i);
  }
  bool f = true;
  rep(i, n) {
    if (ss[s[i] - 'a'] != tt[t[i] - 'a'])
      f = false;
  }
  cout << (f ? "Yes" : "No");
}


Fixed submission:
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

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

vector<int> bitSearch(int bit, int n) {
  vector<int> S;
  rep(i, n) if (bit & (1 << i)) S.push_back(i);
  return S;
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<vector<int>> ss(26);
  vector<vector<int>> tt(26);
  int n = s.size();
  rep(i, n) {
    ss[s[i] - 'a'].push_back(i);
    tt[t[i] - 'a'].push_back(i);
  }
  bool f = true;
  rep(i, n) {
    if (ss[s[i] - 'a'].size() != tt[t[i] - 'a'].size())
      f = false;
  }
  cout << (f ? "Yes" : "No");
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-9-23 21:07:54
 * Powered by Visual Studio Code
 */

#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
#include <complex>
#include <functional>
#include <iomanip> // << fixed << setprecision(xxx)
#include <iostream>
#include <map> // if (M.find(key) != M.end()) { }
#include <queue>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <set>
#include <stack>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <tuple>
#include <vector>
// start = std::chrono::system_clock::now();
// double elapsed =
// std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

set<int> to[26];
set<int> from[26];
string S, T;

int main() {
  cin >> S >> T;
  int N = S.size();
  for (auto i = 0; i < N; i++) {
    int x = S[i] - 'a';
    int y = T[i] - 'a';
    to[x].insert(y);
    from[y].insert(x);
  }
  for (auto i = 0; i < N; i++) {
    if (to[i].size() > 1 || from[i].size() > 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-9-23 21:07:54
 * Powered by Visual Studio Code
 */

#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
#include <complex>
#include <functional>
#include <iomanip> // << fixed << setprecision(xxx)
#include <iostream>
#include <map> // if (M.find(key) != M.end()) { }
#include <queue>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <set>
#include <stack>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <tuple>
#include <vector>
// start = std::chrono::system_clock::now();
// double elapsed =
// std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

set<int> to[26];
set<int> from[26];
string S, T;

int main() {
  cin >> S >> T;
  int N = S.size();
  for (auto i = 0; i < N; i++) {
    int x = S[i] - 'a';
    int y = T[i] - 'a';
    to[x].insert(y);
    from[y].insert(x);
  }
  for (auto i = 0; i < 26; i++) {
    if (to[i].size() > 1 || from[i].size() > 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;

int main() {
  string s, t;
  cin >> s >> t;
  vb used(s.size(), false);
  for (int i = 0; i < t.size(); i++) {
    if (!used[i]) {
      for (int j = 0; j < t.size(); j++) {
        if (s[j] == s[i] && t[j] == t[i])
          used[i] = true;
        if (s[j] == s[i] && t[j] != t[i] || s[j] != s[i] && t[j] == t[i]) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;

int main() {
  string s, t;
  cin >> s >> t;
  vb used(s.size(), false);
  for (int i = 0; i < t.size(); i++) {
    if (!used[i]) {
      for (int j = 0; j < t.size(); j++) {
        if (s[j] == s[i] && t[j] == t[i])
          used[j] = true;
        if (s[j] == s[i] && t[j] != t[i] || s[j] != s[i] && t[j] == t[i]) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  string s, t;
  cin >> s >> t;
  int a = 1;
  map<char, int> mps, mpt;
  int sx[200] = {}, tx[200] = {};
  for (int i = 0; i < (int)s.size(); i++) {
    bool ex = false;
    for (auto itr = mps.begin(); itr != mps.end(); itr++) {
      if (itr->first == s[i])
        ex = true;
    }
    if (ex)
      sx[i] = mps[s[i]];
    else {
      sx[i] = a;
      mps[s[i]] = a;
      a++;
    }
  }
  a = 1;
  for (int i = 0; i < (int)t.size(); i++) {
    bool ex = false;
    for (auto itr = mpt.begin(); itr != mpt.end(); itr++) {
      if (itr->first == t[i])
        ex = true;
    }
    if (ex)
      tx[i] = mpt[t[i]];
    else {
      tx[i] = a;
      mpt[t[i]] = a;
      a++;
    }
  }
  bool res = true;
  for (int i = 0; i < (int)s.size(); i++) {
    // cout << sx[i] << " " << tx[i] << endl;
    if (sx[i] != tx[i])
      res = false;
  }
  dump(res ? "Yes" : "No");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  string s, t;
  cin >> s >> t;
  int a = 1;
  map<char, int> mps, mpt;
  int sx[200005] = {}, tx[200005] = {};
  for (int i = 0; i < (int)s.size(); i++) {
    bool ex = false;
    for (auto itr = mps.begin(); itr != mps.end(); itr++) {
      if (itr->first == s[i])
        ex = true;
    }
    if (ex)
      sx[i] = mps[s[i]];
    else {
      sx[i] = a;
      mps[s[i]] = a;
      a++;
    }
  }
  a = 1;
  for (int i = 0; i < (int)t.size(); i++) {
    bool ex = false;
    for (auto itr = mpt.begin(); itr != mpt.end(); itr++) {
      if (itr->first == t[i])
        ex = true;
    }
    if (ex)
      tx[i] = mpt[t[i]];
    else {
      tx[i] = a;
      mpt[t[i]] = a;
      a++;
    }
  }
  bool res = true;
  for (int i = 0; i < (int)s.size(); i++) {
    // cout << sx[i] << " " << tx[i] << endl;
    if (sx[i] != tx[i])
      res = false;
  }
  dump(res ? "Yes" : "No");
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int a[1 << 17], b[1 << 17], l = s.size(), aa[30], bb[30], c = 0, d = 0;
  for (int i = 0; i < 28; i++)
    aa[i] = bb[i] = -1;
  for (int i = 0; i < l; i++) {
    if (aa[s[i] - 97] < 0)
      a[i] = ++c, aa[s[i] - 97] = i;
    else
      a[i] = a[aa[s[i] - 97]];
    if (bb[t[i] - 97] < 0)
      b[i] = ++d, bb[t[i] - 97] = i;
    else
      b[i] = b[bb[t[i] - 97]];
  }
  for (int i = 0; i < l; i++) {
    if (a[i] != b[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int a[1 << 18], b[1 << 18], l = s.size(), aa[30], bb[30], c = 0, d = 0;
  for (int i = 0; i < 28; i++)
    aa[i] = bb[i] = -1;
  for (int i = 0; i < l; i++) {
    if (aa[s[i] - 97] < 0)
      a[i] = ++c, aa[s[i] - 97] = i;
    else
      a[i] = a[aa[s[i] - 97]];
    if (bb[t[i] - 97] < 0)
      b[i] = ++d, bb[t[i] - 97] = i;
    else
      b[i] = b[bb[t[i] - 97]];
  }
  for (int i = 0; i < l; i++) {
    if (a[i] != b[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>

using namespace std;

char s[100001] = {0};
char sout[100001] = {0};
char t[100001] = {0};
char tout[100001] = {0};

void normalize(char *str, char *strout) {
  char d[300] = {0};
  char current = 'a';
  for (int i = 0; str[i] != '\0'; i++) {
    if (d[str[i]] == 0) {
      d[str[i]] = current;
      current++;
    }
    strout[i] = d[str[i]];
  }
}

int main() {
  scanf("%s\n", s);
  scanf("%s\n", t);
  normalize(s, sout);
  normalize(t, tout);
  // printf("%s\n", s);
  // printf("%s\n", t);
  // printf("%s\n", sout);
  // printf("%s\n", tout);
  if (strcmp(sout, tout) == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>

using namespace std;

char s[1000001] = {0};
char sout[1000001] = {0};
char t[1000001] = {0};
char tout[1000001] = {0};

void normalize(char *str, char *strout) {
  char d[300] = {0};
  char current = 'a';
  for (int i = 0; str[i] != '\0'; i++) {
    if (d[str[i]] == 0) {
      d[str[i]] = current;
      current++;
    }
    strout[i] = d[str[i]];
  }
}

int main() {
  scanf("%s\n", s);
  scanf("%s\n", t);
  normalize(s, sout);
  normalize(t, tout);
  // printf("%s\n", s);
  // printf("%s\n", t);
  // printf("%s\n", sout);
  // printf("%s\n", tout);
  if (strcmp(sout, tout) == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}
Problem p03252 (Python)

Buggy submission (status: Time Limit Exceeded):
S = input()
T = input()

# 例abcdefg...のように文字列が1対1の矢印関係の場合は、
# どのような場合でも置き換えできる。問題は同じ文字が複数現れる場合

# S上に同じ文字sのある場所には
# T上にも同じ文字tがなくてはならない
# つまり、同じ値になっているインデックスの集合を取れば
# 全部同じになっているはず

# 文字種ごとにインデックスの集合を求める
ns = len(S)
indexS = {}
for i in range(ns):
    s = S[i]
    if s in indexS:
        indexS[s].append(i)
    else:
        indexS[s] = [i]
indexT = {}
for i in range(ns):
    t = T[i]
    if t in indexT:
        indexT[t].append(i)
    else:
        indexT[t] = [i]
# 先頭の文字から、インデックスの集合が等しいかチェック
for s, t in zip(S, T):
    i_s = indexS[s]
    i_t = indexT[t]
    if i_s != i_t:
        print("No")
        break
else:
    print("Yes")


Fixed submission:
S = input()
T = input()

# 例abcdefg...のように文字列が1対1の矢印関係の場合は、
# どのような場合でも置き換えできる。問題は同じ文字が複数現れる場合

# S上に同じ文字sのある場所には
# T上にも同じ文字tがなくてはならない
# つまり、同じ値になっているインデックスの集合を取れば
# 全部同じになっているはず

# 文字種ごとにインデックスの集合を求める
ns = len(S)
indexS = {}
for i in range(ns):
    s = S[i]
    if s in indexS:
        indexS[s].append(i)
    else:
        indexS[s] = [i]
indexT = {}
for i in range(ns):
    t = T[i]
    if t in indexT:
        indexT[t].append(i)
    else:
        indexT[t] = [i]
# 先頭の文字から、インデックスの集合が等しいかチェック
for i in range(ns):
    s = S[i]
    t = T[i]
    i_s = len(indexS[s])
    i_t = len(indexT[t])
    if i_s != i_t:
        print("No")
        break
else:
    print("Yes")
Problem p03252 (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 REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP0(i, n) for (int i = n - 1; i >= 0; --i)
#define RREP1(i, n) for (int i = n; i >= 1; --i)
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define FILL(c, v) fill((c).begin(), (c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define CLR(a) memset((a), 0, sizeof(a))

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();
}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e9;
const LL LLINF = 1e18;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve() {
  vector<int> S_histo(256);
  vector<int> T_histo(256);
  string S, T;
  cin >> S >> T;

  REP0(i, S.length()) {
    S_histo[(int)(unsigned char)S[i]]++;
    T_histo[(int)(unsigned char)T[i]]++;
  }

  SORT(S_histo);
  REVERSE(S_histo);
  SORT(T_histo);
  REVERSE(T_histo);

  bool possible = true;

  REP0(i, S.length()) if (S_histo[i] != T_histo[i]) possible = false;

  cout << (possible ? "Yes" : "No") << endl;
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(10);
  solve();
  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP0(i, n) for (int i = n - 1; i >= 0; --i)
#define RREP1(i, n) for (int i = n; i >= 1; --i)
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define FILL(c, v) fill((c).begin(), (c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define CLR(a) memset((a), 0, sizeof(a))

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();
}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e9;
const LL LLINF = 1e18;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve() {
  vector<int> S_histo(256);
  vector<int> T_histo(256);
  string S, T;
  cin >> S >> T;

  REP0(i, S.length()) {
    S_histo[(int)(unsigned char)S[i]]++;
    T_histo[(int)(unsigned char)T[i]]++;
  }

  SORT(S_histo);
  REVERSE(S_histo);
  SORT(T_histo);
  REVERSE(T_histo);

  bool possible = true;

  REP0(i, 256) if (S_histo[i] != T_histo[i]) possible = false;

  cout << (possible ? "Yes" : "No") << endl;
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(10);
  solve();
  return 0;
}
Problem p03253 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
typedef long long ll;
#define mod 1000000007

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n != 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n = n >> 1;
  }
  return res;
}

ll mod_fact(ll x) {
  ll res = 1;
  for (ll i = x; i > 0; i--)
    res *= i, res %= mod;
  return res;
}

ll nCr(ll n, ll r) {
  ll nume = mod_fact(n);
  ll deno = mod_fact(r) * mod_fact(n - r) % mod;
  return nume * mod_pow(deno, mod - 2) % mod;
}

int main() {
  int N, M;
  cin >> N >> M;
  ll ans = 1;
  for (int i = 2; i * i <= M; i++) {
    ll cnt = 0;
    while (M % i == 0) {
      M /= i;
      cnt++;
    }
    ans = ans * nCr(N + cnt - 1, cnt) % mod;
  }
  if (M != 1)
    ans = ans * N % mod;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
typedef long long ll;
#define mod 1000000007

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n != 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n = n >> 1;
  }
  return res;
}

ll mod_fact(ll x) {
  ll res = 1;
  for (ll i = x; i > 0; i--)
    res *= i, res %= mod;
  return res;
}

ll nCr(ll n, ll r) {
  ll nume = mod_fact(n);
  ll deno = mod_fact(r) * mod_fact(n - r) % mod;
  return nume * mod_pow(deno, mod - 2) % mod;
}

int main() {
  int N, M;
  cin >> N >> M;
  ll ans = 1;
  for (int i = 2; i * i <= M; i++) {
    ll cnt = 0;
    while (M % i == 0) {
      M /= i;
      cnt++;
    }
    if (cnt)
      ans = ans * nCr(N + cnt - 1, cnt) % mod;
  }
  if (M != 1)
    ans = ans * N % mod;
  cout << ans << endl;
  return 0;
}
Problem p03253 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

const int MOD = static_cast<int>(1e9 + 7);
const int MAXARRAY = 10;
const long long MULTILIMIT = MOD;

int Combination(int n, int k) {
  int i, j, index = 1;
  long long comb[MAXARRAY] = {1};

  for (i = 0; i < k; i++) {
    for (j = 0; j < index; j++)
      comb[j] *= n - i;

    for (j = 0; j < index; j++)
      if (comb[j] >= MULTILIMIT) {
        comb[j + 1] += comb[j] / MOD;
        comb[j] %= MOD;
      }

    if (comb[j])
      index++;
  }

  for (i = 2; i <= k; i++) {
    for (j = index - 1; j > 0; j--) {
      comb[j - 1] += (comb[j] % i) * MOD;
      comb[j] /= i;
    }
    comb[j] /= i;
  }

  return static_cast<int>(comb[0] % MOD);
}

int main() {
  int N, M, i, j, comb, count = 0, factor = 3, factnum[30] = {0};
  long long ans = 1;
  std::scanf("%d%d", &N, &M);

  while (!(M & 1))
    count++, M >>= 1;
  factnum[count]++;

  while (M != 1) {
    count = 0;
    while (!(M % factor))
      count++, M /= factor;
    factnum[count]++, factor += 2;
  }

  for (i = 1; i < 30; i++) {
    if (factnum[i]) {
      comb = Combination(i + N - 1, i);
      for (j = 0; j < factnum[i]; j++) {
        ans *= comb;
        ans %= MOD;
      }
    }
  }

  std::printf("%d\n", static_cast<int>(ans));

  return 0;
}

Fixed submission:
#include <cstdio>

const int MOD = static_cast<int>(1e9 + 7);
const int MAXARRAY = 100;
const long long MULTILIMIT = MOD;

int Combination(int n, int k) {
  int i, j, index = 1;
  long long comb[MAXARRAY] = {1};

  for (i = 0; i < k; i++) {
    for (j = 0; j < index; j++)
      comb[j] *= n - i;

    for (j = 0; j < index; j++)
      if (comb[j] >= MULTILIMIT) {
        comb[j + 1] += comb[j] / MOD;
        comb[j] %= MOD;
      }

    if (comb[j])
      index++;
  }

  for (i = 2; i <= k; i++) {
    for (j = index - 1; j > 0; j--) {
      comb[j - 1] += (comb[j] % i) * MOD;
      comb[j] /= i;
    }
    comb[j] /= i;
  }

  return static_cast<int>(comb[0] % MOD);
}

int main() {
  int N, M, i, j, comb, count = 0, factor = 3, factnum[30] = {0};
  long long ans = 1;
  std::scanf("%d%d", &N, &M);

  while (!(M & 1))
    count++, M >>= 1;
  factnum[count]++;

  while (M != 1) {
    count = 0;
    while (!(M % factor))
      count++, M /= factor;
    factnum[count]++, factor += 2;
  }

  for (i = 1; i < 30; i++) {
    if (factnum[i]) {
      comb = Combination(i + N - 1, i);
      for (j = 0; j < factnum[i]; j++) {
        ans *= comb;
        ans %= MOD;
      }
    }
  }

  std::printf("%d\n", static_cast<int>(ans));

  return 0;
}