malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int MAXN = 1500907;   vector<vector<long long>> adj;   bool visited[MAXN];   long long n_nodes;   long long n_edges;   void dfs(int node) {     visited[node] = 1;     n_nodes++;     for (auto i : adj[node]) {       n_edges++;       if (!visited[i]) {         dfs(i);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, a, b;     cin >> n >> m;     adj.resize(n + 5);     while (m--) {       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     for (long long i = 1; i <= n; i++) {       if (!visited[i]) {         n_nodes = 0;         n_edges = 0;         dfs(i);         if (n_edges != n_nodes * (n_nodes - 1)) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<long long> num;   void f(int x, int a, int b, long long now) {     if (x == 0) {       num.insert(now);       return;     }     if (a) f(x - 1, a - 1, b, now * 10 + 4);     if (b) f(x - 1, a, b - 1, now * 10 + 7);   }   void init() {     int i;     for (i = 1; i <= 5; i++) f(i * 2, i, i, 0LL);   }   int main() {     long long n;     init();     scanf( %I64d , &n);     printf( %I64d , *num.upper_bound(n - 1));   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     scanf( %d , &n);     long a[n];     long long s = 0, ss = 0;     for (int i = 0; i < n; i++) {       scanf( %ld , &a[i]);       s += a[i];     }     if (s % 3 != 0) {       printf( 0 n );       return 0;     }     s = s / 3;     vector<int> sum1;     vector<int> sum2;     for (int i = 0; i < n - 1; i++) {       ss += a[i];       if (ss == s) sum1.push_back(i);       if (ss == 2 * s) sum2.push_back(i);     }     long long ans = 0;     for (int i = 0; i < sum1.size(); i++) {       ans += sum2.end() - lower_bound(sum2.begin(), sum2.end(), sum1[i] + 1);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, a[110], b[110], a1, b1;     cin >> n >> m;     for (i = 0; i <= n; i++) cin >> a[i];     for (i = 0; i <= m; i++) cin >> b[i];     a1 = a[0], b1 = b[0];     if (n > m) {       if (a1 * b1 > 0)         cout <<  Infinity  << endl;       else         cout <<  -Infinity  << endl;     } else if (n < m) {       printf( 0/1 n );     } else if (n == m) {       for (i = 1; i <= min(abs(a1), abs(b1)); i++) {         if (a1 % i == 0 && b1 % i == 0) j = i;       }       a1 /= j, b1 /= j;       if (a1 * b1 > 0)         printf( %d/%d n , abs(a1), abs(b1));       else         printf( -%d/%d n , abs(a1), abs(b1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, s, i, j, k;   bool A[301][301];   char str[301];   int main() {     scanf( %d%d%d , &n, &m, &s);     for (i = 0; i < n; i++) {       scanf( %s , str);       for (j = 0; j < m; j++) A[i][j] = str[j] ==  * ;     }     for (i = 1; 2 * i + 1 <= min(n, m); i++) {       for (j = i; j + i < n; j++) {         for (k = i; k + i < m; k++)           if (A[j][k] && A[j][k + i] && A[j][k - i] && A[j + i][k] &&               A[j - i][k]) {             s--;             if (!s) break;           }         if (!s) break;       }       if (!s) break;     }     if (s)       printf( -1 n );     else {       j++;       k++;       printf( %d %d n%d %d n%d %d n%d %d n%d %d n , j, k, j - i, k, j + i, k, j,              k - i, j, k + i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nm = 100002;   int n, d;   long long x;   int a[nm], b[nm], vt[nm];   int c[nm];   int nc;   int getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void init() {     int i;     for (i = 0; i < n; i = i + 1) {       a[i] = i + 1;     }     for (i = 0; i < n; i = i + 1) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (i = 0; i < n; i = i + 1) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (i = 0; i < n; i = i + 1) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   int main() {     scanf( %d%d%I64d , &n, &d, &x);     init();     int i, j, k;     for (i = 0; i < n; ++i) {       vt[a[i]] = i;       if (b[i]) c[++nc] = i;     }     for (i = 0; i < n; ++i) {       for (j = n; j > n - 100 && j > 0; --j)         if (vt[j] <= i && b[i - vt[j]]) break;       if (j > n - 100 && j > 0) {         printf( %d n , j);         continue;       }       k = 0;       for (j = 1; j <= nc && c[j] <= i; ++j) k = max(k, a[i - c[j]]);       printf( %d n , k);     }   }
#include<cstdio>   int t,n;   int vx[13][2003];   int vy[13][2003];   int fx[13][2003];   int lx[13][2003];   int fy[13][2003];   int ly[13][2003];   int a[2003][2003];   int main()   {    scanf(  %d ,&t);    while(t--)    {     scanf(  %d ,&n);     for(int i=1;i<=n;++i)     {      for(int j=1;j<=n;++j)      {       scanf(  %1d ,&a[i][j]);      }     }     for(int d=0;d<10;++d)     {      int ans=0;      for(int j=1;j<=n;++j)      {       fx[d][j]=lx[d][j]=0;       for(int i=1;i<=n;++i)       {        if(a[i][j]!=d)continue;        if(!fx[d][j])        {         fx[d][j]=i;         break;        }       }       for(int i=n;i;--i)       {        if(a[i][j]!=d)continue;        if(!lx[d][j])        {         lx[d][j]=i;         break;        }       }       if(fx[d][j])vx[d][j]=((n-fx[d][j]>lx[d][j]-1)?(n-fx[d][j]):(lx[d][j]-1));       else vx[d][j]=0;      }      for(int i=1;i<=n;++i)      {       fy[d][i]=ly[d][i]=0;       for(int j=1;j<=n;++j)       {        if(a[i][j]!=d)continue;        if(!fy[d][i])        {         fy[d][i]=j;         break;        }       }       for(int j=n;j;--j)       {        if(a[i][j]!=d)continue;        if(!ly[d][i])        {         ly[d][i]=j;         break;        }       }       if(fy[d][i])vy[d][i]=((n-fy[d][i]>ly[d][i]-1)?(n-fy[d][i]):(ly[d][i]-1));       else vy[d][i]=0;      }      for(int i=1;i<=n;++i)      {       if(!vx[d][i])continue;       for(int j=1;j<i;++j)       {        if(!vx[d][j])continue;        if(vx[d][j]*(i-j)>ans)ans=vx[d][j]*(i-j);        if(vx[d][i]*(i-j)>ans)ans=vx[d][i]*(i-j);       }      }      for(int i=1;i<=n;++i)      {       if(!vy[d][i])continue;       for(int j=1;j<i;++j)       {        if(!vy[d][j])continue;        if(vy[d][j]*(i-j)>ans)ans=vy[d][j]*(i-j);        if(vy[d][i]*(i-j)>ans)ans=vy[d][i]*(i-j);       }      }      printf( %d  ,ans);     }     puts(  );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long PR = 1000000009;   int n, m, premin[100009], sufmax[100009];   char A[100009], B[100009];   int main() {     ios::sync_with_stdio(false);     cin >> A >> B;     n = strlen(A);     m = strlen(B);     for (int i = 0; i < m; i++) premin[i] = n, sufmax[i] = -1;     int st = 0;     for (int i = 0; i < m && st < n; i++) {       while (A[st] != B[i]) {         st++;         if (st >= n) break;       }       premin[i] = st;       st++;     }     st = n - 1;     for (int i = m - 1; i >= 0 && st >= 0; i--) {       while (A[st] != B[i]) {         st--;         if (st < 0) break;       }       sufmax[i] = st;       st--;     }     int ans = m, i1 = -1, j1 = -1;     for (int i = 0; i < m; i++) {       if (premin[i] != n) {         int mid, st = i + 1, end = m - 1;         while (st < end) {           mid = (st + end) / 2;           if (sufmax[mid] >= premin[i] + 1)             end = mid;           else             st = mid + 1;         }         if (sufmax[st] < premin[i] + 1) st = m;         int now = st - i - 1;         if (now < ans) {           i1 = i + 1;           j1 = st - 1;           ans = now;         }       }     }     for (int i = m - 1; i >= 0; i--) {       if (sufmax[i] == -1) break;       int now = i - 1;       if (now < ans) {         j1 = i - 1;         i1 = 0;         ans = now;       }     }     if (i1 == -1 || j1 - i1 + 1 == m) {       cout <<  -  << endl;       return 0;     }     for (int i = 0; i < i1; i++) cout << B[i];     for (int j = j1 + 1; j < m; j++) cout << B[j];     cout << endl;     return 0;   };
#include <bits/stdc++.h>   using namespace std;   int n, k;   string a;   int change(char c) {     int j = 0, i = 0, ans = 0, cont = 0;     for (i = 0; i < n; i++) {       if (a[i] == c) cont++;       if (cont > k) {         while (cont > k)           if (a[j++] == c) cont--;       }       ans = max(ans, i - j + 1);     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     while (cin >> n >> k) {       a =   ;       int suma = 0, sumb = 0;       for (int i = 0; i < n; ++i) {         char c;         cin >> c;         if (c ==  a )           suma++;         else           sumb++;         a += c;       }       int ans;       if (suma > sumb)         ans = change( b );       else if (sumb > suma)         ans = change( a );       else         ans = max(change( a ), change( b ));       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[100100];   int fa[100100][18], typ[100100], n;   int sum[100100][2], dep[100100];   void dfs(int u) {     for (int i = 1; i < 18; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];     for (auto v : g[u]) {       int A = v.first, tp = v.second;       sum[A][0] = sum[u][0];       sum[A][1] = sum[u][1];       ++sum[A][tp];       dep[A] = dep[u] + 1;       dfs(A);     }   }   int LCA(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     int hu = dep[u], hv = dep[v];     int tu = u, tv = v;     for (int det = hv - hu, i = 0; det; det >>= 1, i++)       if (det & 1) tv = fa[tv][i];     if (tu == tv) return tu;     for (int i = 17; i >= 0; --i) {       if (fa[tu][i] == fa[tv][i]) continue;       tu = fa[tu][i];       tv = fa[tv][i];     }     return fa[tu][0];   }   int tmp[2];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &fa[i][0], &typ[i]);       if (fa[i][0] == -1) fa[i][0] = typ[i] = 0;     }     for (int i = 1; i <= n; ++i) g[fa[i][0]].push_back(pair<int, int>(i, typ[i]));     dfs(0);     int q;     scanf( %d , &q);     while (q--) {       int tp, u, v;       scanf( %d%d%d , &tp, &u, &v);       int lca = LCA(u, v);       if (!lca || lca == v) {         puts( NO );         continue;       }       if (tp == 1) {         if (lca != u) {           puts( NO );           continue;         }         tmp[0] = sum[v][0] - sum[u][0];         tmp[1] = sum[v][1] - sum[u][1];         if (tmp[1]) {           puts( NO );           continue;         }         puts( YES );       } else {         tmp[0] = sum[u][0] - sum[lca][0];         tmp[1] = sum[u][1] - sum[lca][1];         if (tmp[1]) {           puts( NO );           continue;         }         tmp[0] = sum[v][0] - sum[lca][0];         tmp[1] = sum[v][1] - sum[lca][1];         if (tmp[0]) {           puts( NO );           continue;         }         puts( YES );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[32];   int n, k;   double dp[32][32][205];   int main() {     memset(dp, 0, sizeof(dp));     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       for (int j = i; j < n; ++j) {         if (a[i] > a[j]) {           dp[i][j][0] = 1;         }       }     }     double prob = (double)2 / (n * (n + 1));     for (int op = 1; op <= k; ++op) {       for (int start = 0; start < n; ++start) {         for (int end = start; end < n; ++end) {           for (int x = 0; x < n; ++x) {             for (int y = x; y < n; ++y) {               int nx = x;               if (start <= x && x <= end) nx = end - x + start;               int ny = y;               if (start <= y && y <= end) ny = start + end - y;               if (ny >= nx)                 dp[x][y][op] += dp[nx][ny][op - 1] * prob;               else                 dp[x][y][op] += (1 - dp[ny][nx][op - 1]) * prob;             }           }         }       }     }     double ans = 0;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j) ans += dp[i][j][k];     cout << fixed << setprecision(9) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int cicle[300] = {0,  1,  2,  3,  4,  5,  6, 7, 8, 9, 10, 11, 12, 13, 14,                     15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5,  4,  3,  2,  1,                     0,  1,  2,  3,  4,  5,  6, 7, 8, 9, 10, 11, 12, 13, 14,                     15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5,  4,  3,  2,  1,                     0,  1,  2,  3,  4,  5,  6, 7, 8, 9, 10, 11, 12, 13, 14,                     15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5,  4,  3,  2,  1,                     0,  1,  2,  3,  4,  5,  6, 7, 8, 9, 10, 11, 12, 13, 14,                     15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5,  4,  3,  2,  1};   int main() {     int n;     scanf( %d , &n);     if (n == 1) {       int b;       scanf( %d , &b);       if (b == 15)         printf( DOWN n );       else if (b == 0) {         printf( UP n );       } else         printf( -1 n );       return 0;     }     int a[n];     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     for (int i = 0; i < 100; ++i) {       if (a[n - 1] == cicle[i + 1] && a[n - 2] == cicle[i]) {         if (cicle[i + 2] > cicle[i + 1])           printf( UP n );         else           printf( DOWN n );         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int N = 3e5 + 1;   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   long long arr[N], brr[N];   long long n, m, k, q, a, b;   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = res * a;       a = a * a;       n /= 2;     }     return res;   }   void solve() {     cin >> n;     vector<long long> arr(n);     vector<long long> v;     for (int i = 0; i < n; i++) cin >> arr[i];     long long x = arr[0];     arr[0] = 0;     for (int k = 0; k + 1 < n; k++) {       x = min(max(0LL, arr[k + 1] - arr[k]), x);       arr[k + 1] -= x;     }     bool ok = true;     for (int k = 0; k + 1 < n; k++) {       if (arr[k + 1] - arr[k] < 0) ok = false;     }     n = v.size();     for (int i = 0; i < n; i++)       if (v[i] < 0) ok = false;     if (ok)       cout <<  yes ;     else       cout <<  no ;     cout <<   n ;     cerr <<   n ;   }   int main() {     int t;     t = 1;     cin >> t;     int a = 0;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, q;   struct interv {     long long l, r, ubonus, lbonus;     interv(long long L, long long R, long long UBONUS, long long LBONUS) {       l = L;       r = R;       ubonus = UBONUS;       lbonus = LBONUS;     }     bool operator<(const interv& x) const { return r < x.r; }   };   set<interv> s;   set<interv>::iterator it;   long long x, y, to;   char dir[3];   long long ans;   int main() {     scanf( %lld %lld , &n, &q);     s.insert(interv(1, n, 0, 0));     for (int i = 1; i <= q; i++) {       scanf( %lld %lld , &x, &y);       scanf( %s , dir);       it = s.lower_bound(interv(0, x, 0, 0));       if (it == s.end()) {         printf( 0 n );         continue;       }       long long b = (*it).r;       long long a = (*it).l;       long long ubonus = (*it).ubonus;       long long lbonus = (*it).lbonus;       if (x < a) {         printf( 0 n );         continue;       }       if (dir[0] ==  U ) {         ans = (b - a + 1) - (x - a) + ubonus;         printf( %lld n , ans);         s.erase(it);         if (x - 1 >= 1 && a <= x - 1) s.insert(interv(a, x - 1, ans, lbonus));         if (x + 1 <= n && x + 1 <= b) s.insert(interv(x + 1, b, ubonus, 0));       } else {         ans = (b - a + 1) - (b - x) + lbonus;         printf( %lld n , ans);         s.erase(it);         if (x - 1 >= 1 && a <= x - 1) s.insert(interv(a, x - 1, 0, lbonus));         if (x + 1 <= n && x + 1 <= b) s.insert(interv(x + 1, b, ubonus, ans));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void solve() {     long long n;     cin >> n;     vector<bool> isp(n + 1, 1);     vector<long long> maxx(n + 1, -1);     isp[0] = isp[1] = 0;     for (long long i = 2; i <= n; i++) {       if (isp[i]) {         if (i * 2 <= n) {           for (long long j = i * 2; j <= n; j += i) {             isp[j] = 0;             maxx[j] = max(maxx[j], i);           }         }       }     }     long long best = 1, now = n;     for (long long j = 2; j * j <= n; j++) {       while (now % j == 0) {         now /= j;         best = max(best, j);       }     }     best = max(best, now);     long long ans = n - best + 1;     for (long long i = n - best + 1; i < n; i++) {       ans = min(ans, i - maxx[i] + 1);     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, y, a, b, c;   long long A[2005];   bool B[2005];   int main() {     cin >> n >> k;     priority_queue<pair<int, int> > pq;     for (int i = int(0); i < int(n); i++) {       cin >> A[i];       pq.push({A[i], i});     }     int ans = 0;     for (int i = int(0); i < int(k); i++) {       B[pq.top().second] = true;       ans += pq.top().first;       pq.pop();     }     cout << ans <<   n ;     m = -1;     int t = 0;     for (int i = int(0); i < int(n); i++) {       if (B[i] && t + 1 < k) {         cout << i - m <<    ;         m = i;         t++;       }     }     cout << n - 1 - m <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n;   int seq[N];   vector<int> zli[N];   int res[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , seq + i);       seq[i] = n - seq[i];       zli[seq[i]].push_back(i);     }     int rodzaj = 0;     for (int ile = 1; ile <= n; ++ile) {       if ((int)(zli[ile]).size() % ile) {         puts( Impossible );         exit(0);       }       for (int i = 0; i < (int)(zli[ile]).size(); i += ile) {         rodzaj++;         for (int j = i; j < i + ile; ++j) {           res[zli[ile][j]] = rodzaj;         }       }     }     puts( Possible );     for (int i = 1; i <= n; ++i) {       printf( %d  , res[i]);     }     puts(  );   }
#include <bits/stdc++.h>   int find_min(int pos, int target) {     int right = -1;     for (int i = 0; right == -1; i++)       if ((pos + i) % 26 == target) right = i;     int left = -1;     for (int i = 0; left == -1; i++)       if ((pos - i + 26 * 2) % 26 == target) left = i;     return std::min(right, left);   }   int main() {     int n;     std::cin >> n;     std::string s;     std::cin >> s;     std::string genome =  ACTG ;     int min_moves = INT_MAX;     for (int i = 0; i < n - 3; i++) {       int min_temp = 0;       for (int j = 0; j < 4; j++)         min_temp += find_min(s[i + j] -  A , genome[j] -  A );       min_moves = std::min(min_moves, min_temp);     }     std::cout << min_moves <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const long long MOD = 998244353;   struct node {     int v;     node *d, *r;   };   node a[1050][1050];   long long n, m, q;   void solve() {     cin >> n >> m >> q;     for (int i = (int)(1); i <= (int)(n); i += 1) {       for (int j = (int)(1); j <= (int)(m); j += 1) {         cin >> a[i][j].v;       }     }     for (int i = (int)(0); i <= (int)(n); i += 1) {       for (int j = (int)(0); j <= (int)(m); j += 1) {         a[i][j].r = &a[i][j + 1];         a[i][j].d = &a[i + 1][j];       }     }     while (q--) {       long long e, b, c, d, h, w;       cin >> e >> b >> c >> d >> h >> w;       node *x, *y, *j, *k;       x = y = &a[0][0];       for (int i = (int)(1); i <= (int)(e - 1); i += 1) x = x->d;       for (int i = (int)(1); i <= (int)(b - 1); i += 1) x = x->r;       for (int i = (int)(1); i <= (int)(c - 1); i += 1) y = y->d;       for (int i = (int)(1); i <= (int)(d - 1); i += 1) y = y->r;       j = x, k = y;       for (int i = (int)(1); i <= (int)(h); i += 1) {         x = x->d, y = y->d;         swap(x->r, y->r);       }       for (int i = (int)(1); i <= (int)(w); i += 1) {         x = x->r, y = y->r;         swap(x->d, y->d);       }       for (int i = (int)(1); i <= (int)(w); i += 1) {         j = j->r, k = k->r;         swap(j->d, k->d);       }       for (int i = (int)(1); i <= (int)(h); i += 1) {         j = j->d, k = k->d;         swap(j->r, k->r);       }     }     node *x = &a[0][0];     for (int i = (int)(1); i <= (int)(n); i += 1) {       x = x->d;       node *y = x;       for (int j = (int)(1); j <= (int)(m); j += 1) {         y = y->r;         cout << y->v <<    ;       }       cout << endl;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 50, maxm = 5e3 + 100;   int n, lim, f[maxn + 3], s[maxn + 3];   double p[maxn + 3], q[maxn + 3], dp[maxn + 3][maxm + 3];   bool check(double x) {     for (int i = n; i; i--) {       for (int j = lim + 1; j <= lim + 100; j++) {         dp[i + 1][j] = x;       }       for (int j = 0; j <= lim; j++) {         dp[i][j] = min(x, (dp[i + 1][j + f[i]] + f[i]) * p[i] +                               (dp[i + 1][j + s[i]] + s[i]) * q[i]);       }     }     return dp[1][0] == x;   }   int main() {     scanf( %d %d , &n, &lim);     for (int i = 1, x; i <= n; i++) {       scanf( %d %d %d , &f[i], &s[i], &x);       p[i] = x / 100., q[i] = (100 - x) / 100.;     }     double l = 0, r = 1e9, mid;     for (int k = 0; k < 70; k++) {       mid = (l + r) / 2;       if (check(mid)) {         l = mid;       } else {         r = mid;       }     }     printf( %.12lf n , (l + r) / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     bool flag = false;     int a[105];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       if (a[i] == 2) {         if (a[i - 1] == 1) {           if (i >= 2 && a[i - 2] == 3)             ans += 2;           else             ans += 3;         } else {           flag = true;           break;         }       } else if (a[i] == 1) {         if (a[i - 1] == 2)           ans += 3;         else if (a[i - 1] == 3)           ans += 4;         else {           flag = true;           break;         }       } else {         if (a[i - 1] == 1)           ans += 4;         else {           flag = true;           break;         }       }     }     if (flag)       puts( Infinite );     else {       puts( Finite );       cout << ans << endl;     }     return 0;   }