#include <bits/stdc++.h>
using namespace std;
int x[20005], y[20005], f[20005], g[20005], p, n, m, str1 = 0;
char str[20005 << 1];
inline int v(int i, int j) { return (x[i] + y[j]) % p; }
int work(int l, int r, int d, int u) {
  int ans = 0, mid = (l + r) >> 1, mid1;
  if (l == r) {
    for (int i = d; i < u; ++i) str[++str1] = 'S', ans += v(l, i);
    ans += v(l, u);
    return ans;
  }
  for (int i = d; i <= u; ++i) f[i] = 0;
  for (int i = d; i <= u; ++i) g[i] = 0;
  for (int i = l; i <= mid; ++i) {
    f[d] += v(i, d);
    for (int j = d + 1; j <= u; ++j) f[j] = max(f[j], f[j - 1]) + v(i, j);
  }
  for (int i = r; i > mid; --i) {
    g[u] += v(i, u);
    for (int j = u - 1; j >= d; --j) g[j] = max(g[j], g[j + 1]) + v(i, j);
  }
  for (int i = d; i <= u; ++i)
    if (f[i] + g[i] >= ans) ans = f[i] + g[i], mid1 = i;
  work(l, mid, d, mid1);
  str[++str1] = 'C';
  work(mid + 1, r, mid1, u);
  return ans;
}
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= n; ++i) cin >> x[i];
  for (int i = 1; i <= m; ++i) cin >> y[i];
  printf("%d\n", work(1, n, 1, m));
  str[str1 + 1] = '\0';
  printf("%s\n", str + 1);
  return 0;
}
