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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  string s, t;
  cin >> s >> t;
  vector<string> res;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool now = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j])
        now = false;
    }
    if (now) {
      string in;
      in += s.substr(0, i);
      // cout << i << " " << in << endl;
      in += t;
      // cout << i << " " << in << endl;
      // cout<<i+t.size()+1<<" "<<s.size()-i-t.size()<<endl;
      in += s.substr(i + t.size(), s.size() - i - t.size());
      // cout << i << " " << in << endl;
      for (int k = 0; k < in.size(); k++) {
        if (in[k] == '?')
          in[k] = 'a';
      }
      res.push_back(in);
      // cout << i << " " << in << endl;
    }
    // cout << i << endl;
  }
  sort(res.begin(), res.end());
  if (res.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else
    cout << res[0] << endl;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  if (s.size() == 1 && t.size() == 1) {
    if (s == t || s == "?")
      cout << t << endl;
    else
      cout << "UNRESTORABLE" << endl;
    return 0;
  }
  vector<string> res;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool now = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && s[i + j] != t[j])
        now = false;
    }
    if (now) {
      string in;
      in += s.substr(0, i);
      // cout << i << " " << in << endl;
      in += t;
      // cout << i << " " << in << endl;
      // cout<<i+t.size()+1<<" "<<s.size()-i-t.size()<<endl;
      in += s.substr(i + t.size(), s.size() - i - t.size());
      // cout << i << " " << in << endl;
      for (int k = 0; k < in.size(); k++) {
        if (in[k] == '?')
          in[k] = 'a';
      }
      res.push_back(in);
      // cout << i << " " << in << endl;
    }
    // cout << i << endl;
  }
  sort(res.begin(), res.end());
  if (res.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else
    cout << res[0] << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void) {
  string s, ss;
  cin >> s >> ss;
  size_t l = s.size();
  size_t k = ss.size();
  int ind = -1;
  for (int i = 0; i <= l - k; ++i) {
    int f = 0;
    for (int j = i; j < i + k; ++j) {
      if (s[j] == '?')
        continue;
      if (s[j] != ss[j - i]) {
        f = -1;
        break;
      }
    }
    if (f == 0) {
      ind = i;
    }
  }
  if (ind == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = ind; i < ind + k; ++i) {
    s[i] = ss[i - ind];
  }
  for (int i = 0; i < l; ++i) {
    if (s[i] == '?') {
      cout << 'a';
    } else {
      printf("%c", s[i]);
    }
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void) {
  string s, ss;
  cin >> s >> ss;
  int l = s.size();
  int k = ss.size();
  int ind = -1;
  for (int i = 0; i <= l - k; ++i) {
    int f = 0;
    for (int j = i; j < i + k; ++j) {
      if (s[j] == '?')
        continue;
      if (s[j] != ss[j - i]) {
        f = -1;
        break;
      }
    }
    if (f == 0) {
      ind = i;
    }
  }
  if (ind == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = ind; i < ind + k; ++i) {
    s[i] = ss[i - ind];
  }
  for (int i = 0; i < l; ++i) {
    if (s[i] == '?') {
      cout << 'a';
    } else {
      printf("%c", s[i]);
    }
  }
  cout << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int index = -1;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool no = false;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j] || s[i + j] == '?') {
        continue;
      } else {

        no = true;
      }
    }
    if (!no) {
      index = i;
    }
  }
  if (index != -1) {
    for (int i = 0; i < min(index, (int)s.size()); i++) {
      if (s[i] == '?') {
        cout << "a";
      } else {
        cout << s[i];
      }
    }
    for (int i = 0; i < t.size(); i++) {
      cout << t[i];
    }
    for (int i = t.size() + index; i < s.size(); i++) {
      if (s[i] == '?') {
        cout << "a";
      } else {
        cout << s[i];
      }
    }
  } else {
    cout << "UNRESTORABLE";
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int index = -1;
  if (t.size() > s.size()) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (int i = 0; i <= s.size() - t.size(); i++) {
    bool no = false;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j] || s[i + j] == '?') {
        continue;
      } else {

        no = true;
      }
    }
    if (!no) {
      index = i;
    }
  }
  if (index != -1) {
    for (int i = 0; i < min(index, (int)s.size()); i++) {
      if (s[i] == '?') {
        cout << "a";
      } else {
        cout << s[i];
      }
    }
    for (int i = 0; i < t.size(); i++) {
      cout << t[i];
    }
    for (int i = t.size() + index; i < s.size(); i++) {
      if (s[i] == '?') {
        cout << "a";
      } else {
        cout << s[i];
      }
    }
  } else {
    cout << "UNRESTORABLE";
  }
}
Problem p03565 (C++)

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

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


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

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

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

