Problem: Little Gerald and his coach Mike play an interesting game. At the beginning of the game there is a pile consisting of n candies and a pile consisting of m stones. Gerald and Mike move in turns, Mike goes first. During his move Mike checks how many candies and stones Gerald has eaten. Let Gerald eat a candies and b stones. Then Mike awards Gerald f(a, b) prize points. Gerald during his move either eats a candy from the pile of candies or a stone from the pile of stones. As Mike sees that Gerald has eaten everything apart one candy and one stone, he awards points for the last time and the game ends. Gerald is not allowed to eat all the candies, and he is not allowed to eat all the stones too. Tell Gerald how to play to get the largest possible number of points: it is required to find one of the possible optimal playing strategies for Gerald.

Input

The first line contains three integers n, m, p (1 ≤ n, m ≤ 20000, 1 ≤ p ≤ 109). The second line contains n integers x0, x1, ..., xn - 1 (0 ≤ xi ≤ 20000). The third line contains m integers y0, y1, ..., ym - 1 (0 ≤ yi ≤ 20000). The value of f(a, b) is calculated as a remainder of the division of the sum xa + yb by number p.

Output

Print on the first line the only number: the maximal number of points Gerald can earn. Print on the second line a sting consisting of n + m - 2 characters, each of which is either a "C" or "S", the i-th character should be "C" if Gerald's i-th move should be eating a candy and "S" if he should eat a stone.

Examples

Input

2 2 10
0 0
0 1


Output

2
SC


Input

3 3 10
0 2 0
0 0 2


Output

10
CSSC


Input

3 3 2
0 1 1
1 1 0


Output

4
SCSC

Note

In the first test if Gerald's first move is eating a stone, he will receive a point for it and if he eats a candy, he will get zero pints. In any way Gerald will get 0 points before his first move, and 1 after his second one. This, the maximum number of points Gerald can get equals to 2, and for that he should first eat a stone, then a candy.

Solution (in CPP):

Solution:
#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 < 1e+7) {
    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;
}