malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   long long n, m, a[200010], dp[200010][2];   vector<pair<long long, long long> > allseg, okseg;   vector<long long> hvseg[200010];   void solve() {     long long i, j, l, r, mn, dx, dy;     scanf( %lld%lld , &n, &m);     a[0] = -1000000000000;     a[n + 1] = 1000000000000;     hvseg[0].clear();     for (i = 1; i <= n; i++) {       hvseg[i].clear();       scanf( %lld , &a[i]);     }     hvseg[n + 1].clear();     sort(a, a + n + 2);     allseg.clear();     for (i = 0; i < m; i++) {       scanf( %lld%lld , &l, &r);       allseg.push_back(make_pair(l, r));     }     sort(allseg.begin(), allseg.end());     okseg.clear();     mn = 1000000000000;     for (i = allseg.size() - 1; i >= 0; i--) {       if (allseg[i].second >= mn) {         continue;       }       mn = min(mn, allseg[i].second);       l = lower_bound(a, a + n + 2, allseg[i].first) - a;       r = upper_bound(a, a + n + 2, allseg[i].second) - a - 1;       if (l <= r) {         continue;       }       hvseg[r].push_back(okseg.size());       okseg.push_back(allseg[i]);     }     reverse(okseg.begin(), okseg.end());     for (i = 0; i <= n + 1; i++) {       for (j = 0; j < hvseg[i].size(); j++) {         hvseg[i][j] = okseg.size() - hvseg[i][j] - 1;       }       reverse(hvseg[i].begin(), hvseg[i].end());     }     for (i = 0; i <= n + 1; i++) {       dp[i][0] = dp[i][1] = 1000000000000;     }     dp[0][0] = dp[0][1] = 0;     for (i = 1; i <= n + 1; i++) {       for (dx = 0; dx < 2; dx++) {         if (dp[i - 1][dx] >= 1000000000000) {           continue;         }         for (dy = 0; dy < 2; dy++) {           if (hvseg[i - 1].size() == 0) {             dp[i][dy] = min(dp[i][dy], dp[i - 1][dx]);             continue;           }           dp[i][dy] = min(               dp[i][dy],               dp[i - 1][dx] +                   (dx + 1) * (okseg[hvseg[i - 1][hvseg[i - 1].size() - 1]].first -                               a[i - 1]));           dp[i][dy] = min(               dp[i][dy],               dp[i - 1][dx] + (2 - dy) * (a[i] - okseg[hvseg[i - 1][0]].second));           for (j = 0; j + 1 < hvseg[i - 1].size(); j++) {             dp[i][dy] =                 min(dp[i][dy],                     dp[i - 1][dx] +                         (dx + 1) * (okseg[hvseg[i - 1][j]].first - a[i - 1]) +                         (2 - dy) * (a[i] - okseg[hvseg[i - 1][j + 1]].second));           }         }       }     }     printf( %lld n , min(dp[n + 1][0], dp[n + 1][1]));     return;   }   int main() {     long long T;     scanf( %lld , &T);     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 53;   const int maxm = 23;   int n, m;   char s[maxn][maxm];   double dp[1 << 20];   long long f[1 << 20];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     m = strlen(s[1]);     memset(f, 0, sizeof(f));     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int same = 0;         for (int k = 0; k < m; k++) {           if (s[i][k] == s[j][k]) same |= (1 << k);         }         f[same] |= (1LL << j) | (1LL << i);       }     }     for (int same = (1 << m) - 1; same >= 0; same--) {       for (int i = 0; i < m; i++) {         if (same & (1 << i)) f[same ^ (1 << i)] |= f[same];       }     }     double ans = 0;     memset(dp, 0, sizeof(dp));     dp[0] = 1;     for (int sta = 0; sta < (1 << m); sta++) {       int cnt = 0;       for (int i = 0; i < m; i++)         if (sta & (1 << i)) cnt++;       for (int i = 0; i < m; i++) {         if (sta & (1 << i)) continue;         dp[sta | (1 << i)] += dp[sta] / (m - cnt);       }       for (int i = 0; i < n; i++) {         if (f[sta] & (1LL << i)) ans += dp[sta];       }     }     printf( %.10f n , ans / n);   }
#include <bits/stdc++.h>   using namespace std;   int n;   int x[20005], y[20005], c[20005], ans[20005], LOC;   bool cmp(const int &u, const int &v) {     return (x[u] - x[LOC]) * (y[v] - y[LOC]) - (y[u] - y[LOC]) * (x[v] - x[LOC]) <            0;   }   void solve(int l, int r) {     if (l > r) return;     int loc = l;     for (int i = (l), LIM = (r); i <= LIM; i++)       if (x[c[i]] < x[c[loc]]) loc = i;     swap(c[loc], c[l]);     LOC = c[l];     sort(c + l + 1, c + r + 1, cmp);     int s0 = 0, s1 = 0, k = -100000;     for (int i = (l + 1), LIM = (r); i <= LIM; i++) {       if (s0 == s1 && ((c[i] <= n) ^ (c[l] <= n))) {         if (k == -100000 || max(k - l - 1, r - k) > max(i - l - 1, r - i)) k = i;       }       if (c[i] <= n)         s0++;       else         s1++;     }     ans[c[l]] = c[k], ans[c[k]] = c[l];     solve(l + 1, k - 1), solve(k + 1, r);   }   int main() {     scanf( %d , &n);     for (int i = (1), LIM = (2 * n); i <= LIM; i++)       scanf( %d%d , &x[i], &y[i]), c[i] = i;     solve(1, 2 * n);     for (int i = (1), LIM = (n); i <= LIM; i++) printf( %d n , ans[i] - n);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   const int MOD = 1e9 + 7;   int m, d, L;   int bit[2001];   long long dp[2001][2001];   void add(long long &x, long long y) { x = (x + y) % MOD; }   long long DFS(int pos, int preyu, bool yes) {     if (pos == L) return preyu == 0;     if (!yes && dp[pos][preyu] != -1) return dp[pos][preyu];     long long ans = 0;     int End = yes ? bit[pos] : 9;     for (int i = 0; i <= End; i++) {       if (pos % 2 == 0 && i == d) continue;       if (pos % 2 == 1 && i != d) continue;       add(ans, DFS(pos + 1, (preyu * 10 + i) % m, yes && i == End));     }     if (!yes) dp[pos][preyu] = ans;     return ans;   }   long long Count(string str) {     int len = str.size();     int cnt = 0;     for (int i = 0; i < len; i++) bit[i] = str[i] -  0 ;     return DFS(0, 0, 1);   }   bool judge(string str) {     int len = str.size();     int yu = 0;     for (int i = 0; i < len; i++) {       int v = str[i] -  0 ;       yu = yu * 10 + v;       yu %= m;       if ((i + 1) & 1 && v == d) return false;       if (i & 1 && v != d) return false;     }     return yu == 0;   }   int main() {     memset(dp, (-1), sizeof(dp));     cin >> m >> d;     string a, b;     cin >> a >> b;     L = a.size();     cout << (Count(b) - Count(a) + judge(a) + MOD) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using si = unordered_set<int>;   using vsi = vector<si>;   using vvi = vector<vi>;   using qi = queue<int>;   int n, k, r, s = -1;   vi d, depth;   vsi h;   vvi g;   bool dfs(int u, int p) {     if (p == -1 && (d[u] != 2 && d[u] != 3)) return 0;     if (p == -1 && d[u] == 3) {       if (r) return 0;       r = u + 1;       int c = 0;       for (int v : g[u]) {         if (depth[v] == depth[u] - 1)           s = v + 1;         else if (depth[v] == depth[u] - 2)           c++;       }       if (c != 2 || s == -1) return 0;     }     if (p >= 0 && d[u] == 4 && depth[u] > 1) {       if (r) return 0;       r = u + 1;     }     if (p >= 0 && d[u] == 2 && depth[u] > 1) return 0;     if (p >= 0 && d[u] == 2 && depth[u] == 1) {       if (r) return 0;       r = u + 1;     }     bool ok = 1;     for (int v : g[u])       if (v != p) {         if (r != u + 1 && depth[v] + 1 != depth[u]) ok = 0;         if (!dfs(v, u)) ok = 0;       }     return ok;   }   int main() {     int n, u, v;     cin >> n;     if (n == 2) {       cout <<  2 n1 2 n ;       return 0;     }     int k = 1;     for (int i = 0; i < n; i++) k *= 2;     k -= 2;     g = vvi(k), h = vsi(k);     for (int i = 0; i < k - 1; i++) {       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);       h[u].insert(v);       h[v].insert(u);     }     vi c(5);     d = vi(k), depth = vi(k);     qi q;     for (int i = 0; i < k; i++) {       d[i] = g[i].size();       if (d[i] >= 1 && d[i] <= 4)         c[d[i]]++;       else         c[0]++;       if (d[i] == 1) {         q.push(i);         depth[i] = 0;       }     }     int l = (k + 2) / 2;     if (c[0] || c[4] > 1 || (c[1] != l && c[1] != l - 1)) {       cout <<  0 n ;       return 0;     }     vi p(k, -1);     while (!q.empty()) {       int u = q.front();       q.pop();       if (h[u].empty()) continue;       int v = *h[u].begin();       p[u] = v;       depth[v] = max(depth[u], depth[u] + 1);       h[v].erase(u);       if (h[v].size() == 1) q.push(v);     }     int root = -1;     for (int i = 0; i < k; i++)       if (p[i] == -1) {         if (root == -1)           root = i;         else {           cout <<  0 n ;           return 0;         }       }     if (root == -1) {       cout <<  0 n ;       return 0;     }     if (dfs(root, -1)) {       if (s >= 0)         cout <<  2 n  << min(r, s) <<     << max(r, s) <<   n ;       else         cout <<  1 n  << r <<   n ;     } else       cout <<  0 n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 4e5;   long long fac[N];   long long qpow(long long x, long long y) {     long long res = 1;     for (; y; y >>= 1, x = x * x % mod)       if (y & 1) res = res * x % mod;     return res;   }   long long inv(long long x) { return qpow(x, mod - 2); }   long long C(long long x, long long y) {     return ((fac[x] * inv(fac[y]) % mod) * inv(fac[x - y])) % mod;   }   void build() {     fac[0] = 1;     for (long long i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod;   }   long long a[N];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     build();     long long n;     cin >> n;     for (long long i = 0; i < 2 * n; i++) cin >> a[i];     sort(a, a + 2 * n);     for (long long i = 0; i < 2 * n; i++) a[i] %= mod;     long long ans = 0;     for (long long i = 0; i < n; i++) ans = (ans + a[i + n] - a[i] + mod) % mod;     cout << ans * C(2 * n, n) % mod <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int used[1123], used1[1123];   char a[1123][1123];   int main() {     int n, m, i, j;     bool flag = 0;     cin >> n >> m;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     int ans = 0;     for (j = 1; j <= m; j++) {       flag = 0;       for (i = 2; i <= n; i++) {         if (used[i] == 0) {           if (a[i][j] < a[i - 1][j]) {             ans++;             flag = 1;             break;           } else if (a[i][j] > a[i - 1][j]) {             used1[i] = 1;           }         } else {           used1[i] = 1;         }       }       if (flag == 0) {         for (i = 2; i <= n; i++) {           used[i] = used1[i];         }       }       for (i = 2; i <= n; i++) {         used1[i] = 0;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> bitr;   void update(long long ind, long long val, long long n) {     long long i = ind + 1;     while (i <= n) {       bitr[i] += val;       i += i & (-i);     }   }   long long sum(long long ind) {     long long i = ind + 1;     long long ans = 0;     while (i > 0) {       ans += bitr[i];       i -= i & (-i);     }     return ans;   }   int main() {     long long n, q, i;     cin >> n >> q;     long long arr[n];     bitr.push_back(0);     for (i = 0; i < n; i++) {       cin >> arr[i];       bitr.push_back(0);     }     sort(arr, arr + n);     for (i = 0; i < q; i++) {       long long l, r;       cin >> l >> r;       l--;       r--;       update(l, 1, n);       update(r + 1, -1, n);     }     long long fact[n];     for (i = 0; i < n; i++) fact[i] = sum(i);     sort(fact, fact + n);     long long res = 0;     for (i = 0; i < n; i++) {       res += (fact[i] * arr[i]);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long long linf = 1ll * inf * inf;   const int N = 100000 + 7;   const int multipleTest = 0;   vector<pair<int, int> > adj[N];   int pa[N][20];   int depth[N];   int g[N];   int root[N];   int k = 0;   int n;   int low[N];   int high[N];   int rr = 0;   int curRoot;   void dfs(int u, int r) {     pa[u][0] = r;     low[u] = ++rr;     for (int j = 1; j < 20; ++j) {       if (pa[u][j - 1] == -1)         pa[u][j] = -1;       else         pa[u][j] = pa[pa[u][j - 1]][j - 1];     }     root[u] = curRoot;     for (pair<int, int> x : adj[u]) {       int v = x.first;       int c = x.second;       if (v != r) {         depth[v] = depth[u] + 1;         g[v] = g[u] + c;         dfs(v, u);       }     }     high[u] = rr;   }   bool isPa(int r, int u) { return low[r] <= low[u] && high[r] >= high[u]; }   int LCA(int u, int v) {     if (depth[u] < depth[v]) swap(u, v);     while (depth[u] > depth[v]) {       int k = log2(depth[u] - depth[v]);       u = pa[u][k];     }     if (u == v) return u;     for (int j = 19; j >= 0; --j) {       if (pa[u][j] != -1 && pa[v][j] != pa[u][j]) {         u = pa[u][j];         v = pa[v][j];       }     }     return pa[u][0];   }   void solve() {     cin >> n;     for (int i = (1), _b = (n + 1); i < _b; ++i) {       int u, c;       scanf( %d%d , &u, &c);       if (u != -1)         adj[u].push_back(make_pair(i, c));       else         pa[i][0] = -1;     }     for (int i = (1), _b = (n + 1); i < _b; ++i)       if (pa[i][0] == -1) {         curRoot = i;         dfs(i, -1);       }     int q;     cin >> q;     while (q-- > 0) {       int op, u, v;       scanf( %d%d%d , &op, &u, &v);       if (root[u] != root[v] || u == v) {         puts( NO );         continue;       }       if (op == 1) {         if (isPa(u, v) && g[v] - g[u] == 0)           puts( YES );         else           puts( NO );       } else {         int r = LCA(u, v);         if (r == u) {           if (g[v] - g[u] == depth[v] - depth[u])             puts( YES );           else             puts( NO );         } else if (r == v) {           puts( NO );         } else {           if (g[u] - g[r] == 0 && g[v] - g[r] == depth[v] - depth[r])             puts( YES );           else             puts( NO );         }       }     }   }   int main() {     int Test = 1;     if (multipleTest) {       cin >> Test;     }     for (int i = 0; i < Test; ++i) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m;     cin >> n >> m;     vector<vector<int> > file(n);     for (int i = (0); i < ((m)); ++i) {       int tmp;       cin >> tmp;       vector<int> f(tmp);       for (int j = (0); j < ((tmp)); ++j) cin >> f[j];       file.push_back(f);     }     vector<int> v;     for (int i = (0); i < ((file.size())); ++i)       for (int j = (0); j < ((file[i].size())); ++j) v.push_back(file[i][j]);     sort((v).begin(), (v).end());     int emp = v.size() + 1;     for (int i = (0); i < ((v.size())); ++i) {       if (i + 1 != v[i]) {         emp = i + 1;         break;       }     }     int index = 1;     vector<pair<int, int> > res;     for (int i = (0); i < ((file.size())); ++i) {       for (int j = (0); j < ((file[i].size())); ++j) {         for (int k = (0); k < ((file.size())); ++k) {           for (int l = (0); l < ((file[k].size())); ++l) {             if (file[k][l] == index) {               if (i != k || j != l) {                 int tmp;                 res.push_back(make_pair(file[k][l], emp));                 res.push_back(make_pair(file[i][j], index));                 tmp = file[k][l];                 file[k][l] = emp;                 emp = file[i][j];                 file[i][j] = tmp;               }               ++index;               goto NEXT;             }           }         }         res.push_back(make_pair(file[i][j], index));         emp = file[i][j];         file[i][j] = index;         ++index;       NEXT:;       }     }     cout << res.size() << endl;     for (int i = (0); i < ((res.size())); ++i)       cout << res[i].first <<     << res[i].second << endl;   }
#include <bits/stdc++.h>   using namespace std;      int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<int> x(n + m - 1);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int a;           cin >> a;           x[i + j] ^= a;         }       }       bool flag = false;       for (int i = 0; i < n + m - 1; i++) {         if (x[i] != 0) {           flag = true;           break;         }       }       cout << (flag ?  Ashish  :  Jeel ) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char getOtherValue(char val) {     if (val ==  . ) return  0 ;     if (val ==  1 ) return  0 ;     return  1 ;   }   int main() {     int n, p;     cin >> n >> p;     string str;     cin >> str;     bool ok = false;     for (int i = 0; i < n - p; ++i) {       if (str[i] ==  .  || str[i] != str[i + p]) {         ok = true;         if (str[i] ==  . ) {           str[i] = getOtherValue(str[i + p]);         }         if (str[i + p] ==  . ) {           str[i + p] = getOtherValue(str[i]);         }         break;       }     }     if (ok) {       for (int i = 0; i < n; ++i) {         if (str[i] ==  . ) {           str[i] =  0 ;         }       }       cout << str;       return 0;     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000009;   const int Max = 1000007;   const double PI = acos(-1.0);   double binSearch(double p, double b) {     int low = 0, high = INF, k;     double x;     while (low <= high) {       k = (low + high) / 2;       x = p / (2.0 * k);       if (x < b)         high = k - 1;       else if (x == b)         return x;       else         low = k + 1;     }     x = p / (2 * high);     if (x < b) x = p / (2 * low);     return x;   }   int main() {     int i, j, k, l, temp, t, n, m, caseno = 0, ans;     string str;     double a, b, x;     while (cin >> a >> b) {       if (b > a) {         cout << -1 << endl;         continue;       }       x = binSearch((a + b), b);       printf( %.10lf n , x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[10005];   long long a[100005], dis[10005];   int b[100005], vis[10005];   bool cmp(const int &first, const int &second) { return a[first] < a[second]; }   priority_queue<pair<long long, int> > T, Q;   int main() {     long long h;     int n, m, p;     scanf( %I64d%d%d%d , &h, &n, &m, &p);     for (int i = 0; i < p; i++) dis[i] = h + 1;     dis[1] = 1;     for (int i = 1; i <= n; i++) {       scanf( %I64d%d , &a[i], &b[i]);       if (a[i] % p == 1 % p)         T.push(pair<long long, int>(b[i], -i));       else         v[a[i] % p].push_back(i);     }     for (int i = 0; i < p; i++) sort(v[i].begin(), v[i].end(), cmp);     for (int i = 1, ch; i <= m; i++) {       scanf( %d , &ch);       if (ch == 1) {         long long first;         scanf( %I64d , &first);         for (int j = 0; j < p; j++) Q.push(pair<long long, int>(-dis[j], j));         for (; !Q.empty();) {           pair<long long, int> t = Q.top();           Q.pop();           if (vis[t.second] == i) continue;           vis[t.second] = i;           int q = (t.second + first) % p;           if (first - t.first < dis[q])             dis[q] = first - t.first,             Q.push(pair<long long, int>(t.first - first, q));         }         for (int j = 0; j < p; j++)           while (!v[j].empty() && a[v[j][v[j].size() - 1]] >= dis[j])             T.push(pair<long long, int>(b[v[j][v[j].size() - 1]],                                         -v[j][v[j].size() - 1])),                 v[j].resize(v[j].size() - 1);       }       if (ch == 2) {         int first, second;         scanf( %d%d , &first, &second);         b[first] -= second;       }       if (ch == 3) {         pair<long long, int> t;       retry:         if (!T.empty())           t = T.top(), T.pop();         else           t = pair<long long, int>(0, -n - 1);         if (t.first != b[-t.second]) {           T.push(pair<long long, int>(b[-t.second], t.second));           goto retry;         }         b[-t.second] = 0;         printf( %d n , t.first);       }     }   }
#include <bits/stdc++.h>   using namespace std;   char str[1010000];   int b[1010000];   int a[1010000];   int bb[1010000];   int main() {     int n;     int flag = 1;     scanf( %d , &n);     scanf( %s , str);     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);     }     int coutt1 = 0;     for (int i = 0; i <= n - 1; i++) {       if (str[i] ==  R ) {         coutt1++;         a[coutt1] = b[i + 1];       }     }     int coutt2 = 0;     for (int i = 0; i <= n - 1; i++) {       if (str[i] ==  L ) {         coutt2++;         bb[coutt2] = b[i + 1];       }     }     int ans = 1000000005;     int i, j;     for (i = 1, j = 1; i <= coutt1 && j <= coutt2;) {       if (a[i] < bb[j]) {         flag = 0;         ans = min((bb[j] - a[i]) / 2, ans);         i++;       } else {         j++;       }     }     if (flag)       printf( -1 );     else       printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<double, double> > vec;   double x[10], y[10];   int cross(pair<double, double> a, pair<double, double> b,             pair<double, double> c) {     double re = (a.first - c.first) * (b.second - c.second);     re -= (a.second - c.second) * (b.first - c.first);     if (fabs(re) < 1e-8) return 0;     return re > 0 ? 1 : -1;   }   bool work() {     double x0, y0, d, xb, yb, xc, yc, xa, ya, xd, yd;     int i;     x0 = x[1] * 2 - x[2];     y0 = y[1] * 2 - y[2];     d = x0 * (y[1] - y[3]) + x[1] * (y[3] - y0) + x[3] * (y0 - y[1]);     d *= 2;     xb = (x0 * x0 + y0 * y0) * (y[1] - y[3]);     xb += (x[1] * x[1] + y[1] * y[1]) * (y[3] - y0);     xb += (x[3] * x[3] + y[3] * y[3]) * (y0 - y[1]);     xb /= d;     yb = (x0 * x0 + y0 * y0) * (x[3] - x[1]);     yb += (x[1] * x[1] + y[1] * y[1]) * (x0 - x[3]);     yb += (x[3] * x[3] + y[3] * y[3]) * (x[1] - x0);     yb /= d;     xc = 2 * x[1] - xb;     yc = 2 * y[1] - yb;     xa = 2 * x[3] - xb;     ya = 2 * y[3] - yb;     xd = 2 * x[2] - xc;     yd = 2 * y[2] - yc;     vec.clear();     vec.push_back(make_pair(xa, ya));     vec.push_back(make_pair(xd, yd));     vec.push_back(make_pair(xc, yc));     vec.push_back(make_pair(xb, yb));     for (i = 0; i < 4; i++)       if (cross(vec[i], vec[(i + 1) % 4], vec[(i + 2) % 4]) *               cross(vec[i], vec[(i + 1) % 4], vec[(i + 3) % 4]) <=           0)         return false;     printf( YES n );     for (i = 0; i < 4; i++) printf( %.10f %.10f  , vec[i].first, vec[i].second);     printf(  n );     return true;   }   int main() {     int T, i;     scanf( %d , &T);     while (T--) {       for (i = 1; i <= 3; i++) scanf( %lf%lf , &x[i], &y[i]);       if ((x[1] - x[3]) * (y[2] - y[3]) == (y[1] - y[3]) * (x[2] - x[3])) {         printf( NO n n );         continue;       }       if (work()) continue;       swap(x[1], x[2]);       swap(y[1], y[2]);       if (work()) continue;       swap(x[1], x[3]);       swap(y[1], y[3]);       if (work()) continue;       printf( NO n n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     v.insert(v.begin(), 0);     for (int i = 1; i <= n; i++) {       v[i] += v[i - 1];     }     int ans = 0;     int l, r;     cin >> l >> r;     if (l > r) swap(l, r);     ans = v[r - 1] - v[l - 1];     ans = min(ans, v[n] - ans);     cout << ans << endl;     return 0;   }