Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(), (u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 1e5 + 10;

char s[MR];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  REP(i, n)
  if (s[i] == '?')
    s[i] = 'D';

  printf("%s\n", s);

  return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

// #include <Processthreadsapi.h>
// #include <iostream>
// #include <Synchapi.h>
// #include <windows.h>
// #include <process.h>
//
// DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//     main2(nullptr);
//     return 0;
// }
// int main() {
//     auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr,
//     STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); WaitForSingleObject(h,
//     INFINITE);
// }

Fixed submission:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(), (u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 2e5 + 10;

char s[MR];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  REP(i, n)
  if (s[i] == '?')
    s[i] = 'D';

  printf("%s\n", s);

  return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

// #include <Processthreadsapi.h>
// #include <iostream>
// #include <Synchapi.h>
// #include <windows.h>
// #include <process.h>
//
// DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//     main2(nullptr);
//     return 0;
// }
// int main() {
//     auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr,
//     STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); WaitForSingleObject(h,
//     INFINITE);
// }