#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int N=20005;
const int INF=-1;
int n,m,p;
int a[N];
int b[N];
int F[2][N];
int Ra[N];
int Rb[N];
string Path;
inline
void checkmax(int &t,const int x){
if (x>t) t=x;
}
inline int w(int i,int j){
int ret=a[i]+b[j];
if (ret>=p) ret-=p;
return ret;
}
long long Gao(int sx,int sy,int ex,int ey){
if (sx==ex && sy==ey) return w(sx,sy);
int step=ex-sx + ey-sy;
if (step==1){
if (sx<ex) Path+='C';
else Path+='S';
return w(sx,sy)+w(ex,ey);
}
int s1=step/2;
int s2=step-s1;
for (int j=0;j+sy<=ey;j++) F[0][j]=F[1][j]=INF;
for (int j=sy;j<=ey;j++) Ra[j]=Rb[j]=INF;
F[0][0]=w(sx,sy);
for (int i=1;i<=s1;i++){
int p=i&1;
for (int j=max(0,i+sx-ex);j<=i && j<=ey-sy;j++){
F[p][j]=INF;
int nx=i-j+sx;
int ny=sy+j;
if (F[p^1][j]!=INF)
checkmax(F[p][j],F[p^1][j]+w(nx,ny));
if (j && F[p^1][j-1]!=INF)
checkmax(F[p][j],F[p^1][j-1]+w(nx,ny));
if (i==s1) Ra[ny]=F[p][j];
}
}
for (int j=0;j+sy<=ey;j++) F[0][j]=F[1][j]=INF;
F[0][0]=w(ex,ey);
for (int i=1;i<=s2;i++){
int p=i&1;
for (int j=max(0,sx+i-ex);j<=i && j<=ey-sy;j++){
F[p][j]=INF;
int nx=ex-(i-j);
int ny=ey-j;
if (F[p^1][j]!=INF)
checkmax(F[p][j],F[p^1][j]+w(nx,ny));
if (j && F[p^1][j-1]!=INF)
checkmax(F[p][j],F[p^1][j-1]+w(nx,ny));
if (i==s2) Rb[ny]=F[p][j]-w(nx,ny);
}
}
int bx=-1;
int by=-1;
int ret=-1;
for (int j=sy;j<=ey;j++){
if (Ra[j]!=INF && Rb[j]!=INF && Ra[j]+Rb[j]>ret){
bx=sx+s1-(j-sy);
by=j;
ret=Ra[j]+Rb[j];
}
}
Gao(sx,sy,bx,by);
Gao(bx,by,ex,ey);
return ret;
}
int main(){
scanf("%d%d%d",&n,&m,&p);
for (int i=0;i<n;i++) { scanf("%d",&a[i]); a[i]%=p; }
for (int i=0;i<m;i++) { scanf("%d",&b[i]); b[i]%=p; }
cout << Gao(0,0,n-1,m-1) << endl;
cout << Path << endl;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHF1ZXVlPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE49MjAwMDU7CmNvbnN0IGludCBJTkY9LTE7CmludCBuLG0scDsKaW50IGFbTl07CmludCBiW05dOwppbnQgRlsyXVtOXTsKaW50IFJhW05dOwppbnQgUmJbTl07CnN0cmluZyBQYXRoOwoKaW5saW5lCnZvaWQgY2hlY2ttYXgoaW50ICZ0LGNvbnN0IGludCB4KXsKICAgIGlmICh4PnQpIHQ9eDsKfQoKaW5saW5lIGludCB3KGludCBpLGludCBqKXsKICAgIGludCByZXQ9YVtpXStiW2pdOwogICAgaWYgKHJldD49cCkgcmV0LT1wOwogICAgcmV0dXJuIHJldDsKfQoKbG9uZyBsb25nIEdhbyhpbnQgc3gsaW50IHN5LGludCBleCxpbnQgZXkpewogICAgaWYgKHN4PT1leCAmJiBzeT09ZXkpIHJldHVybiB3KHN4LHN5KTsKICAgIGludCBzdGVwPWV4LXN4ICsgZXktc3k7CiAgICBpZiAoc3RlcD09MSl7CiAgICAgICBpZiAoc3g8ZXgpIFBhdGgrPSdDJzsKICAgICAgICAgICAgIGVsc2UgUGF0aCs9J1MnOwogICAgICAgcmV0dXJuIHcoc3gsc3kpK3coZXgsZXkpOwogICAgfQogICAgaW50IHMxPXN0ZXAvMjsKICAgIGludCBzMj1zdGVwLXMxOwogICAgZm9yIChpbnQgaj0wO2orc3k8PWV5O2orKykgRlswXVtqXT1GWzFdW2pdPUlORjsKICAgIGZvciAoaW50IGo9c3k7ajw9ZXk7aisrKSBSYVtqXT1SYltqXT1JTkY7CiAgICBGWzBdWzBdPXcoc3gsc3kpOwogICAgZm9yIChpbnQgaT0xO2k8PXMxO2krKyl7CiAgICAgICAgaW50IHA9aSYxOwogICAgICAgIGZvciAoaW50IGo9bWF4KDAsaStzeC1leCk7ajw9aSAmJiBqPD1leS1zeTtqKyspewogICAgICAgICAgICBGW3BdW2pdPUlORjsKICAgICAgICAgICAgaW50IG54PWktaitzeDsKICAgICAgICAgICAgaW50IG55PXN5K2o7CiAgICAgICAgICAgIGlmIChGW3BeMV1bal0hPUlORikKICAgICAgICAgICAgY2hlY2ttYXgoRltwXVtqXSxGW3BeMV1bal0rdyhueCxueSkpOwogICAgICAgICAgICBpZiAoaiAmJiBGW3BeMV1bai0xXSE9SU5GKQogICAgICAgICAgICBjaGVja21heChGW3BdW2pdLEZbcF4xXVtqLTFdK3cobngsbnkpKTsKICAgICAgICAgICAgaWYgKGk9PXMxKSBSYVtueV09RltwXVtqXTsKICAgICAgICB9CiAgICB9CgogICAgZm9yIChpbnQgaj0wO2orc3k8PWV5O2orKykgRlswXVtqXT1GWzFdW2pdPUlORjsKICAgIEZbMF1bMF09dyhleCxleSk7CiAgICBmb3IgKGludCBpPTE7aTw9czI7aSsrKXsKICAgICAgICBpbnQgcD1pJjE7CiAgICAgICAgZm9yIChpbnQgaj1tYXgoMCxzeCtpLWV4KTtqPD1pICYmIGo8PWV5LXN5O2orKyl7CiAgICAgICAgICAgIEZbcF1bal09SU5GOwogICAgICAgICAgICBpbnQgbng9ZXgtKGktaik7CiAgICAgICAgICAgIGludCBueT1leS1qOwogICAgICAgICAgICBpZiAoRltwXjFdW2pdIT1JTkYpCiAgICAgICAgICAgIGNoZWNrbWF4KEZbcF1bal0sRltwXjFdW2pdK3cobngsbnkpKTsKICAgICAgICAgICAgaWYgKGogJiYgRltwXjFdW2otMV0hPUlORikKICAgICAgICAgICAgY2hlY2ttYXgoRltwXVtqXSxGW3BeMV1bai0xXSt3KG54LG55KSk7CiAgICAgICAgICAgIGlmIChpPT1zMikgUmJbbnldPUZbcF1bal0tdyhueCxueSk7CiAgICAgICAgfQogICAgfQogICAgaW50IGJ4PS0xOwogICAgaW50IGJ5PS0xOwogICAgaW50IHJldD0tMTsKICAgIGZvciAoaW50IGo9c3k7ajw9ZXk7aisrKXsKICAgICAgICBpZiAoUmFbal0hPUlORiAmJiBSYltqXSE9SU5GICYmIFJhW2pdK1JiW2pdPnJldCl7CiAgICAgICAgICBieD1zeCtzMS0oai1zeSk7CiAgICAgICAgICBieT1qOwogICAgICAgICAgcmV0PVJhW2pdK1JiW2pdOwogICAgICAgIH0KICAgIH0KICAgIEdhbyhzeCxzeSxieCxieSk7CiAgICBHYW8oYngsYnksZXgsZXkpOwogICAgcmV0dXJuIHJldDsKfQoKaW50IG1haW4oKXsKICAgIHNjYW5mKCIlZCVkJWQiLCZuLCZtLCZwKTsKICAgIGZvciAoaW50IGk9MDtpPG47aSsrKSB7IHNjYW5mKCIlZCIsJmFbaV0pOyBhW2ldJT1wOyB9CiAgICBmb3IgKGludCBpPTA7aTxtO2krKykgeyBzY2FuZigiJWQiLCZiW2ldKTsgYltpXSU9cDsgfQogICAgY291dCA8PCBHYW8oMCwwLG4tMSxtLTEpIDw8IGVuZGw7CiAgICBjb3V0IDw8IFBhdGggPDwgZW5kbDsKfQo=