func_code_string: #include <bits/stdc++.h>   template <typename T>   inline void SWAP(T &a, T &b) {     T tmp = a;     a = b;     b = tmp;   }   template <typename T>   inline T ABS(const T &val) {     return val < 0 ? -val : val;   }   template <typename T>   inline T MAX(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline T MIN(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline T SQR(const T &a) {     return a * a;   }   const int INTinf = 2147483647;   const int nINTinf = 0 - 2147483648;   using namespace std;   int n, m, p;   const int SZ = 20002;   int _X[SZ], _Y[SZ];   int A[142][SZ];   int B[141][SZ];   int F[SZ << 1];   int *m1, *m2;   int kol = 0;   long long answ2 = 0L;   string answ =   ;   inline int f(const int &a, const int &b) { return F[_X[a] + _Y[b]]; }   int main() {     cin >> n >> m >> p;     int SZ2 = SZ << 1;     for (int i = 0; i != SZ2; i++) {       F[i] = i % p;     }     for (int i = 0; i != n; i++) cin >> _X[i];     for (int i = 0; i != m; i++) cin >> _Y[i];     m1 = A[0];     m1[0] = f(0, 0);     for (int i = 1; i <= n - 1; i++) {       m1[i] = m1[i - 1] + f(i, 0);     }     int nPos = 0;     for (int i = 1; i <= m - 1; i++) {       if (!nPos) {         copy(m1, m1 + SZ, B[kol++]);       }       nPos++;       if (nPos == 142) nPos = 0;       m2 = A[nPos];       m2[0] = m1[0] + f(0, i);       for (int j = 1; j <= n - 1; j++) {         m2[j] = MAX(m1[j], m2[j - 1]) + f(j, i);       }       m1 = m2;     }     int Y = n - 1;     int X = m - 1;     while (true) {       while (Y && (A[nPos][Y] - f(Y, X) == A[nPos][Y - 1])) {         answ.push_back( C );         answ2 += f(Y, X);         Y--;       }       answ2 += f(Y, X);       answ.push_back( S );       X--;       if (!nPos) {         break;       }       nPos--;     }     kol--;     if (m % 142 != 1) {       kol--;     }     while (kol > -1) {       copy(B[kol], B[kol] + SZ, A[0]);       int to = (kol + 1) * 142;       m1 = A[0];       for (int i = 142 * kol + 1; i != to; i++) {         nPos++;         m2 = A[nPos];         m2[0] = m1[0] + f(0, i);         for (int j = 1; j <= n - 1; j++) {           m2[j] = MAX(m1[j], m2[j - 1]) + f(j, i);         }         m1 = m2;       }       while (true) {         while (Y && (A[nPos][Y] - f(Y, X) == A[nPos][Y - 1])) {           answ.push_back( C );           answ2 += f(Y, X);           Y--;         }         answ2 += f(Y, X);         answ.push_back( S );         X--;         if (!nPos) {           break;         }         nPos--;       }       kol--;     }     answ = answ.substr(0, answ.size() - 1);     reverse(answ.begin(), answ.end());     cout << answ2 << endl;     cout << answ << endl;     return 0;   }   