#include <bits/stdc++.h>
using namespace std;
const int maxn = 30000;
long long f[maxn];
long long g[maxn];
int N, M, X[maxn], Y[maxn], P;
int Nextint() {
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  int x = 0;
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
void Sol(int x1, int y1, int x2, int y2) {
  if (x1 == x2) {
    if (x2 - x1 + y2 - y1 == N + M - 2) {
      long long mx = 0;
      for (int i = y1; i <= y2; i++) mx += (X[x1] + Y[i]) % P;
      cout << mx << endl;
    }
    for (int i = y1; i < y2; i++) printf("S");
    return;
  }
  int mid = (x1 + x2) / 2;
  for (int i = y1; i <= y2; i++) f[i] = g[i] = 0;
  for (int i = x1; i <= mid; i++) {
    f[y1] += (X[i] + Y[y1]) % P;
    for (int j = y1 + 1; j <= y2; j++) {
      if (f[j] < f[j - 1]) f[j] = f[j - 1];
      f[j] = f[j] + (X[i] + Y[j]) % P;
    }
  }
  for (int i = x2; i > mid; i--) {
    g[y2] += (X[i] + Y[y2]) % P;
    for (int j = y2 - 1; j >= y1; j--) {
      if (g[j] < g[j + 1]) g[j] = g[j + 1];
      g[j] += (X[i] + Y[j]) % P;
    }
  }
  long long mx = -1;
  for (int i = y1; i <= y2; i++)
    if (f[i] + g[i] > mx) mx = f[i] + g[i];
  if (x2 - x1 + y2 - y1 == N + M - 2) cout << mx << endl;
  for (int i = y1; i <= y2; i++)
    if (f[i] + g[i] == mx) {
      Sol(x1, y1, mid, i);
      printf("C");
      Sol(mid + 1, i, x2, y2);
      return;
    }
}
int main() {
  scanf("%d%d%d", &N, &M, &P);
  for (int i = 0; i < N; i++) X[i] = Nextint();
  for (int i = 0; i < M; i++) Y[i] = Nextint();
  Sol(0, 0, N - 1, M - 1);
  return 0;
}
