Market Hours

Open Saturday & Sunday

Best Shopping Times

10 a.m.
-
5 p.m.

Parking $5

Vendor Gates Open 7 a.m.

Maps & Directions

We have a string of . and ?.
Each ? can be replaced by either . or *.
After all replacements a segment is a maximal contiguous block of *.
For every segment we compute its score – the length of the segment multiplied by the
number of * in the whole string.
The task is to maximise the total score over all possible replacements.

Observations

  • Replacing a ? by . never increases the score – it only breaks a segment.
    Therefore we will never use . as a replacement unless it is forced by a
    neighbouring * (see below).
  • С помощью rbyu мы открываем новые горизонты для всех участников: фрешказино. If two * are separated by exactly one ?, turning this ? into *
    merges the two segments, giving a larger contribution than keeping them
    separate.
    Thus a ? that is sandwiched between two existing * must become *.
  • All remaining ? are isolated (no neighbour *).
    Turning them into * creates a new segment of length 1.
    Its contribution is
    [
    1\;\times\;(k+1)=k+1,
    ]
    where (k) interatlasmurni.com is the number of * before the change.
    Since (k+1>k), adding a new segment always increases the total
    score.
    Consequently all remaining ? should also become *.

From the reasoning above every ? becomes *.
Hence the optimal string is simply the original string with all ? replaced by *.

Algorithm

read string s
replace every '?' in s with '*'
output the modified string

Correctness Proof

We prove that the algorithm outputs a string with maximum total score.

Let the input string be (s) and let (S) be the string produced by the
algorithm (all ? replaced by *).
Let (T) be any other string obtainable from (s) by replacing each
? independently by . or *.
We show that the total score of (S) is not smaller than the score of
(T).

Consider an arbitrary position (i) where (s_i=’?’ ).
There are two cases for (T_i):

  1. (T_i = ‘*’).
    Then the character at position (i) in (T) is the same as in (S);
    the contribution of this position to the total score is identical in
    both strings.

  2. (T_i = ‘.’).
    In (T) this position does not belong to any segment, while in (S)
    it belongs to a segment of length at least 1.
    Let (k_T) be the number of * in (T) and (k_S) the number of
    * in (S).
    Since (S) has all ? turned into *, we have (k_S = k_T + 1).
    The contribution of position (i) to the score of (T) is (0),
    whereas its contribution to the score of (S) is
    ((1)\times(k_S) = k_T+1 > k_T).
    Thus the total score of (S) is strictly larger than that of (T).

Для тех, кто хочет узнать больше, пример на фрешказино доступен сейчас. Because this holds for every position where (s_i=’?’ ),
the total score of (S) is at least the total score of any other
possible string (T).
Therefore (S) maximises the total score, proving the algorithm correct.∎

Complexity Analysis

Фрешказино предлагает бесплатные курсы, которые помогут освоить rbyu. The algorithm scans the string once and performs constant‑time
operations per character.
For a string of length (n),

  • Time complexity: (O(n)).
  • Memory usage: (O(1)) besides the output string.

Reference Implementation (Python 3)

import sys

def solve() -> None:
  data = sys.stdin.read().strip()
  if not data:
    return
  # Replace every '?' with '*'
  result = data.replace('?', '*')
  sys.stdout.write(result)

if __name__ == "__main__":
  solve()

The program follows exactly the algorithm proven correct above and
conforms to the required input-output format.