using namespace std;
typedef long long ll;

const string UNRES = "UNRESTORABLE";

string check(const string &s, const string &t, int i) {
  string ret = s;
  for (int j = 0; j < s.size(); ++j) {
    if (i <= j && j < i + t.size()) {
      if (s.at(j) == '?') {
        ret.at(j) = t.at(j - i);
      } else if (s.at(j) != t.at(j - i)) {
        return UNRES;
      }
    } else if (s.at(j) == '?') {
      ret.at(j) = 'a';
    }
  }
}

int main() {
  string s, t;
  cin >> s >> t;
  string ans = UNRES;
  for (int i = 0; i < s.size() - t.size() + 1; ++i) {
    const string tmp = check(s, t, i);
    if (tmp == UNRES) {
      continue;
    }
    if (ans == UNRES) {
      ans = tmp;
    } else {
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

const string UNRES = "UNRESTORABLE";

string check(const string &s, const string &t, int i) {
  string ret = s;
  for (int j = 0; j < s.size(); ++j) {
    if (i <= j && j < i + t.size()) {
      if (s.at(j) == '?') {
        ret.at(j) = t.at(j - i);
      } else if (s.at(j) != t.at(j - i)) {
        return UNRES;
      }
    } else if (s.at(j) == '?') {
      ret.at(j) = 'a';
    }
  }
  return ret;
}

int main() {
  string s, t;
  cin >> s >> t;
  string ans = UNRES;
  for (int i = 0; i < s.size() - t.size() + 1; ++i) {
    const string tmp = check(s, t, i);
    if (tmp == UNRES) {
      continue;
    }
    if (ans == UNRES) {
      ans = tmp;
    } else {
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <algorithm>
#include <deque>
#include <iostream>
#include <limits.h>
#include <queue>
#include <vector>

using namespace std;

vector<string> strvect;
void solve() {
  string SS, T;
  cin >> SS >> T;
  for (int n = 0; n <= SS.size() - T.size(); n++) {
    // SSのn文字目からTに置き換える
    bool flag = true;
    for (int t = 0; t < T.size(); t++) {
      if (SS[n + t] == '?')
        continue;
      if (SS[n + t] != T[t]) {
        flag = false;
        break;
      }
    }
    if (!flag)
      continue;
    string sstemp = SS;
    for (int ntemp = 0; ntemp < n; ntemp++) {
      if (sstemp[ntemp] == '?')
        sstemp[ntemp] = 'a';
    }
    for (int t = 0; t < T.size(); t++) {
      sstemp[n + t] = T[t];
    }
    for (int ntemp = n + T.size(); ntemp < SS.size(); ntemp++) {
      if (sstemp[ntemp] == '?')
        sstemp[ntemp] = 'a';
    }
    strvect.push_back(sstemp);
  }
  if (strvect.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return;
  }
  sort(strvect.begin(), strvect.end(), [](string a, string b) {
    for (int i = 0; i < min(a.size(), b.size()); i++) {
      if (a[i] != b[i])
        return a[i] < b[i];
    }
    return a.size() < b.size();
  });
  cout << strvect[0] << endl;
  return;
}

Fixed submission:
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <algorithm>
#include <deque>
#include <iostream>
#include <limits.h>
#include <queue>
#include <vector>

using namespace std;

vector<string> strvect;
void solve() {
  string SS, T;
  cin >> SS >> T;
  for (int n = 0; n <= (int)SS.size() - (int)T.size(); n++) {
    // SSのn文字目からTに置き換える
    bool flag = true;
    for (int t = 0; t < T.size(); t++) {
      if (SS[n + t] == '?')
        continue;
      if (SS[n + t] != T[t]) {
        flag = false;
        break;
      }
    }
    if (!flag)
      continue;
    string sstemp = SS;
    for (int ntemp = 0; ntemp < n; ntemp++) {
      if (sstemp[ntemp] == '?')
        sstemp[ntemp] = 'a';
    }
    for (int t = 0; t < T.size(); t++) {
      sstemp[n + t] = T[t];
    }
    for (int ntemp = n + T.size(); ntemp < SS.size(); ntemp++) {
      if (sstemp[ntemp] == '?')
        sstemp[ntemp] = 'a';
    }
    strvect.push_back(sstemp);
  }
  if (strvect.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return;
  }
  sort(strvect.begin(), strvect.end(), [](string a, string b) {
    for (int i = 0; i < min(a.size(), b.size()); i++) {
      if (a[i] != b[i])
        return a[i] < b[i];
    }
    return a.size() < b.size();
  });
  cout << strvect[0] << endl;
  return;
}
Problem p03565 (C++)

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

int main() {
  string SS, T;
  cin >> SS >> T;
  reverse(SS.begin(), SS.end());
  reverse(T.begin(), T.end());
  bool can = false;
  for (int i = 0; i <= SS.size() - T.size(); i++) {
    int j = 0;
    while (SS.at(i + j) == '?' || SS.at(i + j) == T.at(j)) {
      // cout << "i " << i << " j " << j << endl;
      if (j == T.size() - 1) {
        // cout << "OK" << endl;
        SS.replace(i, j + 1, T);
        can = true;
        break;
      } else {
        j++;
        if (i + j == SS.size())
          break;
      }
    }
    if (can)
      break;
  }

  if (can) {
    for (int i = 0; i < SS.size(); i++) {
      if (SS.at(i) == '?') {
        SS.replace(i, 1, "a");
      }
    }
    reverse(SS.begin(), SS.end());
  } else {
    SS = "UNRESTORABLE";
  }

  cout << SS << endl;
}

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

int main() {
  string SS, T;
  cin >> SS >> T;
  reverse(SS.begin(), SS.end());
  reverse(T.begin(), T.end());
  bool can = false;
  if (SS.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= SS.size() - T.size(); i++) {
    int j = 0;
    while (SS.at(i + j) == '?' || SS.at(i + j) == T.at(j)) {
      // cout << "i " << i << " j " << j << endl;
      if (j == T.size() - 1) {
        // cout << "OK" << endl;
        SS.replace(i, j + 1, T);
        can = true;
        break;
      } else {
        j++;
        if (i + j == SS.size())
          break;
      }
    }
    if (can)
      break;
  }

  if (can) {
    for (int i = 0; i < SS.size(); i++) {
      if (SS.at(i) == '?') {
        SS.replace(i, 1, "a");
      }
    }
    reverse(SS.begin(), SS.end());
  } else {
    SS = "UNRESTORABLE";
  }

  cout << SS << endl;
}
Problem p03565 (C++)

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

int main() {
  int lens, lent;
  bool flag = true, flg = false;
  string s, t, ans, tmp = "";
  cin >> s >> t;
  ans = s;
  lens = s.size();
  lent = t.size();
  for (int i = 0; i < lens; i++)
    tmp += 'z';
  for (int j = 0; j <= lens - lent; j++) {
    ans = s;
    flag = true;
    for (int i = 0; i < lent; i++)
      if (s.at(lens - i - j - 1) != '?' &&
          s.at(lens - i - j - 1) != t.at(lent - i - 1)) {
        flag = false;
      } else
        ans.at(lens - i - j - 1) = t.at(lent - i - 1);
    if (flag) {
      flg = true;
      replace(ans.begin(), ans.end(), '?', 'a');
      if (tmp > ans)
        tmp = ans;
      //                goto OUT;
      //            cout << ans << endl;
    }
  }
  if (!flg) {
    cout << "UNRESTORABLE" << endl;
    return 1;
  }
  //    OUT:;
  cout << tmp << endl;
}

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

int main() {
  int lens, lent;
  bool flag = true, flg = false;
  string s, t, ans, tmp = "";
  cin >> s >> t;
  ans = s;
  lens = s.size();
  lent = t.size();
  for (int i = 0; i < lens; i++)
    tmp += 'z';
  for (int j = 0; j <= lens - lent; j++) {
    ans = s;
    flag = true;
    for (int i = 0; i < lent; i++)
      if (s.at(lens - i - j - 1) != '?' &&
          s.at(lens - i - j - 1) != t.at(lent - i - 1)) {
        flag = false;
      } else
        ans.at(lens - i - j - 1) = t.at(lent - i - 1);
    if (flag) {
      flg = true;
      replace(ans.begin(), ans.end(), '?', 'a');
      if (tmp > ans)
        tmp = ans;
      //                goto OUT;
      //            cout << ans << endl;
    }
  }
  if (!flg) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  //    OUT:;
  cout << tmp << endl;
}
Problem p03565 (C++)

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

bool zcomp(string::iterator first1, string::iterator last1,
           string::iterator first2) {
  bool flag = true;
  for (auto it1 = first1, it2 = first2; it1 != last1; it1++, it2++) {
    if (*it1 != *it2 && *it2 != '?') {
      flag = false;
      break;
    }
  }
  return flag;
}

int main(void) {
  string s, t;
  set<string> ans;
  cin >> s >> t;
  for (int i = s.size() - t.size(); i >= 0; i--) {
    if (zcomp(t.begin(), t.end(), s.begin() + i)) {
      string temp = s;
      temp.replace(i, t.size(), t);
      replace(temp.begin(), temp.end(), '?', 'a');
      ans.insert(temp);
    }
  }
  cout << *ans.begin() << endl;
}

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

bool zcomp(string::iterator first1, string::iterator last1,
           string::iterator first2) {
  bool flag = true;
  for (auto it1 = first1, it2 = first2; it1 != last1; it1++, it2++) {
    if (*it1 != *it2 && *it2 != '?') {
      flag = false;
      break;
    }
  }
  return flag;
}

int main(void) {
  string s, t;
  set<string> ans;
  cin >> s >> t;
  for (int i = s.size() - t.size(); i >= 0; i--) {
    if (zcomp(t.begin(), t.end(), s.begin() + i)) {
      string temp = s;
      temp.replace(i, t.size(), t);
      replace(temp.begin(), temp.end(), '?', 'a');
      ans.insert(temp);
    }
  }
  cout << (!ans.empty() ? *ans.begin() : "UNRESTORABLE") << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <regex>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  vector<string> v;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    string str = S;
    int j = 0;
    bool flag = true;
    while (j < T.size()) {
      if (str[i + j] != '?' && str[i + j] != T[j]) {
        flag = false;
        break;
      }
      j++;
    }
    if (flag) {
      str.replace(i, T.size(), T);
      for (int i = 0; i < str.size(); i++) {
        if (str[i] == '?')
          str[i] = 'a';
      }
      v.push_back(str);
    }
  }
  if (v.size() == 0) {
    printf("UNRESTORABLE\n");
    return 0;
  } else if (v.size() == 1) {
    cout << v[0] << endl;
    return 0;
  }

  string min = v.front();
  for (auto itr = v.begin() + 1; itr != v.end(); ++itr) {
    string now = *itr;
    for (int i = 0; i < S.size(); i++) {
      if (min[i] > now[i]) {
        min = now;
        break;
      }
    }
  }
  // 辞書順比較
  cout << min << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <regex>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  if (S.size() < T.size()) {
    printf("UNRESTORABLE\n");
    return 0;
  }

  vector<string> v;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    string str = S;
    int j = 0;
    bool flag = true;
    while (j < T.size()) {
      if (str[i + j] != '?' && str[i + j] != T[j]) {
        flag = false;
        break;
      }
      j++;
    }
    if (flag) {
      str.replace(i, T.size(), T);
      for (int i = 0; i < str.size(); i++) {
        if (str[i] == '?')
          str[i] = 'a';
      }
      v.push_back(str);
    }
  }
  if (v.size() == 0) {
    printf("UNRESTORABLE\n");
    return 0;
  } else if (v.size() == 1) {
    cout << v[0] << endl;
    return 0;
  }

  string min = v.front();
  for (auto itr = v.begin() + 1; itr != v.end(); ++itr) {
    string now = *itr;
    for (int i = 0; i < S.size(); i++) {
      if (min[i] > now[i]) {
        min = now;
        break;
      }
    }
  }
  // 辞書順比較
  cout << min << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
set<string> ss;
string s, t;

bool Search(int i) {
  int k = 0;
  for (int j = i; j <= i + t.length() - 1;) {
    if (s[j] == t[k] || s[j] == '?') {
      k++;
      ++j;
    } else {
      return false;
    }
  }
  if (k == t.length()) {
    string z = s;
    int temp = 0;
    for (int j = i; j <= i + t.length() - 1; ++j) {
      z[j] = t[temp];
      temp++;
    }
    int pos = z.find('?');
    while (pos != -1) {
      z[pos] = 'a';
      pos = z.find('?');
    }
    ss.insert(z);
    return true;
  } else {
    return false;
  }
}
int main(void) {
  cin >> s >> t;
  for (int i = 0; i <= s.length() - t.length(); ++i) {
    Search(i);
  }
  if (ss.empty()) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << *ss.begin() << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
set<string> ss;
string s, t;

bool Search(int i) {
  int k = 0;
  for (int j = i; j <= i + t.length() - 1;) {
    if (s[j] == t[k] || s[j] == '?') {
      k++;
      ++j;
    } else {
      return false;
    }
  }
  if (k == t.length()) {
    string z = s;
    int temp = 0;
    for (int j = i; j <= i + t.length() - 1; ++j) {
      z[j] = t[temp];
      temp++;
    }
    int pos = z.find('?');
    while (pos != -1) {
      z[pos] = 'a';
      pos = z.find('?');
    }
    ss.insert(z);
    return true;
  } else {
    return false;
  }
}
int main(void) {
  cin >> s >> t;
  if (t.length() > s.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.length() - t.length(); ++i) {
    Search(i);
  }
  if (ss.empty()) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << *ss.begin() << endl;
  }
  return 0;
}
Problem p03565 (C++)

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

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

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

using namespace std;

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

// 45106 - 111

void oneCase() {
  string s, t;
  cin >> s >> t;
  vector<string> ans;
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    string f(i, '?');
    string e(s.size() - t.size() - i, '?');
    auto cnd = f + t + e;
    int ok = 1;
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] == '?' && cnd[j] == '?') {
        cnd[j] = 'a';
        continue;
      }
      if (s[j] != '?' && cnd[j] != '?' && s[j] != cnd[j]) {
        ok = 0;
        break;
      }
      if (s[j] != '?' && cnd[j] == '?') {
        cnd[j] = s[j];
      }
    }
    if (ok) {
      ans.pb(cnd);
    }
  }
  if (!ans.empty()) {
    sort(ans.begin(), ans.end());
    cout << ans.front() << "\n";
    return;
  }

  cout << "UNRESTORABLE"
       << "\n";
}

int main() {
  int t = 1;
  //    cin >> t;
  while (t--) {
    oneCase();
  }

  return 0;
}


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

using namespace std;

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

// 45106 - 111

void oneCase() {
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE"
         << "\n";
    return;
  }
  vector<string> ans;
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    string f(i, '?');
    string e(s.size() - t.size() - i, '?');
    auto cnd = f + t + e;
    int ok = 1;
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] == '?' && cnd[j] == '?') {
        cnd[j] = 'a';
        continue;
      }
      if (s[j] != '?' && cnd[j] != '?' && s[j] != cnd[j]) {
        ok = 0;
        break;
      }
      if (s[j] != '?' && cnd[j] == '?') {
        cnd[j] = s[j];
      }
    }
    if (ok) {
      ans.pb(cnd);
    }
  }
  if (!ans.empty()) {
    sort(ans.begin(), ans.end());
    cout << ans.front() << "\n";
    return;
  }

  cout << "UNRESTORABLE"
       << "\n";
}

