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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second

const int mx = 200010;
const ll mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }

  rep(i, n) {
    int cnt = 0;
    auto pos = a[i].find(b[cnt]);
    bool flag = false;
    while (pos != std::string::npos) {
      flag = true;
      rep(j, m) {
        if (a[i + j].substr(pos, m) != b[j]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        break;
      }
      pos = a[i].find(b[cnt], pos + b[cnt].length());
    }
    if (flag) {
      cout << "Yes" << endl;
      return 0;
    }
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second

const int mx = 200010;
const ll mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }

  rep(i, n - m + 1) {
    int cnt = 0;
    auto pos = a[i].find(b[cnt]);
    bool flag = false;
    while (pos != std::string::npos) {
      flag = true;
      rep(j, m) {
        if (a[i + j].substr(pos, m) != b[j]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        break;
      }
      pos = a[i].find(b[cnt], pos + b[cnt].length());
    }
    if (flag) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}
Problem p03804 (Python)

Buggy submission (status: Runtime Error):
import numpy as np

N, M = map(int, input().split())
A = np.array([list(input()) for _ in range(N)])
B = np.array([list(input()) for _ in range(M)])
# print('AB', A, B)
for i in range(N - M + 1):
    for j in range(N - M + 1):
        # print('i j', i, j)
        A_subset = A[i : i + N - 1, j : j + N - 1]
        # print('A_subset', A_subset)
        if np.all(A_subset == B):
            print("Yes")
            exit()
print("No")


Fixed submission:
import numpy as np

N, M = map(int, input().split())
A = np.array([list(input()) for _ in range(N)])
B = np.array([list(input()) for _ in range(M)])
# print('AB', A, B)
for i in range(N - M + 1):
    for j in range(N - M + 1):
        # print('i j', i, j)
        A_subset = A[i : i + M, j : j + M]
        # print('A_subset', A_subset)
        if np.all(A_subset == B):
            print("Yes")
            exit()
print("No")
Problem p03804 (C++)

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  vector<string> B(M);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int j = 0; j < M; j++) {
    cin >> B[j];
  }

  for (int i = 0; i <= N - M; i++) {
    for (int j = 0; j <= N - M; j++) {
      bool flag = true;
      for (int x = 0; x < M; x++) {
        for (int y = 0; y < M; y++) {
          if (B[x][y] != A[i + x - 1][j + y - 1]) {
            flag = false;
          }
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  vector<string> B(M);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int j = 0; j < M; j++) {
    cin >> B[j];
  }

  for (int i = 0; i <= N - M; i++) {
    for (int j = 0; j <= N - M; j++) {
      bool flag = true;
      for (int x = 0; x < M; x++) {
        for (int y = 0; y < M; y++) {
          if (B[x][y] != A[i + x][j + y]) {
            flag = false;
          }
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
// cout << fixed << setprecision(20) << *** << endl;
typedef long long ll;
using namespace std;
int main() {
  ll N, M;
  string ANS = "No";
  vector<vector<char>> A, B;
  cin >> N >> M;
  rep(i, N) {
    vector<char> vec;
    string s;
    cin >> s;
    rep(j, N) { vec.push_back(s[j]); }
    A.push_back(vec);
  }
  rep(i, M) {
    vector<char> vec;
    string s;
    cin >> s;
    rep(j, M) { vec.push_back(s[j]); }
    B.push_back(vec);
  }
  rep(i, N - M + 1) {
    rep(j, N - M + 1) {
      if (A[i][j] == B[0][0]) {
        bool f = true;
        rep(k, N - M - 1) {
          rep(l, N - M - 1) {
            if (A[i + k][j + l] != B[k][l])
              f = false;
          }
        }
        if (f == true)
          ANS = "Yes";
      }
      // cout<<A[i][j];
    }
    // cout<<endl;
  }
  cout << ANS << endl;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
// cout << fixed << setprecision(20) << *** << endl;
typedef long long ll;
using namespace std;
int main() {
  ll N, M;
  string ANS = "No";
  vector<vector<char>> A, B;
  cin >> N >> M;
  rep(i, N) {
    vector<char> vec;
    string s;
    cin >> s;
    rep(j, N) { vec.push_back(s[j]); }
    A.push_back(vec);
  }
  rep(i, M) {
    vector<char> vec;
    string s;
    cin >> s;
    rep(j, M) { vec.push_back(s[j]); }
    B.push_back(vec);
  }
  rep(i, N - M + 1) {
    rep(j, N - M + 1) {
      if (A[i][j] == B[0][0]) {
        bool f = true;
        rep(k, M) {
          rep(l, M) {
            if (A[i + k][j + l] != B[k][l])
              f = false;
          }
        }
        if (f == true)
          ANS = "Yes";
      }
      // cout<<A[i][j];
    }
    // cout<<endl;
  }
  cout << ANS << endl;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
/*
    Come feed the rain
        Cos I'm thirsty for your love
        Dancing underneath the skies of lust
        Yeah feed the rain...
        Cos without your love my life
        Ain't nothing but this carnival of rust
    _________________________
    _________________________
    816 Hours of Solitude
    Quarantine_Day : 34
*/

#include <bits/stdc++.h>

using namespace std;

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

#define pb(n) push_back(n)
#define GSORT(v) sort(v.begin(), v.end(), greater<int>())
#define SORT(v) sort(v.begin(), v.end());
#define REV(v) reverse(v.begin(), v.end());
#define db(a) cout << #a << " = " << a << endl;
#define FIN freopen("in.txt", "r", stdin);
#define FOUT freopen("out.txt", "w", stdout);
#define REP(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)

#define MAX 50005

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

  int n, m;
  cin >> n >> m;

  string s1[n];
  string s2[m];

  REP(i, n) cin >> s1[i];
  REP(i, m) cin >> s2[i];

  REP(i, n) {
    REP(j, n) {
      bool flag = false;
      if (s1[i][j] == s2[0][0]) {
        flag = true;
        REP(ii, m) {
          REP(jj, m) {
            if (s1[i + ii][j + jj] != s2[ii][jj]) {
              flag = false;
            }
          }
        }
      }
      if (flag) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";

  return 0;
}


Fixed submission:
/*
    Come feed the rain
        Cos I'm thirsty for your love
        Dancing underneath the skies of lust
        Yeah feed the rain...
        Cos without your love my life
        Ain't nothing but this carnival of rust
    _________________________
    _________________________
    816 Hours of Solitude
    Quarantine_Day : 34
*/

#include <bits/stdc++.h>

using namespace std;

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

#define pb(n) push_back(n)
#define GSORT(v) sort(v.begin(), v.end(), greater<int>())
#define SORT(v) sort(v.begin(), v.end());
#define REV(v) reverse(v.begin(), v.end());
#define db(a) cout << #a << " = " << a << endl;
#define FIN freopen("in.txt", "r", stdin);
#define FOUT freopen("out.txt", "w", stdout);
#define REP(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)

#define MAX 50005

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

  int n, m;
  cin >> n >> m;

  string s1[n];
  string s2[m];

  REP(i, n) cin >> s1[i];
  REP(i, m) cin >> s2[i];

  for (int i = 0; i + m - 1 < n; i++) {
    for (int j = 0; j + m - 1 < n; j++) {
      bool flag = false;
      if (s1[i][j] == s2[0][0]) {
        flag = true;
        REP(ii, m) {
          REP(jj, m) {
            if (s1[i + ii][j + jj] != s2[ii][jj]) {
              flag = false;
            }
          }
        }
      }
      if (flag) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";

  return 0;
}
Problem p03804 (C++)

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

int main() {
  int N, M;
  char A[50][50], B[50][50];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++)
    scanf(" %s", A[i]);
  for (int i = 0; i < M; i++)
    scanf(" %s", B[i]);
  bool yes;
  for (int i = 0; i < (N - M + 1) * (N - M + 1); i++) {
    yes = true;
    for (int j = 0; j < M * M; j++) {
      if (A[i / (N - M) + j / M][i % (N - M) + j % M] != B[j / M][j % M]) {
        yes = false;
        break;
      }
    }
    if (yes)
      break;
  }

  if (yes)
    printf("Yes");
  else
    printf("No");
}

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

int main() {
  int N, M;
  char A[50][50], B[50][50];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++)
    scanf(" %s", A[i]);
  for (int i = 0; i < M; i++)
    scanf(" %s", B[i]);
  bool yes;
  for (int i = 0; i < (N - M + 1) * (N - M + 1); i++) {
    yes = true;
    for (int j = 0; j < M * M; j++) {
      if (A[i / (N - M + 1) + j / M][i % (N - M + 1) + j % M] !=
          B[j / M][j % M]) {
        yes = false;
        break;
      }
    }
    if (yes)
      break;
  }

  if (yes)
    printf("Yes");
  else
    printf("No");
}
Problem p03804 (C++)

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> v(N);
  vector<string> w(M);

  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> w[i];
  }

  bool ans_flg = false;
  for (int i = 0; i < N + M; i++) {
    for (int j = 0; j < N + M; j++) {
      bool flg = true;
      // 1つでもfalseになれば、ijを更新する
      for (int k = 0; k < M; k++) {
        for (int l = 0; l < M; l++) {
          if (v[i + k][j + l] != w[k][l]) {
            flg = false;
            break;
          }
        }
        if (!flg)
          break;
      }
      if (flg) {
        ans_flg = true;
        break;
      }
      if (!flg) {
        continue;
      }
    }
    if (ans_flg) {
      break;
    }
  }

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


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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> v(N);
  vector<string> w(M);

  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> w[i];
  }

  bool ans_flg = false;
  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < N - M + 1; j++) {
      bool flg = true;
      // 1つでもfalseになれば、ijを更新する
      for (int k = 0; k < M; k++) {
        for (int l = 0; l < M; l++) {
          if (v[i + k][j + l] != w[k][l]) {
            flg = false;
            break;
          }
        }
        if (!flg)
          break;
      }
      if (flg) {
        ans_flg = true;
        break;
      }
      if (!flg) {
        continue;
      }
    }
    if (ans_flg) {
      break;
    }
  }

  cout << (ans_flg ? "Yes" : "No") << endl;
}
Problem p03804 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  char a[n][n], b[m][m];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];

  bool ans = false;
  for (int i = 0; i < n - m + 1; i++) {
    for (int j = 0; j < n - m + 1; j++) {
      bool match = true;
      for (int y = 0; y < m; y++) {
        for (int x = 0; x < m; x++) {
          if (a[i + y][j + x] != b[y][x])
            match = false;
        }
      }
      if (match)
        ans = true;
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  char a[n][n], b[m][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }

  bool ans = false;
  for (int i = 0; i < n - m + 1; i++) {
    for (int j = 0; j < n - m + 1; j++) {
      bool match = true;
      for (int y = 0; y < m; y++) {
        for (int x = 0; x < m; x++) {
          if (a[i + y][j + x] != b[y][x])
            match = false;
        }
      }
      if (match)
        ans = true;
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03804 (C++)

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

int main() {
  int m, n;
  char s[51];
  scanf("%d %d", &n, &m);
  vector<vector<int>> a(n, vector<int>(n)), b(m, vector<int>(m));
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < n; j++)
      a[i][j] = s[j];
  }
  for (int i = 0; i < m; i++) {
    scanf("%s", s);
    for (int j = 0; j < n; j++)
      b[i][j] = s[j];
  }
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      int f = 1;
      for (int k = 0; k < m; k++)
        for (int l = 0; l < m; l++)
          if (a[i + k][j + l] != b[k][l])
            f = 0;
      if (f) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
}

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

int main() {
  int m, n;
  char s[51];
  scanf("%d %d", &n, &m);
  vector<vector<int>> a(n, vector<int>(n)), b(m, vector<int>(m));
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < n; j++)
      a[i][j] = s[j];
  }
  for (int i = 0; i < m; i++) {
    scanf("%s", s);
    for (int j = 0; j < m; j++)
      b[i][j] = s[j];
  }
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      int f = 1;
      for (int k = 0; k < m; k++)
        for (int l = 0; l < m; l++)
          if (a[i + k][j + l] != b[k][l])
            f = 0;
      if (f) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
}
Problem p03804 (C++)

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<char>> I(N, vector<char>(N, 'x'));
  vector<vector<char>> P(M, vector<char>(M, 'x'));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++)
      cin >> I[i][j];
  }

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++)
      cin >> P[i][j];
  }
  bool f = true;
  for (int sx = 0; sx < N; sx++) {
    for (int sy = 0; sy < N; sy++) {
      f = true;
      for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
          if (I[sx + i][sy + j] != P[i][j]) {
            f = false;
          }
        }
      }
      if (f)
        break;
    }
    if (f)
      break;
  }
  if (f)
    cout << "Yes";
  else
    cout << "No";
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<char>> I(N, vector<char>(N, 'x'));
  vector<vector<char>> P(M, vector<char>(M, 'x'));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++)
      cin >> I[i][j];
  }

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++)
      cin >> P[i][j];
  }
  bool f = false;
  for (int sx = 0; sx < N - M + 1; sx++) {
    for (int sy = 0; sy < N - M + 1; sy++) {
      f = true;
      for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
          if (I[sx + i][sy + j] != P[i][j]) {
            f = false;
          }
        }
      }
      if (f)
        break;
    }
    if (f)
      break;
  }
  if (f)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03804 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<string> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

  for (int i = 0; i <= N - M; i++) {
    for (int j = 0; j <= N - M; j++) {
      int I = i;
      while (I < i + M) {
        if (A[I].substr(j, M) != B[I]) {
          break;
        };
        I++;
        if (I == M + i) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

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


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<string> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

  for (int i = 0; i <= N - M; i++) {
    for (int j = 0; j <= N - M; j++) {
      int I = i;
      while (I < i + M) {
        if (A[I].substr(j, M) != B[I - i]) {
          break;
        };
        I++;
        if (I == M + i) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

  cout << "No" << endl;
  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll(i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

int N, M;
vector<string> A, B;

void solve() {
  REP(i, N - M + 1) {
    REP(j, N - M + 1) {
      bool same = true;
      REP(k, M) {
        if (A[i + k].substr(j, M) != B[i + k]) {
          same = false;
        }
      }
      if (same) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
}

signed main() {
  cin >> N >> M;
  REP(i, N) {
    string a;
    cin >> a;
    A.push_back(a);
  }
  REP(i, M) {
    string b;
    cin >> b;
    B.push_back(b);
  }
  solve();
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll(i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

int N, M;
vector<string> A, B;

void solve() {
  REP(i, N - M + 1) {
    REP(j, N - M + 1) {
      bool same = true;
      REP(k, M) {
        if (A[i + k].substr(j, M) != B[k]) {
          same = false;
        }
      }
      if (same) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
}

signed main() {
  cin >> N >> M;
  REP(i, N) {
    string a;
    cin >> a;
    A.push_back(a);
  }
  REP(i, M) {
    string b;
    cin >> b;
    B.push_back(b);
  }
  solve();
}
Problem p03804 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  char a[n][n], b[m][m], ab[m][m];
  bool isGood = true;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      for (int x = i; x < m; x++) {
        for (int y = j; y < m; y++) {
          ab[x][y] = a[i + x][j + y];
        }
      }
      isGood = true;
      for (int x = 0; x < m; x++) {
        for (int y = 0; y < m; y++) {
          if (ab[x][y] != b[x][y]) {
            isGood = false;
          }
        }
      }
      if (isGood == true) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  char a[n][n], b[m][m], ab[m][m];
  bool isGood = true;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      for (int x = 0; x < m; x++) {
        for (int y = 0; y < m; y++) {
          ab[x][y] = a[i + x][j + y];
        }
      }
      isGood = true;
      for (int x = 0; x < m; x++) {
        for (int y = 0; y < m; y++) {
          if (ab[x][y] != b[x][y]) {
            isGood = false;
          }
        }
      }
      if (isGood == true) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, yes = 0;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  for (int j = 0; j < m; j++)
    cin >> b.at(j);
  for (int k = 0; k < n - m + 1; k++) {
    for (int l = 0; l < n - m + 1; l++) {
      int x = 0;
      for (int p = l; p < l + m - 1; p++) {
        if (a.at(k + p).substr(l, m) != b.at(p)) {
          x++;
          break;
        }
      }
      if (x == 0) {
        cout << "Yes" << endl;
        yes = 1;
        break;
      }
    }
    if (yes == 1)
      break;
  }
  if (yes == 0)
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, yes = 0;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  for (int j = 0; j < m; j++)
    cin >> b.at(j);
  for (int k = 0; k < n - m + 1; k++) {
    for (int l = 0; l < n - m + 1; l++) {
      int x = 0;
      for (int p = 0; p < m; p++) {
        if (a.at(k + p).substr(l, m) != b.at(p)) {
          x++;
          break;
        }
      }
      if (x == 0) {
        cout << "Yes" << endl;
        yes = 1;
        break;
      }
    }
    if (yes == 1)
      break;
  }
  if (yes == 0)
    cout << "No" << endl;
}
Problem p03804 (C++)

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

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> a(n, vector<char>(n));
  vector<vector<char>> b(m, vector<char>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> a.at(i).at(j);
    }
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      cin >> b.at(i).at(j);
    }

  bool exist = false; // あるかないかのチェック

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {           // Aの範囲で
      if (i + m - 1 >= n || j + m - 1 >= n) // 検索範囲
        continue;                           // 次へ

      bool match = true; // 検索元画像と同じものがないかチェック
      for (int y = 0; y < m; i++) {
        for (int x = 0; x < m; j++) {
          if (a.at(i + y).at(j + x) != b.at(i).at(j)) // 選択範囲の要素とBを比較
            match = false;
        }
      }
      if (match)
        exist = true;
    }
  }
  if (exist) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;

  return 0;
}


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

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> a(n, vector<char>(n));
  vector<vector<char>> b(m, vector<char>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> a.at(i).at(j);
    }
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      cin >> b.at(i).at(j);
    }

  bool exist = false; // あるかないかのチェック

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {           // Aの範囲で
      if (i + m - 1 >= n || j + m - 1 >= n) // 検索範囲
        continue;                           // 次へ

      bool match = true; // 検索元画像と同じものがないかチェック
      for (int y = 0; y < m; y++) {
        for (int x = 0; x < m; x++) {
          if (a.at(i + y).at(j + x) != b.at(y).at(x)) // 選択範囲の要素とBを比較
            match = false;
        }
      }
      if (match)
        exist = true;
    }
  }
  if (exist) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;

  return 0;
}
Problem p03804 (C++)

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

bool match(int l, int m, int r, int c, string arr1[], string arr2[]) {
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < m; j++) {
      char char1 = arr1[i + r][j + c];
      char char2 = arr2[i][j];
      if (char1 != char2) {
        return false;
      }
    }
  }
  return true;
}

// #.#         #.  00 01   for (int i=0; i<2; i++)
//.#.  11 12  .#  10 11        for (int j=0; j<2; j++)
// #.#  21 22                         arr1[i+r][j+c]==arr2[i][j]

int main() {
  int l, m;
  cin >> l >> m;
  string arr1[l];
  string arr2[m];
  for (int i = 0; i < l; i++) {
    cin >> arr1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> arr2[i];
  }
  for (int i = 0; i <= l - m; i++) {
    for (int j = 0; j <= l - m; j++) {
      if (match(l, m, i, j, arr1, arr2)) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
}


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

bool match(int l, int m, int r, int c, string arr1[], string arr2[]) {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      char char1 = arr1[i + r][j + c];
      char char2 = arr2[i][j];
      if (char1 != char2) {
        return false;
      }
    }
  }
  return true;
}

// #.#         #.  00 01   for (int i=0; i<2; i++)
//.#.  11 12  .#  10 11        for (int j=0; j<2; j++)
// #.#  21 22                         arr1[i+r][j+c]==arr2[i][j]

int main() {
  int l, m;
  cin >> l >> m;
  string arr1[l];
  string arr2[m];
  for (int i = 0; i < l; i++) {
    cin >> arr1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> arr2[i];
  }
  for (int i = 0; i <= l - m; i++) {
    for (int j = 0; j <= l - m; j++) {
      if (match(l, m, i, j, arr1, arr2)) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  string a[n], b[m];
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      bool flag = true;
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; l++) {
          if (a[i + k][j + l] != b[k][l])
            flag = false;
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  string a[n], b[m];
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }
  for (int i = 0; i + m - 1 < n; i++) {
    for (int j = 0; j + m - 1 < n; j++) {
      bool flag = true;
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; l++) {
          if (a[i + k][j + l] != b[k][l])
            flag = false;
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03804 (C++)

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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
  int n, m;
  cin >> n >> m;

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

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

  for (int px = 0; px < n; ++px) {
    for (int py = 0; py < n; ++py) {
      int cnt = 0;

      for (int tx = 0; tx < m; ++tx) {
        for (int ty = 0; ty < m; ++ty) {
          if (px + tx - 1 >= n || py + ty - 1 >= n)
            continue;

          if (a[px + tx][py + ty] == b[tx][ty]) {
            cnt++;
          }
        }
      }

      if (cnt == m * m) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
  int n, m;
  cin >> n >> m;

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

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

  for (int px = 0; px < n; ++px) {
    for (int py = 0; py < n; ++py) {
      int cnt = 0;

      for (int tx = 0; tx < m; ++tx) {
        for (int ty = 0; ty < m; ++ty) {
          if (px + m - 1 >= n || py + m - 1 >= n)
            continue;

          if (a[px + tx][py + ty] == b[tx][ty]) {
            cnt++;
          }
        }
      }

      if (cnt == m * m) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}
Problem p03804 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a;
  vector<string> b;
  for (int k = 0; k < n; k++) {
    string s;
    cin >> s;
    a.push_back(s);
  }
  for (int k = 0; k < m; k++) {
    string s;
    cin >> s;
    b.push_back(s);
  }

  bool ans = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int count = 0;
      for (int k = 0; k < m; k++) {
        if (b.at(k) == a.at(i + k).substr(j, m)) {
          count++;
        }
      }
      if (count == m) {
        ans = true;
        break;
      }
    }
    if (ans) {
      break;
    }
  }
  ans ? cout << "Yes" << endl : cout << "No" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a;
  vector<string> b;
  for (int k = 0; k < n; k++) {
    string s;
    cin >> s;
    a.push_back(s);
  }
  for (int k = 0; k < m; k++) {
    string s;
    cin >> s;
    b.push_back(s);
  }

  bool ans = false;
  for (int i = 0; i < n - m + 1; i++) {
    for (int j = 0; j < n - m + 1; j++) {
      int count = 0;
      for (int k = 0; k < m; k++) {
        if (b.at(k) == a.at(i + k).substr(j, m)) {
          count++;
        }
      }
      if (count == m) {
        ans = true;
        break;
      }
    }
    if (ans) {
      break;
    }
  }
  ans ? cout << "Yes" << endl : cout << "No" << endl;
}
Problem p03804 (C++)

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

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

  bool flag = true;
  for (int i = 0; i < n - m + 1; i++) {
    for (int j = 0; j < n - m + 1; j++) {
      flag = true;
      for (int k = i; k < i + m; k++) {
        for (int l = j; l < j + m; l++) {
          if (a[k][l] != b[k][l]) {
            flag = false;
          }
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

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

  bool flag = true;
  for (int i = 0; i < n - m + 1; i++) {
    for (int j = 0; j < n - m + 1; j++) {
      flag = true;
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; l++) {
          if (a[k + i][l + j] != b[k][l]) {
            flag = false;
          }
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03804 (C++)

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

using namespace std;

int main() {
  int N, M;
  bool ans = false;
  string *A, *B;

  cin >> N >> M;
  A = new string[N];
  for (int n = 0; n < N; n++) {
    cin >> A[n];
  }

  B = new string[N];
  for (int m = 0; m < N; m++) {
    cin >> B[m];
  }

  int n = 0, m = 0, left = -1;
  while (n < N && m < M) {
    if (left > -1) {
      if (A[n].substr(left, M) == B[m]) {
        n++;
        m++;
      } else {
        n = n;
        m = 0;
      }
      continue;
    }

    left = A[n].find(B[m]);

    // not found
    if (left == -1) {
      n++;
      continue;
    } else {
      n++;
      m++;
    }
  }

  if (left > -1 && m == M) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  cout << endl;
  return 0;
}


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

using namespace std;

int main() {
  int N, M;
  bool ans = false;
  string *A, *B;

  cin >> N >> M;
  A = new string[N];
  for (int n = 0; n < N; n++) {
    cin >> A[n];
  }

  B = new string[N];
  for (int m = 0; m < N; m++) {
    cin >> B[m];
  }

  int n = 0, m = 0, left = -1;
  while (n < N && m < M) {
    if (left > -1) {
      if (A[n].substr(left, M) == B[m]) {
        n++;
        m++;
      } else {
        left = -1;
        n = n;
        m = 0;
      }
      continue;
    }

    left = A[n].find(B[m]);

    // not found
    if (left == -1) {
      n++;
      continue;
    } else {
      n++;
      m++;
    }
  }

  if (left > -1 && m == M) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  cout << endl;
  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
const int mod = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  rep(ai, n) {
    rep(aj, a[ai].length()) {
      bool ok = true;
      rep(bi, m) {
        rep(bj, b[bi].length()) {
          if (ai + bi > n || aj + bj > a[ai].length()) {
            ok = false;
            break;
          }
          if (a[ai + bi][aj + bj] != b[bi][bj]) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  rep(ai, n) {
    rep(aj, a[ai].length()) {
      bool ok = true;
      rep(bi, m) {
        rep(bj, b[bi].length()) {
          if (ai + bi >= n || aj + bj >= a[ai].length()) {
            ok = false;
            break;
          }
          if (a[ai + bi][aj + bj] != b[bi][bj]) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}
Problem p03804 (C++)

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

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = (1e9) + 7;
using P = pair<ll, ll>;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  bool flg = false;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      bool now = true;
      if (i + m > n)
        continue;
      if (j + m > n)
        continue;
      for (int k = 0; k < m; ++k) {
        if (a[j + k].substr(i, m) != b[j + k])
          now = false;
      }
      if (now)
        flg = true;
    }
  }
  if (flg)
    puts("Yes");
  if (!flg)
    puts("No");
  return 0;
}

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

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = (1e9) + 7;
using P = pair<ll, ll>;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  bool flg = false;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      bool now = true;
      if (i + m > n)
        continue;
      if (j + m > n)
        continue;
      for (int k = 0; k < m; ++k) {
        if (a[j + k].substr(i, m) != b[k])
          now = false;
      }
      if (now)
        flg = true;
    }
  }
  if (flg)
    puts("Yes");
  if (!flg)
    puts("No");
  return 0;
}
Problem p03804 (C++)

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

int main() {
  int n, m;
  int i, j, k, l, key, judge = 0;

  cin >> n >> m;

  vector<string> a(n, ""), b(m, "");

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

  for (i = 0; (i <= n - m) && (judge == 0); i++) {
    for (j = 0; (j <= n - m) && (judge == 0); j++) {

      key = 1;
      for (k = 0; (k < m) && (key == 1); k++) {
        for (l = 0; (l < m) && (key == 1); l++) {
          if (a[k][l] != b[i + k][j + l]) {
            key = 0;
          }
        }
      }
      if (key == 1) {
        judge = 1;
      }
    }
  }

  if (judge == 1) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

  return 0;
}

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

int main() {
  int n, m;
  int i, j, k, l, key, judge = 0;

  cin >> n >> m;

  vector<string> a(n, ""), b(m, "");

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

  for (i = 0; (i <= n - m) && (judge == 0); i++) {
    for (j = 0; (j <= n - m) && (judge == 0); j++) {

      key = 1;
      for (k = 0; (k < m) && (key == 1); k++) {
        for (l = 0; (l < m) && (key == 1); l++) {

          if (b[k][l] != a[i + k][j + l]) {
            key = 0;
          }
        }
      }
      if (key == 1) {
        judge = 1;
      }
    }
  }

  if (judge == 1) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  char a[55][55], b[55][55];
  int f, n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; i < n; j++)
      cin >> a[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++)
      cin >> b[i][j];
  for (int k = 0; k <= n - m; k++) {
    for (int l = 0; l <= n - m; l++) {
      f = 0;
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i + k][j + l] != b[i][j]) {
            f = 1;
            break;
          }
        }
        if (f == 1)
          break;
      }
      if (f == 0) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  char a[55][55], b[55][55];
  int f, n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      cin >> a[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++)
      cin >> b[i][j];
  for (int k = 0; k <= n - m; k++) {
    for (int l = 0; l <= n - m; l++) {
      f = 0;
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i + k][j + l] != b[i][j]) {
            f = 1;
            break;
          }
        }
        if (f == 1)
          break;
      }
      if (f == 0) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); i++)
#define INF 1001001001
#define LLINF 1001001001001001001
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main() {

  int n, m;
  cin >> n >> m;

  char a[n][n], b[m][m];

  rep(i, n) rep(j, n) cin >> a[i][j];
  rep(i, m) rep(j, m) cin >> b[i][j];

  bool exist = false;
  rep(i, n) {
    rep(j, n) {
      bool match = true;
      rep(k, m) {
        rep(l, m) {
          if (a[i + k][j + l] != b[k][l])
            match = false;
        }
      }
      if (match)
        exist = true;
    }
  }

  if (exist)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); i++)
#define INF 1001001001
#define LLINF 1001001001001001001
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main() {

  int n, m;
  cin >> n >> m;

  char a[n][n], b[m][m];

  rep(i, n) rep(j, n) cin >> a[i][j];
  rep(i, m) rep(j, m) cin >> b[i][j];

  bool exist = false;
  rep(i, n) {
    rep(j, n) {
      if (j + m - 1 >= n or i + m - 1 >= n)
        continue;
      bool match = true;
      rep(k, m) {
        rep(l, m) {
          if (a[i + k][j + l] != b[k][l])
            match = false;
        }
      }
      if (match)
        exist = true;
    }
  }

  if (exist)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03804 (C++)

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

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

  bool exist = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + m - 1 > n || j + m - 1 > n)
        continue;

      bool match = true;
      for (int by = 0; by < m; by++) {
        for (int bx = 0; bx < m; bx++) {
          if (a[i + by][j + bx] != b[by][bx])
            match = false;
        }
      }
      if (match)
        exist = true;
    }
  }
  cout << (exist ? "Yes" : "No") << endl;

  return 0;
}

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

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

  bool exist = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + m - 1 >= n || j + m - 1 >= n)
        continue;

      bool match = true;
      for (int by = 0; by < m; by++) {
        for (int bx = 0; bx < m; bx++) {
          if (a[i + by][j + bx] != b[by][bx])
            match = false;
        }
      }
      if (match)
        exist = true;
    }
  }
  cout << (exist ? "Yes" : "No") << endl;

  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> n;
  vector<string> a(n);
  vector<string> b(m);
  int i, j, k, l;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  int anss = 0;
  int chk = 0;

  for (i = 0; i <= n - m; i++) {
    for (j = 0; j <= n - m; j++) {
      if (a[i][j] == b[0][0]) {
        chk = 1;
        for (k = 0; k < m; k++) {
          for (l = 0; l < m; l++) {
            if (a[i + k][j + l] != b[k][l])
              chk = 0;
          }
        }
        if (chk == 1)
          anss = 1;
      }
    }
  }
  if (anss == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  int i, j, k, l;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  int anss = 0;
  int chk = 0;

  for (i = 0; i <= n - m; i++) {
    for (j = 0; j <= n - m; j++) {
      if (a[i][j] == b[0][0]) {
        chk = 1;
        for (k = 0; k < m; k++) {
          for (l = 0; l < m; l++) {
            if (a[i + k][j + l] != b[k][l])
              chk = 0;
          }
        }
        if (chk == 1)
          anss = 1;
      }
    }
  }
  if (anss == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}