#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 9223372036854775807;
const int Sz = 4e4 + 2;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long dp1[Sz], dp2[Sz];
int a[Sz], b[Sz];
int n, m, p;
int len;
int cost;
string ans;
inline int f(int x, int y) { return (a[x] + b[y]) % p; }
void solve(int lx, int ly, int rx, int ry) {
  if (lx == rx) {
    cost += f(lx, ly);
    for (int j = ly + 1; j <= ry; j++) ans.push_back('S'), cost += f(lx, j);
    return;
  }
  int mid = (lx + rx) >> 1;
  for (int i = ly - 1; i <= ry + 1; i++) dp1[i] = dp2[i] = 0;
  for (int i = lx; i <= mid; i++)
    for (int j = ly; j <= ry; j++) dp1[j] = max(dp1[j], dp1[j - 1]) + f(i, j);
  for (int i = rx; i >= mid; i--)
    for (int j = ry; j >= ly; j--) dp2[j] = max(dp2[j], dp2[j + 1]) + f(i, j);
  int y = 0;
  long long V = -1;
  for (int j = ry; j >= ly; j--) {
    long long val = dp1[j] + dp2[j] - f(mid, j);
    if (val > V) {
      V = val;
      y = j;
    }
  }
  solve(lx, ly, mid, y);
  ans.push_back('C');
  solve(mid + 1, y, rx, ry);
}
int getInt() {
  char x = getchar();
  while (!isdigit(x)) x = getchar();
  int res = 0;
  while (isdigit(x)) res = res * 10 + x - '0', x = getchar();
  return res;
}
int main() {
  n = getInt(), m = getInt(), p = getInt();
  for (int i = 1; i <= n; i++) a[i] = getInt();
  for (int i = 1; i <= m; i++) b[i] = getInt();
  solve(1, 1, n, m);
  printf("%d\n%s", cost, ans.c_str());
  return 0;
}
