func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   const int INF = 0x3f3f3f3f;   int n, s;   int a[maxn << 1], vis[maxn], nxt[maxn << 1][maxn], prv[maxn << 1][maxn],       lst[maxn];   int f[maxn][maxn], h[maxn][maxn];   vector<int> g[maxn][maxn];   vector<int> vec;   vector<int> pos[maxn];   inline void disC(int p1, int p2, int &nf, vector<int> &ng) {     if (p1 > p2) p2 += n;     nf += p2 - p1;     ng.push_back(p2 - p1);     return;   }   inline void disR(int p1, int p2, int &nf, vector<int> &ng) {     if (p1 < p2) p1 += n;     nf += p1 - p2;     ng.push_back(p2 - p1);     return;   }   inline bool between(int x, int y, int z) {     x %= n;     y %= n;     z %= n;     if (z <= x) z += n;     if (y < x) y += n;     return y > x && y < z;   }   inline void calcCGB(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = prv[p1 + n][a[p2]] % n;     if (between(p2, to, p1)) {       disC(p1, p2, resf, resg);       disC(p2, to, resf, resg);       disR(to, p2, resf, resg);     } else       disC(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;     return;   }   inline void calcCBG(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = nxt[p2][a[p2]] % n;     if (between(p2, to, p1)) {       disR(p1, to, resf, resg);       disC(to, p2, resf, resg);     } else       disC(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;     return;   }   inline void calcRGB(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = nxt[p1][a[p2]] % n;     if (between(p1, to, p2)) {       disR(p1, to, resf, resg);       disC(to, p2, resf, resg);     } else       disR(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;     return;   }   inline void calcRBG(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = prv[p2 + n][a[p2]] % n;     if (between(p1, to, p2)) {       disC(p1, to, resf, resg);       disR(to, p2, resf, resg);     } else       disR(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;   }   inline void calc(int p1, int p2, int &nf, vector<int> &ng) {     nf = INF;     calcCGB(p1, p2, nf, ng);     calcCBG(p1, p2, nf, ng);     calcRGB(p1, p2, nf, ng);     calcRBG(p1, p2, nf, ng);     return;   }   inline void print(int x) {     printf( %c%d n , x < 0 ?  -  :  + , abs(x));     return;   }   int x, dlt;   inline void go(int i, int j) {     if (i > 0) go(i - 1, h[i][j]);     for (int k = (0); k < (g[i][j].size()); ++k) {       int d = (g[i][j][k] < 0 ? -1 : 1), len = abs(g[i][j][k]);       for (int l = (0); l <= (len); ++l) {         if (a[x] == i && !vis[x]) print(dlt), dlt = 0, vis[x] = true;         ((x += d) += n) %= n;         dlt += d;       }       ((x -= d) += n) %= n;       (dlt -= d);     }     return;   }   int main() {     scanf( %d%d , &n, &s);     --s;     for (int i = (0); i < (n); ++i) {       scanf( %d , a + i);       vec.push_back(a[i]);     }     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());     int mx = 0;     for (int i = (0); i < (n); ++i) {       a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin(),       mx = max(mx, a[i]);       pos[a[i]].push_back(i);     }     for (int i = (0); i < (n); ++i) a[n + i] = a[i];     memset(lst, -1, sizeof(lst));     for (int i = (n << 1) - 1; i >= 0; --i) {       for (int j = (0); j <= (mx); ++j) nxt[i][j] = lst[j];       lst[a[i]] = i;     }     memset(lst, -1, sizeof(lst));     for (int i = (0); i < (n << 1); ++i) {       for (int j = (0); j <= (mx); ++j) prv[i][j] = lst[j];       lst[a[i]] = i;     }     memset(f, 0x3f, sizeof(f));     for (int i = (0); i < (pos[0].size()); ++i)       calc(s, pos[0][i], f[0][i], g[0][i]);     for (int i = (1); i <= (mx); ++i)       for (int j = (0); j < (pos[i].size()); ++j)         for (int k = (0); k < (pos[i - 1].size()); ++k)           if (f[i - 1][k] != INF) {             int nf = 0;             vector<int> ng;             calc(pos[i - 1][k], pos[i][j], nf, ng);             nf += f[i - 1][k];             if (nf < f[i][j]) f[i][j] = nf, g[i][j] = ng, h[i][j] = k;           }     int best = -1;     for (int i = (0); i < (pos[mx].size()); ++i)       if (!~best || f[mx][i] < f[mx][best]) best = i;     printf( %d n , f[mx][best]);     x = s, dlt = 0;     go(mx, best);     return 0;   }   