int main() {
  int t = 1;
  //    cin >> t;
  while (t--) {
    oneCase();
  }

  return 0;
}
Problem p03565 (C++)

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

using namespace std;
typedef pair<int, int> P;
typedef vector<P> pairs;

int main() {
  string S, T;
  int N, M, a, b, x, ans = 0;
  int ind = -1;
  pairs vi;
  cin >> S >> T;
  for (int i = 0; i < S.size() - T.size(); i++) {
    int j = 0;
    while (S[i + j] == T[j] || S[i + j] == '?') {
      j++;
      if (j == T.size()) {
        ind = i;
        break;
      }
    }
  }
  if (ind != -1) {
    for (int i = 0; i < T.size(); i++) {
      S[i + ind] = T[i];
    }
  }

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

  if (ind == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << S << endl;
  }
}

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

using namespace std;
typedef pair<int, int> P;
typedef vector<P> pairs;

int main() {
  string S, T;
  int N, M, a, b, x, ans = 0;
  int ind = -1;
  pairs vi;
  cin >> S >> T;
  for (int i = 0; i < S.size() - T.size() + 1; i++) {
    int j = 0;
    while (S[i + j] == T[j] || S[i + j] == '?') {
      j++;
      if (j == T.size()) {
        ind = i;
        break;
      }
    }
  }
  if (ind != -1) {
    for (int i = 0; i < T.size(); i++) {
      S[i + ind] = T[i];
    }
  }

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

  if (ind == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << S << endl;
  }
}
Problem p03565 (C++)

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

