#include <bits/stdc++.h>
int n, m;
int MOD;
int x[20010], y[20010];
inline int w(int i, int j) { return (x[i] + y[j]) % MOD; }
char s[50010], *pc = s;
int f[20010], g[20010];
inline void maxto(int &a, int b) {
  if (a < b) a = b;
}
int work(int x, int y, int n, int m) {
  int ret = 0;
  if (x == n) {
    for (int i = y + 1; i <= m; i++) *(pc++) = 'S', ret += w(x, i);
    return ret + w(x, y);
  }
  int t = (x + n) / 2;
  for (int i = y; i <= m; i++) f[i] = g[i] = 0;
  for (int i = x; i <= t; i++) {
    f[y] += w(i, y);
    for (int j = y + 1; j <= m; j++) maxto(f[j], f[j - 1]), f[j] += w(i, j);
  }
  for (int i = n; i > t; i--) {
    g[m] += w(i, m);
    for (int j = m - 1; j >= y; j--) maxto(g[j], g[j + 1]), g[j] += w(i, j);
  }
  int p = -1;
  for (int i = y; i <= m; i++)
    if (f[i] + g[i] >= ret) ret = f[i] + g[i], p = i;
  work(x, y, t, p);
  *(pc++) = 'C';
  work(t + 1, p, n, m);
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &m, &MOD);
  for (int i = 0; i < n; i++) scanf("%d", x + i);
  for (int i = 0; i < m; i++) scanf("%d", y + i);
  printf("%d\n", work(0, 0, n - 1, m - 1));
  puts(s);
  return 0;
}
