alexjercan/bugnet huggingface dataset:
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("O3")
#pragma G++ optimize("O3")

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/priority_queue.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define endl '\\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define ls t[root << 1]
#define rs t[root << 1 | 1]
#define tr t[root]
#define lowbit(x) x & (-x)
#define all(x) (x).begin(), (x).end()
#define sf(x) scanf("%d", &x)
#define pf(x) printf("%d", x)
#define debug(x) cout << x << endl
#define mod(x) (x % mod + mod) % mod

template <typename T> void read(T &x) {
  x = 0;
  char ch = getchar();
  ll f = 1;
  while (!isdigit(ch)) {
    if (ch == '-')
      f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}

const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 5e5 + 7;
const int maxm = 1e3 + 7;
const int mod = 1e9 + 7;

#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// template<typename T> using ordered_set =
// tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main() {
  string s, t;
  cin >> s >> t;
  int lens = s.length();
  int lent = t.length();
  int ans = INF;
  for (int i = 0; i <= lens - lent; ++i) {
    int num = 0;
    for (int j = 0; j < lent; ++j) {
      if (s[i + j] != t[j])
        num++;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
string s, t;
// int a[100]={0};
int sum = 0;
int dfs(int x, int y) {
  for (int i = 1; i + y < t.size(); i++) {
    if (s[x + i] == t[y + i])
      sum++;
  }
}
int main() {
  cin >> s >> t;
  int len1, len2;
  len1 = s.size();
  len2 = t.size();
  int ans = len2;
  //	for(int j=0;j<len2;j++)a[t[j]-'a']=1;
  for (int i = 0; i < len1; i++) {

    if (len2 - 1 > i) {
      for (int j = 0; j <= i; j++) {
        //	if(len1-i-1<len2-j-1)break;
        if (s[i] == t[j] && len1 - i - 1 >= len2 - j - 1) {
          sum++;
          dfs(i, j);
          ans = min(ans, len2 - sum);
          sum = 0;
        }
      }
    } else {
      for (int j = 0; j < len2; j++) {
        if (len1 - i - 1 < len2 - j - 1)
          j = len2 - (len1 - i) - 1;
        if (s[i] == t[j]) {
          sum++;
          dfs(i, j);
          ans = min(ans, len2 - sum);
          sum = 0;
        }
      }
    }
  }
  cout << ans;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  string S, T;
  cin >> S >> T;

  int n = T.size();
  int ans = 1e9;
  for (int i = 0; i <= (int)S.size() - n; i++) {
    string s = S.substr(i, n);
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (s[j] != T[j])
        sum++;
    }
    ans = min(ans, sum);
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  string S, T;
  cin >> S >> T;

  int n = T.size();
  int ans = 1e9;
  for (int i = 0; i < (int)S.size() - n; i++) {
    string s = s.substr(i, n);
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (S[i + j] != T[j])
        sum++;
    }
    ans = min(ans, sum);
  }

  cout << ans << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

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

  vector<int> V;
  int P = 0;
  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < M; j++) {
      if (S.at(i + j) == T.at(j))
        P++;
    }
    V.push_back(M - P);
    P = 0;
  }

  sort(V.begin(), V.end());
  cout << V.at(0) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

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

  vector<int> V;
  int P = 0;
  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < M; j++) {
      if (S.at(i + j) == T.at(j))
        P++;
    }
    V.push_back(M - P);
    P = 0;
  }

  sort(V.begin(), V.end());
  cout << V.at(1) << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
#define endl "\\n"
#define pi acos(-1)
#define ll long long
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int q = 1; // cin>>q;
  while (q--) {
    solve();
  }
  return 0;
}
void solve() {
  string s, t;
  cin >> s >> t;
  int a = t.length(), g = INT_MAX, p = 0, k = 0;
  // cout<<s.length()-t.length()<<endl;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    k = -1;
    for (int j = i; j < t.length() + i; j++) {
      k++;
      if (s[j] != t[k])
        p++;
    }
    g = min(p, g);
    p = 0;
  }
  cout << g << endl;
}


Error: WA

Fixed submission:


