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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
// #define int long

signed main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++)
    cin >> x[i];
  for (int i = 0; i < M; i++)
    cin >> y[i];
  int max_x = -100, min_y = 100;
  for (int i = 0; i < N; i++)
    if (max_x < x[i])
      max_x = x[i];
  for (int i = 0; i < M; i++)
    if (min_y > y[i])
      min_y = y[i];
  if (Y - X >= 1 && min_y - max_x >= 1 && min_y - X >= 1 && Y - max_x >= 1)
    cout << "No War";
  else
    cout << "War";
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
// #define int long

signed main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  for (int i = 0; i < N; i++)
    cin >> x[i];
  for (int i = 0; i < M; i++)
    cin >> y[i];
  int max_x = -100, min_y = 100;
  for (int i = 0; i < N; i++)
    if (max_x < x[i])
      max_x = x[i];
  for (int i = 0; i < M; i++)
    if (min_y > y[i])
      min_y = y[i];
  if (Y - X >= 1 && min_y - max_x >= 1 && min_y - X >= 1 && Y - max_x >= 1)
    cout << "No War";
  else
    cout << "War";
}
Problem p03251 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  for (int i = 0; i < M; i++) {
    cin >> y.at(i);
  }
  int count = 0;
  for (int i = X + 1; i <= Y; i++) {
    for (int j = 0; j < N; j++) {
      if (x.at(j) >= i) {
        count++;
        break;
      }
    }
    for (int k = 0; k < M; k++) {
      if (y.at(k) < i) {
        count++;
        break;
      }
    }
    if (count == 0) {
      cout << "No War" << endl;
      return 0;
    }
    count = 0;
  }
  cout << "War" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  for (int i = 0; i < M; i++) {
    cin >> y.at(i);
  }
  int count = 0;
  for (int i = X + 1; i <= Y; i++) {
    for (int j = 0; j < N; j++) {
      if (x.at(j) >= i) {
        count++;
        break;
      }
    }
    for (int k = 0; k < M; k++) {
      if (y.at(k) < i) {
        count++;
        break;
      }
    }
    if (count == 0) {
      cout << "No War" << endl;
      return 0;
    }
    count = 0;
  }
  cout << "War" << endl;
  return 0;
}
Problem p03251 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for (int i = a; i < b; i++)

int main() {

  int n, m, X, Y;
  cin >> n >> m >> X >> Y;

  int xmax = -100, ymin = 100;
  vector<int> x(n), y(n);
  rep(i, 0, n) {
    cin >> x[i];
    xmax = max(xmax, x[i]);
  }
  rep(i, 0, m) {
    cin >> y[i];
    ymin = min(ymin, y[i]);
  }

  if (X >= ymin || Y <= xmax || ymin <= xmax)
    cout << "War" << endl;
  else
    cout << "No War" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for (int i = a; i < b; i++)

int main() {

  int n, m, X, Y;
  cin >> n >> m >> X >> Y;

  int xmax = -100, ymin = 100;
  vector<int> x(n), y(m);
  rep(i, 0, n) {
    cin >> x[i];
    xmax = max(xmax, x[i]);
  }
  rep(i, 0, m) {
    cin >> y[i];
    ymin = min(ymin, y[i]);
  }

  if (X >= ymin || Y <= xmax || ymin <= xmax)
    cout << "War" << endl;
  else
    cout << "No War" << endl;

  return 0;
}
Problem p03251 (C++)

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

int main() {
  int x, y, n, m;
  cin >> x >> y >> n >> m;
  vector<int> vecx(n + 1), vecy(m + 1);
  vecx.at(0) = x;
  vecy.at(0) = y;
  for (int i = 0; i < n; i++) {
    cin >> vecx.at(i + 1);
  }
  for (int i = 0; i < m; i++) {
    cin >> vecy.at(i + 1);
  }
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  if (vecx.at(n) + 1 <= vecy.at(0)) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
}


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

int main() {
  int x, y, n, m;
  cin >> n >> m >> x >> y;
  vector<int> vecx(n + 1), vecy(m + 1);
  vecx.at(0) = x;
  vecy.at(0) = y;
  for (int i = 0; i < n; i++) {
    cin >> vecx.at(i + 1);
  }
  for (int i = 0; i < m; i++) {
    cin >> vecy.at(i + 1);
  }
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  if (vecx.at(n) + 1 <= vecy.at(0)) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
}
Problem p03251 (C++)

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

#define INF 1e18
#define REP(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = " << x << endl

const double PI =
    3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  REP(i, N) cin >> x[i];
  REP(i, M) cin >> y[i];

  int z = X + 1;
  bool ans = false;
  while (z <= Y) {
    bool ok = true;
    REP(i, N) {
      if (x[i] < z) {
        continue;
      } else {
        ok = false;
      }
    }

    REP(i, M) {
      if (y[i] >= z) {
        continue;
      } else {
        ok = false;
      }
    }
    if (ok) {
      ans = true;
      break;
    }
  }

  if (ans) {
    print("No War");
  } else {
    print("War");
  }
}

signed main() { solve(); }


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

#define INF 1e18
#define REP(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = " << x << endl

