malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double eps = 1e-4;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 7;   const int maxm = 1e6 + 7;   const double pi = acos(-1.0);   long long a[maxn];   long long b[maxn], c[maxn];   int main() {     int n;     scanf( %d , &n);     ;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i < n; i++) {       int tmp = a[i] - a[i + 1];       if (tmp < 0) tmp = -tmp;       if (i % 2 == 1) {         b[i] = tmp;         c[i] = -tmp;       } else {         b[i] = -tmp;         c[i] = tmp;       }     }     long long sum = 0;     long long mx1 = -1, mx2 = -1;     for (int i = 1; i < n; i++) {       sum += b[i];       mx1 = max(mx1, sum);       if (sum < 0) {         sum = 0;         if (i % 2 == 1) i--;       }     }     sum = 0;     for (int i = 2; i < n; i++) {       sum += c[i];       mx2 = max(mx2, sum);       if (sum < 0) {         sum = 0;         if (i % 2 == 0) i--;       }     }     cout << max(mx1, mx2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     vector<int> spareIndices;     vector<bool> LetterPresent(n);     for (int i = 0, j = s.length() - 1; i < (s.length() + 1) / 2; ++i, --j) {       if (s[i] != s[j]) {         if (s[i] ==  ? ) {           s[i] = s[j];           LetterPresent[s[i] -  a ] = true;           continue;         }         if (s[j] ==  ? ) {           s[j] = s[i];           LetterPresent[s[i] -  a ] = true;           continue;         }         cout <<  IMPOSSIBLE ;         return 0;       }       if (s[i] ==  ? ) {         spareIndices.push_back(i);         continue;       }       LetterPresent[s[i] -  a ] = true;     }     vector<char> unused_letters;     for (int i = 0; i < LetterPresent.size(); ++i) {       if (!LetterPresent[i]) unused_letters.push_back( a  + i);     }     if (unused_letters.size() > spareIndices.size()) {       cout <<  IMPOSSIBLE ;       return 0;     }     int a = spareIndices.size() - unused_letters.size();     int i = 0;     for (; i < a; ++i) {       s[spareIndices[i]] = s[s.size() - 1 - spareIndices[i]] =  a ;     }     for (; i < spareIndices.size(); ++i) {       s[spareIndices[i]] = s[s.size() - 1 - spareIndices[i]] =           unused_letters[i - a];     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   char s[1000001], t[1000001];   long long z[1000001], c[1000001];   int main() {     int n, k;     scanf( %d%d%s%s , &n, &k, s + 1, t + 1);     if (k == 1) {       printf( %d n , k * n);       return 0;     }     int o = 1;     while (o <= n && s[o] == t[o]) o++;     if (o > n) {       printf( %d n , n);       return 0;     }     long long ans = n + (n - o + 1);     k -= 2;     o++;     while (o <= n) {       if (s[o] ==  a ) z[n - o + 1]++;       if (t[o] ==  b ) z[n - o + 1]++;       o++;     }     for (int i = n; i; i--) {       z[i] += c[i];       c[i - 1] += c[i];       int kk = min(1ll * k, z[i]);       ans += 1ll * i * kk;       k -= kk;       c[i - 1] += kk;     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   long long rights[1000010], lefts[1000010], mins[1000010];   long long suml[1000010], sumr[1000010];   int min(int a, int b) { return a < b ? a : b; }   int main() {     scanf( %d , &n);     cin >> s;     lefts[0] = 0;     rights[n - 1] = 0;     for (int i = 1; i < n; i++) {       if (s[i - 1] ==  U ) lefts[i]++;       lefts[i] += lefts[i - 1];     }     for (int i = n - 2; i >= 0; i--) {       if (s[i + 1] ==  D ) rights[i]++;       rights[i] += rights[i + 1];     }     for (int i = 0; i < n; i++)       mins[i] = min(lefts[i] + (s[i] ==  U  ? 1 : 0),                     rights[i] + (s[i] ==  D  ? 1 : 0));     long long t = 0;     queue<long long> q;     for (int i = 0; i < n; i++) {       t += q.size();       if (q.size() <= mins[i]) {         suml[i] = t;       } else {         while (q.size() > mins[i]) {           t -= i - q.front();           q.pop();         }         suml[i] = t;       }       if (s[i] ==  U ) q.push(i);     }     while (!q.empty()) q.pop();     t = 0;     for (int i = n - 1; i >= 0; i--) {       t += q.size();       if (q.size() <= mins[i]) {         sumr[i] = t;       } else {         while (q.size() > mins[i]) {           t -= q.front() - i;           q.pop();         }         sumr[i] = t;       }       if (s[i] ==  D ) q.push(i);     }     for (long long i = 0; i < n; i++) {       if (rights[i] > lefts[i]) {         cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ;       } else if (rights[i] < lefts[i]) {         cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ;       } else {         if (s[i] ==  D )           cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ;         else           cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 2e5 + 5;   vector<int> v(MX);   struct Q {     int t, l, r;   };   vector<Q> qs(MX);   int n, q, m, p;   int main() {     cin >> n >> q >> m;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= q; i++) cin >> qs[i].t >> qs[i].l >> qs[i].r;     while (m--) {       cin >> p;       for (int i = q; i > 0; i--) {         if (p < qs[i].l || p > qs[i].r) continue;         if (qs[i].t == 1) {           p--;           if (p < qs[i].l) p = qs[i].r;         } else           p = qs[i].r - (p - qs[i].l);       }       cout << v[p] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> v;   int main(void) {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char s[50];       scanf( %s , &s);       v.push_back((string)s);     }     int res = 0;     while (true) {       int ok = 1;       for (int i = 0; i < n; i++)         if (v[i][res] != v[0][res]) {           printf( %d n , res);           return 0;         }       res++;     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       if (a == b) {         if (a == 0)           cout << 0 <<   n ;         else           cout << 1 <<   n ;       } else if ((a + b) % 2)         cout << -1 <<   n ;       else         cout << 2 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, carry = 0, flag = 1;     cin >> n;     int ar[n];     for (i = 0; i < n; i++) {       cin >> ar[i];       if (ar[i] == 0 && carry == 1) {         flag = 0;       }       if (ar[i] % 2 == 0 && carry == 0) {         continue;       }       if (i == (n - 1)) {         if (ar[i] % 2 == 0 && carry == 1) {           cout <<  NO n ;           return 0;         }         if (ar[i] % 2 == 1 && carry == 0) {           cout <<  NO n ;           return 0;         }       }       if (ar[i] % 2 == 1 && carry == 1) {         carry = 0;         continue;       }       carry = 1;     }     if (flag == 0) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-12;   struct P {     double x, y;     P(double x = 0, double y = 0) : x(x), y(y){};   } a, b, c, o, p;   P operator+(P a, P b) { return P(a.x + b.x, a.y + b.y); }   P operator*(P a, double b) { return P(a.x * b, a.y * b); }   inline double dis(P a, P b) {     return sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y)));   }   inline void read(P &a) { scanf( %lf%lf , &a.x, &a.y); }   double t1, t2, l, r, m, m1, m2, ab, bc, ac, ap;   double Calc(double k) {     p = b * (1 - k) + c * k;     ap = dis(a, p);     if (ap + bc * (1 + k) < t1 && ap + bc * (1 - k) < t2)       return min(t1 - bc * (1 + k), t2 - bc * (1 - k));     double l = 0, r = 1;     for (int i = 0; i < 100; ++i) {       m = (l + r) * 0.5;       o = a * (1 - m) + p * m;       if (ap * m + dis(o, b) + bc < t1 && ap * m + dis(o, c) < t2)         l = m;       else         r = m;     }     return (l + r) * 0.5 * ap;   }   int main() {     scanf( %lf%lf , &t1, &t2);     read(a);     read(c);     read(b);     ab = dis(a, b);     bc = dis(b, c);     ac = dis(a, c);     t1 += ab + bc + eps;     t2 += ac + eps;     if (ab + bc < t2) {       printf( %.10lf n , min(t1, t2));       return 0;     }     l = 0, r = 1;     for (int i = 0; i < 100; ++i) {       m1 = (l + l + r) / 3;       m2 = (l + r + r) / 3;       if (Calc(m1) < Calc(m2))         l = m1;       else         r = m2;     }     printf( %.10lf n , Calc((l + r) * .5));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(istream& in, ostream& out) {     int n;     in >> n;     int res = n % 2 ? 0 : 1LL << (n / 2);     out << res << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     std::istream& in(std::cin);     std::ostream& out(std::cout);     solve(in, out);   }
#include <bits/stdc++.h>   using namespace std;   long long mi, mx, n, ta, tb, tc;   void C(long long x, long long y, long long z) {     ta = (x + 1) * (y + 2) * (z + 2);     if (ta > mx) mx = ta;     if (ta < mi) mi = ta;   }   int main() {     long long a, b, c, d, uu;     uu = 1000000;     scanf( %I64d , &n);     int k = (int)sqrt(double(n));     mx = -999;     mi = uu * uu * uu;     for (int i = 1; i <= k; i++) {       if (n % i == 0) {         a = i;         b = n / i;         int kk = (int)sqrt(double(b));         for (int j = 1; j <= kk; j++)           if (b % j == 0) {             c = b / j;             d = j;             C(a, c, d);             C(c, a, d);             C(d, a, c);           }       }     }     printf( %I64d %I64d n , mi - n, mx - n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long expo(long long a, long long b, long long m) {     long long result = 1;     while (b) {       if (b & 1) {         result = (result * a) % m;       }       b = (b >> 1) % m;       a = (a * a) % m;     }     return result;   }   double expof(double a, int b) {     double result = 1;     while (b) {       if (b & 1) {         result = (result * a);       }       b = (b >> 1);       a = (a * a);     }     return result;   }   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.second < b.second) return true;   }   int main() {     long long m, n, t, c, l, x;     vector<pair<long long, pair<long long, long long> > > p;     vector<long long> v;     cin >> m;     long long ans = 0;     for (int i = 0; i < m; ++i) {       cin >> t;       if (t == 1) {         cin >> x;         ans++;         v.push_back(ans);         p.push_back(make_pair(1, make_pair(x, 0)));       } else {         cin >> l >> c;         ans += c * l;         v.push_back(ans);         p.push_back(make_pair(2, make_pair(l, c)));       }     }     cin >> n;     long long q[100005];     for (int i = 0; i < n; ++i) {       cin >> q[i];     }     for (int i = 0; i < n; ++i) {       x = q[i];       vector<long long>::iterator it = upper_bound(v.begin(), v.end(), x);       long long ix = it - v.begin();       ix--;       if (v[ix] == x) {         if (p[ix].first == 1) {           cout << p[ix].second.first <<    ;           continue;         } else {           x = p[ix].second.first;         }       } else {         if ((x - v[ix]) % p[ix + 1].second.first == 0) {           x = p[ix + 1].second.first;         } else           x = (x - v[ix]) % p[ix + 1].second.first;       }       while (1) {         vector<long long>::iterator it = upper_bound(v.begin(), v.end(), x);         long long ix = it - v.begin();         ix--;         if (v[ix] == x) {           if (p[ix].first == 1) {             cout << p[ix].second.first <<    ;             break;           } else {             x = p[ix].second.first;             continue;           }         }         if ((x - v[ix]) % p[ix + 1].second.first == 0) {           x = p[ix + 1].second.first;         } else           x = (x - v[ix]) % p[ix + 1].second.first;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 200005;   const int MOD = 1e9 + 9;   vector<int> g[MAXN];   int n, m, q, ans;   int rows[MAXN];   bool vist[MAXN];   pair<int, int> samp[MAXN];   void dfs(int st) {     if (vist[st]) return;     vist[st] = 1;     for (int i = 0; i < g[st].size(); i++) {       dfs(g[st][i]);     }   }   void buildG() {     sort(samp, samp + q);     for (int i = 1; i < q; ++i) {       int r = samp[i].first, c = samp[i].second;       int rl = samp[i - 1].first, cl = samp[i - 1].second;       if (r == rl) {         g[c].push_back(cl);         g[cl].push_back(c);       }     }   }   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < q; ++i) {       int r, c;       scanf( %d %d , &r, &c);       r--;       c--;       rows[r] = 1;       samp[i] = {r, c};     }     buildG();     for (int i = 0; i < m; ++i) {       if (!vist[i]) {         ans++;         dfs(i);       }     }     ans--;     for (int i = 1; i < n; ++i) rows[i] += rows[i - 1];     ans += n - rows[n - 1];     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     const long maxSteps = 1000000000;     long n, m;     cin >> n >> m;     long x, y;     cin >> x >> y;     int k;     cin >> k;     long long total = 0;     while (k--) {       long dx = 0, dy = 0;       cin >> dx >> dy;       long stepsX = maxSteps, stepsY = maxSteps;       if (dx > 0) {         stepsX = (n - x) / dx;       } else if (dx < 0) {         stepsX = (x - 1) / -dx;       }       if (dy > 0) {         stepsY = (m - y) / dy;       } else if (dy < 0) {         stepsY = (y - 1) / -dy;       }       long stepsnum = 0;       if (stepsY > 0 && stepsX > 0) {         stepsnum = min(stepsX, stepsY);       }       x += stepsnum * dx;       y += stepsnum * dy;       total += stepsnum;     }     cout << total;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int link, next;   } e[100010];   int n, k, f[50010][510], h[100010], jud[50010], tt = 0;   long long ans[50010], tot;   void addEdge(int x, int y) {     tt++;     e[tt].link = y;     e[tt].next = h[x];     h[x] = tt;   }   void dfs(int x) {     jud[x] = 1;     f[x][0] = 1;     for (int i = h[x]; i != 0; i = e[i].next)       if (jud[e[i].link] == 0) {         int y = e[i].link;         dfs(y);         for (int j = 0; j < k; j++)           ans[x] = ans[x] + 1LL * f[x][j] * f[y][k - j - 1];         for (int j = 0; j < k; j++) f[x][j + 1] += f[y][j];       }     tot += ans[x];     return;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       addEdge(a, b);       addEdge(b, a);     }     memset(jud, 0, sizeof(jud));     dfs(1);     cout << tot << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int st[100100][20];   vector<int> graph[100100], ind[100100];   int lev[100100];   int t[100100], l[100100], lg[100100];   int s[100100];   void blg(int n) {     lg[0] = -1;     for (int i = 0; i < n; ++i) lg[i + 1] = lg[i] + !(i & (i + 1));   }   void dfs(int u, int p, int l) {     st[u][0] = p;     for (int i = 1; (1 << i) <= l; ++i) st[u][i] = st[st[u][i - 1]][i - 1];     lev[u] = l;     for (int v : graph[u])       if (v != p) dfs(v, u, l + 1);   }   int getParent(int u, int d) {     if (lev[u] < d) return -1;     for (int i = d; i; i -= i & -i) u = st[u][lg[i & -i]];     return u;   }   int LCA(int u, int v) {     if (lev[u] < lev[v]) v = getParent(v, lev[v] - lev[u]);     if (lev[u] > lev[v]) u = getParent(u, lev[u] - lev[v]);     int r = lev[u], l = 0, m;     while (l < r) {       m = (l + r) / 2;       if (getParent(u, m) == getParent(v, m))         r = m;       else         l = m + 1;     }     return getParent(u, l);   }   int solve(int u, int p) {     int y = l[u] - t[u];     for (int j = 0; j < graph[u].size(); ++j) {       int v = graph[u][j];       if (v != p) {         y += s[ind[u][j]] = solve(v, u);       }     }     return y;   }   int main() {     int n, k, x, y;     cin >> n;     blg(n);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &x, &y);       graph[x].push_back(y), graph[y].push_back(x);       ind[x].push_back(i);       ind[y].push_back(i);     }     dfs(1, 1, 0);     cin >> k;     while (k--) {       scanf( %d%d , &x, &y);       t[LCA(x, y)] += 2;       l[x]++, l[y]++;     }     solve(1, 0);     for (int i = 1; i < n; ++i) cout << s[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 2;   const long long mod = 998244353;   long long fpow(long long a, long long b) {     if (b == 0) return 1;     long long cur = fpow(a, b >> 1);     cur *= cur;     cur %= mod;     if (b & 1) cur *= a;     return cur % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, L, R;     cin >> n >> m >> L >> R;     long long dif = R - L + 1;     long long par = 0, impar = 0;     if (L & 1)       impar = dif >> 1ll, par = dif - impar;     else       par = dif >> 1ll, impar = dif - par;     if (n * m & 1)       cout << fpow(par + impar, n * m) <<   n ;     else       cout << ((((fpow(par + impar, n * m) + fpow(par - impar, n * m)) *                  fpow(2, mod - 2)) %                 mod) +                mod) %                   mod            <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool tomax(T &x, T y) {     if (x < y) return x = y, 1;     return 0;   }   template <class T>   bool tomin(T &x, T y) {     if (x > y) return x = y, 1;     return 0;   }   int A[400005], n, K;   int cnt[400005], B[400005], res;   void Add(int x, int v) {     if (cnt[x] == 0 && v > 0) res++;     if (cnt[x] == 1 && v < 0) res--;     cnt[x] += v;   }   bool Check() {     int p = log2(res);     if (1.0 * pow(2, p) != 1.0 * res) p++;     return 1LL * p * n <= 8LL * K;   }   bool check(int x) {     if (x == n) return 1;     memset(cnt, 0, sizeof(cnt));     x = n - x;     res = 0;     for (int i = 1; i <= x; i++) Add(A[i], 1);     if (Check()) return 1;     for (int i = x + 1; i <= n; i++) {       Add(A[i - x], -1), Add(A[i], 1);       if (Check()) return 1;     }     return 0;   }   int main() {     cin >> n >> K;     for (int i = 1; i <= n; i++) scanf( %d , &A[i]), B[i] = A[i];     sort(B + 1, B + 1 + n);     int len = unique(B + 1, B + 1 + n) - B - 1;     for (int i = 1; i <= n; i++) A[i] = lower_bound(B + 1, B + 1 + len, A[i]) - B;     sort(A + 1, A + 1 + n);     int L = 0, R = n, ans = 0;     while (L <= R) {       int mid = L + R >> 1;       if (check(mid))         ans = mid, R = mid - 1;       else         L = mid + 1;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   const double PI = atan(1) * 4;   const double E = exp(1);   const int oo = 1e9;   const int eps = 1e-9;   using namespace std;   bool vo(char c) {     return (c ==  a  or c ==  e  or c ==  i  or c ==  o  or c ==  u );   }   int main() {     ios::sync_with_stdio(0);     string s;     cin >> s;     bool b = true;     for (int i = 0; i < ((int)((s).size())) and b; i++) {       if ((!vo(s[i]) and s[i] !=  n ) and           (i + 1 >= ((int)((s).size())) or !vo(s[i + 1])))         b = false;     }     if (b)       cout <<  YES n ;     else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n;     long long int a[100000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       cout << a[i] + a[i + 1] <<    ;     }     cout << a[n - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   const int INF = 1;   const double eps = 1e-10;   int N, M, T = INF, Cases = 0;   int arr[MAXN];   char a[MAXN], b[MAXN];   long long zeros[MAXN], ones[MAXN];   int main() {     while (T-- && gets(a + 1) && gets(b + 1)) {       a[0] = b[0] =  ? ;       N = strlen(a) - 1;       M = strlen(b) - 1;       memset(ones, 0, sizeof(ones));       memset(zeros, 0, sizeof(zeros));       for (int i = 1; i <= M; i++) {         if (b[i] ==  1 )           ones[i] = ones[i - 1] + 1, zeros[i] = zeros[i - 1];         else           ones[i] = ones[i - 1], zeros[i] = zeros[i - 1] + 1;       }       int sp = M - N;       long long ans = 0;       for (int i = 1; i <= N; i++) {         int j = i + sp;         if (a[i] ==  0 )           ans += ones[j] - ones[i - 1];         else           ans += zeros[j] - zeros[i - 1];       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 50;   const long long oo = 1e9;   const long long mod = 998244353;   long long dp[2][510][510], cnt[501], p[501];   int main() {     int n, k;     scanf( %d%d , &n, &k);     dp[0][0][0] = 1;     for (int i = 0; i < n; i++) {       int q = i % 2;       memset(dp[!q], 0, sizeof(dp[!q]));       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= n; k++) {           dp[!q][j + 1][max(j + 1, k)] =               (dp[!q][j + 1][max(j + 1, k)] + dp[q][j][k]) % mod;           dp[!q][1][max(k, 1)] = (dp[!q][1][max(k, 1)] + dp[q][j][k]) % mod;         }       }     }     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) cnt[i] = (cnt[i] + dp[n % 2][j][i]) % mod;     for (int i = 0; i <= n; i++) {       p[i + 1] = (p[i + 1] + p[i]) % mod;       p[i + 1] = (p[i + 1] + cnt[i]) % mod;     }     long long ans = 0;     for (int i = 1; i <= n; ++i)       ans = (ans + (cnt[i] * p[min(n + 1, (k - 1) / i + 1)]) % mod) % mod;     ans = (ans * ((mod + 1) / 2)) % mod;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1000;   long long a, b, p, x;   long long qpow(long long x, long long y, long long MOD) {     long long res = 1;     while (y) {       if (y & 1) res = (res * x) % MOD;       x = (x * x) % MOD;       y = y >> 1;     }     return res;   }   int main() {     scanf( %lld%lld%lld%lld , &a, &b, &p, &x);     long long ans = 0;     for (long long i = 1; i < p; i++) {       long long tp = qpow(a, i, p);       long long invt = qpow(tp, p - 2, p);       long long invp = qpow(p - 1, p - 2, p);       long long y = ((b * invt - i + p) % p * invp) % p;       long long ty = (x - i) / (p - 1);       if (i + y * (p - 1) > x) continue;       long long anst = (ty - y) / p + 1;       ans = ans + anst;     }     printf( %lld n , ans);     return 0;   }