using namespace std;

using int64 = long long;

int main() {
  string S, T;

  cin >> S;
  cin >> T;

  string x = "~";
  for (int i = 0; i <= (int)S.size() - T.size(); i++) {
    bool match = true;
    for (int j = 0; j < T.size(); j++) {
      match &= S[i + j] == '?' || S[i + j] == T[j];
    }

    if (match) {
      string Q = S;
      for (int j = 0; j < T.size(); j++)
        Q[i + j] = T[j];
      for (int j = 0; j < Q.size(); j++)
        if (Q[j] == '?')
          Q[j] = 'a';
      x = min(x, Q);
    }
  }

  if (x == "~")
    x = "UNRESTORABLE";
  cout << x << endl;
}

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

using namespace std;

using int64 = long long;

int main() {
  string S, T;

  cin >> S;
  cin >> T;

  string x = "~";
  for (int i = 0; i <= (int)S.size() - (int)T.size(); i++) {
    bool match = true;
    for (int j = 0; j < T.size(); j++) {
      match &= S[i + j] == '?' || S[i + j] == T[j];
    }

    if (match) {
      string Q = S;
      for (int j = 0; j < T.size(); j++)
        Q[i + j] = T[j];
      for (int j = 0; j < Q.size(); j++)
        if (Q[j] == '?')
          Q[j] = 'a';
      x = min(x, Q);
    }
  }

  if (x == "~")
    x = "UNRESTORABLE";
  cout << x << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fr(i, n) for (i = 0; i < (n); ++i)
#define Fr(i, n) for (int i = 1; i <= (n); ++i)
#define ifr(i, n) for (int i = (n)-1; i >= 0; --i)
#define iFr(i, n) for (int i = (n); i > 0; --i)

int main(void) {
  string s, t;
  cin >> s >> t;
  reverse(s.begin(), s.end()), reverse(t.begin(), t.end());
  bool can = false;
  int i;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == t[0] || s[i] == '?') {
      can = true;
      Fr(j, t.size() - 1) {
        if (i + j >= s.size()) {
          can = false;
          break;
        }
        if (s[i + j] != t[j] && s[i + j] != '?')
          can = false;
      }
    }
    if (can)
      break;
  }
  for (int j = 0; j < t.size(); j++)
    s[j + i] = t[j];
  for (int j = 0; j < s.size(); j++)
    if (s[j] == '?')
      s[j] = 'a';
  reverse(s.begin(), s.end());
  cout << (can ? s : "UNRESTORABLE") << endl;
  return 0;
}


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

