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

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

using namespace std;

inline bool is_valid(const string &S, const string T, int offset) {
  if (S.length() - offset < T.length())
    return false;
  for (int i = 0; i < T.length(); i++) {
    if (S[offset + i] != T[i] && S[offset + i] != '?') {
      return false;
    }
  }
  return true;
}

inline string dic_min(const string &str1, const string &str2) {
  for (int i = 0; i < str1.length(); i++) {
    if (str1[i] < str2[i]) {
      return str1;
    } else if (str1[i] > str2[i]) {
      return str2;
    }
  }
  return str1;
}

int main() {
  string ans("UNRESTORABLE");

  string S, T;
  cin >> S >> T;
  for (int offset = 0; offset <= S.length() - T.length(); offset++) {
    if (is_valid(S, T, offset)) {
      string valid_S = S;
      valid_S.replace(valid_S.begin() + offset,
                      valid_S.begin() + offset + T.length(), T);
      for (int i = 0; i < valid_S.length(); i++) {
        if (valid_S[i] == '?')
          valid_S[i] = 'a';
      }
      ans = ans == "UNRESTORABLE" ? valid_S : dic_min(valid_S, ans);
    }
  }
  cout << ans << endl;
}
//
// Dubious Document 2
// https://abc076.contest.atcoder.jp/tasks/abc076_c
//

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

using namespace std;

inline bool is_valid(const string &S, const string T, int offset) {
  if (S.length() - offset < T.length())
    return false;
  for (int i = 0; i < T.length(); i++) {
    if (S[offset + i] != T[i] && S[offset + i] != '?') {
      return false;
    }
  }
  return true;
}

inline string dic_min(const string &str1, const string &str2) {
  for (int i = 0; i < str1.length(); i++) {
    if (str1[i] < str2[i]) {
      return str1;
    } else if (str1[i] > str2[i]) {
      return str2;
    }
  }
  return str1;
}

int main() {
  string ans("UNRESTORABLE");

  string S, T;
  cin >> S >> T;
  if (S.length() < T.length()) {
    cout << ans << endl;
    return 0;
  }

  for (int offset = 0; offset <= S.length() - T.length(); offset++) {
    if (is_valid(S, T, offset)) {
      string valid_S = S;
      valid_S.replace(valid_S.begin() + offset,
                      valid_S.begin() + offset + T.length(), T);
      for (int i = 0; i < valid_S.length(); i++) {
        if (valid_S[i] == '?')
          valid_S[i] = 'a';
      }
      ans = ans == "UNRESTORABLE" ? valid_S : dic_min(valid_S, ans);
    }
  }
  cout << ans << endl;
}
//
// Dubious Document 2
// https://abc076.contest.atcoder.jp/tasks/abc076_c
//
Problem p03565 (C++)

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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL << 60)

