#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int oo = ~0u >> 2, mo = (int)1e9 + 7;
const int mn = 21000, ml = 200, mm = mn / ml + 3;
const string dic = "CS";
struct Block {
  long long r[ml], d[ml];
} rec[mm][mm];
long long f[mn];
bool g[ml][ml];
int a[mn], b[mn];
int n, m, p;
string Path;
int get(int x, int y) {
  int row = x / ml, col = y / ml, sx = row * ml, sy = col * ml;
  if (x == sx) return rec[row][col].r[y - sy];
  if (y == sy) return rec[row][col].d[x - sx];
  return -oo;
}
void Gen(int n, int m) {
  do {
    int row = n / ml, col = m / ml;
    int sx = row * ml, sy = col * ml;
    for (int i = sx; i <= n; ++i)
      for (int j = sy; j <= m; ++j) {
        int l(-oo), u(-oo),
            t = (a[i] + b[j] >= p ? a[i] + b[j] - p : a[i] + b[j]);
        if (j)
          if (j == sy) {
            if (i == sx) l = get(i, j - 1);
          } else
            l = f[j - 1];
        if (i)
          if (i == sx) {
            if (j == sy) u = get(i - 1, j);
          } else
            u = f[j];
        if (i == sx || j == sy)
          f[j] = get(i, j);
        else
          (f[j] = max(f[j], f[j - 1])), f[j] += t;
        if (l + t == f[j] || (l == -oo && u + t != f[j]))
          g[i - sx][j - sy] = 1;
        else if (u + t == f[j] || (u == -oo && l + t != f[j]))
          g[i - sx][j - sy] = 0;
      }
    while (n >= sx && m >= sy) {
      if (!n && !m) return;
      int t = g[n - sx][m - sy];
      Path = dic[t] + Path;
      if (t)
        --m;
      else
        --n;
    }
  } while (n >= 0 && m >= 0);
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i <= n - 1; ++i) {
    scanf("%d", a + i);
    a[i] %= p;
  }
  for (int i = 0; i <= m - 1; ++i) {
    scanf("%d", b + i);
    b[i] %= p;
  }
  for (int i = 0; i <= n - 1; ++i) {
    for (int j = 0; j <= m - 1; ++j) {
      if (j) (f[j] = max(f[j], f[j - 1]));
      f[j] += (a[i] + b[j] >= p ? a[i] + b[j] - p : a[i] + b[j]);
    }
    int row = i / ml, col = i % ml;
    if (!(i % ml))
      for (int j = 0; j <= m - 1; ++j) rec[row][j / ml].r[j % ml] = f[j];
    for (int j = 0; j < m; j += ml) rec[row][j / ml].d[col] = f[j];
  }
  cout << f[m - 1] << endl;
  Gen(n - 1, m - 1);
  cout << Path << endl;
}
