malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int ara[55][55];   void solve() {     int n;     cin >> n;     vector<pair<int, int> > odds;     map<pair<int, int>, int> done;     for (int i = 1; i <= n; i++) {       odds.push_back({i, n / 2 + 1});       done[{i, n / 2 + 1}] = 1;     }     for (int j = 1; j <= n; j++) {       if (!done[{n / 2 + 1, j}]) odds.push_back({n / 2 + 1, j});       done[{n / 2 + 1, j}] = 1;     }     for (int k = 1; k <= n / 2; k++) {       int i = k;       int j = 1;       while (i < n && j < n) {         if (!done[{i, j}]) {           odds.push_back({i, j});           done[{i, j}] = 1;         }         if (!done[{i, n - j + 1}]) {           odds.push_back({i, n - j + 1});           done[{i, n - j + 1}] = 1;         }         if (!done[{n - i + 1, j}]) {           odds.push_back({n - i + 1, j});           done[{n - i + 1, j}] = 1;         }         if (!done[{n - i + 1, n - j + 1}]) {           odds.push_back({n - i + 1, n - j + 1});           done[{n - i + 1, n - j + 1}] = 1;         }         i++;         j++;       }     }     for (int i = 0, k = 1; k <= n * n; k += 2, i++) {       int x = odds[i].first;       int y = odds[i].second;       ara[x][y] = k;     }     for (int i = 1, k = 2; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (!ara[i][j]) {           ara[i][j] = k;           k += 2;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) cout << ara[i][j] <<    ;       cout <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, w, used[300005];   long long ans, a[300005], b[300005];   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       Q1, Q2;   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  less<pair<long long, int> > >       Used;   int main() {     scanf( %d %d , &n, &w);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &a[i], &b[i]);       Q1.push(make_pair(a[i], i));       Q2.push(make_pair(b[i], i));     }     if (w == 1) {       pair<long long, int> x = Q1.top();       ans = x.first;       used[x.second]++;       printf( %lld n , ans);       for (int i = 1; i <= n; i++) printf( %d , used[i]);       return 0;     }     while (w > 0 && !Q1.empty() && !Q2.empty()) {       pair<long long, int> x = Q1.top();       if (used[abs(x.second)] == 2) {         Q1.pop();         continue;       }       pair<long long, int> y = Q2.top();       if (used[y.second]) {         Q2.pop();         continue;       }       if (x.first * 2 <= y.first) {         int now = x.second;         w--;         ans += x.first;         Q1.pop();         if (now > 0) Q1.push(make_pair(b[now] - a[now], -now));         used[abs(now)]++;         Used.push(make_pair(x.first, abs(now)));       } else {         int now = y.second;         w--, w--;         ans += y.first;         Q2.pop();         used[now] = 2;         Used.push(make_pair(b[now] - a[now], now));       }     }     while (w > 0 && !Q1.empty()) {       pair<long long, int> x = Q1.top();       if (used[abs(x.second)] == 2) {         Q1.pop();         continue;       }       int now = x.second;       w--;       ans += x.first;       Q1.pop();       if (now > 0) Q1.push(make_pair(b[now] - a[now], -now));       used[abs(now)]++;       Used.push(make_pair(x.first, abs(now)));     }     while (w > 0 && !Q2.empty()) {       pair<long long, int> y = Q2.top();       if (used[y.second]) {         Q2.pop();         continue;       }       int now = y.second;       w--, w--;       ans += y.first;       Q2.pop();       used[now] = 2;       Used.push(make_pair(b[now] - a[now], now));     }     if (w == -1) {       pair<long long, int> x = Used.top();       ans -= x.first;       used[x.second]--;     }     int f = 1;     while (f) {       f = 0;       while (!Q1.empty()) Q1.pop();       while (!Used.empty()) Used.pop();       for (int i = 1; i <= n; i++) {         if (used[i] == 2)           Used.push(make_pair(b[i], i));         else if (used[i] == 1)           Q1.push(make_pair(b[i] - a[i], i));         else           Q1.push(make_pair(a[i], i));       }       if (Q1.size() < 2 || Used.empty()) break;       pair<long long, int> x = Q1.top();       Q1.pop();       pair<long long, int> y = Q1.top();       Q1.pop();       pair<long long, int> z = Used.top();       Used.pop();       if (x.first + y.first < z.first) {         ans = ans - (z.first - x.first - y.first);         used[x.second]++;         used[y.second]++;         used[z.second] = 0;         f = 1;       }     }     printf( %lld n , ans);     for (int i = 1; i <= n; i++) printf( %d , used[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const int MOD = 998244353;   struct node {     long long a, b;     node() {}     node(long long a, long long b) {       this->a = a;       this->b = b;     }     node operator+(const node& rhs) const {       return node((a + rhs.a) % MOD, (b + rhs.b) % MOD);     }     node operator*(const node& rhs) const {       return node(a * rhs.a % MOD, b * rhs.b % MOD);     }     bool operator==(const node& rhs) const { return a == rhs.a && b == rhs.b; }   };   node BASE(2333, 233333);   node h[maxn];   node ALL(0, 0);   node s[maxn][15];   vector<pair<int, int> > vec[maxn];   int n, m, k, ans;   void dfs(int u, node hh) {     if (u > k) {       ans += (hh == ALL ? 1 : 0);       return;     }     for (int i = 0; i < u; i++) {       node v = hh + s[u][i];       dfs(u + 1, v);     }     return;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     h[0] = node(1, 1);     for (int i = 1; i <= n; i++) {       h[i] = h[i - 1] * BASE;       ALL = ALL + h[i];     }     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       vec[u].emplace_back(make_pair(v, w));     }     for (int i = 1; i <= n; i++) {       sort(vec[i].begin(), vec[i].end(), [](pair<int, int> a, pair<int, int> b) {         return a.second < b.second;       });       int lens = vec[i].size();       for (int j = 0; j < lens; j++) s[lens][j] = s[lens][j] + h[vec[i][j].first];     }     dfs(1, node(0, 0));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m = 1;   vector<vector<int> > edge(105);   int from[105];   int to[105];   bool bfs(int a, int b) {     int use[105] = {0};     queue<int> q;     q.push(a);     use[a] = 1;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (int i = 0; i < edge[cur].size(); i++) {         if (edge[cur][i] == b) return true;         if (use[edge[cur][i]] == 0) {           q.push(edge[cur][i]);           use[edge[cur][i]] = 1;         }       }     }     return false;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int t, x, y;       cin >> t >> x >> y;       if (t == 1) {         from[m] = x;         to[m] = y;         for (int j = 1; j < m; j++) {           if ((from[j] < x && x < to[j] && y >= to[j]) ||               (from[j] < y && y < to[j]) && x <= from[j]) {             edge[j].push_back(m);             edge[m].push_back(j);           } else if (x <= from[j] && y >= to[j]) {             edge[j].push_back(m);           }         }         m++;       } else {         if (bfs(x, y))           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e6 + 5;   int n, p = 1, pa[N];   int ch[N][26];   vector<int> cnt[N][2];   vector<pair<int, int> > as;   long long ans;   inline void dfs(int u, int dep) {     for (register int i = 0; i <= 25; ++i) {       int v = ch[u][i];       if (v) {         dfs(v, dep + 1);         for (register int j = 0; j < cnt[v][0].size(); ++j)           cnt[u][0].push_back(cnt[v][0][j]);         for (register int j = 0; j < cnt[v][1].size(); ++j)           cnt[u][1].push_back(cnt[v][1][j]);       }     }     ans += min(cnt[u][0].size(), cnt[u][1].size()) * dep;     for (register int i = min(cnt[u][0].size(), cnt[u][1].size()) - 1; i > -1;          --i) {       as.push_back(           {cnt[u][0][cnt[u][0].size() - 1], cnt[u][1][cnt[u][1].size() - 1]});       cnt[u][0].pop_back();       cnt[u][1].pop_back();     }   }   string a;   int main() {     cin >> n;     for (register int id = 1; id <= n; ++id) {       cin >> a;       int u = 1;       for (register int i = 0; i < a.size(); ++i) {         int c = a[i] -  a ;         if (ch[u][c] == 0) ch[u][c] = ++p;         u = ch[u][c];       }       cnt[u][0].push_back(id);     }     for (register int id = 1; id <= n; ++id) {       cin >> a;       int u = 1;       for (int i = 0; i < a.size(); ++i) {         int c = a[i] -  a ;         if (!ch[u][c]) ch[u][c] = ++p;         u = ch[u][c];       }       cnt[u][1].push_back(id);     }     dfs(1, 0);     printf( %d n , ans);     for (register int i = 0; i <= n - 1; ++i)       printf( %d %d n , as[i].first, as[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char a[105][3];   int main() {     scanf( %s%d , a[0], &n);     for (int i = 1; i <= n; ++i) {       scanf( %s , a[i]);       if (a[i][0] == a[0][0] && a[i][1] == a[0][1]) {         printf( YES n );         return 0;       }     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if ((a[i][1] == a[0][0] && a[j][0] == a[0][1])) {           printf( YES n );           return 0;         }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int T, n, a[N];   map<int, int> mp;   int main() {     cin >> T;     while (T--) {       double sum = 0;       mp.clear();       cin >> n;       for (int i = 0; i < n; ++i) {         cin >> a[i];         sum += a[i];       }       double mean = sum / n;       double need = sum - (n - 2) * mean;       if (need != floor(need)) {         cout << 0 << endl;         continue;       }       long long ans = 0;       for (int i = 0; i < n; ++i) {         if (mp.find(need - a[i]) != mp.end()) ans += mp[need - a[i]];         mp[a[i]]++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(int num);   int main() {     int n;     cin >> n;     for (int i = 1; i <= 1000; i++) {       if (!(isPrime(n * i + 1))) {         cout << i;         break;       }     }     return 0;   }   bool isPrime(int num) {     if (num <= 1)       return false;     else if (num == 2)       return true;     else if (num % 2 == 0)       return false;     else {       bool prime = true;       int divisor = 3;       double num_d = static_cast<double>(num);       int upperLimit = static_cast<int>(sqrt(num_d) + 1);       while (divisor <= upperLimit) {         if (num % divisor == 0) prime = false;         divisor += 2;       }       return prime;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 5;   int dp[mx][3], arr[mx], n, h[mx];   void solve() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       h[arr[i]]++;     }     sort(arr, arr + n + 1);     memset(dp, 0, sizeof dp);     dp[1][0] = dp[1][1] = dp[1][2] = 1;     for (int i = 2; i <= n; i++) {       if (arr[i] - arr[i - 1] > 2) {         dp[i][1] = dp[i][2] = dp[i][0] =             min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) + 1;       } else if (arr[i] - arr[i - 1] == 2) {         dp[i][0] = min(dp[i - 1][0] + 1, min(dp[i - 1][1] + 1, dp[i - 1][2]));         dp[i][1] = dp[i][2] =             min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) + 1;       } else if (arr[i] - arr[i - 1] == 1) {         dp[i][0] = min(dp[i - 1][0] + 1, min(dp[i - 1][1], dp[i - 1][2] + 1));         dp[i][1] = min(dp[i - 1][0] + 1, min(dp[i - 1][1] + 1, dp[i - 1][2]));         dp[i][2] = min(dp[i - 1][0] + 1, min(dp[i - 1][1] + 1, dp[i - 1][2] + 1));       } else {         dp[i][0] = min(dp[i - 1][0], min(dp[i - 1][1] + 1, dp[i - 1][2] + 1));         dp[i][1] = min(dp[i - 1][0] + 1, min(dp[i - 1][1], dp[i - 1][2] + 1));         dp[i][2] = min(dp[i - 1][0] + 1, min(dp[i - 1][1] + 1, dp[i - 1][2]));       }     }     cout << min(dp[n][0], min(dp[n][1], dp[n][2])) <<    ;     set<int> s;     for (int i = 0; i < mx; i++) {       if (h[i] > 0) {         int t = min(3, h[i]);         int x = i - 1;         if (s.find(x) == s.end()) {           s.insert(x);           h[i]--;         }         x++;         if (h[i] > 0) {           if (s.find(x) == s.end()) {             s.insert(x);             h[i]--;           }         }         x++;         if (h[i] > 0) {           if (s.find(x) == s.end()) {             s.insert(x);             h[i]--;           }         }       }     }     cout << s.size();   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const double esp = 1e-7;   const int mod = 1e9 + 7;   vector<int> adj[N];   int leaf = 0;   void dfs(int node = 1, int par = 0) {     int cnt = 0;     for (int child : adj[node]) {       if (child == par) continue;       dfs(child, node);       cnt++;     }     if (!cnt) {       leaf++;     }   }   int main() {     int n, s, u, v;     double ans;     scanf( %d %d , &n, &s);     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs();     if (adj[1].size() == 1) leaf++;     if (n == 2) {       leaf = 1;       ans = s;     } else {       ans = 2.0 * s / double(leaf);     }     printf( %.09f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a << endl;     err(++it, args...);   }   const long long MOD = 1e9 + 7;   long long modExp(long long b, long long p) {     long long res = 1;     while (p > 0) {       if (p & 1) {         res = (res * b) % MOD;       }       b = (b * b) % MOD;       p >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     long long ans = 1;     for (int i = 1; i <= n; i++) {       ans = ((2 * m - 1) * ans + modExp(m, i - 1)) % MOD;     }     cout << ans;     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];     for (int k = 1; k <= n / 3; k++) {       if (n % k == 0) {         for (int p = 0; p < k; p++) {           int sum = 0;           for (int v = p; v < n; v += k) {             if (a[v] == 1) sum++;           }           if (sum == n / k) {             cout <<  YES n ;             return 0;           }         }       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Popcount(long long int a) {     int k;     for (k = 0; a; a >>= 1)       if (a & 1ll) k++;     return k;   }   int Ffs(long long int a) {     int k;     for (k = 0; a; a >>= 1, k++)       ;     return k;   }   long long int C[50][50];   long long int getAns(long long int n, long long int t) {     if (n < t || t <= 0) return 0ll;     long long int i;     int k = 0, j = Ffs(t) - 1;     for (i = 1ll; (i << 1) < n; (i <<= 1), k++)       ;     long long int res = getAns(n - i, t >> 1);     if (k < j) return res;     return C[k][j] + res;   }   int main() {     C[0][0] = 1ll;     for (int i = 1; i < 50; i++) {       C[i][0] = C[i][i] = 1ll;       for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];     }     long long int N, T;     while (cin >> N >> T) {       N++;       if (Popcount(T) != 1) {         puts( 0 );         continue;       }       long long int Ans = 0ll, x, di = 0ll;       for (x = 1ll; x + di <= N; x <<= 1) {         Ans += getAns(x, T);         di += x;       }       Ans += getAns(N - di, T);       if (T == 1ll) Ans--;       cout << Ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct BIT {     vector<int> t;     int n;     void add(int x, int v) {       for (; x < n; x += x & -x) {         t[x] += v;       }     }     BIT(int sz) {       t = vector<int>(sz);       n = sz;     }     void add(int l, int r, int v) {       ++l;       ++r;       add(l, v);       add(r, -v);     }     int query(int x) {       ++x;       int ans = 0;       for (; x; x -= x & -x) {         ans += t[x];       }       return ans;     }   };   const int N = 100100;   vector<BIT> bits;   vector<int> adj[N];   int my_bit[N], my_ind[N], n, q;   int dfs(int u, int p, int bit_ind, int ind) {     my_bit[u] = bit_ind;     my_ind[u] = ind;     int res = ind;     for (auto& v : adj[u]) {       if (v == p) continue;       res = dfs(v, u, bit_ind, ind + 1);     }     return res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n >> q;     int u, v;     for (int i = 1; i <= n - 1; ++i) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     bits.emplace_back(1);     int mx = 5;     for (int v : adj[1]) {       int amt = dfs(v, 1, bits.size(), 2);       bits.emplace_back(amt + 5);       mx = max(mx, amt + 5);     }     BIT all(mx);     my_ind[1] = 1;     for (int qq = 0; qq < q; ++qq) {       int type;       cin >> type;       if (type == 0) {         int x, d;         cin >> u >> x >> d;         if (u == 1) {           all.add(1, 2 + d, x);         } else {           int extra = 0;           int lo = my_ind[u] - d;           int hi = my_ind[u] + d + 1;           if (lo < 2) {             extra = 2 - lo;             lo = extra + 1;           }           bits[my_bit[u]].add(lo, hi, x);           if (extra) {             all.add(1, extra + 1, x);           }         }       } else if (type == 1) {         cin >> u;         int res = all.query(my_ind[u]);         if (u != 1) {           assert(my_ind[u] > 1);           res += bits[my_bit[u]].query(my_ind[u]);         }         cout << res <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lli = long long int;   using pii = pair<int, int>;   using vi = vector<int>;   using vb = vector<bool>;   using vvi = vector<vector<int>>;   using vlli = vector<long long int>;   using vpii = vector<pair<int, int>>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     lli n, k, a, x[100005], c[100005], money = 0;     multiset<lli> unused;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> x[i];     cin >> a;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n; i++) {       unused.insert(c[i]);       while (!unused.empty() && k < x[i]) {         auto temp = unused.begin();         k += a;         money += *temp;         unused.erase(temp);       }       if (k < x[i]) return cout << -1, 0;     }     cout << money;   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   const int N = 1e6 + 5, M = 300, MAX = 10, T = 3e4, INF = 1e9;   int d[N], w[T], dist[300][M + 5];   vector<int> h[T], pr;   vector<vector<int>> v;   map<vector<int>, int> mp;   int cnt = 0;   vector<int> path;   void f(int max, int prod, int ct) {     v.push_back(path);     pr.push_back(prod);     mp[path] = cnt++;     if (ct == MAX) return;     for (int i = 2; i <= max; i++) {       if (prod * i <= M) {         path.push_back(i);         f(i, prod * i, ct + 1);         path.pop_back();       }     }   }   vector<int> getV(int a) {     vector<int> g;     while (a > 1) {       int x = 0, y = d[a];       while (d[a] == y) {         a /= d[a];         x++;       }       g.push_back(x + 1);     }     sort(g.rbegin(), g.rend());     return g;   }   int main() {     f(M, 1, 0);     map<vector<int>, int> g;     for (int i = 2; i < N; i++) {       if (!d[i]) {         d[i] = i;         for (long long int j = i * (long long int)i; j < N; j += i) {           if (!d[j]) d[j] = i;         }       }     }     for (int i = 1; i < N; i++) {       vector<int> t = getV(i);       if (!g.count(t)) {         int x = g.size();         g[t] = x;       }     }     for (int i = 0; i < v.size(); i++) {       vector<int> &c = v[i];       for (int j = 0; j < c.size(); j++) {         if (j == 0 || c[j - 1] != c[j]) {           c[j]++;           if (mp.count(c)) {             h[i].push_back(mp[c]);             h[mp[c]].push_back(i);           }           c[j]--;         }       }       if (c.size() < MAX) {         c.push_back(2);         if (mp.count(c)) {           h[i].push_back(mp[c]);           h[mp[c]].push_back(i);         }         c.pop_back();       }     }     for (int i = 0; i < 300; i++) {       for (int j = 0; j <= M; j++) {         dist[i][j] = INF;       }     }     for (auto &p : g) {       fill(w, w + T, -1);       queue<int> q;       w[mp[p.first]] = 0;       q.push(mp[p.first]);       while (!q.empty()) {         int node = q.front();         q.pop();         for (int to : h[node]) {           if (w[to] == -1) {             w[to] = w[node] + 1;             q.push(to);           }         }       }       for (int j = 0; j < v.size(); j++) {         dist[p.second][pr[j]] = min(dist[p.second][pr[j]], w[j]);       }     }     int q;     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       a = g[getV(a)];       b = g[getV(b)];       int ans = INF;       for (int i = 0; i <= M; i++) ans = min(ans, dist[a][i] + dist[b][i]);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[2 * 1000005];   int n;   int input() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; i++) p[i] = i;     return 0;   }   int solve() {     int i, j, ii;     int t1, t2;     for (i = 2; i <= n; i++) {       t1 = p[i - 1];       for (j = i + i - 1; j < n + i - 1; j += i) {         t2 = p[j];         p[j] = t1;         t1 = t2;       }       p[n + i - 1] = t1;     }     return 0;   }   int output() {     int i;     for (i = n; i < n + n; i++) printf( %d  , p[i]);     printf(  n );     return 0;   }   int main() {     input();     solve();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int C[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, r;     cin >> n >> r;     double sum = 0;     for (int i = 0; i < (1 << n); i++) {       cin >> C[i];       sum += C[i];     }     cout << setprecision(15) << fixed << sum / (1 << n) <<   n ;     while (r--) {       int z, g;       cin >> z >> g;       sum += g - C[z];       C[z] = g;       cout << setprecision(15) << fixed << sum / (1 << n) <<   n ;     }     return 0;   }