malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string s1(const pair<string, string> &x) { return x.first.substr(0, 3); }   string s2(const pair<string, string> &x) {     return x.first.substr(0, 2) + x.second.substr(0, 1);   }   const int MAXN = 1050;   vector<int> g[MAXN], mt;   int used[MAXN];   bool dfs(const int &v, const int &now) {     if (used[v] == now) return false;     used[v] = now;     for (auto to : g[v]) {       if (mt[to] == -1 || dfs(mt[to], now)) {         mt[to] = v;         return true;       }     }     return false;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<pair<string, string>> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;     }     map<string, int> str_idx;     map<string, bool> banned;     vector<string> idx_str;     for (char c1 =  A ; c1 <=  Z ; ++c1) {       for (char c2 =  A ; c2 <=  Z ; ++c2) {         for (char c3 =  A ; c3 <=  Z ; ++c3) {           string name =   ;           name += c1;           name += c2;           name += c3;           str_idx[name] = idx_str.size();           idx_str.emplace_back(name);         }       }     }     vector<bool> precalced(n);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (s1(a[i]) == s1(a[j])) {           precalced[i] = precalced[j] = true;         }       }     }     int cnt = 0;     for (int i = 0; i < n; ++i) {       if (precalced[i]) {         string name = s2(a[i]);         if (banned[name]) {           cout <<  NO ;           return 0;         }         ++cnt;         banned[name] = true;       }     }     for (int i = 0; i < n; ++i) {       if (!precalced[i]) {         string name1 = s1(a[i]);         string name2 = s2(a[i]);         if (!banned[name1]) {           g[i].emplace_back(str_idx[name1]);         }         if (!banned[name2]) {           g[i].emplace_back(str_idx[name2]);         }       }     }     mt.resize(30 * 30 * 30, -1);     for (int i = 0; i < n; ++i) {       if (!precalced[i]) dfs(i, i + 1);     }     for (int i = 0; i < 30 * 30 * 30; ++i) {       if (mt[i] != -1) ++cnt;     }     if (cnt == n) {       cout <<  YES n ;       vector<string> ans(n);       for (int i = 0; i < n; ++i) {         if (precalced[i]) ans[i] = s2(a[i]);       }       for (int i = 0; i < 30 * 30 * 30; ++i) {         if (mt[i] != -1) ans[mt[i]] = idx_str[i];       }       for (auto s : ans) cout << s <<   n ;     } else {       cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5;   int vis[N][N][N];   int l[N], r[N];   double get_frac(int x, int y) { return (1.0 * x) / (1.0 * y); }   double dfs(vector<vector<vector<double>>> &dp, int b, int cur, int g, int e,              int n) {     if (cur == n) {       if (g == 0)         return (e > 1) ? 1.0 : 0.0;       else if (g == 1)         return (e > 0) ? 1.0 : 0.0;       return 0.0;     }     if (vis[cur][g][e] == -1) {       vis[cur][g][e] = 0;       double p = 0;       if (g == 0 && r[cur] > b)         p += get_frac(r[cur] - max(b, l[cur] - 1), r[cur] - l[cur] + 1) *              dfs(dp, b, cur + 1, g + 1, e, n);       if (l[cur] <= b && r[cur] >= b)         p += get_frac(1, r[cur] - l[cur] + 1) * dfs(dp, b, cur + 1, g, e + 1, n);       if (l[cur] < b)         p += get_frac(min(r[cur] + 1, b) - l[cur], r[cur] - l[cur] + 1) *              dfs(dp, b, cur + 1, g, e, n);       dp[cur][g][e] = p;     }     return dp[cur][g][e];   }   double solve() {     int n, mn = 1e4 + 5, mx = 0;     double res = 0, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];       mn = min(mn, l[i]);       mx = max(mx, r[i]);     }     for (int i = mn; i <= mx; i++) {       memset(vis, -1, sizeof(vis));       vector<vector<vector<double>>> dp(           n, vector<vector<double>>(n, vector<double>(n)));       res += 1.0 * i * dfs(dp, i, 0, 0, 0, n);     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(12);     cout << solve() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long n;     cin >> n;     string str1, str2;     cin >> str1 >> str2;     long long freq1[26] = {0};     long long freq2[26] = {0};     for (long long i = 0; i < n; i++) {       freq1[str1[i] -  a ]++;       freq2[str2[i] -  a ]++;     }     for (long long i = 0; i < 26; i++) {       if (freq1[i] != freq2[i]) {         cout <<  NO n ;         return 0;       }     }     for (long long i = 0; i < 26; i++) {       if (freq1[i] >= 2) {         cout <<  YES n ;         return 0;       }     }     for (long long i = 0; i < n - 2; i++) {       long long pos = -1;       for (long long j = i; j < n; j++) {         if (str1[i] == str2[j]) {           pos = j;           break;         }       }       long long cnt = 0;       while (pos > i) {         swap(str2[pos], str2[pos - 1]);         cnt++;         pos--;       }       cnt = cnt % 2;       if (cnt == 0)         continue;       else         swap(str2[n - 1], str2[n - 2]);     }     for (long long i = 0; i < n; i++) {       if (str1[i] != str2[i]) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t-- != 0) {       long long stat = solve();     }     return 0;   }
#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];     for (int i = 0; i < n; ++i) {       if (v[i] != i + 1) {         for (int j = n - 1; j >= 0; --j) {           if (v[j] != j + 1) {             reverse(begin(v) + i, begin(v) + j + 1);             for (int k = i; k <= j; ++k) {               if (v[k] != k + 1) goto __bad;             }             cout << i + 1 <<     << j + 1 << endl;             return 0;           }         }       }     }   __bad:     cout <<  0 0 n ;     return 0;   }
#include <bits/stdc++.h>   using lint = long long int;   using pii = std::pair<int, int>;   using std::vector;   int ve[200100];   bool check[200100];   int main(void) {     int N, hol = 0;     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       int temp;       scanf( %d , &temp);       ve[i] = temp;     }     for (int i = 1; i <= N; i++) {       int temp;       scanf( %d , &temp);       hol += temp;     }     int cou = 0;     for (int i = 1; i <= N; i++) {       if (!check[i]) {         int ind = i;         cou++;         while (!check[ind]) {           check[ind] = true;           ind = ve[ind];         }       }     }     int ans = 1 - (hol % 2);     if (cou != 1) {       ans += cou;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int etf(int n) {     int res = n, i = 2;     while (n > 1) {       if (n % i == 0) {         res -= res / i;         while (n % i == 0) n /= i;       }       ++i;       if (i * i > n) i = n;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     int p;     cin >> p;     cout << etf(p - 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, w, a[N];   int main() {     cin >> n >> w;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int lo = 0, hi = w, n_lo = 0, n_hi = w;     for (int i = 0; i < n; i++) {       n_lo += a[i];       n_hi += a[i];       if (n_lo > w || n_hi < 0) return cout << 0 <<   n , 0;       if (n_lo < 0) {         lo += -n_lo;         n_lo = 0;       }       if (n_hi > w) {         hi -= n_hi - w;         n_hi = w;       }     }     cout << (hi - lo + 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000010;   struct node {     int v, id;   } MAX[MAXN], MMAX[MAXN];   int n, f[MAXN];   int main() {     scanf( %d , &n);     n++;     MAX[1].v = MMAX[1].v = 0;     MAX[1].id = MMAX[1].id = 1;     for (register int i = 2; i <= n; i++) {       scanf( %d , &f[i]);       MAX[i].v = 0;       MMAX[i].v = 0;       MAX[i].id = MMAX[i].id = i;       int now = i;       while (now) {         if (MAX[f[now]].id == now) {           if (max(MAX[now].v, MMAX[now].v + 1) > MAX[f[now]].v) {             MAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);           } else {             break;           }         } else if (MMAX[f[now]].id == now) {           if (max(MAX[now].v, MMAX[now].v + 1) > MAX[f[now]].v) {             swap(MAX[f[now]], MMAX[f[now]]);             MAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);           } else if (max(MAX[now].v, MMAX[now].v + 1) > MMAX[f[now]].v) {             MMAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);           } else {             break;           }         } else {           if (max(MAX[now].v, MMAX[now].v + 1) > MAX[f[now]].v) {             swap(MAX[f[now]], MMAX[f[now]]);             MAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);             MAX[f[now]].id = now;           } else if (max(MAX[now].v, MMAX[now].v + 1) > MMAX[f[now]].v) {             MMAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);             MMAX[f[now]].id = now;           } else {             break;           }         }         now = f[now];       }       printf( %d  , MAX[1].v);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10000001];   int main() {     int n, k = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a + 1, a + n);     while (a[0] <= a[n - 1]) {       a[0]++;       a[n - 1]--;       k++;       sort(a + 1, a + n);     }     cout << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, l, a, x, y, sum, t[1000009], px, py;     sum = 0;     px = py = 0;     cin >> n >> l >> a;     for (int i = 0; i <= n; i++) {       if (i == n) {         t[i] = l - (px + py);         break;       }       cin >> x >> y;       if (i == 0) {         t[i] = x - 0;         px = x;         py = y;       } else {         t[i] = x - (px + py);       }       px = x;       py = y;     }     for (int i = 0; i <= n; i++) {       if (t[i] >= a) {         sum += (t[i] / a);       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print(vector<long long int> &v) {     long long int n = v.size();     for (long long int i = 0; i < n; i++) cout << v[i] <<    ;     cout <<   n ;     ;     return;   }   vector<long long int> parent(200001);   vector<long long int> size1(200001);   long long int find(long long int a) {     if (a == parent[a]) return a;     return parent[a] = find(parent[a]);   }   void union1(long long int a, long long int b) {     long long int a1 = find(a);     long long int b1 = find(b);     if (a1 == b1) return;     long long int t1 = size1[a1];     long long int t2 = size1[b1];     if (t1 < t2) {       parent[a1] = b1;       size1[b1] += size1[a1];     } else {       parent[b1] = a1;       size1[a1] += size1[b1];     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n;     cin >> n;     for (long long int i = 0; i < n + 1; i++) {       parent[i] = i;       size1[i] = 1;     }     vector<string> v(n);     vector<vector<bool> > ar(n, vector<bool>(26, 0));     for (long long int i = 0; i < n; i++) {       cin >> v[i];       long long int p = v[i].length();       for (long long int j = 0; j < p; j++) {         ar[i][v[i][j] -  a ] = 1;       }     }     for (long long int j = 0; j < 26; j++) {       long long int prev = -1;       for (long long int i = 0; i < n; i++) {         if (ar[i][j] == 1) {           if (prev == -1)             prev = i;           else {             union1(prev, i);           }         }       }     }     set<long long int> st;     for (long long int i = 0; i < n; i++) {       st.insert(find(i));     }     cout << st.size() <<   n ;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, c, b, v, d, l, n;     cin >> a >> b >> c;     v = c / (b * 2);     n = c % (b * 2);     if (n > 0) {       v += 1;     }     l = n / 2 + n % 2;     if (l == 0) {       l = b;     }     if (c % 2 == 0) {       cout << v <<     << l <<     <<  R ;     } else       cout << v <<     << l <<     <<  L ;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return f == -1 ? ~x + 1 : x;   }   long long n, m;   long long a[4010];   long long ls[4010], rs[4010];   long long stk[4010], top;   void build() {     for (long long i = 1; i <= n; ++i) {       while (top && a[stk[top]] > a[i]) {         rs[stk[top]] = ls[i], ls[i] = stk[top];         --top;       }       if (top) rs[stk[top]] = i;       stk[++top] = i;     }   }   long long sz[4010], dp[4010][4010], tmp[4010];   void dfs(long long x) {     sz[x] = 1;     dp[x][1] = (m - 1) * a[x];     if (ls[x]) {       dfs(ls[x]);       for (long long i = 0; i <= sz[x] + sz[ls[x]]; ++i) tmp[i] = 0;       for (long long i = 0; i <= sz[x]; ++i) {         for (long long j = 0; j <= sz[ls[x]]; ++j) {           tmp[i + j] =               max(tmp[i + j], dp[x][i] + dp[ls[x]][j] - 2 * i * j * a[x]);         }       }       sz[x] += sz[ls[x]];       for (long long i = 0; i <= sz[x]; ++i) dp[x][i] = tmp[i];     }     if (rs[x]) {       dfs(rs[x]);       for (long long i = 0; i <= sz[x] + sz[rs[x]]; ++i) tmp[i] = 0;       for (long long i = 0; i <= sz[x]; ++i) {         for (long long j = 0; j <= sz[rs[x]]; ++j) {           tmp[i + j] =               max(tmp[i + j], dp[x][i] + dp[rs[x]][j] - 2 * i * j * a[x]);         }       }       sz[x] += sz[rs[x]];       for (long long i = 0; i <= sz[x]; ++i) dp[x][i] = tmp[i];     }   }   signed main() {     n = read(), m = read();     for (long long i = 1; i <= n; ++i) a[i] = read();     build();     dfs(stk[1]);     printf( %lld n , dp[stk[1]][m]);   }
#include <bits/stdc++.h>   using namespace std;   long long solve(vector<long long> arr, int index, int currIndex) {     if (currIndex == index) {       return 1;     } else {       return 1 + solve(arr, index, arr[currIndex] - 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long testCase;     cin >> testCase;     while (testCase--) {       long long n;       cin >> n;       vector<long long> arr;       for (int i = 0; i < n; i++) {         long long j;         cin >> j;         arr.push_back(j);       }       std::vector<int> dp(n, 0);       for (int i = 0; i < n; i++) {         if (!dp[i]) {           long long currentIndex = arr[i] - 1;           long long ans = 1;           while (currentIndex != i) {             ans++;             currentIndex = arr[currentIndex] - 1;           }           long long pos = arr[i] - 1;           dp[arr[i] - 1] = ans;           while (pos != i) {             pos = arr[pos] - 1;             dp[pos] = ans;           }         }       }       for (int i = 0; i < n; i++) {         cout << dp[i] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int N, M;   vector<int> g[maxn];   long long out[maxn], in[maxn];   int main() {     cin >> N >> M;     for (int i = 1; i <= N; ++i) {       g[i].clear();       out[i] = in[i] = 0;     }     for (int i = 1; i <= M; ++i) {       int a, b;       cin >> a >> b;       int x = max(a, b), y = min(a, b);       g[y].push_back(x);       ++out[x];       ++in[y];     }     long long ret = 0;     for (int i = 1; i <= N; ++i) {       ret += out[i] * in[i];     }     int Q;     cin >> Q;     cout << ret << endl;     for (int q = 1; q <= Q; ++q) {       int x;       cin >> x;       ret -= out[x] * in[x];       for (int i : g[x]) {         ret -= out[i] * in[i];         --out[i];         ++in[i];         g[i].push_back(x);         ret += out[i] * in[i];         ++out[x];         --in[x];       }       ret += out[x] * in[x];       g[x].clear();       cout << ret << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > neib;   struct Square {     long long max;     long long diff;     long long size;   };   vector<long long> a;   vector<Square> stat;   vector<int> color;   void dfs(int u) {     color[u] = 1;     stat[u].max += a[u];     if (neib[u].size() == 1 && u != 0) {       stat[u].max = a[u];       stat[u].diff = 0;       stat[u].size = 1;       return;     }     for (auto to : neib[u]) {       if (color[to] == 1) {         continue;       }       dfs(to);       stat[u].size += stat[to].size;       stat[u].max += stat[to].max;     }   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int n;     cin >> n;     neib.resize(n);     a.resize(n);     stat.resize(n);     color.resize(n, 0);     for (long long i = 0; i < (long long)n - 1; i++) {       int v;       cin >> v;       neib[i + 1].push_back(v - 1);       neib[v - 1].push_back(i + 1);     }     for (long long i = 0; i < (long long)n; i++) {       cin >> a[i];     }     if (n == 2) {       cout << a[0] + a[1];     } else {       dfs(0);       long long ans = -1;       for (long long i = 0; i < (long long)n; i++) {         long long t = (stat[i].max + stat[i].size - 1) / stat[i].size;         ans = max(ans, t);       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int id[105];   int A[105];   int B[105];   long long dp[77][77];   bool check(int left, int right, int pos1, int pos2) {     for (int i = 0; i < k; i++) {       if (A[i] == pos1) {         if (B[i] == pos2 && id[i] == 1) return false;         if (B[i] <= left || B[i] >= right) {           return false;         }       } else if (A[i] == pos2) {         if (B[i] == pos1 && id[i] == 1) return false;         if (B[i] <= left || B[i] >= right) {           return false;         }       } else if (B[i] == pos1) {         if (A[i] == pos2 && id[i] == 1) return false;         if (A[i] <= left || A[i] >= right) {           if (id[i] == 0) return false;         }       } else if (B[i] == pos2) {         if (A[i] == pos1 && id[i] == 1) return false;         if (A[i] <= left || A[i] >= right) {           if (id[i] == 0) return false;         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     for (int i = 0; i < k; i++) {       string s;       cin >> A[i] >> s >> B[i];       if (s ==  < ) {         id[i] = 1;       } else if (s ==  > ) {         id[i] = 1;         swap(A[i], B[i]);       } else if (s ==  = ) {         id[i] = 0;       } else if (s ==  <= ) {         id[i] = 2;       } else {         id[i] = 2;         swap(A[i], B[i]);       }     }     dp[0][2 * n + 1] = 1;     for (int i = 0; i <= 2 * n - 2; i++) {       for (int j = 2 * n + 1; j >= i + 3; j--) {         long long x = dp[i][j];         if (x == 0) continue;         if (j - i > 3 && check(i, j, i + 1, i + 2)) dp[i + 2][j] += x;         if (check(i, j, i + 1, j - 1)) dp[i + 1][j - 1] += x;         if (j - i > 3 && check(i, j, j - 2, j - 1)) dp[i][j - 2] += x;       }     }     long long answer = 0;     for (int i = 1; i < 2 * n; i++) {       answer += dp[i][i + 1];     }     cout << answer << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> vc;       vc.clear();       for (int i = 1; i <= sqrt(n); i++) {         if (n / i != i) vc.push_back(n / i);       }       int rt = sqrt(n);       cout << rt + vc.size() + 1 << endl;       cout << 0 <<    ;       for (int i = 1; i <= sqrt(n); i++) {         cout << i <<    ;       }       for (int i = vc.size() - 1; i >= 0; i--) cout << vc[i] <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> XandY, XXX, YYY;   int NOseg;   int query(int x, int y) {     cout << 0 <<     << x <<     << y << endl;     int ret;     cin >> ret;     return ret;   }   void SOLVE(int l, int r) {     if (l > r) return;     int mid = (l + r) / 2;     int x = query(mid, mid);     if (x == 0)       XandY.push_back(mid), x = 1;     else       NOseg = mid;     SOLVE(l, mid - x);     SOLVE(mid + x, r);   }   void solve() {     SOLVE(-100000000, 100000000);     for (int k : XandY) {       if (query(NOseg, k) == 0) YYY.push_back(k);       if (query(k, NOseg) == 0) XXX.push_back(k);     }   }   int main() {     solve();     cout <<  1   << XXX.size() <<     << YYY.size() << endl;     for (int x : XXX) cout << x <<    ;     cout << endl;     for (int y : YYY) cout << y <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   string s, p;   long long bin[34][34];   void read() {     cin >> n;     for (int i = 0; i <= 30; i++) {       bin[i][0] = bin[i][i] = 1;       for (int j = 1; j < i; j++) {         bin[i][j] = bin[i - 1][j - 1] + bin[i - 1][j];       }     }   }   void solve() {     string res =   ;     for (int i = 30; i >= 9; i--) {       while (n >= bin[i][9]) {         n -= bin[i][9];         res +=  b ;       }       res +=  a ;     }     cout <<  aaaaaaaa ;     for (int i = res.length() - 1; i >= 0; i--) cout << res[i];     cout <<   aaaaaaaaab n ;   }   int main() {     std::ios::sync_with_stdio(false);     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, f;   void read() { cin >> a >> b >> c >> d >> e >> f; }   void solve() {     int res = 0;     res += (a + b + f) * (a + b + f);     res -= f * f;     res -= b * b;     res -= d * d;     cout << res << endl;   }   int main() {     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[100005], B[100005];   long long pwr[15];   int main() {     int n, k, i;     long long res = 1, MOD = 1000000007, c;     cin >> n >> k;     for (i = 0; i < n / k; i++) cin >> A[i];     for (i = 0; i < n / k; i++) cin >> B[i];     for (i = pwr[0] = 1; i <= 10; i++) pwr[i] = 10 * pwr[i - 1];     for (i = 0; i < n / k; i++) {       long long l = pwr[k] - 1;       l = l / A[i] + 1;       long long t1 = pwr[k - 1];       if (B[i]) {         l = l - ((((B[i] + 1) * t1) - 1) / A[i] - ((B[i] * t1) - 1) / A[i]);       } else {         l = l - (((B[i] + 1) * t1) - 1) / A[i] - 1;       }       res = (res * l) % MOD;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int n = 8;     bool ww = 1;     int con = 0;     while (n--) {       string s;       cin >> s;       bool tb = 1;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  W ) {           tb = 0;         }       }       if (tb == 0 && ww == 1) {         for (int i = 0; i < s.size(); i++) {           if (s[i] ==  B ) {             con++;           }         }         ww = 0;       } else if (tb) {         con++;       }     }     cout << con;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define int long long       void hota(){     int n,m,x;     cin>>n>>m>>x;     vector<pair<int,int>> v;     for (int i = 0; i < n; ++i)     {      int x;      cin>>x;      v.push_back(make_pair(x,i+1));     }     sort(v.begin(), v.end());     std::vector<int> ans(m,0);     vector<pair<int,int>> r;     int j=0;     while(j<n)     {      int i =0;      while(i<m && j<n)      {       ans[i]+=v[j].first;       r.push_back(make_pair(v[j].second,i+1));       i++;       j++;      }     }     int mx = *max_element(ans.begin(), ans.end());     int mn = *min_element(ans.begin(), ans.end());     if(mx-mn>x || mn == 0)      {cout<< NO <<endl;}     else     {      sort(r.begin(), r.end());      cout<< YES <<endl;      for (int i = 0; i < n; ++i)      {       cout<<r[i].second<<   ;      }      cout<<endl;     }    }       signed main(){     std::ios::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin>>t;     for(int tc=1;tc<=t;tc++){           hota();     }    }