int main(void) {
  string s, t;
  cin >> s >> t;
  reverse(s.begin(), s.end()), reverse(t.begin(), t.end());
  bool can = false;
  int i;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == t[0] || s[i] == '?') {
      can = true;
      Fr(j, t.size() - 1) {
        if (i + j >= s.size()) {
          can = false;
          break;
        }
        if (s[i + j] != t[j] && s[i + j] != '?')
          can = false;
      }
    }
    if (can)
      break;
  }
  if (can) {
    for (int j = 0; j < t.size(); j++)
      s[j + i] = t[j];
    for (int j = 0; j < s.size(); j++)
      if (s[j] == '?')
        s[j] = 'a';
    reverse(s.begin(), s.end());
    cout << s << endl;
  } else
    cout << "UNRESTORABLE" << endl;
  return 0;
}
Problem p03565 (C++)

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int b;
string s;
string t;
int main() {
  cin >> s >> t;
  int n = 0;
  if (t.size() > s.size()) {
    cout << "UNRESTORABLE";
    return 0;
  }
  for (int i = 0; i <= s.size() - t.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        break;
      }
      if (j == t.size() - 1) {
        b = 1;
        n = i;
      }
    }
  }
  if (b == 1) {
    for (int i = 0; i < n; i++) {
      cout << (s[i] == '?' ? 'a' : s[i]);
    }
    cout << t;
    for (int i = n + t.size(); i < s.size(); i++) {
      cout << (s[i] == '?' ? 'a' : s[i]);
    }
  } else
    cout << "UNRESTORABLE";
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

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

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

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

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

