malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1.5e3 + 5;   const int T = 1e5 + 5;   const int mod = 1e9 + 7;   int n, m, a, b, p, t;   int fac[T], inv[T], res;   int P[N], F[N], SP[N], SPL[N], S[N][N], L[N][N];   namespace _ {   inline int mul(int x, int y) { return 1ll * x * y % mod; }   inline int dec(int x, int y) {     x -= y;     if (x < 0) x += mod;     return x;   }   inline int add(int x, int y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline int modpow(int x, int y, int res = 1) {     for (; y; y >>= 1, x = mul(x, x))       if (y & 1) res = mul(res, x);     return res;   }   inline int C(int n, int m) {     if (m > n) return 0;     return mul(fac[n], mul(inv[m], inv[n - m]));   }   template <typename _Tp>   inline void IN(_Tp& x) {     char ch;     bool flag = 0;     x = 0;     while (ch = getchar(), !isdigit(ch))       if (ch ==  - ) flag = 1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     if (flag) x = -x;   }   }  // namespace _   using namespace _;   int main() {     fac[0] = inv[0] = 1;     IN(n), IN(m), IN(a), IN(b), IN(t), p = mul(a, modpow(b, mod - 2));     for (int i = 1; i <= t; ++i) fac[i] = mul(fac[i - 1], i);     for (int i = 1; i <= t; ++i) inv[i] = modpow(fac[i], mod - 2);     for (int i = 0; i <= m; ++i)       if (i <= t)         P[i] = mul(C(t, i), mul(modpow(p, i), modpow(dec(1, p), t - i)));     for (int i = 0; i <= m; ++i) SP[i] = i ? add(P[i], SP[i - 1]) : P[i];     S[0][m] = F[0] = 1;     for (int i = 1; i <= n; ++i) {       for (int r = 1; r <= m; ++r) {         res = dec(mul(SP[r - 1], dec(F[i - 1], L[i - 1][m - r + 1])), SPL[r]);         S[i][r] = mul(P[m - r], res), L[i][r + 1] = add(L[i][r], S[i][r]);         SPL[r] = add(SPL[r - 1], mul(P[r - 1], L[i][r]));       }       for (int r = 1; r <= m; ++r) F[i] = add(F[i], S[i][r]);     }     printf( %d n , F[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int matrix[105][105];   int vis[105][105];   int main() {     int n, k;     while (scanf( %d%d , &n, &k) != EOF) {       memset(matrix, 0, sizeof(matrix));       memset(vis, 0, sizeof(vis));       if (k > n * n) {         printf( -1 n );         continue;       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (!vis[i][j] && k) {             if (i == j) {               matrix[i][j]++;               vis[i][j] = 1;               k--;             } else if (k >= 2) {               matrix[i][j]++;               matrix[j][i]++;               vis[i][j] = vis[j][i] = 1;               k -= 2;             }           }         }       }       if (k) {         printf( -1 n );         continue;       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (j == n) {             printf( %d n , matrix[i][j]);           } else {             printf( %d  , matrix[i][j]);           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 5;   long long int dp[N][102];   int main() {     int n, k, m;     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= 9; i++) dp[1][i % k]++;     long long int wynik = 0, p = 1;     for (int x = 1; x <= n - 1; x++) {       p = (p * 10) % k;       wynik = (wynik * 10) % m;       wynik += dp[x][0] % m;       for (int i = 1; i < k; i++) {         dp[x][i] %= m;         for (int j = 0; j <= 9; j++)           if (j || (x != n - 1)) dp[x + 1][(i + j * p) % k] += dp[x][i];       }       for (int j = 1; j <= 9; j++) dp[x + 1][(j * p) % k]++;     }     wynik *= 9;     wynik += dp[n][0];     printf( %lld n , wynik % m);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000006, B = 1000001969;   int n, k, m, L[N], R[N];   char a[N], b[N];   long long a1[N], M[N];   set<int> Set;   int actual(int x) {     auto it = Set.lower_bound(x);     return it == Set.end() ? n + 1 : *it;   }   void hash_build(char a[], int n, long long H[]) {     for (int i = 1; i <= n; i++) H[i] = (H[i - 1] * M[1] + a[i]) % B;   }   long long hash_range(long long H[], int L, int R) {     return (H[R] - H[L - 1] * M[R - L + 1] + 1LL * B * B) % B;   }   int main() {     scanf( %d%d , &n, &k);     scanf( %s , b + 1);     m = strlen(b + 1);     for (int i = 1; i <= k; i++) {       scanf( %d , &L[i]);       R[i] = L[i] + m - 1;     }     for (int i = 1; i <= n; i++) {       a[i] =  ? ;       Set.insert(i);     }     for (int i = 1; i <= k; i++) {       for (int j = actual(L[i]); j <= R[i]; j = actual(j + 1)) {         a[j] = b[j - L[i] + 1];         Set.erase(j);       }     }     M[0] = 1;     M[1] = 2309;     for (int i = 2; i < N; i++) M[i] = M[i - 1] * M[1] % B;     hash_build(a, n, a1);     if (k) {       long long H = hash_range(a1, L[1], R[1]);       for (int i = 2; i <= k; i++)         if (hash_range(a1, L[i], R[i]) != H) {           cout << 0 << endl;           return 0;         }     }     long long P = 1;     for (int i = 1; i <= Set.size(); i++) P = P * 26 % 1000000007;     cout << P << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     long long int arr[n], i, c = 0;     for (i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] == 1) c++;     }     if (c == n) {       for (i = 0; i < n - 1; i++) cout << 1 <<    ;       cout << 2 <<   n ;     } else {       sort(arr, arr + n);       cout << 1 <<    ;       for (i = 0; i < n - 1; i++) cout << arr[i] <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   unsigned N, M;   vector<unsigned> V;   double dens(const unsigned idxV1, const unsigned idxV2, const unsigned eW) {     if (eW == 0) {       return 0;     }     return (double)(V[idxV1] + V[idxV2]) / (double)eW;   }   int main() {     unsigned v1, v2, w, n, m;     double densidad;     double max = 0;     cout << setprecision(20);     cin >> N;     cin >> M;     V = vector<unsigned>(N);     for (n = 0; n < N; n++) {       cin >> w;       V[n] = w;     }     for (m = 0; m < M; m++) {       cin >> v1;       cin >> v2;       cin >> w;       v1--;       v2--;       densidad = dens(v1, v2, w);       if (densidad > max) {         max = densidad;       }     }     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 2e6 + 10;   const long long mod = 1000000007;   const double eps = 1e-9;   const double PI = acos(-1);   template <typename T>   inline void read(T &a) {     char c = getchar();     T x = 0, f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     a = f * x;   }   int gcd(int a, int b) { return (b > 0) ? gcd(b, a % b) : a; }   int n, m;   char str[N];   int main() {     int T;     read(T);     while (T--) {       read(n), read(m);       scanf( %s , str + 1);       int len = strlen(str + 1);       int dx = 0, dy = 0;       int minx = 0, miny = 0;       int maxx = 0, maxy = 0;       int ansx = 1, ansy = 1;       for (int i = 1; i <= len; i++) {         char it = str[i];         if (it ==  L )           dx--;         else if (it ==  R )           dx++;         else if (it ==  U )           dy--;         else if (it ==  D )           dy++;         minx = min(minx, dx);         miny = min(miny, dy);         maxx = max(maxx, dx);         maxy = max(maxy, dy);         if ((maxx - minx) >= m || (maxy - miny) >= n) break;         ansx = 1 - minx;         ansy = 1 - miny;       }       cout << ansy <<     << ansx << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     ;     int T;     cin >> T;     while (T--) {       int n;       string s;       cin >> n;       cin >> s;       int arr[200002];       int cnt = 1;       int idx = 1;       char x = s[0];       for (int i = (1); i <= (n - 1); i++) {         if (s[i] == x) {           cnt++;         } else if (s[i] != x) {           x = s[i];           arr[idx] = cnt;           idx++;           cnt = 1;         }       }       arr[idx] = cnt;       arr[idx + 1] = 2;       int ans = 0;       int idx2 = 1;       int usable_idx = 1;       int len = idx;       while (arr[usable_idx] == 1) {         usable_idx++;       }       while (idx2 <= len) {         if (usable_idx > len) {           ans += (len - idx2) / 2 + 1;           break;         }         if (arr[idx2] == 1) {           arr[usable_idx]--;           if (arr[usable_idx] == 1) {             usable_idx++;             while (arr[usable_idx] == 1) {               usable_idx++;             }           }         } else if (arr[idx2] != 1) {           if (usable_idx == idx2) {             usable_idx++;             while (arr[usable_idx] == 1) {               usable_idx++;             }           }         }         idx2++;         ans++;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     cout << (n / 2) + 1 << endl;     for (i = 1; i <= (n / 2) + 1; i++) cout << i <<   1  << endl;     ;     if (n % 2 != 0)       for (i = 2; i <= (n / 2) + 1; i++) cout << (n / 2) + 1 <<     << i << endl;     else       for (i = 2; i < (n / 2) + 1; i++) cout << (n / 2) + 1 <<     << i << endl;   }
#include <bits/stdc++.h>   using namespace std;   void dbg_out() { cerr <<   b b] n ; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr << H <<  ,  ;     dbg_out(T...);   }   void solve() {     long double n;     cin >> n;     cout << fixed << setprecision(10);     if (n == 2) {       long double ans = 1;       cout << ans <<   n ;       return;     }     n *= 2;     const double pi = acosl((long double)-1);     double radian = pi / n;     double radius = 1.0 / tan(radian);     cout << radius <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long int> a(n);     for (auto &it : a) cin >> it;     long long o = (n + 1) / 2, e = n / 2;     for (auto it : a) {       if (!it) continue;       if (it % 2)         o--;       else         e--;     }     long long l_val = -1, l_idx = -1;     vector<pair<long long int, long long int> > v11, v00, v10, v01;     for (long long i = 0; i < n; i++) {       long long it = a[i];       if (!it) continue;       if (it % 2) {         if (l_val == -1)           v11.push_back({i - l_idx - 1, 1});         else if (l_val % 2)           v11.push_back({i - l_idx - 1, 0});         else           v01.push_back({i - l_idx - 1, 0});       } else {         if (l_val == -1)           v00.push_back({i - l_idx - 1, 1});         else if (l_val % 2 == 0)           v00.push_back({i - l_idx - 1, 0});         else           v10.push_back({i - l_idx - 1, 0});       }       l_idx = i, l_val = it % 2;     }     if (l_val != -1) {       if (l_val % 2)         v11.push_back({n - l_idx - 1, 1});       else         v00.push_back({n - l_idx - 1, 1});     }     sort(v00.begin(), v00.end());     sort(v11.begin(), v11.end());     long long ans = ((long long int)(v01).size()) + ((long long int)(v10).size());     for (auto it : v11) {       if (it.second == 1) continue;       if (o >= it.first)         o -= it.first;       else         ans += 2;     }     for (auto it : v11) {       if (it.second == 0) continue;       if (o >= it.first)         o -= it.first;       else         ans++;     }     for (auto it : v00) {       if (it.second == 1) continue;       if (e >= it.first)         e -= it.first;       else         ans += 2;     }     for (auto it : v00) {       if (it.second == 0) continue;       if (e >= it.first)         e -= it.first;       else         ans++;     }     bool first = 0;     for (auto it : a) first |= it;     if (!first and n > 1) ans++;     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(20);     long long t = 1;     while (t--) {       solve();       cout <<   n ;     }     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[100006][2];   int main(void) {     string s;     cin >> s;     int len = s.size();     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     dp[0][1] = 0;     for (int i = 1; i <= len; ++i) {       dp[i][1] = dp[i - 1][1] + (bool)islower(s[i - 1]);       dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + (bool)isupper(s[i - 1]);     }     cout << min(dp[len][0], dp[len][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 100, mod = 998244353;   int n, c[N], s[N];   int qpow(int x, int y) {     int res = 1;     while (y) {       if (y & 1) res = 1ll * res * x % mod;       x = 1ll * x * x % mod, y >>= 1;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &c[i]);     sort(c + 1, c + n + 1), reverse(c + 1, c + n + 1);     for (int i = 1; i <= n; ++i) s[i] = (s[i - 1] + c[i]) % mod;     int iv = qpow(n, mod - 2);     for (int i = 1; i <= n; ++i) {       int ans = 0;       for (int j = i + 1; j <= n; j += i)         ans = (ans + 1ll * (s[min(n, j + i - 1)] - s[j - 1] + mod) *                          ((j - 1) / i) % mod) %               mod;       printf( %lld  , 1ll * ans * iv % mod);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100007], b[100007];   vector<int> v, ans;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, x;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> x, a[x]++;     for (int i = 0; i < n; i++) cin >> x, b[m - x - 1]++;     for (int x = 0; x < 2 * m; x++) {       int i = x % m;       while (a[i]) v.push_back(i), a[i]--;       while (b[i] && v.size())         ans.push_back((v.back() + m - i - 1) % m), v.pop_back(), b[i]--;     }     sort(ans.begin(), ans.end());     for (long i = ans.size() - 1; i >= 0; i--) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int popc(long long int x) {     int cnt = 0;     for (int i = 0; i < 50; i++) {       if ((1ll << i) & x) cnt++;     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(0);     long long int s, x;     cin >> s >> x;     if (s < x) {       cout <<  0 n ;       return 0;     }     if (s == x) {       cout << ((1ll << (popc(s))) - 2) << endl;       return 0;     }     if ((s - x) % 2 == 1) {       cout <<  0  << endl;       return 0;     }     long long int rest = (s - x) / 2;     for (int i = 0; i < 50; i++) {       if ((((1ll << i) & x) != 0) && (((1ll << i) & rest) != 0)) {         cout <<  0 n ;         return 0;       }     }     cout << (1ll << popc(x)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int p = 1;     int diagjump = n + 1;     for (int i = 1; i <= n; i++) {       p = i;       for (int j = 1; j <= n; j++) {         cout << p <<    ;         if (p == n * j)           p++;         else           p += diagjump;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool checkprime(long long n) {     long long i = 2;     while (i * i <= n) {       if (n % i == 0) return 0;       i++;     }     return 1;   }   long long fact(long long n) {     if (n == 0) return 1;     return n * fact(n - 1);   }   bool compare(const pair<long long, long long>& i,                const pair<long long, long long>& j) {     return i.first < j.first;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long ans = 0;     long long l[m + 1], r[m + 1], t[m + 1], c[m + 1];     for (long long i = 1; i <= m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];     for (long long i = 1; i <= n; i++) {       long long mxc = 0, mx = 100000, mxi = -1;       for (long long j = 1; j <= m; j++) {         if (i >= l[j] && i <= r[j] && t[j] < mx) {           mxi = j;           mx = t[j];           mxc = c[j];         }       }       ans += mxc;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool flag;   int n, k, vis[10][105];   char s[10][105];   int judge(int x, int y) {     if ((s[x][y] ==  .  || s[x][y] ==  s ) && (x >= 1 && x <= 3))       return 1;     else       return 0;   }   void dfs(int x, int y) {     vis[x][y] = 1;     if (y >= n - 1) {       flag = 1;       return;     }     if (!judge(x, y + 1)) return;     if (flag == 1) return;     if (judge(x, y + 1) && judge(x, y + 2) && judge(x, y + 3) && !vis[x][y + 3])       dfs(x, y + 3);     if (judge(x - 1, y + 1) && judge(x - 1, y + 2) && judge(x - 1, y + 3) &&         !vis[x - 1][y + 3])       dfs(x - 1, y + 3);     if (judge(x + 1, y + 1) && judge(x + 1, y + 2) && judge(x + 1, y + 3) &&         !vis[x + 1][y + 3])       dfs(x + 1, y + 3);   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> k;       flag = 0;       for (int i = 1; i <= 3; i++) {         for (int j = 0; j < n; j++) cin >> s[i][j];       }       int x, y;       for (int i = 1; i <= 3; i++) {         for (int j = 0; j < n; j++) {           if (s[i][j] ==  s ) x = i, y = j;         }       }       for (int i = 1; i <= 3; i++)         for (int j = n; j <= 104; j++) s[i][j] =  . ;       memset(vis, 0, sizeof(vis));       dfs(x, y);       if (flag == 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a, b, c;       cin >> a >> b >> c;       string s;       cin >> s;       long long x = 0, y = 0, z = 0;       for (long long i = 0; i < n; i++) {         if (s[i] ==  R ) {           x++;         } else if (s[i] ==  P ) {           y++;         } else {           z++;         }       }       long long win = 0;       win = min(a, z) + min(b, x) + min(c, y);       long long r = (n + 1) / 2;       if (win >= r) {         cout <<  YES  << endl;         char ans[n];         for (long long i = 0; i < n; i++) {           if (s[i] ==  S  && a) {             ans[i] =  R ;             a--;             z--;           } else if (s[i] ==  R  && b) {             ans[i] =  P ;             b--;             x--;           } else if (s[i] ==  P  && c) {             ans[i] =  S ;             c--;             y--;           } else if (s[i] ==  S  && b > x) {             ans[i] =  P ;             b--;           } else if (s[i] ==  S  && c > y) {             ans[i] =  S ;             c--;           } else if (s[i] ==  R  && a > z) {             ans[i] =  R ;             a--;           } else if (s[i] ==  R  && c > y) {             ans[i] =  S ;             c--;           } else if (s[i] ==  P  && a > z) {             ans[i] =  R ;             a--;           } else if (s[i] ==  P  && b > x) {             ans[i] =  P ;             b--;           }         }         for (long long i = 0; i < n; i++) {           cout << ans[i];         }         cout << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   const ll INF = 1e18;   const ll MOD = 1e9 + 7;   const ld EPS = 1e-10;   const ld PI = acos(-1);   vector<ll> po[2];   ll n, k;   pair<ll, ll> CountHash(ll x, ll ind, ll q) {     ll h1 = 0, h2 = 0;     for (ll i = 2; i * i <= x; ++i) {       if (x % i == 0) {         ll a = 0;         while (x % i == 0) {           ++a;           x /= i;         }         a %= k;         ll b = (k - a) % k;         h1 += a * po[ind][i] % q;         h2 += b * po[ind][i] % q;         h1 %= q;         h2 %= q;       }     }     if (x > 1) {       h1 += 1 * po[ind][x] % q;       h2 += (k - 1) * po[ind][x] % q;       h1 %= q;       h2 %= q;     }     return {h1, h2};   }   void solve() {     cin >> n >> k;     map<pair<ll, ll>, ll> cnt;     ll P1 = 239;     ll Q1 = 1e9 + 7;     ll P2 = 41;     ll Q2 = 1e9 + 9;     po[0].resize(100000);     po[1].resize(100000);     po[0][0] = 1;     po[1][0] = 1;     for (int i = 1; i < 100000; ++i) {       po[0][i] = po[0][i - 1] * P1 % Q1;       po[1][i] = po[1][i - 1] * P2 % Q2;     }     ll ans = 0;     for (int i = 0; i < n; ++i) {       ll x;       cin >> x;       auto h1 = CountHash(x, 0, Q1);       auto h2 = CountHash(x, 1, Q2);       ans += cnt[{h1.second, h2.second}];       ++cnt[{h1.first, h2.first}];     }     cout << ans <<   n ;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000 + 5;   int s, n, m, a[maxN];   vector<int> p[maxN];   vector<int> f[maxN], g[maxN];   void initialize() {     ios::sync_with_stdio(false);     cin >> n >> s;     s--;     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> t(a, a + n);     sort(t.begin(), t.end());     t.erase(unique(t.begin(), t.end()), t.end());     for (int i = 0; i < n; ++i)       a[i] = lower_bound(t.begin(), t.end(), a[i]) - t.begin() + 1;     m = t.size();     for (int i = 0; i < n; ++i) p[a[i]].push_back(i);     p[0].push_back(s);     f[0].push_back(0);     g[0].push_back(-1);   }   int cyc(int x, int y) { return y < x ? y + n - x : y - x; }   int cont(int x, int y) { return cyc(y, x); }   int sp(int x, int y) { return min(cyc(x, y), cont(x, y)); }   template <typename T>   bool chmin(T &x, const T &y) {     return y < x ? x = y, true : false;   }   int solve() {     for (int st = 1; st <= m; ++st) {       int sz = p[st].size();       f[st].assign(sz, maxN * maxN);       g[st].assign(sz, -1);       for (int i = 0; i < sz; ++i) {         int pre = i - 1, post = i + 1;         if (pre == -1) pre = sz - 1;         if (post == sz) post = 0;         for (int j = 0; j < (int)p[st - 1].size(); ++j) {           chmin(f[st][i], f[st - 1][j] + sp(p[st - 1][j], p[st][pre]) +                               cont(p[st][pre], p[st][i])) &&               (g[st][i] = j);           chmin(f[st][i], f[st - 1][j] + sp(p[st - 1][j], p[st][post]) +                               cyc(p[st][post], p[st][i])) &&               (g[st][i] = j);         }       }     }     return *min_element(f[m].begin(), f[m].end());   }   void psp(int x, int y) {     if (cyc(x, y) <= cont(x, y))       printf( +%d n , cyc(x, y));     else       printf( -%d n , cont(x, y));   }   void print(int st, int i) {     if (st == 0) return;     int j = g[st][i];     print(st - 1, j);     int sz = p[st].size();     int pre = i - 1, post = i + 1;     if (pre == -1) pre = sz - 1;     if (post == sz) post = 0;     int cpre =         f[st - 1][j] + sp(p[st - 1][j], p[st][pre]) + cont(p[st][pre], p[st][i]);     int cpost =         f[st - 1][j] + sp(p[st - 1][j], p[st][post]) + cyc(p[st][post], p[st][i]);     if (cpre < cpost) {       psp(p[st - 1][j], p[st][pre]);       while (pre != i) {         int pp = pre - 1;         if (pp == -1) pp = sz - 1;         printf( -%d n , cont(p[st][pre], p[st][pp]));         pre = pp;       }     } else {       psp(p[st - 1][j], p[st][post]);       while (post != i) {         int pp = post + 1;         if (pp == sz) pp = 0;         printf( +%d n , cyc(p[st][post], p[st][pp]));         post = pp;       }     }   }   int main() {     initialize();     cout << solve() << endl;     print(m, min_element(f[m].begin(), f[m].end()) - f[m].begin());     return 0;   }