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

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

int main() {
  string Sd, T;
  cin >> Sd;
  cin >> T;
  string S = Sd;
  bool usd = false;
  for (int i = 0; i <= Sd.size() - T.size(); ++i) {
    bool flg = true;
    for (int j = 0; j < T.size(); ++j)
      if (Sd[i + j] != '?' && Sd[i + j] != T[j]) {
        flg = false;
        break;
      }

    if (flg) {
      string stmp = Sd;
      for (int j = 0; j < T.size(); ++j)
        stmp[i + j] = T[j];
      for (int j = 0; j < stmp.size(); ++j)
        if (stmp[j] == '?')
          stmp[j] = 'a';

      if (!usd) {
        S = stmp;
        usd = true;
      } else {
        if (S > stmp)
          S = stmp;
      }
    }
  }

  if (usd)
    cout << S << endl;
  else
    cout << "UNRESTORABLE" << endl;
  return 0;
}

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

int main() {
  string Sd, T;
  cin >> Sd;
  cin >> T;
  string S = Sd;
  bool usd = false;
  // Sd.size() < T.size() のとき、.size()は符号なしのsize_tなので
  // Sd.size() - T.size()は負の数にならないことに注意
  for (int i = 0; i <= (int)Sd.size() - (int)T.size(); ++i) {
    bool flg = true;
    for (int j = 0; j < T.size(); ++j)
      if (Sd[i + j] != '?' && Sd[i + j] != T[j]) {
        flg = false;
        break;
      }

    if (flg) {
      string stmp = Sd;
      for (int j = 0; j < T.size(); ++j)
        stmp[i + j] = T[j];
      for (int j = 0; j < stmp.size(); ++j)
        if (stmp[j] == '?')
          stmp[j] = 'a';

      if (!usd) {
        S = stmp;
        usd = true;
      } else {
        if (S > stmp)
          S = stmp;
      }
    }
  }

  if (usd)
    cout << S << 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 ans = "";
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp = s;
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j] || s[i + j] == '?') {
        tmp[i + j] = t[j];
        cnt++;
      }
    }
    if (cnt == t.size()) {
      for (int j = 0; j < tmp.size(); j++) {
        if (tmp[j] == '?') {
          tmp[j] = 'a';
        }
      }
      if (ans == "") {
        ans = tmp;
      } else {
        ans = min(ans, tmp);
      }
    }
  }
  if (ans == "") {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  string ans = "";
  for (int i = 0; i < s.size(); i++) {
    if (i + t.size() > s.size()) {
      break;
    }
    string tmp = s;
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j] || s[i + j] == '?') {
        tmp[i + j] = t[j];
        cnt++;
      }
    }
    if (cnt == t.size()) {
      for (int j = 0; j < tmp.size(); j++) {
        if (tmp[j] == '?') {
          tmp[j] = 'a';
        }
      }
      if (ans == "") {
        ans = tmp;
      } else {
        ans = min(ans, tmp);
      }
    }
  }
  if (ans == "") {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p03565 (C++)

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

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

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

int main() {
  string s, t;
  cin >> s >> t;
  int st = -1;
  for (int i = 0; i <= int(s.length()) - int(t.length()); i++) {
    bool tflag = true;
    for (int j = 0; j < t.length(); j++)
      if (!(s[i + j] == '?' || s[i + j] == t[j]))
        tflag = false;
    if (tflag)
      st = i;
  }
  if (st < 0) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '?') {
      if (st <= i && i < st + t.length())
        s[i] = t[i - st];
      else
        s[i] = 'a';
    }
  }
  cout << s;
  return 0;
}
Problem p03565 (C++)

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

  string ans = "{}";
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    string po = s;
    bool f = true;
    for (int j = 0; j < t.size(); ++j) {
      if (po[i + j] != '?' && po[i + j] != t[j]) {
        f = false;
      }
      po[i + j] = t[j];
    }
    if (f) {
      for (int j = 0; j < s.size(); ++j) {
        if (po[j] == '?')
          po[j] = 'a';
      }
      ans = min(ans, po);
    }
  }

  if (ans == "{}") {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ans << endl;
  }
}


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

  string ans = "{}";
  for (int i = 0; i <= (int)s.size() - (int)t.size(); ++i) {
    string po = s;
    bool f = true;
    for (int j = 0; j < t.size(); ++j) {
      if (po[i + j] != '?' && po[i + j] != t[j]) {
        f = false;
      }
      po[i + j] = t[j];
    }
    if (f) {
      for (int j = 0; j < s.size(); ++j) {
        if (po[j] == '?')
          po[j] = 'a';
      }
      ans = min(ans, po);
    }
  }

  if (ans == "{}") {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ans << 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;
using ll = long long;

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

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

  // 入れる場所があるのかどうか
  int fit = -1;
  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]) {
        if (j == t.size() - 1) {
          fit = max(fit, i);
        }
      } else {
        break;
      }
    }
  }
  // cout << fit << endl;

  // 不可能判定
  if (fit == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  // 入れるべき場所にいれる
  for (int i = fit; i < t.size() + fit; i++) {
    s[i] = t[i - fit];
  }
  // cout << s << endl;

  // ？をaに
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      s[i] = 'a';
  }
  cout << s << endl;
}


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

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

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

  // 入れる場所があるのかどうか
  int fit = -1;
  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]) {
        if (j == t.size() - 1) {
          fit = max(fit, i);
        }
      } else {
        break;
      }
    }
  }
  // cout << fit << endl;

  // 不可能判定
  if (fit == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  // 入れるべき場所にいれる
  for (int i = fit; i < t.size() + fit; i++) {
    s[i] = t[i - fit];
  }
  // cout << s << endl;

  // ？をaに
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      s[i] = 'a';
  }
  cout << s << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, t, s;
  cin >> s1 >> t;
  bool ok = 0;
  s = string(s1.size(), 'z');
  for (int i = 0; i <= s1.size() - t.size(); i++) {
    bool flag = 1;
    for (int j = 0; j < t.size(); j++) {
      if (s1[i + j] != '?' && s1[i + j] != t[j]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ok = 1;
      string ts = s1;
      for (int j = 0; j < t.size(); j++)
        ts[i + j] = t[j];
      for (int j = 0; j < ts.size(); j++)
        if (ts[j] == '?')
          ts[j] = 'a';
      if (ts < s)
        s = ts;
    }
  }
  if (ok)
    cout << s;
  else
    cout << "UNRESTORABLE";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, t, s;
  cin >> s1 >> t;
  bool ok = 0;
  s = string(s1.size(), 'z');
  if (s1.size() < t.size()) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (int i = 0; i <= s1.size() - t.size(); i++) {
    bool flag = 1;
    for (int j = 0; j < t.size(); j++) {
      if (s1[i + j] != '?' && s1[i + j] != t[j]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ok = 1;
      string ts = s1;
      for (int j = 0; j < t.size(); j++)
        ts[i + j] = t[j];
      for (int j = 0; j < ts.size(); j++)
        if (ts[j] == '?')
          ts[j] = 'a';
      if (ts < s)
        s = ts;
    }
  }
  if (ok)
    cout << s;
  else
    cout << "UNRESTORABLE";
  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;
  int N = S.size(), K = T.size();
  vector<string> ans;

  for (int i = 0; i < N - K + 1; i++) {
    bool R = true;
    for (int j = 0; j < K; j++) {
      if (S.at(i + j) != '?' && S.at(i + j) != T.at(j))
        R = false;
    }
    if (R) {
      string A = S;
      for (int l = 0; l < A.size(); l++) {
        if (l >= i && i < i + K)
          A.at(l) = T.at(l - i);
        else if (A.at(l) == '?')
          A.at(l) = 'a';
      }
      ans.push_back(A);
    }
  }

  if (ans.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else {
    sort(ans.begin(), ans.end());
    cout << ans.at(0) << endl;
  }
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size(), K = T.size();
  vector<string> ans;

  for (int i = 0; i < N - K + 1; i++) {
    bool R = true;
    for (int j = 0; j < K; j++) {
      if (S.at(i + j) != '?' && S.at(i + j) != T.at(j))
        R = false;
    }
    if (R) {
      string A = S;
      for (int l = 0; l < A.size(); l++) {
        if (l >= i && l < i + K)
          A.at(l) = T.at(l - i);
        else if (A.at(l) == '?')
          A.at(l) = 'a';
      }
      ans.push_back(A);
    }
  }

  if (ans.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else {
    sort(ans.begin(), ans.end());
    cout << ans.at(0) << endl;
  }
}
Problem p03565 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  bool a = true;
  vector<int> b;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    if (s[i] == '?' || s[i] == t[0]) {
      for (int j = 0; j < t.size(); j++) {
        if (s[i + j] == t[j] || s[i + j] == '?') {
          a = true;
        } else {
          a = false;
          break;
        }
      }
      if (a) {
        b.push_back(i);
      }
      a = true;
    }
  }
  if (b.empty() == 1) {
    cout << "UNRESTORABLE\n";
    return 0;
  }
  int last = b.back();
  for (int i = last; i < last + t.size(); i++) {
    s[i] = t[i - last];
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      s[i] = 'a';
    }
  }
  cout << s << "\n";
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE\n";
    return 0;
  }
  bool a = true;
  vector<int> b;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    if (s[i] == '?' || s[i] == t[0]) {
      for (int j = 0; j < t.size(); j++) {
        if (s[i + j] == t[j] || s[i + j] == '?') {
          a = true;
        } else {
          a = false;
          break;
        }
      }
      if (a) {
        b.push_back(i);
      }
      a = true;
    }
  }
  if (b.empty() == 1) {
    cout << "UNRESTORABLE\n";
    return 0;
  }
  int last = b.back();
  for (int i = last; i < last + t.size(); i++) {
    s[i] = t[i - last];
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      s[i] = 'a';
    }
  }
  cout << s << "\n";
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int index = -1;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    string s = S.substr(i, T.size());
    bool match = true;
    for (int i = 0; i < T.size(); i++) {
      if (s[i] != '?' && s[i] != T[i])
        match = false;
    }
    if (match)
      index = i;
  }
  if (index == -1)
    cout << "UNRESTORABLE" << endl;
  else {
    S.replace(index, T.size(), T);
    for (char c : S)
      cout << (c == '?' ? 'a' : c);
    cout << endl;
  }
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int index = -1;
  // using size_t = unsigned long long;
  // using std::string::size_type = size_t;
  // std::string::size_typeが符号なし整数型として定義されている為、
  //  S.size() - T.size() < 0の場合でout_of_range例外が発生していた
  for (int i = 0; i <= (int)S.size() - (int)T.size(); i++) {
    string s = S.substr(i, T.size());
    bool match = true;
    for (int i = 0; i < T.size(); i++) {
      if (s[i] != '?' && s[i] != T[i])
        match = false;
    }
    if (match)
      index = i;
  }
  if (index == -1)
    cout << "UNRESTORABLE" << endl;
  else {
    S.replace(index, T.size(), T);
    for (char c : S)
      cout << (c == '?' ? 'a' : c);
    cout << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int slen, tlen;
  string s, t;
  cin >> s >> t;
  slen = s.length();
  tlen = t.length();
  for (int i = slen - tlen; i >= 0; i++) {
    bool flg = true;
    for (int j = 0; j < tlen; j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        flg = false;
        break;
      }
    }
    if (flg) {
      for (int j = 0; j < slen; j++) {
        if (j == i) {
          while (j < i + tlen) {
            s[j] = t[j - i];
            j++;
          }
        }
        if (s[j] == '?')
          s[j] = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }
  puts("UNRESTORABLE");
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int slen, tlen;
  string s, t;
  cin >> s >> t;
  slen = s.length();
  tlen = t.length();
  for (int i = slen - tlen; i >= 0; i--) {
    bool flg = true;
    for (int j = 0; j < tlen; j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        flg = false;
        break;
      }
    }
    if (flg) {
      for (int j = 0; j < slen; j++) {
        if (j == i) {
          while (j < i + tlen) {
            s[j] = t[j - i];
            j++;
          }
        }
        if (s[j] == '?')
          s[j] = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }
  puts("UNRESTORABLE");
}
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 b = 1;
    for (int j = 0; j < T.size(); j++) {
      if (S.at(j + i) != T.at(j) && S.at(j + i) != '?')
        b = 0;
    }
    if (b) {
      string s = S;
      for (int j = 0; j < T.size(); j++)
        s.at(j + i) = T.at(j);
      for (int j = 0; j < s.size(); j++) {
        if (s.at(j) == '?')
          s.at(j) = 'a';
      }
      ans.push_back(s);
    }
  }

  sort(ans.begin(), ans.end());

  cout << ((ans.size()) ? ans.at(0) : "UNRESTORABLE") << "\n";
}

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

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

  vector<string> ans;

  for (int i = 0; i <= int(S.size() - T.size()); i++) {
    bool b = 1;
    for (int j = 0; j < T.size(); j++) {
      if (S.at(j + i) != T.at(j) && S.at(j + i) != '?')
        b = 0;
    }
    if (b) {
      string s = S;
      for (int j = 0; j < T.size(); j++)
        s.at(j + i) = T.at(j);
      for (int j = 0; j < s.size(); j++) {
        if (s.at(j) == '?')
          s.at(j) = 'a';
      }
      ans.push_back(s);
    }
  }

  sort(ans.begin(), ans.end());

  cout << ((ans.size()) ? ans.at(0) : "UNRESTORABLE") << "\n";
}
Problem p03565 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1e9;
const long long LINF = 1e18;

