#include <bits/stdc++.h>
int f[20002], g[20002];
int x[20002];
int y[20002];
char path[20002 + 20002];
int p, count;
int dp(int x0, int x1, int y0, int y1) {
  extern int count;
  int i, j;
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  int mid = (x0 + x1) / 2;
  if (x0 == x1) {
    f[y0] = (x[x0] + y[y0]) % p;
    for (j = y0 + 1; j <= y1; j++) {
      f[j] = f[j - 1] + (x[x0] + y[j]) % p;
      path[count++] = 'S';
    }
    return f[y1];
  } else {
    for (i = x0; i <= mid; i++) {
      for (j = y0; j <= y1; j++) {
        if (f[j] < f[j - 1])
          f[j] = f[j - 1] + (x[i] + y[j]) % p;
        else
          f[j] = f[j] + (x[i] + y[j]) % p;
      }
    }
    for (i = x1; i > mid; i--) {
      for (j = y1; j >= y0; j--) {
        if (g[j] < g[j + 1])
          g[j] = g[j + 1] + (x[i] + y[j]) % p;
        else
          g[j] = g[j] + (x[i] + y[j]) % p;
      }
    }
    int max = -1, pos;
    for (i = y0; i <= y1; i++) {
      if (f[i] + g[i] > max) {
        max = f[i] + g[i];
        pos = i;
      }
    }
    dp(x0, mid, y0, pos);
    path[count++] = 'C';
    dp(mid + 1, x1, pos, y1);
    return max;
  }
}
int main() {
  int n, m, i, result;
  extern int p;
  scanf("%d%d%d", &n, &m, &p);
  for (i = 1; i <= n; i++) scanf("%d", &x[i]);
  for (i = 1; i <= m; i++) scanf("%d", &y[i]);
  result = dp(1, n, 1, m);
  printf("%d\n", result);
  printf("%s\n", path);
  return 0;
}