int match_t(int pos, string s, string t);
string substitute(int pos, string s, string t);

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

  string result = "UNRESTORABLE";
  string temp;
  for (int i = 0; i <= s.size() - t.size(); ++i) {
    if (match_t(i, s, t) != 0) {
      temp = substitute(i, s, t);
      // fprintf(stderr,"matched at %d, %s\n",i,temp.c_str());
      if ((result == "UNRESTORABLE") || (temp < result)) {
        result = temp;
      }
    }
  }
  cout << result << endl;
}

int match_t(int pos, string s, string t) {
  for (int i = 0; i < t.size(); ++i) {
    if ((s[pos + i] != '?') && (s[pos + i] != t[i])) {
      return 0;
    }
  }
  return 1;
}

string substitute(int pos, string s, string t) {

  for (int i = 0; i < t.size(); ++i) {
    if (s[pos + i] == '?') {
      s[pos + i] = t[i];
    }
  }

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '?') {
      s[i] = 'a';
    }
  }

  return s;
}


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

int match_t(int pos, string s, string t);
string substitute(int pos, string s, string t);

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

  string result = "UNRESTORABLE";
  string temp;

  if (t.size() > s.size()) {
    cout << result << endl;
    return 0;
  }

  for (int i = 0; i <= s.size() - t.size(); ++i) {
    if (match_t(i, s, t) != 0) {
      temp = substitute(i, s, t);
      // fprintf(stderr,"matched at %d, %s\n",i,temp.c_str());
      if ((result == "UNRESTORABLE") || (temp < result)) {
        result = temp;
      }
    }
  }
  cout << result << endl;
}

int match_t(int pos, string s, string t) {
  for (int i = 0; i < t.size(); ++i) {
    if ((s[pos + i] != '?') && (s[pos + i] != t[i])) {
      return 0;
    }
  }
  return 1;
}

