malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const long long int MAX = 1e9 + 7;   void array_show(int *array, int array_n, char middle =    ) {     for (int i = 0; i < array_n; i++)       printf( %d%c , array[i], (i != array_n - 1 ? middle :   n ));   }   void array_show(long long int *array, int array_n, char middle =    ) {     for (int i = 0; i < array_n; i++)       printf( %lld%c , array[i], (i != array_n - 1 ? middle :   n ));   }   void array_show(vector<int> &vec_s, int vec_n = -1, char middle =    ) {     if (vec_n == -1) vec_n = vec_s.size();     for (int i = 0; i < vec_n; i++)       printf( %d%c , vec_s[i], (i != vec_n - 1 ? middle :   n ));   }   void array_show(vector<long long int> &vec_s, int vec_n = -1,                   char middle =    ) {     if (vec_n == -1) vec_n = vec_s.size();     for (int i = 0; i < vec_n; i++)       printf( %lld%c , vec_s[i], (i != vec_n - 1 ? middle :   n ));   }   string st[110000];   int t[110000];   int string_to_int(string sa) {     int s = 0;     int a;     for (auto ca : sa) {       s *= 10;       a = (int)ca - (int) 0 ;       if (a < 0 || a >= 10) return -1;       if (s == 0 && a == 0) return -1;       s += a;     }     return s;   }   bool used[110000];   vector<string> va[2], vb[2];   vector<pair<string, string>> vs;   int main() {     int n, m;     int i, j, k;     int a, b, c;     string sa;     cin >> n;     m = 0;     for (i = 0; i < n; i++) {       cin >> st[i] >> t[i];       if (t[i] == 1) m++;     }     b = -1;     for (i = 0; i < n; i++) {       a = string_to_int(st[i]);       if (a <= 0 || a > n)         vb[t[i]].push_back(st[i]);       else {         used[a] = true;         if (t[i] == 0 && a <= m) va[0].push_back(st[i]);         if (t[i] == 1 && a > m) va[1].push_back(st[i]);       }     }     for (i = 1; i <= n; i++) {       if (!used[i]) {         b = i;         break;       }     }     if (b == -1) {       if (va[0].empty()) {         cout << 0 << endl;         return 0;       }       vs.push_back(make_pair(va[0].back(), to_string(n + 1)));       a = string_to_int(va[0].back());       used[a] = false, b = a;       va[0].pop_back();       vb[0].push_back(to_string(n + 1));     }     while (1) {       if (b <= m)         a = 1;       else         a = 0;       if (va[a].empty()) break;       vs.push_back(make_pair(va[a].back(), to_string(b)));       c = string_to_int(va[a].back());       used[c] = false, used[b] = true;       va[a].pop_back(), b = c;     }     for (i = 1; i <= n; i++) {       if (used[i]) continue;       if (i <= m)         a = 1;       else         a = 0;       if (va[a].empty()) continue;       vs.push_back(make_pair(va[a].back(), to_string(i)));       c = string_to_int(va[a].back());       used[c] = false, used[i] = true;       va[a].pop_back();     }     for (i = 1; i <= n; i++) {       if (used[i]) continue;       if (i <= m)         a = 1;       else         a = 0;       if (vb[a].empty()) continue;       vs.push_back(make_pair(vb[a].back(), to_string(i)));       vb[a].pop_back();     }     cout << vs.size() << endl;     for (auto node : vs) {       cout <<  move   << node.first <<     << node.second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int dp[2002][2002];   vector<long long int> col, row;   long long int sol(long int p, long int q, int n, int m, int jk) {     if (p == 0 || q == 0) {       return 0;     }     vector<long long int>::iterator it;     if (p <= 2 * n && q <= 2 * m) {       if (jk == 0) {         return (p * q - dp[p][q]);       }       return dp[p][q];     } else if (p <= 2 * n) {       it = lower_bound(col.begin(), col.end(), q);       if (*it != q) {         it--;       }       long long int ab = *it;       q = q % ab;       ab /= 2;       ab = ab * p;       return ab + sol(p, q, n, m, 1 - jk);     } else {       it = lower_bound(row.begin(), row.end(), p);       if (*it != p) {         it--;       }       long long int ab = *it;       p = p % ab;       ab /= 2;       ab = ab * q;       return ab + sol(p, q, n, m, 1 - jk);     }     return 0;   }   int main() {     int n, m, q;     cin >> n >> m >> q;     int arr[2 * n + 2][2 * m + 2];     for (int x = 1; x <= n; x++) {       string s;       cin >> s;       for (int y = 1; y <= m; y++) {         arr[x][y] = s[y - 1] -  0 ;       }     }     for (int x = 1; x <= 2 * n; x++) {       for (int y = 1; y <= 2 * m; y++) {         if (x <= n && y <= m) {         } else if (x > n && y > m) {           arr[x][y] = arr[x - n][y - m];         } else if (x > n) {           arr[x][y] = 1 - arr[x - n][y];         } else {           arr[x][y] = 1 - arr[x][y - m];         }         dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1] + arr[x][y];       }     }     int sz = 0;     col.push_back(m);     while (col[sz] < INT_MAX) {       col.push_back(col[sz++] * 2);     }     sz = 0;     row.push_back(n);     while (row[sz] < INT_MAX) {       row.push_back(row[sz++] * 2);     }     while (q--) {       int x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       long long int a = sol(x2, y2, n, m, 1);       long long int b = sol(x1 - 1, y2, n, m, 1);       long long int c = sol(x2, y1 - 1, n, m, 1);       long long int d = sol(x1 - 1, y1 - 1, n, m, 1);       cout << a + d - b - c << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n;   int a[26];   int b[26];   bool flag[26];   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s >> n;     memset(a, 0, sizeof(a));     memset(flag, 1, sizeof(flag));     for (int i = 0; i < s.size(); ++i) {       a[s[i] -  a ]++;     }     for (int i = 0; i < 26; ++i) {       b[i] = i;     }     int ans = 26;     sort(b, b + 26, cmp);     for (int i = 0; i < 26; ++i) {       if (a[b[i]] <= n) {         flag[b[i]] = 0;         n -= a[b[i]];         ans--;       }     }     cout << ans <<   n ;     for (int i = 0; i < s.size(); ++i) {       if (flag[s[i] -  a ]) cout << s[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long n) {     if (a == 0) return 0;     if (a == 1 || n == 0) return 1;     if (n == 1) return a % 1000000007;     long long t = power(a, n / 2);     t = t * t % 1000000007;     if (n & 1) return t * a % 1000000007;     return t;   }   int popcount(long long a) {     int c = 0;     while (a) {       c++;       a -= a & -a;     }     return c;   }   void factorize(int a) {}   void update(int tree[], int idx, int val, int maxval) {     for (; idx <= maxval; idx += idx & -idx) {       tree[idx] += val;     }   }   int read(int tree[], int idx) {     long long sum = 0;     for (; idx > 0; idx -= idx & -idx) {       sum += tree[idx];     }     return sum;   }   struct node2 {     int id, val;     node2() {       static int ctx = 1;       id = ctx++;     };     node2(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {       val = a;     }   };   struct comp2 {     bool operator()(int a, int b) { return b < a; }   };   bool cmp2(int a, int b) { return b < a; }   struct node {     int id, val;     node() {       static int ctx = 1;       id = ctx++;     };     node(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {       val = a;     }   };   struct comp {     bool operator()(int a, int b) { return b < a; }   };   bool cmp(int a, int b) { return b < a; }   int n, m, a[100009], b, c, d, k, h, w, x, y, p, q, t, res, ma, mi, T,       act = 0, pas = 1, cur, flag, now;   int bit[33][100009];   long long ans, dp[100009][2];   char s[1];   double e, f, z;   vector<int> v[100009], vec;   set<int> sett;   map<int, int> mapp;   void print() {}   void print2() {}   void input() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i < n + 1; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }   }   void init() {     for (int pos = 0; pos < 30; pos++) {       for (int i = 1; i < n + 1; i++) {         bit[pos][i] = (((1 << pos) & a[i]) != 0);       }     }   }   void calc(int id, int par, int a[]) {     dp[id][a[id]] = 1;     for (auto u : v[id]) {       if (u == par) continue;       calc(u, id, a);       if (a[id]) {         dp[id][1] += dp[u][0];         dp[id][0] += dp[u][1];         ans += T * (dp[id][1] - dp[u][0]) * dp[u][0];         ans += T * (dp[id][0] - dp[u][1]) * dp[u][1];       } else {         dp[id][1] += dp[u][1];         dp[id][0] += dp[u][0];         ans += T * (dp[id][1] - dp[u][1]) * dp[u][0];         ans += T * (dp[id][0] - dp[u][0]) * dp[u][1];       }     }     ans += T * a[id];   }   void solve() {     init();     int l = 0;     int r = 29;     for (int pos = l; pos < r + 1; pos++) {       T = 1 << pos;       memset(dp, 0, sizeof(dp));       calc(1, 0, bit[pos]);     }   }   void output() { cout << ans; }   int main() {     input();     solve();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265358979323846;   long long MOD = 1e9 + 7;   const char nl =   n ;   const long long inf = 1e15;   long long nxt() {     long long x;     cin >> x;     return x;   }   long long mul(long long x, long long y) {     return (1ll * (x % MOD) * (y % MOD));   }   long long modpow(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y % 2) z = mul(z, x);       x = mul(x, x);       y /= 2;     }     return z;   }   long long power(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y % 2) z = z * x;       x = x * x;       y /= 2;     }     return z;   }   long long gcd(long long a, long long b) {     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   long long min(long long a, long long b) {     if (a < b) return a;     return b;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long sq(long long a) {     long long ans = (1ll * a * a);     return ans;   }   void solve() {     long long n, k;     cin >> n >> k;     long long t[n];     vector<long long> neg;     for (long long i = 0; i < n; i++) {       cin >> t[i];       if (t[i] < 0) neg.push_back(i);     }     if ((long long)(neg.size()) > k) {       cout << -1 << nl;       return;     }     if ((long long)(neg.size()) == 0) {       cout << 0 << nl;       return;     }     if (n == 1) {       if (t[0] < 0) {         cout << 1 << nl;       } else         cout << 0 << nl;       return;     }     vector<long long> dis;     for (long long i = 0; i < (long long)(neg.size()) - 1; i++) {       if (neg[i + 1] - neg[i] > 1) {         dis.push_back(neg[i + 1] - neg[i] - 1);       }     }     sort(((dis).begin()), ((dis).end()));     long long ans = (long long)(dis.size()) * 2;     ans++;     if (t[n - 1] >= 0) ans++;     long long ewd = k - (long long)(neg.size());     for (long long x : dis) {       if (ewd >= x) ewd -= x, ans -= 2;     }     long long ex = n - 1 - neg.back();     if (ewd >= ex && ex) ans--;     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long TC = 1;     while (TC--) {       solve();     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   bool isprime(int a) {     for (int i = 2; i <= sqrt((double)a); i++) {       if (a % i == 0) return false;     }     return true;   }   int main() {     int n;     cin >> n;     if (n <= 7)       cout << 1 << endl << n;     else {       cout << 3 << endl << 3 <<    ;       n -= 3;       for (int i = 2; i <= n; i++) {         if (isprime(i) && isprime(n - i)) {           cout << i <<     << n - i;           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string n1 = to_string(m);     for (int i = 0; i < n1.length() / 2; i++) {       char s = n1[i];       n1[i] = n1[n1.length() - 1 - i];       n1[n1.length() - 1 - i] = s;     }     cout << n + stoi(n1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long l, r;     cin >> l >> r;     long long ans = 0;     for (long long i = 1; i <= r; i *= 2) {       long long cur = i;       while (cur <= r) {         if (cur >= l) ans++;         cur *= 3;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, h1, m1;   int h[10000], m[10000];   bool a[10000];   int main() {     int n;     cin >> n;     cin.ignore();     for (__typeof(n) i = (1); i <= (n); i++) {       getline(cin, s);       h1 = s.substr(1, 2);       m1 = s.substr(4, 2);       if (s[7] ==  a )         a[i] = true;       else         a[i] = false;       stringstream sh, sm;       sh.flush();       sm.flush();       sh.clear();       sm.clear();       sh << h1;       sm << m1;       sh >> h[i];       sm >> m[i];       h[i] %= 12;       if (!a[i]) h[i] += 12;     }     int ans = 1;     int k = 0;     for (__typeof(n - 1) i = (1); i <= (n - 1); i++) {       int t1 = h[i] * 10000 + m[i];       int t2 = h[i + 1] * 10000 + m[i + 1];       if (t1 == t2)         k++;       else         k = 0;       if (k == 10) {         k = 0;         ans++;         continue;       }       if (!(a[i]) && a[i + 1]) {         ans++;         continue;       }       if (t1 > t2) {         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   typedef struct {     char name[20];     char phone[200][20];     int len[200];     int avai[200];     int cnt, now;   } friends;   friends frd[20];   int total;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char tmp[20];       scanf( %s , tmp);       int pos = -1;       for (int j = 0; j < total; j++) {         if (!strcmp(frd[j].name, tmp)) {           pos = j;           break;         }       }       if (pos == -1) pos = total++;       int num;       scanf( %d , &num);       for (int j = 0; j < num; j++) {         char ph_num[20];         scanf( %s , ph_num);         int l = strlen(ph_num), flag = 0;         for (int k = 0; k < frd[pos].now; k++) {           if (frd[pos].avai[k]) {             if (frd[pos].len[k] >= l) {               if (!strcmp(frd[pos].phone[k] + frd[pos].len[k] - l, ph_num)) {                 flag = 1;                 break;               }             } else {               if (!strcmp(ph_num + l - frd[pos].len[k], frd[pos].phone[k])) {                 frd[pos].avai[k] = 0;                 frd[pos].cnt--;                 break;               }             }           }         }         if (!flag) {           strcpy(frd[pos].name, tmp);           strcpy(frd[pos].phone[frd[pos].now], ph_num);           frd[pos].len[frd[pos].now] = l;           frd[pos].avai[frd[pos].now] = 1;           frd[pos].cnt++;           frd[pos].now++;         }       }     }     printf( %d n , total);     for (int i = 0; i < total; i++) {       printf( %s %d , frd[i].name, frd[i].cnt);       for (int j = 0; j < frd[i].now; j++) {         if (frd[i].avai[j]) printf(  %s , frd[i].phone[j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   using std::string;   using std::vector;   int zfn[100010];   int count = 0, nodes_count;   string P, T;   vector<string> str;   vector<vector<int> > connections;   void kmpPreprocess() {     int i = 0, j = -1;     zfn[0] = -1;     while (i < P.size()) {       while (j >= 0 && P[i] != P[j]) j = zfn[j];       i++;       j++;       zfn[i] = j;     }   }   void kmp_DFS(int current, int j) {     string T = str[current];     int i = 0;     while (i < T.size()) {       while (j >= 0 && T[i] != P[j]) j = zfn[j];       i++;       j++;       if (j == P.size()) {         count++;         j = zfn[j];       }     }     for (vector<int>::iterator it = connections.at(current).begin();          it != connections.at(current).end(); ++it) {       kmp_DFS(*it, j);     }   }   int main() {     cin.sync_with_stdio(false);     cin >> nodes_count;     str.resize(nodes_count + 1);     for (int i = 0; i < nodes_count; i++) {       vector<int> v;       connections.push_back(v);     }     int current_parent;     for (int current_node = 0; current_node < nodes_count - 1; current_node++) {       T =   ;       cin >> current_parent >> T;       connections[current_parent - 1].push_back(current_node + 1);       str.at(current_node + 1) = T;     }     cin >> P;     kmpPreprocess();     T =   ;     kmp_DFS(0, 0);     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int y, k, n;     scanf( %d%d%d , &y, &k, &n);     int x = k - y % k;     int top = n - y;     if (x <= top) {       printf( %d , x);       x += k;       while (x <= top) {         printf(  %d , x);         x += k;       }       printf(  n );     } else {       printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans1 = INT_MAX, ans = -198896785;     cin >> n;     int c = 0, d = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a < 0) {         c++;         ans = max(a, ans);       }       if (a > 0) {         d++;         ans1 = min(a, ans1);       }     }     n = (n + 1) / 2;     if (d >= n)       cout << ans1 << endl;     else if (c >= n)       cout << ans << endl;     else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   const int MOD = 1e9 + 7;   int dp[MAXN][MAXN][2];   int Steps[MAXN];   int add(int a, int b) { return ((a + b) >= MOD ? a + b - MOD : a + b); }   void PreproccessSteps() {     Steps[1] = 1;     for (int i = (2); i < (1010); i++)       Steps[i] = Steps[__builtin_popcount(i)] + 1;   }   int Ones(int N, string s) {     int cnt = 0;     for (int i = (1); i < (N); i++)       if (s[i] ==  1 ) cnt++;     return cnt;   }   void FillDP(int N, string s) {     for (int j = (0); j < (N + 1); j++) dp[0][j][0] = dp[0][j][1] = 1;     for (int i = (1); i < (N + 1); i++)       for (int j = (1); j < (N + 1); j++) {         if (s[j - 1] ==  1 )           dp[i][j][0] = add(dp[i - 1][j - 1][0], dp[i][j - 1][1]);         if (s[j - 1] ==  0 ) dp[i][j][0] = dp[i][j - 1][0];         dp[i][j][1] = add(dp[i - 1][j - 1][1], dp[i][j - 1][1]);       }   }   int main() {     int N, k, sum = 0;     string s;     cin >> s >> k;     reverse(s.begin(), s.end());     PreproccessSteps();     N = (int)s.size();     FillDP(N, s);     for (int i = (1); i < (N + 1); i++)       if (Steps[i] == k) sum = add(sum, dp[i][N][0]);     if (k == 1) {       cout << dp[1][N][0] - 1;       return 0;     }     if (!k) sum++;     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int x, y, n;     cin >> x >> y >> n;     int max = (n / x) * x;     if (max + y > n) {       max = max - x + y;     } else {       max += y;     }     cout << max <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const long long mod = 1e9 + 7;   void rd(int &x) {     int f = 1;     x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   void pr(int x) { printf( %d n , x); }   int n, a[55][55];   int go[4][2] = {-1, -1, 1, -1, -1, 1, 1, 1};   pair<int, int> g[4];   int main() {     int odd = 1, even = 2;     cin >> n;     if (n == 1) {       puts( 1 );       return 0;     }     if (n == 3) {       printf( 2 1 4 n3 5 7 n6 9 8 n );       return 0;     }     int k = (n + 1) / 2;     int l = k, r = k;     for (int i = (1); i <= k; i++) {       for (int j = (l); j <= r; j++) a[i][j] = odd, odd += 2;       l--, r++;     }     l = k, r = k;     for (int i = n; i >= k + 1; i--) {       for (int j = (l); j <= r; j++) a[i][j] = odd, odd += 2;       l--, r++;     }     for (int i = (1); i <= n; i++) {       for (int j = (1); j <= n; j++) {         if (a[i][j] == 0) a[i][j] = even, even += 2;       }     }     for (int i = (1); i <= n; i++) {       for (int j = (1); j <= n; j++) printf( %d  , a[i][j]);       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int arr[n];     for (int i = 0; i < (n); ++i) cin >> arr[i];     int ans = 1, idx = 1, cnt = 1;     while (idx < n) {       ans = (ans > cnt) ? ans : cnt;       if (arr[idx] <= 2 * arr[idx - 1])         ++cnt;       else         cnt = 1;       ++idx;     }     ans = (ans > cnt) ? ans : cnt;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<bool> primes(n + 1, 1);     primes[0] = primes[1] = 0;     for (int i = 2; i <= n; ++i) {       if (!primes[i]) continue;       for (int j = i * i; j <= n; j += i) primes[j] = 0;     }     vector<int> quest;     for (int i = 2; i <= n; ++i) {       if (!primes[i]) continue;       int k = i;       do {         quest.push_back(k);         k *= i;       } while (k <= n);     }     cout << quest.size() <<   n ;     for (int i = 0; i < quest.size(); ++i) cout << quest[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char mat[110][110];   int main() {     int r, c;     int cnt = 0;     int status = 0;     int i, j;     scanf( %d%d  , &r, &c);     for (i = 0; i < r; i++) {       for (j = 0; j < c; j++) {         scanf( %c , &mat[i][j]);       }       getchar();     }     for (i = 0; i < c; i++) {       if (status == 0 && mat[r - 1][i] ==  B ) {         status = 1;         cnt++;       }       if (mat[r - 1][i] ==  . ) {         status = 0;       }     }     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int m, r, t, i;     long double s = 1.4142135623730950488;     long long int b, f;     long double d, ans, last, sum = 0;     long double x, y, z;     cin >> m >> r;     x = 2 * r;     y = 2 * r + (s * r);     z = 2 * r + (2 * s * r);     t = (m % 2 == 0) ? (m / 2) : (m / 2 + 1);     for (i = 1; i <= t; i++) {       d = x;       b = (i - 1);       f = (m - i);       if (f > 1) {         d = d + y + z;         d = d + (f - 2) * z + ((f - 1) * (f - 2) * (x)) / 2;       }       if (f == 1) {         d = y + d;       }       if (b > 1) {         d = d + y + z;         d = d + (b - 2) * z + ((b - 1) * (b - 2) * (x)) / 2;       }       if (b == 1) {         d = y + d;       }       sum = sum + d;       if (i == t) {         last = d;       }     }     sum = (m % 2 == 0) ? (2 * sum) : (2 * (sum - last) + last);     ans = (sum) / (m * m);     cout << setprecision(16) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, a, b, cnt, p;   long long ak[101], tot;   int main() {     cin >> t >> a >> b;     if (t == a && a == b) {       if (t == 1)         cout <<  inf ;       else         cout <<  2 ;     } else if (a == b)       cout <<  1 ;     else {       if (a == 1) {         cout <<  0 ;         return 0;       }       if (t == 1) {         p = 1;         while (p < b) {           p *= a;           if (p == b) {             cout <<  1 ;             return 0;           }         }       }       memset(ak, 0, sizeof(ak));       tot = 0;       ak[tot] = b;       while (ak[tot] / a) {         ak[tot + 1] = ak[tot] / a;         ak[tot] %= a;         tot++;       }       cnt = 0;       p = 1;       for (int i = 0; i < 70; i++) {         if (ak[i]) cnt = cnt + ak[i] * p;         p *= t;       }       if (cnt == a)         cout <<  1 ;       else         cout <<  0 ;     }     return 0;   }