#K9236. Traffic Signals Simulation

    ID: 38180 Type: Default 1000ms 256MiB

Traffic Signals Simulation

Traffic Signals Simulation

You are given an initial state of traffic signals arranged in a 4x4 grid. Each cell in the grid is represented by either a 'G' (indicating "Go") or an 'S' (indicating "Stop"). Every minute, each cell toggles its state: a 'G' becomes an 'S' and an 'S' becomes a 'G'. Given the number of minutes N, determine the grid's state after N minutes.

The toggling operation is applied simultaneously to every cell. If N is even, the grid remains unchanged; if it is odd, every cell in the grid will flip its state.

Note: All mathematical expressions should be rendered in LaTeX format, for example: if \( N \) is odd, then each cell \( c \) in the grid is updated based on \( c' = \begin{cases} S & \text{if } c = G \\ G & \text{if } c = S \end{cases} \).

inputFormat

The input consists of 5 lines:

  • The first 4 lines each contain a string of 4 characters ('G' or 'S'), representing the rows of the grid.
  • The 5th line contains a single integer \( N \), denoting the number of minutes.

outputFormat

Output the state of the 4x4 grid after \( N \) minutes. Each row of the grid should be printed on a separate line.

## sample
GGSG
SSGS
GSGS
SGSG
1
SSGS

GGSG SGSG GSGS

</p>