signed main() {

  string s, t;
  cin >> s >> t;

  vector<string> v; // 候補
  // 開始位置
  for (int i = 0; i <= s.length() - t.length(); i++) {
    bool ok = true;
    string tmp = s;
    for (int j = 0; j < t.length(); j++) {
      if (!(s[i + j] == t[j] || s[i + j] == '?')) {
        ok = false;
        break;
      }
      tmp[i + j] = t[j];
    }
    if (ok) {
      for (int j = 0; j < s.length(); j++) {
        if (tmp[j] == '?')
          tmp[j] = 'a';
      }
      v.push_back(tmp);
    }
  }
  if (v.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  cout << v[0] << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL << 60)

signed main() {

  string s, t;
  cin >> s >> t;
  if (s.length() < t.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  vector<string> v; // 候補
  // 開始位置
  for (int i = 0; i <= s.length() - t.length(); i++) {
    bool ok = true;
    string tmp = s;
    for (int j = 0; j < t.length(); j++) {
      if (!(s[i + j] == t[j] || s[i + j] == '?')) {
        ok = false;
        break;
      }
      tmp[i + j] = t[j];
    }
    if (ok) {
      for (int j = 0; j < s.length(); j++) {
        if (tmp[j] == '?')
          tmp[j] = 'a';
      }
      v.push_back(tmp);
    }
  }
  if (v.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  cout << v[0] << endl;

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define opr iterator
typedef long long ll;
using namespace std;
string s, t;
int main() {
  cin >> s >> t;
  string res;
  bool fd = false;
  for (int i = 0; i < s.size(); i++) {
    res += "z";
  }
  for (int beg = 0; beg <= s.size() - t.size(); beg++) {
    string tmp;
    bool ok = 1;
    for (int i = 0; i < t.size(); i++) {
      if (t[i] != s[i + beg] && s[i + beg] != '?') {
        ok = 0;
        break;
      }
    }
    if (ok) {
      tmp = s;
      for (int i = 0; i < t.size(); i++) {
        if (t[i] != tmp[i + beg]) {
          tmp[i + beg] = t[i];
        }
      }
      for (int i = 0; i < tmp.size(); i++) {
        if (tmp[i] == '?') {
          tmp[i] = 'a';
        }
      }
      res = min(res, tmp);
      fd = true;
    }
  }
  if (fd) {
    cout << res << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define opr iterator
typedef long long ll;
using namespace std;
string s, t;
int main() {
  cin >> s >> t;
  string res;
  bool fd = false;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    exit(0);
  }
  for (int i = 0; i < s.size(); i++) {
    res += "z";
  }
  for (int beg = 0; beg <= s.size() - t.size(); beg++) {
    string tmp;
    bool ok = 1;
    for (int i = 0; i < t.size(); i++) {
      if (t[i] != s[i + beg] && s[i + beg] != '?') {
        ok = 0;
        break;
      }
    }
    if (ok) {
      tmp = s;
      for (int i = 0; i < t.size(); i++) {
        if (t[i] != tmp[i + beg]) {
          tmp[i + beg] = t[i];
        }
      }
      for (int i = 0; i < tmp.size(); i++) {
        if (tmp[i] == '?') {
          tmp[i] = 'a';
        }
      }
      res = min(res, tmp);
      fd = true;
    }
  }
  if (fd) {
    cout << res << 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;

  int okIndex = -1;

  for (size_t i = 0; i <= S.size() - T.size(); i++) {
    bool isOK = true;
    string sb = S.substr(i, T.size());
    for (size_t j = 0; j < T.size(); j++) {
      if (sb[j] == T[j]) {
        continue;
      } else if (sb[j] == '?') {
        sb[j] = T[j];
      } else {
        isOK = false;
      }
    }
    if (isOK) {
      okIndex = i;
    }
  }

  if (okIndex != -1) {
    for (size_t k = 0; k < S.size(); k++) {
      if ((size_t)okIndex <= k && k < okIndex + T.size()) {
        cout << T[k - okIndex];
      } else if (S[k] == '?') {
        cout << 'a';
      } else {
        cout << S[k];
      }
    }

    cout << "\n";

    return 0;
  }

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


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

using namespace std;

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

  int okIndex = -1;

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

  for (size_t i = 0; i <= S.size() - T.size(); i++) {
    bool isOK = true;
    string sb = S.substr(i, T.size());
    for (size_t j = 0; j < T.size(); j++) {
      if (sb[j] == T[j]) {
        continue;
      } else if (sb[j] == '?') {
        sb[j] = T[j];
      } else {
        isOK = false;
      }
    }
    if (isOK) {
      okIndex = i;
    }
  }

  if (okIndex != -1) {
    for (size_t k = 0; k < S.size(); k++) {
      if ((size_t)okIndex <= k && k < okIndex + T.size()) {
        cout << T[k - okIndex];
      } else if (S[k] == '?') {
        cout << 'a';
      } else {
        cout << S[k];
      }
    }

    cout << "\n";

    return 0;
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  vector<string> words;
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    string w = s;
    bool ok = true;
    for (int j = i; j < i + t.size(); ++j) {
      if (w[j] != t[j - i] && w[j] != '?')
        ok = false;
    }
    if (ok) {
      for (int j = i; j < i + t.size(); ++j)
        w[j] = t[j - i];
      for (int j = 0; j < s.size(); ++j)
        if (w[j] == '?')
          w[j] = 'a';
      words.push_back(w);
    }
  }
  string ans = "UNRESTORABLE";
  if (words.size() > 0) {
    sort(words.begin(), words.end());
    ans = words[0];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  vector<string> words;
  if (s.size() >= t.size()) {
    for (int i = 0; i <= s.size() - t.size(); ++i) {
      string w = s;
      bool ok = true;
      for (int j = i; j < i + t.size(); ++j) {
        if (w[j] != t[j - i] && w[j] != '?')
          ok = false;
      }
      if (ok) {
        for (int j = i; j < i + t.size(); ++j)
          w[j] = t[j - i];
        for (int j = 0; j < s.size(); ++j)
          if (w[j] == '?')
            w[j] = 'a';
        words.push_back(w);
      }
    }
  }
  string ans = "UNRESTORABLE";
  if (words.size() > 0) {
    sort(words.begin(), words.end());
    ans = words[0];
  }
  cout << ans << endl;
  return 0;
}
Problem p03565 (C++)

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

using namespace std;

bool comp(string s, string t) {
  bool ret = true;

  if (s.size() != t.size()) {
    ret = false;
    cout << "ERROR " << s << " " << t << endl;
  }

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != '?' && s.at(i) != t.at(i)) {
      ret = false;
      break;
    }
  }

  return ret;
}

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

  for (int l = 0; l <= s.size() - t.size(); l++) {
    int r = l + t.size();

    if (comp(s.substr(l, t.size()), t)) {
      hoge.push(s.substr(0, l) + t + s.substr(r, s.size() - r));
    }
  }

  if (hoge.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  priority_queue<string, vector<string>, greater<string>> ans;

  while (!hoge.empty()) {
    string pre = hoge.top();
    hoge.pop();

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

    ans.push(pre);
  }

  cout << ans.top() << endl;

  return 0;
}


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

using namespace std;

bool comp(string s, string t) {
  bool ret = true;

  if (s.size() != t.size()) {
    ret = false;
    cout << "ERROR " << s << " " << t << endl;
  }

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != '?' && s.at(i) != t.at(i)) {
      ret = false;
      break;
    }
  }

  return ret;
}

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

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

  for (int l = 0; l <= s.size() - t.size(); l++) {
    int r = l + t.size();

    if (comp(s.substr(l, t.size()), t)) {
      hoge.push(s.substr(0, l) + t + s.substr(r, s.size() - r));
    }
  }

  if (hoge.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  priority_queue<string, vector<string>, greater<string>> ans;

  while (!hoge.empty()) {
    string pre = hoge.top();
    hoge.pop();

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

    ans.push(pre);
  }

  cout << ans.top() << 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 = "UNRESTORABLE";
  // if (S.size() < T.size())
  // {
  //     cout << ans << 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 tmp = S;
      replace(tmp.begin(), tmp.end(), '?', 'a');
      tmp.replace(i, T.size(), T);
      if (ans.compare("UNRESTORABLE") == 0) {
        ans = tmp;
      } else {
        ans = min(ans, tmp);
      }
    }
  }
  cout << ans << endl;
}


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

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

  string ans = "UNRESTORABLE";
  if (S.size() < T.size()) {
    cout << ans << 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 tmp = S;
      replace(tmp.begin(), tmp.end(), '?', 'a');
      tmp.replace(i, T.size(), T);
      if (ans.compare("UNRESTORABLE") == 0) {
        ans = tmp;
      } else {
        ans = min(ans, tmp);
      }
    }
  }
  cout << ans << endl;
}
Problem p03565 (C++)

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

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

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

  vector<string> candidates(0);
  for (int i = 0; i <= S.length() - T.length(); i++) {
    bool flag = true;
    rep(j, T.length()) {
      if (S[i + j] != '?' && S[i + j] != T[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      string str = S.substr(0, i) + T + S.substr(i + T.length());
      rep(j, str.length()) {
        if (str[j] == '?')
          str[j] = 'a';
      }
      candidates.emplace_back(str);
    }
  }

  if (candidates.size() == 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    partial_sort(candidates.begin(), candidates.begin() + 1, candidates.end());
    cout << candidates[0] << endl;
  }

  /*
  rep(i,candidates.size()){
      cout << candidates[i] << endl;
  }
  */

  return 0;
}

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

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

int main() {
  string S, T;
  cin >> S >> T;
  if (S.length() < T.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  vector<string> candidates(0);
  for (int i = 0; i <= S.length() - T.length(); i++) {
    bool flag = true;
    rep(j, T.length()) {
      if (S[i + j] != '?' && S[i + j] != T[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      string str = S.substr(0, i) + T + S.substr(i + T.length());
      rep(j, str.length()) {
        if (str[j] == '?')
          str[j] = 'a';
      }
      candidates.emplace_back(str);
    }
  }

  if (candidates.size() == 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    partial_sort(candidates.begin(), candidates.begin() + 1, candidates.end());
    cout << candidates[0] << endl;
  }

  /*
  rep(i,candidates.size()){
      cout << candidates[i] << endl;
  }
  */

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main() {

  string s;
  cin >> s;
  string t;
  cin >> t;

  int start = s.length();
  for (int i = 0; i <= s.length() - t.length(); i++) {
    bool flag = true;
    for (int j = 0; j < t.length(); j++) {
      if (t[j] != s[i + j] && s[i + j] != '?') {
        flag = false;
      }
    }
    if (flag) {
      start = i;
    }
  }

  if (start == s.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i < t.length(); i++) {
    s[start + i] = t[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 <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main() {

  string s;
  cin >> s;
  string t;
  cin >> t;

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

  if (start == s.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i < t.length(); i++) {
    s[start + i] = t[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;

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

  vector<int> start_index;
  for (auto i = 0; i <= (s.size() - t.size()); i++) {
    int count = 0;
    for (auto j = 0; j < t.size(); j++) {
      if (s[i + j] == '?' or s[i + j] == t[j])
        count++;
    }
    if (count == t.size())
      start_index.push_back(i);
  }

  if (start_index.empty()) {
    cout << ("UNRESTORABLE") << endl;
    return 0;
  }

  vector<string> key;
  for (int start : start_index) {
    string tmp = "";
    for (auto j = 0; j < s.size(); j++) {
      if (j > start and start + t.size() > j)
        continue;
      if (j == start) {
        tmp += t;
        continue;
      }
      if (s[j] == '?') {
        tmp += 'a';
      } else {
        tmp += s[j];
      }
    }
    key.push_back(tmp);
  }
  sort(key.begin(), key.end());
  cout << key[0] << 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<int> start_index;
  for (auto i = 0; i <= (s.size() - t.size()); i++) {
    int count = 0;
    for (auto j = 0; j < t.size(); j++) {
      if (s[i + j] == '?' or s[i + j] == t[j])
        count++;
    }
    if (count == t.size())
      start_index.push_back(i);
  }

  if (start_index.empty()) {
    cout << ("UNRESTORABLE") << endl;
    return 0;
  }

  vector<string> key;
  for (int start : start_index) {
    string tmp = "";
    for (auto j = 0; j < s.size(); j++) {
      if (j > start and start + t.size() > j)
        continue;
      if (j == start) {
        tmp += t;
        continue;
      }
      if (s[j] == '?') {
        tmp += 'a';
      } else {
        tmp += s[j];
      }
    }
    key.push_back(tmp);
  }
  sort(key.begin(), key.end());
  cout << key[0] << endl;
  return 0;
}
Problem p03565 (C++)

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

using namespace std;

string change(string str) {
  for (size_t i = 0; i < str.size(); i++) {
    if (str[i] == '?') {
      str[i] = 'a';
    }
  }
  return str;
}

int main(int argc, char const *argv[]) {
  string sd, t;
  std::cin >> sd;
  std::cin >> t;

  if (sd.size() < t.size()) {
    std::cout << "UNRESTORABLE" << '\n';
  }

  bool flag = true;
  // 後ろから順番に一致するかを見て行く
  for (size_t i = 0; i <= sd.size() - t.size(); i++) {
    flag = true;
    for (size_t j = 0; j < t.size(); j++) {
      if ((sd[sd.size() - t.size() - i + j] != t[j]) &&
          (sd[sd.size() - t.size() - i + j] != '?')) {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (size_t j = 0; j < t.size(); j++) {
        sd[sd.size() - t.size() - i + j] = t[j];
      }
      sd = change(sd);
      std::cout << sd << '\n';
      return 0;
    }
  }
  std::cout << "UNRESTORABLE" << '\n';
  return 0;
}


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

using namespace std;

string change(string str) {
  for (size_t i = 0; i < str.size(); i++) {
    if (str[i] == '?') {
      str[i] = 'a';
    }
  }
  return str;
}

int main(int argc, char const *argv[]) {
  string sd, t;
  std::cin >> sd;
  std::cin >> t;

  if (sd.size() < t.size()) {
    std::cout << "UNRESTORABLE" << '\n';
    return 0;
  }

  bool flag = true;
  // 後ろから順番に一致するかを見て行く
  for (size_t i = 0; i <= sd.size() - t.size(); i++) {
    flag = true;
    for (size_t j = 0; j < t.size(); j++) {
      if ((sd[sd.size() - t.size() - i + j] != t[j]) &&
          (sd[sd.size() - t.size() - i + j] != '?')) {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (size_t j = 0; j < t.size(); j++) {
        sd[sd.size() - t.size() - i + j] = t[j];
      }
      sd = change(sd);
      std::cout << sd << '\n';
      return 0;
    }
  }
  std::cout << "UNRESTORABLE" << '\n';
  return 0;
}
Problem p03565 (C++)

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

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s, t;
  cin >> s >> t;
  string ans = "UNRESTORABLE";
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    bool flg = true;
    for (int j = 0; j < t.size(); ++j) {
      if (s[i + j] == t[j] || s[i + j] == '?')
        continue;
      else
        flg = false;
    }
    if (!flg)
      continue;
    string sn;
    for (int k = 0; k < s.size(); ++k) {
      if (i <= k && k < i + t.size())
        sn += t[k - i];
      else if (s[k] == '?')
        sn += 'a';
      else
        sn += s[k];
    }
    if (ans[0] == 'U')
      ans = sn;
    else
      ans = min(ans, sn);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s, t;
  cin >> s >> t;
  string ans = "UNRESTORABLE";
  if (s.size() < t.size()) {
    cout << ans << endl;
    return 0;
  }
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    bool flg = true;
    for (int j = 0; j < t.size(); ++j) {
      if (s[i + j] == t[j] || s[i + j] == '?')
        continue;
      else
        flg = false;
    }
    if (!flg)
      continue;
    string sn;
    for (int k = 0; k < s.size(); ++k) {
      if (i <= k && k < i + t.size())
        sn += t[k - i];
      else if (s[k] == '?')
        sn += 'a';
      else
        sn += s[k];
    }
    if (ans[0] == 'U')
      ans = sn;
    else
      ans = min(ans, sn);
  }
  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;
  int index = -1;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool check = true;
    for (int j = 0; j < t.size(); j++) {
      if (s.at(i + j) != t.at(j) && s.at(i + j) != '?')
        check = false;
    }
    if (check)
      index = i;
  }
  if (index == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < s.size(); i++) {
    if (index <= i && i < index + t.size()) {
      cout << t.at(i - index);
    } else if (s.at(i) == '?') {
      cout << 'a';
    } else {
      cout << s.at(i);
    }
  }
  cout << endl;
}


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

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

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int ind = -1;

  for (int i = 0; i <= (int)(s.size() - t.size()); i++) {
    int c = 1;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        c = 0;
        break;
      }
    }
    if (c) {
      ind = i;
    }
  }
  if (ind == -1)
    cout << "UNRESTORABLE\n";
  else {
    int j = 0;
    while (j < t.size()) {
      s[ind + j] = t[j];
      j++;
    }
    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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  vector<string> vc;
  for (int i = 0; i <= S.length() - T.length(); i++) {
    if (S[i] == T[0] || S[i] == '?') {
      int index = i;
      for (int j = 0; j < T.length(); j++) {
        if (S[i + j] != '?' && S[i + j] != T[j])
          index = -1;
      }
      if (index != -1) {
        string ans = S;
        for (int j = 0; j < T.length(); j++)
          ans[index + j] = T[j];
        for (int j = 0; j < ans.length(); j++) {
          if (ans[j] == '?')
            ans[j] = 'a';
        }
        vc.push_back(ans);
      }
    }
  }
  if (vc.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else {
    sort(vc.begin(), vc.end());
    cout << vc[0] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  vector<string> vc;
  if (S.length() < T.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= S.length() - T.length(); i++) {
    if (S[i] == T[0] || S[i] == '?') {
      int index = i;
      for (int j = 0; j < T.length(); j++) {
        if (S[i + j] != '?' && S[i + j] != T[j])
          index = -1;
      }
      if (index != -1) {
        string ans = S;
        for (int j = 0; j < T.length(); j++)
          ans[index + j] = T[j];
        for (int j = 0; j < ans.length(); j++) {
          if (ans[j] == '?')
            ans[j] = 'a';
        }
        vc.push_back(ans);
      }
    }
  }
  if (vc.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else {
    sort(vc.begin(), vc.end());
    cout << vc[0] << endl;
  }
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        break;
      }
      if (j == t.length() - 1) {
        s.replace(i, t.length(), t);
        for (int k = 0; k < s.length(); k++) {
          if (s[k] == '?') {
            s[k] = 'a';
          }
        }
        cout << s << endl;
        return 0;
      }
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  if (s.length() < t.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = s.length() - t.length(); i >= 0; i--) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        break;
      }
      if (j == t.length() - 1) {
        s.replace(i, t.length(), t);
        for (int k = 0; k < s.length(); k++) {
          if (s[k] == '?') {
            s[k] = 'a';
          }
        }
        cout << s << endl;
        return 0;
      }
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// typedef pair<ll, ll> P;

#define rep(i, m) for (ll i = 0; i < (m); i++)
#define rep1(i, m) for (ll i = 1; i <= (m); i++)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

string S, T;

int main() {
  cin >> S >> T;
  for (int i = S.size() - 1; i >= 0; i++) {
    int reable = 0;
    rep(j, T.size()) {
      if (i + j >= S.size()) {
        reable = 1;
        break;
      }
      if (S[i + j] != T[j] && S[i + j] != '?') {
        reable = 1;
        break;
      }
    }
    if (reable == 0) {
      rep(j, T.size()) {
        if (S[i + j] == '?') {
          S[i + j] = T[j];
        }
      }
      rep(k, S.size()) {
        if (S[k] == '?') {
          S[k] = 'a';
        }
      }
      cout << S << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// typedef pair<ll, ll> P;

#define rep(i, m) for (ll i = 0; i < (m); i++)
#define rep1(i, m) for (ll i = 1; i <= (m); i++)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

string S, T;

int main() {
  cin >> S >> T;
  for (int i = S.size() - 1; i >= 0; i--) {
    int reable = 0;
    rep(j, T.size()) {
      if (i + j >= S.size()) {
        reable = 1;
        break;
      }
      if (S[i + j] != T[j] && S[i + j] != '?') {
        reable = 1;
        break;
      }
    }
    if (reable == 0) {
      rep(j, T.size()) {
        if (S[i + j] == '?') {
          S[i + j] = T[j];
        }
      }
      rep(k, S.size()) {
        if (S[k] == '?') {
          S[k] = 'a';
        }
      }
      cout << S << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}
Problem p03565 (C++)

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

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

  set<string> candidates;

  for (int i = 0; i <= s.length() - t.length(); i++) {
    int j;
    for (j = 0; j < t.length(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[j])
        continue;
      else
        break;
    }

    if (j == t.length()) {
      string tmp = s;
      for (j = 0; j < t.length(); j++)
        tmp[i + j] = t[j];
      for (j = 0; j < s.length(); j++)
        if (tmp[j] == '?')
          tmp[j] = 'a';
      candidates.insert(tmp);
    }
  }

  if (candidates.size() > 0) {
    cout << *candidates.begin() << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }

  return 0;
}

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

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

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

  set<string> candidates;

  for (int i = 0; i <= s.length() - t.length(); i++) {
    int j;
    for (j = 0; j < t.length(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[j])
        continue;
      else
        break;
    }

    if (j == t.length()) {
      string tmp = s;
      for (j = 0; j < t.length(); j++)
        tmp[i + j] = t[j];
      for (j = 0; j < s.length(); j++)
        if (tmp[j] == '?')
          tmp[j] = 'a';
      candidates.insert(tmp);
    }
  }

  if (candidates.size() > 0) {
    cout << *candidates.begin() << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll INF = pow(10, 9) + 7;

int main() {
  string s, t;
  cin >> s >> t;
  int u = s.size() - 1;
  int n = t.size() - 1;
  int next = u - 1;
  while (u >= 0) {
    if (s[u] == t[n] || s[u] == '?')
      n--;
    else {
      n = t.size() - 1;
      u = next;
      next = u - 1;
      continue;
    }
    if (n > 0 && next == 0) {
      if (s[u] == t[t.size() - 1] || s[u] == '?')
        next = u;
    }

    if (n < 0) {
      break;
    }
    u--;
  }

  if (u < 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    string ans = "";
    int i = 0;
    while (i < s.size()) {
      if (i == u) {
        ans += t;
        i += t.size();
      } else if (s[i] == '?') {
        ans += 'a';
        i++;
      } else {
        ans += s[i];
        i++;
      }
    }
    cout << ans << 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;
using P = pair<int, int>;
ll INF = pow(10, 9) + 7;

int main() {
  string s, t;
  cin >> s >> t;
  int u = s.size() - 1;
  int n = t.size() - 1;
  int next = u - 1;
  while (u >= 0) {
    if (s[u] == t[n] || s[u] == '?')
      n--;
    else {
      n = t.size() - 1;
      u = next;
      next = u - 1;
      continue;
    }
    if (n < 0) {
      break;
    }
    u--;
  }

  if (u < 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    string ans = "";
    int i = 0;
    while (i < s.size()) {
      if (i == u) {
        ans += t;
        i += t.size();
      } else if (s[i] == '?') {
        ans += 'a';
        i++;
      } else {
        ans += s[i];
        i++;
      }
    }
    cout << ans << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string s, t, ans;
bool check(string x, string y) {
  for (int i = 0; i < x.size(); i++) {
    if (x[i] != '?' && x[i] != y[i])
      return 0;
  }
  return 1;
}
int main() {
  cin >> s >> t;
  ans = "~";
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string st = s.substr(i, t.size());
    if (check(st, t)) {
      string tmp = s;
      tmp.replace(i, t.size(), t);
      for (int j = 0; j < tmp.size(); j++)
        if (tmp[j] == '?')
          tmp[j] = 'a';
      ans = min(ans, tmp);
    }
  }
  if (ans == "~")
    cout << "UNRESTORABLE" << endl;
  else
    cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s, t, ans;
bool check(string x, string y) {
  for (int i = 0; i < x.size(); i++) {
    if (x[i] != '?' && x[i] != y[i])
      return 0;
  }
  return 1;
}
int main() {
  cin >> s >> t;
  ans = "~";
  int ls = s.size(), lt = t.size();
  for (int i = 0; i <= ls - lt; i++) {
    string st = s.substr(i, t.size());
    if (check(st, t)) {
      string tmp = s;
      tmp.replace(i, t.size(), t);
      for (int j = 0; j < tmp.size(); j++)
        if (tmp[j] == '?')
          tmp[j] = 'a';
      ans = min(ans, tmp);
    }
  }
  if (ans == "~")
    cout << "UNRESTORABLE" << endl;
  else
    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;

  int ts = t.size();

  for (int i = 0; i <= s.size() - ts; i++) {
    bool include = true;
    for (int j = 0; j < ts; j++) {
      if (s.at(i + j) != t.at(j))
        include = false;
    }

    if (include) {
      for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == '?')
          s.at(i) = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }

  for (int i = s.size() - ts; i >= 0; i--) {
    bool include = true;
    for (int j = 0; j < ts; j++) {
      if (s.at(i + j) != t.at(j) && s.at(i + j) != '?')
        include = false;
    }

    if (include) {
      for (int j = 0; j < ts; j++) {
        s.at(i + j) = t.at(j);
      }
      for (int j = 0; j < s.size(); j++) {
        if (s.at(j) == '?')
          s.at(j) = 'a';
      }

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

  cout << "UNRESTORABLE" << endl;
}

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

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

  int ts = t.size();

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

  for (int i = 0; i <= s.size() - ts; i++) {
    bool include = true;
    for (int j = 0; j < ts; j++) {
      if (s.at(i + j) != t.at(j))
        include = false;
    }

    if (include) {
      for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == '?')
          s.at(i) = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }

  for (int i = s.size() - ts; i >= 0; i--) {
    bool include = true;
    for (int j = 0; j < ts; j++) {
      if (s.at(i + j) != t.at(j) && s.at(i + j) != '?')
        include = false;
    }

    if (include) {
      for (int j = 0; j < ts; j++) {
        s.at(i + j) = t.at(j);
      }
      for (int j = 0; j < s.size(); j++) {
        if (s.at(j) == '?')
          s.at(j) = 'a';
      }

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

  cout << "UNRESTORABLE" << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int n = -1;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    auto flag = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      n = i;
  }

  if (n != -1) {
    for (int j = 0; j < t.length(); j++) {
      s[n + j] = t[j];
    }
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '?')
        s[i] = 'a';
    }
    cout << s << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int n = -1;
  if (s.length() < t.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.length() - t.length(); i++) {
    auto flag = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      n = i;
  }

  if (n != -1) {
    for (int j = 0; j < t.length(); j++) {
      s[n + j] = t[j];
    }
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '?')
        s[i] = 'a';
    }
    cout << s << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  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;
  int sn = s.size(), tn = t.size();
  vector<string> ans(sn - tn + 1);
  for (int i = 0; i < sn - tn + 1; i++) {
    string ss = s;
    for (int j = 0; j < tn; j++) {
      if (s[j + i] == t[j] || s[j + i] == '?') {
        ss[j + i] = t[j];
      } else {
        ss = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
        break;
      }
    }
    for (int j = 0; j < sn; j++) {
      if (ss[j] == '?')
        ss[j] = 'a';
    }
    ans[i] = ss;
  }

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

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

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define MAX 300000
#define INF 3000
typedef long long ll;
typedef pair<int, int> P;

int main() {
  bool flag = false;
  int count = 0, ans = -1;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++, count = 0) {
    for (int j = 0; j < t.size(), i + j < s.size(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[count]) {
        count++;
      } else
        break;
      if (count == t.size()) {
        ans = i;
      }
    }
  }
  if (ans != -1) {
    for (int j = 0; j < t.size(); j++) {
      s[ans - t.size() + 1 + j] = t[j];
    }
    flag = true;
  }

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


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define MAX 300000
#define INF 3000
typedef long long ll;
typedef pair<int, int> P;

int main() {
  bool flag = false;
  int count = 0, ans = -1;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++, count = 0) {
    for (int j = 0; j < t.size(), i + j < s.size(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[count]) {
        count++;
      } else
        break;
      if (count == t.size()) {
        ans = i + j;
      }
    }
  }
  if (ans != -1) {
    for (int j = 0; j < t.size(); j++) {
      s[ans - t.size() + 1 + j] = t[j];
    }
    flag = true;
  }

  if (flag) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '?')
        cout << "a";
      else
        cout << s[i];
    }
    cout << endl;
  } else
    cout << "UNRESTORABLE" << endl;
}
Problem p03565 (C++)

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

using namespace std;

string S, T;

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

int main() {
  cin >> S >> T;
  string ans;
  for (int i = 0; i < S.size(); i++) {
    ans += 'z';
  }
  bool updated = false;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    if (check(S.substr(i, T.size()), T)) {
      string tmp = S;
      updated = true;
      for (int j = i; j < i + T.size(); j++) {
        tmp[j] = T[j - i];
      }
      for (int j = 0; j < S.size(); j++) {
        if (tmp[j] == '?')
          tmp[j] = 'a';
      }
      if (tmp < ans)
        ans = tmp;
    }
  }
  if (!updated)
    cout << "UNRESTORABLE" << endl;
  else
    cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string S, T;

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

int main() {
  cin >> S >> T;
  string ans;
  if (S.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < S.size(); i++) {
    ans += 'z';
  }
  bool updated = false;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    if (check(S.substr(i, T.size()), T)) {
      string tmp = S;
      updated = true;
      for (int j = i; j < i + T.size(); j++) {
        tmp[j] = T[j - i];
      }
      for (int j = 0; j < S.size(); j++) {
        if (tmp[j] == '?')
          tmp[j] = 'a';
      }
      if (tmp < ans)
        ans = tmp;
    }
  }
  if (!updated)
    cout << "UNRESTORABLE" << endl;
  else
    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;
  cin >> t;
  for (int i = s.length() - t.length(); i >= 0; i--) {
    string ss = s.substr(i, t.length());
    bool ac = true;
    for (int j = 0; j < t.length(); j++) {
      if (ss.at(j) != t.at(j)) {
        if (ss.at(j) != '?')
          ac = false;
      }
    }
    if (ac) {
      s = s.substr(0, i) + t + s.substr(i + 5);
      for (int j = 0; j < s.length(); j++) {
        if (s.at(j) == '?')
          s.at(j) = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}


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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  for (int i = s.length() - t.length(); i >= 0; i--) {
    string ss = s.substr(i, t.length());
    bool ac = true;
    for (int j = 0; j < t.length(); j++) {
      if (ss.at(j) != t.at(j)) {
        if (ss.at(j) != '?')
          ac = false;
      }
    }
    if (ac) {
      s = s.substr(0, i) + t + s.substr(i + t.length());
      for (int j = 0; j < s.length(); j++) {
        if (s.at(j) == '?')
          s.at(j) = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}