string substitute(int pos, string s, string t) {

  for (int i = 0; i < t.size(); ++i) {
    if (s[pos + i] == '?') {
      s[pos + i] = t[i];
    }
  }

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '?') {
      s[i] = 'a';
    }
  }

  return s;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;

int main(void) {
  string S, T;
  cin >> S >> T;
  string ans = "";
  if (S.size() < T.size()) {
    cout << "UNRESTORABLE\n" << endl;
  }
  string SS = S;
  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]) {

      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int j = 0; j < T.size(); ++j) {
        S[i + j] = T[j];
      }
      for (int j = 0; j < S.size(); ++j) {
        if (S[j] == '?')
          S[j] = 'a';
      }
      if (ans.empty()) {
        ans = S;
      } else {
        ans = min(ans, S);
      }
    }
    S = SS;
  }
  if (ans.empty())
    cout << "UNRESTORABLE\n";
  else {
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;

int main(void) {
  string S, T;
  cin >> S >> T;
  string ans = "";
  if (S.size() < T.size()) {
    cout << "UNRESTORABLE\n" << endl;
    return 0;
  }
  string SS = S;
  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]) {

      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int j = 0; j < T.size(); ++j) {
        S[i + j] = T[j];
      }
      for (int j = 0; j < S.size(); ++j) {
        if (S[j] == '?')
          S[j] = 'a';
      }
      if (ans.empty()) {
        ans = S;
      } else {
        ans = min(ans, S);
      }
    }
    S = SS;
  }
  if (ans.empty())
    cout << "UNRESTORABLE\n";
  else {
    cout << ans << endl;
  }
  return 0;
}
Problem p03565 (C++)

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

#define REP(i, a, n) for (int i = a; i < n; i++)

using namespace std;

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

  bool flag1 = false;

  REP(i, 0, s.size() - t.size() - 1) {
    bool flag2 = true;
    REP(j, 0, t.size()) {
      if (t[t.size() - j - 1] != s[s.size() - j - i - 1] and
          s[s.size() - j - i - 1] != '?') {
        flag2 = false;
        break;
      }
    }

    if (flag2 == true) {
      flag1 = true;
      REP(j, 0, t.size()) { s[s.size() - j - i - 1] = t[t.size() - j - 1]; }

      break;
    }
  }

  if (flag1 == true) {
    REP(i, 0, s.size()) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;

  } else {
    cout << "UNRESTORABLE" << endl;
  }
}


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

#define REP(i, a, n) for (int i = a; i < n; i++)