bool isMatch(const string &S, int start, const string &T) {
  for (size_t i = 0; i < T.size(); i++) {
    if (start + i >= S.size()) {
      return false;
    }

    if ((S[start + i] != '?') && (S[start + i] != T[i])) {
      return false;
    }
  }
  return true;
}

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

  for (size_t i = S.size() - 1; i >= 0; i--) {
    if (isMatch(S, i, T)) {
      for (size_t j = 0; j < T.size(); j++) {
        S[i + j] = T[j];
      }

      for (size_t j = 0; j < S.size(); j++) {
        if (S[j] == '?') {
          S[j] = 'a';
        }
      }

      cout << S << endl;
      return 0;
    }
  }

  cout << "UNRESTORABLE" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1e9;
const long long LINF = 1e18;

bool isMatch(const string &S, int start, const string &T) {
  for (size_t i = 0; i < T.size(); i++) {
    if (start + i >= S.size()) {
      return false;
    }

    if ((S[start + i] != '?') && (S[start + i] != T[i])) {
      return false;
    }
  }
  return true;
}

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

  for (int i = S.size() - 1; i >= 0; i--) {
    // cout << "i: " << i << endl;
    if (isMatch(S, i, T)) {
      for (size_t j = 0; j < T.size(); j++) {
        S[i + j] = T[j];
      }

      for (size_t j = 0; j < S.size(); j++) {
        if (S[j] == '?') {
          S[j] = 'a';
        }
      }

      cout << S << endl;
      return 0;
    }
  }

  cout << "UNRESTORABLE" << endl;

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

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

  vector<int> candidate;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    if (S[i] == T[0] || S[i] == '?') {
      bool ok = true;
      for (int j = 1; j < T.size(); j++)
        if (S[i + j] != T[j] && S[i + j] != '?') {
          ok = false;
          break;
        }
      if (ok)
        candidate.push_back(i);
    }
  }
  if (candidate.size() == 0) {
    cout << "UNRESTORABLE\n";
    return 0;
  }
  vector<string> answers;
  for (int i = 0; i < candidate.size(); i++) {
    string tmp = S;
    for (int j = 0; j < S.size(); j++) {
      if (S[j] == '?') {
        if (candidate[i] <= j && j < candidate[i] + T.size())
          tmp[j] = T[j - candidate[i]];
        else
          tmp[j] = 'a';
      }
    }
    answers.push_back(tmp);
  }
  sort(answers.begin(), answers.end());
  cout << answers[0] << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
  string S, T;
  cin >> S >> T;
  if (S.size() < T.size()) {
    cout << "UNRESTORABLE\n";
    return 0;
  }
  vector<int> candidate;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    if (S[i] == T[0] || S[i] == '?') {
      bool ok = true;
      for (int j = 1; j < T.size(); j++)
        if (S[i + j] != T[j] && S[i + j] != '?') {
          ok = false;
          break;
        }
      if (ok)
        candidate.push_back(i);
    }
  }
  if (candidate.size() == 0) {
    cout << "UNRESTORABLE\n";
    return 0;
  }
  vector<string> answers;
  for (int i = 0; i < candidate.size(); i++) {
    string tmp = S;
    for (int j = 0; j < S.size(); j++) {
      if (S[j] == '?') {
        if (candidate[i] <= j && j < candidate[i] + T.size())
          tmp[j] = T[j - candidate[i]];
        else
          tmp[j] = 'a';
      }
    }
    answers.push_back(tmp);
  }
  sort(answers.begin(), answers.end());
  cout << answers[0] << "\n";
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
int main() {
  std::string s, t;
  std::cin >> s >> t;
  int inf = 1001001, p = inf;
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    int j = 0;
    bool f = true;
    while (j < t.size()) {
      if (s[i + j] == '?' || s[i + j] == t[j]) {
        ++j;
      } else {
        f = false;
        break;
      }
    }
    p = (f ? i : p);
  }
  if (p == inf) {
    std::cout << "UNRESTORABLE"
              << "\n";
  } else {
    for (int i = 0; i < s.size(); ++i) {
      if (i >= p && i < p + t.size()) {
        std::cout << t[i - p];
      } else {
        std::cout << (s[i] == '?' ? 'a' : s[i]);
      }
    }
    std::cout << "\n";
  }
}


