Company: Texas
Difficulty: medium
Maximum Mangoes in Mirrored Gardens You are given an `N x N` garden `A`. Each cell is `*` (empty and passable), `$` (a passable cell containing one mango), or `X` (blocked). Garden `B` is a separate horizontal mirror image of `A`; its bottom-left cell is connected to the bottom-right cell of `A`. Start at the top-right of `B`, travel to its bottom-left using only left and down moves, cross to `A`, travel to the top-left using only left and up moves, return to the bottom-right of `A` using only right and down moves, cross back to `B`, and return to its top-right using only right and up moves. Collect a mango the first time a cell is visited. Print the maximum number of mangoes that can be collected. If any required route is impossible, print `0`. Input The first line contains `N`. The next `N` lines each contain a string of length `N`. Output Print the maximum number of mangoes. Constraints `1 <= N <= 100`. Notes The two gardens are distinct: a mango collected in one garden does n