malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAX = 103;   long long dp[MAX][MAX][MAX];   long long tmp[MAX][MAX];   long long ncr[MAX][MAX];   long long res[MAX];   int sub[MAX];   vector<int> adj[MAX];   int modulo(int a, int b, int c) {     long long res = 1;     for (int i = 0; i < b; i++) {       res *= a;       res %= c;     }     return res % c;   }   void merge(int a, int b) {     memset(tmp, 0, sizeof tmp);     for (int i = 0; i < sub[b]; i++) {       for (int j = 1; j <= sub[b]; j++) {         for (int k = 0; k < sub[a]; k++) {           for (int l = 1; l <= sub[a]; l++) {             long long x = dp[b][i][j];             long long y = dp[a][k][l];             tmp[i + k + 1][j + l] += ((x * y) % MOD);             tmp[i + k + 1][j + l] %= MOD;             tmp[i + k][j] += ((((x * y) % MOD) * 1ll * l) % MOD);             tmp[i + k][j] %= MOD;           }         }       }     }     for (int i = 0; i < (sub[a] + sub[b]); i++) {       for (int j = 1; j <= (sub[a] + sub[b]); j++) {         dp[b][i][j] = tmp[i][j];       }     }   }   void dfs(int s, int p) {     dp[s][0][1] = 1;     sub[s] = 1;     for (int i = 0; i < adj[s].size(); i++) {       int u = adj[s][i];       if (u != p) {         dfs(u, s);         merge(u, s);         sub[s] += sub[u];       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 0);     for (int i = 0; i < n - 1; i++) {       for (int j = 1; j <= n; j++) {         dp[1][i][j] = (dp[1][i][j] * 1ll * j) % MOD;         dp[1][i][j] = (dp[1][i][j] * 1ll * modulo(n, n - i - 2, MOD)) % MOD;         res[i] += dp[1][i][j];         res[i] %= MOD;       }     }     res[n - 1] = 1;     ncr[0][0] = 1;     ncr[1][0] = 1;     ncr[1][1] = 1;     for (int i = 2; i <= n; i++) {       ncr[i][0] = 1;       for (int j = 1; j <= i; j++) {         ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % MOD;       }     }     for (int i = n - 2; i >= 0; i--) {       for (int j = i + 1; j < n; j++) {         res[i] -= ((ncr[j][i] * res[j]) % MOD);         res[i] += MOD;         res[i] %= MOD;       }     }     for (int i = 0; i < n; i++) {       printf( %lld n , res[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int xp, yp, xc, yc;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> xp >> yp >> xc >> yc;     vector<pair<int, int>> store;     while (xc != 0 || yc != 0) {       store.push_back({xc, yc});       xc--;       yc--;       xc = max(0, xc);       yc = max(0, yc);     }     store.push_back({xc, yc});     for (int i = 0; i < store.size(); i++) {       pair<int, int> h = store[i];       int z = max(0, xp - h.first) + max(0, yp - h.second);       if (z <= i) {         cout <<  Polycarp ;         return 0;       }     }     cout <<  Vasiliy ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int A(int n, int k) {     if (n < k) {       return 0;     }     long long int res = 1;     for (int i = n; i > n - k; --i) res *= i;     return res;   }   int fact(int n) {     int res = 1;     for (int i = 2; i <= n; ++i) res *= i;     return res;   }   int main() {     long long int n, m;     cin >> n >> m;     --n;     --m;     int dn = 0, dm = 0;     int lastn = 0, lastm = 0;     vector<int> dign, digm;     if (n == 0) {       dn = 1;       dign.push_back(0);     }     if (m == 0) {       dm = 1;       digm.push_back(0);     }     while (n) {       dn++;       lastn = n % 7;       dign.push_back(lastn);       n /= 7;     }     while (m) {       dm++;       lastm = m % 7;       digm.push_back(lastm);       m /= 7;     }     reverse(dign.begin(), dign.end());     reverse(digm.begin(), digm.end());     if (dn + dm > 7) {       cout << 0 << endl;       return 0;     }     long long int ans = 0;     int mask = 0;     for (; mask < (1 << 7); ++mask) {       vector<int> digits;       for (int i = 0; i < 7; ++i) {         if (mask & (1 << i)) {           digits.push_back(i);         }       }       if (digits.size() != dn + dm) continue;       for (int i = 0; i < fact(dn + dm); ++i) {         bool flag = 1;         int j = 0;         while (j < dn && digits[j] == dign[j]) ++j;         if (j < dn && digits[j] > dign[j]) flag = 0;         j = dn;         while (j < dn + dm && digits[j] == digm[j - dn]) ++j;         if (j < dn + dm && digits[j] > digm[j - dn]) flag = 0;         if (flag) {           ++ans;         }         next_permutation(digits.begin(), digits.end());       }     }     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   #define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)   #define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)   #define ll long long   #define pii pair<int, int>   #define db double   #define x first   #define y second   #define ull unsigned long long   #define sz(a) ((int) (a).size())   #define vi vector<int>   using namespace std;   const int N = 5e6 + 7;   int n, a[N], b[N], now[N];   char s[N];   void Main() {    cin >> n >> (s + 1);    int cnt = 0, cnt0 = 0, cnt1 = 0;    L(i, 1, n) if(s[i] ==  1 ) cnt ++;    cnt /= 2;    L(i, 1, n) if(s[i] ==  1 ) {     if(cnt) now[i] = 1, --cnt;     else now[i] = -1;    }    L(i, 1, n) {     if(s[i] ==  0 ) {      if(cnt0 < cnt1) a[i] = 1, b[i] = -1, cnt0 ++, cnt1 --;      else a[i] = -1, b[i] = 1, cnt0 --, cnt1 ++;     }     else {      cnt0 += now[i], cnt1 += now[i];      a[i] = b[i] = now[i];     }     if(cnt0 < 0 || cnt1 < 0) {      cout <<  NO n ;      return;     }     }    if(cnt0 || cnt1) {     cout <<  NO n ;     return;    }    cout <<  YES n ;    L(i, 1, n) cout << (a[i] == 1 ?  (  :  ) );    cout <<   n ;    L(i, 1, n) cout << (b[i] == 1 ?  (  :  ) );    cout <<   n ;   }   int main() {    ios::sync_with_stdio(false);    cin.tie(0); cout.tie(0);    int T;    cin >> T;    while(T--) Main();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &dig) {     int flg;     char c;     flg = dig = 0;     while (c = getchar(), !isdigit(c))       if (c ==  - ) flg = 1;     while (isdigit(c)) dig = dig * 10 + c -  0 , c = getchar();     if (flg) dig = -dig;   }   template <typename _T, typename... Args>   inline void read(_T &x, Args &...args) {     read(x);     read(args...);   }   const int N = 505, M = 1e5 + 5;   int n, f[N][N], a[N];   int head[M], nxt[M], tot, ver[M], v[N], in[N];   queue<int> q;   void add(int u, int v) { nxt[++tot] = head[u], head[u] = tot, ver[tot] = v; }   int main() {     read(n);     for (int i = (1); i <= (n); ++i) read(a[i]), f[i][i] = a[i];     for (int k = 2; k <= n; ++k)       for (int i = 1; i + k - 1 <= n; ++i)         for (int j = i; j < i + k - 1; ++j)           if (f[i][j] && f[i][j] == f[j + 1][i + k - 1]) {             f[i][i + k - 1] = f[i][j] + 1;             break;           }     for (int i = 1; i <= n; ++i)       for (int j = i; j <= n; ++j)         if (f[i][j]) add(i, j + 1);     memset(v, 0x3f, sizeof(v));     v[1] = 0, q.push(1);     int x, y;     while (q.size()) {       x = q.front(), q.pop(), in[x] = 0;       for (int i = head[x]; i; i = nxt[i]) {         if (v[y = ver[i]] > v[x] + 1) {           v[y] = v[x] + 1;           if (!in[y]) q.push(y), in[y] = 1;         }       }     }     printf( %d n , v[n + 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, ways = 0;     int c[100];     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> c[i];       sum = sum + c[i];     }     for (int i = 0; i < n; ++i) {       if ((sum - c[i]) % 2 == 0) ways++;     }     cout << ways << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a[n];     long long int f[100005];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int x = a[n - 1] - a[0];     long long int y = 1;     int i = 1;     while (a[i] == a[0] && i < n - 1) {       y++;       i++;     }     i = n - 2;     long long int z = 1;     while (a[i] == a[n - 1] && i > 0) {       z++;       i--;     }     if (a[n - 1] == a[0]) {       cout << x <<     << (n * (n - 1)) / 2;       exit(0);     }     cout << x <<     << z * y << endl;   }
#include <bits/stdc++.h>   using namespace std;   using pqboro = priority_queue<long long, vector<long long>, less<long long>>;   using pqchoto =       priority_queue<long long, vector<long long>, greater<long long>>;   template <typename T>   string toString(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <typename T>   long long toll(T str) {     stringstream ss;     ss << str;     long long num;     ss >> num;     return num;   }   const int N = 2e5 + 7;   const int M = 1e9 + 7;   const long long inf = 0x7f7f7f7f7f7f7f7f;   void run_for_testcase() {     long long n, m, i, j, k, x;     cin >> n >> k;     string s;     cin >> s;     vector<long long> a;     long long tot = 0;     long long cnt = 0;     i = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  W ) {         break;       }     }     for (; i < n; i++) {       if (s[i] ==  L ) {         ++cnt;         j = i + 1;         for (; j < n; j++) {           if (s[j] ==  W ) {             a.emplace_back(cnt);             cnt = 0;             break;           }           ++cnt;         }         i = j - 1;       } else {         ++tot;         j = i + 1;         for (; j < n; j++) {           if (s[j] ==  L ) {             break;           }           tot += 2;         }         i = j - 1;       }     }     if (tot == 0) {       cout << max(0LL, 2 * k - 1) << endl;       return;     }     sort(a.begin(), a.end());     for (i = 0; i < a.size(); i++) {       if (a[i] <= k) {         k -= a[i];         tot += (1 + (a[i] * 2));       } else {         tot += (k * 2);         cout << tot << endl;         return;       }     }     if (k > 0) {       if (s.front() ==  L ) {         cnt = 0;         for (i = 0; i < n; i++) {           if (s[i] ==  L ) {             ++cnt;           } else             break;         }         if (k > cnt) {           tot += (cnt * 2);           k -= cnt;         } else {           tot += (k * 2);           cout << tot << endl;           return;         }       }     }     if (k > 0) {       if (s.back() ==  L ) {         cnt = 0;         for (i = n - 1; i >= 0; i--) {           if (s[i] ==  L )             ++cnt;           else             break;         }         tot += (min(k, cnt) * 2);       }     }     cout << tot << endl;   }   int main() {     int tc;     cin >> tc;     while (tc--) run_for_testcase();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s = 0, a[200001] = {0};     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     if (n == 1) {       s = 0;     } else {       int m = 0, y = 0, f = 0;       m = a[0];       if (a[0] == 1) {         y = 1;       } else         f = 1;       for (int i = 1; i < n; ++i) {         if (a[i] == 1) {           if (a[i - 1] == 1) {             m++;           } else {             s = max(s, m);             m = 1;           }           if (f == 0) y++;         } else           f = 1;       }       if (a[n - 1] == 1) m += y;       s = max(s, m);     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string st;     cin >> st;     bool ev = false, od = false;     for (int i = 0; i < n; i++) {       if (st[i] % 2 == 1 and i % 2 == 0)         od = true;       else if (st[i] % 2 == 0 and i % 2 == 1)         ev = true;     }     if (n & 1) {       if (od) {         cout <<  1 n ;       } else         cout <<  2 n ;     } else {       if (ev)         cout <<  2 n ;       else         cout <<  1 n ;     }   }   int main() {     int tc;     cin >> tc;     while (tc--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 305;   const int inf = 0x3f3f3f3f;   const double eps = 1e-5;   int n, c;   int dp[605][N][N], a[N][N];   int max(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     memset(dp, -inf, sizeof(dp));     dp[0][1][1] = a[1][1];     int l = (n - 1) * 2;     for (int i = 1; i <= l; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) {           if (k == j)             c = a[j][i + 2 - j];           else             c = a[j][i + 2 - j] + a[k][i + 2 - k];           dp[i][j][k] = max(dp[i - 1][j - 1][k - 1], dp[i - 1][j][k - 1],                             dp[i - 1][j - 1][k], dp[i - 1][j][k]) +                         c;         }       }     }     printf( %d n , dp[l][n][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int inf = 2012345678;   const int N = 2e5 + 10;   string s, ans, tmp;   bool ch() {     int i = 0;     while (s[i] == tmp[i] && i < tmp.length()) ++i;     return i == tmp.length();   }   int main() {     int n, k;     cin >> n >> k >> s;     ans = s, --k;     int ps = 1;     while (k--) {       while (true) {         if (ps == ans.length()) {           ans += s, ps = ans.length();           break;         }         tmp = ans.substr(ps);         if (ch()) {           for (int i = tmp.length(); i < (int)(s.length()); ++i) ans += s[i];           ++ps;           break;         } else           ++ps;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   char d[8][8];   int i, j, sch, k, m;   int main() {     k = 0;     m = 0;     for (i = 0; i < 8; i++) {       sch = 0;       for (j = 0; j < 8; j++) {         cin >> d[i][j];         if (d[i][j] ==  B ) sch++;       }       if (sch == 8)         k++;       else if (sch > m)         m = sch;     }     cout << k + m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, nn = 0, range;     int a, b, c, d, pos, neg, ok = 1, finddd = 0;     int ara[200], ara2[200];     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d %d , &ara[i], &ara2[i]);       if (ara2[i] == m || ara[i] == m) {         finddd = 1;       }     }     if (n == 1 && ara[0] == 1) {       finddd = 0;     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < i; j++) {         if (ara[i] <= ara2[j]) {           pos = 1;         }       }       if (pos == 1) {         ok = 1;       } else {         ok = 0;         break;       }       pos = 0;       neg = 0;     }     if (ok == 1 && finddd == 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   char s[8][10];   int i;   vector<int> p;   int cnt() {     int v[8];     int i, j;     for (i = 0; i < n; i++) {       v[i] = 0;       for (j = 0; j < k; j++) v[i] = v[i] * 10 + (int)(s[i][p[j]] -  0 );     }     int minv = v[0];     int maxv = v[0];     for (i = 0; i < n; i++) {       if (v[i] > maxv) maxv = v[i];       if (v[i] < minv) minv = v[i];     }     return maxv - minv;   }   int main() {     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %s , s[i]);     for (i = 0; i < k; i++) p.push_back(i);     int sol = cnt();     while (next_permutation(p.begin(), p.end())) {       int res = cnt();       if (res < sol) sol = res;     }     printf( %d n , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long t, n, h, i, j, x, y, z, k, e, m;     string s;     cin >> n >> m;     x = 0;     for (i = 1; i <= n; i++) {       y = i / 5;       z = (i + m) / 5;       x += (z - y);     }     cout << x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool read(T &x) {     int c = getchar();     int sgn = 1;     while (~c && c< 0  | c>  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   const long long N = 100005;   const long long MOD = 1e9 + 7;   long long dp[N][2];   string str;   long long n;   long long solve(long long pos, long long c) {     if (pos >= n) return 0;     if (dp[pos][c] != -1) return dp[pos][c];     long long x = n;     if (c == 1) {       x = solve(pos + 1, 1) + (str[pos] >  Z );       x = min(x, solve(pos + 1, 0) + (str[pos] <  a ));     } else {       x = min(x, solve(pos + 1, 0) + (str[pos] <  a ));     }     return dp[pos][c] = x;   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> str;     n = str.size();     cout << solve(0, 1) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, u, v, a, b, A, B, C;     A = B = C = 0;     cin >> a >> b;     for (i = 1; i <= 6; i++) {       u = abs(i - a);       v = abs(i - b);       if (u < v)         A++;       else if (u == v)         B++;       else         C++;     }     cout << A <<     << B <<     << C;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int n = 10000000;   bitset<n> b;   vector<int> v;   void sieve() {     b.set();     b[0] = 0;     b[1] = 0;     for (long long i = 2; i <= n; i++) {       if (b[i]) {         v.push_back(i);         for (long long j = i * i; j <= n; j = j + i) {           b[j] = 0;         }       }     }   }   bool large_prime(long long no) {     if (no <= n) {       if (b[no]) {         return true;       } else {         return false;       }     }     for (long long i = 0; v[i] * (long long)v[i] <= no; i++) {       if (no % v[i] == 0) {         return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     sieve();     long long a, b;     while (t--) {       cin >> a >> b;       if (a - b == 1) {         long long ans = (a - b) * (a + b);         if (large_prime(ans)) {           cout <<  YES                 <<   n ;         } else {           cout <<  NO                 <<   n ;         }       } else {         cout <<  NO               <<   n ;       }     }   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   void checkmin(int &x, int y) {     if (x > y) x = y;   }   void checkmax(int &x, int y) {     if (x < y) x = y;   }   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   const int N = 20;   const int M = (1 << 20);   int n;   long long a[N], sum[M];   int dp[M], vis[M], sz[M];   signed main() {     n = read();     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       if (!a[i]) n--, i--;     }     int full = (1 << n) - 1;     for (int i = 0; i <= full; i++)       for (int j = 0; j < n; j++)         if (i >> j & 1) sum[i] += a[j], sz[i]++;     for (int mask1 = 1; mask1 <= full; mask1++) {       for (int mask2 = (mask1 - 1) & mask1; (mask2 << 1) >= mask1;            mask2 = mask1 & (mask2 - 1)) {         int mask3 = mask1 ^ mask2;         long long tmp = abs(sum[mask2] - sum[mask3]);         if (tmp < sz[mask1] && (sz[mask1] - tmp) & 1) {           vis[mask1] = 1;           break;         }       }     }     for (int i = 1; i <= full; i++)       if (vis[i]) {         int rest = full ^ i;         checkmax(dp[i], 1);         for (int j = rest; j; j = rest & (j - 1))           checkmax(dp[i | j], dp[j] + dp[i]);       }     int mx = 0;     for (int mask = 1; mask <= full; mask++) checkmax(mx, dp[mask]);     printf( %d n , n - mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long p = 1000000007;   char s[100005];   long long w[100005];   long long te[100005] = {1};   void build() {     for (int i = 1; i <= 100000; i++) {       te[i] = (te[i - 1] * 10) % p;     }   }   long long quick_mod(long long a, long long b) {     long long ans = 1;     a %= p;     while (b) {       if (b & 1) {         ans = ans * a % p;         b--;       }       b >>= 1;       a = a * a % p;     }     return ans;   }   long long C(long long n, long long m) {     if (m > n) return 0;     long long ans = 1;     for (int i = 1; i <= m; i++) {       long long a = (n + i - m) % p;       long long b = i % p;       ans = ans * (a * quick_mod(b, p - 2) % p) % p;     }     return ans;   }   int main() {     build();     long long n, k;     scanf( %I64d%I64d , &n, &k);     scanf( %s , s);     long long ans = 0;     w[n - 1] = C(n - 1, k);     long long t = w[n - 1];     for (int i = n - 1; i >= 1; i--) {       t = t * ((i - k) * quick_mod(i, p - 2) % p) % p;       w[i - 1] = (w[i] + (te[n - i - 1] * t) % p * 9) % p;     }     for (int i = 0; i < n; i++) ans = (ans + w[i] * (s[i] -  0 )) % p;     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int MAX = 1e6 + 5;   const int N = 2e5 + 5;   const long long int mod = 1e9 + 7;   const long long int mx = 1e16;   bool comp(const int a, const int b) { return a > b; }   const double PI = 2 * acos(0.0);   long long int fac[N];   void pre() {     fac[0] = 1LL;     for (long long int i = 1; i < N; i++) {       fac[i] = 1LL * i * fac[i - 1];       if (fac[i] >= mod) fac[i] %= mod;     }   }   long long int power(long long int a, long long int b) {     long long int x = 1;     while (b) {       if (b & 1) {         x *= a;         if (x >= mod) x %= mod;       }       a *= a;       if (a >= mod) a %= mod;       b >>= 1;     }     return x;   }   long long int inv(long long int k) { return power(k, mod - 2); }   string strngtoint(int n) {     ostringstream str1;     str1 << n;     string ans = str1.str();     return ans;   }   bool fun(long long int z, long long int x, long long int y, long long int p,            long long int q) {     if (p * z >= x && q * z - p * z >= y - x)       return true;     else       return false;   }   int main() {     long long t;     scanf( %lld n , &t);     while (t--) {       long long int x, y, p, q;       scanf( %lld %lld %lld %lld , &x, &y, &p, &q);       long long int low = -1, high = 1e9, mid;       if (!fun(high, x, y, p, q)) {         cout << -1 << endl;         continue;       }       while (high - low > 1) {         mid = (low + high) / 2;         if (fun(mid, x, y, p, q)) {           high = mid;         } else {           low = mid;         }       }       cout << high * q - y << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     char s1[15], s2[15], s3[15];     int p[15];     scanf( %s%s , s1, s2);     int len = strlen(s1);     int pos = 0;     for (int i = 0; i < len; i++) {       if (s1[i] ==  + )         pos++;       else         pos--;     }     int cnt = 0;     for (int i = 0; i < len; i++)       if (s2[i] ==  ? ) p[cnt++] = i;     int m = 1 << cnt, ans = 0;     for (int i = 0; i < m; i++) {       int k = i, u = 0;       strcpy(s3, s2);       for (int j = 0; j < cnt; j++) {         if (k & 1)           s3[p[u]] =  + ;         else           s3[p[u]] =  - ;         k >>= 1;         u++;       }       int w = 0;       for (int j = 0; j < len; j++) {         if (s3[j] ==  + )           w++;         else           w--;       }       if (w == pos) ans++;     }     printf( %.12f n , ans * 1.0 / m);     return 0;   }