#include <bits/stdc++.h>
using namespace std;
const int maxn = 20005;
int a[maxn], b[maxn];
int f[maxn], f0[maxn];
bitset<maxn> act[maxn / 2];
char res[maxn * 2];
int n, m, p, tot;
int main() {
  int i, j, h;
  scanf("%d%d%d", &n, &m, &p);
  h = n / 2;
  for (i = 0; i < n; ++i) scanf("%d", a + i);
  for (i = 0; i < m; ++i) scanf("%d", b + i);
  tot = n + m - 2;
  res[tot] = '\0';
  for (i = 0; i < n; ++i) {
    memcpy(f0, f, sizeof f);
    memset(f, 255, sizeof f);
    for (j = 0; j < m; ++j) {
      if (j > 0) f[j] = f[j - 1];
      if (f0[j] > f[j]) {
        f[j] = f0[j];
        if (i >= h) act[i - h].set(j);
      }
      f[j] += (a[i] + b[j]) % p;
    }
  }
  printf("%d\n", f[m - 1]);
  while (n > h && (n > 1 || m > 1))
    if (act[n - 1 - h][m - 1]) {
      res[--tot] = 'C';
      --n;
    } else {
      res[--tot] = 'S';
      --m;
    }
  memset(f, 0, sizeof f);
  for (i = 0; i < n; ++i) {
    memcpy(f0, f, sizeof f);
    memset(f, 255, sizeof f);
    act[i].reset();
    for (j = 0; j < m; ++j) {
      if (j > 0) f[j] = f[j - 1];
      if (f0[j] > f[j]) {
        f[j] = f0[j];
        act[i].set(j);
      }
      f[j] += (a[i] + b[j]) % p;
    }
  }
  while (n > 1 || m > 1)
    if (act[n - 1][m - 1]) {
      res[--tot] = 'C';
      --n;
    } else {
      res[--tot] = 'S';
      --m;
    }
  printf("%s\n", res);
  return 0;
}