const double PI =
    3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  REP(i, N) cin >> x[i];
  REP(i, M) cin >> y[i];

  int z = X + 1;
  bool ans = false;
  while (z <= Y) {
    bool ok = true;
    REP(i, N) {
      if (x[i] < z) {
        continue;
      } else {
        ok = false;
      }
    }

    REP(i, M) {
      if (y[i] >= z) {
        continue;
      } else {
        ok = false;
      }
    }
    if (ok) {
      ans = true;
      break;
    }
    z++;
  }

  if (ans) {
    print("No War");
  } else {
    print("War");
  }
}

signed main() { solve(); }
Problem p03251 (Python)

Buggy submission (status: Runtime Error):
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

if max(x, X) < min(y, Y):
    print("No War")
else:
    print("War")


Fixed submission:
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

if max(x + [X]) < min(y + [Y]):
    print("No War")
else:
    print("War")
Problem p03251 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
import sys

try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, X: int, Y: int, x: "List[int]", y: "List[int]"):
    xs = {X, *x}
    ys = {Y, *y}
    x1 = min(xs)
    x2 = max(xs)
    y1 = min(ys)
    y2 = max(ys)
    print("No War" if (x2 < y1 or y2 < x1) else "War")


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    y = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, X, Y, x, y)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, X: int, Y: int, x: "List[int]", y: "List[int]"):
    xs = set(x)
    xs.add(X)
    ys = set(y)
    ys.add(Y)
    x1 = min(xs)
    x2 = max(xs)
    y1 = min(ys)
    y2 = max(ys)
    print("No War" if (x2 < y1 or y2 < x1) else "War")


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    y = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, X, Y, x, y)


if __name__ == "__main__":
    main()
Problem p03251 (Python)

Buggy submission (status: Runtime Error):
# max min
n, m, x, y = map(int, input().split())
xs = max(list(map(int, input().split())))
ys = min(list(map(int, input().split())))
print("No War" if xs + 1 < ys else "War")
# max min
n, m, x, y = map(int, input().split())
xs = max(list(map(int, input().split())))
ys = min(list(map(int, input().split())))
print("No War" if xs + 1 <= ys else "War")


Fixed submission:
# max min
n, m, x, y = map(int, input().split())
xs = max(list(map(int, input().split())))
ys = min(list(map(int, input().split())))

print("No War" if xs < ys and x <= xs and ys <= y else "War")
Problem p03251 (C++)

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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> X(n), Y(n);
  for (int i = 0; i < n; i++)
    cin >> X[i];
  for (int i = 0; i < m; i++)
    cin >> Y[i];
  int xmax = x, ymin = y;
  for (int i = 0; i < n; i++) {
    xmax = max(xmax, X[i]);
  }
  for (int i = 0; i < m; i++) {
    ymin = min(ymin, Y[i]);
  }
  for (int i = -200; i < 200; i++) {
    if (xmax < i && ymin >= i) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
}

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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> X(n), Y(m);
  for (int i = 0; i < n; i++)
    cin >> X[i];
  for (int i = 0; i < m; i++)
    cin >> Y[i];
  int xmax = x, ymin = y;
  for (int i = 0; i < n; i++) {
    xmax = max(xmax, X[i]);
  }
  for (int i = 0; i < m; i++) {
    ymin = min(ymin, Y[i]);
  }
  for (int i = -200; i < 200; i++) {
    if (xmax < i && ymin >= i) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
}
Problem p03251 (C++)

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int X, Y;
  cin >> X >> Y;
  vector<int> x(N);
  vector<int> y(N);
  for (int n = 0; n < N; n++) {
    cin >> x[n];
  }
  for (int m = 0; m < M; m++) {
    cin >> y[m];
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  if (X < y[0] && y[0] <= Y && x[N - 1] < y[0]) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int X, Y;
  cin >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);
  for (int n = 0; n < N; n++) {
    cin >> x[n];
  }
  for (int m = 0; m < M; m++) {
    cin >> y[m];
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  if (X < y[0] && y[0] <= Y && x[N - 1] < y[0]) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }

  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> pii;
