Problem:
Score : 200 points

Problem Statement

For a string S consisting of the uppercase English letters P and D, let the doctoral and postdoctoral quotient of S be the total number of occurrences of D and PD in S as contiguous substrings. For example, if S = PPDDP, it contains two occurrences of D and one occurrence of PD as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3.

We have a string T consisting of P, D, and ?.

Among the strings that can be obtained by replacing each ? in T with P or D, find one with the maximum possible doctoral and postdoctoral quotient.

Constraints

1 \leq |T| \leq 2 \times 10^5

T consists of P, D, and ?.

Input

Input is given from Standard Input in the following format:

T

Output

Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each ? in T with P or D.
If there are multiple such strings, you may print any of them.

Sample Input 1

PD?D??P

Sample Output 1

PDPDPDP

This string contains three occurrences of D and three occurrences of PD as contiguous substrings, so its doctoral and postdoctoral quotient is 6, which is the maximum doctoral and postdoctoral quotient of a string obtained by replacing each ? in T with P or D.

Sample Input 2

P?P?

Sample Output 2

PDPD

Solution in Rust (1.42.0) (judge verdict: Runtime Error)

mod prog_comp {

    pub use std::cmp::{max, min};
    pub use std::collections::*;
    pub use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
    pub use std::iter::{repeat, repeat_with};
    pub use std::mem::{size_of, size_of_val, swap};
    pub use std::ops::{Range, RangeBounds};
    pub use std::str::FromStr;

    const BUF_SIZE: usize = 1024;
    pub struct Io<'a> {
        pub reader: Bytes<StdinLock<'a>>,
        pub writer: StdoutLock<'a>,
        pub in_buf: [u8; BUF_SIZE],
    }
    impl<'a> Io<'a> {
        pub fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
            Io {
                reader: stdin.lock().bytes(),
                writer: stdout.lock(),
                in_buf: [0; BUF_SIZE],
            }
        }
        pub fn r<T: FromStr>(&mut self) -> T {
            let mut count = 0;
            loop {
                match self.reader.next() {
                    Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                    None if count > 0 => break,
                    Some(Ok(c)) => self.in_buf[count] = c,
                    _ => panic!(),
                }
                count += 1;
            }

            let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
            s.parse().unwrap_or_else(|_| panic!())
        }
        pub fn ru(&mut self) -> usize {
            self.r()
        }
        pub fn ri(&mut self) -> isize {
            self.r()
        }
        pub fn rf(&mut self) -> f64 {
            self.r()
        }
        pub fn rs(&mut self) -> String {
            self.r()
        }
        pub fn rc(&mut self) -> Vec<char> {
            self.rs().chars().collect()
        }
        pub fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
            IoIter::new(self)
        }

        pub fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.iter().take(n).collect()
        }
        pub fn cu(&mut self, n: usize) -> Vec<usize> {
            self.c(n)
        }
        pub fn ci(&mut self, n: usize) -> Vec<isize> {
            self.c(n)
        }
        pub fn cf(&mut self, n: usize) -> Vec<f64> {
            self.c(n)
        }

        pub fn w<T: std::fmt::Display>(&mut self, v: T) {
            writeln!(self.writer, "{}", v).unwrap();
        }
        pub fn wn<T: std::fmt::Display>(&mut self, v: T) {
            write!(self.writer, "{}", v).unwrap();
        }
    }

    pub struct IoIter<'a: 'b, 'b, T> {
        io: &'b mut Io<'a>,
        m: std::marker::PhantomData<T>,
    }
    impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
        pub fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
            IoIter {
                io,
                m: std::marker::PhantomData,
            }
        }
    }
    impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
        type Item = T;
        fn next(&mut self) -> Option<Self::Item> {
            Some(self.io.r())
        }
    }
    #[macro_export]
    macro_rules! w {
    ($io:expr, $($tt:tt)*) => {
        writeln!($io.writer, $($tt)*).unwrap();
    };
}
    #[macro_export]
    macro_rules! wn {
    ($io:expr, $($tt:tt)*) => {
        write!($io.writer, $($tt)*).unwrap();
    };
}
    #[macro_export]
    macro_rules! init {
        () => {
            use prog_comp::*;
            fn main() {
                let stdin = stdin();
                let stdout = stdout();
                let mut io = Io::new(&stdin, &stdout);
                unsafe {
                    solve(&mut io);
                }
            }
        };
    }
}

use self::prog_comp::*;
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}

unsafe fn solve(io: &mut Io) {
    let mut t = io.rc();

    let mut i = 0;
    while i < t.len() {
        match t[i] {
            '?' => {
                if i == 0 {
                    let mut j = i + 1;
                    while j < t.len() && t[j] == '?' {
                        j += 1;
                    }

                    t[i] = if j == t.len() {
                        'P'
                    } else if (j - i) % 2 == 0 {
                        t[j]
                    } else if t[j] == 'P' {
                        'D'
                    } else {
                        'P'
                    };
                } else if t[i - 1] == 'P' || i + 1 == t.len() || t[i + 1] == 'P' {
                    t[i] = 'D';
                } else {
                    t[i] = 'P';
                }
            }
            _ => {}
        }
        i += 1;
    }

    io.w(t.into_iter().collect::<String>());
}