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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I, A, B) for (ll I = ll(A); I < ll(B); ++I)

struct RollingHash {
  ll M;
  vector<ll> H, B;
  RollingHash(string s, ll b = 1009LL, ll m = 1000000007LL) {
    M = m;
    ll n = s.size();
    B.resize(n + 1);
    H.resize(n + 1, 0);
    B[0] = 1;
    for (ll i = 0; i < n; i++) {
      B[i + 1] = (B[i] * b) % M;
      H[i + 1] = (H[i] * b % M + s[i]) % M;
    }
  }
  ll GetHash(ll l, ll r) { // [l,r)
    return (H[r] + (M - B[r - l] * H[l] % M)) % M;
  }
};

int main() {
  string t, p;
  cin >> t >> p;
  RollingHash T(t);
  RollingHash P(p);

  ll lt = t.size();
  ll lp = p.size();
  FOR(i, 0, lt - lp + 1) {
    if (T.GetHash(i, i + lp) == P.GetHash(0, lp)) {
      cout << i << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I, A, B) for (ll I = (A); I < (B); ++I)
#define POSL(x, v)                                                             \\
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // ai>=v  x is sorted
#define POSU(x, v)                                                             \\
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // ai>v  x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v))        // x is sorted
#define SORT(x) (sort(x.begin(), x.end()))         // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(), x.end()))       // reverse
#define TO(x, t, f) ((x) ? (t) : (f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x, a) fill(x.begin(), x.end(), a)
#define FILA(ar, N, a) fill(ar, ar + N, a)
#define NEXTP(x) next_permutation(x.begin(), x.end())
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return ((a / c) * (b / c) * c);
} // saisyo kobaisu
#define pb push_back
#define pri(aa) cout << (aa) << endl
const ll INF = 1e9 + 7;
const ll N = 100002;
string t, p;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t >> p;
  if (t.size() < p.size())
    return 0;
  FOR(i, 0, t.size() - p.size() + 1) {
    if (t.substr(i, p.size()) == p)
      pri(i);
  }
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <string>

using namespace std;
#define fordebug                                                               \\
  int hoge;                                                                    \\
  cin >> hoge;
#define DEKAI 1000000007
#define INF 200000000
#define int long long
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)

vector<int> match(string a, string b) {
  int al = a.size(), bl = b.size();
  vector<int> ans;
  if (al < bl)
    return ans;
  int t = 1;
  int ah = 0, bh = 0;
  lp(i, bl) {
    int x = a[i];
    int y = b[i];
    ah = ah * DEKAI + x;
    bh = bh * DEKAI + y;
    t *= DEKAI;
  }
  if (ah == bh)
    ans.push_back(0);
  for (int i = 0; i + bl < al; i++) {
    ah = ah * DEKAI + a[i + bl] - a[i] * t;
    if (ah == bh)
      ans.push_back(i + 1);
  }
  return ans;
}

