#include <bits/stdc++.h>
using namespace std;
const int maxn = 21000;
int n, m, P;
struct Tcxx {
  int x, y;
} A[maxn];
namespace Ninit {
void init() {
  int i;
  scanf("%d%d%d", &n, &m, &P);
  for (i = 1; i <= n; ++i) scanf("%d", &A[i].x);
  for (i = 1; i <= m; ++i) scanf("%d", &A[i].y);
}
}  // namespace Ninit
namespace Nsolve {
bool O[maxn * 2];
int N;
long long ans;
int Px, Py;
namespace Ndp {
bitset<maxn> G[maxn / 2];
long long F[maxn];
inline int B(int x, int y) { return (A[x].x + A[y].y) % P; }
void solve(bool flag) {
  int i, j;
  memset(F, 0, sizeof F), F[0] = -1, F[1] = 0;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      if (F[j - 1] < F[j]) {
        F[j] += B(i, j);
        if (flag && i <= n / 2) G[i][j] = 0;
        if (!flag && i > n / 2) G[i - n / 2][j] = 0;
      } else {
        F[j] = F[j - 1] + B(i, j);
        if (flag && i <= n / 2) G[i][j] = 1;
        if (!flag && i > n / 2) G[i - n / 2][j] = 1;
      }
    }
  if (!flag) {
    for (ans = F[m]; Px > n / 2;) (O[N++] = G[Px - n / 2][Py]) ? --Py : --Px;
  } else {
    for (; Px;) (O[N++] = G[Px][Py]) ? --Py : --Px;
  }
}
}  // namespace Ndp
void solve() {
  int i;
  Px = n, Py = m;
  Ndp::solve(false), Ndp::solve(true);
  cout << ans << endl;
  reverse(O, O + n + m - 2);
  for (i = 0; i < n + m - 2; ++i) printf(O[i] ? "S" : "C");
  printf("\n");
}
}  // namespace Nsolve
int main() {
  Ninit::init();
  Nsolve::solve();
  return 0;
}
