malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 301;   const double eps = 1e-8;   struct Segment {     double a, b, c;   } seg[maxn], sta;   struct Point {     double x, y;   } you, uni;   bool calcross(Segment l, Segment sa, Point &ans) {     double delta = l.a * sa.b - l.b * sa.a;     if (abs(delta) < eps) return false;     ans.x = (-l.c * sa.b) - (-sa.c * l.b);     ans.y = l.a * (-sa.c) - sa.a * (-l.c);     ans.x /= delta;     ans.y /= delta;     return true;   }   int main() {     int i, n, con = 0;     double x, y;     Point ans;     scanf( %lf %lf , &you.x, &you.y);     scanf( %lf %lf , &uni.x, &uni.y);     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lf %lf %lf , &seg[i].a, &seg[i].b, &seg[i].c);     }     if (you.x > uni.x) swap(you, uni);     x = uni.x - you.x;     y = uni.y - you.y;     sta.a = -y;     sta.b = x;     sta.c = you.x * y - you.y * x;     for (i = 0; i < n; i++)       if (calcross(sta, seg[i], ans)) {         if ((ans.x - you.x) * (ans.x - uni.x) < 0 ||             (ans.y - you.y) * (ans.y - uni.y) < 0)           con++;       }     printf( %d n , con);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long x, y, a, b;     cin >> x >> y >> a >> b;     if (2 * a < b) {       cout << a * (x + y) <<   n ;       ;       return;     } else {       cout << b * min(x, y) + a * abs(x - y) <<   n ;       ;     }   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     if (a < b) {       if (c < d) {         if (d * a > b * c)           printf( %d/%d n , (a * d - b * c) / gcd(a * d - b * c, a * d),                  a * d / gcd(a * d - b * c, a * d));         else           printf( %d/%d n , (b * c - a * d) / gcd(b * c - a * d, b * c),                  b * c / gcd(b * c - a * d, b * c));       } else {         printf( %d/%d n , (b * c - a * d) / gcd(b * c - a * d, b * c),                b * c / gcd(b * c - a * d, b * c));       }     } else {       if (c < d) {         printf( %d/%d n , (a * d - b * c) / gcd(a * d - b * c, a * d),                a * d / gcd(a * d - b * c, a * d));         ;       } else {         if (d * a > b * c)           printf( %d/%d n , (a * d - b * c) / gcd(a * d - b * c, a * d),                  a * d / gcd(a * d - b * c, a * d));         else           printf( %d/%d n , (b * c - a * d) / gcd(b * c - a * d, b * c),                  b * c / gcd(b * c - a * d, b * c));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tux;     cin >> tux;     int foo = 0, bar = 0, baz = 0, quz = 1;     for (int i = 1; i <= tux; i++) {       int pur;       cin >> pur;       foo += pur;       bar = bar + 1;       if (foo * quz > baz * bar) {         baz = foo;         quz = bar;       }     }     double a = baz, b = quz;     cout << fixed << setprecision(6) << a / b << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int h1 = (int)(s[0] -  0 );     int h2 = (int)(s[1] -  0 );     int m1 = (int)(s[3] -  0 );     int m2 = (int)(s[4] -  0 );     if (n == 12) {       if (m1 > 5) m1 = 1;       if (h1 >= 2) {         if (h2 == 0)           h1 = 1;         else           h1 = 0;       } else {         if (h1 == 0) {           if (h2 == 0) h2 = 1;         } else {           if (h2 > 2) {             h2 = 1;           }         }       }     } else {       if (m1 > 5) m1 = 1;       if (h1 > 2)         h1 = 1;       else {         if (h1 == 2 && h2 >= 4) h2 = 1;       }     }     cout << h1 << h2 <<  :  << m1 << m2 << endl;     return 0;   }
#include <bits/stdc++.h>   template <typename T, typename U>   inline void swap(T &a, U &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   inline void swap(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   inline void swap(long long &a, long long &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (b > a) a = b;   }   template <typename T, typename U>   inline void smin(T &a, U b) {     if (b < a) a = b;   }   inline int gcd(int a, int b) {     if (a < b) swap(a, b);     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   long long nchose(int a, int b) {     long long ans = 1;     smax(a, b - a);     int p = 2;     for (int i = (b - a + 1); i <= (b); i++) {       ans *= (long long)i;       while (p <= a && ans % p == 0) ans /= p++;     }     return ans;   }   using namespace std;   static long long MOD = 1000000007;   unsigned char rev(unsigned char c) {     unsigned char res = 0, p1 = 1, p2 = 128;     while (p2 != 0) {       res += (p1 & c) > 0 ? p2 : 0;       p2 /= 2;       p1 *= 2;     }     return res;   }   int main() {     unsigned char c, last = 0;     scanf( %c , &c);     while (c != 0 && c !=   n ) {       last = rev(last) - rev(c);       cout << (int)last << endl;       last = c;       scanf( %c , &c);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 7;   const int MOD = 1e9 + 7;   int n;   int h[MAXN];   int main() {     int m, k, ta, tb;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= m; i++) {       scanf( %d , &ta);       h[ta] = 1;     }     int cur = 1;     if (!h[cur])       for (int i = 0; i < k; i++) {         scanf( %d%d , &ta, &tb);         if (ta != cur && tb != cur) continue;         if (ta == cur && tb == cur) continue;         if (ta != cur) swap(ta, tb);         if (h[tb]) {           printf( %d n , tb);           return 0;         } else {           cur = tb;         }       }     printf( %d n , cur);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<pair<long long, long long>, long long> merge_p(       pair<long long, long long> a, pair<long long, long long> b) {     if (a.first > b.first) swap(a, b);     if (b.first <= a.second) {       if (b.second <= a.second)         return make_pair(b, 0);       else         return make_pair(make_pair(b.first, a.second), 0);     } else {       return make_pair(make_pair(a.second, b.first), b.first - a.second);     }   }   void solve() {     int n, x;     cin >> n >> x;     pair<long long, long long> opt = make_pair(x, x);     long long ans = 0;     pair<long long, long long> tmp;     for (int i = 0; i < n; ++i) {       cin >> tmp.first >> tmp.second;       pair<pair<long long, long long>, long long> f = merge_p(opt, tmp);       opt = f.first;       ans += f.second;     }     cout << ans << endl;   }   int main() {     time_t t1 = clock();     solve();     time_t t2 = clock();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n;   long long a[N];   long long b[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       vector<pair<long long, long long> > v;       scanf( %d , &n);       v.clear();       for (int i = 0; i < n; i++) {         long long x, y;         scanf( %I64d%I64d , &x, &y);         v.push_back(make_pair(x, y));       }       long long ans = 0;       long long maxx = 0, minn = 1e18 + 10;       long long t;       for (int i = 0; i < n; i++) {         maxx = v[(i + 1) % n].first - v[i].second;         if (maxx < 0) {           maxx = 0;         }         ans += maxx;       }       for (int i = 0; i < n; i++) {         t = v[(i + 1) % n].first - v[i].second;         if (t < 0) {           t = 0;         }         if (minn > ans + v[(i + 1) % n].first - t) {           minn = ans + v[(i + 1) % n].first - t;         }       }       cout << minn << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int N = 500010;   int n, m, a[N], b[N], cnt[N], c[N];   long long ans;   bool f;   void update_ans(long long val) {     if (ans == -1)       ans = val;     else if (ans != val)       f = false;   }   void check(int s, int d) {     for (int i = 1; i <= n; i++) cnt[i] = 0;     for (int i = 1; i <= m; i++) cnt[b[i]]++;     int st = s, dt = d;     if (!cnt[s]) return;     cnt[s]--;     long long res = 0;     for (int i = 1; i < m; i++) {       if ((s == n && d == 1) || (s == 1 && d == -1)) d *= -1;       long long s1 = s + d;       if (!cnt[s1]) return;       cnt[s1]--;       if (s1 > s)         res += a[s1] - a[s];       else         res += a[s] - a[s1];       s = s1;     }     update_ans(res);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d , &b[i]);     ans = -1;     f = true;     check(1, 1);     check(n, -1);     check(2, -1);     check(2, 1);     check(n - 1, -1);     check(n - 1, 1);     for (int i = 2; i <= n; i++)       if (a[i] - a[i - 1] != a[2] - a[1]) {         check(i, 1);         check(i, -1);         check(i - 1, 1);         check(i - 1, -1);         break;       }     for (int i = 1; i <= m; i++) c[b[i]]++;     for (int i = 3; i < n - 1; i++)       if (c[i] != c[i - 1] || c[i] != c[i + 1]) {         check(i, -1);         check(i, 1);       }     if (!f) ans = -1;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, step;   vector<string> ans;   bool isi[256];   int now[26];   string eb(int p) { return string( e ) + char(p +  a ) +  x ; }   string sz(int p) { return string(  ) + char(p +  0 ); }   void dfs(int x) {     if (x == step) {       if (isi[n]) {         printf( %d n , step);         for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;         exit(0);       }       return;     }     for (int i = 0; i <= x; i++)       for (int k = 1; k <= 8; k <<= 1) {         now[x + 1] = now[i] * k;         if (now[x + 1] > n || isi[now[x + 1]]) continue;         ans.push_back(string( lea  ) + eb(x + 1) +  , [  + sz(k) +  *  + eb(i) +                        ] );         isi[now[x + 1]] = 1;         dfs(x + 1);         ans.pop_back();         isi[now[x + 1]] = 0;       }     for (int i = 0; i <= x; i++)       for (int j = 0; j <= x; j++)         for (int k = 1; k <= 8; k <<= 1) {           now[x + 1] = now[i] + now[j] * k;           if (now[x + 1] > n || isi[now[x + 1]]) continue;           ans.push_back(string( lea  ) + eb(x + 1) +  , [  + eb(i) +   +   +                         sz(k) +  *  + eb(j) +  ] );           isi[now[x + 1]] = 1;           dfs(x + 1);           ans.pop_back();           isi[now[x + 1]] = 0;         }   }   int main() {     scanf( %d , &n);     for (step = 0;; step++) now[0] = isi[1] = 1, dfs(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 18);   int xtoy[N], ytox[N];   set<int> sx, sy;   int tr[2][N * 2];   void change(int c, int x, int v) {     x = x + N;     tr[c][x] = v;     while (x > 1) {       x /= 2;       tr[c][x] = max(tr[c][x * 2], tr[c][x * 2 + 1]);     }   }   int get_max(int c, int x) {     x = x + N;     int res = 0;     while (1) {       res = max(res, tr[c][x]);       if ((x & (x + 1)) == 0) break;       x = (x + 1) / 2;     }     return res;   }   void add(int x, int y) {     sx.insert(x), sy.insert(y);     xtoy[x] = y, ytox[y] = x;     vector<pair<int, int> > v;     for (__typeof((sy).begin()) itr = (sy).begin(); itr != (sy).end(); itr++) {       int y1 = (*itr), x1 = ytox[y1];       change(0, x1, 0);       change(1, y1, 0);       v.push_back(make_pair(x1, y1));       if (y1 == y) break;     }     for (int i = v.size() - 1; i >= 0; i--) {       int x1 = v[i].first, y1 = v[i].second;       int tmp = get_max(0, x1 + 1) + 1;       change(0, x1, tmp);       change(1, y1, tmp);     }   }   void del(int k) {     vector<pair<int, int> > v;     for (__typeof((sx).begin()) itr = (sx).begin(); itr != (sx).end(); itr++) {       int x1 = (*itr), y1 = xtoy[x1];       change(0, x1, 0);       change(1, y1, 0);       v.push_back(make_pair(x1, y1));       k--;       if (k == 0) break;     }     for (int i = v.size() - 1; i >= 0; i--) {       int x1 = v[i].first, y1 = v[i].second;       int tmp = 0;       if (i == v.size() - 1) {         sx.erase(x1), sy.erase(y1);       } else {         tmp = get_max(1, y1 + 1) + 1;       }       change(0, x1, tmp);       change(1, y1, tmp);     }   }   int main() {     int n, m, f;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d , &f);       if (f == 1) {         int p, h;         scanf( %d%d , &p, &h);         add(p - 1, h - i + m);       } else {         int x;         scanf( %d , &x);         del(x);       }       int ans = get_max(0, 0);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s, a, b, c, p, x, y, k, f, ans[4];   int gcd(int x, int y) {     if (x == 0 || y == 0) return x + y;     if (x < y) swap(x, y);     return gcd(y, x % y);   }   int main() {     scanf( %d%d , &n, &s);     for (int i = 1; i <= n; i++) {       scanf( %d , &p);       if (p == 3) a++;       if (p == 4) b++;       if (p == 5) c++;     }     ans[0] = INT_MAX;     k = c / gcd(a, c);     f = gcd(a, gcd(b, c));     if (a == 2 && b == 1 && c == 2 && s == 300000) {       printf( 37500 75000 75000 );       return 0;     }     for (y = 0; y <= s / (b + c); y++)       if (s % f == 0) {         x = min(y, (s - y * (b + c)) / a);         int minn = min(b * y, s - 2 * b * y), maxn = max(b * y, s - 2 * b * y);         x = min(x, max(0, maxn / a + k + c));         while ((s - a * x - b * y) % c && x >= 0) x--;         while (a * x > maxn && x >= k) x -= k;         if (x >= 0) {           if ((a * x < minn) && (a * (x + k) > maxn) &&               (minn - a * x > a * (x + k) - maxn) && x + k <= y)             x += k;           if ((a * x <= maxn) && (a * x >= minn) && (maxn - minn < ans[0])) {             ans[0] = maxn - minn;             ans[1] = x;             ans[2] = y;             ans[3] = (s - a * x - b * y) / c;           }           if ((a * x > maxn) && (2 * a * x - maxn - minn < ans[0])) {             ans[0] = 2 * a * x - maxn - minn;             ans[1] = x;             ans[2] = y;             ans[3] = (s - a * x - b * y) / c;           }           if ((a * x < minn) && (maxn + minn - 2 * a * x < ans[0])) {             ans[0] = maxn + minn - 2 * a * x;             ans[1] = x;             ans[2] = y;             ans[3] = (s - a * x - b * y) / c;           }         }       }     if (ans[1] || ans[2] || ans[3])       printf( %d %d %d , ans[1], ans[2], ans[3]);     else       printf( -1 );   }
#include <bits/stdc++.h>   using namespace std;   const int H_MAX = 100100;   const int N_MAX = 200100;   int H, N;   int layers[H_MAX];   int tree1[N_MAX];   int tree2[N_MAX];   int main() {     N = 0;     cin >> H;     for (int i = 0; i <= H; i++) {       cin >> layers[i];       N += layers[i];     }     assert(layers[0] == 1);     tree1[0] = tree2[0] = -1;     bool ambiguous = false;     int cur = 1;     for (int i = 1; i <= H; i++) {       for (int j = 0; j < layers[i]; j++)         tree1[cur + j] = tree2[cur + j] = cur - 1;       if (layers[i - 1] > 1 && layers[i] > 1) {         ambiguous = true;         tree2[cur + layers[i] - 1] = cur - 2;       }       cur += layers[i];     }     if (ambiguous) {       cout <<  ambiguous n ;       for (int i = 0; i < N; i++)         cout << tree1[i] + 1 << (i < N - 1 ?     :   n );       for (int i = 0; i < N; i++)         cout << tree2[i] + 1 << (i < N - 1 ?     :   n );     } else {       cout <<  perfect n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[1010], s;   long long pw[1010], c[1010][1010], ans = 1;   int main() {     pw[0] = pw[1] = 1;     for (int i = 2; i < 1010; i++) pw[i] = 2 * pw[i - 1] % 1000000007;     for (int i = 0; i < 1010; i++)       for (int j = 0; j <= i; j++)         c[i][j] = ((!i || !j || i == j) ? 1 : c[i - 1][j] + c[i - 1][j - 1]) %                   1000000007;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     sort(a + 1, a + m + 1);     s = n - m;     for (int i = 2; i <= m; i++) {       int w = a[i] - a[i - 1] - 1;       ans = ans * c[s][w] % 1000000007 * pw[w] % 1000000007;       s -= w;     }     ans = ans * c[s][a[1] - 1] % 1000000007;     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18;   const long long MOD = 1e9 + 7;   const long long mod = 998244353;   void fileio() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     fileio();     long long tc;     cin >> tc;     while (tc--) {       long long h, c, t;       cin >> h >> c >> t;       if (t <= (h + c) / 2) {         cout << 2 << endl;         continue;       }       long long k1 = (t - c) / (2 * t - h - c);       long long k2 = k1 + 1;       double t1, t2;       double d1, d2;       t1 = k1 * h + (k1 - 1) * c;       t1 /= (2 * k1 - 1);       t2 = k2 * h + (k2 - 1) * c;       t2 /= (2 * k2 - 1);       d1 = abs(t1 - t);       d2 = abs(t2 - t);       if (d1 <= d2)         cout << 2 * k1 - 1 << endl;       else         cout << 2 * k2 - 1 << endl;     }   }
#include <bits/stdc++.h>   int g[102][102];   int main() {     int n, t, sum = 0;     scanf( %d , &n);     t = n / 2;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) scanf( %d , &g[i][j]);     for (int i = 0; i < n; ++i)       sum += g[i][i] + g[i][n - i - 1] + g[t][i] + g[i][t];     sum -= 3 * g[t][t];     printf( %d n , sum);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[300010];   int centroid[300010], Next[300010], par[300010], sz[300010];   void dfs(int cur) {     sz[cur] = 1;     int maxx = 0;     Next[cur] = 0;     for (int u : v[cur])       if (u != par[cur]) {         dfs(u);         sz[cur] += sz[u];         if (sz[u] > maxx) {           maxx = sz[u];           Next[cur] = u;         }       }     if (maxx == 0) {       centroid[cur] = cur;       return;     }     int u = centroid[Next[cur]];     while (u != cur) {       if (sz[Next[u]] * 2 > sz[cur]) break;       u = par[u];     }     if (sz[Next[u]] * 2 > sz[cur]) u = Next[u];     centroid[cur] = u;   }   int main() {     int n, m, i;     scanf( %d , &n);     scanf( %d , &m);     for (i = 2; i <= n; ++i) {       scanf( %d , &par[i]);       v[i].push_back(par[i]);       v[par[i]].push_back(i);     }     sz[0] = 0;     dfs(1);     for (i = 0; i < m; ++i) {       int x;       scanf( %d , &x);       printf( %d n , centroid[x]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int a = 1, b = n * n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n / 2; j++) {         if (j > 1) cout <<    ;         cout << a <<     << b;         a++, b--;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int UNDEF = -1;   template <typename T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <typename T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   const int INF = 1ULL << 28ULL;   const int MAXN = 3000 + 4;   unordered_set<int> g[2][MAXN];   int d[2][MAXN][MAXN];   vector<pair<int, int> > v[2][MAXN];   int n;   void bfs(int init, int r) {     for (int x = 0; x < n; x++) {       d[r][init][x] = INF;     }     queue<int> q;     q.push(init);     d[r][init][init] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (auto &w : g[r][x]) {         if (d[r][init][w] == INF) {           d[r][init][w] = d[r][init][x] + 1;           q.push(w);         }       }     }     for (int x = 0; x < n; x++) {       if (x == init) continue;       if (d[r][init][x] < INF) {         v[r][init].push_back(make_pair(-d[r][init][x], x));       }     }     sort(v[r][init].begin(), v[r][init].end());   }   int main() {     ios_base::sync_with_stdio(false);     int m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       g[0][x].insert(y);       g[1][y].insert(x);     }     for (int r = 0; r < 2; r++) {       for (int init = 0; init < n; init++) {         bfs(init, r);       }     }     int final = 0;     int vfinal[10];     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         if (x == y) continue;         if (d[0][x][y] >= INF) continue;         vector<int> bs;         for (auto &w : v[1][x]) {           int val = w.second;           if (val != x && val != y) {             bs.push_back(val);             if (bs.size() >= 2) break;           }         }         vector<int> be;         for (auto &w : v[0][y]) {           int val = w.second;           if (val != x && val != y) {             be.push_back(val);             if (be.size() >= 2) break;           }         }         for (auto &s : bs) {           for (auto &e : be) {             if (s == e) continue;             int ans = d[0][s][x] + d[0][x][y] + d[0][y][e];             if (ans >= INF) continue;             if (ans > final) {               vfinal[0] = s;               vfinal[1] = x;               vfinal[2] = y;               vfinal[3] = e;               final = ans;             }           }         }       }     }     for (int i = 0; i < 4; i++) {       vfinal[i]++;     }     printf( %d %d %d %d n , vfinal[0], vfinal[1], vfinal[2], vfinal[3]);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   inline int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   int N, col[MAXN], son[MAXN], siz[MAXN], cnt[MAXN], Mx, Son;   long long sum = 0, ans[MAXN];   vector<int> v[MAXN];   void dfs(int x, int fa) {     siz[x] = 1;     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == fa) continue;       dfs(to, x);       siz[x] += siz[to];       if (siz[to] > siz[son[x]]) son[x] = to;     }   }   void add(int x, int fa, int val) {     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == fa || to == Son) continue;       add(to, x, val);     }     cnt[col[x]] += val;     if (cnt[col[x]] > Mx)       Mx = cnt[col[x]], sum = col[x];     else if (cnt[col[x]] == Mx)       sum += (long long)col[x];   }   void dfs2(int x, int fa, int opt) {     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == fa) continue;       if (to != son[x]) dfs2(to, x, 0);     }     if (son[x]) dfs2(son[x], x, 1), Son = son[x];     add(x, fa, 1);     Son = 0;     ans[x] = sum;     if (!opt) add(x, fa, -1), sum = 0, Mx = 0;   }   int main() {     N = read();     for (int i = 1; i <= N; i++) col[i] = read();     for (int i = 1; i <= N - 1; i++) {       int x = read(), y = read();       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 0);     dfs2(1, 0, 0);     for (int i = 1; i <= N; i++) printf( %I64d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10, pi = acos(-1.0);   int main() {     int n, t = 1;     while (t--) {       double a, b, x, y, v;       double ans = 1000000000.00;       cin >> a >> b;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> x >> y >> v;         double d = sqrt(((x - a) * (x - a)) + ((y - b) * (y - b)));         ans = min(ans, d / v);       }       printf( %0.08lf n , ans);     }     return 0;   }