signed main() {
  string t, p;
  cin >> t >> p;
  vector<int> m = match(t, p);
  lp(i, m.size()) cout << m[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define fordebug                                                               \\
  int hoge;                                                                    \\
  cin >> hoge;
#define DEKAI 1000000007;
#define INF 200000000
#define int long long
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)

string t, p;
int a[500];
int search(int i) {
  int cnt = 0;
  for (int j = 0; j < p.size(); j++) { /*
                   int hogehoge;
                   cout<<p[p.size()-j-1]<<" "<<t[i-j]<<i<<j<<endl;
                   cin>>hogehoge;
                   cout<<a[t[i-j]]-j;*/
    if (p[p.size() - j - 1] != t[i - j]) {
      return a[t[i - j]] - j;
    }
  }
  return INF;
}

signed main() {
  cin >> t >> p;
  lp(i, 500) a[i] = p.size();
  for (int i = 0; i < p.size(); i++) {
    a[p[i]] = p.size() - i - 1;
  }
  for (int i = p.size() - 1; i < t.size(); 1) {
    if (a[t[i]] == 0) {
      int x = search(i);
      if (x == INF) {
        cout << i - p.size() + 1 << endl;
        i++;
      } else {
        if (x < 1)
          x = 1;
        i += x;
      }
    } else
      i += a[t[i]];
  }
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string T, P;
  cin >> T >> P;
  if (T.size() < P.size())
    return 0;
  for (long i = 0; i < T.size() - P.size() + 1; i++) {
    if (T[i] == P[0]) {
      if (T.substr(i, P.size()) == P)
        printf("%d\\n", i);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string T, P;
  cin >> T >> P;
  if (T.size() < P.size())
    return 0;
  for (long i = 0; i < T.size() - P.size() + 1; i++) {
    if (T[i] == P[0]) {
      if (T.substr(i, P.size()) == P)
        cout << i << endl;
    }
  }
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;

void Rolling_Hash(const string &a, const string &b) {
  const ull B = 100000007;
  int al = a.length(), bl = b.length();
  if (al > bl)
    return;

  ull t = 1;
  for (int i = 0; i < al; i++)
    t *= B;

  ull ah = 0, bh = 0;
  for (int i = 0; i < al; i++)
    ah = ah * B + a[i];
  for (int i = 0; i < al; i++)
    bh = bh * B + b[i];

  for (int i = 0; i + al <= bl; i++) {
    if (ah == bh)
      cout << i << endl;
    if (i + al < bl)
      bh = bh * B + b[i + al] - b[i] * t;
  }
}

int main() {
  string T, P;
  cin >> T >> P;
  Rolling_Hash(P, T);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;

void Rolling_Hash(const string &a, const string &b) {
  const ull B = 100000007;
  int al = a.length(), bl = b.length();
  if (al > bl)
    return;

  ull t = 1;
  for (int i = 0; i < al; i++)
    t *= B;

  ull ah = 0, bh = 0;
  for (int i = 0; i < al; i++)
    ah = ah * B + a[i];
  for (int i = 0; i < al; i++)
    bh = bh * B + b[i];

  for (int i = 0; i + al <= bl; i++) {
    if (ah == bh && a == b.substr(i, al))
      cout << i << endl;
    if (i + al < bl)
      bh = bh * B + b[i + al] - b[i] * t;
  }
}

int main() {
  string T, P;
  cin >> T >> P;
  Rolling_Hash(P, T);
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

template <typename T> std::vector<int> kmp(const T &target) {
  std::vector<int> result(target.size());
  if (result.size() == 1) {
    result[0] = -1;
    return result;
  }
  int longest_prefix{0};
  result[0] = -1;
  result[1] = 0;
  for (auto i = 2; i < target.size(); ++i) {
    while (longest_prefix >= 0 && target[i - 1] != target[longest_prefix]) {
      longest_prefix = result[longest_prefix];
    }
    result[i] = ++longest_prefix;
  }
  return result;
}
template <typename T>
std::vector<int> match_position(const T &word, const T &target) {
  const auto shift = kmp(target);
  int it = 0;
  std::vector<int> result;
  for (auto iw = 0; iw < word.size(); ++iw) {
    while (it >= 0 && word[iw] != target[it]) {
      it = shift[it];
    }
    if (++it == target.size()) {
      result.push_back(iw - it + 1);
      it = shift.back();
      while (it >= 0 && word[iw] != target[it]) {
        it = shift[it];
      }
      ++it;
    }
  }
  return result;
}
int main() {
  std::string word, target;
  std::cin >> word >> target;
  for (auto pos : match_position(word, target)) {
    std::cout << pos << '\\n';
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
class Match_pattern {
  const std::string m_pattern;
  std::vector<int> m_sub_string;

public:
  Match_pattern(const std::string &pattern)
      : m_pattern{pattern}, m_sub_string(pattern.size()) {
    m_sub_string[0] = -1;
    if (m_pattern.size() > 1)
      m_sub_string[1] = 0;
    for (auto idx = 2; idx < m_pattern.size(); ++idx) {
      m_sub_string[idx] =
          (m_pattern[m_sub_string[idx - 1]] == m_pattern[idx - 1])
              ? m_sub_string[idx - 1] + 1
          : (m_pattern[0] == m_pattern[idx - 1]) ? 1
                                                 : 0;
    }
  }
  size_t size() const { return m_pattern.size(); }
  int back_track(int missmatch_index) const {
    return m_sub_string[missmatch_index];
  }
  char operator[](int index) const { return m_pattern[index]; }
};
int main() {
  std::string target, pattern;
  std::cin >> target >> pattern;
  Match_pattern match_pattern(pattern);
  for (auto i = 0; i + match_pattern.size() <= target.size();) {
    bool is_matched = true;
    for (auto j = 0; j < match_pattern.size(); ++j) {
      if (target[i + j] != match_pattern[j]) {
        i += j - match_pattern.back_track(j);
        is_matched = false;
        break;
      }
    }
    if (is_matched)
      std::cout << i++ << std::endl;
  }
}
Problem p02248 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long lli;
typedef unsigned long long ull;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<vector<bool>> matb;
typedef vector<string> vst;
typedef pair<lli, lli> pll;
typedef pair<double, double> pdd;

string t;
string p;

const ull b = 1000000007;
ull hsh = 0;
ull cmp = 0;
vll vb;

int main() {
  cin >> t >> p;
  if (t.size() < p.size())
    return 0;
  vb = vll(p.size());
  vb[0] = 1;
  for (lli i = 1; i < p.size(); i++) {
    vb[i] = vb[i - 1] * b;
  }
  for (lli i = 0; i < p.size(); i++) {
    hsh += ((lli)p[i]) * vb[p.size() - i - 1];
    cmp += ((lli)t[i]) * vb[p.size() - i - 1];
  }
  for (lli i = 0; i < t.size() - p.size(); i++) {
    if (hsh == cmp)
      cout << i << endl;
    cmp -= vb.back() * t[i];
    cmp *= b;
    cmp += t[i + p.size()];
  }
  if (cmp == hsh)
    cout << t.size() - p.size() << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long lli;
typedef unsigned long long ull;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<vector<bool>> matb;
typedef vector<string> vst;
typedef pair<lli, lli> pll;
typedef pair<double, double> pdd;

string t;
string p;

const ull b = 1000000007;
ull hsh = 0;
ull cmp = 0;
vll vb;

int main() {
  cin >> t >> p;
  vb = vll(p.size());
  vb[0] = 1;
  for (lli i = 1; i < p.size(); i++) {
    vb[i] = vb[i - 1] * b;
  }
  for (lli i = 0; i < p.size(); i++) {
    hsh += ((lli)p[i]) * vb[p.size() - i - 1];
    cmp += ((lli)t[i]) * vb[p.size() - i - 1];
  }
  for (lli i = 0; i < t.size() - p.size(); i++) {
    if (hsh == cmp)
      cout << i << endl;
    cmp -= vb.back() * t[i];
    cmp *= b;
    cmp += t[i + p.size()];
  }
  if (cmp == hsh)
    cout << t.size() - p.size() << endl;
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <map>
#include <math.h>

#define SENTINEL 1000000001

#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)

using namespace std;

typedef pair<int, int> pii;

int jt[10001];

int main() {
  map<char, int> mt;
  string T, P;
  cin >> T >> P;

  jt[0] = -1;
  jt[1] = 0;
  int i = 2, j = 0;
  int k = 0;
  while (i <= P.size()) {
    if (P[i - 1] == P[j]) {
      jt[i] = j + 1;
      ++i;
      ++j;
    } else if (j > 0) {
      j = jt[j];
    } else {
      jt[i++] = 0;
    }
  }

  i = j = 0;
  while (i < T.size()) {
    if (T[i] == P[j]) {
      ++i;
      ++j;
      if (j == P.size()) {
        cout << i - P.size() << '\\n';
        j = jt[j];
      }
    } else if (j == 0) {
      ++i;
    } else {
      j = jt[j];
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <map>
#include <math.h>

#define SENTINEL 1000000001

#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)

using namespace std;

typedef pair<int, int> pii;

int main() {
  map<char, int> mt;
  string T, P;
  cin >> T >> P;

  for (int i = 0; i != P.size(); i++) {
    mt[P[i]] = P.size() - i;
  }

  int k = 0;
  while (k + P.size() <= T.size()) {
    for (int i = 0; i != P.size(); i++) {
      if (T[k + i] != P[i]) {
        if (k + P.size() < T.size()) {
          if (mt.find(T[k + P.size()]) == mt.end()) {
            k += P.size();
          } else {
            k += mt[T[k + P.size()]];
          }
        } else {
          k++;
        }
        break;
      }
      if (i == P.size() - 1) {
        printf("%d\\n", k);
        k++;
      }
    }
  }

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

#include <iostream>
#include <string>

using namespace std;

void sringSearch(string, string);
void kmpSearch(string T, string P);

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

  kmpSearch(T, P);

  return 0;
}

void sringSearch(string T, string P) {
  int k = T.length() - P.length() + 1;
  for (int i = 0; i < k; ++i) {
    if (T.substr(i, P.length()) == P) {
      cout << i << endl;
    }
  }
}

void kmpSearch(string T, string P) {
  // construct dfs
  int dfa[P.length() + 1][256] = {0};
  int x = 0;
  dfa[0][P[0]] = 1;
  for (int i = 1; i < P.length(); ++i) {
    // mismatch case
    for (int j = 0; j < 256; ++j) {
      dfa[i][j] = dfa[x][j];
    }
    // match case
    dfa[i][P[i]] = i + 1;
    // restart state
    x = dfa[x][P[i]];
  }
  // final mismatch case
  for (int j = 0; j < 256; ++j) {
    dfa[P.length()][j] = dfa[x][j];
  }

  // search
  int s = 0;
  for (int k = 0; k < T.length(); ++k) {
    s = dfa[s][T[k]];
    if (s == P.length())
      cout << k - P.length() + 1 << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

void sringSearch(string, string);

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

  sringSearch(T, P);

  return 0;
}

void sringSearch(string T, string P) {
  int k = T.length() - P.length() + 1;
  for (int i = 0; i < k; ++i) {
    if (T.substr(i, P.length()) == P) {
      cout << i << endl;
    }
  }
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string T, P;
  int Tlen, Plen;

  cin >> T >> P;
  Tlen = T.size();
  Plen = P.size();

  for (int i = 0; i <= Tlen - Plen; i++) {
    if (T[i] == P[0]) {
      if (P == T.substr(i, Plen)) {
        printf("%d", i);
        puts("");
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string T, P;
  int Tlen, Plen;

  cin >> T >> P;
  Tlen = T.size();
  Plen = P.size();

  for (int i = 0; i <= Tlen - Plen; i++) {
    if (T[i] == P[0]) {
      if (P == T.substr(i, Plen)) {
        cout << i << endl;
      }
    }
  }

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

#include <cstdio>
#include <cstring>

char T[1000001], P[10001];
int n, m;     // T:text, P:pattern, n:T's length, m:P's length
int F[10001]; // Prefix Function

void Prefix_Table(char P[], int m) {
  int i = 1, j = 0;
  F[0] = 0;
  while (i < m) {
    if (P[i] == P[j]) {
      F[i] = j + 1;
      i++;
      j++;
    } else if (j > 0)
      j = F[j - 1];
    else {
      F[i] = 0;
      i++;
    }
  }
}

int KMP(char T[], int n, char P[], int m) {
  int i = 0, j = 0;
  Prefix_Table(P, m);
  while (i < n) {
    if (T[i] == P[j]) {
      if (j == m - 1)
        printf("%d\\n", i - j);
      i++;
      j++;

    } else if (j > 0)
      j = F[j - 1];
    else
      i++;
  }
  return -1;
}

int main() {
  scanf("%s", T);
  scanf("%s", P);
  n = strlen(T);
  m = strlen(P);
  KMP(T, n, P, m);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

char T[10000001], P[10001];
int n,
    m; // T???????????????????????????P???????????????????????????n???????????????????????????????????°???m???????????????????????????????????°

int BruteForceStringMatch(char T[], char P[], int m, int i) {
  int j = 0;
  while (j < m && P[j] == T[i + j])
    j = j + 1;
  if (j == m)
    return i;
  return -1;
}

int main() {
  scanf("%s", T);
  scanf("%s", P);
  n = strlen(T);
  m = strlen(P);
  for (int i = 0; i < n; i++) {
    int match_point = BruteForceStringMatch(T, P, m, i);
    if (match_point != -1)
      printf("%d\\n", match_point);
  }
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <string>
using namespace std;

// typedef unsigned long long ull;

void RabinCarp(string T, string P, int d) {
  int n = T.size();
  int m = P.size();
  int h = 1;
  int p = 0;
  int t[n];
  t[0] = 0;

  for (int i = 0; i < m - 1; i++) {
    h = h * d;
  }
  for (int i = 0; i < m; i++) {
    p = d * p + P[i];
    t[0] = d * t[0] + T[i];
  }

  for (int s = 0; s < n - m + 1; s++) {
    if (p == t[s]) {
      cout << s << endl;
    }
    if (s < n - m) {
      t[s + 1] = d * (t[s] - T[s] * h) + T[s + m];
    }
  }
}

int main() {
  int d = 167;
  string T, P;
  cin >> T >> P;

  RabinCarp(T, P, d);

  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
using namespace std;

// typedef unsigned long long ull;

void RabinCarp(string T, string P, int d) {
  int n = T.size();
  int m = P.size();
  int h = pow(d, m - 1);
  int p = 0;
  int t[n];
  t[0] = 0;

  for (int i = 0; i < m; i++) {
    p = d * p + P[i];
    t[0] = d * t[0] + T[i];
  }

  for (int s = 0; s < n - m + 1; s++) {
    if (p == t[s]) {
      if (P == T.substr(s, m)) {
        cout << s << endl;
      }
    }
    if (s < n - m) {
      t[s + 1] = d * (t[s] - T[s] * h) + T[s + m];
    }
  }
}

int main() {
  int d = 0;
  string T, P;
  cin >> T >> P;

  RabinCarp(T, P, d);

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

#include <iostream>

#define B (1000000007ULL)
using namespace std;
typedef unsigned long long ull;

int h, w, r, c;
char t[1000][1001], p[1000][1001];
ull th[1000][1000], ph[1000];
int st[1001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  cin.ignore();
  for (int i = 0; i < h; i++)
    cin.getline(t[i], 1001);
  cin >> r >> c;
  cin.ignore();
  for (int i = 0; i < r; i++)
    cin.getline(p[i], 1001);

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      ph[i] = ph[i] * B + p[i][j];
    }
  }
  ull bn = B;
  for (int i = 1; i < c; i++)
    bn *= B;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < c; j++)
      th[i][0] = th[i][0] * B + t[i][j];
    for (int j = 0; j < w - c; j++)
      th[i][j + 1] = th[i][j] * B - t[i][j] * bn + t[i][j + c];
  }
  for (int y = 0; y <= h - r; y++) {
    for (int x = 0; x <= w - c; x++) {
      int i;
      for (i = 0; i < r && th[y + i][x] == ph[i]; i++)
        ;
      if (i == r)
        cout << y << ' ' << x << '\\n';
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int h, w, r, c;
char t[1000][1001], p[1000][1001];
int st[1001];
vector<int> li;

void kmp_table(char *w) {
  int i = 2, j = 0;
  st[0] = st[1] = 0;
  while (i <= c) {
    if (w[i - 1] == w[j])
      st[i++] = ++j;
    else if (j > 0)
      j = st[j];
    else
      st[i++] = 0;
  }
}

void kmp_search(char *s, char *t) {
  int p = 0, i = 0;
  li.resize(0);
  while (p <= w) {
    if (t[i] == s[p]) {
      ++p;
      ++i;
      if (i == c) {
        li.push_back(p - c);
        i = st[c];
      }
    } else {
      if (i == 0)
        ++p;
      i = st[i];
    }
  }
}

bool check(int x, int y) {
  for (int i = 1; i < r; i++) {
    if (memcmp(t[y + i] + x, p[i], c))
      return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  cin.ignore();
  for (int i = 0; i < h; i++)
    cin.getline(t[i], 1001);
  cin >> r >> c;
  cin.ignore();
  for (int i = 0; i < r; i++)
    cin.getline(p[i], 1001);
  kmp_table(p[0]);

  for (int y = 0; y <= h - r; y++) {
    kmp_search(t[y], p[0]);
    for (int i = 0, n = li.size(); i < n; i++) {
      int x = li[i];
      if (check(x, y)) {
        cout << y << ' ' << x << '\\n';
      }
    }
  }
  return 0;
}