#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, m, op, len = 0;
int a[N], b[N];
char s[N + N];
long long f[N], g[N], ans = 0;
void Gans(const int x1, const int x2, const int y1, const int y2) {
  if (x1 == x2) {
    long long now = (a[x1] + b[y2]) % op;
    for (int i = y1; i < y2; ++i)
      s[++len] = 'S',
      now += (a[x1] + b[i] < op ? a[x1] + b[i] : a[x1] + b[i] - op);
    ans = now;
    return;
  }
  int mid = (x1 + x2) >> 1, q = y1;
  for (int i = y1 - 1; i <= y2 + 1; ++i) f[i] = g[i] = 0;
  for (int i = x1; i <= mid; ++i)
    for (int j = y1; j <= y2; ++j) {
      if (f[j - 1] > f[j]) f[j] = f[j - 1];
      f[j] += (a[i] + b[j] < op ? a[i] + b[j] : a[i] + b[j] - op);
    }
  for (int i = x2; i > mid; --i)
    for (int j = y2; j >= y1; --j) {
      if (g[j + 1] > g[j]) g[j] = g[j + 1];
      g[j] += (a[i] + b[j] < op ? a[i] + b[j] : a[i] + b[j] - op);
    }
  long long now = f[q] + g[q];
  for (int i = y1 + 1; i <= y2; ++i)
    if (f[i] + g[i] > now) now = f[i] + g[i], q = i;
  Gans(x1, mid, y1, q);
  s[++len] = 'C';
  Gans(mid + 1, x2, q, y2);
  ans = now;
}
int main() {
  scanf("%d%d%d", &n, &m, &op);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i] %= op;
  for (int i = 1; i <= m; ++i) scanf("%d", &b[i]), b[i] %= op;
  Gans(1, n, 1, m);
  printf("%I64d\n", ans);
  puts(s + 1);
  return 0;
}
