#include <bits/stdc++.h>
using namespace std;
const int maxn = 20010;
int n, m, p;
int _x[2 * maxn], _y[2 * maxn];
int layer[2][maxn];
pair<int, int> points[2][maxn];
int getcost(pair<int, int> point) {
  int x = point.first, y = point.second;
  int ans = _x[x] + _y[y];
  while (ans >= p) ans -= p;
  return ans;
}
bool check(pair<int, int> point, int x1, int y1, int x2, int y2) {
  return (x1 <= point.first && point.first <= x2 && y1 <= point.second &&
          point.second <= y2) ||
         (x1 >= point.first && point.first >= x2 && y1 >= point.second &&
          point.second >= y2);
}
int L = 0;
pair<vector<int>, vector<pair<int, int> > > solve(int fx, int fy, int tx,
                                                  int ty, int dist) {
  int signum = dist > 0 ? 1 : -1;
  dist = dist > 0 ? dist : -dist;
  layer[0][0] = getcost(make_pair(fx, fy));
  layer[1][0] = 0;
  points[0][0] = make_pair(fx, fy);
  int lastsize = 1;
  int fr = 0, to = 1;
  L = 0;
  for (int j = 0; j < dist; ++j) {
    for (int i = 0; i < lastsize; ++i)
      points[to][i] =
          make_pair(points[fr][i + L].first, points[fr][i + L].second + signum);
    points[to][lastsize] =
        make_pair(points[fr][lastsize - 1 + L].first + signum,
                  points[fr][lastsize - 1 + L].second);
    for (int i = 0; i < lastsize; ++i) {
      layer[to][i] =
          max(layer[to][i], layer[fr][i + L] + getcost(points[to][i]));
      layer[to][i + 1] = layer[fr][i + L] + getcost(points[to][i + 1]);
    }
    lastsize++;
    L = 0;
    if (!check(points[to][0], fx, fy, tx, ty)) {
      lastsize--;
      L = 1;
    }
    if (!check(points[to][lastsize - 1], fx, fy, tx, ty)) {
      lastsize--;
    }
    swap(fr, to);
  }
  vector<int> Layer(lastsize);
  vector<pair<int, int> > Points(lastsize);
  for (int i = 0; i < lastsize; ++i)
    Layer[i] = layer[fr][i + L], Points[i] = points[fr][i + L];
  return make_pair(Layer, Points);
}
set<pair<int, int> > answer;
int answerValue;
void stupid(int x1, int y1, int x2, int y2) {
  vector<vector<int> > dp(x2 - x1 + 1, vector<int>(y2 - y1 + 1));
  dp[0][0] = getcost(make_pair(x1, y1));
  for (int i = 0; i < ((int)dp.size()); ++i) {
    for (int j = 0; j < ((int)dp[i].size()); ++j) {
      if (i) dp[i][j] = dp[i - 1][j] + getcost(make_pair(x1 + i, y1 + j));
      if (j)
        dp[i][j] =
            max(dp[i][j], dp[i][j - 1] + getcost(make_pair(x1 + i, y1 + j)));
    }
  }
  answerValue = dp.back().back();
  pair<int, int> curpos = make_pair(x2 - x1, y2 - y1);
  answer.insert(make_pair(x1, y1));
  for (int i = 0; i < x2 + y2 - x1 - y1; ++i) {
    int cnt = getcost(make_pair(curpos.first + x1, curpos.second + y1));
    dp[curpos.first][curpos.second] -= cnt;
    answer.insert(make_pair(curpos.first + x1, curpos.second + y1));
    if (curpos.second && dp[curpos.first][curpos.second - 1] ==
                             dp[curpos.first][curpos.second]) {
      curpos.second--;
    } else {
      curpos.first--;
    }
  }
}
void solve(int x1, int y1, int x2, int y2) {
  int needX = x2 - x1, needY = y2 - y1;
  int middle1 = (needX + needY) >> 1;
  int middle2 = needX + needY - middle1;
  if (needX * needY < 100) {
    stupid(x1, y1, x2, y2);
    return;
  }
  pair<vector<int>, vector<pair<int, int> > > l =
      solve(x1, y1, min(x2, x1 + middle1), min(y2, y1 + middle1), middle1);
  pair<vector<int>, vector<pair<int, int> > > r =
      solve(x2, y2, max(x1, x2 - middle2), max(y1, y2 - middle2), -middle2);
  vector<int> res(((int)l.first.size()));
  int index = 0;
  int tlen = ((int)r.first.size());
  for (int i = 0; i < ((int)l.first.size()); ++i) {
    res[i] = l.first[i] + r.first[tlen - i - 1] - getcost(l.second[i]);
    if (res[i] > res[index]) index = i;
  }
  answer.insert(l.second[index]);
  solve(x1, y1, l.second[index].first, l.second[index].second);
  solve(l.second[index].first, l.second[index].second, x2, y2);
  answerValue = res[index];
}
void solve() {
  scanf("%d%d%d", &n, &m, &p);
  memset(_x, -1, sizeof(_x)), memset(_y, -1, sizeof(_y));
  for (int i = 0; i < n; ++i) scanf("%d", &_x[i]), _x[i] %= p;
  for (int i = 0; i < m; ++i) scanf("%d", &_y[i]), _y[i] %= p;
  solve(0, 0, n - 1, m - 1);
  printf("%d\n", answerValue);
  vector<pair<int, int> > answer(::answer.begin(), ::answer.end());
  for (int i = 0; i < ((int)answer.size()) - 1; ++i) {
    if (answer[i + 1].first > answer[i].first)
      putchar('C');
    else
      putchar('S');
  }
  printf("\n");
}
int main() {
  solve();
  return 0;
}
