malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (~scanf( %d , &n)) {       int cnt = 0;       for (int i = 1; i < n; i++) {         for (int j = i + 1; j < n; j++) {           int sum = i * i + j * j;           if (sum <= n * n) {             if ((int)sqrt(sum) * (int)sqrt(sum) == sum) cnt++;           }         }       }       printf( %d n , cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k[1005], n, i, j;   long long kx[1005];   int main() {     cin >> n;     for (i = 1; i <= n; i++) cin >> k[i];     kx[1] = 2;     for (i = 2; i <= n; i++) {       if (k[i] == i)         kx[i] = 2;       else {         for (j = k[i]; j < i; j++) kx[i] = (kx[i] + kx[j]) % 1000000007;         kx[i] = (kx[i] + 2) % 1000000007;       }     }     long long ans = 0;     for (i = 1; i <= n; i++) ans = (ans + kx[i]) % 1000000007;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (n == 1) {       cout <<  YES ;       return 0;     }     vector<long long> v;     long long cnt0 = 1;     for (int i = 1; i < n; i++) {       if (a[i] != a[i - 1]) {         v.push_back(cnt0);         cnt0 = 1;       } else         cnt0++;       if (i == n - 1) {         v.push_back(cnt0);       }     }     long long cnt = 1;     for (int i = 0; i < v.size(); i++) {       if (v[i] == v[i + 1]) cnt++;     }     if (cnt == v.size())       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC push_options   #pragma GCC optimize( unroll-loops )   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int INF = 10e18;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n], c[n];       for (long long i = 0; i < n; i++) {         cin >> a[i] >> b[i];       }       for (long long i = 1; i <= n; i++) {         c[i % n] = max(0ll, a[i % n] - b[i - 1]);       }       long long sum = accumulate(c, c + n, 0ll);       long long res = INF;       for (long long i = 0; i < n; i++) {         res = min(res, sum + a[i] - c[i]);       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int contrib[312345] = {0};   bool in_set[312345] = {0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     vector<int> ans;     int cnt = 0;     for (int i = 1; i <= n / 2; i++) {       if (cnt + contrib[i] <= k) {         ans.push_back(i);         in_set[i] = true;         cnt += contrib[i];         for (int j = i + i; j <= n; j += i) contrib[j]++;       } else {         while (cnt + contrib[i] > k) {           cnt -= contrib[ans.back()];           for (int j = ans.back() + ans.back(); j <= n; j += ans.back())             contrib[j]--;           in_set[ans.back()] = false;           ans.pop_back();         }         ans.push_back(i);         in_set[i] = true;         cnt += contrib[i];         for (int j = i + i; j <= n; j += i) contrib[j]++;       }       if (cnt == k) break;     }     priority_queue<pair<int, int> > pq;     for (int i = n / 2 + 1; i <= n; i++) {       if (in_set[i]) continue;       pq.push(make_pair(contrib[i], i));     }     while (!pq.empty()) {       while (!pq.empty() && cnt + pq.top().first > k) pq.pop();       if (pq.empty()) break;       cnt += pq.top().first;       ans.push_back(pq.top().second);       pq.pop();     }     if (cnt != k) {       cout <<  No  << endl;       return 0;     }     cout <<  Yes  << endl;     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   void qread(int &x) {     int neg = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     x *= neg;   }   const int maxn = 200005;   char c[maxn];   int n, m;   string s, t;   int main() {     scanf( %d%d , &n, &m);     scanf( %s , c);     s = c;     scanf( %s , c);     t = c;     bool ok = false;     for (int(i) = 0; (i) < n; i++)       if (s[i] ==  * ) ok = true;     if (!ok) {       puts(s == t ?  YES  :  NO );       return 0;     }     int pre = 0, suf = 0;     while (s[pre] !=  *  && s[pre] == t[pre]) pre++;     while (s[n - suf - 1] !=  *  && s[n - suf - 1] == t[m - suf - 1]) suf++;     if (s[pre] ==  *  && s[n - suf - 1] ==  *  && pre - 1 < m - suf)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[500000];   int mina, maxa;   int n, k;   long long sum = 0;   bool check(int c) {     sum = 0;     for (int i = 0; i < n; i++) {       if (a[i] + c < mina) {         sum += mina - c - a[i];       } else {         break;       }     }     if (sum > k) return false;     return true;   }   bool checkp(int c) {     sum = 0;     for (int i = 0; i < n; i++) {       if (a[i] - c > maxa) {         sum += a[i] - c - maxa;       }     }     if (sum > k) return false;     return true;   }   int main() {     scanf( %d %d , &n, &k);     long long sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     if (sum % n == 0) {       mina = maxa = sum / n;     } else {       mina = sum / n;       maxa = sum / n + 1;     }     sort(a, a + n);     int ll = 0, rr = 1000000000;     while (ll != rr) {       int mid = (ll + rr) / 2;       if (check(mid)) {         rr = mid;       } else {         ll = mid + 1;       }     }     int lll = 0, rrr = 1000000000;     while (lll != rrr) {       int mid = (lll + rrr) / 2;       if (checkp(mid)) {         rrr = mid;       } else {         lll = mid + 1;       }     }     printf( %lld , (long long)lll + ll + maxa - mina);     scanf( %d , &n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s, f, i;     cin >> n >> m >> s >> f;     long long t;     map<long long, pair<int, int>> h;     pair<int, int> R;     for (i = 0; i < m; i++) {       cin >> t >> R.first >> R.second;       h[t] = R;     }     i = 1;     if (s < f)       while (s != f) {         if (h.find(i) == h.end()) {           cout <<  R ;           s++;         } else {           if ((h[i].first <= s && s <= h[i].second) ||               (h[i].first <= s + 1 && s + 1 <= h[i].second)) {             cout <<  X ;           } else {             cout <<  R ;             s++;           }         }         i++;       }     else {       while (s != f) {         if (h.find(i) == h.end()) {           cout <<  L ;           s--;         } else {           if ((h[i].first <= s && s <= h[i].second) ||               (h[i].first <= s - 1 && s - 1 <= h[i].second)) {             cout <<  X ;           } else {             cout <<  L ;             s--;           }         }         i++;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int d[n];     int total = 0;     for (int i = 0; i < n; i++) {       cin >> d[i];       total += d[i];     }     int s, t;     cin >> s >> t;     if (s == t) {       cout << 0;       return 0;     }     if (s > t) swap(s, t);     int ans = 0;     for (int i = s; i < t; i++) {       ans += d[i - 1];     }     cout << min(ans, total - ans);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, Q;   double sy, l[200100], r[200100], sum[200100], zl, zr, x, y, ans;   struct Node {     double x, y;   } bj[2][200100], tmp, L, R;   inline bool lef(Node u, Node v, Node w) {     if (u.x == v.x) return w.x < u.x;     double t;     t = v.x - (v.x - u.x) * (v.y - w.y) / (v.y - u.y);     return w.x < t;   }   inline double ask(int u) {     double p, q;     if (bj[0][u].x == x)       p = x;     else {       p = x - (x - bj[0][u].x) * (y - sy) / y;     }     if (bj[1][u].x == x)       q = x;     else {       q = x - (x - bj[1][u].x) * (y - sy) / y;     }     return max((double)0, min(q, zr) - max(p, zl));   }   int main() {     int i, j, p, q, mid, a, b;     cin >> sy >> zl >> zr >> n;     L.y = R.y = sy, L.x = zl, R.x = zr;     for (i = 1; i <= n; i++) {       scanf( %lf%lf , &l[i], &r[i]);       sum[i] = sum[i - 1] + r[i] - l[i];       bj[0][i].y = 0, bj[0][i].x = l[i];       bj[1][i].y = 0, bj[1][i].x = r[i];     }     cin >> m;     for (i = 1; i <= m; i++) {       scanf( %lf%lf , &x, &y);       ans = 0;       tmp.x = x, tmp.y = y;       for (p = 1, q = n; p < q;) {         mid = ((p + q) >> 1);         if (lef(tmp, bj[0][mid], L))           q = mid;         else           p = mid + 1;       }       a = p - 1;       for (p = 1, q = n; p < q;) {         mid = ((p + q) >> 1);         if (!lef(tmp, bj[1][mid], R))           p = mid + 1;         else           q = mid;       }       b = p;       printf( %.10f n , ask(a) + ask(b) * (a != b) +                             max((double)0, sum[b - 1] - sum[a]) * (y - sy) / y);     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   const int MAX_N = 1000009;   const long long mod = 998244353;   long long modpow(long long a, long long b, long long m) {     long long p = 1, q = a;     for (int i = 0; i < 32; i++) {       if ((b / (1LL << i)) % 2 == 1) {         p *= q;         p %= m;       }       q *= q;       q %= m;     }     return p;   }   long long N, fact[MAX_N], factinv[MAX_N];   void init() {     fact[0] = 1;     for (int i = 1; i <= 1000000; i++) fact[i] = (1LL * fact[i - 1] * i) % mod;     for (int i = 0; i <= 1000000; i++) factinv[i] = modpow(fact[i], mod - 2, mod);   }   long long ncr(long long n, long long r) {     if (r < 0 || n < r) return 0;     return (fact[n] * factinv[r] % mod) * factinv[n - r] % mod;   }   int main() {     cin >> N;     init();     long long V1 = modpow(modpow(3, N, mod), N, mod) -                    modpow((modpow(3, N, mod) - 3LL + mod), N, mod);     V1 += mod;     V1 *= 2LL;     V1 %= mod;     long long V2 = 0;     for (int i = 1; i <= N; i++) {       long long E1 = ncr(N, i);       long long E2 = modpow(3, N - i, mod);       long long E3 = (E2 + mod - 1) % mod;       E2 = modpow(E2, N, mod);       E3 = modpow(E3, N, mod);       if (i % 2 == 1) V2 += E1 * (E2 - E3 + mod);       if (i % 2 == 0) V2 -= E1 * (E2 - E3 + mod);       while (V2 < 0) V2 += mod * mod;       V2 %= mod;     }     V2 *= 3LL;     V2 %= mod;     cout << (V1 - V2 + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 4 * atan((long double)1);   const long long mod = 1e9 + 7;   const long long inf = 922337203685477;   const long long nax = 1e5 + 5;   long long n, p, m;   long long d[nax], t[nax];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> p >> m;     for (long long i = 1; i <= n; i++) {       cin >> d[i] >> t[i];     }     d[0] = 1;     d[n + 1] = m + 1;     long long cur = 0, ans = 0;     for (long long i = 1; i <= n + 1; i++) {       long long dif = 0;       if (cur > 0) {         dif = cur / p;       }       long long minus = d[i] - d[i - 1] - dif;       if (minus < 0) {         minus = 0;       }       ans += minus;       cur -= (d[i] - d[i - 1]) * p;       cur += t[i];     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int SIZ_TREE = 3e5 + 10;   int n, m;   struct Node {     int u, v;     Node(int U = 0, int V = 0) {       u = U, v = V;       if (u < v) swap(u, v);     }     bool operator<(const Node A) const {       if (u < A.u || (u == A.u && v < A.v)) return true;       return false;     }   };   vector<int> f[N], ans[2];   vector<Node> edg;   map<Node, bool> col;   bool v[N], opr[N], flag1, flag2, add[N];   int cnt_p, cnt_opr;   void init() {     char s;     int x, y;     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x, &y);       while ((s = getchar()) ==    )         ;       f[y].push_back(x);       f[x].push_back(y);       edg.push_back(Node(x, y));       col[Node(x, y)] = (s ==  R  ? false : true);     }   }   bool dfs(int x) {     v[x] = true;     cnt_p++;     cnt_opr += opr[x];     for (int i = 0; i < f[x].size(); i++) {       int y = f[x][i];       if (v[y]) {         if ((col[Node(x, y)] ^ opr[x] ^ opr[y]) == true) return false;       } else {         opr[y] = col[Node(x, y)] ^ opr[x];         if (!dfs(y)) return false;       }     }     return true;   }   void add_ans(int x, bool s1, int s2) {     if (add[x]) return;     opr[x] ^= s1;     add[x] = true;     if (opr[x]) ans[s2].push_back(x);     for (int i = 0; i < f[x].size(); i++) add_ans(f[x][i], s1, s2);   }   bool solve(int sign) {     memset(opr, 0, sizeof(opr));     memset(v, 0, sizeof(v));     memset(add, 0, sizeof(add));     for (int i = 1; i <= n; i++)       if (!v[i]) {         cnt_opr = cnt_p = 0;         if (!dfs(i)) return false;         add_ans(i, (cnt_opr * 2 > cnt_p), sign);       }     return true;   }   void print(int s) {     printf( %d n , ans[s].size());     for (int i = 0; i < ans[s].size(); i++) printf( %d  , ans[s][i]);     printf(  n );   }   void work() {     flag1 = solve(0);     for (int i = 0; i < edg.size(); i++) col[edg[i]] = (!col[edg[i]]);     flag2 = solve(1);     if (!flag1 && !flag2)       printf( -1 n );     else if (flag1 && !flag2)       print(0);     else if (!flag1 && flag2)       print(1);     else if (ans[0].size() < ans[1].size())       print(0);     else       print(1);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e6 + 3;   long long power(long long base, long long exp) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = (ans * base) % MOD;       base = (base * base) % MOD;       exp >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     if (n <= 63 && k > (1LL << n)) {       cout << 1 <<     << 1;       return 0;     }     long long v2 = 0;     int digits = __builtin_popcountll(k - 1);     v2 = k - 1 - digits;     long long ntmp = n % (MOD - 1);     if (ntmp < 0) ntmp += (MOD - 1);     long long ktmp = k % (MOD - 1);     if (ktmp < 0) ktmp += (MOD - 1);     long long v2tmp = v2 % (MOD - 1);     if (v2tmp < 0) v2tmp += (MOD - 1);     long long exponent = ntmp * (ktmp - 1) - v2tmp;     exponent %= (MOD - 1);     if (exponent < 0) exponent += MOD - 1;     long long denom = power(2, exponent);     long long numpart = 0;     if (k - 1 >= MOD) {       numpart = 0;     } else {       long long prod = 1;       long long ntmp2 = power(2, ntmp);       prod = power(2, v2tmp);       prod = power(prod, MOD - 2);       if (prod < 0) prod += MOD;       for (long long y = 1; y <= k - 1; y++) {         prod = (prod * (ntmp2 - y)) % MOD;       }       numpart = prod;     }     long long num = (denom - numpart) % MOD;     num %= MOD;     denom %= MOD;     if (num < 0) num += MOD;     if (denom < 0) denom += MOD;     cout << num <<     << denom;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n, k, i;     cin >> n >> k;     vector<pair<long long, long long> > v;     long long a[n], b[n];     long long x, y;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < n; i++) {       x = a[i] - b[i];       v.push_back(make_pair(x, i));     }     sort(v.begin(), v.end());     i = 0;     y = 0;     while (i < n) {       if (i < k || v[i].first <= 0)         y = y + a[v[i].second];       else if (i >= k && v[i].first > 0)         break;       ++i;     }     while (i < n) {       y = y + b[v[i].second];       ++i;     }     cout << y;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long s, x;     cin >> s >> x;     long long ans = __builtin_popcountll(x);     ans = 1LL << ans;     if (s == x) ans -= 2;     for (int i = 0; i < 60; i++) {       if (x & (1LL << i)) s -= 1LL << i;     }     for (int i = 0; i < 60; i++) {       int j = i + 1;       if ((s & (1LL << j)) && !(x & (1LL << i))) s -= 1LL << j;     }     if (s != 0)       puts( 0 );     else       cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tmp;     bool ok = 1;     int ar[5];     memset(ar, 0, sizeof(ar));     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &tmp);       tmp /= 25;       if (!ok) continue;       if (tmp == 1) {         ar[1]++;       } else if (tmp == 2) {         if (ar[1] > 0) {           ar[1]--;           ar[2]++;         } else           ok = 0;       } else if (tmp == 4) {         if (ar[1] > 0 && ar[2] > 0) {           ar[1]--;           ar[2]--;           ar[4]++;         } else if (ar[1] > 2) {           ar[1] -= 3;           ar[4]++;         } else           ok = 0;       }     }     if (ok)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Que {     int a, b, w;   } Q[300010];   bool operator<(Que a, Que b) { return a.b < b.b; }   int n, i, m, Lim, j;   long long ans[301000], w[301000], s[301000];   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %I64d , &w[i]);     scanf( %d , &m);     for (i = 0; i < m; i++) scanf( %d%d , &Q[i].a, &Q[i].b), Q[i].a--, Q[i].w = i;     sort(Q, Q + m);     Lim = (int)sqrt(n);     for (i = 0; i < m; i++) {       if (Q[i].b > Lim) {         long long tmp = 0;         for (j = Q[i].a; j < n; j += Q[i].b) tmp += w[j];         ans[Q[i].w] = tmp;       } else {         memset(s, 0, sizeof(s));         for (j = n - 1; j >= 0; j--) s[j] = w[j] + s[j + Q[i].b];         j = i;         do {           ans[Q[j].w] = s[Q[j].a];           j++;         } while (Q[j].b == Q[j - 1].b);         i = j - 1;       }     }     for (i = 0; i < m; i++) printf( %I64d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1000000 + 5;   const long long DIFF = 2000;   const long long mod = 1000000000 + 7;   long long dp[DIFF + 5][DIFF + 5];   char s[maxn];   int main() {     dp[0][0] = 1;     for (int i = 1; i <= DIFF; dp[i][0] = dp[i - 1][1], i++)       for (int j = 1; j <= i; j++)         dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % mod;     long long n, m;     scanf( %I64d%I64d%s , &n, &m, s);     long long len = strlen(s), diff = 0, Min = 0, ans = 0;     for (long long i = 0; i < len; i++) {       diff += (s[i] ==  (  ? 1 : -1);       Min = min(Min, diff);     }     for (long long i = 0; i <= n - m; i++)       for (long long j = 0; j <= i; j++)         if (j + Min >= 0 && j + diff >= 0 && j + diff <= n - m)           ans = (ans + (dp[i][j] * dp[n - m - i][j + diff]) % mod) % mod;     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, a, b, i, c = 0, j = 0;     cin >> x >> y;     a = 240 - y;     for (i = 1; c <= a; i++) {       c = c + (5 * i);       j++;     }     if (j - 1 <= x) {       cout << j - 1 << endl;     } else {       cout << x << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mx = (1 << 22);   long long f[mx], ans[mx];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     memset(ans, -1, sizeof(ans));     for (long long i = 0; i < n; i++) {       f[a[i]]++;       ans[a[i]] = a[i];     }     for (long long j = 0; j < 22; j++)       for (long long i = 0; i < mx; i++)         if (i & (1 << j)) {           f[i] += f[i ^ (1 << j)];           if (f[i ^ (1 << j)]) ans[i] = ans[i ^ (1 << j)];         }     for (long long i = 0; i < n; i++) {       long long p = (mx - 1) & (~a[i]);       cout << ans[p] <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   inline void upd1(T1& a, const T2& b) {     a = a < b ? a : b;   }   template <class T1, class T2>   inline void upd2(T1& a, const T2& b) {     a = a > b ? a : b;   }   template <class T>   inline bool equ(const T& a, const T& b) {     return !memcmp(&a, &b, sizeof a);   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   struct ano {     operator long long() {       long long x = 0, y = 0, c = getchar();       while (c < 48) y = c == 45, c = getchar();       while (c > 47) x = x * 10 + c - 48, c = getchar();       return y ? -x : x;     }   } buf;   const int p = 1e9 + 7;   const int N = 1e6 + 5;   int w[N], a[N], l[N], r[N];   long long cal(long long a, long long n, long long d) {     return (a * n + n * (n - 1) / 2 % p * d) % p;   }   int main() {     int n = buf, m = buf;     for (int i = 1; i <= n; ++i) w[i] = buf;     w[n + 1] = 1 << 30;     int j = 0;     for (int i = 1; i <= n + 1; ++i) {       while (j > 0 && w[a[j]] <= w[i]) r[a[j--]] = i - 1;       l[i] = a[j] + 1;       a[++j] = i;     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       int a = i - l[i] + 1;       int b = r[i] - i + 1;       int c = (min(a, b) - 1) / (m - 1);       long long s = cal(m, c, m - 1);       int v = (c + 1) * (m - 1) + 1;       if (max(a, b) >= v) {         long long d = (max(a, b) - v) / (m - 1);         s += ((d + 1) * min(a, b)) % p;         v += (d + 1) * (m - 1);       }       v = a + b - v;       if (v >= 1) s += cal(v, (v - 1) / (m - 1) + 1, 1 + p - m);       ans += w[i] * s % p;     }     cout << ans % p << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 105, maxm = 5005;   const double eps = 1e-9;   int N, M, m, X[maxm], Y[maxm], Z[maxm];   double f[maxn][maxn], p[maxn];   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= M; i++) {       scanf( %d%d%d , &X[i], &Y[i], &Z[i]);       if (X[i] > 1 && X[i] < N) f[X[i]][X[i]]++, f[X[i]][Y[i]]--;       if (Y[i] > 1 && Y[i] < N) f[Y[i]][Y[i]]++, f[Y[i]][X[i]]--;     }     f[1][N + 1] = 1, f[1][1] = 1;     f[N][N + 1] = 0, f[N][N] = 1;     for (int i = 1; i <= N; i++) {       if (abs(f[i][i]) < eps)         for (int j = i + 1; j <= N; j++)           if (abs(f[j][i]) > eps) {             for (int k = i; k <= N + 1; k++) f[i][k] += f[j][k];             break;           }       for (int j = i + 1; j <= N; j++)         if (abs(f[j][i]) > eps) {           double r(f[j][i] / f[i][i]);           for (int k = i; k <= N + 1; k++) f[j][k] -= f[i][k] * r;         }     }     for (int i = N; i; i--)       if (abs(f[i][i]) > eps) {         p[i] = f[i][N + 1];         for (int j = i + 1; j <= N; j++) p[i] -= f[i][j] * p[j];         p[i] /= f[i][i];       }     double rate(1.0 / 0), ans(0);     for (int i = 1; i <= M; i++) rate = min(rate, Z[i] / abs(p[X[i]] - p[Y[i]]));     for (int i = 1; i <= M; i++) {       if (X[i] == 1) ans += p[1] - p[Y[i]];       if (Y[i] == 1) ans += p[1] - p[X[i]];     }     printf( %.7f n , isfinite(rate) ? ans * rate : 0);     for (int i = 1; i <= M; i++)       printf( %.7f n , isfinite(rate) ? (p[X[i]] - p[Y[i]]) * rate : 0);     return 0;   }