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

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

using namespace std;
typedef long long int ll;
string S, T;

bool f(string s, string t) {
  for (int i = 0; i < t.size(); i++) {
    if (s[i] == '?')
      continue;
    if (s[i] == t[i])
      continue;
    return false;
  }
  return true;
}
void g(string &s, int n, string t) {
  for (int i = 0; i < t.size(); i++) {
    s[n + i] = t[i];
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      s[i] = 'a';
  }
}
int main() {
  cin >> S >> T;

  for (int i = S.size() - T.size(); i; i--) {
    if (f(S.substr(i), T)) {
      g(S, i, T);
      break;
    }
  }
  if (S.find_first_of('?') == string::npos) {
    cout << S << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }

  return 0;
}


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

using namespace std;
typedef long long int ll;
string S, T;

bool f(string s, string t) {
  for (int i = 0; i < t.size(); i++) {
    if (s[i] == '?')
      continue;
    if (s[i] == t[i])
      continue;
    return false;
  }
  return true;
}
void g(string &s, int n, string t) {
  for (int i = 0; i < t.size(); i++) {
    s[n + i] = t[i];
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      s[i] = 'a';
  }
}
int main() {
  cin >> S >> T;

  for (int i = S.size() - T.size(); i >= 0; i--) {
    if (f(S.substr(i), T)) {
      g(S, i, T);
      break;
    }
  }
  if (S.find_first_of('?') == string::npos) {
    cout << S << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef long long ll;
typedef priority_queue<int> pq;
int main(void) {
  string encrypt_S, T;
  cin >> encrypt_S >> T;
  int tsize = T.size();
  vector<string> probabilities;
  for (int i = 0; i <= encrypt_S.size() - tsize; i++) {
    probabilities.push_back(encrypt_S.substr(i, tsize));
  }
  int index = -1;
  rep(i, probabilities.size()) {
    bool found = true;
    int c;
    for (c = 0; c < tsize; c++) {
      char now = probabilities[i][c];
      if (now == '?')
        continue;
      if (now != T[c]) {
        found = false;
        break;
      }
    }
    if (found) {
      index = i;
    }
  }
  if (index == -1)
    cout << "UNRESTORABLE" << endl;
  else {
    for (int k = index; k < index + tsize; k++) {
      encrypt_S[k] = T[k - index];
    }

    for (int k = 0; k < encrypt_S.size(); k++) {
      cout << ((encrypt_S[k] == '?') ? 'a' : encrypt_S[k]);
    }
    cout << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef long long ll;
typedef priority_queue<int> pq;
int main(void) {
  string encrypt_S, T;
  cin >> encrypt_S >> T;
  int tsize = T.size();
  if (tsize > encrypt_S.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  vector<string> probabilities;
  for (int i = 0; i <= encrypt_S.size() - tsize; i++) {
    probabilities.push_back(encrypt_S.substr(i, tsize));
  }
  int index = -1;
  rep(i, probabilities.size()) {
    bool found = true;
    int c;
    for (c = 0; c < tsize; c++) {
      char now = probabilities[i][c];
      if (now == '?')
        continue;
      if (now != T[c]) {
        found = false;
        break;
      }
    }
    if (found) {
      index = i;
    }
  }
  if (index == -1)
    cout << "UNRESTORABLE" << endl;
  else {
    for (int k = index; k < index + tsize; k++) {
      encrypt_S[k] = T[k - index];
    }

    for (int k = 0; k < encrypt_S.size(); k++) {
      cout << ((encrypt_S[k] == '?') ? 'a' : encrypt_S[k]);
    }
    cout << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string ps = s.substr(i, t.size());
    // cout<<ps<<endl;
    bool jud = true;
    rep(j, t.size()) if (ps[j] != t[j] && ps[j] != '?') {
      jud = false;
      break;
    }
    if (jud) {
      rep(j, t.size()) s[i + j] = t[j];
      rep(j, s.size()) if (s[j] == '?') s[j] = 'a';
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  for (int i = (s.size() - t.size()); i >= 0; i--) {
    string ps = s.substr(i, t.size());
    // cout<<ps<<endl;
    bool jud = true;
    rep(j, t.size()) if (ps[j] != t[j] && ps[j] != '?') {
      jud = false;
      break;
    }
    if (jud) {
      rep(j, t.size()) s[i + j] = t[j];
      rep(j, s.size()) if (s[j] == '?') s[j] = 'a';
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int index = -1;
  bool flag = true;
  REP(i, s.size() - t.size()) {
    REP(j, t.size()) {
      if (s[i + j] == '?') {
        continue;
      } else if (s[i + j] == t[j]) {
        continue;
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      index = i;
    }
    flag = true;
  }

  if (index == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  } else {
    string ans = "";
    REP(i, index) {
      if (s[i] == '?') {
        ans += 'a';
      } else {
        ans += s[i];
      }
    }
    ans += t;
    for (int i = index + t.size(); i < s.size(); i++) {
      if (s[i] == '?') {
        ans += 'a';
      } else {
        ans += s[i];
      }
    }
    cout << ans << endl;
    return 0;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int index = -1;
  bool flag = true;
  REP(i, s.size() - t.size() + 1) {
    REP(j, t.size()) {
      if (s[i + j] == '?') {
        continue;
      } else if (s[i + j] == t[j]) {
        continue;
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      index = i;
    }
    flag = true;
  }

  if (index == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  } else {
    string ans = "";
    REP(i, index) {
      if (s[i] == '?') {
        ans += 'a';
      } else {
        ans += s[i];
      }
    }
    ans += t;
    for (int i = index + t.size(); i < s.size(); i++) {
      if (s[i] == '?') {
        ans += 'a';
      } else {
        ans += s[i];
      }
    }
    cout << ans << endl;
    return 0;
  }
  return 0;
}
Problem p03565 (C++)

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

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

  if (T.size() > S.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (i = S.size() - T.size(); i >= 0; i--) {
    for (j = i; j < T.size() + i; j++)
      if (S.at(j) != '?' && S.at(j) != T.at(j - i))
        break;
    if (j == T.size() + i)
      break;
  }

  if (i == -1)
    cout << "UNRESTORABLE";
  else {
    for (j = 0; j < S.size(); j++)
      if (S.at(j) == '?')
        if (j >= i && j <= i + T.size())
          S.at(j) = T.at(j - i);
        else
          S.at(j) = 'a';
    cout << S;
  }
  cout << endl;
}

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

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

  if (T.size() > S.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (i = S.size() - T.size(); i >= 0; i--) {
    for (j = i; j < T.size() + i; j++)
      if (S.at(j) != '?' && S.at(j) != T.at(j - i))
        break;
    if (j == T.size() + i)
      break;
  }

  if (i == -1)
    cout << "UNRESTORABLE";
  else {
    for (j = 0; j < S.size(); j++)
      if (S.at(j) == '?')
        if (j >= i && j < i + T.size())
          S.at(j) = T.at(j - i);
        else
          S.at(j) = 'a';
    cout << S;
  }
  cout << endl;
}
Problem p03565 (C++)

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  vector<string> ANS;
  for (int i = 0; i <= S.length() - T.length(); i++) {
    bool can = true;
    for (int j = 0; j < T.length(); j++) {
      if (S[i + j] == '?')
        continue;
      if (S[i + j] != T[j])
        can = false;
    }
    if (can) {
      string A = S.substr(0, i);
      A += T;
      A += S.substr(i + T.length());
      for (int k = 0; k < A.size(); k++)
        if (A[k] == '?')
          A[k] = 'a';
      ANS.push_back(A);
    }
  }
  if (ANS.size() == 0) {
    cout << "UNRESTORABLE";
    return 0;
  }
  sort(ANS.begin(), ANS.end());
  cout << ANS[0];
}

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  vector<string> ANS;
  if (S.length() < T.length()) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (int i = 0; i <= S.length() - T.length(); i++) {
    bool can = true;
    for (int j = 0; j < T.length(); j++) {
      if (S[i + j] == '?')
        continue;
      if (S[i + j] != T[j])
        can = false;
    }
    if (can) {
      string A = S.substr(0, i);
      A += T;
      A += S.substr(i + T.length());
      for (int k = 0; k < A.size(); k++)
        if (A[k] == '?')
          A[k] = 'a';
      ANS.push_back(A);
    }
  }
  if (ANS.size() == 0) {
    cout << "UNRESTORABLE";
    return 0;
  }
  sort(ANS.begin(), ANS.end());
  cout << ANS[0];
}
Problem p03565 (C++)

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

using namespace std;

bool match(int k, string &s, string &t) {
  for (int i = 0; i < t.size(); i++) {
    if (t[i] != s[i + k] && s[i + k] != '?')
      return false;
  }
  return true;
}

int main() {
  string s, t;
  cin >> s >> t;
  int t_max = -1;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    if (match(i, s, t))
      t_max = i;
  }
  if (t_max == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < t.size(); i++) {
    s[i + t_max] = t[i];
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      s[i] = 'a';
  }

  cout << s << endl;
  return 0;
}


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

using namespace std;

bool match(int k, string &s, string &t) {
  for (int i = 0; i < t.size(); i++) {
    if (t[i] != s[i + k] && s[i + k] != '?')
      return false;
  }
  return true;
}

int main() {
  string s, t;
  cin >> s >> t;
  if (t.size() > s.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  int t_max = -1;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    if (match(i, s, t))
      t_max = i;
  }
  if (t_max == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < t.size(); i++) {
    s[i + t_max] = t[i];
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      s[i] = 'a';
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define pb push_back
#define mp make_pair
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<string> ans;
  int cnt = 0;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    bool f = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        f = false;
      }
    }
    if (f) {
      string tmp = s;
      for (int j = 0; j < t.length(); j++) {
        tmp[i + j] = t[j];
      }
      for (int j = 0; j < tmp.length(); j++) {
        if (tmp[j] == '?') {
          tmp[j] = 'a';
        }
      }
      ans.pb(tmp);
      cnt++;
    }
  }
  if (cnt == 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    string mi = ans[0];
    for (auto v : ans) {
      if (v.compare(mi) < 0) {
        mi = v;
      }
    }
    cout << mi << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define pb push_back
#define mp make_pair
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s, t;
  cin >> s >> t;
  if (s.length() < t.length()) {
    bool g = true;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '?') {
        g = false;
      }
    }
    if (!g) {
      cout << "UNRESTORABLE" << endl;
    } else {
      cout << s << endl;
    }
    return 0;
  }
  vector<string> ans;
  int cnt = 0;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    bool f = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        f = false;
      }
    }
    if (f) {
      string tmp = s;
      for (int j = 0; j < t.length(); j++) {
        tmp[i + j] = t[j];
      }
      for (int j = 0; j < tmp.length(); j++) {
        if (tmp[j] == '?') {
          tmp[j] = 'a';
        }
      }
      ans.pb(tmp);
      cnt++;
    }
  }
  if (cnt == 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    string mi = ans[0];
    for (auto v : ans) {
      if (v.compare(mi) < 0) {
        mi = v;
      }
    }
    cout << mi << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7, MAX = 1e5;

int main() {
  string s, t;
  cin >> s >> t;
  int sn = s.size(), tn = t.size();
  for (int i = sn - tn; 0 <= i; i++) {
    // cout<<endl;
    bool is = true;
    for (int j = i; j < tn + i; j++) {
      // cout<<s[j]<<t[j-i]<<endl;
      if (s[j] != t[j - i] && s[j] != '?')
        is = false;
    }
    if (is) {
      for (int j = i; j < tn + i; j++) {
        s[j] = t[j - i];
      }
      for (int j = 0; j < sn; j++) {
        if (s[j] != '?')
          cout << s[j];
        else
          cout << 'a';
      }
      cout << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7, MAX = 1e5;

int main() {
  string s, t;
  cin >> s >> t;
  int sn = s.size(), tn = t.size();
  if (sn < tn) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = sn - tn; 0 <= i; i--) {
    // cout<<endl;
    bool is = true;
    for (int j = i; j < tn + i; j++) {
      // cout<<s[j]<<t[j-i]<<endl;
      if (s[j] != t[j - i] && s[j] != '?')
        is = false;
    }
    if (is) {
      for (int j = i; j < tn + i; j++) {
        s[j] = t[j - i];
      }
      for (int j = 0; j < sn; j++) {
        if (s[j] != '?')
          cout << s[j];
        else
          cout << 'a';
      }
      cout << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}
Problem p03565 (C++)

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

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

  string res = "UNRESTORABLE";
  for (int l = 0; l <= Sp.size() - T.size(); l++) {
    bool b = true;
    for (int i = 0; i < T.size(); i++) {
      if (Sp.at(l + i) != '?' && Sp.at(l + i) != T.at(i)) {
        b = false;
        break;
      }
    }
    if (b) {
      string S = Sp;
      for (int i = 0; i < T.size(); i++) {
        S.at(l + i) = T.at(i);
      }
      for (int i = 0; i < S.size(); i++) {
        S.at(i) = (S.at(i) == '?') ? 'a' : S.at(i);
      }

      if (res == "UNRESTORABLE") {
        res = S;
      } else {
        res = min(res, S);
      }
    }
  }
  cout << res << endl;
}

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

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

  if (Sp.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  string res = "UNRESTORABLE";
  for (int l = 0; l <= Sp.size() - T.size(); l++) {
    bool b = true;
    for (int i = 0; i < T.size(); i++) {
      if (Sp.at(l + i) != '?' && Sp.at(l + i) != T.at(i)) {
        b = false;
        break;
      }
    }
    if (b) {
      string S = Sp;
      for (int i = 0; i < T.size(); i++) {
        S.at(l + i) = T.at(i);
      }
      for (int i = 0; i < S.size(); i++) {
        S.at(i) = (S.at(i) == '?') ? 'a' : S.at(i);
      }

      if (res == "UNRESTORABLE") {
        res = S;
      } else {
        res = min(res, S);
      }
    }
  }
  cout << res << endl;
}
Problem p03565 (C++)

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

using namespace std;

int main() {
  string _S, T;
  int index = -1;

  cin >> _S >> T;

  for (int i = 0; i <= _S.size() - T.size(); i++) {
    for (int j = 0; j < T.size(); j++) {
      if (_S[i + j] != '?' && _S[i + j] != T[j])
        break;
      if (j == T.size() - 1)
        index = i;
    }
  }

  if (index == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i < _S.size(); i++) {
    if (i >= index && i < index + T.size()) {
      _S[i] = T[i - index];
    } else if (_S[i] == '?')
      _S[i] = 'a';
  }

  cout << _S << endl;

  return 0;
}


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

using namespace std;

int main() {
  string _S, T;
  int index = -1;

  cin >> _S >> T;

  if (_S.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i <= _S.size() - T.size(); i++) {
    for (int j = 0; j < T.size(); j++) {
      if (_S[i + j] != '?' && _S[i + j] != T[j])
        break;
      if (j == T.size() - 1)
        index = i;
    }
  }

  if (index == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i < _S.size(); i++) {
    if (i >= index && i < index + T.size()) {
      _S[i] = T[i - index];
    } else if (_S[i] == '?')
      _S[i] = 'a';
  }

  cout << _S << endl;

  return 0;
}
Problem p03565 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  vector<string> ans;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp = s;
    for (int j = 0; j < i; j++) {
      if (tmp[j] == '?') {
        tmp[j] = 'a';
      }
    }
    for (int j = i + t.size(); j < s.size(); j++) {
      if (tmp[j] == '?') {
        tmp[j] = 'a';
      }
    }
    for (int j = 0; j < t.size(); j++) {
      if (s[j + i] != '?' && s[j + i] != t[j]) {
        break;
      } else if (s[i + j] == '?') {
        tmp[i + j] = t[j];
      }
      if (j == t.size() - 1) {
        ans.push_back(tmp);
      }
    }
  }

  if (ans.empty()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  } else {
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
    return 0;
  }
}

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

int main() {
  string s, t;
  cin >> s >> t;
  vector<string> ans;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp = s;
    for (int j = 0; j < i; j++) {
      if (tmp[j] == '?') {
        tmp[j] = 'a';
      }
    }
    for (int j = i + t.size(); j < s.size(); j++) {
      if (tmp[j] == '?') {
        tmp[j] = 'a';
      }
    }
    for (int j = 0; j < t.size(); j++) {
      if (s[j + i] != '?' && s[j + i] != t[j]) {
        break;
      } else if (s[i + j] == '?') {
        tmp[i + j] = t[j];
      }
      if (j == t.size() - 1) {
        ans.push_back(tmp);
      }
    }
  }

  if (ans.empty()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  } else {
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
    return 0;
  }
}
Problem p03565 (C++)

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

string s, t;

bool match(int k) {
  for (int i = 0; i < t.size(); ++i) {
    if (s[i + k] != t[i] && s[i + k] != '?') {
      return false;
    }
  }
  return true;
}

int main() {
  int i, j, k, kk;
  kk = 0;
  cin >> s;
  cin >> t;
  bool ha = false;
  k = 0;
  if (s.size() - t.size() < 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  while (k <= s.size() - t.size()) {
    ha = match(k);
    k++;
    if (ha == true) {
      kk = k;
      ha = false;
    }
  }
  string ans = s;
  kk--;
  for (i = 0; i < t.size(); ++i) {
    ans[kk + i] = t[i];
  }
  for (i = 0; i < s.size(); ++i) {
    if (ans[i] == '?') {
      ans[i] = 'a';
    }
  }
  if (ans.find(t) != string::npos) {
    cout << ans << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}


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

string s, t;

bool match(int k) {
  for (int i = 0; i < t.size(); ++i) {
    if (s[i + k] != t[i] && s[i + k] != '?') {
      return false;
    }
  }
  return true;
}

int main() {
  int i, j, k, kk;
  kk = 0;
  cin >> s;
  cin >> t;
  bool ha = false;
  k = 0;
  if (s.size() - t.size() < 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  while (k <= s.size() - t.size() + 1) {
    ha = match(k);
    k++;
    if (ha == true) {
      kk = k;
      ha = false;
    }
  }
  string ans = s;
  kk--;
  for (i = 0; i < t.size(); ++i) {
    ans[kk + i] = t[i];
  }
  for (i = 0; i < s.size(); ++i) {
    if (ans[i] == '?') {
      ans[i] = 'a';
    }
  }
  if (ans.find(t) != string::npos) {
    cout << ans << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}
Problem p03565 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  string maxS = "";
  for (int i = 0; i < 50; i++) {
    maxS += "z";
  }
  string ans = maxS;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    string ss = s;
    string substr = ss.substr(i, t.length());
    bool isCorrect = true;
    for (int j = 0; j < t.length(); j++) {
      //      cout << substr << endl;
      if (substr[j] != '?' && substr[j] != t[j]) {
        isCorrect = false;
        break;
      }
    }

    if (isCorrect) {
      ss.replace(i, t.length(), t);
      for (int j = 0; j < ss.length(); j++) {
        if (ss[j] == '?')
          ss[j] = 'a';
      }
      ans = min(ans, ss);
    }
  }

  if (ans == maxS) {
    ans = "UNRESTORABLE";
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  string maxS = "";
  for (int i = 0; i < 50; i++) {
    maxS += "z";
  }
  string ans = maxS;
  if (s.length() < t.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.length() - t.length(); i++) {
    string ss = s;
    string substr = ss.substr(i, t.length());
    bool isCorrect = true;
    for (int j = 0; j < t.length(); j++) {
      //      cout << substr << endl;
      if (substr[j] != '?' && substr[j] != t[j]) {
        isCorrect = false;
        break;
      }
    }

    if (isCorrect) {
      ss.replace(i, t.length(), t);
      for (int j = 0; j < ss.length(); j++) {
        if (ss[j] == '?')
          ss[j] = 'a';
      }
      ans = min(ans, ss);
    }
  }

  if (ans == maxS) {
    ans = "UNRESTORABLE";
  }

  cout << ans << endl;

  return 0;
}
Problem p03565 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  vector<string> ans;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool f = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        f = false;
        break;
      }
    }
    if (f) {
      string ss = s;
      for (int j = 0; j < ss.size(); j++)
        if (ss[j] == '?')
          ss[j] = 'a';
      for (int j = 0; j < t.size(); j++)
        ss[i + j] = t[j];
      ans.push_back(ss);
    }
  }
  if (!ans.empty())
    cout << *(ans.end() - 1) << endl;
  else
    cout << "UNRESTORABLE" << endl;
  return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  vector<string> ans;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool f = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        f = false;
        break;
      }
    }
    if (f) {
      string ss = s;
      for (int j = 0; j < ss.size(); j++)
        if (ss[j] == '?')
          ss[j] = 'a';
      for (int j = 0; j < t.size(); j++)
        ss[i + j] = t[j];
      ans.push_back(ss);
    }
  }
  if (!ans.empty())
    cout << *(ans.end() - 1) << endl;
  else
    cout << "UNRESTORABLE" << endl;
  return 0;
}
Problem p03565 (C++)

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

using namespace std;
typedef long long int ll;

int main() {
  string S, T;
  cin >> S >> T;
  int p = -1;
  for (int i = 0; i <= S.length() - T.length(); i++) {
    if (S[i] == T[0] || S[i] == '?') {
      bool f = true;
      for (int j = 0; j < T.length(); j++) {
        if (S[i + j] == '?')
          continue;
        if (S[i + j] == T[j])
          continue;
        f = false;
      }
      if (f)
        p = i;
    }
  }
  if (p == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < T.length(); i++)
    S[i + p] = T[i];
  for (int i = 0; i < S.length(); i++)
    if (S[i] == '?')
      S[i] = 'a';
  cout << S << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF 1e7

using namespace std;
typedef long long int ll;

int main() {
  string S, T;
  cin >> S >> T;
  if (S.length() < T.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  int p = -1;
  for (int i = 0; i <= S.length() - T.length(); i++) {
    if (S[i] == T[0] || S[i] == '?') {
      bool f = true;
      for (int j = 0; j < T.length(); j++) {
        if (S[i + j] == '?')
          continue;
        if (S[i + j] == T[j])
          continue;
        f = false;
      }
      if (f)
        p = i;
    }
  }
  if (p == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < T.length(); i++)
    S[i + p] = T[i];
  for (int i = 0; i < S.length(); i++)
    if (S[i] == '?')
      S[i] = 'a';
  cout << S << endl;
}
Problem p03565 (C++)

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

int main() {
  string S, T;
  cin >> S >> T;
  bool b = false;
  int place = S.size() - T.size();
  for (int i = S.size() - T.size(); 0 <= i; i++) {
    bool make = true;
    for (int j = i; j < i + T.size(); j++) {
      if (S[j] != T[j - i] && S[j] != '?') {
        make = false;
        break;
      }
    }
    if (make) {
      b = true;
      break;
    }
    place--;
  }
  if (b) {
    for (int i = 0; i < S.size(); i++) {
      if (place <= i && i < place + T.size()) {
        S[i] = T[i - place];
      } else if (S[i] == '?') {
        S[i] = 'a';
      }
    }
    cout << S << endl;
  } else
    cout << "UNRESTORABLE" << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  bool b = false;
  int place = S.size() - T.size();
  for (int i = S.size() - T.size(); 0 <= i; i--) {
    bool make = true;
    for (int j = i; j < i + T.size(); j++) {
      if (S[j] != T[j - i] && S[j] != '?') {
        make = false;
        break;
      }
    }
    if (make) {
      b = true;
      break;
    }
    place--;
  }
  if (b) {
    for (int i = 0; i < S.size(); i++) {
      if (place <= i && i < place + T.size()) {
        S[i] = T[i - place];
      } else if (S[i] == '?') {
        S[i] = 'a';
      }
    }
    cout << S << endl;
  } else
    cout << "UNRESTORABLE" << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
string s, t, x;
vector<string> v;
int main() {
  int i, j;
  cin >> s >> t;
  for (i = 0; i <= s.size() - t.size(); i++) {
    for (j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j])
        break;
    }
    if (j == t.size()) {
      x = s;
      for (j = 0; j < t.size(); j++)
        x[i + j] = t[j];
      for (j = 0; x[j]; j++)
        if (x[j] == '?')
          x[j] = 'a';
      v.push_back(x);
    }
  }
  if (v.empty())
    cout << "UNRESTORABLE";
  else {
    sort(v.begin(), v.end());
    cout << v[0];
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
string s, t, x;
vector<string> v;
int main() {
  int i, j;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (i = 0; i <= s.size() - t.size(); i++) {
    for (j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j])
        break;
    }
    if (j == t.size()) {
      x = s;
      for (j = 0; j < t.size(); j++)
        x[i + j] = t[j];
      for (j = 0; x[j]; j++)
        if (x[j] == '?')
          x[j] = 'a';
      v.push_back(x);
    }
  }
  if (v.empty())
    cout << "UNRESTORABLE";
  else {
    sort(v.begin(), v.end());
    cout << v[0];
  }
  return 0;
}
Problem p03565 (C++)

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

int main() {
  string S, T;
  cin >> S >> T;
  vector<string> vec;
  string ans;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    bool ok = true;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] != '?' && S[i + j] != T[j])
        ok = false;
    }
    if (ok) {
      string s = S;
      for (int k = i; k < i + T.size(); k++) {
        if (s[k] == '?')
          s[k] = T[k - i];
      }
      for (int k = 0; k < s.size(); k++) {
        if (s[k] == '?')
          s[k] = 'a';
      }
      vec.push_back(s);
    }
  }

  if (vec.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else {
    for (int i = 0; i < vec.size(); i++) {
      if (i == 0)
        ans = vec[0];
      else {
        if (vec[i] < ans)
          ans = vec[i];
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
  string S, T;
  cin >> S >> T;
  vector<string> vec;
  string ans;
  int l = S.size() - T.size() + 1;
  for (int i = 0; i < max(0, l); i++) {
    bool ok = true;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] != '?' && S[i + j] != T[j])
        ok = false;
    }
    if (ok) {
      string s = S;
      for (int k = i; k < i + T.size(); k++) {
        if (s[k] == '?')
          s[k] = T[k - i];
      }
      for (int k = 0; k < s.size(); k++) {
        if (s[k] == '?')
          s[k] = 'a';
      }
      vec.push_back(s);
    }
  }

  if (vec.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else {
    for (int i = 0; i < vec.size(); i++) {
      if (i == 0)
        ans = vec[0];
      else {
        if (vec[i] < ans)
          ans = vec[i];
      }
    }
    cout << ans << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI = 3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF = 1 << 30;
#define vec2(a, y, x) vector<vector<char>> a(y, vector<char>(x))
#define vec1(a, n)                                                             \
  vector<int> a(n);                                                            \
  rep(i, n) cin >> a[i]

int main() {
  string s, t;
  cin >> s >> t;
  int x = s.size();
  int y = t.size();
  bool pos = true;
  int fin = 100;
  for (int i = x - 1; i >= y - 1; i--) {
    pos = true;
    for (int j = y - 1; j >= 0; j--) {
      if (s[i - (y - 1 - j)] == t[j] || s[i - y + 1 + j] == '?')
        continue;
      pos = false;
      break;
    }
    if (pos) {
      fin = i;
      break;
    }
  }
  if (!pos) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  rep(i, y) { s[fin - i] = t[y - i - 1]; }
  rep(i, x) if (s[i] == '?') s[i] = 'a';
  cout << s << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI = 3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF = 1 << 30;
#define vec2(a, y, x) vector<vector<char>> a(y, vector<char>(x))
#define vec1(a, n)                                                             \
  vector<int> a(n);                                                            \
  rep(i, n) cin >> a[i]

int main() {
  string s, t;
  cin >> s >> t;
  int x = s.size();
  int y = t.size();
  bool pos = true;
  int fin = 100;
  if (x < y) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = x - 1; i >= y - 1; i--) {
    pos = true;
    for (int j = y - 1; j >= 0; j--) {
      if (s[i - (y - 1 - j)] == t[j] || s[i - y + 1 + j] == '?')
        continue;
      pos = false;
      break;
    }
    if (pos) {
      fin = i;
      break;
    }
  }
  if (!pos) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  rep(i, y) { s[fin - i] = t[y - i - 1]; }
  rep(i, x) if (s[i] == '?') s[i] = 'a';
  cout << s << endl;
}
Problem p03565 (C++)

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

using namespace std;

int main() {
  string s, t;
  vector<string> ans;
  cin >> s >> t;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool flag = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      string u = s;
      for (int j = 0; j < t.size(); j++) {
        u[i + j] = t[j];
      }
      for (int j = 0; j < u.size(); j++) {
        if (u[j] == '?')
          u[j] = 'a';
      }
      ans.push_back(u);
    }
  }
  if (!ans.empty()) {
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
  } else
    cout << "UNRESTORABLE" << endl;
  return 0;
}

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

using namespace std;

int main() {
  string s, t;
  vector<string> ans;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool flag = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      string u = s;
      for (int j = 0; j < t.size(); j++) {
        u[i + j] = t[j];
      }
      for (int j = 0; j < u.size(); j++) {
        if (u[j] == '?')
          u[j] = 'a';
      }
      ans.push_back(u);
    }
  }
  if (!ans.empty()) {
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
  } else
    cout << "UNRESTORABLE" << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int main(int argc, const char *argv[]) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  string sprime, t;
  cin >> sprime >> t;
  string s = sprime;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '?')
      s.at(i) = 'z';
  }

  bool does_exist = 0;
  for (int i = 0; i <= sprime.size() - t.size(); i++) {
    bool t_flag = 1;
    for (int j = 0; j < t.size(); j++) {
      if (sprime.at(i + j) != '?' && sprime.at(i + j) != t.at(j)) {
        t_flag = 0;
        break;
      }
    }
    if (!t_flag)
      continue;
    // the above is tested only for candidates.

    does_exist = 1;
    string temp_ans = sprime;
    for (int j = 0; j < t.size(); j++)
      temp_ans.at(i + j) = t.at(j);
    for (int j = 0; j < temp_ans.size(); j++) {
      if (temp_ans.at(j) == '?')
        temp_ans.at(j) = 'a';
    }
    if (temp_ans < s)
      s = temp_ans;
  }

  cout << (does_exist ? s : "UNRESTORABLE") << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int main(int argc, const char *argv[]) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  string sprime, t;
  cin >> sprime >> t;
  string s = sprime;

  if (sprime.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '?')
      s.at(i) = 'z';
  }

  bool does_exist = 0;
  for (int i = 0; i <= sprime.size() - t.size(); i++) {
    bool t_flag = 1;
    for (int j = 0; j < t.size(); j++) {
      if (sprime.at(i + j) != '?' && sprime.at(i + j) != t.at(j)) {
        t_flag = 0;
        break;
      }
    }
    if (!t_flag)
      continue;
    // the above is tested only for candidates.

    does_exist = 1;
    string temp_ans = sprime;
    for (int j = 0; j < t.size(); j++)
      temp_ans.at(i + j) = t.at(j);
    for (int j = 0; j < temp_ans.size(); j++) {
      if (temp_ans.at(j) == '?')
        temp_ans.at(j) = 'a';
    }
    if (temp_ans < s)
      s = temp_ans;
  }

  cout << (does_exist ? s : "UNRESTORABLE") << endl;

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i <= end; i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main() {
  char S[51], T[51];
  cin >> S >> T;

  int pos = -1;
  FOR(i, 0, strlen(S) - strlen(T)) {
    bool match = true;
    // cout << "----" << endl;
    for (int j = 0; j < strlen(T); j++) {
      if (S[i + j] != '?' && S[i + j] != T[j]) {
        match = false;
        // cout << "false:" << S[i+j] << " " << T[j] << endl;
      }
    }
    if (match)
      pos = i;
  }

  if (pos == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    rep(i, strlen(S)) {
      if (pos <= i && i < pos + strlen(T))
        cout << T[i - pos];
      else if (S[i] == '?')
        cout << 'a';
      else
        cout << S[i];
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i <= end; i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main() {
  char S[51], T[51];
  cin >> S >> T;

  if (strlen(S) < strlen(T)) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  int pos = -1;
  FOR(i, 0, strlen(S) - strlen(T)) {
    bool match = true;
    // cout << "----" << endl;
    for (int j = 0; j < strlen(T); j++) {
      if (S[i + j] != '?' && S[i + j] != T[j]) {
        match = false;
        // cout << "false:" << S[i+j] << " " << T[j] << endl;
      }
    }
    if (match)
      pos = i;
  }

  if (pos == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    rep(i, strlen(S)) {
      if (pos <= i && i < pos + strlen(T))
        cout << T[i - pos];
      else if (S[i] == '?')
        cout << 'a';
      else
        cout << S[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// 解説閲覧後

bool isOK(
    string ss,
    string t) { // sをi文字目からtと同じ文字数で切り取ったものがssとして届く
  // cout << ss<<":"<<t<<endl;
  rep(i, ss.size()) {
    if (ss[i] != '?' && ss[i] != t[i]) {
      return false;
    }
  }
  // cout<<"true!"<<endl;
  return true;
}

int main() {
  string s, t, ans = "~";
  // s,tは小文字なので、どんなSでも置き換えられる
  // 置き換えることができなければそのままUNRESTORABLE

  cin >> s >> t;

  for (int i = 0; i <= s.size() - t.size(); i++) {
    if (isOK(s.substr(i, t.size()), t)) // そこに挿入可なら
    {                                   // 実際に挿入
      string v = s;
      for (int j = 0; j < t.size(); j++) {
        v[j + i] = t[j];
      }

      //?を置き換え
      rep(j, i) // i(挿入開始地点)まで見る
      {
        if (v[j] == '?')
          v[j] = 'a';
      }
      for (int j = i + t.size(); j < s.size(); j++) {
        if (v[j] == '?')
          v[j] = 'a';
      }

      ans = min(ans, v);
    }
  }

  if (ans == "~") {
    ans = "UNRESTORABLE";
  }

  cout << ans << endl;
  return 0;
}

/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// 解説閲覧後

bool isOK(
    string ss,
    string t) { // sをi文字目からtと同じ文字数で切り取ったものがssとして届く
  // cout << ss<<":"<<t<<endl;
  rep(i, ss.size()) {
    if (ss[i] != '?' && ss[i] != t[i]) {
      return false;
    }
  }
  // cout<<"true!"<<endl;
  return true;
}

int main() {
  string s, t, ans = "~";
  // s,tは小文字なので、どんなSでも置き換えられる
  // 置き換えることができなければそのままUNRESTORABLE

  cin >> s >> t;

  for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
    if (isOK(s.substr(i, t.size()), t)) // そこに挿入可なら
    {                                   // 実際に挿入
      string v = s;
      for (int j = 0; j < t.size(); j++) {
        v[j + i] = t[j];
      }

      //?を置き換え
      rep(j, i) // i(挿入開始地点)まで見る
      {
        if (v[j] == '?')
          v[j] = 'a';
      }
      for (int j = i + t.size(); j < s.size(); j++) {
        if (v[j] == '?')
          v[j] = 'a';
      }

      ans = min(ans, v);
    }
  }

  if (ans == "~") {
    ans = "UNRESTORABLE";
  }

  cout << ans << endl;
  return 0;
}

/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
string s, t, B = "~";
bool isOK(
    string ss,
    string t) { // sをi文字目からtと同じ文字数で切り取ったものがssとして届く
  // cout << ss<<":"<<t<<endl;
  rep(i, ss.size()) {
    if (ss[i] != '?' && ss[i] != t[i]) {
      return false;
    }
  }
  // cout<<"true!"<<endl;
  return true;
}
int main() {
  cin >> s >> t;
  // for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
  for (size_t i = 0; i <= (int)s.size() - (int)t.size(); i++) {
    /*string U = s.substr(i, t.size());
    if (isOK(U, t) == true) {*/
    if (isOK(s.substr(i, t.size()), t)) {
      string v = s;
      // for (int j = i; j < i + t.size(); j++)v[j] = t[j - i];
      for (int j = 0; j < t.size(); j++) {
        v[j + i] = t[j];
      }
      rep(j, i) // i(挿入開始地点)まで見る
      {
        if (v[j] == '?')
          v[j] = 'a';
      }
      for (int j = i + t.size(); j < s.size(); j++) {
        if (v[j] == '?')
          v[j] = 'a';
      }
      B = min(B, v);

      /*string v=s;
for(int j=0; j<t.size(); j++)
{v[j+i]=t[j];}
//?を置き換え
      rep(j,i)//i(挿入開始地点)まで見る
      {if(v[j]=='?')v[j]='a';}
      for(int j=i+t.size(); j <s.size();j++)
      {if(v[j]=='?')v[j]='a';}*/
    }
  }
  if (B == "~")
    cout << "UNRESTORABLE" << endl;
  else
    cout << B << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
string s, t, B = "~";
bool isOK(
    string ss,
    string t) { // sをi文字目からtと同じ文字数で切り取ったものがssとして届く
  // cout << ss<<":"<<t<<endl;
  rep(i, ss.size()) {
    if (ss[i] != '?' && ss[i] != t[i]) {
      return false;
    }
  }
  // cout<<"true!"<<endl;
  return true;
}
int main() {
  cin >> s >> t;
  // for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
  for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
    /*string U = s.substr(i, t.size());
    if (isOK(U, t) == true) {*/
    if (isOK(s.substr(i, t.size()), t)) {
      string v = s;
      // for (int j = i; j < i + t.size(); j++)v[j] = t[j - i];
      for (int j = 0; j < t.size(); j++) {
        v[j + i] = t[j];
      }
      rep(j, i) // i(挿入開始地点)まで見る
      {
        if (v[j] == '?')
          v[j] = 'a';
      }
      for (int j = i + t.size(); j < s.size(); j++) {
        if (v[j] == '?')
          v[j] = 'a';
      }
      B = min(B, v);

      /*string v=s;
for(int j=0; j<t.size(); j++)
{v[j+i]=t[j];}
//?を置き換え
      rep(j,i)//i(挿入開始地点)まで見る
      {if(v[j]=='?')v[j]='a';}
      for(int j=i+t.size(); j <s.size();j++)
      {if(v[j]=='?')v[j]='a';}*/
    }
  }
  if (B == "~")
    cout << "UNRESTORABLE" << endl;
  else
    cout << B << endl;
  return 0;
}
Problem p03565 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  int basho = -1;
  bool flag;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    flag = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j])
        flag = false;
    }
    if (flag)
      basho = i;
  }

  if (basho == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    string ans = "";
    for (int i = 0; i < basho; i++) {
      ans += ((s[i] == '?') ? 'a' : s[i]);
    }
    ans += t;
    for (int i = basho + t.length(); i < s.length(); i++) {
      ans += ((s[i] == '?') ? 'a' : s[i]);
    }
    cout << ans << endl;
  }

  return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int basho = -1;
  bool flag;
  if (s.length() < t.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.length() - t.length(); i++) {
    flag = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j])
        flag = false;
    }
    if (flag)
      basho = i;
  }

  if (basho == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    string ans = "";
    for (int i = 0; i < basho; i++) {
      ans += ((s[i] == '?') ? 'a' : s[i]);
    }
    ans += t;
    for (int i = basho + t.length(); i < s.length(); i++) {
      ans += ((s[i] == '?') ? 'a' : s[i]);
    }
    cout << ans << endl;
  }

  return 0;
}