Fixed submission:
#include <iostream>
#include <string>
int main() {
  std::string s, t;
  std::cin >> s >> t;
  int inf = 1001001, p = inf;
  if (t.size() > s.size()) {
    std::cout << "UNRESTORABLE"
              << "\n";
    return 0;
  }
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    int j = 0;
    bool f = true;
    while (j < t.size()) {
      if (s[i + j] == '?' || s[i + j] == t[j]) {
        ++j;
      } else {
        f = false;
        break;
      }
    }
    p = (f ? i : p);
  }
  if (p == inf) {
    std::cout << "UNRESTORABLE"
              << "\n";
  } else {
    for (int i = 0; i < s.size(); ++i) {
      if (i >= p && i < p + t.size()) {
        std::cout << t[i - p];
      } else {
        std::cout << (s[i] == '?' ? 'a' : s[i]);
      }
    }
    std::cout << "\n";
  }
}
Problem p03565 (C++)

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

int main() {
  int n, m, a;
  bool flag = false;
  string s, h;
  cin >> s >> h;
  n = s.size();
  m = h.size();
  for (int i = n - 1; i >= m - 1; i--) {
    for (int j = 0; j < m; j++) {
      string t = s.substr(i - j, 1);
      if (t == "?" || t == h.substr(m - j - 1, 1)) {
        flag = true;
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      a = i;
      break;
    }
  }
  string p;
  if (flag) {
    string::size_type pos(s.find("?"));
    while (pos != string::npos) {
      s.replace(pos, 1, "a");
      pos = s.find("?", pos + 1);
    }
    if (a - m < 0) {
      p = h + s.substr(m + 1);
    } else if (a = n - 1) {
      p = s.substr(0, a - m + 1) + h;
    } else {
      p = s.substr(0, a - m + 1) + h + s.substr(a + 1);
    }
  } else {
    p = "UNRESTORABLE";
  }
  cout << p << endl;
}

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

int main() {
  int n, m, a;
  bool flag = false;
  string s, h;
  cin >> s >> h;
  n = s.size();
  m = h.size();
  for (int i = n - 1; i >= m - 1; i--) {
    for (int j = 0; j < m; j++) {
      string t = s.substr(i - j, 1);
      if (t == "?" || t == h.substr(m - j - 1, 1)) {
        flag = true;
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      a = i;
      break;
    }
  }
  string p;
  if (flag) {
    string::size_type pos(s.find("?"));
    while (pos != string::npos) {
      s.replace(pos, 1, "a");
      pos = s.find("?", pos + 1);
    }
    if (a - m < 0) {
      p = h + s.substr(m);
    } else if (a == n - 1) {
      p = s.substr(0, a - m + 1) + h;
    } else {
      p = s.substr(0, a - m + 1) + h + s.substr(a + 1);
    }
  } else {
    p = "UNRESTORABLE";
  }
  cout << p << endl;
}
Problem p03565 (C++)

Buggy submission (status: Time Limit Exceeded):
#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++) {
    string tmp = s;
    for (int j = 0; j < t.length(); j++) {
      if (i + j > s.size() - 1)
        break;
      if (tmp[i + j] == '?' || tmp[i + j] == t[j])
        tmp[i + j] = t[j];
      else
        break;
      if (j == t.length() - 1) {
        for (int k = 0; k < tmp.length(); k++) {
          if (tmp[k] == '?')
            tmp[k] = 'a';
        }
        ans.push_back(tmp);
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
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 < t.length(); j++) {
      if (i + j > s.size() - 1)
        break;
      if (tmp[i + j] == '?' || tmp[i + j] == t[j])
        tmp[i + j] = t[j];
      else
        break;
      if (j == t.length() - 1) {
        for (int k = 0; k < tmp.length(); k++) {
          if (tmp[k] == '?')
            tmp[k] = 'a';
        }
        ans.push_back(tmp);
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main(void) {
  string sd, t;
  cin >> sd >> t;
  int lensd, lent;
  int i, j;
  lensd = sd.length();
  lent = t.length();
  i = lensd - 1;
  j = lent - 1;
  while (i >= 0) {
    if (sd[i] == t[j] || sd[i] == '?') {
      j--;
      i--;
    } else {
      i = i + (lent - j) - 1;
      j = lent - 1;
    }
    if (j < 0)
      break;
  }
  if (j >= 0) {
    cout << "UNRESTORABLE\n";
    return (0);
  }
  i++;
  j++;
  while (j < lent)
    sd[i++] = t[j++];
  i = 0;
  while (i < lensd) {
    if (sd[i] == '?')
      sd[i] = 'a';
    i++;
  }
  cout << sd;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main(void) {
  string sd, t;
  cin >> sd >> t;
  int lensd, lent;
  int i, j;
  lensd = sd.length();
  lent = t.length();
  i = lensd - 1;
  j = lent - 1;
  while (i >= 0) {
    if (sd[i] == t[j] || sd[i] == '?') {
      j--;
      i--;
    } else {
      i = i + (lent - j) - 2;
      j = lent - 1;
    }
    if (j < 0)
      break;
  }
  if (j >= 0) {
    cout << "UNRESTORABLE\n";
    return (0);
  }
  i++;
  j++;
  while (j < lent)
    sd[i++] = t[j++];
  i = 0;
  while (i < lensd) {
    if (sd[i] == '?')
      sd[i] = 'a';
    i++;
  }
  cout << sd;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string s, ss;
bool f = 0;
int main() {
  cin >> s >> ss;
  string mn = s, a = s;
  for (int i = 0; i < s.size(); i++) {
    mn[i] = 'z';
  }
  for (int i = 0; i <= s.size() - ss.size(); i++) {
    bool fl = 1;
    for (int j = 0; j < ss.size(); j++) {
      if (s[i + j] == '?')
        continue;
      if (s[i + j] != ss[j]) {
        fl = 0;
        break;
      }
    }
    if (fl) {
      for (int j = 0; j < ss.size(); j++)
        if (s[i + j] == '?')
          a[i + j] = ss[j];
      for (int j = 0; j < s.size(); j++)
        if (a[j] == '?')
          a[j] = 'a';
      if (mn > a)
        mn = a;
      f = 1;
    }
    a = s;
  }
  if (f == 1)
    cout << mn;
  else
    cout << "UNRESTORABLE";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s, ss;
bool f = 0;
int main() {
  cin >> s >> ss;
  string mn = s, a = s;
  for (int i = 0; i < s.size(); i++) {
    mn[i] = 'z';
  }
  if (s.size() < ss.size()) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (int i = 0; i <= s.size() - ss.size(); i++) {
    bool fl = 1;
    for (int j = 0; j < ss.size(); j++) {
      if (s[i + j] == '?')
        continue;
      if (s[i + j] != ss[j]) {
        fl = 0;
        break;
      }
    }
    if (fl) {
      for (int j = 0; j < ss.size(); j++)
        if (s[i + j] == '?')
          a[i + j] = ss[j];
      for (int j = 0; j < s.size(); j++)
        if (a[j] == '?')
          a[j] = 'a';
      if (mn > a)
        mn = a;
      f = 1;
    }
    a = s;
  }
  if (f == 1)
    cout << mn;
  else
    cout << "UNRESTORABLE";
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

void go() {
  string res = "UNRESTORABLE";
  string s, t;
  cin >> s >> t;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    bool f = true;
    string tmp = s;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[j])
        ;
      else
        f = false;
      tmp[i + j] = t[j];
    }
    if (f) {
      for (int j = 0; j < tmp.length(); j++)
        if (tmp[j] == '?')
          tmp[j] = 'a';
      if (res == "UNRESTORABLE" || res > tmp)
        res = tmp;
    }
  }
  cout << res << endl;
}

int main() {
  go();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

void go() {
  string res = "UNRESTORABLE";
  string s, t;
  cin >> s >> t;
  for (int i = 0; i <= (int)s.length() - (int)t.length(); i++) {
    bool f = true;
    string tmp = s;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[j])
        ;
      else
        f = false;
      tmp[i + j] = t[j];
    }
    if (f) {
      for (int j = 0; j < tmp.length(); j++)
        if (tmp[j] == '?')
          tmp[j] = 'a';
      if (res == "UNRESTORABLE" || res > tmp)
        res = tmp;
    }
  }
  cout << res << endl;
}

int main() {
  go();
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string s, t;
vector<string> str;
int main() {
  cin >> s >> t;
  int n = t.size();
  for (int i = 0; i <= s.size() - n; i++) {
    string z = s.substr(i, n);
    bool flag = true;
    for (int j = 0; j < n; j++)
      if (z[j] != t[j] && z[j] != '?') {
        flag = false;
        break;
      }
    if (flag) {
      string o = s;
      for (int j = 0; j < n; j++)
        o[i + j] = t[j];
      for (int j = 0; j < o.size(); j++)
        if (o[j] == '?')
          o[j] = 'a';
      str.push_back(o);
    }
  }
  if (str.size() == 0)
    puts("UNRESTORABLE");
  else {
    sort(str.begin(), str.end());
    cout << str[0] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s, t;
vector<string> str;
int main() {
  cin >> s >> t;
  if (s.size() < t.size()) {
    puts("UNRESTORABLE");
    return 0;
  }
  int n = t.size();
  for (int i = 0; i <= s.size() - n; i++) {
    string z = s.substr(i, n);
    bool flag = true;
    for (int j = 0; j < n; j++)
      if (z[j] != t[j] && z[j] != '?') {
        flag = false;
        break;
      }
    if (flag) {
      string o = s;
      for (int j = 0; j < n; j++)
        o[i + j] = t[j];
      for (int j = 0; j < o.size(); j++)
        if (o[j] == '?')
          o[j] = 'a';
      str.push_back(o);
    }
  }
  if (str.size() == 0)
    puts("UNRESTORABLE");
  else {
    sort(str.begin(), str.end());
    cout << str[0] << endl;
  }
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  vector<string> cand;
  for (ll i = 0; i <= s.size() - t.size(); i++) {
    bool candans = true;
    for (ll j = 0; j < t.size(); j++) {
      if (s[j + i] != '?' && t[j] != s[i + j])
        candans = false;
    }
    if (candans) {
      string S = s;
      for (ll j = 0; j < t.size(); j++) {
        S[i + j] = t[j];
      }
      cand.emplace_back(S);
    }
  }
  for (ll i = 0; i < cand.size(); i++) {
    for (ll j = 0; j < cand[i].size(); j++) {
      if (cand[i][j] == '?')
        cand[i][j] = 'a';
    }
  }
  sort(cand.begin(), cand.end());
  if (cand.size() == 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << cand[0] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  vector<string> cand;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (ll i = 0; i <= s.size() - t.size(); i++) {
    bool candans = true;
    for (ll j = 0; j < t.size(); j++) {
      if (s[j + i] != '?' && t[j] != s[i + j])
        candans = false;
    }
    if (candans) {
      string S = s;
      for (ll j = 0; j < t.size(); j++) {
        S[i + j] = t[j];
      }
      cand.emplace_back(S);
    }
  }
  for (ll i = 0; i < cand.size(); i++) {
    for (ll j = 0; j < cand[i].size(); j++) {
      if (cand[i][j] == '?')
        cand[i][j] = 'a';
    }
  }
  sort(cand.begin(), cand.end());
  if (cand.size() == 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << cand[0] << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll> P;
bool prime(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      cnt++;
  }
  if (cnt != 1)
    return false;
  else
    return n != 1;
}
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
signed main() {
  ll memo = 0;
  string s, t;
  cin >> s >> t;
  ll n = s.size(), m = t.size();
  string ans;
  if (n < m)
    puts("UNRESTORABLE");
  else {
    rep(i, n) {
      if (s[i] == '?')
        ans[i] = 'a';
      else
        ans[i] = s[i];
    }
    for (int i = n - m; i >= 0; i++) {
      for (int j = i; j < i + m; j++) {
        if (s[j] == t[j - i] || s[j] == '?')
          memo++;
      }
      if (memo == m) {
        for (int k = i; k < i + m; k++) {
          ans[k] = t[k - i];
        }
        break;
      }
      memo = 0;
    }
    if (memo == 0)
      puts("UNRESTORABLE");
    else
      rep(i, n) cout << ans[i];
  }
  ggr
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll> P;
bool prime(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      cnt++;
  }
  if (cnt != 1)
    return false;
  else
    return n != 1;
}
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
signed main() {
  ll memo = 0;
  string s, t;
  cin >> s >> t;
  ll n = s.size(), m = t.size();
  string ans;
  if (n < m)
    puts("UNRESTORABLE");
  else {
    rep(i, n) {
      if (s[i] == '?')
        ans[i] = 'a';
      else
        ans[i] = s[i];
    }
    for (int i = n - m; i >= 0; i--) {
      for (int j = i; j < i + m; j++) {
        if (s[j] == t[j - i] || s[j] == '?')
          memo++;
      }
      if (memo == m) {
        for (int k = i; k < i + m; k++) {
          ans[k] = t[k - i];
        }
        break;
      }
      memo = 0;
    }
    if (memo == 0)
      puts("UNRESTORABLE");
    else
      rep(i, n) cout << ans[i];
  }
  ggr
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define int long long
#define mod(int) (1000000007)
using namespace std;
signed main() {
  int n = 0, ok = 100;
  string s, t;
  cin >> s >> t;
  for (int h = 0; h <= s.size() - t.size(); h++) {
    for (int i = 0; i < t.size(); i++) {
      if (s[h + i] != t[i] && s[h + i] != '?') {
        n = 1;
        break;
      }
    }
    if (n == 0) {
      ok = h;
    }
    n = 0;
  }
  if (ok == 100) {
    cout << "UNRESTORABLE" << endl;
  } else {
    for (int h = 0; h < s.size(); h++) {
      if (h >= ok && h < ok + t.size()) {
        cout << t[h - ok];
      } else {
        if (s[h] == '?') {
          cout << 'a';
        } else {
          cout << s[h];
        }
      }
    }
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define int long long
#define mod(int) (1000000007)
using namespace std;
signed main() {
  int n = 0, ok = 100;
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int h = 0; h <= s.size() - t.size(); h++) {
    for (int i = 0; i < t.size(); i++) {
      if (s[h + i] != t[i] && s[h + i] != '?') {
        n = 1;
        break;
      }
    }
    if (n == 0) {
      ok = h;
    }
    n = 0;
  }
  if (ok == 100) {
    cout << "UNRESTORABLE" << endl;
  } else {
    for (int h = 0; h < s.size(); h++) {
      if (h >= ok && h < ok + t.size()) {
        cout << t[h - ok];
      } else {
        if (s[h] == '?') {
          cout << 'a';
        } else {
          cout << s[h];
        }
      }
    }
  }
  cout << endl;
  return 0;
}
Problem p03565 (Python)

Buggy submission (status: Runtime Error):
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i <= ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")


Fixed submission:
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i < ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string a = s.substr(i, t.size());
    bool can = true;
    for (int j = 0; j < t.size(); j++) {
      if (a[j] == t[j] || a[j] == '?')
        continue;
      can = false;
      break;
    }
    if (can) {
      for (int j = i; j < i + t.size(); ++j) {
        s[j] = t[j - i];
      }
      for (auto &x : s) {
        if (x == '?')
          x = 'a';
      }
      cout << s;
      return 0;
    }
  }
  cout << "UNRESTORABLE";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  if (t.size() > s.size()) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (int i = s.size() - t.size(); i >= 0; i--) {
    string a = s.substr(i, t.size());
    bool can = true;
    for (int j = 0; j < t.size(); j++) {
      if (a[j] == t[j] || a[j] == '?')
        continue;
      can = false;
      break;
    }
    if (can) {
      for (int j = i; j < i + t.size(); ++j) {
        s[j] = t[j - i];
      }
      for (auto &x : s) {
        if (x == '?')
          x = 'a';
      }
      cout << s;
      return 0;
    }
  }
  cout << "UNRESTORABLE";
}
Problem p03565 (C++)

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

using namespace std;

int main() {
  string s;
  string a;
  cin >> s;
  cin >> a;
  int num = 100;
  for (int i = 0; i <= s.length() - a.length(); ++i) {
    bool check = true;
    for (int j = 0; j < a.length(); ++j) {
      if (s[i + j] != '?' && s[i + j] != a[j]) {
        check = false;
        break;
      }
    }
    if (check == true)
      num = i;
  }

  if (num == 100) {
    cout << "UNRESTORABLE" << endl;
  } else {
    for (int i = 0; i < a.length(); ++i) {
      s[num + i] = a[i];
    }
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s;
  string a;
  cin >> s;
  cin >> a;
  int num = 100;
  for (int i = 0; i < s.length() - a.length() + 1; ++i) {
    bool check = true;
    for (int j = 0; j < a.length(); ++j) {
      if (s[i + j] != '?' && s[i + j] != a[j]) {
        check = false;
        break;
      }
    }
    if (check == true)
      num = i;
  }

  if (num == 100) {
    cout << "UNRESTORABLE" << endl;
  } else {
    for (int i = 0; i < a.length(); ++i) {
      s[num + i] = a[i];
    }
    for (int i = 0; i < s.length(); ++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 int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

string s, t;
vector<string> v;
bool isMatch(string a, string b) {

  for (int i = 0; i < a.size(); i++) {
    if (a[i] != '?' && a[i] != b[i])
      return false;
  }
  return true;
}

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

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

  for (int i = 0; i <= s.size() - t.size(); i++) {
    if (isMatch(s.substr(i, t.size()), t)) {
      string ts = "";
      for (int j = 0; j < i; j++) {
        if (s[j] == '?')
          ts += "a";
        else
          ts += s[j];
      }
      ts += t;
      for (int j = i + t.size(); j < s.size(); j++) {
        if (s[j] == '?')
          ts += "a";
        else
          ts += s[j];
      }
      v.push_back(ts);
    }
  }
  sort(v.begin(), v.end());

  // if (v.size() == 0)
  //     cout << "UNRESTORABLE" << endl;
  // else
  cout << v[0] << endl;

  return 0;
}


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

using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

string s, t;
vector<string> v;
bool isMatch(string a, string b) {

  for (int i = 0; i < a.size(); i++) {
    if (a[i] != '?' && a[i] != b[i])
      return false;
  }
  return true;
}

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

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

  for (int i = 0; i <= s.size() - t.size(); i++) {
    if (isMatch(s.substr(i, t.size()), t)) {
      string ts = "";
      for (int j = 0; j < i; j++) {
        if (s[j] == '?')
          ts += "a";
        else
          ts += s[j];
      }
      ts += t;
      for (int j = i + t.size(); j < s.size(); j++) {
        if (s[j] == '?')
          ts += "a";
        else
          ts += s[j];
      }
      v.push_back(ts);
    }
  }
  sort(v.begin(), v.end());

  if (v.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else
    cout << v[0] << endl;

  return 0;
}