#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 105;
const int maxlen = 20010;
const int block = 200;
long long a1[maxn][maxlen];
char a1p[maxn][maxlen];
char a2[maxn * 2][maxlen] = {};
char tch[maxlen] = {};
int fcnst[40100];
long long tt[maxlen], tmdl;
int n, m;
int x[maxlen], y[maxlen], p;
inline long long f(int a, int b) { return fcnst[x[a] + y[b]]; }
inline void getnextpr(long long *pr, int ind, char *wh) {
  for (int i = 0; i < n; ++i) {
    long long cf = f(i, ind);
    pr[i] = pr[i];
    wh[i] = 2;
    if (i && pr[i - 1] > pr[i]) pr[i] = pr[i - 1], wh[i] = 1;
    pr[i] += cf;
  }
}
inline void copycol(long long *src, long long *dst) {
  for (int i = 0; i < n; ++i) dst[i] = src[i];
}
inline void copycol(char *src, char *dst) {
  for (int i = 0; i < n; ++i) dst[i] = src[i];
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < n; ++i) cin >> x[i];
  for (int j = 0; j < m; ++j) cin >> y[j];
  for (int i = 0; i < 40100; ++i) fcnst[i] = i % p;
  tt[0] = f(0, 0);
  a1p[0][0] = 2;
  for (int i = 1; i < n; ++i) tt[i] = tt[i - 1] + f(i, 0), a1p[0][i] = 1;
  int cnt = 0;
  copycol(tt, a1[cnt++]);
  for (int j = 1; j < m; ++j) {
    getnextpr(tt, j, tch);
    if (j % block == 0) {
      copycol(tt, a1[cnt]);
      copycol(tch, a1p[cnt]);
      cnt++;
    }
  }
  cout << tt[n - 1] << endl;
  int maxend = n - 1;
  string res = "";
  for (int i = cnt - 1; i >= 0; --i) {
    int len = block;
    if (i == cnt - 1) len = m % block;
    if (len == 0) len = block;
    copycol(a1p[i], a2[0]);
    int bbeg = i * block;
    for (int j = 1; j < len; ++j) {
      getnextpr(a1[i], bbeg + j, a2[j]);
    }
    int ci = maxend;
    int cj = len - 1;
    string cres = "";
    while (cj >= 0) {
      if (a2[cj][ci] == 1) {
        cres += 'C';
        ci--;
      } else {
        cres += 'S';
        cj--;
      }
    }
    maxend = ci;
    res += cres;
  }
  reverse(res.begin(), res.end());
  cout << res.substr(1) << endl;
  return 0;
}
