Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ARREP(i, n, X)                                                         \
  for (int i = 0; i < (n); i++)                                                \
  cin >> X[i]
#define FOR(i, X, n) for (int i = (X); i < (n); i++)
#define EREP(i, n) for (int i = 1; i <= n; i++)

#define DEB(X)                                                                 \
  if (mode == 1)                                                               \
    cout << #X << ": " << X << " ";
#define DEB2(X)                                                                \
  if (mode == 1)                                                               \
    cout << #X << ": "                                                         \
         << " ";
#define ARDEB(i, X)                                                            \
  if (mode == 1)                                                               \
    cout << #X << "[" << i << "]: " << X[i] << " ";
#define FORDEB(n, X)                                                           \
  if (mode == 1)                                                               \
    for (int i = 0; i < (n); i++)                                              \
  ARDEB(i, X)
#define END                                                                    \
  if (mode == 1)                                                               \
    cout << endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
#define ALL(X) X.begin(), X.end()
struct edge {
  int to, cost;
};
// struct edge{int from,cost,to;};

const int INF = 100000000;
int mode = 1;

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ARREP(i, n, X)                                                         \
  for (int i = 0; i < (n); i++)                                                \
  cin >> X[i]
#define FOR(i, X, n) for (int i = (X); i < (n); i++)
#define EREP(i, n) for (int i = 1; i <= n; i++)

#define DEB(X)                                                                 \
  if (mode == 1)                                                               \
    cout << #X << ": " << X << " ";
#define DEB2(X)                                                                \
  if (mode == 1)                                                               \
    cout << #X << ": "                                                         \
         << " ";
#define ARDEB(i, X)                                                            \
  if (mode == 1)                                                               \
    cout << #X << "[" << i << "]: " << X[i] << " ";
#define FORDEB(n, X)                                                           \
  if (mode == 1)                                                               \
    for (int i = 0; i < (n); i++)                                              \
  ARDEB(i, X)
#define END                                                                    \
  if (mode == 1)                                                               \
    cout << endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
#define ALL(X) X.begin(), X.end()
struct edge {
  int to, cost;
};
// struct edge{int from,cost,to;};

const int INF = 100000000;
int mode = 1;

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