#include <bits/stdc++.h>
char ans[50000];
int len, n, m, yz, x[20001], y[20001], p;
int f[150][20001], st[150][20001];
int g[150][20001];
void doit(int e, int start, int final) {
  int i = 0, j = 0, k = 0;
  for (i = 1; i <= m; i++) f[0][i] = st[e - 1][i];
  for (i = start; i <= final; i++)
    for (j = 1; j <= m; j++) {
      k = i - start + 1;
      if (j != 1)
        f[k][j] = f[k][j - 1], g[k][j] = 1;
      else
        f[k][j] = -1, g[k][j] = 0;
      if (f[k - 1][j] > f[k][j]) f[k][j] = f[k - 1][j], g[k][j] = 2;
      f[k][j] += (x[i] + y[j]) % p;
    }
}
void getans(int x, int &yz) {
  while (x > 0) {
    if (g[x][yz] == 1)
      ans[++len] = 'S', yz--;
    else
      ans[++len] = 'C', x--;
  }
}
int main() {
  int i = 0, j = 0, start = 0, final = 0, k = 0, kk = 0;
  scanf("%d%d%d\n", &n, &m, &p);
  for (i = 1; i <= n; i++) scanf("%d", &x[i]), x[i] %= p;
  for (i = 1; i <= m; i++) scanf("%d", &y[i]), y[i] %= p;
  k = (int)sqrt(n);
  kk = n / k + 1;
  for (i = 1; i <= k; i++) {
    start = (i - 1) * kk + 1;
    final = (i * kk <= n) ? i * kk : n;
    doit(i, start, final);
    for (j = 1; j <= m; j++) st[i][j] = f[final - start + 1][j];
  }
  printf("%d\n", st[k][m]);
  yz = m;
  for (i = k; i >= 1; i--) {
    start = (i - 1) * kk + 1;
    final = (i * kk <= n) ? i * kk : n;
    doit(i, start, final);
    getans(final - start + 1, yz);
  }
  for (i = len - 1; i >= 1; i--) printf("%c", ans[i]);
  return 0;
}