#define fastio() ios::sync_with_stdio(0), cin.tie(0);
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  fastio();
  string S, T;
  cin >> S >> T;
  int a[26] =
      {
          0,
      },
      b[26] = {
          0,
      };
  REP(i, S.size()) a[S[i] - 'a']++;
  REP(i, T.size()) b[T[i] - 'a']++;
  bool x = false;
  REP(i, S.size()) x |= (a[i] != b[i]);
  x ? cout << "No" : cout << "Yes";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fastio() ios::sync_with_stdio(0), cin.tie(0);
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  fastio();
  string S, T;
  cin >> S >> T;
  int a[26] =
      {
          0,
      },
      b[26] = {
          0,
      };
  REP(i, S.size()) a[S[i] - 'a']++;
  REP(i, T.size()) b[T[i] - 'a']++;
  bool x = false;
  sort(a, a + 26);
  sort(b, b + 26);
  REP(i, 26) x |= (a[i] != b[i]);
  x ? cout << "No" : cout << "Yes";
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S[2];
  cin >> S[1] >> S[2];
  int S_[2][200001];
  int N = (int)S[1].size();
  for (int i = 0; i < 2; i++) {
    string a = "";
    for (int j = 0; j < N; j++) {
      int n = a.size();
      int p = 0;
      while (p < n && a[p] != S[i][j])
        p++;
      S_[i][j] = p;
      if (p == n)
        a += S[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    if (S_[0][i] != S_[1][i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S[2];
  cin >> S[0] >> S[1];
  int S_[2][200001];
  int N = (int)S[1].size();
  for (int i = 0; i < 2; i++) {
    string a = "";
    for (int j = 0; j < N; j++) {
      int n = a.size();
      int p = 0;
      while (p < n && a[p] != S[i][j])
        p++;
      S_[i][j] = p;
      if (p == n)
        a += S[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    if (S_[0][i] != S_[1][i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03252 (C++)

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

using namespace std;

const int MAXN = (int)1e5 + 1;

struct Node {
  vector<int> node;
};

bool cmp(Node x, Node y) {
  if (x.node.size() != y.node.size())
    return x.node.size() < y.node.size();
  else {
    for (int i = 0; i < x.node.size(); ++i) {
      if (x.node[i] != y.node[i])
        return x.node[i] < y.node[i];
    }
  }
}

Node a[26], b[26];
char s[MAXN], t[MAXN];

bool solve() {
  int n = strlen(s);
  for (int i = 0; i < n; ++i) {
    a[s[i] - 'a'].node.push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    b[t[i] - 'a'].node.push_back(i);
  }
  for (int i = 0; i < 26; ++i) {
    sort(a[i].node.begin(), a[i].node.end());
    sort(b[i].node.begin(), b[i].node.end());
  }
  sort(a, a + 26, cmp);
  sort(b, b + 26, cmp);
  for (int i = 0; i < 26; ++i) {
    if (a[i].node.size() != b[i].node.size())
      return false;
    for (int j = 0; j < a[i].node.size(); ++j) {
      if (a[i].node[j] != b[i].node[j])
        return false;
    }
  }
  return true;
}

int main() {
  scanf("%s", s);
  scanf("%s", t);
  if (solve())
    puts("Yes");
  else
    puts("No");
  return 0;
}


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

using namespace std;

const int MAXN = (int)2e5 + 1;

struct Node {
  vector<int> node;
};

bool cmp(Node x, Node y) {
  if (x.node.size() != y.node.size())
    return x.node.size() < y.node.size();
  else {
    for (int i = 0; i < x.node.size(); ++i) {
      if (x.node[i] != y.node[i])
        return x.node[i] < y.node[i];
    }
  }
}

Node a[26], b[26];
char s[MAXN], t[MAXN];

bool solve() {
  int n = strlen(s);
  for (int i = 0; i < n; ++i) {
    a[s[i] - 'a'].node.push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    b[t[i] - 'a'].node.push_back(i);
  }
  for (int i = 0; i < 26; ++i) {
    sort(a[i].node.begin(), a[i].node.end());
    sort(b[i].node.begin(), b[i].node.end());
  }
  sort(a, a + 26, cmp);
  sort(b, b + 26, cmp);
  for (int i = 0; i < 26; ++i) {
    if (a[i].node.size() != b[i].node.size())
      return false;
    for (int j = 0; j < a[i].node.size(); ++j) {
      if (a[i].node[j] != b[i].node[j])
        return false;
    }
  }
  return true;
}

int main() {
  scanf("%s", s);
  scanf("%s", t);
  if (solve())
    puts("Yes");
  else
    puts("No");
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
map<char, int> s;
char s1[505], s2[505];
int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  int t = strlen(s1);
  for (register int i = 0; i < t; i++)
    if (s[s1[i]] == 0)
      s[s1[i]] = s2[i] - 'a' + 1;
    else if (s[s1[i]] != s2[i] - 'a' + 1) {
      printf("No\n");
      exit(0);
    }
  s.clear();
  for (register int i = 0; i < t; i++)
    if (s[s2[i]] == 0)
      s[s2[i]] = s1[i] - 'a' + 1;
    else if (s[s2[i]] != s1[i] - 'a' + 1) {
      printf("No\n");
      exit(0);
    }
  printf("Yes\n");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
map<char, int> s;
char s1[200005], s2[200005];
int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  int t = strlen(s1);
  for (register int i = 0; i < t; i++)
    if (s[s1[i]] == 0)
      s[s1[i]] = s2[i] - 'a' + 1;
    else if (s[s1[i]] != s2[i] - 'a' + 1) {
      printf("No\n");
      exit(0);
    }
  s.clear();
  for (register int i = 0; i < t; i++)
    if (s[s2[i]] == 0)
      s[s2[i]] = s1[i] - 'a' + 1;
    else if (s[s2[i]] != s1[i] - 'a' + 1) {
      printf("No\n");
      exit(0);
    }
  printf("Yes\n");
  return 0;
}
Problem p03252 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  vector<char> r1(30);
  vector<char> r2(30);
  rep(i, n) {
    r1[s[i]] = '1';
    r2[t[i]] = '1';
  }
  bool ok = 1;
  rep(i, n) {
    if (r1[s[i]] == '1')
      r1[s[i]] = t[i];
    if (r2[t[i]] == '1')
      r2[t[i]] = s[i];
    if (r1[s[i]] != '1' && r1[s[i]] != t[i])
      ok = 0;
    if (r2[t[i]] != '1' && r2[t[i]] != s[i])
      ok = 0;
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  char r1[200005];
  char r2[200005];
  rep(i, n) {
    r1[s[i]] = '1';
    r2[t[i]] = '1';
  }
  bool ok = 1;
  rep(i, n) {
    if (r1[s[i]] == '1')
      r1[s[i]] = t[i];
    if (r2[t[i]] == '1')
      r2[t[i]] = s[i];
    if (r1[s[i]] != '1' && r1[s[i]] != t[i])
      ok = 0;
    if (r2[t[i]] != '1' && r2[t[i]] != s[i])
      ok = 0;
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
//============================================================================
// Name        : abc110c.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s, t;
  cin >> s;
  map<char, vector<char>> mp1;
  map<char, vector<char>> mp2;

  for (int i = 0; i < s.length(); ++i) {
    char c;
    cin >> c;
    t += c;

    mp1[c].push_back(s[i]);
    mp2[s[i]].push_back(c);
  }

  for (int i = 0; i < t.length(); ++i) {
    static map<char, bool> check;
    if (check[t[i]] == true) {
      continue;
    }
    check[t[i]] = true;
    vector<char> c1 = mp1[t[i]];
    sort(c1.begin(), c1.end());
    if (c1[0] != c1[c1.size() - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < t.length(); ++i) {
    static map<char, bool> check;
    if (check[s[i]] == true) {
      continue;
    }
    check[t[i]] = true;
    vector<char> c2 = mp2[s[i]];
    sort(c2.begin(), c2.end());
    if (c2[0] != c2[c2.size() - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Fixed submission:
//============================================================================
// Name        : abc110c.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s, t;
  cin >> s;
  map<char, vector<char>> mp1;
  map<char, vector<char>> mp2;

  for (int i = 0; i < s.length(); ++i) {
    char c;
    cin >> c;
    t += c;

    mp1[c].push_back(s[i]);
    mp2[s[i]].push_back(c);
  }

  for (int i = 0; i < t.length(); ++i) {
    static map<char, bool> check;
    if (check[t[i]] == true) {
      continue;
    }
    check[t[i]] = true;
    vector<char> c1 = mp1[t[i]];
    sort(c1.begin(), c1.end());
    if (c1[0] != c1[c1.size() - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < t.length(); ++i) {
    static map<char, bool> check;
    if (check[s[i]] == true) {
      continue;
    }
    check[s[i]] = true;
    vector<char> c2 = mp2[s[i]];
    sort(c2.begin(), c2.end());
    if (c2[0] != c2[c2.size() - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int n, box[30];
char s[100010], t[100010];
int main() {

  vector<int> vs[30];
  vector<int> vt[30];
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    vs[s[i] - 'a'].push_back(i);
    vt[t[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 30; i++) {
    for (int j = 1; j < vs[i].size(); j++)
      if (t[vs[i][0]] != t[vs[i][j]]) {
        printf("No\n");
        return 0;
      }
    for (int j = 1; j < vt[i].size(); j++)
      if (s[vt[i][0]] != s[vt[i][j]]) {
        printf("No\n");
        return 0;
      }
  }
  printf("Yes\n");
}


Fixed submission:
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int n, box[30];
char s[200010], t[200010];
int main() {

  vector<int> vs[30];
  vector<int> vt[30];
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    vs[s[i] - 'a'].push_back(i);
    vt[t[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 30; i++) {
    for (int j = 1; j < vs[i].size(); j++)
      if (t[vs[i][0]] != t[vs[i][j]]) {
        printf("No\n");
        return 0;
      }
    for (int j = 1; j < vt[i].size(); j++)
      if (s[vt[i][0]] != s[vt[i][j]]) {
        printf("No\n");
        return 0;
      }
  }
  printf("Yes\n");
}
Problem p03252 (C++)

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

using namespace std;

int main(void) {
  string s, t;
  char c1 = -1, c2 = -1;
  bool fail = false;
  int find_pos = -1;

  cin >> s >> t;

  while (s != t) {
    c1 = c2 = -1;
    find_pos = -1;
    for (int i = 0; i < s.length(); i++) {
      char ch = s[i] - 'a';
      char ch_t = t[i] - 'a';
      if (s[i] != t[i] && c1 == -1) {
        // cout << (char)(ch + 'a') << ">" << (char)(ch_t + 'a') << " " << i <<
        // endl;
        c1 = ch;
        c2 = ch_t;
        find_pos = i;
        i = -1;
        continue;
      }
      if (c1 == ch) {
        s[i] = c2 + 'a';
      } else if (c2 == ch) {
        s[i] = c1 + 'a';
        // cout << i << " : " << find_pos << endl;
        if (i < find_pos) {
          // cout << "fail\n";
          fail = true;
          break;
        }
      }
    }
    // cout << s << endl;
    if (fail) {
      break;
    }
  }
  if (fail) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

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

using namespace std;

int main(void) {
  string s, t;
  char c1 = -1, c2 = -1;
  bool fail = false;
  int find_pos = -1;

  cin >> s >> t;

  while (s != t) {
    c1 = c2 = -1;
    find_pos = -1;
    for (int i = 0; i < s.length(); i++) {
      char ch = s[i] - 'a';
      char ch_t = t[i] - 'a';
      if (s[i] != t[i] && c1 == -1) {
        // cout << (char)(ch + 'a') << ">" << (char)(ch_t + 'a') << " " << i <<
        // endl;
        c1 = ch;
        c2 = ch_t;
        find_pos = i;
        i = -1;
        continue;
      }
      if (c1 == ch) {
        s[i] = c2 + 'a';
        if (i < find_pos) {
          // cout << "fail\n";
          fail = true;
          break;
        }
      } else if (c2 == ch) {
        s[i] = c1 + 'a';
        // cout << i << " : " << find_pos << endl;
        if (i < find_pos) {
          // cout << "fail\n";
          fail = true;
          break;
        }
      }
    }
    // cout << s << endl;
    if (fail) {
      break;
    }
  }
  if (fail) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 100005

char S[SIZE], T[SIZE];
int int_S[SIZE], int_T[SIZE];
int table_S[26], table_T[26];

int main() {

  scanf("%s", S);
  scanf("%s", T);

  for (int i = 0; i < 26; i++) {

    table_S[i] = -1;
    table_T[i] = -1;
  }

  int index_S = 0;
  int len;
  for (len = 0; S[len] != '\0'; len++)
    ;

  for (int i = 0; i < len; i++) {

    int ch = S[i] - 'a';
    if (table_S[ch] == -1) {

      table_S[ch] = index_S++;
    }
    int_S[i] = table_S[ch];
  }

  int index_T = 0;

  for (int i = 0; i < len; i++) {

    int ch = T[i] - 'a';
    if (table_T[ch] == -1) {

      table_T[ch] = index_T++;
    }
    int_T[i] = table_T[ch];
  }

  for (int i = 0; i < len; i++) {

    if (int_S[i] != int_T[i]) {

      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 200005

char S[SIZE], T[SIZE];
int int_S[SIZE], int_T[SIZE];
int table_S[26], table_T[26];

int main() {

  scanf("%s", S);
  scanf("%s", T);

  for (int i = 0; i < 26; i++) {

    table_S[i] = -1;
    table_T[i] = -1;
  }

  int index_S = 0;
  int len;
  for (len = 0; S[len] != '\0'; len++)
    ;

  for (int i = 0; i < len; i++) {

    int ch = S[i] - 'a';
    if (table_S[ch] == -1) {

      table_S[ch] = index_S++;
    }
    int_S[i] = table_S[ch];
  }

  int index_T = 0;

  for (int i = 0; i < len; i++) {

    int ch = T[i] - 'a';
    if (table_T[ch] == -1) {

      table_T[ch] = index_T++;
    }
    int_T[i] = table_T[ch];
  }

  for (int i = 0; i < len; i++) {

    if (int_S[i] != int_T[i]) {

      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main() {
  string s, t;
  cin >> s >> t;

  REP(i, (int)s.size()) {
    if (s[i] != t[i]) {
      char a = s[i], b = t[i];
      for (int j = 0; j < (int)s.size(); j++) {
        if (s[j] == a) {
          s[j] = b;
          continue;
        }
        if (s[j] == b) {
          s[j] = a;
        }
      }
    }
  }

  if (s == t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main() {
  string s, t;
  cin >> s >> t;

  REP(i, (int)s.size()) {
    if (s[i] != t[i]) {
      char a = s[i], b = t[i];
      for (int j = 0; j < (int)s.size(); j++) {
        if (s[j] == a) {
          s[j] = b;
          continue;
        }
        if (s[j] == b) {
          s[j] = a;
        }
        if (j < i && s[j] != t[j])
          break;
      }
    }
  }

  if (s == t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03252 (Python)

Buggy submission (status: Runtime Error):
import sys
import socket

hostname = socket.gethostname()

if hostname == "F551C":
    sys.stdin = open("c1.in")


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    S = read_str()
    T = read_str()
    n = len(S)
    res = "Yes"
    A = [0] * n
    B = [0] * n
    vu = {}
    for i in range(n):
        if S[i] in vu:
            A[i] = vu[S[i]]
        else:
            vu[S[i]] = i
            A[i] = vu[S[i]]

    vu = {}
    for i in range(n):
        if T[i] in vu:
            T[i] = vu[T[i]]
        else:
            vu[T[i]] = i
            B[i] = vu[T[i]]

    if A != B:
        res = "No"

    # for i in range(n):
    #     for j in range(n):
    #         if S[i] != S[j] and T[i] == T[j]:
    #             res = 'No'
    #         if S[i] == S[j] and T[i] != T[j]:
    #             res = 'No'
    print(res)


main()


Fixed submission:
import sys
import socket

hostname = socket.gethostname()

if hostname == "F551C":
    sys.stdin = open("c1.in")


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    S = read_str()
    T = read_str()
    n = len(S)
    res = "Yes"
    A = [0] * n
    B = [0] * n
    vu = {}
    for i in range(n):
        if S[i] in vu:
            A[i] = vu[S[i]]
        else:
            vu[S[i]] = i
            A[i] = vu[S[i]]

    vu = {}
    for i in range(n):
        if T[i] in vu:
            B[i] = vu[T[i]]
        else:
            vu[T[i]] = i
            B[i] = vu[T[i]]

    if A != B:
        res = "No"

    # for i in range(n):
    #     for j in range(n):
    #         if S[i] != S[j] and T[i] == T[j]:
    #             res = 'No'
    #         if S[i] == S[j] and T[i] != T[j]:
    #             res = 'No'
    print(res)


main()
Problem p03252 (Python)

Buggy submission (status: Time Limit Exceeded):
S = input()
T = input()
N = len(S)
pos_S = {c: set() for c in "abcdefghijklmnopqrstuvwxyz"}
[pos_S[S[i]].add(i) for i in range(N)]
pos_T = {c: set() for c in "abcdefghijklmnopqrstuvwxyz"}
[pos_T[T[i]].add(i) for i in range(N)]
if all(pos_S[S[i]] == pos_T[T[i]] for i in range(N)):
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
T = input()
S_cnt = sorted(S.count(c) for c in set(S))
T_cnt = sorted(T.count(c) for c in set(T))
print("Yes") if S_cnt == T_cnt else print("No")
Problem p03252 (Python)

Buggy submission (status: Runtime Error):
ch_S = input()
ch_T = input()

ind_S = []
ind_T = []
for i in list("abcdefghijklmnopqrstuvwxyz"):
    L = [ch_S.find(i)]
    ind_S.append(
        L,
    )
    R = [ch_T.find(i)]
    ind_T.append(
        R,
    )

if set(ind_S) == set(ind_T):
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
T = input()
ls = [0] * 26
lt = [0] * 26
al = [chr(ord("a") + i) for i in range(26)]
for i in range(S.__len__()):
    si = al.index(S[i])
    ti = al.index(T[i])
    ls[si] += 1
    lt[ti] += 1
ls.sort()
lt.sort()
if ls == lt:
    print("Yes")
else:
    print("No")
Problem p03252 (Python)

Buggy submission (status: Runtime Error):
S = input()
T = input()

dic = {}
dic_rev = {}


def solve():
    for s, t in zip(S, T):
        if t in dic.keys():
            if s != dic[t]:
                print("No")
                return
        else:
            dic[t] = s
    for s, t in zip(S, T):
        if t in dic_rev.keys():
            if t != dic_rev[s]:
                print("No")
                return
        else:
            dic_rev[s] = t
    print("Yes")
    return


solve()


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

dic = {}
dic_rev = {}


def solve():
    for s, t in zip(S, T):
        if t in dic.keys():
            if s != dic[t]:
                print("No")
                return
        else:
            dic[t] = s
    for s, t in zip(S, T):
        if s in dic_rev.keys():
            if t != dic_rev[s]:
                print("No")
                return
        else:
            dic_rev[s] = t
    print("Yes")
    return


solve()
Problem p03252 (C++)

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

int main() {
  int arr[26][26];
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++)
      arr[i][j] = 0;
  char s[20001], t[20001];
  cin >> s >> t;
  int length = strlen(s);
  for (int i = 0; i < length; i++) {
    int x = s[i] - 'a', y = t[i] - 'a';
    if (arr[x][y] == 0) {
      for (int j = 0; j < 26; j++) {
        if (arr[x][j] != 1 && j != y)
          arr[x][j] = -1;
        else if (arr[x][j] == 1) {
          printf("No\n");
          return 0;
        }
        if (arr[j][y] != 1 && j != x)
          arr[j][y] = -1;
        else if (arr[j][y] == 1) {
          printf("No\n");
          return 0;
        }
      }
      arr[x][y] = 1;
    } else if (arr[x][y] == -1) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

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

int main() {
  int arr[26][26];
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++)
      arr[i][j] = 0;
  char s[200001], t[200001];
  cin >> s >> t;
  int length = strlen(s);
  for (int i = 0; i < length; i++) {
    int x = s[i] - 'a', y = t[i] - 'a';
    if (arr[x][y] == 0) {
      for (int j = 0; j < 26; j++) {
        if (arr[x][j] != 1 && j != y)
          arr[x][j] = -1;
        else if (arr[x][j] == 1) {
          printf("No\n");
          return 0;
        }
        if (arr[j][y] != 1 && j != x)
          arr[j][y] = -1;
        else if (arr[j][y] == 1) {
          printf("No\n");
          return 0;
        }
      }
      arr[x][y] = 1;
    } else if (arr[x][y] == -1) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 100000;
char a[MAXN + 5], b[MAXN + 5];
int cnt1[30], cnt2[30], num1[MAXN + 5], num2[MAXN + 5];
int alen, blen, Max;
int main() {
  scanf("%s%s", a, b);
  alen = strlen(a);
  blen = strlen(b);
  for (int i = 0; i < alen; i++) {
    cnt1[a[i] - 'a']++;
    if (cnt1[a[i] - 'a'] > Max)
      Max = cnt1[a[i] - 'a'];
  }
  for (int i = 0; i < blen; i++) {
    cnt2[b[i] - 'a']++;
    if (cnt2[b[i] - 'a'] > Max)
      Max = cnt2[b[i] - 'a'];
  }
  for (int i = 0; i <= 25; i++)
    num1[cnt1[i]]++;
  for (int i = 0; i <= 25; i++)
    num2[cnt2[i]]++;
  for (int i = 0; i <= Max; i++)
    if (num1[i] != num2[i]) {
      printf("No\n");
      return 0;
    }
  printf("Yes\n");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 200000;
char a[MAXN + 5], b[MAXN + 5];
int cnt1[30], cnt2[30], num1[MAXN + 5], num2[MAXN + 5];
int alen, blen, Max;
int main() {
  scanf("%s%s", a, b);
  alen = strlen(a);
  blen = strlen(b);
  for (int i = 0; i < alen; i++) {
    cnt1[a[i] - 'a']++;
    if (cnt1[a[i] - 'a'] > Max)
      Max = cnt1[a[i] - 'a'];
  }
  for (int i = 0; i < blen; i++) {
    cnt2[b[i] - 'a']++;
    if (cnt2[b[i] - 'a'] > Max)
      Max = cnt2[b[i] - 'a'];
  }
  for (int i = 0; i <= 25; i++)
    num1[cnt1[i]]++;
  for (int i = 0; i <= 25; i++)
    num2[cnt2[i]]++;
  for (int i = 0; i <= Max; i++)
    if (num1[i] != num2[i]) {
      printf("No\n");
      return 0;
    }
  printf("Yes\n");
  return 0;
}
Problem p03252 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  int alphabet[26];
  for (int i = 0; i < 26; i++) {
    alphabet[i] = -1;
  }
  vector<vector<int>> all(26, vector<int>());
  for (int i = 0; i < s.size(); i++) {
    all[s[i] - 97].push_back(i);
  }

  for (int i = 0; i < s.size(); i++) {
    // まずは、s[i]が変わっていないか調べる
    if (s[i] == t[i] || alphabet[s[i] - 97] == 1) {
      // なにもしない
      if (s[i] != t[i]) {
        cout << "No" << endl;
        break;
      }
      alphabet[t[i] - 97] = 1;
    } else {
      // s[i]に該当するところを変えていく
      vector<int> ss;
      for (int j = 0; j < all[s[i] - 97].size(); j++) {
        int sub = all[s[i] - 97][j];
        if (sub != i) {
          s[sub] = t[i];
        }
      }
      for (int j = 0; j < all[t[i] - 97].size(); j++) {
        int sub = all[t[i] - 97][j];
        if (sub != i) {
          s[sub] = s[i];
        }
      }
      all[s[i] - 97].swap(all[t[i] - 97]);
      s[i] = t[i];
      alphabet[t[i] - 97] = 1;
    }
    if (s == t) {
      cout << "Yes" << endl;
      break;
    }
    if (i == (s.size() - 1)) {
      if (s == t) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int alphabet[26];
  for (int i = 0; i < 26; i++) {
    alphabet[i] = -1;
  }
  vector<vector<int>> all(26, vector<int>());
  for (int i = 0; i < s.size(); i++) {
    all[s[i] - 97].push_back(i);
  }

  for (int i = 0; i < s.size(); i++) {
    // まずは、s[i]が変わっていないか調べる
    if (s[i] == t[i] || alphabet[s[i] - 97] == 1) {
      // なにもしない
      if (s[i] != t[i]) {
        cout << "No" << endl;
        break;
      }
      alphabet[t[i] - 97] = 1;
    } else {
      // s[i]に該当するところを変えていく
      vector<int> ss;
      for (int j = 0; j < all[s[i] - 97].size(); j++) {
        int sub = all[s[i] - 97][j];
        if (sub != i) {
          s[sub] = t[i];
        }
        if (sub < i) {
          cout << "No" << endl;
          return 0;
        }
      }
      for (int j = 0; j < all[t[i] - 97].size(); j++) {
        int sub = all[t[i] - 97][j];
        if (sub != i) {
          s[sub] = s[i];
        }
      }
      all[s[i] - 97].swap(all[t[i] - 97]);
      s[i] = t[i];
      alphabet[t[i] - 97] = 1;
    }
    if (s == t) {
      cout << "Yes" << endl;
      break;
    }
    if (i == (s.size() - 1)) {
      if (s == t) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  bool a[n];
  char c1[26] = {}, c2[26] = {};
  bool ans = true;
  for (int i = 0; i < n; i++) {
    c1[s.at(i) - 'a']++;
  }
  for (int i = 0; i < n; i++) {
    c2[t.at(i) - 'a']++;
  }
  int n1 = 0, n2 = 0;
  for (int i = 0; i < 26; i++) {
    if (c1[i] > 0)
      n1++;
    if (c2[i] > 0)
      n2++;
  }
  if (n1 != n2)
    ans = false;
  for (int i = 0; i < n; i++)
    a[i] = true;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != t.at(i) && a[i]) {
      for (int j = i; j < n; j++) {
        if (a[i]) {
          if (s.at(j) == s.at(i) && t.at(j) != t.at(i)) {
            ans = false;
          } else if (s.at(j) == s.at(i)) {
            a[j] = false;
          }
        }
      }
    }
  }
  if (ans)
    cout << "Yes";
  else
    cout << "No";
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  bool a[n];
  char c1[26] = {}, c2[26] = {};
  bool ans = true;
  for (int i = 0; i < n; i++) {
    c1[s.at(i) - 'a']++;
  }
  for (int i = 0; i < n; i++) {
    c2[t.at(i) - 'a']++;
  }
  int n1 = 0, n2 = 0;
  for (int i = 0; i < 26; i++) {
    if (c1[i] > 0)
      n1++;
    if (c2[i] > 0)
      n2++;
  }
  if (n1 != n2)
    ans = false;
  for (int i = 0; i < n; i++)
    a[i] = true;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != t.at(i) && a[i]) {
      for (int j = i; j < n; j++) {
        if (s.at(j) == s.at(i) && t.at(j) != t.at(i)) {
          ans = false;
          a[j] = false;
        } else if (s.at(j) == s.at(i)) {
          a[j] = false;
        }
      }
    }
  }
  if (ans)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define nl cout << "\n"
#define dbg(x) cout << x << " ";
#define fi(a, b) for (int i = a; i < b; i++)
#define fj(a, b) for (int j = a; j < b; j++)
#define UM unordered_map<char, int>
#define ULL unordered_map<ll, int>
void fun() {
  string s, t;
  cin >> s >> t;
  UM ms, mt;
  int S = 1, T = 1;
  fi(0, s.size()) {
    if (ms[s[i]] != mt[t[i]]) {
      cout << "No\n";
      return;
    }
    if (ms[s[i]] == 0) {
      ms[s[i]] = S;
      S++;
    }
    if (mt[t[i]] == 0) {
      mt[t[i]] = T;
      T++;
    }
  }
  cout << "Yes\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("/ATOM/input.txt", "r", stdin);
  freopen("/ATOM/output.txt", "w", stdout);
#endif
  fun();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define nl cout << "\n"
#define dbg(x) cout << x << " ";
#define fi(a, b) for (int i = a; i < b; i++)
#define fj(a, b) for (int j = a; j < b; j++)
#define UM unordered_map<char, int>
#define ULL unordered_map<ll, int>
void fun() {
  string s, t;
  cin >> s >> t;
  UM ms, mt;
  int S = 1, T = 1;
  fi(0, s.size()) {
    if (ms[s[i]] != mt[t[i]]) {
      cout << "No\n";
      return;
    }
    if (ms[s[i]] == 0) {
      ms[s[i]] = S;
      S++;
    }
    if (mt[t[i]] == 0) {
      mt[t[i]] = T;
      T++;
    }
  }
  cout << "Yes\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  fun();
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char s[100005], t[100005];
int main() {
  cin >> s >> t;
  int fs[26], ft[26];
  memset(fs, -1, sizeof(fs));
  memset(ft, -1, sizeof(ft));
  int l = strlen(s);
  int flag = 0;
  for (int i = 0; i < l; i++) {
    if (fs[s[i] - 'a'] == -1) {
      fs[s[i] - 'a'] = t[i];
    } else {
      if (fs[s[i] - 'a'] != t[i]) {
        flag = 1;
        break;
      }
    }
    if (ft[t[i] - 'a'] == -1) {
      ft[t[i] - 'a'] = s[i];
    } else {
      if (ft[t[i] - 'a'] != s[i]) {
        flag = 1;
        break;
      }
    }
  }
  if (flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char s[200005], t[200005];
int main() {
  cin >> s >> t;
  int fs[26], ft[26];
  memset(fs, -1, sizeof(fs));
  memset(ft, -1, sizeof(ft));
  int l = strlen(s);
  int flag = 0;
  for (int i = 0; i < l; i++) {
    if (fs[s[i] - 'a'] == -1) {
      fs[s[i] - 'a'] = t[i];
    } else {
      if (fs[s[i] - 'a'] != t[i]) {
        flag = 1;
        break;
      }
    }
    if (ft[t[i] - 'a'] == -1) {
      ft[t[i] - 'a'] = s[i];
    } else {
      if (ft[t[i] - 'a'] != s[i]) {
        flag = 1;
        break;
      }
    }
  }
  if (flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p03252 (Python)

Buggy submission (status: Runtime Error):
def solve(string):
    s, t = map(int, string.split())

    c_s = sorted([s.count(_c) for _c in set(s)])
    c_t = sorted([t.count(_c) for _c in set(t)])

    if c_s == c_t:
        return "Yes"
    else:
        return "No"


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))


Fixed submission:
def solve(string):
    s, t = string.split()

    c_s = sorted([s.count(_c) for _c in set(s)])
    c_t = sorted([t.count(_c) for _c in set(t)])

    if c_s == c_t:
        return "Yes"
    else:
        return "No"


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))
Problem p03252 (Python)

Buggy submission (status: Time Limit Exceeded):
S = input()
T = input()
n = len(S)
for i in range(n):
    s = S[i]
    t = T[i]
    S = S.translate(str.maketrans({s: t, t: s}))
if S == T:
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
T = input()
st = {}
ts = {}
for s, t in zip(S, T):
    if s in st and st[s] != t:
        print("No")
        exit()
    if t in ts and ts[t] != s:
        print("No")
        exit()
    st[s] = t
    ts[t] = s
print("Yes")
Problem p03252 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) {
      char c = s[i];
      for (int j = 0; j < s.size(); j++) {
        if (s[j] == c) {
          s[j] = t[i];
        } else if (s[j] == t[i]) {
          s[j] = c;
        }
      }
    }
  }
  cout << (s == t ? "Yes" : "No");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) {
      char c = s[i];
      for (int j = 0; j < s.size(); j++) {
        if (j < i) {
          if (t[i] == s[j]) {
            cout << "No";
            return 0;
          }
        }
        if (s[j] == c) {
          s[j] = t[i];
        } else if (s[j] == t[i]) {
          s[j] = c;
        }
      }
    }
  }
  cout << (s == t ? "Yes" : "No");
}
Problem p03252 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
char ss[111111];
void gen(vector<vector<int>> &s) {
  scanf("%s", ss);
  for (int i = 0; ss[i]; i++) {
    s[ss[i] - 'a'].push_back(i);
  }
  sort(s.begin(), s.end());
}
int main() {
  vector<vector<int>> s1(26), s2(26);
  gen(s1);
  gen(s2);
  puts(s1 == s2 ? "Yes" : "No");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
char ss[222222];
void gen(vector<vector<int>> &s) {
  scanf("%s", ss);
  for (int i = 0; ss[i]; i++) {
    s[ss[i] - 'a'].push_back(i);
  }
  sort(s.begin(), s.end());
}
int main() {
  vector<vector<int>> s1(26), s2(26);
  gen(s1);
  gen(s2);
  puts(s1 == s2 ? "Yes" : "No");
  return 0;
}