malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   double mas[10000][3];   void optim(int cnt, double Px, double Py, double Pz, double vs, double vp) {     double l = 0, r = 0;     double x1 = mas[cnt][0];     double y1 = mas[cnt][1];     double z1 = mas[cnt][2];     double x2 = mas[cnt + 1][0];     double y2 = mas[cnt + 1][1];     double z2 = mas[cnt + 1][2];     for (int i = 0; i < cnt; i++) {       l += sqrt((mas[i][0] - mas[i + 1][0]) * (mas[i][0] - mas[i + 1][0]) +                 (mas[i][1] - mas[i + 1][1]) * (mas[i][1] - mas[i + 1][1]) +                 (mas[i][2] - mas[i + 1][2]) * (mas[i][2] - mas[i + 1][2]));       r += sqrt((mas[i][0] - mas[i + 1][0]) * (mas[i][0] - mas[i + 1][0]) +                 (mas[i][1] - mas[i + 1][1]) * (mas[i][1] - mas[i + 1][1]) +                 (mas[i][2] - mas[i + 1][2]) * (mas[i][2] - mas[i + 1][2]));     }     int j = cnt;     r += sqrt((mas[j][0] - mas[j + 1][0]) * (mas[j][0] - mas[j + 1][0]) +               (mas[j][1] - mas[j + 1][1]) * (mas[j][1] - mas[j + 1][1]) +               (mas[j][2] - mas[j + 1][2]) * (mas[j][2] - mas[j + 1][2]));     l /= vs;     r /= vs;     while (r - l > 1E-12) {       double m = (r + l) / 2;       double xx = (x1 + x2) / 2, yy = (y1 + y2) / 2, zz = (z1 + z2) / 2;       double dist2 = sqrt((xx - Px) * (xx - Px) + (yy - Py) * (yy - Py) +                           (zz - Pz) * (zz - Pz));       double t2 = dist2 / vp;       if (t2 - m > 1E-10) {         l = m;         x1 = xx;         y1 = yy;         z1 = zz;       } else if (t2 - m < -1E-10) {         r = m;         x2 = xx;         y2 = yy;         z2 = zz;       } else {         l = m;         x1 = xx;         y1 = yy;         z1 = zz;         break;       }     }     printf( %.6lf n , l);     printf( %.6lf %.6lf %.6lf n , x1, y1, z1);   }   int main() {     int n;     cin >> n;     double vs, vp;     for (int i = 0; i <= n; i++) cin >> mas[i][0] >> mas[i][1] >> mas[i][2];     cin >> vp >> vs;     double Px, Py, Pz;     cin >> Px >> Py >> Pz;     bool f = false;     int cnt = 0;     double dist = 0;     if (fabs(Px - mas[0][0]) < 1E-7 && fabs(Py - mas[0][1]) < 1E-7 &&         fabs(Pz - mas[0][2]) < 1E-7) {       cout <<  YES  << endl;       printf( %.6lf n , 0.0);       printf( %.6lf %.6lf %.6lf n , Px, Py, Pz);       return 0;     }     for (int i = 0; i < n; i++) {       dist += sqrt((mas[i][0] - mas[i + 1][0]) * (mas[i][0] - mas[i + 1][0]) +                    (mas[i][1] - mas[i + 1][1]) * (mas[i][1] - mas[i + 1][1]) +                    (mas[i][2] - mas[i + 1][2]) * (mas[i][2] - mas[i + 1][2]));       double dist2 = sqrt((mas[i + 1][0] - Px) * (mas[i + 1][0] - Px) +                           (mas[i + 1][1] - Py) * (mas[i + 1][1] - Py) +                           (mas[i + 1][2] - Pz) * (mas[i + 1][2] - Pz));       double t1 = dist / vs;       double t2 = dist2 / vp;       if (t1 - t2 > -1E-14) {         cnt = i;         f = true;         break;       }     }     if (!f) {       cout <<  NO ;       return 0;     } else       cout <<  YES  << endl;     optim(cnt, Px, Py, Pz, vs, vp);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long MOD = 1e9 + 7;   struct {     int val, lazy;   } tree[4 * 1000010];   int bal(int p) { return tree[p].val + tree[p].lazy; }   void ins(int S, int val, int L = 1, int R = 1000000, int p = 1) {     if (S < L || R < 1) return;     if (1 <= L && R <= S) {       tree[p].lazy += val;       return;     }     tree[2 * p].lazy += tree[p].lazy;     tree[2 * p + 1].lazy += tree[p].lazy;     tree[p].lazy = 0;     int M = (L + R) / 2;     ins(S, val, L, M, 2 * p);     ins(S, val, M + 1, R, 2 * p + 1);     tree[p].val = max(bal(2 * p), bal(2 * p + 1));   }   int query(int L = 1, int R = 1000000, int p = 1) {     if (L == R) {       return bal(p) > 0 ? L : -1;     }     int M = (L + R) / 2;     tree[2 * p].lazy += tree[p].lazy;     tree[2 * p + 1].lazy += tree[p].lazy;     tree[p].val += tree[p].lazy;     tree[p].lazy = 0;     if (bal(2 * p + 1) > 0) return query(M + 1, R, 2 * p + 1);     return query(L, M, 2 * p);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<int> a[2];     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       a[0].push_back(x);       ins(x, 1);     }     for (int i = 0; i < m; ++i) {       int x;       scanf( %d , &x);       a[1].push_back(x);       ins(x, -1);     }     int q;     scanf( %d , &q);     while (q--) {       int idx, i, x;       scanf( %d%d%d , &idx, &i, &x);       --i;       --idx;       if (idx == 0) {         ins(a[idx][i], -1);         ins(x, 1);       } else {         ins(a[idx][i], 1);         ins(x, -1);       }       a[idx][i] = x;       printf( %d n , query());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int main() {     long long k;     long long now = 9;     long long last = 1;     cin >> k;     if (k <= 9) {       cout << k;       return 0;     }     long long finalk = k;     long long pow = 1;     for (int step = 1; step <= 15; step++) {       long long tmplast = last - 1;       if (k <= now) {         long long this_num = tmplast + (k / step);         bool OK = 1;         long long tmpnum = this_num;         for (int i = 1; i <= step; i++) {           if (tmpnum % 10 != 9) OK = false;           tmpnum /= 10;         }         if (OK) step++;         if (k % step) this_num += 1;         long long yiwei = (step - k % step);         if (yiwei == step) yiwei = 0;         for (int i = 1; i <= yiwei; i++) {           this_num /= 10;         }         printf( %d n , this_num % 10);         return 0;       }       k -= now;       pow *= 10;       now = 9 * pow;       now *= (step + 1);       last *= 10;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int m;   vector<vector<int>> row;   vector<vector<int>> col;   vector<string> g;   vector<vector<bool>> vis;   struct node {     int d;     int i;     int j;   };   struct NODE {     vector<int> e;     bool vis = false;   };   vector<NODE> G;   bool operator<(const node a, const node b) { return a.d > b.d; }   int dijk() {     priority_queue<pair<int, int>> q;     q.push({-1, n - 1});     pair<int, int> cur;     while (!q.empty()) {       cur = q.top();       q.pop();       if (!G[cur.second].vis) {         G[cur.second].vis = true;         if (cur.second == 0) {           return -cur.first - 1;         }         for (int i = 0; i < G[cur.second].e.size(); ++i) {           int nex = G[cur.second].e[i];           q.push({cur.first - 1, nex});         }       }     }     return -1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     g.resize(n);     row.resize(n);     col.resize(m);     string T1(n,  . );     string T2(m,  # );     vis.resize(n, (vector<bool>(m, false)));     G.resize(n + m);     for (int i = 0; i < n; ++i) {       cin >> g[i];     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (g[i][j] ==  # ) {           G[i].e.push_back(n + j);           G[n + j].e.push_back(i);         }       }     }     cout << dijk() <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int f[200005][3], ans, dep[200005];   int head[200005], cnt;   struct data {     int next, to;     data(int next = 0, int to = 0) : next(next), to(to) {}   } edge[200005 << 1];   int read() {     char c = getchar();     int x = 0;     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return x;   }   void connect(int u, int v) {     edge[++cnt] = data(head[u], v);     head[u] = cnt;   }   void DFS(int u, int pre) {     f[u][0] = 1;     dep[u] = dep[pre] + 1;     int mini = 0x3f3f3f3f;     for (int i = head[u]; i; i = edge[i].next) {       int v = edge[i].to;       if (v == pre) continue;       DFS(v, u);       f[u][0] = f[u][0] + min(min(f[v][0], f[v][1]), f[v][2]);       f[u][2] = f[u][2] + min(f[v][0], f[v][1]);       mini = min(mini, f[v][0] - min(f[v][0], f[v][1]));     }     f[u][1] = f[u][2] + mini;     if (dep[u] == 3) ans = ans + min(f[u][0], min(f[u][1], f[u][2]));   }   int main() {     n = read();     for (int i = 1; i < n; ++i) {       int u = read(), v = read();       connect(u, v);       connect(v, u);     }     DFS(1, 0);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> q;     vector<int> powers;     powers.reserve(10000);     for (int i = 0; i < (1 << 10); i++) {       long long tot = 0;       long long pow = 1;       for (int j = 0; j < 10; j++) {         if (i & (1 << j)) tot += pow;         pow *= 3;       }       powers.push_back(tot);     }     sort(powers.begin(), powers.end());     while (q--) {       int n;       cin >> n;       if (find(powers.begin(), powers.end(), n) == powers.end())         cout << *upper_bound(powers.begin(), powers.end(), n) <<   n ;       else         cout << n <<   n ;     }   }
#include<bits/stdc++.h>   #define ll long long   #define L(i, j, k) for(int i = (j); i <= (k); ++i)   #define R(i, j, k) for(int i = (j); i >= (k); --i)   #define vi vector < int >    #define sz(a) ((int) a.size())    using namespace std;   const int N = 1e6 + 7;   int T;      int n, m, c[N], a[N], b[N];    void Main () {    n = m = 0;    int x;    cin >> x;    L(i, 1, x) {     int w;     cin >> w;     c[i] = w;     if(i & 1) a[++n] = w;     else b[++m] = w;    }    sort(a + 1, a + n + 1);    sort(b + 1, b + m + 1);    sort(c + 1, c + x + 1);    n = 0, m = 0;    L(i, 1, x) {     if(i & 1) {      if(a[++n] != c[i]) return cout <<  NO n , void();     }     else {      if(b[++m] != c[i]) return cout <<  NO n , void();     }     }    cout <<  YES n ;   }   int main() {     ios::sync_with_stdio(false);    cin.tie(0); cout.tie(0);    cin >> T;    while (T--) Main();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BMOD(T p, T e, T m) {     T ret = 1;     while (e) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;       e >>= 1;     }     return (T)ret;   }   template <class T>   inline T MODINV(T a, T m) {     return BMOD(a, m - 2, m);   }   template <class T>   inline T isPrime(T a) {     for (T i = 2; i <= sqrt(double(a)); i++) {       if (a % i == 0) {         return 0;       }     }     return 1;   }   template <class T>   inline T lcm(T a, T b) {     return (a / __gcd(a, b)) * b;   }   template <class T>   inline T power(T a, T b) {     return (b == 0) ? 1 : a * power(a, b - 1);   }   template <class T>   inline string to_str(T t) {     stringstream ss;     ss << t;     return ss.str();   }   int main() {     int h, m;     scanf( %d:%d , &h, &m);     h %= 12;     double a = h * 30.0 + (m / 2.0);     double b = m * 6.0;     printf( %.10lf %.10lf n , a, b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long f[102][102];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i <= n; i++) f[0][i] = 1;     for (int j = 1; j <= n; j++)       for (int i = 1; i <= n; i++)         for (int k = 0; k < i; k++) f[i][j] += f[k][j - 1] * f[i - k - 1][j - 1];     printf( %lld , f[n][n] - f[n][m - 1]);   }
#include <bits/stdc++.h>   using namespace std;   int cnt[26];   void sol() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long k, x;       cin >> k >> x;       cout << (x + (k - 1) * 9) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) sol();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int ans = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         int inp;         cin >> inp;         if (i == j || i + j == n - 1 || i == n / 2 || j == n / 2) ans += inp;       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 1 << 19;   const int MOD = 1000000007;   int arr[MXN];   int suf[2 * MXN];   int pre[2 * MXN];   int lb[2 * MXN];   int rb[2 * MXN];   void build(int c, int l, int r) {     lb[c] = l;     rb[c] = r;     if (l == r) return;     int k = (l + r) / 2;     build(2 * c, l, k);     build(2 * c + 1, k + 1, r);   }   void updatesuf(int c, int idx, int amt) {     if (lb[c] == rb[c]) {       suf[c] += amt;       return;     }     int k = (lb[c] + rb[c]) / 2;     if (idx <= k)       updatesuf(2 * c, idx, amt);     else       updatesuf(2 * c + 1, idx, amt);     suf[c] = suf[2 * c] + suf[2 * c + 1];     suf[c] %= MOD;   }   void updatepre(int c, int idx, int amt) {     if (lb[c] == rb[c]) {       pre[c] += amt;       return;     }     int k = (lb[c] + rb[c]) / 2;     if (idx <= k)       updatepre(2 * c, idx, amt);     else       updatepre(2 * c + 1, idx, amt);     pre[c] = pre[2 * c] + pre[2 * c + 1];     pre[c] %= MOD;   }   int querysuf(int c, int l, int r) {     if (lb[c] == l && rb[c] == r) return suf[c];     int k = (lb[c] + rb[c]) / 2;     if (l <= k && k < r)       return (querysuf(2 * c, l, k) + querysuf(2 * c + 1, k + 1, r)) % MOD;     else if (r <= k)       return querysuf(2 * c, l, r);     else       return querysuf(2 * c + 1, l, r);   }   int querypre(int c, int l, int r) {     if (lb[c] == l && rb[c] == r) return pre[c];     int k = (lb[c] + rb[c]) / 2;     if (l <= k && k < r)       return (querypre(2 * c, l, k) + querypre(2 * c + 1, k + 1, r)) % MOD;     else if (r <= k)       return querypre(2 * c, l, r);     else       return querypre(2 * c + 1, l, r);   }   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int> > proc;     for (int i = 1; i <= n; i++) {       scanf( %d , arr + i);       proc.emplace_back(arr[i], i);     }     build(1, 0, MXN - 1);     sort(proc.begin(), proc.end());     int ans = 0;     for (auto p : proc) {       int x = p.first;       int idx = p.second;       int l = idx - 1;       int r = n - l - 1;       int a = querysuf(1, idx, n);       int b = querypre(1, 1, idx);       long long cur =           1ll * a * (l + 1) + 1ll * b * (r + 1) + 1ll * (l + 1) * (r + 1);       cur %= (long long)MOD;       cur *= (long long)x;       cur %= (long long)MOD;       ans += cur;       ans %= MOD;       updatesuf(1, idx, r + 1);       updatepre(1, idx, l + 1);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &x, T y) {     return x > y ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   inline void read(int &x) {     char ch = getchar();     int f = 1;     x = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   int n, m, p[100050], v[100050], nx[100050], pr[100050], id[100050];   set<pair<int, int> > se;   int get(int x, int y) {     if (x == y) return 1000000005;     int d = (p[y] - p[x] + m) % m;     if (x > y) d += v[y];     if (d <= v[x]) return 1;     if (v[x] <= v[y]) return 1000000005;     return (d - v[y] - 1) / (v[x] - v[y]) + 1;   }   bool cmp(int x, int y) { return p[x] < p[y]; }   int main() {     read(n), read(m);     for (register int i = 1; i <= n; ++i)       read(p[i]), --p[i], read(v[i]), id[i] = i;     sort(id + 1, id + n + 1, cmp);     for (register int i = 1; i <= n; ++i)       pr[id[i]] = id[i - 1], nx[id[i]] = id[i + 1];     nx[pr[id[1]] = id[n]] = id[1];     for (register int i = 1; i <= n; ++i) se.insert(make_pair(get(i, nx[i]), i));     while (1) {       set<pair<int, int> >::iterator it = se.begin();       if (it->first >= 1000000005) break;       int u = it->second, t = it->first;       se.erase(it);       se.erase(make_pair(get(pr[u], u), pr[u])),           se.erase(make_pair(get(nx[u], nx[nx[u]]), nx[u]));       pr[nx[u] = nx[nx[u]]] = u;       p[u] = (p[u] + t) % m, --v[u];       se.insert(make_pair(get(pr[u], u), pr[u])),           se.insert(make_pair(get(u, nx[u]), u));     }     printf( %d n , se.size());     for (auto v : se) printf( %d  , v.second);     puts(  );     return 0;   }
#include  bits/stdc++.h    using namespace std;   typedef long long ll;   typedef long double ld;   typedef unsigned long long ull;   #define int ll   #define sz(a) int(a.size())   #define dbg(a) cout << #a <<   =   << a << endl   #define dbg1(a) cout << #a <<   = [  ; for (auto& _ : a) cout << _ <<    ; cout <<  ]  << endl   #define dbg2(a) cout << #a <<   = [  ; for (auto& _ : a) cout <<  (  << _.first <<     << _.second <<  )  ; cout <<  ]  << endl   const int inf = int(1e9) + 7;   void solve() {     int n;     cin >> n;     bool ok = false;     for (int i = 0; i < n; ++i) {       int q;       cin >> q;       ok |= q != int(sqrt(q)) * int(sqrt(q));     }     cout << (ok ?  YES n  :  NO n );   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(15);     int tests = 1;     cin >> tests;     while (tests--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, a[12][12];     cin >> n;     memset(a, 0, sizeof(a));     for (int i = 1; i <= n; i++) {       a[1][i] = 1;       a[i][1] = 1;     }     for (int i = 2; i <= n; i++) {       for (int j = 2; j <= n; j++) {         a[i][j] = a[i - 1][j] + a[i][j - 1];       }     }     cout << a[n][n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int>> v(n);     vector<int> v2(k);     for (int i = 0; i < n; i++) {       cin >> v[i].first;       v[i].second = i + 1;     }     sort(v.begin(), v.end());     int sum = 0;     for (int i = 0; i < k; i++) {       sum += v[n - 1 - i].first;       v2[i] = v[n - 1 - i].second;     }     cout << sum << endl;     sort(v2.begin(), v2.end());     for (int i = k - 1; i > 0; i--) {       v2[i] = v2[i] - v2[i - 1];     }     int cnt = 0;     for (int i = 0; i < k - 1; i++) {       cout << v2[i] <<    ;       cnt += v2[i];     }     cout << n - cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct Trie {     int trie[6000005][2];     int cnt[6000005];     int root = 0;     long long val[6000005];     long long xorsum = 0;     long long ans[6000005 / 10];     int C = 0;     int newroot() {       trie[C][0] = trie[C][1] = -1;       cnt[C] = 0;       return C++;     }     void Insert(long long x) {       long long p = root;       for (int i = 60; i >= 0; i--) {         long long id = (x >> i) & 1;         if (trie[p][id] == -1) trie[p][id] = newroot();         p = trie[p][id];         cnt[p]++;       }       val[p] = x;     }     bool check(long long xorsum, long long &res, int index, bool limit, int dep) {       if (index != root && (cnt[index] == 0 || index == -1)) return false;       if (dep == -1) {         res = val[index];         cnt[index]--;         return true;       }       int id = (xorsum >> dep) & 1;       if (id == 0) {         bool ret = (check(xorsum, res, trie[index][0], limit, dep - 1)) ||                    (!limit && check(xorsum, res, trie[index][1], limit, dep - 1));         if (ret == 0) return false;         cnt[index]--;         return true;       } else {         bool ret = (check(xorsum, res, trie[index][0], limit, dep - 1)) ||                    (check(xorsum, res, trie[index][1], false, dep - 1));         if (ret == 0) return false;         cnt[index]--;         return true;       }     }     void solve() {       for (int i = n - 1; i >= 0; i--) {         long long res;         bool ret = check(xorsum, res, root, true, 60);         if (ret == 0) {           puts( No );           return;         }         ans[i] = res;         assert(xorsum > (xorsum ^ res));         xorsum ^= res;       }       puts( Yes );       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       puts(  );     }   } Tree;   int main() {     scanf( %d , &n);     Tree.root = Tree.newroot();     for (int i = 0; i < n; i++) {       long long x;       scanf( %I64d , &x);       Tree.Insert(x);       Tree.xorsum ^= x;     }     Tree.solve();   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   long long powm(long long a, long long b, long long mod) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   const long long mod = 1e9 + 7;   const long long N = 1000005;   const long long inf = 1e9;   void solve() {     int n;     cin >> n;     deque<long long> dq;     long long ans = 0;     while (n--) {       long long x;       cin >> x;       if (dq.size() == 0) {         dq.push_back(x);         continue;       }       if (dq.size() > 0) ans = max(ans, (dq.back() ^ x));       while (dq.size() > 0 and dq.back() < x) {         ans = max(ans, (x ^ dq.back()));         dq.pop_back();       }       if (dq.size() > 0) ans = max(ans, (dq.back() ^ x));       dq.push_back(x);     }     long long curr = dq.back();     dq.pop_back();     while (!dq.empty()) {       ans = max(ans, (curr ^ dq.back()));       curr = dq.back();       dq.pop_back();     }     cout << ans << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cout << fixed << setprecision(15);     int tc = 1;     while (tc--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double g = 9.8;   const double eps = 1e-9;   int n, m, v;   struct Ques {     double angle;     int id;   } ques[10010];   struct Wall {     double x, y;   } wall[100010];   double ans_x[10010], ans_y[10010];   bool cmp(const Ques &a, const Ques &b) { return a.angle < b.angle; }   bool cmp2(const Wall &a, const Wall &b) { return a.x < b.x; }   int main() {     scanf( %d%d , &n, &v);     for (int i = 1; i <= n; i++) {       scanf( %lf , &ques[i].angle);       ques[i].id = i;     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %lf%lf , &wall[i].x, &wall[i].y);     sort(ques + 1, ques + n + 1, cmp);     sort(wall + 1, wall + m + 1, cmp2);     int h = 1;     for (int i = 1; i <= n; i++) {       double v_y = v * sin(ques[i].angle), v_x = v * cos(ques[i].angle);       while (h <= m) {         double time = wall[h].x / v_x;         double y = v_y * time - 0.5 * g * time * time;         if (y < eps) {           ans_x[ques[i].id] = v_x * (v_y / (0.5 * g));           ans_y[ques[i].id] = 0;           break;         } else if (y < wall[h].y + eps) {           ans_x[ques[i].id] = wall[h].x;           ans_y[ques[i].id] = y;           break;         } else           h++;       }     }     for (int i = 1; i <= n; i++)       if (ans_x[ques[i].id] < eps) {         double v_y = v * sin(ques[i].angle), v_x = v * cos(ques[i].angle);         ans_x[ques[i].id] = v_x * (v_y / (0.5 * g));         ans_y[ques[i].id] = 0;       }     for (int i = 1; i <= n; i++) printf( %.9lf %.9lf n , ans_x[i], ans_y[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     k--;     int a[n];     int sum = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     if (a[k] == 1) sum++;     for (int i = 1; i < n; ++i) {       if (k - i < 0) {         for (int j = k + i; j < n; ++j) {           sum += a[j];         }         break;       }       if (k + i >= n) {         for (int j = k - i; j >= 0; --j) {           sum += a[j];         }         break;       }       if (a[k - i] == 1 && a[k + i] == 1) sum += 2;     }     cout << sum;     return 0;   }