malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 5001;   const int B = 27;   int zhu[B], n, m;   char s[N], t[N];   void solve() {     memset(zhu, 0, sizeof(zhu));     n = strlen(s);     m = strlen(t);     for (int i = 0; i < n; ++i) zhu[s[i] -  a ]++;     int r = -1, p;     if (n > m)       p = m;     else       p = min(n, m) - 1;     for (int i = t[0] -  a  + 1; i < 26; ++i)       if (zhu[i]) r = 0;     for (int i = 1; i <= p; ++i) {       zhu[t[i - 1] -  a ]--;       if (zhu[t[i - 1] -  a ] < 0) break;       if (i == m) {         r = m;         continue;       }       for (int j = t[i] -  a  + 1; j < 26; ++j)         if (zhu[j]) r = i;     }     if (r == -1) {       printf( -1 n );       return;     } else {       memset(zhu, 0, sizeof(zhu));       for (int i = 0; i < n; ++i) zhu[s[i] -  a ]++;       for (int i = 0; i < r; ++i) {         printf( %c , t[i]);         zhu[t[i] -  a ]--;       }       if (r < m)         for (int i = t[r] -  a  + 1; i < 26; ++i)           if (zhu[i]) {             printf( %c , i +  a );             zhu[i]--;             break;           }       for (int i = 0; i < 26; ++i)         while (zhu[i]--) printf( %c , i +  a );       printf(  n );     }   }   int main() {     while (~scanf( %s%s , s, t)) solve();   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int fac[2000010], inv[2000010], f[2000010];   inline int Power(int x, int y, int Q) {     int ret = 1;     while (y) {       if (y & 1) ret = 1ll * ret * x % Q;       x = (1ll * x * x) % Q;       y >>= 1;     }     return ret;   }   int main() {     int n = read(), m = read(), a = read(), Q = read();     int p = 1;     for (int i = a; i != 1; i = (1ll * i * a % Q), p++)       ;     fac[1] = 1;     for (int i = (2); i <= (max(n, m)); i++) fac[i] = 1ll * fac[i - 1] * i % p;     inv[0] = inv[1] = 1;     for (int i = (2); i <= (max(n, m)); i++)       inv[i] = 1ll * (p - p / i) * inv[p % i] % p;     for (int i = (2); i <= (max(n, m)); i++)       inv[i] = 1ll * inv[i - 1] * inv[i] % p;     f[0] = 1;     for (int i = (1); i <= (m); i++) {       f[i] = (f[i - 1] + (1ll * fac[m] * inv[m - i] % p * inv[i] % p)) % p;     }     for (int i = (m + 1); i <= (n); i++) f[i] = f[i - 1];     for (int i = n; i >= 1; i--) printf( %d  , Power(a, f[i - 1], Q));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x;   int dist[501][501];   bool color[501];   unsigned short num_red;   unsigned short ans[501][501][501], best[501][501], sizes[501];   unsigned short inf = ~0;   vector<unsigned short> edge[501];   void dfs(unsigned short& now, unsigned short& before) {     for (int i = 0; i < edge[now].size(); i++) {       unsigned short& next = edge[now][i];       if (next == before) continue;       dfs(next, now);     }     for (int i = 1; i <= n; i++)       if (dist[now][i] <= x) {         sizes[now] = 1;         ans[now][i][1] = !color[i];         for (int j = 0; j < edge[now].size(); j++) {           unsigned short& next = edge[now][j];           if (next == before) continue;           int num_node;           if (num_red < sizes[now] + sizes[next])             num_node = num_red;           else             num_node = sizes[now] + sizes[next];           for (unsigned short k = num_node;; k--) {             unsigned short temp = inf;             int num_node_1 = k - sizes[now];             if (num_node_1 < 0) num_node_1 = 0;             int num_node_2 = k;             if (k > sizes[next]) num_node_2 = sizes[next];             for (unsigned short j = num_node_1; j <= num_node_2; j++) {               if (temp > ans[now][i][k - j] + best[next][j])                 temp = ans[now][i][k - j] + best[next][j];             }             num_node_1++;             for (unsigned short j = num_node_1; j <= num_node_2; j++) {               if (temp > ans[now][i][k - j + 1] + ans[next][i][j] - !color[i])                 temp = ans[now][i][k - j + 1] + ans[next][i][j] - !color[i];             }             ans[now][i][k] = temp;             if (!k) break;           }           sizes[now] += sizes[next];         }       }     for (unsigned short i = 1; i <= num_red; i++) {       best[now][i] = inf;       for (unsigned short j = 1; j <= n; j++) {         best[now][i] = min(best[now][i], ans[now][j][i]);       }     }   }   int main() {     num_red = 0;     memset(ans, 0xff, sizeof ans);     memset(best, 0xff, sizeof best);     memset(dist, 0x3f3f, sizeof dist);     cin >> n >> x;     unsigned short col;     for (int i = 1; i <= n; i++) {       cin >> col;       num_red += col;       color[i] = col == 1;     }     unsigned short a, b;     int cost;     for (int i = 1; i < n; i++) {       cin >> a >> b >> cost;       edge[a].push_back(b);       edge[b].push_back(a);       dist[a][b] = dist[b][a] = cost;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dist[i][j] = i == j ? 0 : min(dist[i][j], dist[i][k] + dist[k][j]);         }       }     }     unsigned short start = 1;     unsigned short before = 0;     dfs(start, before);     if (best[1][num_red] == inf)       cout << -1 << endl;     else       cout << best[1][num_red] << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int main() {     int T, i, j, k, ca = 0, n, m;     int x1, y1, x2, y2;     while (~scanf( %d%d%d%d , &x1, &y1, &x2, &y2)) {       scanf( %d , &n);       int ans = 0, a, b, c;       while (n--) {         scanf( %d%d%d , &a, &b, &c);         long long first = 1LL * a * x1 + 1LL * b * y1 + c,                   second = 1LL * a * x2 + 1LL * b * y2 + c;         if (first > 0 && second < 0)           ans++;         else if (first < 0 && second > 0)           ans++;       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e9 + 7;   vector<long long int> v;   long long int calcmulti(string s, long long int l, long long int r) {     long long int ans = 1;     string z =   ;     for (long long int i = l; i <= r; i++) {       if (s[i] ==  * ) {         ans *= stoll(z);         z =   ;       } else         z += s[i];     }     ans *= stoll(z);     return ans;   }   long long int calc(string s, long long int ss, long long int st) {     if (ss == st) return s[ss] -  0 ;     long long int mid = (ss + st) / 2, mindist = MAXN;     for (long long int i = mid; i <= st; i++) {       if (s[i] ==  + ) {         mindist = min(mindist, i);         break;       }     }     for (long long int i = mid; i >= ss; i--) {       if (s[i] ==  + ) {         mindist = min(mindist, i);         break;       }     }     if (mindist == MAXN) return calcmulti(s, ss, st);     return calc(s, ss, mindist - 1) + calc(s, mindist + 1, st);   }   long long int change(string s, long long int ss, long long int st) {     string z;     long long int ans = calc(s, ss, st);     for (long long int i = 0; i <= ss - 1; i++) z += s[i];     z += to_string(ans);     for (long long int i = st + 1; i <= (long long int)s.length() - 1; i++)       z += s[i];     return calc(z, 0, (long long int)z.length() - 1);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int ans = 0;     string s;     cin >> s;     for (long long int i = 0; i < s.length(); i++)       if (s[i] ==  * ) v.push_back(i);     if (v.size() == 0) {       cout << calc(s, 0, (long long int)s.length() - 1);       return 0;     }     if (v.size() == 1) {       cout << max(change(s, 0, v[0] - 1),                   max(change(s, v[0] + 1, (long long int)s.length() - 1),                       calc(s, 0, (long long int)s.length() - 1)));       ;       return 0;     }     ans = max(ans, calc(s, 0, (long long int)s.length() - 1));     for (long long int i = 0; i < (long long int)v.size(); i++) {       ans = max(ans, change(s, 0, v[i] - 1));       ans = max(ans, change(s, v[i] + 1, (long long int)s.length() - 1));       for (long long int j = i + 1; j < (long long int)v.size(); j++) {         ans = max(ans, change(s, v[i] + 1, v[j] - 1));       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     unsigned n(0);     cin >> n;     vector<unsigned> array(n, 0);     for (unsigned it(0); it != n; ++it) {       array[it] = it + 1;     }     --n;     for (unsigned it(n); it > 0; --it) {       swap(array[it], array[it - 1]);     }     ++n;     for (unsigned it(0); it != n; ++it) {       cout << array[it] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     cout << a[1] - a[0] <<     << a[n - 1] - a[0] << endl;     for (int i = 1; i < n - 1; i++)       cout << min(a[i + 1] - a[i], a[i] - a[i - 1]) <<                << max(a[n - 1] - a[i], a[i] - a[0]) << endl;     cout << a[n - 1] - a[n - 2] <<     << a[n - 1] - a[0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long tab[70];   void Tab() {     for (int i = 0; i < 64; i++) tab[i] = pow(2, i);   }   long long Sum(long long n) {     long long m = n + 1;     if ((long long)(m) % 2 == 0)       m /= 2;     else       n /= 2;     long long sum = m * n;     return sum;   }   long long Sum1(long long n) {     long long sum1 = pow(2, n) - 1;     return sum1;   }   int Find(long long n) {     int i = 0;     for (; i < 64; i++) {       if (tab[i] > n) break;     }     return i;   }   int main() {     Tab();     long long ans, sum, sum1;     int t;     long long n;     cin >> t;     while (t--) {       ans = 0;       cin >> n;       sum = Sum(n);       long long site = Find(n);       sum1 = Sum1(site);       ans = sum - sum1 - sum1;       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const long long oo = 1LL << 60;   const long long kNumMoves = 4;   const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};   struct Line {     Line() : m(0), c(0) {}     Line(long long slope, long long yOrd) : m(slope), c(yOrd) {}     long long m;     long long c;   };   class ConvexHullOptimization {    public:     ConvexHullOptimization(int n) : cur(0), lines(n), count(0) {}     void Add(long long m, long long c) {       Line newLine(m, c);       while (!KeepCurrentTop(newLine)) --count;       lines[count++] = newLine;     }     void Reset() { cur = count = 0; }     long long GetValue(long long x) {       if (cur >= count) cur = count - 1;       while ((cur < count - 1) && ((lines[cur].m * x + lines[cur].c) >=                                    (lines[cur + 1].m * x + lines[cur + 1].c)))         ++cur;       return lines[cur].m * x + lines[cur].c;     }       private:     bool KeepCurrentTop(const Line& l3) {       if ((count - cur) < 2) return true;       Line l2 = lines[count - 1];       Line l1 = lines[count - 2];       long double newCost = (l3.c - l1.c) * (long double)(l1.m - l2.m);       long double oldCost = (l2.c - l1.c) * (long double)(l1.m - l3.m);       return newCost > oldCost;     }     int cur;     int count;     vector<Line> lines;   };   int n, m, p;   vector<long long> d, t, accum;   long long GetMinWaitingTime() {     vector<vector<long long> > dp(m, vector<long long>(2, 0));     for (int i = 0; i < int(m); ++i) dp[i][0] = (i + 1) * t[i] - accum[i];     long long res = oo;     ConvexHullOptimization chOpt(m + 1);     for (int i = 1; i < int(p); ++i) {       int curIdx = (i & 1);       int prevIdx = curIdx ^ 1;       chOpt.Reset();       chOpt.Add(-1, accum[0] + dp[0][prevIdx]);       for (int k = 1; k < int(m); ++k) {         dp[k][curIdx] = dp[k][prevIdx];         dp[k][curIdx] =             min(dp[k][curIdx], (k + 1) * t[k] - accum[k] + chOpt.GetValue(t[k]));         chOpt.Add(-(k + 1), accum[k] + dp[k][prevIdx]);       }       res = min(res, dp[m - 1][curIdx]);     }     return res;   }   int main() {     cin >> n >> m >> p;     d.resize(n, 0);     for (int i = 0; i < int(n - 1); ++i) cin >> d[i + 1];     accum.resize(n, 0);     for (int i = 0; i < int(n - 1); ++i) accum[i + 1] = accum[i] + d[i + 1];     t.resize(m);     for (int i = 0; i < int(m); ++i) {       int h;       cin >> h >> t[i];       t[i] -= accum[--h];     }     sort(t.begin(), t.end());     long long mn = t.front();     for (int i = 0; i < int(m); ++i) t[i] -= mn;     accum.clear();     accum.resize(m, 0);     accum[0] = t[0];     for (int i = 0; i < int(m - 1); ++i) accum[i + 1] = accum[i] + t[i + 1];     long long res = GetMinWaitingTime();     cout << res;     int i;     cin >> i;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, in[5100], st[5100], f[5100], ans = 9999999999999;   signed main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> in[i];     }     memset(f, 0x7f, sizeof(f));     memcpy(st, in, sizeof(in));     sort(st + 1, st + n + 1);     for (long long i = 1; i <= n; i++) f[i] = 0;     for (long long i = 1; i <= n; i++) {       for (long long o = 1; o <= n; o++) {         f[o] = min(f[o - 1], f[o] + abs(in[i] - st[o]));       }     }     for (long long i = 1; i <= n; i++) {       ans = min(ans, f[i]);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   double f[4][207][207];   struct node {     int x, y;   };   node a[207];   bool cmp(const node& x, const node& y) { return x.y > y.y; }   int n, m, bm;   int main() {     while (scanf( %d %d %d , &n, &m, &bm) != EOF) {       int i, j, k, r, w;       int sum = 0;       memset(f, 0, sizeof(f));       sum = bm;       for (i = 1; i <= n; i++) {         scanf( %d  , &a[i].x);       }       for (i = 1; i <= n; i++) scanf( %d , &a[i].y);       sort(a + 1, a + n + 1, cmp);       double ans = 0;       memset(f, 0, sizeof(f));       f[0][0][bm] = 1;       for (i = 0; i < n; i++) {         w = (i + 1) & 1;         r = (i)&1;         memset(f[w], 0, sizeof(f[w]));         for (j = 0; j <= i; j++)           for (k = 0; k <= 200; k++) {             int h = k + a[i + 1].y;             if (h < 0) continue;             if (h > 200) h = 200;             f[w][j + 1][h] += f[r][j][k] * (double)a[i + 1].x / 100;           }         for (j = 0; j <= i; j++)           for (k = 0; k <= 200; k++) {             int h = k + a[i].y;             f[w][j][k] += f[r][j][k] * (1 - (double)a[i + 1].x / 100);           }       }       w = n & 1;       for (j = m; j <= n; j++)         for (k = 0; k <= 200; k++) ans += f[w][j][k];       printf( %f n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int num1 = n / 3;     long long int num2 = n - (2 * num1);     if (num1 % 3 != 0 && num2 % 3 != 0)       cout << num1 <<     << num1 <<     << num2;     else if (num1 - 1 > 0 && (num1 - 1) % 3 != 0 && (num2 + 2) % 3 != 0)       cout << num1 - 1 <<     << num1 - 1 <<     << num2 + 2;     else if (num2 - 2 > 0 && (num1 + 1) % 3 != 0 && (num2 - 2) % 3 != 0)       cout << num1 + 1 <<     << num1 + 1 <<     << num2 - 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, c[5555], num[5555], ans[5555];   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) scanf( %d , &c[i]);       memset(num, 0, sizeof(num));       memset(ans, 0, sizeof(ans));       for (int i = 1; i <= n; i++) {         memset(num, 0, sizeof(num));         num[c[i]]++, ans[c[i]]++;         int Max = c[i];         for (int j = i + 1; j <= n; j++) {           num[c[j]]++;           if (num[c[j]] > num[Max] || num[c[j]] == num[Max] && c[j] < Max)             Max = c[j];           ans[Max]++;         }       }       for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;      #define all(x)       (x).begin(), (x).end()   #define acarr(arr, n, type)     type *arr=new type[n]; for(long long i=0; i<n; ++i) cin >> arr[i];   #define ll       long long   #define TF(ok)      cout << (ok ?  YES n  :  NO n )   #define ld       long double   #define vi       vector<int> v1   #define pb       push_back      int solve(){        ll ans=0, tab=0;       vector<int> v1(3);    for (int i=0; i<3; i++){     cin >> v1[i];     ans+=v1[i];    }       if (ans%9==0){     tab= ans/9;     for (int i=0; i<3; i++){      if (v1[i]<tab){       cout <<  NO n  ;       return 0;      }     }     cout <<  YES n ;    }    else{     cout <<  NO n  ;    }          return 0;   }         int main(){    ios::sync_with_stdio(false);    cin.tie(0);    int q;     q=1;   cin >> q;    while(q--){     solve();    }       return 0;   }      /*   ~ Check for overflow    ~ Division by 0    ~ Uninitialized    ~   */
#include <bits/stdc++.h>   using namespace std;   int x, y;   int main() {     cin >> x >> y;     if (x > 0 && y > 0)       cout <<  0   << x + y <<     << x + y <<   0 n ;     else if (x > 0 && y < 0)       cout <<  0   << -1 * (x + -1 * y) <<     << x + -1 * y <<   0 n ;     else if (x < 0 && y > 0)       cout << -1 * (-1 * x + y) <<   0 0   << -1 * x + y <<   n ;     else       cout << -1 * (-1 * x + -1 * y) <<   0 0   << -1 * (-1 * x + -1 * y) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d %d %d , &a, &b, &c);     bool valid = false;     int bo1, bo2, bo3;     for (int i = 0; i <= a; i++) {       bo1 = i;       bo3 = a - i;       bo2 = c - bo3;       if (bo1 + bo3 != a || bo1 + bo2 != b || bo2 + bo3 != c) continue;       if (bo1 < 0 || bo2 < 0 || bo3 < 0) continue;       valid = true;       break;     }     if (!valid)       puts( Impossible );     else       printf( %d %d %d n , bo1, bo2, bo3);     return 0;   }
#include <bits/stdc++.h>   const int mod = 998244353;   const int N = 1e6 + 7;   using namespace std;   long long n, m, k, i, j, t, sig = 0, ans;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   map<pair<int, int>, set<long long>> mp;   long long x[1005], y[1005];   struct node {     int x, pos;   } p[500007];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     long long ans = 0, sum = 0;     for (i = 1; i <= n; i++) cin >> x[i] >> y[i];     for (i = 1; i <= n - 1; i++) {       for (j = i + 1; j <= n; j++) {         long long x1 = x[i], x2 = x[j], y1 = y[i], y2 = y[j];         int b = x1 - x2, a = y1 - y2;         long long d = gcd(a, b);         a /= d, b /= d;         if (a < 0 || (!a && b < 0)) {           a = -a, b = -b;         }         pair<int, int> line(a, b);         long long c = a * x1 - b * y1;         if (!mp[line].count(c)) {           sum++;           mp[line].insert(c);           ans += sum - mp[line].size();         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int a, b, c;       cin >> a;       cin >> b;       cin >> c;       int p1, p2;       cin >> p1;       cin >> p2;       int min_no = min(b, c);       if (a <= 1) {         cout << 0 <<   n ;         continue;       }       if (b * 2 + c * 2 > a) {         int p = 0;         if (p2 >= p1) {           if (c * 2 > a) {             cout << (a / 2) * p2 <<   n ;             continue;           } else {             p += c * p2;             if ((a - c * 2) <= 1) {               cout << p <<   n ;               continue;             }             p += ((a - c * 2) / 2) * p1;             cout << p <<   n ;             continue;           }         } else if (p1 > p2) {           if (b * 2 > a) {             cout << (a / 2) * p1 <<   n ;             continue;           } else {             p += b * p1;             if ((a - b * 2) <= 1) {               cout << p <<   n ;               continue;             }             p += ((a - b * 2) / 2) * p2;             cout << p <<   n ;             continue;           }         }       } else {         int p = 0;         p += (p2 * c) + (p1 * b);         cout << p <<   n ;         continue;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, h, t, u, v, tim, d[100100], w[100100], W[100100];   vector<int> e[100100], ans;   int main() {     scanf( %d%d%d%d , &n, &m, &h, &t);     for (int i = 0; i < m; i++)       scanf( %d%d , &u, &v), e[u].push_back(v), e[v].push_back(u);     for (int i = 1; i < n + 1; i++) d[i] = e[i].size();     for (int i = 1; i < n + 1; i++) {       if (d[i] <= h) continue;       for (int j : e[i]) w[j] = i;       for (int j : e[i]) {         tim++;         int p = d[i] - 1 - h, q = 0;         ans.clear();         for (int k : e[j]) {           if (k != i)             if (p && w[k] == i)               p--, q++, ans.push_back(k), W[k] = tim;             else if (w[k] != i)               q++, ans.push_back(k), W[k] = tim;           if (q == t) break;         }         if (q == t) {           puts( YES );           printf( %d %d n , i, j);           int p = 0;           for (int k : e[i])             if (k != j && W[k] != tim) {               p++, printf( %d  , k);               if (p == h) break;             }           puts(  );           for (int k : ans) printf( %d  , k);           return 0;         }       }     }     puts( NO );   }
#include <bits/stdc++.h>   int main() {     int x, y;     scanf( %d%d , &x, &y);     double r = sqrt(x * x + y * y);     int rmin = r;     if ((double)rmin == r) {       printf( black );       return 0;     }     if (x == 0 || y == 0) {       printf( black );       return 0;     }     double tan = (double)y / (double)x;     if (rmin % 2 == 1 && tan > 0)       printf( white );     else if (rmin % 2 == 1 && tan < 0)       printf( black );     else if (rmin % 2 == 0 && tan > 0)       printf( black );     else if (rmin % 2 == 0 && tan < 0)       printf( white );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   int n, m, a, b, g;   int dis[N];   long long ans, c[N];   long long sum(int u) { return 1LL * u * (u + 1) / 2; }   long long query(int u) {     return sum(u / g + 1) * g - 1LL * (u / g + 1) * ((g - ((u + 1) % g)) % g);   }   int gcd(int u, int v) {     if (v == 0) {       return u;     }     return gcd(v, u % v);   }   set<pair<int, int> > s;   int main() {     scanf( %d%d%d , &n, &a, &b);     g = gcd(a, b);     if (n > a + b - g) {       ans += query(n) - query(a + b - g);       n = a + b - g;     }     memset(dis, 0x3f, sizeof dis);     dis[0] = 0;     s.insert({0, 0});     while (!s.empty()) {       auto u = *s.begin();       s.erase(s.begin());       if (dis[u.second] != u.first) {         continue;       }       ++c[u.first];       if (u.second >= b && u.first < dis[u.second - b]) {         dis[u.second - b] = u.first;         s.insert({u.first, u.second - b});       }       if (u.second + a <= n && max(u.first, u.second + a) < dis[u.second + a]) {         dis[u.second + a] = max(u.first, u.second + a);         s.insert({max(u.first, u.second + a), u.second + a});       }     }     for (int i = 1; i <= n; i++) {       c[i] += c[i - 1];     }     for (int i = 0; i <= n; i++) {       ans += c[i];     }     printf( %lld n , ans);     return 0;   }