#include <bits/stdc++.h>
using namespace std;
const int MaxN = 20005;
const int MaxM = 10010;
unsigned int g[MaxM][MaxN / 32];
int a[MaxN], b[MaxN], dp[2][MaxN];
int ans[MaxN * 2];
int main() {
  int n, m, P;
  while (scanf("%d%d%d", &n, &m, &P) == 3) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      a[i] %= P;
    }
    for (int i = 0; i < m; i++) {
      scanf("%d", &b[i]);
      b[i] %= P;
    }
    memset(dp, 0, sizeof(dp));
    memset(g, 0, sizeof(g));
    for (int i = 0; i < n; i++) {
      int q = i & 1, p = 1 - q;
      for (int j = 0; j < m; j++) {
        int x = a[i] + b[j];
        if (x >= P) x -= P;
        dp[p][j] = dp[q][j] + x;
        if (j > 0 && dp[p][j] <= dp[p][j - 1] + x) {
          dp[p][j] = dp[p][j - 1] + x;
          if (i >= n - MaxM)
            g[i - max(0, n - MaxM)][j / 32] |= ((unsigned int)1 << (j % 32));
        }
      }
    }
    printf("%d\n", dp[n & 1][m - 1]);
    int N = 0, x = n - 1 - max(0, n - MaxM), y = m - 1;
    while (1) {
      if (n <= MaxM && x == 0 && y == 0) break;
      if (y && (g[x][y / 32] & ((unsigned int)1 << (y % 32)))) {
        ans[N++] = 1;
        y--;
      } else {
        ans[N++] = 0;
        if (x == 0)
          break;
        else
          x--;
      }
    }
    if (n > MaxM) {
      memset(dp, 0, sizeof(dp));
      memset(g, 0, sizeof(g));
      for (int i = 0; i < n; i++) {
        int q = i & 1, p = 1 - q;
        for (int j = 0; j < m; j++) {
          int x = a[i] + b[j];
          if (x >= P) x -= P;
          dp[p][j] = dp[q][j] + x;
          if (j > 0 && dp[p][j] <= dp[p][j - 1] + x) {
            dp[p][j] = dp[p][j - 1] + x;
            if (i < n - MaxM) g[i][j / 32] |= ((unsigned int)1 << (j % 32));
          }
        }
      }
      x = n - MaxM - 1;
      while (x || y) {
        if (!x || (g[x][y / 32] & ((unsigned int)1 << (y % 32)))) {
          ans[N++] = 1;
          y--;
        } else {
          ans[N++] = 0;
          x--;
        }
      }
    }
    for (int i = N - 1; i >= 0; i--) printf("%c", ans[i] ? 'S' : 'C');
    puts("");
  }
  return 0;
}
