We need to parse a string s of length n (1 <= n <= 100). We need to identify all filler words as per definition: filler is "ogo" and can be followed by any number of "go" repeats. So the pattern is: "ogo" + ("go")* zero or more times. So regex: ogo(go). But the problem says filler words have maximal size: meaning we should match the longest possible filler. So we need to greedily match "ogo" then as many "go" as possible, but it must be maximal: i.e., if we have substring that could be interpreted as a filler, but there's a longer filler covering it, we take longer. Actually example: "ogogoo" they say: cannot consider ogo a filler and goo as normal phrase. Should consider ogogo as filler. So indeed we need to find substrings that are exactly the pattern and are maximal: i.e., we scan and when we encounter 'o' followed by 'g' followed by 'o', we then try to extend with repeating "go" pairs until no longer possible. Then we replace that entire chunk with "**". Then continue scanning after the replaced chunk.
But careful: The filler is maximal: meaning that if we have a pattern that matches, and after that there might be overlapping possible? But since we replace and then continue, it's fine: we just greedily find longest sequence matching ogo(go). The pattern: start with "ogo". Then check next two characters: if they are "go", then they belong to filler; then continue checking next two, and so on. So essentially, we need to scan the string and when we find an 'o', check if next two are "go"? Actually starting at position i, we need to see if s[i] = 'o', s[i+1] = 'g', s[i+2] = 'o'. If yes, then we have at least length 3 filler. Then we can extend: j = i+3; while j+1 < n and s[j] == 'g' and s[j+1] == 'o', then j += 2; So the filler spans from i to j-1 inclusive (or j after loop). Then we replace that substring with "**". Then set i = j (continue after filler). If at position i we don't have "ogo", then we output the character as is and increment i.
But careful about overlapping: Consider "ogogo": start i=0, we see "ogo" (positions 0-2), then extend: j=3, check s[3]='g', s[4]='o' -> yes, so j=5. filler covers 0-4. That's fine. Then i=5, end.
What about "ogogogo"? i=0, pattern "ogo", extend twice -> filler 0-6. Good.
What about "ogoogo"? i=0: see "ogo", then next two are "og"? Actually s[3]='o', s[4]='g', s[5]='o'? Let's say s = "ogoogo": positions 0 o,1 g,2 o,3 o,4 g,5 o. At i=0: check s[0]='o', s[1]='g', s[2]='o' -> yes. Then j=3; while j+1 < n and s[j]=='g' and s[j+1]=='o': s[3] is 'o', not 'g' -> stop. So filler covers 0-2. Replace with "". Then i=3. Then at i=3: s[3]='o', check s[4]='g', s[5]='o' -> yes, so filler covers 3-5. So we get "***". So that matches sample 3: "ogoogoogo" -> becomes 9 asterisks. So yes.
Thus algorithm: Iterate i from 0 to n-1. If i <= n-3 and s[i]=='o' and s[i+1]=='g' and s[i+2]=='o', then find end = i+3; while end+1 < n and s[end]=='g' and s[end+1]=='o', end += 2; Then output "***" and set i = end; else output s[i] and i+=1.
We need to handle boundaries: n up to 100 so simple.
Implementation: read n, then s. Use while loop.
Edge cases: if n<3, no filler possible; output s as is.
Test with examples:
Ex1: n=7, s="aogogob". i=0: 'a' no, output 'a', i=1. i=1: check "ogo"? s[1]='o', s[2]='g', s[3]='o'? s[3] = 'o'? Actually "a o g o g o b": indices:0 a,1 o,2 g,3 o,4 g,5 o,6 b. At i=1: s[1]='o', s[2]='g', s[3]='o' -> yes (positions 1,2,3 = o g o). Then extend: end=4; while: s[4]='g', s[5]='o' -> yes, end=6; now end+1=7 not < n, so stop. filler covers 1..5 ( indices 1-5). Then output "", i=6. Then i=6: output s[6]='b'. So output "ab". Good.
Ex2: "ogogmgogogogo": n=13? Actually string: o g o g m g o g o g o g o? Let's write: indices:0 o,1 g,2 o,3 g,4 m,5 g,6 o,7 g,8 o,9 g,10 o,11 g,12 o. At i=0: check "ogo": s[0]=o,1=g,2=o -> yes. extend: end=3; while: s[3]=g, s[4]=m? No, because s[4] is m not o. So stop. filler indices 0-2. output "", i=3. i=3: s[3]='g'? Check filler? Need "ogo", but s[3] is g, not o, so output 'g', i=4. i=4: s[4]='m' output, i=5. i=5: s[5]='g' output, i=6. i=6: s[6]='o' check i=6: s[6]=o, s[7]=g, s[8]=o -> yes. Then extend: end=9; while: s[9]=g, s[10]=o -> yes, end=11; while again: s[11]=g, s[12]=o -> yes, end=13; now end=13 out of range. filler indices 6-12. output "", i=13 done. So output "gmg". Good.
Ex3: "ogoogoogo": n=9. i=0: "ogo" yes, extend: next s[3]='o', not g, stop. filler 0-2, output "", i=3. i=3: "ogo" yes (3-5), extend: s[6]='o'? Actually s[6]='o'? string: indices:0 o,1 g,2 o,3 o,4 g,5 o,6 o,7 g,8 o. i=3: s[3]=o, s[4]=g, s[5]=o -> yes, extend: end=6; while: s[6]=o? not g, stop. filler 3-5, output "", i=6. i=6: s[6]=o, s[7]=g, s[8]=o -> yes, filler 6-8, output "". final "******". Good.
All good.
Now ensure we handle when we might have a filler that ends exactly at the end of string.
Implementation details: read n (though we could ignore n and compute length). But we'll read both.
We'll construct result string by iterating.
Pseudo:
def solve():
import sys
data = sys.stdin.read().split()
n = int(data[0])
s = data[1].strip()
i = 0
res = []
while i < n:
if i + 2 < n and s[i] == 'o' and s[i+1] == 'g' and s[i+2] == 'o':
j = i + 3
while j + 1 < n and s[j] == 'g' and s[j+1] == 'o':
j += 2
res.append('***')
i = j
else:
res.append(s[i])
i += 1
print(''.join(res))
That's it.
Check for possible pitfalls: if after extension, j might be exactly n or beyond; we set i=j. If j==n, loop ends.
Complexity O(n) which is fine.
Now we need to output final answer as python code. Ensure reading from input.
Thus final answer: Provide code in python.
But the instruction: "You are an AI. Provide the final answer." So we need to output the solution.
Thus produce final python code.
Additionally, we might need to handle the case if n is not needed: but we can still use it.
We'll output as a typical solution.
Edge test: n=1, s='a' -> output 'a'.
n=2, s='og' -> output 'og'.
n=3, s='ogo' -> output '***'.
n=3, s='ogg' -> output 'ogg'.
n=4, s='ogoo' -> check: i=0: s[0]='o', s[1]='g', s[2]='o' -> yes. extend: j=3; while j+1<4? j=3, j+1=4 not <4, so stop. filler 0-2, output "", i=3; then i=3 output s[3]='o'? Actually we need to output remaining: but i=3, j=3, after adding '', i becomes 3, but 3 is less than 4? Actually after processing filler covering indices 0,1,2, i is set to j=3. Then loop continues: i=3, we check for filler? i+2 =5 not < n, so else branch: output s[3] ('o'), i=4. So final "o". But is that correct? Let's think: string "ogoo": does it contain filler? Starting at 0, "ogo" is a filler. Then after that we have 'o'. But could 'ogoo' be considered filler? The pattern is ogo(go), so only even length after initial 3? Actually pattern: ogo + (go). So after "ogo", the next two must be "go" to extend. Here after "ogo", we have 'o' alone. So filler is "ogo". So we replace "ogo" with "", leaving "o". So output "***o". That seems correct. But could "ogo" be considered part of larger? No, because need "go" pairs. So correct.
But wait: What if we have "ogog"? n=4: s= o g o g. i=0: see o g o -> yes, extend: j=3; while j+1<4? j=3, j+1=4 not <4, so stop. filler indices 0-2, i=3, output 'g'? Actually s[3]='g' output. So "***g". That's correct. But could there be an overlapping filler starting at i=1? At i=1: s[1]='g', not 'o', so no. So fine.
What about "ogogox"? We'll test.
Now we can produce final answer.
Given the problem statement and constraints, this solution is correct.
Thus we provide final answer as python code with solve() function and if name == "main": solve().
But in the answer we can just output the code.
Thus final.
```python
import sys
def solve() -> None:
data = sys.stdin.read().split()
if not data:
return
n = int(data[0])
s = data[1].strip()
i = 0
res = []
while i < n:
# check for the beginning of a filler: "ogo"
if i + 2 < n and s[i] == 'o' and s[i + 1] == 'g' and s[i + 2] == 'o':
j = i + 3
# extend while "go" pairs follow
while j + 1 < n and s[j] == 'g' and s[j + 1] == 'o':
j += 2
res.append('***')
i = j
else:
res.append(s[i])
i += 1
print(''.join(res))
if name == "main":
solve()