The Windblume Festival in Mondstadt is coming! People are preparing windblumes for Barbatos and for
those they love and adore. The Windblume Festival is also an opportunity to improve the relationships
people have.
During the festival, a famous game will be played every year, invented by Jean, the Acting Grand Master
of the Knights of Favonius. In the game, n players numbered from 1 to n stand in a circle, each holding
an integer with them. Each turn, one player will be removed. The game will end when there is only one
player left.
For each turn, let k be the number of players remaining and ai be the integer player i holds. Two adjacent
players, x and (x mod k + 1) are selected and player (x mod k + 1) is removed from the game. Player x’s
integer will then change from ax to (ax − ax mod k+1). Player y in this turn will become player (y − 1) in
the next turn for all x < y ≤ k, though the integer they hold will not change.
Jean wants to know the maximum possible integer held by the last remaining player in the game by
selecting the players in each round optimally