#include <bits/stdc++.h>
using namespace std;
bitset<20005> a[20005 / 2];
int x[20005], y[20005], f[20005], g[20005], n, m, p, len, flag = 1;
char ans[20005 + 20005];
void work() {
  for (int i = 1; i <= n; i++) {
    memset(g, 0, sizeof(g));
    if (n - i < 20005 / 2) a[n - i].reset();
    for (int j = 1; j <= m; j++) {
      g[j] = g[j - 1];
      if (j < 2 || f[j] > g[j]) {
        g[j] = f[j];
        if (n - i < 20005 / 2) a[n - i][j] = 1;
      }
      g[j] += (x[i] + y[j]) % p;
    }
    memcpy(f, g, sizeof(f));
  }
  int i = 0;
  if (flag) printf("%d\n", f[m]), flag = 0;
  while (i < 20005 / 2 && i < n && n - i + m > 1 && m)
    if (a[i][m])
      i++, ans[--len] = 'C';
    else
      m--, ans[--len] = 'S';
  n -= i;
  memset(f, 0, sizeof(f));
}
int main() {
  scanf("%d%d%d", &n, &m, &p), len = n + m - 2;
  for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &y[i]);
  work(), work();
  puts(ans);
  return 0;
}
