Codeforces Beta Round 79 (Div. 1 Only)
E
Candies and Stones
Codeforces
2500
原题
← D→
翻译中…

Little Gerald and his coach Mike play an interesting game. At the beginning of the game there is a pile consisting of $*n*$ candies and a pile consisting of $*m*$ stones. Gerald and Mike move in turns, Mike goes first. During his move Mike checks how many candies and stones Gerald has eaten. Let Gerald eat $*a*$ candies and $*b*$ stones. Then Mike awards Gerald $*f*(*a*, *b*)$ prize points. Gerald during his move either eats a candy from the pile of candies or a stone from the pile of stones. As Mike sees that Gerald has eaten everything apart one candy and one stone, he awards points for the last time and the game ends. Gerald is not allowed to eat all the candies, and he is not allowed to eat all the stones too. Tell Gerald how to play to get the largest possible number of points: it is required to find one of the possible optimal playing strategies for Gerald.

翻译中…

Input

翻译中…

The first line contains three integers $*n*, *m*, *p*$ ($1 ≤ *n*, *m* ≤ 20000$, $1 ≤ *p* ≤ 10^{9}$). The second line contains $*n*$ integers $*x*_{0}$, $*x*_{1}$, ..., $*x*_{*n* - 1}$ ($0 ≤ *x*_{*i*} ≤ 20000$). The third line contains $*m*$ integers $*y*_{0}$, $*y*_{1}$, ..., $*y*_{*m* - 1}$ ($0 ≤ *y*_{*i*} ≤ 20000$). The value of $*f*(*a*, *b*)$ is calculated as a remainder of the division of the sum $*x*_{*a*} + *y*_{*b*}$ by number $*p*$.

翻译中…

Output

翻译中…

Print on the first line the only number: the maximal number of points Gerald can earn. Print on the second line a sting consisting of $*n* + *m* - 2$ characters, each of which is either a "C" or "S", the $*i*$-th character should be "C" if Gerald's $*i*$-th move should be eating a candy and "S" if he should eat a stone.

翻译中…

Note

翻译中…

In the first test if Gerald's first move is eating a stone, he will receive a point for it and if he eats a candy, he will get zero pints. In any way Gerald will get $0$ points before his first move, and $1$ after his second one. This, the maximum number of points Gerald can get equals to $2$, and for that he should first eat a stone, then a candy.

翻译中…

样例

Input #1
2 2 10
0 0
0 1
Output #1
2
SC
InputCopy OutputCopy
Input #2
3 3 10
0 2 0
0 0 2
Output #2
10
CSSC
InputCopy OutputCopy
Input #3
3 3 2
0 1 1
1 1 0
Output #3
4
SCSC
InputCopy OutputCopy
题目信息
题号
101E
时间限制
7.5 s
内存限制
45 MB
标签
分治
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。