#include <bits/stdc++.h>
#define endl "\\n"
#define pi acos(-1)
#define ll long long
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int q = 1; // cin>>q;
  while (q--) {
    solve();
  }
  return 0;
}
void solve() {
  string s, t;
  cin >> s >> t;
  int a = t.length(), g = INT_MAX, p = 0, k = 0;
  for (int i = 0; i < s.length() - t.length(); i++) {
    a = a + i;
    k = -1;
    for (int j = i; j < a; j++) {
      k++;
      if (s[j] != t[k])
        p++;
    }
    g = min(p, g);
    p = 0;
  }
  cout << g << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

/* BABA JAGAAAAAA  */

#include <bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL)
#define l1 long
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 3;
int check(vector<char> v1, vector<char> v2) {
  int count = 0;
  for (int i = 0; i < min(v1.size(), v2.size()); i++) {
    if (v1[i] != v2[i]) {
      continue;
    }
    count++;
  }
  return count;
}
int main() {
  fast;
  // 2nd//
  string s, t;
  cin >> s >> t;
  int l, r;
  l = 0;
  r = 0;
  vector<char> v;
  vector<char> v1;
  for (char f : t)
    v1.pb(f);

  int maxi = 0;
  while (r < t.size()) {
    v.pb(s[r]);
    r++;
  }
  int n = check(v, v1);
  //  cout<<n;
  //   for(int i=0; i<v.size(); i++)
  //   cout<<v[i]<<" ";
  maxi = max(maxi, n);
  //   cout<<maxi;

  while (r < s.size()) {
    v.pb(s[r]);
    v.erase(v.begin() + l);

    //  for(int i=0; i<v.size(); i++)
    //   cout<<v[i];
    //   cout<<endl;
    int n = check(v, v1);
    maxi = max(maxi, n);
    //  l++;
    r++;
  }

  cout << t.size() - maxi << endl;

  return 0;
}


Error: 0

Fixed submission:

/* BABA JAGAAAAAA  */

#include <bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL)
#define l1 long
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 3;
int check(vector<char> v1, vector<char> v2) {
  int count = 0;
  for (int i = 0; i < min(v1.size(), v2.size()); i++) {
    if (v1[i] != v2[i]) {
      continue;
    }
    count++;
  }
  return count;
}
int main() {
  fast;
  // 2nd//
  string s, t;
  cin >> s >> t;
  int d = t.length();
  int l, r;
  l = 0;
  r = d;
  vector<char> v;
  vector<char> v1;
  for (char f : t)
    v1.pb(f);

  int maxi = 0;
  while (l < r) {
    v.pb(s[l]);
    l++;
  }
  int n = check(v, v1);
  //  cout<<n;
  //   for(int i=0; i<v.size(); i++)
  //   cout<<v[i]<<" ";
  maxi = max(maxi, n);
  l = 0;
  //   cout<<maxi;

  while (r < s.size()) {
    v.pb(s[r]);

    v.erase(v.begin() + l);
    int n = check(v, v1);
    maxi = max(maxi, n);
    l++, r++;
  }

  cout << d - maxi << endl;

  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const char nl = '\\n';

int main() {
  string s, t;
  cin >> s >> t;
  int cnt = 1001;
  for (int i = 0; i + t.length() <= s.length(); ++i) {
    string ans = s.substr(i, t.length());
    int res = 0;
    for (int j = 0; j < t.length(); ++j) {
      if (t[j] != ans[j]) {
        res++;
      }
    }
    cnt = min(cnt, res);
  }
  cout << cnt << nl;
}

Error: -11

Fixed submission:

/* bimillahir rahmanir rahim...
 * AUTHOR
 * mubin_akib */
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define REP(i, a, b) for (int i = a; i <= (b); ++i)
#define trav(a, x) for (auto &a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\\n';

ll solve() {
  string s, t;
  cin >> s >> t;
  int cnt = 1001;
  for (int i = 0; i + t.length() <= s.length(); ++i) {
    string ans = s.substr(i, t.length());
    int res = 0;
    for (int j = 0; j < t.length(); ++j) {
      if (t[j] != ans[j]) {
        res++;
      }
    }
    cnt = min(cnt, res);
  }
  cout << cnt << nl;
}

int main() {
#ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  int sl = s.length();
  int tl = t.length();
  vector<int> v(sl - tl + 1);
  for (int i = 0; i <= sl - tl; i++) {
    for (int j = 0; j < tl; j++) {
      if (s[i + j] == t[j])
        v[i]++;
    }
  }
  cout << tl - *max_element(v.begin(), v.end());
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  int sl = s.length();
  int tl = t.length();
  vector<int> v(sl - tl);
  for (int i = 0; i < sl - tl; i++) {
    for (int j = 0; j < tl; j++) {
      if (s[i + j] == t[j])
        v[i]++;
    }
  }
  cout << tl - *max_element(v.begin(), v.end());
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define Vsort(a) sort(a.begin(), a.end())
#define rep(i, n) for (long long int i = 0; i < (n); i++)
#define ll long long
#define P pair<int, int>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int count = s.size() - t.size() + 1;
  vector<long long int> wa(count);
  int size = t.size();
  rep(i, count) {
    rep(j, t.size()) {
      char S, T;
      S = s.at(i + j);
      T = t.at(j);
      if (S != T)
        wa[i]++;
    }
  }
  Vsort(wa);
  cout << wa[0] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define Vsort(a) sort(a.begin(), a.end())
#define rep(i, n) for (long long int i = 0; i < (n); i++)
#define ll long long
#define P pair<int, int>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int count = s.size() - t.size();
  vector<long long int> wa(count);
  int size = t.size();
  rep(i, count) {
    rep(j, size) {
      char S, T;
      S = s.at(i + j);
      T = t.at(j);
      if (S != T)
        wa[i]++;
    }
  }
  Vsort(wa);
  cout << wa[0] << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

int main() {
  int ans = INF;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size() - T.size() + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] != T[j]) {
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

int main() {
  int ans = INF;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size() - T.size() - 1; i++) {
    int cnt = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] != T[j]) {
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int i = 0;
  int z = t.size();
  while (s.size() - i >= t.size()) {
    int r = 0;
    for (int j = 0; j < t.size(); j++)
      if (s[i + j] != t[j])
        r++;

    if (r < z)
      z = r;
    i++;
  }
  cout << z << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  string s, t;
  int i = 0;
  int z = t.size();
  while (s.size() - i >= t.size()) {
    int r = 0;
    for (int j = 0; j < t.size(); j++)
      if (s[i + j] != t[j])
        r++;

    if (r < z)
      z = r;
    i++;
  }
  cout << z << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

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

  int ns = s.size();
  int nt = t.size();
  vector<int> match(ns - nt + 2);
  match[0] = nt;

  for (int i = 0; i < ns - nt + 1; i++) {
    int mat = nt;
    for (int j = 0; j < nt; j++) {
      if (t[j] == s[i + j]) {
        mat--;
      }
    }
    match[i + 1] = min(match[i], mat);
  }

  cout << match[ns - nt + 1] << endl;
}


Error: 0

Fixed submission:

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

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

  int ns = s.size();
  int nt = t.size();
  vector<int> match(ns - nt + 1);
  match[0] = nt;

  for (int i = 0; i < ns - nt + 1; i++) {
    int mat = nt;
    for (int j = 0; j < nt; j++) {
      if (t[j] == s[i + j]) {
        mat--;
      }
    }
    match[i + 1] = min(match[i], mat);
  }

  cout << match[ns - nt + 1] << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

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

  int sm = s.size();
  int tm = t.size();
  int ans = t.size();

  rep(i, sm - tm + 1) {
    int cnt = 0;
    rep(j, tm) {
      if (s[i + j] != t[j])
        cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

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

  int ans = t.size();

  rep(i, s.size() - t.size() - 1) {
    int cnt = 0;
    rep(j, t.size()) {
      if (s[i + j] == t[j])
        cnt++;
    }
    ans = min(ans, ans - cnt);
  }

  cout << ans << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define Nayon                                                                  \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / gcd(a, b)) * b
#define v_sum(a) accumulate(a.begin(), a.end(), 0)
#define v_max(a) *max_element(a.begin(), a.end())
#define v_min(a) *min_element(a.begin(), a.end())
#define v_uni(a) a.erase(unique(a.begin(), a.end()), a.end())

using namespace std;

int main() {
  Nayon;
  string s, t;
  int i, j, cnt = 0, l, k, x = 100000;
  cin >> s >> t;
  l = t.size();
  for (i = 0; i < s.size() - l + 1; i++) {
    for (j = 0; j < l; j++) {
      if (s[i + j] != t[j]) {
        cnt++;
      }
    }
    x = min(x, cnt);
    cnt = 0;
  }
  cout << x << nl;
  return 0;
}

// Happy Coding.........

Error: 0

Fixed submission:

// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define Nayon                                                                  \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / gcd(a, b)) * b
#define v_sum(a) accumulate(a.begin(), a.end(), 0)
#define v_max(a) *max_element(a.begin(), a.end())
#define v_min(a) *min_element(a.begin(), a.end())
#define v_uni(a) a.erase(unique(a.begin(), a.end()), a.end())

using namespace std;

int main() {
  Nayon;
  string s, t;
  int i, j, cnt = 0, l, k, x = 100000;
  cin >> s >> t;
  l = t.size();
  for (i = 0; i < s.size() - l - 1; i++) {
    k = i;
    for (j = 0; j < l; j++) {
      if (s[k] != t[j]) {
        cnt++;
      }
      k++;
    }
    x = min(x, cnt);
    cnt = 0;
  }
  cout << x << nl;
  return 0;
}

// Happy Coding........
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
  string s, t;
  cin >> s >> t;
  int i = 0, sz;
  if (s.size() == t.size()) {
    sz = 1;
  } else {
    sz = s.size() - t.size();
  }
  vector<int> zure(sz, 0);
  do {
    rep(j, t.size()) {
      if (s[i + j] != t[j]) {
        zure[i]++;
      }
    }
    i++;
  } while (i < s.size() - t.size());
  sort(zure.begin(), zure.end());
  cout << zure[0] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
  string s, t;
  cin >> s >> t;
  int i = 0;
  vector<int> zure(s.size() - t.size(), 0);
  do {
    rep(j, t.size()) {
      if (s[i + j] != t[j]) {
        zure[i]++;
      }
    }
    i++;
  } while (i < s.size() - t.size());
  sort(zure.begin(), zure.end());
  cout << zure[0] << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int kekka, kari;
  kekka = 0;
  kari = 0;
  string iti, ni;
  cin >> iti >> ni;
  for (int i = 0; i <= iti.size() - ni.size(); i++) {
    for (int s = 0; s < ni.size(); s++) {
      if (iti.at(i + s) == ni.at(s)) {
        kari++;
      }
    }
    if (kekka < kari) {
      kekka = kari;
    }
    kari = 0;
  }
  cout << ni.size() - kekka << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

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

int main() {
  int kekka, kari;
  kekka = 0;
  kari = 0;
  string iti, ni;
  cin >> iti >> ni;
  for (int i = 0; i < iti.size() - ni.size(); i++) {
    for (int s = 0; s <= ni.size(); s++) {
      if (iti.at(i + s) == ni.at(s)) {
        kari++;
      }
    }
    if (kekka < kari) {
      kekka = kari;
    }
    kari = 0;
  }
  cout << ni.size() - kekka << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      string s,
      t;
  cin >> s >> t;
  int ans = 0;
  vector<int> vec;
  rep(i, s.size() - t.size() + 1) {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j])
        cnt++;
    }
    vec.push_back(cnt);
  }
  sort(vec.begin(), vec.end());
  cout << t.size() - vec[vec.size() - 1] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      string s,
      t;
  cin >> s >> t;
  int ans = 0;
  vector<int> vec;
  rep(i, s.size() - t.size()) {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j])
        cnt++;
    }
    vec.push_back(cnt);
  }
  sort(vec.begin(), vec.end());
  cout << t.size() - vec[vec.size() - 1] << endl;
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string S, T;
  cin >> S >> T;
  vector<int> N(S.size() - T.size() + 1);
  for (int i = 0; i <= S.size() - T.size(); i++) {
    for (int j = 0, k = i; j < T.size(); j++, k++) {
      if (S.at(k) != T.at(j)) {
        N.at(i)++;
      }
    }
    // cout << N.at(i) << endl;
  }
  sort(N.begin(), N.end());
  if (S.size() - T.size() != 0) {
    cout << N.at(0) << endl;
  } else {
    cout << N.at(0) << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  string S, T;
  cin >> S >> T;
  vector<int> N(S.size() - T.size());
  for (int i = 0; i < S.size() - T.size(); i++) {
    for (int j = 0, k = i; j < T.size(); j++, k++) {
      if (S.at(k) != T.at(j)) {
        N.at(i)++;
      }
    }
    // cout << N.at(i) << endl;
  }
  sort(N.begin(), N.end());
  cout << N.at(0) << endl;
}