#include <bits/stdc++.h>
using namespace std;
int x[20000], y[20000], n, m, p;
int dp[20000];
bitset<20001> par[10000 + 1];
int main() {
  cin >> n >> m >> p;
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int j = 0; j < m; j++) cin >> y[j];
  memset(dp, 0, sizeof dp);
  dp[0] = (x[0] + y[0]) % p;
  for (int i = 1; i < n; i++) dp[i] = dp[i - 1] + ((x[i] + y[0]) % p);
  for (int j = 1; j < m; j++) {
    dp[0] += ((x[0] + y[j]) % p);
    if (j >= 10000) par[j - 10000].set(0, true);
    for (int i = 1; i < n; i++) {
      if (dp[i] < dp[i - 1]) {
        dp[i] = dp[i - 1] + ((x[i] + y[j]) % p);
        if (j >= 10000) par[j - 10000].set(i, true);
      } else {
        dp[i] += ((x[i] + y[j]) % p);
        if (j >= 10000) par[j - 10000].reset(i);
      }
    }
  }
  cout << dp[n - 1] << endl;
  string ans;
  int k = n - 1;
  for (int j = m - 1; j >= 10000; j--) {
    while (k && par[j - 10000].test(k)) {
      k--;
      ans += 'C';
    }
    ans += 'S';
  }
  m = min(m, 10000);
  dp[0] = (x[0] + y[0]) % p;
  for (int i = 1; i < n; i++) dp[i] = dp[i - 1] + ((x[i] + y[0]) % p);
  for (int j = 1; j < m; j++) {
    dp[0] += ((x[0] + y[j]) % p);
    par[j].set(0, true);
    for (int i = 1; i < n; i++) {
      if (dp[i] < dp[i - 1]) {
        dp[i] = dp[i - 1] + ((x[i] + y[j]) % p);
        par[j].set(i, true);
      } else {
        dp[i] += ((x[i] + y[j]) % p);
        par[j].reset(i);
      }
    }
  }
  for (int j = m - 1; j > 0; j--) {
    while (k && par[j].test(k)) {
      k--;
      ans += 'C';
    }
    ans += 'S';
  }
  while (k) {
    ans += 'C';
    k--;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}