using namespace std;

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

  bool flag1 = false;

  REP(i, 0, s.size() - t.size() + 1) {
    bool flag2 = true;
    REP(j, 0, t.size()) {
      if (t[t.size() - j - 1] != s[s.size() - j - i - 1] and
          s[s.size() - j - i - 1] != '?') {
        flag2 = false;
        break;
      }
    }

    if (flag2 == true) {
      flag1 = true;
      REP(j, 0, t.size()) { s[s.size() - j - i - 1] = t[t.size() - j - 1]; }

      break;
    }
  }

  if (flag1 == true) {
    REP(i, 0, s.size()) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;

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

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

bool finder(int now_place, string &S, string &T) {
  int tmp = 0;
  int S_size = S.size();
  for (int i = now_place; i < S_size; i++) {
    if (S.at(i) == T.at(tmp) || S.at(i) == '?') {
      tmp++;
      if (tmp >= T.size()) {
        return true;
      }
    } else {
      return false;
    }
  }
  return false;
}

int main() {
  string S, T, ans;
  cin >> S;
  cin >> T;
  int S_size = S.size(), T_size = T.size();
  vector<int> checker(S_size, 0);

  int key = -1;

  for (int i = 0; i < S_size; i++) {
    if (S.at(i) == '?') {
      checker.at(i) = 1;
    }
    if (finder(i, S, T))
      key = i;
  }

  if (key == -1) {
    cout << "UNRESTORABLE";
  } else {
    for (int i = 0; i < S_size; i++) {
      if (checker.at(i) == 1) {
        if (i - key < 0 || i - key > T_size) {
          S.at(i) = 'a';
        } else {
          S.at(i) = T.at(i - key);
        }
      }
    }
    cout << S << endl;
  }
}

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

bool finder(int now_place, string &S, string &T) {
  int tmp = 0;
  int S_size = S.size();
  for (int i = now_place; i < S_size; i++) {
    if (S.at(i) == T.at(tmp) || S.at(i) == '?') {
      tmp++;
      if (tmp >= T.size()) {
        return true;
      }
    } else {
      return false;
    }
  }
  return false;
}

int main() {
  string S, T, ans;
  cin >> S;
  cin >> T;
  int S_size = S.size(), T_size = T.size();
  vector<int> checker(S_size, 0);

  int key = -1;

  for (int i = 0; i < S_size; i++) {
    if (S.at(i) == '?') {
      checker.at(i) = 1;
    }
    if (finder(i, S, T))
      key = i;
  }

  if (key == -1) {
    cout << "UNRESTORABLE";
  } else {
    for (int i = 0; i < S_size; i++) {
      if (checker.at(i) == 1) {
        if (i - key < 0 || i - key >= T_size) {
          S.at(i) = 'a';
        } else {
          S.at(i) = T.at(i - key);
        }
      }
    }
    cout << S << endl;
  }
}
Problem p03565 (C++)

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

#define ll long long

using namespace std;

string S_, T;
vector<string> S;

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

int main() {
  cin >> S_ >> T;
  for (size_t i = 0; i <= S_.size() - T.size(); i++) {
    string S_sub = S_.substr(i, T.size());
    if (match(S_sub)) {

      string S_ans(S_.size(), 'a');
      for (size_t j = 0; j < S_ans.size(); j++) {
        if (j >= i && j < i + T.size()) {
          S_ans[j] = T[j - i];
        } else {
          if (S_[j] != '?') {
            S_ans[j] = S_[j];
          }
        }
      }
      S.push_back(S_ans);
    }
  }

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

string S_, T;
vector<string> S;

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

int main() {
  cin >> S_ >> T;
  if (S_.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (size_t i = 0; i <= S_.size() - T.size(); i++) {
    string S_sub = S_.substr(i, T.size());
    if (match(S_sub)) {

      string S_ans(S_.size(), 'a');
      for (size_t j = 0; j < S_ans.size(); j++) {
        if (j >= i && j < i + T.size()) {
          S_ans[j] = T[j - i];
        } else {
          if (S_[j] != '?') {
            S_ans[j] = S_[j];
          }
        }
      }
      S.push_back(S_ans);
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

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

  vector<string> list;
  for (auto i = 0; i <= S.size() - T.size(); ++i) {
    auto isValid = true;

    for (auto j = 0; j < T.size(); ++j) {
      if (S[i + j] != '?' && S[i + j] != T[j]) {
        isValid = false;
        break;
      }
    }

    if (isValid) {
      string temp = "";
      if (i > 0) {
        temp = S.substr(0, i);
      }
      temp += T;
      if (i + T.size() < S.size()) {
        temp += S.substr(i + T.size());
      }

      replace(temp.begin(), temp.end(), '?', 'a');
      list.push_back(temp);
    }
  }

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

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

  vector<string> list;
  for (auto i = 0; i <= (int)S.size() - (int)T.size(); ++i) {
    auto isValid = true;

    for (auto j = 0; j < T.size(); ++j) {
      if (S[i + j] != '?' && S[i + j] != T[j]) {
        isValid = false;
        break;
      }
    }

    if (isValid) {
      string temp = "";
      if (i > 0) {
        temp = S.substr(0, i);
      }
      temp += T;
      if (i + T.size() < S.size()) {
        temp += S.substr(i + T.size());
      }

      replace(temp.begin(), temp.end(), '?', 'a');
      list.push_back(temp);
    }
  }

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

  return 0;
}
Problem p03565 (C++)

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

using namespace std;

int main(int argc, char const *argv[]) {
  string sp;
  string t;
  cin >> sp >> t;
  set<int> st;
  for (int i = 0; i + t.size() <= sp.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (sp[i + j] != t[j] && sp[i + j] != '?')
        break;
      if (j == t.size() - 1) {
        st.insert(i);
      }
    }
  }
  if (st.size() == 0) {
    cout << "UNRESTORABLE" << endl;
  }
  auto itr = st.end();
  --itr;
  for (int i = 0; i < t.size(); i++) {
    sp[*itr + i] = t[i];
  }
  for (int i = 0; i < sp.size(); i++) {
    if (sp[i] == '?')
      sp[i] = 'a';
  }
  cout << sp << endl;
  return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  string sp;
  string t;
  cin >> sp >> t;
  set<int> st;
  for (int i = 0; i + t.size() <= sp.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (sp[i + j] != t[j] && sp[i + j] != '?')
        break;
      if (j == t.size() - 1) {
        st.insert(i);
      }
    }
  }
  if (st.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  auto itr = st.end();
  --itr;
  for (int i = 0; i < t.size(); i++) {
    sp[*itr + i] = t[i];
  }
  for (int i = 0; i < sp.size(); i++) {
    if (sp[i] == '?')
      sp[i] = 'a';
  }
  cout << sp << endl;
  return 0;
}