malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 2e5 + 5;   const long long MAX2 = 11;   const long long MOD = 998244353;   const long long MOD2 = 1000005329;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 2000;   int n, m, a, b, c, v[205][205], ans;   pair<double, pair<int, int> > e[205 * 205];   double le, ri, m1, m2, n1, n2, a1, a2, u[205][205], nx;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (i != j) v[i][j] = MOD;     for (int i = 1; i <= m; ++i) {       cin >> a >> b >> c;       e[i] = {c, {a, b}};       v[a][b] = v[b][a] = min(v[a][b], c);     }     for (int k = 1; k <= n; ++k)       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) v[i][j] = min(v[i][j], v[i][k] + v[k][j]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) u[i][j] = v[i][j];     ans = 1e9;     for (int i = 1; i <= m; ++i) {       a = e[i].second.first, b = e[i].second.second;       le = 0.0, ri = e[i].first;       for (int k = 1; k <= 40; ++k) {         m1 = (le + le + ri) / 3.0, n1 = e[i].first - m1;         m2 = (le + ri + ri) / 3.0, n2 = e[i].first - m2;         a1 = a2 = 0.0;         for (int j = 1; j <= n; ++j) {           a1 = max(a1, min(u[a][j] + m1, u[b][j] + n1));           a2 = max(a2, min(u[a][j] + m2, u[b][j] + n2));         }         if (a1 < a2)           ri = m2;         else           le = m1;       }       ans = min(ans, (int)round(a1 * 2.0));       nx = m1;       le = 0.0, ri = nx;       for (int k = 1; k <= 40; ++k) {         m1 = (le + le + ri) / 3.0, n1 = e[i].first - m1;         m2 = (le + ri + ri) / 3.0, n2 = e[i].first - m2;         a1 = a2 = 0.0;         for (int j = 1; j <= n; ++j) {           a1 = max(a1, min(u[a][j] + m1, u[b][j] + n1));           a2 = max(a2, min(u[a][j] + m2, u[b][j] + n2));         }         if (a1 < a2)           ri = m2;         else           le = m1;       }       ans = min(ans, (int)round(a1 * 2.0));       le = nx, ri = e[i].first;       for (int k = 1; k <= 40; ++k) {         m1 = (le + le + ri) / 3.0, n1 = e[i].first - m1;         m2 = (le + ri + ri) / 3.0, n2 = e[i].first - m2;         a1 = a2 = 0.0;         for (int j = 1; j <= n; ++j) {           a1 = max(a1, min(u[a][j] + m1, u[b][j] + n1));           a2 = max(a2, min(u[a][j] + m2, u[b][j] + n2));         }         if (a1 < a2)           ri = m2;         else           le = m1;       }       ans = min(ans, (int)round(a1 * 2.0));     }     if (ans & 1)       cout << ans / 2 <<  .5 n ;     else       cout << ans / 2 <<  .0 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double eps = 1e-10;   const double pi = acos(-1.0);   const int maxn = 1e6 + 10;   const long long inf = 0x3f3f3f3f;   const int dir[8][2] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   int n, m;   int dis[1010][1010][4];   char g[1010][1010];   queue<pair<int, int> > q;   void bfs(int x) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (g[i][j] ==  0  + x) q.push(make_pair(i, j)), dis[i][j][x] = 0;     while (!q.empty()) {       pair<int, int> p = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int dx = p.first + dir[i][0];         int dy = p.second + dir[i][1];         if (dx < 1 || dx > n || dy < 1 || dy > m || g[dx][dy] ==  # ) continue;         int v = (g[dx][dy] ==  . );         if (dis[p.first][p.second][x] + v < dis[dx][dy][x]) {           dis[dx][dy][x] = dis[p.first][p.second][x] + v;           q.push(make_pair(dx, dy));         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> g[i] + 1;     memset(dis, inf, sizeof dis);     bfs(1), bfs(2), bfs(3);     long long ans = inf;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         long long tmp = 0;         for (int k = 1; k <= 3; k++) tmp += dis[i][j][k];         if (g[i][j] ==  . ) tmp -= 2;         ans = min(ans, tmp);       }     if (ans == inf)       cout << -1;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000011];   int find(long long v) {     int i, ret = -1;     for (i = 1; i <= 2 * sqrt(v) + 1; ++i) {       if (1ll * i * (i - 1) / 2 >= v) {         ret = i;         break;       }     }     if (ret == -1 || 1ll * ret * (ret - 1) / 2 != v) return -1;     return ret;   }   int main() {     long long a00, a01, a10, a11;     cin >> a00 >> a01 >> a10 >> a11;     if (a00 + a01 + a10 + a11 == 0) {       printf( 0 n );       return 0;     }     long long n = find(a00 + a01 + a10 + a11);     long long n0 = find(a00), n1 = find(a11);     if (a00 == 0 && a01 == 0 && a10 == 0) {       n0 = 0;     }     if (a11 == 0 && a01 == 0 && a10 == 0) {       n1 = 0;     }     if (n0 == -1 || n1 == -1 || n == -1 || n0 + n1 != n) {       printf( Impossible n );       return 0;     }     int i = 1;     while (n0 > 0 && n1 > 0) {       if (a01 >= n1) {         a[i++] = 0;         a01 -= n1;         n0++;       } else {         a[i++] = 1;         n1--;       }     }     if (a01 != 0) {       printf( Impossible n );       return 0;     }     while (n0 > 0) {       a[i++] = 0;       n0--;     }     while (n1 > 0) {       a[i++] = 1;       n1--;     }     for (i = 1; i <= (int)n; ++i) {       printf( %d , a[i]);     }     printf(  n );     return 0;   }
//Code By CXY07   #include<bits/stdc++.h>   using namespace std;      //#define FILE   //#define int long long   #define debug(x) cout << #x <<   =   << x << endl   #define file(FILENAME) freopen(FILENAME .in ,  r , stdin), freopen(FILENAME .out ,  w , stdout)   #define LINE() cout <<  LINE =   << __LINE__ << endl   #define LL long long   #define ull unsigned long long   #define pii pair<int,int>   #define mp make_pair   #define pb push_back   #define fst first   #define scd second   #define inv(x) qpow((x),mod - 2)   #define lowbit(x) ((x) & (-(x)))   #define abs(x) ((x) < 0 ? (-(x)) : (x))   #define randint(l, r) (rand() % ((r) - (l) + 1) + (l))   #define vec vector      const int MAXN = 1e6 + 10;   const int INF = 2e9;   const double PI = acos(-1);   const double eps = 1e-6;   //const int mod = 1e9 + 7;   //const int mod = 998244353;   //const int G = 3;   //const int base = 131;      int T, n, m;   int _L[MAXN], _R[MAXN];   int *L = _L + (int)5e5, *R = _R + (int)5e5;   char s[MAXN];      template<typename T> inline bool read(T &a) {    a = 0; char c = getchar(); int f = 1;    while(c <  0  || c >  9 ) {if(c ==  - ) f = -1; c = getchar();}    while(c >=  0  && c <=  9 ) {a = a * 10 + (c ^ 48); c = getchar();}    a *= f;    return 1;   }      template<typename A, typename ...B>   inline bool read(A &x, B &...y) {return read(x) && read(y...);}      void solve() {    scanf( %s , s + 1);    n = strlen(s + 1);    for(int i = -n; i <= n; ++i) L[i] = R[i] = 0;    int now = 0;    for(int i = 1; i <= n; ++i) {     if(s[i] ==  1 ) R[now++]++;     else L[now--]++;    }    now = 0;    for(int i = 1; i <= n; ++i) {     if(L[now] && (!R[now] || R[now - 1])) L[now--]--, putchar( 0 );     else R[now++]--, putchar( 1 );    }    putchar(  n );   }      signed main () {   #ifdef FILE    freopen( .in , r ,stdin);    freopen( .out , w ,stdout);   #endif    read(T);    while(T--) solve();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 300500;   int n, dp[N];   vector<int> g[N], l;   vector<pair<int, int> > gr, G, ga[N];   void dfs(int v, int pr = -1) {     dp[v] = 1;     for (int to : g[v]) {       if (to != pr) {         dfs(to, v);         dp[v] += dp[to];       }     }   }   int dfs1(int v) {     for (int to : g[v]) {       if (dp[to] * 2 > n) {         dp[v] -= dp[to];         dp[to] += dp[v];         return dfs1(to);       }     }     return v;   }   void dfs2(int v, int pr, int gl = 0) {     gr.push_back(make_pair(gl, v));     for (int to : g[v]) {       if (to != pr) {         dfs2(to, v, gl + 1);       }     }   }   void checkv(int st) {     gr.clear();     dfs2(st, -1, 0);     sort(gr.begin(), gr.end());     for (int i = 0; i + 1 < n; ++i) {       if (gr[i].first == gr[i + 1].first &&           (int)g[gr[i].second].size() != (int)g[gr[i + 1].second].size())         return;     }     cout << st << endl;     exit(0);   }   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; ++i) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1);     int centroid = dfs1(1);     checkv(centroid);     for (int i = 1; i <= n; ++i)       if ((int)g[i].size() == 1) l.push_back(i);     for (int x : l) {       int last = x;       int cur = g[x][0];       int dist = 1;       while ((int)g[cur].size() == 2) {         int nxt = g[cur][0];         if (nxt == last) nxt = g[cur][1];         dist++;         last = cur;         cur = nxt;       }       if (dist == n - 1) {         checkv(x);         cout << -1;         return 0;       }       ga[cur].push_back(make_pair(x, dist));       G.push_back(make_pair(dist, x));     }     for (int i = 1; i <= n; ++i) {       if ((int)ga[i].size() == 1) {         checkv(ga[i][0].first);         cout << -1;         return 0;       }     }     for (int i = 0; i + 1 < (int)G.size(); ++i)       if (G[i].first != G[i + 1].first) {         checkv(G[i].second);         checkv(G[i + 1].second);         cout << -1;         return 0;       }     cout << -1 << endl;     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ns, a[1111];   void ok(long long x) {     long long l = 0, r = min(2000000000ll, (1ll << 62) / (x + 1) + 1);     while (l < r) {       long long m = (l + r) / 2;       if (m * (m - 1) / 2 + m * x >= n)         r = m;       else         l = m + 1;       if (m * (m - 1) / 2 + m * x == n && m % 2) a[++ns] = m + m * x;     }   }   int main() {     while (cin >> n) {       ns = 0;       for (int i = 0; i < 62; i++) ok((1ll << i) - 1);       if (!ns)         cout << -1 << endl;       else {         for (int i = 1; i <= ns; i++) cout << a[i] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char num[200001];   int numLen, m, temp, answer = 0;   int stepArr = 1;   int main() {     cin >> num >> m;     numLen = strlen(num);     answer += (num[numLen - 1] - 48) % m;     for (int i = numLen - 2; i >= 0; i--) {       stepArr = (stepArr * 10) % m;       answer += ((num[i] - 48) * stepArr) % m;       answer %= m;     }     temp = answer;     for (int i = 0; i < numLen - 1; i++) {       temp = ((((temp - (num[i] - 48) * stepArr) % m + m) * 10) % m +               (num[i] - 48) % m) %              m;       if (num[i + 1] ^ 48) {         answer = min(answer, temp);       }     }     cout << answer;     return 0;   }
#include <bits/stdc++.h>   template <typename T>   T mymax(T x, T y) {     return (x > y ? x : y);   }   using namespace std;   const int N = 100005;   const long long inf = 1e18;   vector<int> graph[N], cost[N];   int n, m;   long long dis[N];   struct node {     int nd, c;     node(int _nd, int _c) {       nd = _nd;       c = _c;     }     bool operator<(const node& p) const { return c > p.c; }   };   void dijkstra() {     priority_queue<node> pq;     pq.push(node(1, 0));     for (int i = 0; i < N; i++) dis[i] = inf;     dis[1] = 0;     while (!pq.empty()) {       node top = pq.top();       pq.pop();       int u = top.nd;       for (int i = 0; i < (int)graph[u].size(); i++) {         int v = graph[u][i];         if (dis[v] > dis[u] + cost[u][i]) {           dis[v] = dis[u] + cost[u][i];           pq.push(node(v, dis[v]));         }       }     }     queue<int> q;     q.push(n);     vector<int> ans;     ans.push_back(n);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < graph[u].size(); i++) {         int v = graph[u][i];         if (dis[u] - cost[u][i] == dis[v]) {           ans.push_back(v);           q.push(v);           break;         }       }     }     if (ans.size() == 1) {       printf( -1 n );       return;     }     reverse((ans).begin(), (ans).end());     for (int x : ans) {       printf( %d  , x);     }     printf(  n );   }   void solve() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       graph[u].push_back(v);       graph[v].push_back(u);       if (cost[u].size() == 0) {         cost[u].push_back(w);         cost[v].push_back(w);       } else {         int mn = 1e9;         for (int i = 0; i < graph[u].size() - 1; i++) {           int adj = graph[u][i];           if (adj == v) {             mn = min(mn, cost[u][i]);           }         }         mn = min(mn, w);         cost[u].push_back(mn);         cost[v].push_back(mn);       }     }     dijkstra();     return;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   const int N = 150;   int n;   double p[N];   void init() {     std::cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %lf , &p[i]);       p[i] /= 100.0;     }   }   void work() {     static double f[N];     for (int i = 1; i <= n; i++) {       f[i] = 1.0;     }     double answer = 1.0;     double pr = 1.0;     for (int t = 2; t <= 500000; t++) {       int best = -1;       for (int i = 1; i <= n; i++) {         if (best == -1 || (1.0 - f[i] * (1.0 - p[i])) * (1.0 - f[best]) >                               (1.0 - f[best] * (1.0 - p[best])) * (1.0 - f[i])) {           best = i;         }       }       f[best] *= 1.0 - p[best];       pr = 1.0;       for (int i = 1; i <= n; i++) {         pr *= 1.0 - f[i];       }       answer += 1.0 - pr;     }     printf( %.10f n , answer);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int s[51];   int main() {     int n, g, check = 0, t = 0, q = 0;     cin >> n;     g = (n * (n - 1)) / 2;     pair<int, int> can[g - 1];     for (int i = 0; i < g - 1; i++) {       cin >> can[i].first >> can[i].second;       s[can[i].first]++;       s[can[i].second]++;     }     for (int i = 1; i <= n; i++) {       if (s[i] < n - 1) {         if (t == 0)           t = i;         else           q = i;       }     }     for (int i = 0; i < g; i++) {       if (can[i].first == t) {         check = 1;         for (int r = 0; r < g; r++) {           if (can[r].first == can[i].second && can[r].second == q) {             cout << t <<     << q;             return 0;           }         }       }     }     if (check == 0) {       cout << q <<     << t;       return 0;     }     for (int i = 0; i < g; i++) {       if (can[i].first == q) {         for (int r = 0; r < g; r++) {           if (can[r].first == can[i].second && can[r].second == t) {             cout << q <<     << t;             return 0;           }         }       }     }     cout << t <<     << q;   }
#include <bits/stdc++.h>   using namespace std;   #pragma optimize( -O3 )   string to_string(string s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(const bool& b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(const A& v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) res +=  ,  ;       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T>   inline void _read(T& x) {     cin >> x;   }   template <typename A, typename B>   inline void _read(pair<A, B>& x) {     _read(x.first);     _read(x.second);   }   template <typename T>   inline void _read(vector<T>& x) {     for (auto& v : x) _read(v);   }   void R() {}   template <typename T, typename... U>   void R(T& head, U&... tail) {     _read(head);     R(tail...);   }   template <typename T>   inline void _write(const T& x) {     cout << x <<    ;   }   template <typename A, typename B>   inline void _write(const pair<A, B>& x) {     _write(x.first);     _write(x.second);   }   template <typename T>   inline void _write(const vector<T>& in) {     for (const auto& x : in) _write(x);   }   void W() { cout <<   n ; }   template <typename T, typename... U>   void W(const T& head, const U&... tail) {     _write(head);     W(tail...);   }   void go();   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     go();     return 0;   }   int solve(int a, int b) {     if (a == 1 && b == 2) return 3;     if (a == 1 && b == 3) return 4;     if (a == 2 && b == 1) return 3;     if (a == 2 && b == 3) {       W( Infinite );       exit(0);     }     if (a == 3 && b == 1) return 4;     if (a == 3 && b == 2) {       W( Infinite );       exit(0);     }   }   void go() {     int n;     R(n);     vector<int> a(n);     R(a);     int ans = 0;     for (int i = 1; i < n; i++) {       ans += solve(a[i - 1], a[i]);     }     for (int i = 2; i < n; i++)       if (a[i - 2] == 3 && a[i - 1] == 1 && a[i] == 2) ans--;     W( Finite );     W(ans);   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   int S, n, tot;   int fa[2100], a[2100][2100], p[2100 * 2100 / 2];   vector<int> E[2100];   void EXT() {     printf( NO n );     exit(0);   }   int get(int x) {     if (fa[x] == x) return x;     return fa[x] = get(fa[x]);   }   void dfs(int x, int ff, int dep) {     if (a[S][x] != dep) EXT();     for (int i : E[x])       if (i != ff) dfs(i, x, dep + a[x][i]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; ++i) {       if (a[i][i] != 0) EXT();       for (int j = i + 1; j <= n; ++j) {         if (a[i][j] != a[j][i] || a[i][j] == 0) EXT();         p[++tot] = (i << 20) + j;       }     }     sort(p + 1, p + tot + 1, [](int x, int y) {       return a[x >> 20][x & 0xffff] < a[y >> 20][y & 0xffff];     });     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= tot; ++i) {       int x = p[i] >> 20, y = p[i] & 0xffff;       if (get(x) == get(y)) continue;       E[x].push_back(y);       E[y].push_back(x);       fa[get(x)] = get(y);     }     for (int i = 1; i <= n; ++i) {       S = i;       dfs(i, 0, 0);     }     printf( YES n );   }
#include <bits/stdc++.h>   using namespace std;   int top;   int t[10000];   long long sum[100000];   int ans[5002][5002];   const int MOD = 1e9 + 7;   int main() {     int n, a, b, k;     scanf( %d%d%d%d , &n, &a, &b, &k);     if (a < b)       top = b - 1;     else       top = abs(n - b);     for (int i = 1; i <= top; i++) {       int far = i * 2 - 1;       if (far <= top)         ans[i][1] = 2 * (i - 1);       else         ans[i][1] = i - 1 + (top - i);     }     for (int i = 1; i <= top; i++) sum[i] = (sum[i - 1] + t[i]) % MOD;     for (int j = 2; j <= k; j++) {       for (int q = 1; q <= top; q++) sum[q] = (sum[q - 1] + ans[q][j - 1]) % MOD;       for (int i = 1; i <= top; i++) {         int far = i * 2 - 1;         if (far <= top)           ans[i][j] = (sum[i - 1] + sum[far]) % MOD - sum[i];         else           ans[i][j] = (sum[i - 1] + sum[top]) % MOD - sum[i];         ans[i][j] = ans[i][j] % MOD;       }     }     printf( %d n , (ans[abs(a - b)][k] + MOD) % MOD);   }
#include <bits/stdc++.h>   using namespace std;   int level(int n, int sum[]) {     int i;     for (i = 1; i < 11; i++) {       if (n > sum[i - 1] && n <= sum[i]) {         return i;       }     }   }   int number(int n, int l, int sum[]) {     int st = sum[l - 1] + 1;     return n - st + 1;   }   int main() {     int sum[11] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55};     int n, t, i, j, k;     cin >> n >> t;     int ans = 0;     vector<int> adj[60];     for (i = 1; i < 56; i++) {       int l = level(i, sum);       int num = number(i, l, sum);       adj[i].push_back(sum[l] + num);       adj[i].push_back(sum[l] + num + 1);     }     double w[100] = {0};     double one = 1.00;     for (j = 1; j <= t; j++) {       w[1] += one;       for (i = 1; i < 56; i++) {         if (w[i] >= one) {           double rem = (w[i] - one) / 2.00;           w[i] = one;           for (k = 0; k < adj[i].size(); k++) {             w[adj[i][k]] += rem;           }         }       }     }     for (i = 1; i <= sum[n]; i++) {       if (w[i] == one) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double p[110], S;   int main() {     scanf( %d , &n);     for (int i = 0; i <= n; i++) scanf( %lf , p + i);     for (int i = 0; i < n; i++)       for (int j = i + 1; j <= n; j++)         if (i * 2 <= n && n <= j * 2)           S = max(               S, (n * 0.5 - j) / (i - j) * p[i] + (n * 0.5 - i) / (j - i) * p[j]);     printf( %.9lf n , S);     return 0;   }