#include <bits/stdc++.h>
using namespace std;
const int maxm = 20002, maxn = 10005;
long long d[2][maxm], d1;
int p[maxn][626], x[maxm], y[maxm], n, m, P, r, i, j, u, v;
int cost(int i, int j) {
  r = x[i] + y[j];
  if (r >= P) r -= P;
  return r;
}
void solve(int f, int t) {
  memset(d, 255, sizeof(d));
  memset(p, 0, sizeof(p));
  d[0][0] = 0;
  for (i = 0; i < n; ++i) {
    u = i & 1;
    v = 1 - u;
    memset(d[v], 255, sizeof(d[v]));
    for (j = 0; j < m; ++j)
      if (d[u][j] != -1) d[v][j] = d[u][j] + cost(i, j);
    for (j = 0; j < m - 1; ++j) {
      d1 = d[v][j] + cost(i, j + 1);
      if (d[v][j + 1] < d1) {
        d[v][j + 1] = d1;
        if (i >= f && i < t) p[i - f][(j + 1) >> 5] |= (1 << ((j + 1) & 31));
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &P);
  for (int i = 0; i < n; ++i) scanf("%d", &x[i]), x[i] %= P;
  for (int i = 0; i < m; ++i) scanf("%d", &y[i]), y[i] %= P;
  solve(maxn, maxm);
  string f = "", e = "";
  int c = n - 1, s = m - 1;
  printf("%I64d\n", d[n & 1][m - 1]);
  while (c >= maxn && s >= 0)
    if ((p[c - maxn][s >> 5] & (1 << (s & 31))) == 0)
      f += 'C', --c;
    else
      --s, f += 'S';
  solve(0, maxn);
  while (c > 0 || s > 0)
    if ((p[c][s >> 5] & (1 << (s & 31))) == 0)
      e += 'C', --c;
    else
      e += 'S', --s;
  reverse(f.begin(), f.end());
  reverse(e.begin(), e.end());
  printf("%s%s", e.c_str(), f.c_str());
  return 0;
}
