malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 12;   int b[MAXN][MAXN][MAXN], ans, k, n, m;   bool mark[MAXN][MAXN][MAXN];   void dfs(int i, int j, int l) {     mark[i][j][l] = true;     if (j > 0)       if (b[i][j - 1][l] == 0 && !mark[i][j - 1][l]) {         ans++;         dfs(i, j - 1, l);       }     if (l > 0)       if (b[i][j][l - 1] == 0 && !mark[i][j][l - 1]) {         ans++;         dfs(i, j, l - 1);       }     if (j < n - 1)       if (b[i][j + 1][l] == 0 && !mark[i][j + 1][l]) {         ans++;         dfs(i, j + 1, l);       }     if (l < m - 1)       if (b[i][j][l + 1] == 0 && !mark[i][j][l + 1]) {         ans++;         dfs(i, j, l + 1);       }     if (i > 0)       if (b[i - 1][j][l] == 0 && !mark[i - 1][j][l]) {         ans++;         dfs(i - 1, j, l);       }     if (i < k - 1)       if (b[i + 1][j][l] == 0 && !mark[i + 1][j][l]) {         ans++;         dfs(i + 1, j, l);       }   }   int main() {     cin >> k >> n >> m;     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         for (int l = 0; l < m; l++) {           char ch;           cin >> ch;           if (ch ==  # ) b[i][j][l] = 1;         }       }     }     int x, y;     cin >> x >> y;     x--;     y--;     dfs(0, x, y);     cout << ans + 1;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize(2)   #pragma GCC optimize( Ofast )   using namespace std;   vector<int> g[2097312];   int a[2097312][2];   char st[2097312];   int f[2097312];   int find(int x) {     if (f[x] == x) return x;     return f[x] = find(f[x]);   }   int main() {     int n, i, j, cnt;     scanf( %d , &n);     scanf( %s , st + 1);     for (i = n; i >= 1; --i) {       if (st[i] !=  1 ) {         a[i][0] = a[i + 1][0] + 1;       }       if (st[i] !=  0 ) {         a[i][1] = a[i + 1][1] + 1;       }       g[max(a[i][1], a[i][0])].push_back(i);       f[i] = i;     }     f[n + 1] = n + 1;     for (i = 1; i <= n; ++i) {       j = 1, cnt = 0;       while (j <= n) {         j = find(j);         if (j > n) {           break;         }         cnt++;         j += i;       }       printf( %d  , cnt);       for (auto v : g[i]) {         f[v] = v + 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       long long flag = 0, p = 0, ne = 0;       if (a[0] != b[0]) {         flag = 1;         cout <<  NO  << endl;         continue;       }       if (a[0] == 1) p++;       if (a[0] == -1) ne++;       for (int i = 1; i < n; i++) {         if ((a[i] > b[i] && ne == 0) || (a[i] < b[i] && p == 0)) {           flag = 1;           cout <<  NO  << endl;           break;         }         if (a[i] == 1) p++;         if (a[i] == -1) ne++;       }       if (flag == 0) cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int sum = 0, p = 1;     char ch = getchar();     while (!(( 0  <= ch && ch <=  9 ) || ch ==  - )) ch = getchar();     if (ch ==  - ) p = -1, ch = getchar();     while ( 0  <= ch && ch <=  9 ) sum = sum * 10 + ch - 48, ch = getchar();     return sum * p;   }   const int maxn = 52;   const int mod = 1e9 + 7;   int n, f[maxn][maxn][maxn], g[maxn][maxn], d[maxn], dp[maxn][maxn][maxn],       jc[maxn], jcn[maxn], inv[maxn];   inline int C(int n, int m) {     return (long long)jc[n] * jcn[m] % mod * jcn[n - m] % mod;   }   inline int power(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = (long long)ans * a % mod;       b >>= 1;       a = (long long)a * a % mod;     }     return ans;   }   inline void init() {     n = read();     for (int i = (1), _end_ = (n); i <= _end_; i++) d[i] = read();     jc[0] = jc[1] = jcn[0] = jcn[1] = inv[1] = 1;     for (int i = (2), _end_ = (50); i <= _end_; i++)       jc[i] = (long long)i * jc[i - 1] % mod,       inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod,       jcn[i] = (long long)inv[i] * jcn[i - 1] % mod;     f[0][0][0] = 1;     for (int k = (2), _end_ = (50); k <= _end_; k++)       if (~k & 1) f[0][0][k] = (long long)f[0][0][k - 2] * (k - 1) % mod;     for (int j = (1), _end_ = (50); j <= _end_; j++)       for (int k = (0), _end_ = (50); k <= _end_; k++)         if (~k & 1) {           if (k >= 2)             f[0][j][k] =                 (f[0][j][k] + (long long)f[0][j - 1][k - 2] * C(k, 2)) % mod;           if (j >= 2)             f[0][j][k] =                 (f[0][j][k] + (long long)f[0][j - 2][k] * (j - 1) * k) % mod;           if (j >= 3)             f[0][j][k] =                 (f[0][j][k] + (long long)f[0][j - 3][k + 2] * C(j - 1, 2)) % mod;         }     for (int i = (1), _end_ = (50); i <= _end_; i++)       for (int j = (0), _end_ = (50); j <= _end_; j++)         for (int k = (0), _end_ = (50); k <= _end_; k++)           f[i][j][k] = ((j ? (long long)f[i - 1][j - 1][k + 1] * j : 0) +                         (k ? (long long)f[i - 1][j][k - 1] * k : 0)) %                        mod;   }   inline void doing() {     dp[1][1][1] = 1;     if (d[1] == 2) {       dp[2][3][2] = 1;     } else {       dp[2][4][3] = 1;     }     for (int i = (3), _end_ = (n); i <= _end_; i++) {       for (int j = (i), _end_ = (n); j <= _end_; j++) {         for (int k = (1), _end_ = (j); k <= _end_; k++) {           int A = 0, B = 0;           for (int l = (1), _end_ = (j - k); l <= _end_; l++) {             (d[j - k - l + 1] == 2 ? B : A)++;             dp[i][j][k] =                 (dp[i][j][k] + (long long)dp[i - 1][j - k][l] * f[k][A][B]) % mod;           }         }       }     }     int ans = 0;     for (int i = (2), _end_ = (n); i <= _end_; i++) {       int A = 0, B = 0;       for (int k = (1), _end_ = (n); k <= _end_; k++) {         (d[n - k + 1] == 2 ? B : A)++;         ans = (ans + (long long)dp[i][n][k] * f[0][A][B]) % mod;       }     }     printf( %d n , ans);   }   int main() {     init();     doing();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   bool go(int x, multiset<int> &hand, deque<int> &dq) {     if (hand.find(x) == hand.end()) return false;     hand.erase(hand.find(x));     hand.insert(dq.front());     dq.pop_front();     dq.push_back(x);     return true;   }   multiset<int> hand;   deque<int> dq;   int Try() {     multiset<int> hand1 = hand;     deque<int> dq1 = dq;     int pos = -1;     for (int i = 0; i < n; i++) {       if (dq[i] == 1) pos = i;     }     if (pos == -1) return -1;     for (int i = pos; i < n; i++)       if (dq[i] != i - pos + 1) return -1;     int done = n - pos;     int ans = 0;     while (done < n) {       ++done;       ++ans;       if (!go(done, hand1, dq1)) return -1;     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       hand.insert(x);     }     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       dq.push_back(x);     }     int ans = Try();     if (ans != -1) {       cout << ans << endl;       return 0;     }     ans = 0;     while (hand.find(1) == hand.end()) {       assert(go(0, hand, dq));       ans++;     }     int mx = n;     for (int i = 0; i < n; i++) {       if (dq[i] == 0) continue;       int cur = i + 1 + (n + 1 - dq[i]);       mx = max(mx, cur);     }     cout << ans + mx << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2147483647, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};   const int N = 100005, M = 1000005, K = 200005, mod = 1000000007;   const long long llinf = 9223372036854775807ll;   long long n, m, s, ans, ar;   long long f(long long a, long long b) { return (n - a + 1) * (m - b + 1); }   int main() {     cin >> n >> m >> s;     for (int i = 1; i <= n; i += 2)       for (int j = 1; j <= m; j += 2) {         if (i * j == s)           ans += f(i, j) * (((i + 1) * (j + 1) / 2) - 1);         else if (i * j > s) {           ar = (i * j - s);           if (ar % 4 != 0) continue;           ar /= 4;           for (int l = 1; l <= (i - 1) / 2; l++)             if ((ar % l) == 0 && (ar / l) <= (j - 1) / 2) ans += f(i, j) * 2;         }       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   pair<long long, long long> dif[maxn];   long long x[maxn], y[maxn], pref[maxn], suff[maxn], ans[maxn];   vector<int> adj[maxn];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &x[i], &y[i]);       dif[i] = {y[i] - x[i], i};     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     sort(dif + 1, dif + n + 1);     for (int i = 1; i <= n; i++) {       pref[i] = pref[i - 1] + y[dif[i].second];     }     for (int i = n; i >= 1; i--) {       suff[i] = suff[i + 1] + x[dif[i].second];     }     for (int i = 1; i <= n; i++) {       int u = dif[i].second;       long long res =           pref[i - 1] + suff[i + 1] + 1ll * (i - 1) * x[u] + 1ll * (n - i) * y[u];       for (auto v : adj[u]) {         res -= min(x[u] + y[v], x[v] + y[u]);       }       ans[u] = res;     }     for (int i = 1; i <= n; i++) {       printf( %lld  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int ans = -1;     int sum = 7;     int i = 1;     while (sum <= n) {       int y = n - sum;       if (y % 4 == 0) ans = i;       sum += 7;       i++;     }     if (ans != -1) {       int s = 7 * ans;       int y = n - s;       int x = y / 4;       while (x--) {         cout <<  4 ;       }       while (ans--) {         cout <<  7 ;       }       return 0;     }     if (n % 7 == 0) {       int x = n / 7;       while (x--) cout <<  7 ;       return 0;     }     if (n % 4 == 0) {       int x = n / 4;       while (x--) cout <<  4 ;       return 0;     }     cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string vow =  aeiou ;   const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   const long double pie = 3.14159265358979;   const long long mod = 1e9 + 7;   void solve(int test_case) {     int k;     cin >> k;     string s;     cin >> s;     int n = s.size();     vector<int> pref(n + 1);     for (int i = 1; i < n + 1; i++) pref[i] = pref[i - 1] + s[i - 1] -  0 ;     long long ans = 0;     for (int i = 0; i < n; i++) {       int x = pref[i + 1];       int val = x - k;       if (val < 0) continue;       ;       int ans_indx = -1;       for (int lo = 0, hi = i; lo <= hi;) {         int mid = lo + hi >> 1;         if (pref[mid] > val)           hi = mid - 1;         else if (pref[mid] == val)           ans_indx = mid, hi = mid - 1;         else           lo = mid + 1;       }       if (ans_indx == -1) continue;       ;       long long L = ans_indx;       ans_indx = -1;       for (int lo = 0, hi = i; lo <= hi;) {         int mid = lo + hi >> 1;         if (pref[mid] == val)           ans_indx = mid, lo = mid + 1;         else if (pref[mid] < val)           lo = mid + 1;         else           hi = mid - 1;       }       if (ans_indx == -1) continue;       ;       long long R = ans_indx;       ans += R - L + 1;     }     cout << ans;     cout <<   n ;   }   int main() {     int t = 1;     for (int i = 0; i < t; i++) solve(i);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 100010;   int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], val[MAXN << 1], tot;   void addedge(int b, int e, int v) {     nxt[++tot] = head[b];     to[head[b] = tot] = e;     val[tot] = v;     nxt[++tot] = head[e];     to[head[e] = tot] = b;     val[tot] = v;   }   int n, Q;   std::pair<int, int> diameter(int u, int fa = 0) {     std::pair<int, int> res(0, u);     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa) {         std::pair<int, int> t = diameter(to[i], u);         t.first += val[i];         res = std::max(res, t);       }     return res;   }   struct TTT {     int fa[MAXN], son[MAXN], top[MAXN], dep[MAXN], sonmax[MAXN];     int dis[MAXN];     void dfs1(int u) {       for (int i = head[u]; i; i = nxt[i])         if (to[i] != fa[u]) {           fa[to[i]] = u;           dep[to[i]] = dep[u] + 1;           dis[to[i]] = dis[u] + val[i];           dfs1(to[i]);           sonmax[to[i]] += val[i];           if (sonmax[to[i]] > sonmax[son[u]]) son[u] = to[i];         }       sonmax[u] = sonmax[son[u]];     }     int down[MAXN];     void dfs2(int u) {       down[top[u]] = u;       if (son[u]) top[son[u]] = top[u], dfs2(son[u]);       for (int i = head[u]; i; i = nxt[i])         if (to[i] != fa[u] && to[i] != son[u]) top[to[i]] = to[i], dfs2(to[i]);     }     int chv[MAXN], li[MAXN], rk[MAXN], bak, pre[MAXN];     void init(int rt) {       dep[rt] = 1, top[rt] = rt;       dfs1(rt);       dfs2(rt);       for (int i = 1; i <= n; ++i)         if (i == top[i]) li[++bak] = i, chv[i] = dis[down[i]] - dis[fa[i]];       std::sort(li + 1, li + 1 + bak,                 [this](int a, int b) { return chv[a] > chv[b]; });       for (int i = 1; i <= bak; ++i)         rk[li[i]] = i, pre[i] = pre[i - 1] + chv[li[i]];     }     int solve(int u, int v) {       int lans = 0;       v = std::min(bak, v * 2 - 1);       if (rk[top[u]] <= v)         lans = pre[v];       else {         lans = pre[v - 1] + chv[top[u]];         int now = u;         while (rk[top[now]] > v) now = fa[top[now]];         int tv = pre[v] - dis[down[top[now]]] + dis[down[top[u]]];         tv = std::max(tv, pre[v - 1] - dis[now] + dis[down[top[u]]]);         lans = std::max(lans, tv);       }       return lans;     }   } t1, t2;   int main() {     std::ios_base::sync_with_stdio(false), std::cin.tie(0);     std::cin >> n >> Q;     for (int i = 1, t1, t2, t3; i < n; ++i) {       std::cin >> t1 >> t2 >> t3;       addedge(t1, t2, t3);     }     int rt1 = diameter(1).second, rt2 = diameter(rt1).second;     t1.init(rt1), t2.init(rt2);     int lans = 0;     while (Q-- > 0) {       int u, v;       std::cin >> u >> v;       u = (u + lans - 1) % n + 1;       v = (v + lans - 1) % n + 1;       lans = std::max(t1.solve(u, v), t2.solve(u, v));       std::cout << lans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   long long t, n, nl[100010], ml[100010], nll[100010], mll[100010];   int main() {     n = read();     for (int i = 1; i <= n; i++) {       nl[i] = read();     }     for (int i = 1; i <= n; i++) {       ml[i] = read();     }     for (int i = 1; i < n; i++) {       nll[i] = nl[i + 1] - nl[i];       mll[i] = ml[i + 1] - ml[i];     }     sort(nll + 1, nll + n);     sort(mll + 1, mll + n);     int pd = 0;     for (int i = 1; i < n; i++) {       if (nll[i] != mll[i]) pd = 1;     }     if (pd == 0 && nl[1] == ml[1] && nl[n] == ml[n]) {       puts( Yes );     } else {       puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   const int mod = 1e9 + 7;   int n;   int num[MAXN];   bool vis[MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &num[i]);     int e = n;     printf( 1 );     int sum = 0;     for (int i = 1; i <= n; ++i) {       vis[num[i]] = 1;       while (vis[e] && e >= 1) {         sum++;         e--;       }       printf(  %d , i - sum + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   int Map[50002][7];   int main() {     int m, n;     scanf( %d%d , &m, &n);     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) scanf( %d , &Map[i][j]);     for (int i = 1; i <= m; i++) Map[i][1] += Map[i - 1][1];     for (int j = 1; j <= n; j++) Map[1][j] += Map[1][j - 1];     for (int i = 2; i <= m; i++)       for (int j = 2; j <= n; j++) Map[i][j] += max(Map[i - 1][j], Map[i][j - 1]);     for (int i = 1; i <= m; i++) {       if (i > 1) putchar(   );       printf( %d , Map[i][n]);     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   bool cmpDouble(const double& a, const double& b) {     return std::fabs(a - b) < std::numeric_limits<double>::epsilon();   }   int main() {     int n, k;     cin >> n >> k;     int arr[5001];     int ans[5001];     for (int i = 0; i < n; ++i) {       cin >> arr[i];       ans[i] = 0;     }     map<int, set<int>> seen;     for (int i = 0; i < k; ++i) {       ans[i] = i + 1;       seen[arr[i]].insert(i + 1);     }     for (int i = k; i < n; ++i) {       if (seen[arr[i]].size() >= k) {         cout <<  NO  << endl;         return 0;       }       for (int j = 1; j <= k; ++j) {         if (seen[arr[i]].find(j) == seen[arr[i]].end()) {           ans[i] = j;           seen[arr[i]].insert(j);           break;         }       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; ++i) {       cout << ans[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct data {     int info;     int l, r;     data() {       info = 0;       l = 0;       r = 0;     }   };   data tr[100000 * 40];   int avail = 0;   int update(int no, int s, int e, int in, int val) {     int idx = no;     if (!no) {       idx = ++avail;       tr[idx] = data();     }     if (s == e) {       tr[idx].info += val;       return idx;     }     int mid = (s + e) / 2;     if (mid >= in) {       tr[idx].l = update(tr[idx].l, s, mid, in, val);     } else {       tr[idx].r = update(tr[idx].r, mid + 1, e, in, val);     }     tr[idx].info = (tr[tr[idx].l].info + tr[tr[idx].r].info);     return idx;   }   int query(int idx, int s, int e, int st, int en) {     if (idx == 0) return 0;     if (s >= st && e <= en) return tr[idx].info;     int mid = (s + e) / 2;     if (mid >= en)       return query(tr[idx].l, s, mid, st, en);     else if (mid < st)       return query(tr[idx].r, mid + 1, e, st, en);     else       return query(tr[idx].l, s, mid, st, mid) +              query(tr[idx].r, mid + 1, e, mid + 1, en);   }   int main() {     int n;     cin >> n;     map<int, int> mp;     while (n--) {       int x, y, z;       cin >> x >> y >> z;       if (x == 1) {         mp[z] = update(mp[z], 1, 1e9 + 7, y, 1);       } else if (x == 2) {         mp[z] = update(mp[z], 1, 1e9 + 7, y, -1);       } else {         printf( %d n , query(mp[z], 1, 1e9 + 7, 1, y));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a;     map<int, int> mp;     for (int i = 0; i < n; i++) {       int val;       cin >> val;       if (mp.find(val) == mp.end()) {         mp[val]++;         a.push_back(val);       }     }     sort(a.begin(), a.end());     int i = 0, sum = 0;     int g = a.size();     while (i < min(g, k)) {       int x = a[i] - sum;       cout << x << endl;       sum += x;       i++;     }     while (i < k) {       cout <<  0  << endl;       i++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int xpow(long long int a, long long int b) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long int k = xpow(a, b / 2);       return k * k;     }     if (b % 2 != 0) return a * xpow(a, b - 1);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n, sx, sy;     cin >> n >> sx >> sy;     int l = 0, r = 0, d = 0, u = 0;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (x > sx) r++;       if (x < sx) l++;       if (y > sy) u++;       if (y < sy) d++;     }     int maxi = max({l, r, d, u});     cout << maxi << endl;     if (l == maxi)       sx--;     else if (r == maxi)       sx++;     else if (u == maxi)       sy++;     else if (d == maxi)       sy--;     cout << sx <<     << sy << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     double a;     int ans = 0;     vector<int> v;     int n, m;     cin >> n;     int ara1[n];     for (int i = 0; i < n; i++) cin >> ara1[i];     cin >> m;     int ara2[m];     for (int i = 0; i < m; i++) cin >> ara2[i];     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         a = (double)ara2[i] / ara1[j];         if (a == (int)a) {           int b = a;           v.push_back(b);         }       }     }     sort(v.rbegin(), v.rend());     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         a = (double)ara2[i] / ara1[j];         if (a == v[0]) ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi(3.14159265358979);   int a[100010], d[100010];   int main() {     int x, i, j, n;     scanf( %d , &n);     scanf( %d , &x);     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n; i++) d[i] = abs(a[i] - x);     int ans = 0;     if (n == 1)       ans = 0;     else if (x >= a[n - 1])       ans = d[1];     else if (x <= a[0])       ans = d[n - 2];     else if (n == 2)       ans = min(d[0], d[1]);     else if (x > a[0] && x <= a[1])       ans = min(d[n - 1], min(2 * d[0] + d[n - 2], 2 * d[n - 2] + d[0]));     else if (x < a[n - 1] && x >= a[n - 2])       ans = min(d[0], min(2 * d[n - 1] + d[1], 2 * d[1] + d[n - 1]));     else       ans = min(2 * d[0] + d[n - 2],                 min(2 * d[n - 2] + d[0],                     min(2 * d[n - 1] + d[1], 2 * d[1] + d[n - 1])));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long int n, i, j, k, f = 0;       scanf( %lld , &n);       long long int a[n];       for (i = 0; i < n; i++) scanf( %lld , &a[i]);       for (i = 2; i < n; i++) {         if (a[i] >= a[0] + a[1]) {           f = 1;           break;         }       }       if (f == 1)         printf( 1 2 %lld n , i + 1);       else         printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     int v = 0;     int ans = 0, ans1 = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (i < k - 1 && a != 0) ans1++;       if (i == k - 1) ans = a;       if (i >= k - 1 && a == ans && ans > 0) v++;     }     cout << v + ans1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(vector<T> &vec) {     for (int i = 0; i < (int)(vec).size(); i++)       cout << vec[i] << (i == (int)(vec).size() - 1 ?   n  :    );   }   bool ok(int x) { return (x % 10 == 7); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a, b, x, ans = 0;     cin >> x >> a >> b;     while (1) {       if (ok(a) || ok(b)) break;       if (b >= x)         b -= x;       else {         b = 60 - abs(b - x);         a = (a ? a - 1 : 23);       }       ans++;     }     cout << ans <<   n ;     return 0;   }