malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[200000];   int calculate(int x, int y) {     int pos1 = -1, pos2 = -1;     for (int i = x; i <= y; i++) {       if (a[i] != -1) {         if (pos1 == -1)           pos1 = i;         else if (pos2 == -1)           pos2 = i;         else           break;       }     }     if (pos2 == -1) return 1;     int dst = pos2 - pos1;     int htd = a[pos2] - a[pos1];     int abhtd = abs(htd);     if (abhtd % dst != 0) return 1 + calculate(pos2, y);     int diff = htd / dst;     int j = pos1 - 1;     long long exp = a[pos1] - diff;     while (j >= x) {       if (exp <= 0) break;       exp -= diff;       j--;     }     if (j != x - 1) return 1 + calculate(pos2, y);     j = pos2 + 1, exp = a[pos2] + diff;     while (j <= y) {       if (exp <= 0) break;       if (a[j] != exp && a[j] != -1) break;       exp += diff;       j++;     }     int offset = 0;     if (j != y + 1) offset = calculate(j, y);     return offset + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cout << calculate(0, n - 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t[200025 * 4], lz[200025 * 4], n, a[200025];   void build(int l, int r, int i) {     t[i] = 1ll * l * (l - 1) / 2;     if (l == r) return;     build(l, (l + r) / 2, i * 2 + 1);     build((l + r) / 2 + 1, r, i * 2 + 2);     t[i] = max(t[i * 2 + 1], t[i * 2 + 2]);   }   void down(int i) {     lz[i * 2 + 1] += lz[i];     lz[i * 2 + 2] += lz[i];     t[i * 2 + 1] += lz[i];     t[i * 2 + 2] += lz[i];     lz[i] = 0;   }   void updata(int L, int R, long long v, int l, int r, int i) {     if (L <= l && R >= r) {       t[i] += v;       lz[i] += v;       return;     }     if (lz[i]) down(i);     if (L <= (l + r) / 2) updata(L, R, v, l, (l + r) / 2, i * 2 + 1);     if (R > (l + r) / 2) updata(L, R, v, (l + r) / 2 + 1, r, i * 2 + 2);     t[i] = max(t[i * 2 + 1], t[i * 2 + 2]);   }   int query(long long v, int l, int r, int i) {     if (l == r) return l;     if (lz[i]) down(i);     if (t[i * 2 + 1] >= v) return query(v, l, (l + r) / 2, i * 2 + 1);     return query(v, (l + r) / 2 + 1, r, i * 2 + 2);   }   int main() {     cin >> n;     for (int i = (1); i <= (n); i++) scanf( %lld , &a[i]);     build(1, n, 0);     for (int i = (n); i >= (1); i--) {       a[i] = query(a[i], 1, n, 0);       if (a[i] < n) updata(a[i] + 1, n, -a[i], 1, n, 0);       updata(a[i], a[i], -1e12, 1, n, 0);     }     for (int i = (1); i <= (n); i++) printf( %lld%c , a[i], i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:640000000 )   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   template <class T>   T sqr(T x) {     return x * x;   }   const int maxn = (int)(1e5) + 10;   const int inf = (int)(2e9);   struct Edge {     int to, w, num;     Edge() : to(0), w(0), num(0) {}     Edge(int to, int w, int num) : to(to), w(w), num(num) {}   };   int n, L;   int x[maxn], d[maxn], t[maxn], p[maxn];   vector<Edge> g[2 * maxn];   vector<int> pt;   int dist[2 * maxn], pred[2 * maxn], num[2 * maxn];   int main() {     scanf( %d%d , &n, &L);     set<int> spt;     spt.insert(0);     pt.push_back(0);     spt.insert(L);     pt.push_back(L);     for (int i = 0; i < n; i++) {       scanf( %d%d%d%d , &x[i], &d[i], &t[i], &p[i]);       if (d[i] <= t[i] || x[i] - p[i] < 0) continue;       if (spt.find(x[i] - p[i]) == spt.end()) {         pt.push_back(x[i] - p[i]);         spt.insert(x[i] - p[i]);       }       if (spt.find(x[i] + d[i]) == spt.end()) {         pt.push_back(x[i] + d[i]);         spt.insert(x[i] + d[i]);       }     }     sort(pt.begin(), pt.end());     int N = (int)((pt).size());     for (int i = 0; i < n; i++) {       if (d[i] <= t[i] || x[i] - p[i] < 0) continue;       int v = int(lower_bound(pt.begin(), pt.end(), x[i] - p[i]) - pt.begin());       int u = int(lower_bound(pt.begin(), pt.end(), x[i] + d[i]) - pt.begin());       g[v].push_back(Edge(u, p[i] + t[i], i + 1));     }     for (int i = 0; i < N - 1; i++) {       g[i].push_back(Edge(i + 1, pt[i + 1] - pt[i], 0));       g[i + 1].push_back(Edge(i, pt[i + 1] - pt[i], 0));     }     set<pair<int, int> > sd;     for (int i = 0; i < N; i++) {       dist[i] = inf;       pred[i] = -1;       num[i] = 0;     }     dist[0] = 0;     sd.insert(make_pair(0, 0));     while (!sd.empty()) {       int v = sd.begin()->second;       sd.erase(sd.begin());       for (int i = 0; i < g[v].size(); i++) {         if (dist[g[v][i].to] > dist[v] + g[v][i].w) {           sd.erase(make_pair(dist[g[v][i].to], g[v][i].to));           dist[g[v][i].to] = dist[v] + g[v][i].w;           pred[g[v][i].to] = v;           num[g[v][i].to] = g[v][i].num;           sd.insert(make_pair(dist[g[v][i].to], g[v][i].to));         }       }     }     cout << dist[N - 1] << endl;     vector<int> trp;     for (int v = N - 1; pred[v] != -1; v = pred[v]) {       if (num[v] != 0) trp.push_back(num[v]);     }     reverse(trp.begin(), trp.end());     cout << (int)((trp).size()) << endl;     for (int i = 0; i < (int)((trp).size()); i++) {       cout << trp[i] <<    ;     }     return 0;   }
//#include  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/bits/stdc++.h    #include <bits/stdc++.h>   using namespace std;   //#include <atcoder/dsu>   // #include <ext/pb_ds/assoc_container.hpp>   // #include <ext/pb_ds/tree_policy.hpp>   // using namespace __gnu_pbds;   // #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>   #define int long long int   #define endl   n    #define MOD 1000000007   #define mod 1000000007   #define M 1000000007   #define pb push_back   #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]   #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define mx 1000005   #define fiint(a,b) memset(a,b,sizeof(a))   #define bitcount __builtin_popcount   #define fori(i,a,b) for(int i=a;i<b;i++)   #define ford(i,a,b) for(int i=a;i>=b;i--)   #define debug(x) cout<<x<<endl;   #define cases(t) int t; cin>>t; while(t--)   #define inf1 INT_MAX   #define all(a) a.begin(),a.end()   #define vec vector<int>   #define pii pair<int,int>   #define plii pair<int,int>   #define pint pair<int,int>   #define ff first   #define ss second   #define lb lower_bound   #define ub upper_bound   #define bs binary_search   #define mp make_pair   #define sz(x) (int)x.size()   #define PI    3.14159265359      //const long long INF=1e18;      bool chmin(int& a, int b){ if(a > b){ a = b; return 1; } return 0; }          int factorial[10000001]={0};       int gcd(int a, int b){       if (b == 0)           return a;       return gcd(b, a % b);   }         int powerFunction(int x,int y){       int res = 1;       // int p = mod;       x = x;       while (y > 0)       {           if (y & 1)               res = (res*x) ;           y = y>>1;           x = (x*x) ;       }       return res;   }      void factorialFunction(int maxLimit){       factorial[0]=1;       for(int i=1 ; i <= maxLimit ; i++)       factorial[i]=(factorial[i-1]*i)%MOD;       return;   }       int nCr(int n, int r)   {       if(r < 0 || r > n){           return 0;       }       int temp = factorial[n];       temp *= (powerFunction(factorial[r], MOD-2)%MOD);       temp %= MOD;       temp *= (powerFunction(factorial[n-r], MOD-2)%MOD);       temp %= MOD;       return temp;   }                  signed main()   {       cases(t){           pair<int,int> a , b , f;           cin >> a.ff >> a.ss >> b.ff >> b.ss >> f.ff>> f.ss;           if( (a.ff == b.ff && b.ff == f.ff && min(a.ss , b.ss) < f.ss  && max(a.ss,b.ss) > f.ss ) || (a.ss == b.ss && b.ss == f.ss &&min(a.ff , b.ff) < f.ff  && max(a.ff,b.ff) > f.ff ))               cout <<abs(a.ff - b.ff) + abs(a.ss - b.ss) + 2 << endl;           else cout <<abs(a.ff - b.ff) + abs(a.ss - b.ss)<<endl;       }   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T_container, typename T = typename enable_if<                                       !is_same<T_container, string>::value,                                       typename T_container::value_type>::type>   ostream &operator<<(ostream &os, const T_container &v) {     os <<  { ;     string sep;     for (const T &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   const int MX = 1e5 + 1;   int cnt = 0;   vector<int> adj[MX];   bool vis[MX];   void dfs(int node) {     if (vis[node]) return;     vis[node] = true;     for (auto &u : adj[node])       if (!vis[u]) dfs(u);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     unordered_map<int, bool> mp;     for (int i = 1; i <= n; ++i) {       int tmp;       cin >> tmp;       adj[i].emplace_back(tmp);       adj[tmp].emplace_back(i);     }     for (int i = 1; i <= n; ++i) {       if (vis[i]) continue;       ++cnt;       dfs(i);     }     cout << cnt <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, y1, x2, y2;     while (scanf(  %*d %*d %d %d %d %d , &x1, &y1, &x2, &y2) == 4) {       int a = abs(x1 - x2), b = abs(y1 - y2);       if (min(a, b) <= 2 && max(a, b) < 5)         puts( First );       else if (max(a, b) < 4)         puts( First );       else         puts( Second );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 5;   vector<int> g[N], son[N];   bool used[N];   int tin[N], tout[N], tup[N];   vector<int> fstep[N];   int start = -1, a, b, c;   void dfs(int v, int p) {     static int TIME = 0;     tin[v] = TIME++;     tup[v] = tin[v];     used[v] = true;     for (int u : g[v]) {       if (u == p) continue;       if (used[u]) {         tup[v] = min(tup[v], tin[u]);       } else {         son[v].push_back(u);         dfs(u, v);         tup[v] = min(tup[v], tup[u]);       }     }     for (int x : g[v]) {       fstep[x].clear();     }     for (int x : g[v]) {       if (tin[x] < tin[v]) {         fstep[p].push_back(x);       } else {         auto it =             lower_bound((son[v]).begin(), (son[v]).end(), x,                         [&](int _x, int __x) { return tout[_x] < tout[__x]; });         if (tup[*it] < tin[v])           fstep[p].push_back(x);         else           fstep[*it].push_back(x);       }     }     for (int x : g[v]) {       if (start == -1 && (int)(fstep[x]).size() >= 3) {         start = v;         a = fstep[x][0];         b = fstep[x][1];         c = fstep[x][2];       }     }     tout[v] = TIME++;   }   bool inPath[N];   int par[N];   bool dfs2(int v, vector<int>& path, function<bool(int)> stop) {     if (stop(v)) {       path.push_back(v);       for (int u = v; par[u] != u; u = par[u]) path.push_back(par[u]);       reverse((path).begin(), (path).end());       return true;     }     used[v] = true;     for (int u : g[v]) {       if (u != start && !used[u]) {         par[u] = v;         if (dfs2(u, path, stop)) return true;       }     }     return false;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int x = 0; x < n; ++x) {       if (!used[x]) dfs(x, x);     }     if (start == -1) {       printf( NO n );       return 0;     }     vector<int> p1;     par[a] = a;     memset(used, false, sizeof used);     dfs2(a, p1, [&](int x) { return x == b; });     for (int x : p1) inPath[x] = true;     vector<int> p2;     par[c] = c;     memset(used, false, sizeof used);     dfs2(c, p2, [&](int x) { return inPath[x]; });     int finish = p2.back();     vector<int> out[3];     out[0].push_back(start);     for (int pos = 0; p1[pos] != finish; ++pos) out[0].push_back(p1[pos]);     out[0].push_back(finish);     out[1].push_back(start);     for (int pos = (int)(p1).size() - 1; p1[pos] != finish; --pos)       out[1].push_back(p1[pos]);     out[1].push_back(finish);     out[2].push_back(start);     for (int x : p2) out[2].push_back(x);     printf( YES n );     for (int ii = 0; ii < 3; ++ii) {       printf( %d  , (int)(out[ii]).size());       for (int x : out[ii]) printf( %d  , x + 1);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 9;   const int MAXN = 100005;   struct disj {     int pa[MAXN], sz[MAXN];     void init(int n) {       for (int i = 0; i <= n; i++) {         pa[i] = i;         sz[i] = 1;       }     }     int find(int x) { return pa[x] = (pa[x] == x ? x : find(pa[x])); }     bool uni(int p, int q) {       p = find(p);       q = find(q);       if (p == q) return 0;       pa[q] = p;       sz[p] += sz[q];       return 1;     }   } disj;   int main() {     int n, m;     scanf( %d %d , &n, &m);     disj.init(n);     int ans = 1;     while (m--) {       int s, e;       scanf( %d %d , &s, &e);       if (!disj.uni(s, e)) ans = (ans * 2) % mod;       printf( %d n , ans - 1);     }   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int x, t, whe, s, s2;   } a[100100];   int n, t_cnt, V, ans, ans2, Mint = (1 << 30);   int f[100100], f2[100100], Max[100100 * 4], Max2[100100 * 4];   bool cmp(Node x, Node y) { return x.s > y.s || (x.s == y.s && x.s2 < y.s2); }   bool cmp2(Node x, Node y) { return x.s2 < y.s2 || (x.s2 == y.s2 && x.t < y.t); }   int Maxans1, Maxans2;   void find(int node, int l, int r, int ll, int rr) {     if (l > rr || ll > r) return;     if (ll <= l && rr >= r) {       Maxans1 = max(Max[node], Maxans1);       Maxans2 = max(Max2[node], Maxans2);       return;     }     int mid = (l + r) >> 1, son = node << 1;     find(son, l, mid, ll, rr);     find(son | 1, mid + 1, r, ll, rr);   }   void push(int node, int l, int r, int hig, int whe) {     if (l == r) {       Max[node] = max(f[whe], Max[node]);       Max2[node] = max(f2[whe], Max2[node]);       return;     }     int mid = (l + r) >> 1, son = node << 1;     if (hig > mid)       push(son | 1, mid + 1, r, hig, whe);     else       push(son, l, mid, hig, whe);     Max[node] = max(Max[son], Max[son | 1]);     Max2[node] = max(Max2[son], Max2[son | 1]);   }   void work() {     for (int i = 1; i <= n; i++) {       Maxans1 = 0;       Maxans2 = 0;       find(1, 1, t_cnt, 1, a[i].s2);       if (!Maxans1) {         if (a[i].t * V >= abs(a[i].x)) f[i] = 1;       } else         f[i] = Maxans1 + 1;       f2[i] = Maxans2 + 1;       push(1, 1, t_cnt, a[i].s2, i);       ans = max(f[i], ans);       ans2 = max(f2[i], ans2);     }     printf( %d %d , ans, ans2);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d %d , &a[i].x, &a[i].t);     }     cin >> V;     for (int i = 1; i <= n; i++)       a[i].s = a[i].x - a[i].t * V, a[i].s2 = a[i].x + a[i].t * V;     sort(a + 1, a + n + 1, cmp2);     for (int i = 1; i <= n; i++) {       if (a[i].s2 != a[i - 1].s2) t_cnt++;       a[i].s2 = t_cnt;     }     sort(a + 1, a + n + 1, cmp);     work();   }
#include <bits/stdc++.h>   using namespace std;   bool chmin(int64_t& a, const int64_t& b) { return b < a ? a = b, 1 : 0; }   bool chmax(int64_t& a, const int64_t& b) { return a < b ? a = b, 1 : 0; }   constexpr int pct(int x) { return __builtin_popcount(x); }   constexpr int bits(int x) { return 31 - __builtin_clz(x); }   const int N = 1e6 + 1;   int64_t binpow(int64_t a, int64_t b, int64_t m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   void run_case() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     set<int> second, ans, prev;     for (int i = 0; i < n; i++) {       second.insert(a[i]);       for (auto it : prev) {         second.insert(a[i] | it);       }       prev.clear();       for (auto it : second) {         prev.insert(it);         ans.insert(it);       }       second.clear();     }     cout << ans.size();   }   auto clk = clock();   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       run_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   inline int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }   inline int mul(int a, int b) { return int(1LL * a * b % mod); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<string> s(n);     for (int i = 0; i < n; i++) {       cin >> s[i];     }     int pw = 1;     int ans = 0;     int t = (int)s[0].size();     for (int i = 0; i < t; i++) {       for (string xd : s) {         int at = mul(xd.back() -  0 , pw);         ans = add(ans, mul(at, n));       }       pw = mul(pw, 10);       for (string &xd : s) {         int at = mul(xd.back() -  0 , pw);         ans = add(ans, mul(at, n));         xd.pop_back();       }       pw = mul(pw, 10);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100001];   vector<int> v[100001];   int it = 1;   long double e[100001];   int dfs(const int i) {     a[i] = 1;     for (int j : v[i]) {       int p = dfs(j);       a[i] += p;     }     return a[i];   }   void dfs2(int i, long double t) {     e[i] = t;     for (int j : v[i]) {       dfs2(j, t + ((long double)(a[i] - a[j] - 1)) / 2 + 1.0);     }   }   int main() {     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       int a;       cin >> a;       v[a].push_back(i);     }     dfs(1);     dfs2(1, 1.0);     cout << setprecision(10);     for (int i = 1; i <= n; i++) {       cout << e[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e6 + 11;   using ll = long long;   ll cnt[N];   ll pre[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       cnt[x]++;     }     for (int i = 1; i < N; i++)       for (int j = 1; i * j < N; j++) {         if (i == j)           pre[i * j] += cnt[i] * (cnt[i] - 1);         else           pre[i * j] += cnt[i] * cnt[j];       }     for (int i = 1; i < N; i++) pre[i] += pre[i - 1];     int q;     scanf( %d , &q);     ll all = ll(n) * (n - 1);     while (q--) {       ll x;       scanf( %d , &x);       printf( %lld n , all - pre[x - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   long long m, w[100000];   vector<long long> phiChain;   long long modPow(long long a, long long p, long long mod) {     return (p ? modPow((a * a) % mod, p / 2, mod) * ((p & 1) ? a : 1) : 1) % mod;   }   long long phi(long long x) {     long long temp = x;     for (int i = 2; i * i <= temp; i++) {       if (temp % i == 0) x = x / i * (i - 1);       while (temp % i == 0) temp /= i;     }     if (temp > 1) x = x / temp * (temp - 1);     return x;   }   long long getRemaining(int l, int r) {     if (w[l] == 1) return 1;     if (w[l] >= 50) return 50;     if (r == l + 1) return w[l];     int z = 1, c = 0;     while (z <= 50) z *= w[l], c++;     int re = getRemaining(l + 1, r);     if (re >= c)       return 50;     else       return modPow(w[l], re, 100);   }   long long solve(int l, int r, int idx) {     if (r == l + 1) return w[l] % phiChain[idx];     if (phiChain[idx] == 1) return 0;     int remaining = getRemaining(l + 1, r);     if (remaining < 50) return modPow(w[l], remaining, phiChain[idx]);     return modPow(w[l], phiChain[idx + 1] + solve(l + 1, r, idx + 1),                   phiChain[idx]);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < (n); i++) cin >> w[i];     phiChain.push_back(m);     while (phiChain.back() > 1) phiChain.push_back(phi(phiChain.back()));     cin >> q;     for (int i = 0; i < (q); i++) {       int l, r;       cin >> l >> r;       l--;       cout << solve(l, r, 0) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     string ans =   ;     int cnt = 0;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         if (cnt > 0) {           while (i >= 0 && s[i] ==  1 ) i--;           cnt = 1;           i++;         } else           ans +=  1 ;       } else {         cnt++;       }     }     while (cnt--) ans +=  0 ;     reverse(ans.begin(), ans.end());     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int a[300005], b[300005];   int main() {     int i, k, t, x, y, n, q, num1, num2;     string s;     scanf( %d , &t);     for (i = 0; i < t; i++) {       scanf( %d %d , &n, &q);       cin >> s;       s =     + s;       for (k = 0; k <= n; k++) a[k] = b[k] = 0;       if (s[1] ==  + )         a[1] = a[2] = 1;       else         a[1] = a[2] = -1;       if (s[2] ==  + )         b[2] = 1;       else         b[2] = -1;       for (k = 3; k <= n; k++) {         if (k % 2 == 1) {           if (s[k] ==  + )             a[k] = a[k - 2] + 1;           else             a[k] = a[k - 2] - 1;           b[k] = b[k - 1];         } else {           if (s[k] ==  + )             b[k] = b[k - 2] + 1;           else             b[k] = b[k - 2] - 1;           a[k] = a[k - 1];         }       }       for (k = 0; k < q; k++) {         scanf( %d %d , &x, &y);         num1 = a[y] - a[x - 1];         num2 = b[y] - b[x - 1];         if (abs(num1 - num2) > 2) {           if (abs(num1 - num2) % 2 == 1)             printf( 1 n );           else             printf( 2 n );         } else           printf( %d n , abs(num1 - num2));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   priority_queue<int, vector<int>, greater<int> > pq;   vector<int> v;   char s[300001];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     int mav = s[0], mavi = 0;     for (int i = 1; i < n; i++) {       if (s[i] < mav) return !printf( YES n%d %d , mavi + 1, i + 1);       if (mav < s[i]) {         mav = s[i];         mavi = i;       }     }     printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   int vis[3010][3010];   int A[3010], canKill[3010], canNotKill[3010], n, k;   queue<pair<int, int> > q;   void insert(int i, int j, int t) {     if (t > k) return;     if (vis[i][j] == -1) {       vis[i][j] = t;       q.push(make_pair(i, j));     }   }   void killi(int i, int j, int t) {     if (canKill[j] && A[i] != 100) insert(j, j + 1, t);   }   void killj(int i, int j, int t) {     if (A[i] && canNotKill[j]) insert(i, j + 1, t);   }   void killBoth(int i, int j, int t) {     if (A[i] && canKill[j]) insert(j + 1, j + 2, t);   }   int bfs() {     memset(vis, -1, sizeof vis);     vis[0][1] = 0;     int ans = 0;     q.push(make_pair(0, 1));     while (!q.empty()) {       int i = q.front().first, j = q.front().second;       q.pop();       ans++;       if (j >= n) continue;       killBoth(i, j, vis[i][j] + 1);       killi(i, j, vis[i][j] + 1);       killj(i, j, vis[i][j] + 1);     }     return ans;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < (n); i++) scanf( %d , A + i);     for (int i = n - 1; i >= 0; i--) canKill[i] = max(canKill[i + 1], A[i]);     canNotKill[n] = 1;     for (int i = n - 1; i >= 0; i--)       canNotKill[i] = (A[i] != 100) && canNotKill[i + 1];     cout << bfs() << endl;     return 0;   }