malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   set<int> in[100005];   pair<int, int> id[100005];   int bit[100005];   int lastNum[100005];   int color[100005];   void solve() {     int n, m;     scanf( %d %d  , &n, &m);     long long sum = 0;     for (int i = 1; i <= n; ++i) {       int num;       scanf( %d  , &num);       sum += num;       while (num--) {         int x;         scanf( %d  , &x);         in[i].insert(x);       }       id[i] = {in[i].size(), i};     }     int x = sum / n;     int lim = (n - sum % n);     int t = 0;     for (int i = 1; i <= n; ++i) {       if (i <= lim) {         lastNum[i] = x;       } else {         lastNum[i] = x + 1;       }       t += lastNum[i];     }     assert(t == sum);     sort(id + 1, id + n + 1);     int l = 1, r = n;     vector<pair<pair<int, int>, int> > out;     bool lin = false, rin = false;     set<int> swapNums;     while (l < r) {       int lid = id[l].second;       int rid = id[r].second;       if (in[lid].size() == lastNum[l]) {         if (lin) {           for (int x : in[lid]) {             assert(color[x] & 1);             color[x] ^= 1;             if (color[x] == 2) {               assert(!swapNums.count(x));               swapNums.insert(x);             }           }         }         ++l;         lin = false;         continue;       }       if (in[rid].size() == lastNum[r]) {         if (rin) {           for (int x : in[rid]) {             assert(color[x] & 2);             if (color[x] == 2) {               assert(swapNums.count(x));               swapNums.erase(x);             }             color[x] ^= 2;           }         }         --r;         rin = false;         continue;       }       if (!lin) {         for (int x : in[lid]) {           color[x] |= 1;           if (color[x] == 3) {             assert(swapNums.count(x));             swapNums.erase(x);           }         }         lin = true;       }       if (!rin) {         for (int x : in[rid]) {           color[x] |= 2;           if (color[x] == 2) {             assert(!swapNums.count(x));             swapNums.insert(x);           }         }         rin = true;       }       assert(in[lid].size() < lastNum[l]);       assert(in[rid].size() > lastNum[r]);       while (in[lid].size() != lastNum[l] && in[rid].size() != lastNum[r]) {         assert(swapNums.size() > 0);         int g = *swapNums.begin();         swapNums.erase(g);         in[lid].insert(g);         in[rid].erase(g);         out.push_back({{rid, lid}, g});         color[g] = 1;       }     }     printf( %d n , out.size());     for (pair<pair<int, int>, int> tmp : out) {       printf( %d %d %d n , tmp.first.first, tmp.first.second, tmp.second);     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     queue<int> left;     queue<int> right;     int n;     cin >> n;     char x;     for (int i = 0; i < n; ++i) {       cin >> x;       if (x ==  D )         left.push(i);       else         right.push(i);     }     while (!left.empty() && !right.empty()) {       if (left.front() < right.front())         left.push(left.front() + n);       else         right.push(right.front() + n);       right.pop();       left.pop();     }     if (left.empty())       cout <<  R ;     else       cout <<  D ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int a, b, cnt = 0, sum = 0, i, j, hand, flag = 0, c, n, m, k, t, res,               maxy = 0, miny = 12345678910;     cin >> n;     string str;     getline(cin, str);     int len = str.size();     if (str[len - 1] ==  k ) {       if (n == 5 || n == 6)         printf( 53 n );       else         printf( 52 );     } else if (str[len - 1] ==  h ) {       if (n == 30)         printf( 11 );       else if (n < 30)         printf( 12 );       else         printf( 7 );     }   }
#include <bits/stdc++.h>   const long long INF = LLONG_MAX;   const long long NINF = LLONG_MIN;   const long long MAX = 1e6 + 5;   const long long MOD = 1e9 + 7;   using namespace std;   inline long long gcd(long long a, long long b) {     long long t;     if (a < b) {       t = a;       a = b;       b = t;     }     while (b != 0) {       t = a;       a = b;       b = t % b;     }     return a;   }   inline long long mpow(long long a, long long b) {     long long ans = 1;     while (b != 0) {       if (b & 1) {         ans = ans * a;       }       a = a * a;       b >>= 1;     }     return ans;   }   inline long long mlog2(long long n) {     long long c = 0;     c += 64 - __builtin_clzll(n);     if (__builtin_popcountll(n) == 1) {       c--;     }     return c;   }   void troll() {     long long qwe[100000];     for (long long i = 0; i < 1; i++)       ;   }   long long ass[MAX];   long long ssa[MAX];   int main() {     troll();     string str1, str2;     cin >> str1 >> str2;     long long count = 0;     for (long long i = 0; i < str1.size();) {       long long flag = 1;       if (str1[i] == str2[0]) {         long long j = 1;         for (j = 1; j < str2.size(); j++) {           if (str2[j] != str1[i + j]) {             flag = 0;             break;           }         }         if (!flag) {           flag = 1;           i++;         } else {           i += j;           count++;         }       } else {         i++;       }     }     troll();     cout << count <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     long long t, w, b;     cin >> t >> w >> b;     long long cas = t / (w / gcd(w, b)) / b;     long long exa = t - w / gcd(w, b) * b * cas;     long long minimum = min(w, b);     long long res = minimum * cas + min(minimum, exa + 1) - 1;     long long divition = gcd(res, t);     res /= divition;     t /= divition;     cout << res <<  /  << t << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn(5e5 + 5);   const long long inf(1e18);   struct Qry {     int l, r, id;   };   int n, q, dfn[maxn], idx, ed[maxn];   long long mn[maxn << 2], tag[maxn << 2], ans[maxn];   vector<pair<int, int> > edge[maxn];   vector<Qry> qry[maxn];   void Update(int x, int l, int r, int p, long long v) {     if (l == r)       mn[x] = v + tag[x];     else {       int mid = (l + r) >> 1;       p <= mid ? Update(x << 1, l, mid, p, v)                : Update(x << 1 | 1, mid + 1, r, p, v);       mn[x] = min(mn[x << 1], mn[x << 1 | 1]) + tag[x];     }   }   void Modify(int x, int l, int r, int ql, int qr, long long v) {     if (ql <= l && qr >= r)       tag[x] += v, mn[x] += v;     else {       int mid = (l + r) >> 1;       if (ql <= mid) Modify(x << 1, l, mid, ql, qr, v);       if (qr > mid) Modify(x << 1 | 1, mid + 1, r, ql, qr, v);       mn[x] = min(mn[x << 1], mn[x << 1 | 1]) + tag[x];     }   }   long long Query(int x, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) return mn[x];     int mid = (l + r) >> 1;     long long ret = inf;     if (ql <= mid) ret = Query(x << 1, l, mid, ql, qr);     if (qr > mid) ret = min(ret, Query(x << 1 | 1, mid + 1, r, ql, qr));     return ret + tag[x];   }   void Dfs1(int u, long long d) {     dfn[u] = ++idx;     if (!edge[u].size()) Update(1, 1, n, idx, d);     for (auto v : edge[u]) Dfs1(v.first, d + v.second);     ed[u] = idx;   }   void Dfs2(int u) {     for (auto ques : qry[u]) ans[ques.id] = Query(1, 1, n, ques.l, ques.r);     for (auto v : edge[u]) {       Modify(1, 1, n, 1, n, v.second);       Modify(1, 1, n, dfn[v.first], ed[v.first], -(v.second << 1));       Dfs2(v.first);       Modify(1, 1, n, dfn[v.first], ed[v.first], v.second << 1);       Modify(1, 1, n, 1, n, -v.second);     }   }   int main() {     memset(mn, 63, sizeof(mn));     int p, w, i, l, r;     scanf( %d%d , &n, &q);     for (i = 2; i <= n; ++i) {       scanf( %d%d , &p, &w);       edge[p].push_back(make_pair(i, w));     }     for (i = 1; i <= q; ++i) {       scanf( %d%d%d , &p, &l, &r);       qry[p].push_back((Qry){l, r, i});     }     Dfs1(1, 0), Dfs2(1);     for (i = 1; i <= q; ++i) printf( %lld n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long int dp[100000 + 5] = {0};   void fun(long long int *A, long long int N) {     dp[0] = 0;     long long int a = 0;     for (long long int i = 1; i <= 100000; ++i) {       while (a < N and A[a] <= i) ++a;       dp[i] = a;     }   }   void solve() {     long long int N;     cin >> N;     long long int A[N];     for (long long int i = 0; i < N; ++i) cin >> A[i];     sort(A, A + N);     fun(A, N);     long long int Q;     cin >> Q;     while (Q--) {       long long int M;       cin >> M;       if (M > 100000)         cout << N <<   n ;       else         cout << dp[M] <<   n ;     }   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T = 1;     while (T--) {       solve();     }     exit(0);   }
#include <bits/stdc++.h>   const int maxn = 105;   int a[maxn];   inline int max(int a, int b) { return a > b ? a : b; }   int main() {     int n, ans = 0, temp;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (n < 3 || n % 2 == 0)       puts( -1 );     else {       for (int i = (n - 1); i >= 1; i -= 2) {         temp = max(a[i], a[i + 1]);         ans += temp;         a[i / 2] -= temp;         if (a[i / 2] < 0) a[i / 2] = 0;       }       ans += a[1];       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool a[200087];   int main(void) {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       a[temp + 100000] = true;     }     int ans = 0;     for (int i = 0; i <= 200000; i++) {       if (i != 100000 && a[i] == true) {         ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, l, r;   int ans[1000000 + 5];   long long mmod = 2333, mod = 1e9 + 7;   long long shash[1000000 + 5], base[1000000 + 5];   char s[1000000 + 5];   int main() {     scanf( %d%s , &n, s + 1);     base[0] = 1;     for (int i = 1; i <= n; i++) {       shash[i] = (shash[i - 1] * mmod + s[i] -  a  + 1) % mod;       base[i] = base[i - 1] * mmod % mod;     }     if (n % 2 == 1) {       ans[(n + 1) / 2] = -1;       l = r = (n + 1) / 2;     } else {       l = n / 2;       r = n / 2 + 1;       if (s[l] == s[r])         ans[n / 2] = 1;       else         ans[n / 2] = -1;     }     for (int i = (n + 1) / 2 - 1; i >= 1; i--) {       l--;       r++;       for (int j = ans[i + 1] + 2; j >= 1; j -= 2) {         long long a =             (shash[l + j - 1] - shash[l - 1] * base[j] % mod + mod) % mod;         long long b = (shash[r] - shash[r - j] * base[j] % mod + mod) % mod;         if (a == b) {           ans[i] = j;           break;         }       }       if (ans[i] == 0) ans[i] = -1;     }     for (int i = 1; i < (n + 1) / 2; i++) printf( %d  , ans[i]);     printf( %d , ans[(n + 1) / 2]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mat[6][7] = {       {0, 0, 0, 1, 1, 1, 1}, {0, 1, 1, 0, 0, 1, 1}, {1, 0, 1, 0, 1, 0, 1},       {0, 1, 1, 1, 1, 0, 0}, {1, 0, 1, 1, 0, 1, 0}, {1, 1, 0, 0, 1, 1, 0},   };   int aux[6][7];   int res[7];   bool solve() {     int p, div;     for (int i = 0; i < 6; ++i) {       p = i;       for (int j = i + 1; j < 6; ++j)         if (abs(aux[j][i]) > abs(aux[p][i])) p = j;       for (int j = 0; j <= 6; ++j) swap(aux[i][j], aux[p][j]);       div = aux[i][i];       for (int k = i; k <= 6; ++k) {         if (aux[i][k] % div != 0) return 0;         aux[i][k] /= div;       }       for (int j = i + 1; j < 6; ++j) {         div = aux[j][i];         for (int k = i; k <= 6; ++k) aux[j][k] -= div * aux[i][k];       }     }     for (int i = 6 - 1; i >= 0; --i) {       res[i] = aux[i][6];       for (int k = 6 - 1; k > i; --k) res[i] -= res[k] * aux[i][k];     }     return 1;   }   int main() {     int big = 0;     for (int i = 0; i < 6; ++i)       scanf( %d , &mat[i][6]), big = max(big, mat[i][6]);     bool g = 0;     for (int i = 0; i <= big && !g; ++i) {       memcpy(aux, mat, sizeof aux);       for (int j = 0; j < 3; ++j) aux[j][6] -= i;       g = solve();       for (int j = 0; j < 6 && g; ++j)         if (res[j] < 0) g = 0;       res[6] = i;       int a = 0;       for (int i = 0; i < 7; ++i) a += res[i];       if (!g) continue;       printf( %d n , a);       for (int j = 3; j >= 0; --j) {         for (int i = 0; i < 7; ++i) {           char b =  a ;           if ((i + 1) & 1 << j) b =  b ;           for (int k = 0; k < res[i]; ++k) printf( %c , b);         }         printf(  n );       }     }     if (!g) printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 150004;   const long long mod = 998244353;   struct edge {     long long next, to;   } h[MAX << 1];   long long head[MAX], cnt, cnt_dfsn;   long long n, q, ans, inv;   inline void add(long long x, long long y) {     h[++cnt] = edge{head[x], y};     head[x] = cnt;     h[++cnt] = edge{head[y], x};     head[y] = cnt;   }   long long dfsn[MAX], size[MAX], son[MAX], fa[MAX], top[MAX], w[MAX];   long long tree[MAX];   inline long long lowbit(long long x) { return x & (-x); }   inline void ad(long long x, long long y) {     y %= mod;     for (long long i = x; i <= n; i += lowbit(i)) tree[i] = (tree[i] + y) % mod;   }   inline long long sum(long long x) {     long long ret = 0;     for (long long i = x; i; i -= lowbit(i)) ret = (ret + tree[i]) % mod;     return ret;   }   inline long long quick(long long x, long long y) {     long long ret = 1ll;     while (y) {       if (y & 1) ret = (ret * x) % mod;       y >>= 1;       x = (x * x) % mod;     }     return ret;   }   void dfs1(long long now, long long father) {     fa[now] = father;     size[now] = 1;     for (long long i = head[now]; i; i = h[i].next) {       long long aim = h[i].to;       if (aim != father) {         dfs1(aim, now);         size[now] += size[aim];         if (size[aim] > size[son[now]]) son[now] = aim;       }     }   }   void dfs2(long long now, long long start) {     top[now] = start;     dfsn[now] = ++cnt_dfsn;     if (son[now]) dfs2(son[now], start);     for (long long i = head[now]; i; i = h[i].next) {       long long aim = h[i].to;       if (aim != fa[now] && aim != son[now]) {         dfs2(aim, aim);       }     }   }   signed main() {     scanf( %lld %lld , &n, &q);     inv = quick(n, mod - 2);     for (long long x, y, i = 1; i < n; i++) scanf( %lld %lld , &x, &y), add(x, y);     dfs1(1, 1), dfs2(1, 1);     fa[1] = 0;     for (long long op, x, y, i = 1; i <= q; i++) {       scanf( %lld , &op);       if (op == 1) {         scanf( %lld %lld , &x, &y);         w[x] = (w[x] + y) % mod;         ad(1, size[x] * y % mod);         ad(dfsn[x], (mod - size[x] * y % mod) % mod),             ad(dfsn[x] + size[x], size[x] * y % mod);         if (son[x])           ad(dfsn[son[x]], (n - size[son[x]]) * y % mod),               ad(dfsn[son[x]] + size[son[x]], mod - (n - size[son[x]]) * y % mod);       } else {         scanf( %lld , &x);         ans = (sum(dfsn[x]) + n * w[x] % mod) % mod;         for (long long j = top[x]; fa[j]; j = top[fa[j]])           ans = (ans + (n - size[j]) * w[fa[j]] % mod) % mod;         printf( %lld n , (ans * inv) % mod);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int limit = 1000005;   void die() {     cout <<  NO  << endl;     exit(0);   }   void computereachable(int u, int code, vector<int> g[limit],                         int reachable[limit]) {     if (reachable[u] & code) return;     reachable[u] |= code;     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++)       computereachable(ar[i], code, g, reachable);   }   int n, m;   vector<int> g[limit], ginv[limit];   int reachdir[limit];   int reachinv[limit];   int nsink;   int nsour;   int listsour[limit];   int norder;   int order[limit];   int seen[limit];   void generatepostorder(int u) {     if (seen[u]) return;     seen[u] = 1;     vector<int> &ar = ginv[u];     for (int i = 0; i < int(ar.size()); i++) generatepostorder(ar[i]);     order[norder++] = u;   }   void traverse(int u) {     if (seen[u]) return;     seen[u] = 1;     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++) traverse(ar[i]);   }   void checkalreadystrong() {     for (int u = 1; u <= n; u++) generatepostorder(u);     reverse(order, order + norder);     for (int u = 1; u <= n; u++) seen[u] = 0;     traverse(order[0]);     for (int u = 1; u <= n; u++)       if (not seen[u]) die();     cout <<  YES  << endl;     exit(0);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       ginv[v].push_back(u);     }     for (int u = 1; u <= n; u++) {       if (int(g[u].size()) == 0) {         computereachable(u, 1 << (nsink++), ginv, reachinv);       }       if (int(ginv[u].size()) == 0) {         computereachable(u, 1, g, reachdir);         listsour[nsour++] = u;       }     }     if (nsour == 0) checkalreadystrong();     for (int u = 1; u <= n; u++)       if (not reachdir[u] or not reachinv[u]) die();     for (int c = 1; c < (1 << nsour) - 1; c++) {       int creach = 0;       for (int b = 0; b < nsour; b++)         if (c & (1 << b)) creach |= reachinv[listsour[b]];       if (__builtin_popcount(creach) <= __builtin_popcount(c)) die();     }     cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, len, wmax, ans;   vector<long long> vec[2];   inline void _read(long long &x) {     long long f = 1;     x = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - )         f = -1;       else         f = 1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;     return;   }   inline void _print(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x >= 10) _print(x / 10);     putchar(x % 10 +  0 );     return;   }   inline long long chk(long long x1, long long x2) {     long long x = x1 + x2, y = x2 - x1;     return y * wmax > x && y * wmax > -x;   }   int main() {     _read(n);     _read(len);     _read(wmax);     long long x, v;     for (long long i = 1; i <= n; i++) {       _read(x);       _read(v);       if (v == -1)         vec[0].push_back(x);       else         vec[1].push_back(x);     }     sort(vec[0].begin(), vec[0].end());     if (!vec[0].size()) {       _print(0);       return 0;     }     long long l, r, mid;     for (long long i = 0; i < vec[1].size(); i++) {       l = 0;       r = vec[0].size();       while (l < r) {         mid = (l + r) >> 1;         if (chk(vec[1][i], vec[0][mid] + len))           r = mid;         else           l = mid + 1;       }       ans += (vec[0].size() - r);     }     _print(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3010;   bool visit[maxn];   int n, m, ans, f[maxn];   vector<int> ve;   vector<pair<int, int> > maps[maxn];   void first_dfs(const int u) {     visit[u] = 1;     for (int i = 0; i < ((int)(maps[u]).size()); ++i) {       int v = maps[u][i].first;       int w = maps[u][i].second;       if (!visit[v]) {         first_dfs(v);         f[u] += f[v] + w;       }     }   }   void second_dfs(const int u) {     visit[u] = 1;     for (int i = 0; i < ((int)(maps[u]).size()); ++i) {       int v = maps[u][i].first;       int w = maps[u][i].second;       if (!visit[v]) {         f[v] = f[u] + (w ? -1 : 1);         m = min(m, f[v]);         second_dfs(v);       }     }   }   void solve(const int u) {     first_dfs(u);     ans = min(ans, f[u]);     if (((int)(maps[u]).size()) >= 2) {       ve.clear();       memset(visit, 0, sizeof(visit));       visit[u] = 1;       for (int i = 0; i < ((int)(maps[u]).size()); ++i) {         int v = maps[u][i].first;         int w = maps[u][i].second;         m = f[v];         second_dfs(v);         ve.push_back(m + (w ? -1 : 1) - f[v]);       }       sort(ve.begin(), ve.end());       ans = min(ans, f[u] + ve[0] + ve[1]);     }   }   int main() {     scanf( %d , &n);     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       maps[u].push_back(make_pair(v, 0));       maps[v].push_back(make_pair(u, 1));     }     ans = maxn;     for (int i = 1; i <= n; ++i) {       memset(f, 0, sizeof(f));       memset(visit, 0, sizeof(visit));       solve(i);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int check(int m, int k, string s) {     int i;     for (i = m + 1; i <= m + k && i < s.size(); i++) {       if (s[i] ==  1 ) return i;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t > 0) {       int i = 0, n, k, m, s = 0;       string a;       cin >> n >> k >> a;       for (i = 0; i < n;) {         int temp = check(i, k, a);         if (temp == -1) {           if (a[i] ==  0 ) {             s++;           }           i += (k + 1);         } else           i = temp;       }       cout << s << endl;       t--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   bool ans[50000][4];   int main() {     cin >> t;     for (int i = 0; i < t; i++) {       int toys[4];       for (int j = 0; j < 4; j++) {         cin >> toys[j];       }       bool neg = (toys[0] + toys[1]) % 2 == 1;       bool small = toys[1] >= 1 || toys[2] >= 1;       bool big = toys[0] >= 1 || toys[3] >= 1;       if (neg) {         if (small) {           ans[i][1] = true;         }         if (big) {           ans[i][0] = true;         }       } else {         if (small) {           ans[i][2] = true;         }         if (big) {           ans[i][3] = true;         }       }     }     for (int i = 0; i < t; i++) {       for (int j = 0; j < 4; j++) {         if (j != 0) {           cout <<    ;         }         if (ans[i][j]) {           cout <<  Ya ;         } else {           cout <<  Tidak ;         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 12005, inf = 2e9;   int n, q, a, b, k, m;   double x[N], y[N], ans[N], p[N], t, s;   int main() {     scanf( %d%d%d%d , &n, &q, &a, &b);     for (int i = 1; i <= n; i++) scanf( %lf , &p[i]);     x[m] = 1, y[m] = 2.0 * (1 - p[1]), m++;     x[m] = inf, y[m] = 2.0 * (inf - p[1]), m++;     t = x[0] - y[0] / (y[1] - y[0]) * (x[1] - x[0]);     ans[1] = t;     for (int i = 2; i <= n; i++) {       for (int j = m - 1; j > k; j--) x[j + 2] = x[j], y[j + 2] = y[j];       m += 2;       x[k + 1] = t, y[k + 1] = 0;       x[k + 2] = t, y[k + 2] = 0;       k++;       for (int j = 0; j <= k; j++) x[j] += a;       for (int j = k + 1; j < m; j++) x[j] += b;       for (int j = 0; j < m; j++) y[j] += 2 * (x[j] - p[i]);       if (y[0] >= 0) {         k = -1;         t = x[0];       } else {         for (k = 0; k < m; k++)           if (y[k] <= 0 && y[k + 1] > 0) break;         t = x[k] - y[k] / (y[k + 1] - y[k]) * (x[k + 1] - x[k]);       }       ans[i] = t;     }     ans[n] = min(ans[n], 1.0 * q);     for (int i = n; i >= 2; i--)       ans[i - 1] = min(ans[i] - a, max(ans[i - 1], ans[i] - b));     for (int i = 1; i <= n; i++) {       printf( %.6lf  , ans[i]);       s += (ans[i] - p[i]) * (ans[i] - p[i]);     }     printf(  n%.6lf n , s);     return 0;   }