You’ve decided to create the game Zuma. You’re now working on the part that removes segments of balls having the same color when the segments hit each other. So, having a list of balls with different colors, the player shoots with a ball of some color to a specific position in that line. If there are more than 2 balls with the same color at that segment (including the ball shot by the player), that segment of balls disappears, and the balls surrounding it fill the gap.
If 3 or more balls colliding have the same color, that segment of balls with the same color disappears as well. This process continues until the colliding segments have different colors or there are no balls left.
The first line of the input contains a single string b (1 ≤ |b| ≤ ) representing the balls in the line. The colors of the balls are represented as lowercase Latin letters (y for yellow, b for blue, r for red, etc).
The next line contains the index at which the user shoots a ball i (1 ≤ i ≤ |b|) and the color of the ball c (lowercase Latin letter).
The programs should print the resulting sequence of balls.
rrryyrrb → rrryyyrrb → rrrrrb → b
rgbbrg → rgbbrg → rgrg
ggrrrbbb → gggrrrbbb → rrrbbb (no collision between segments after this)
gbyw → ygbyw (the colors do not match ⇒ insert the ball at the index at which it was shot)