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 C# (.NET Core 3.1.201) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class Nomura_B
    {
        public static void Main(string[] args)
        {
            // 文字列の入力
            string s = Console.ReadLine();

            List<int> where_is_q = new List<int>();
            char[] char_s = s.ToCharArray();

            ////?位置のリストアップ
            for (int Count = 0; Count < s.Length; Count++)
            {
                if (s[Count] == '?')
                {
                    where_is_q.Add(Count);
                }
            }

            int Max_PD = 0;
            string MAX_String = "";

            List<string[]> sourceList = new List<string[]>(where_is_q.Count);
            for (int Q_Count = 0; Q_Count < where_is_q.Count; Q_Count++)
            { 
                sourceList.Add(new string[] { "P", "D" });
            }

            List<string[]> resultList = Combinations<string>.GetCombinations(sourceList);

            for (int POSITION = 0; POSITION < resultList.Count; POSITION++)
            {
                char[] new_s = char_s;
                for (int where_is_q_position = 0; where_is_q_position < where_is_q.Count; where_is_q_position++)
                {

                    var data = resultList[POSITION];
                    for(int char_count=0;char_count< data.Length;char_count++)
                    {
                        new_s[where_is_q[where_is_q_position]] = data[char_count].ToCharArray()[0];
                    }
                }

                int count_D = Global.CountOf(new string(new_s), "D");
                int count_PD = Global.CountOf(new string(new_s), "PD");

                if (count_D + count_PD > Max_PD)
                {
                    Max_PD = count_D + count_PD;
                    MAX_String =new string(new_s);
                }
            }

            string result = MAX_String;

            Console.WriteLine(result);

            Console.Out.Flush();

        }

        public static class Combinations<T>
        {
            public static List<T[]> GetCombinations(List<T[]> sourceList)
            {
                List<T[]> resultList = new List<T[]>();
                Stack<T> stack = new Stack<T>();
                GetCombinationsCore(stack, resultList, sourceList);

                return resultList;
            }

            private static void GetCombinationsCore(Stack<T> stack, List<T[]> resultList, List<T[]> sourceList)
            {
                int dimension = stack.Count;
                if (sourceList.Count <= dimension)
                {
                    T[] array = stack.ToArray();
                    Array.Reverse(array);
                    resultList.Add(array);
                    return;
                }
                else
                {
                    foreach (T item in sourceList[dimension])
                    {
                        stack.Push(item);
                        GetCombinationsCore(stack, resultList, sourceList);
                        stack.Pop();
                    }
                }
            }
        }

        class Global
        {

            /// <summary>
            /// 指定した文字列がいくつあるか
            /// </summary>
            public static int CountOf(string target, params string[] strArray)
            {
                int count = 0;

                foreach (string str in strArray)
                {
                    int index = target.IndexOf(str, 0);
                    while (index != -1)
                    {
                        count++;
                        index = target.IndexOf(str, index + str.Length);
                    }
                }

                return count;
            }

            public static string Left(string str, int len)
            {
                if (str == null || len <= 0)
                {
                    return "";
                }

                if (str.Length >= len && str.Length >= 0)
                {
                    return str.Substring(0, len);
                }
                else
                {
                    return str;
                }
            }


            public static string Right(string str, int len)
            {
                if (str.Length >= len && str.Length >= 0)
                {
                    return str.Substring(str.Length - len);
                }
                else
                {
                    return "";
                }
            }

            public static string Middle(string str, int Left, int Right)
            {
                if (str.Length >= 0)
                {
                    return str.Substring(Left - 1, (Right - Left) + 1);
                }
                else
                {
                    return "";
                }
            }

            //素数判定
            static bool IsPrimeNumber(int number)
            {
                double i = number;
                // 平方根を求める
                double x = Math.Sqrt(i);
                // 平方根以下の値で割り切れるのか確認する
                // 最小値は2
                for (double j = 2; j <= x; j++)
                {
                    if ((number % j) == 0) { return false; }
                }
                if (number == 1) { return false; }
                return true;
            }

            public static long CalcGCD(long a, long b)
            {
                if (b == 0) { return a; }
                return CalcGCD(b, a % b);
            }
            //最小公倍数
            public static long CalcLCM(long a, long b)
            {
                return a * b / CalcGCD(a, b);
            }
        }
    }
}