Every year, the continent of Cacophonea holds the Cacophonean Song Contest. Each of its nations presents an act performed by a national singer or group. Every inhabitant may televote for any act that is not from their own nation, so a nation never votes for its own act.
In the end, each of the $s$ participating nations awards points to $r$ acts. From a given nation, the act with the most votes receives $r$ points, the act with the second-most votes receives $r-1$ points, and so on, so that the act with the $r$-th most votes receives $1$ point; less popular acts receive no points from that nation. The final ranking of the contest is decided by the total number of points each nation receives.
Music producer Dustin has followed the contest for years and has noticed that some nations televote for political rather than artistic reasons:
Dustin knows a trick no other producer knows: an artist can win the favour of a politically voting nation by giving it special attention during the act (for example, singing parts in its local dialect or waving its flag). The more attention a politically voting nation receives, the higher it ranks the performer — but this comes at the expense of the original act and makes quality-motivated nations rank it lower.
Concretely, Dustin can split an act into exactly $s - 1$ parts. Initially every part is dedicated to the performer's own nation (reflecting the original artistic idea), but this can be changed:
Only the number of parts dedicated to a nation affects the voting; the order of the parts within the act does not matter.
Dustin wants to design an act that earns as many points as possible in the overall result. Determine the largest overall point total he can obtain when he uses these act-changing tactics optimally.
q if quality-motivated, p if politically motivated.For each test case, print a single line containing one integer: the maximum overall score the act can achieve when the act-changing tactics are used optimally.