malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   double g[110][110], x[110];   int n, m, ues[110];   pair<pair<int, int>, int> p[5010];   bool vis[110];   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   double Abs(double x) {     if (x < 0) return -x;     return x;   }   int main() {     read(n);     read(m);     g[1][1] = 1;     g[n][n] = 1;     g[n][n + 1] = 1;     for (int i = 1; i <= m; i++) {       read(p[i].first.first);       read(p[i].first.second);       read(p[i].second);       g[p[i].first.first][p[i].first.first]++;       g[p[i].first.first][p[i].first.second]--;       g[p[i].first.second][p[i].first.second]++;       g[p[i].first.second][p[i].first.first]--;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (Abs(g[i][j]) && !vis[j]) {           vis[j] = 1;           ues[i] = j;           break;         }       for (int j = 1; j <= n; j++)         if (ues[i] != j && Abs(g[j][i])) {           double tmp = -g[j][i] / g[ues[i]][i];           for (int k = 1; k <= n + 1; k++) g[j][k] += g[ues[i]][k] * tmp;         }     }     for (int i = 1; i <= n; i++) x[i] = g[ues[i]][n + 1] / g[ues[i]][i];     double Min = 1e20;     for (int i = 1; i <= m; i++) {       if (Abs(x[p[i].first.first] - x[p[i].first.second]) > 1e-6)         Min = min(Min,                   p[i].second / Abs(x[p[i].first.first] - x[p[i].first.second]));     }     double ans = 0;     for (int i = 1; i <= m; i++)       if (p[i].first.first == 1)         ans += Min * (x[p[i].first.second] - x[p[i].first.first]);       else if (p[i].first.second == 1)         ans -= Min * (x[p[i].first.second] - x[p[i].first.first]);     printf( %.5lf n , ans);     if (Abs(ans) < 1e-6) memset(x, 0, sizeof(x));     for (int i = 1; i <= m; i++)       printf( %.5lf n , Min * (x[p[i].first.second] - x[p[i].first.first]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int k, a;     bool operator<(const node &X) const { return a > X.a; }   };   int n, fa[5010], limi[5010], ans[5010];   int order[5010], co;   vector<int> edge[5010];   vector<int> val[5010];   priority_queue<node> train[5010];   void dfs(int u, int father, int weight) {     order[++co] = u;     fa[u] = father;     limi[u] = weight;     for (int i = 0; i < edge[u].size(); i++) {       int v = edge[u][i];       int w = val[u][i];       if (v == father) continue;       dfs(v, u, w);     }   }   int main() {     cin >> n;     node tt;     for (int i = 1; i <= n; i++) {       cin >> tt.a;       tt.k = i;       train[i].push(tt);     }     int x, y, z;     for (int i = 1; i <= n - 1; i++) {       cin >> x >> y >> z;       edge[x].push_back(y);       val[x].push_back(z);       edge[y].push_back(x);       val[y].push_back(z);     }     co = 0;     dfs(1, 0, 0);     int cnt = 0;     for (int i = 0; i <= n - 1; i++) {       while (!train[1].empty()) {         tt = train[1].top();         train[1].pop();         ans[tt.k] = i;         cnt += 1;       }       if (cnt == n) break;       for (int i = 2; i <= n; i++) {         int u = order[i];         int v = fa[u];         int w = limi[u];         for (int i = 1; i <= w; i++) {           if (train[u].empty()) break;           tt = train[u].top();           train[u].pop();           train[v].push(tt);         }       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int f = 1;     int res = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -f;     } while (ch <  0  || ch >  9 );     do {       res = res * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     return f == 1 ? res : -res;   }   const int MAXN = 100010;   const int MAXP = MAXN * 51;   const long long INF = 2000000000000LL;   int n, m, D;   int mod = 1000000007;   int X[MAXN], Y[MAXN];   char open[MAXN][52];   int stck[MAXP], in[MAXP], dfsn[MAXP], low[MAXP], idx, top;   int li[MAXN], bak;   bool hv[MAXN];   int head[MAXP], nxt[MAXP], to[MAXP], tot;   int nid[MAXP], dag[MAXP], sz[MAXP];   std::queue<int> q;   int dp[MAXP];   void addEdge(int x, int y) {     tot++;     nxt[tot] = head[x];     head[x] = tot;     to[tot] = y;   }   int getIndex(int x, int d) { return x + (d % D) * n; }   void append(int x) {     --x;     int c = x % n + 1;     int d = x / n;     if (c <= 0 || d >= D) cout <<  x:   << x << endl;     if (!hv[c] && (c > 0 && d < D && open[c][d] ==  1 )) {       li[++bak] = c;       hv[c] = true;     }   }   void clr() {     for (int i = 1; i <= bak; i++) hv[li[i]] = false;     bak = 0;   }   void tarjan(int u) {     dfsn[u] = low[u] = ++idx;     in[stck[++top] = u] = true;     for (int i = head[u]; i; i = nxt[i])       if (!dfsn[to[i]]) {         tarjan(to[i]);         low[u] = std::min(low[u], low[to[i]]);       } else if (in[to[i]])         low[u] = std::min(low[u], dfsn[to[i]]);     if (low[u] == dfsn[u]) {       int v;       do in[v = stck[top--]] = false, append(v), nid[v] = u;       while (u != v);       sz[u] = bak;       clr();     }   }   int main() {     scanf( %d%d%d , &n, &m, &D);     for (int i = 0; i < m; i++) {       int u = read();       int v = read();       X[i] = u;       Y[i] = v;       for (int j = 0; j < D; j++)         addEdge(getIndex(X[i], j), getIndex(Y[i], j + 1));     }     for (int i = 1; i <= n; i++) {       scanf( %s , open[i]);     }     tarjan(getIndex(1, 0));     memset(head, 0, sizeof(head));     tot = 0;     for (int i = 0; i < m; i++) {       for (int j = 0; j < D; j++) {         int u = getIndex(X[i], j);         int v = getIndex(Y[i], j + 1);         if (!nid[u] || !nid[v]) continue;         if (nid[u] == nid[v]) continue;         addEdge(nid[u], nid[v]);         dag[nid[v]]++;       }     }     q.push(getIndex(1, 0));     int ans = 0;     while (!q.empty()) {       int t = q.front();       q.pop();       ans = std::max(ans, dp[t] += sz[t]);       for (int i = head[t]; i; i = nxt[i]) {         dp[to[i]] = std::max(dp[to[i]], dp[t]);         if (!--dag[to[i]]) q.push(to[i]);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[1000005];   int main() {     int n;     cin >> n;     int a[n], b[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     int l = 0;     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         if (b[j] == a[i]) {           for (int k = j; k > i; k--) {             ans[l++] = k;             swap(b[k - 1], b[k]);           }           break;         }       }     }     cout << l << endl;     for (int i = 0; i < l; i++) {       cout << ans[i] <<     << ans[i] + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     string s1 =  hello ;     int n1 = s1.size();     int i = 0, j = 0;     int count = 0;     while (j < n1 && i < n) {       if (s1[j] == s[i]) {         j++;         count++;       }       i++;     }     if (count == n1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j = 0, k, sum = 0, ctr = 0, c = 0, ok = 0;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long a, b, c;     cin >> a >> b >> c;     for (i = a; i >= 0; i--) {       if (c >= i * 4 && b >= i * 2) {         ok = i;         break;       }     }     cout << ok * 7;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int cen, feet = 0, inch;     cin >> cen;     inch = cen / 3;     if (cen % 3 == 2) inch++;     if (inch >= 12) {       feet = inch / 12;       inch = inch % 12;     }     cout << feet <<     << inch << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int nmin, nmax = 1;     int n, m, a, b;     scanf( %d%d , &n, &m);     nmin = n;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       if (b < a) swap(a, b);       nmin = min(nmin, b);       nmax = max(nmax, a);     }     if (nmax < nmin)       printf( %d n , nmin - nmax);     else       printf( 0 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int infinity = 10000000;   int railway[401][401];   int calculatedistance(int start, int end, bool bus) {     bool visitedtown[401];     int distance[401];     queue<int> myQueue;     for (int i = 1; i <= 400; i++) visitedtown[i] = false;     for (int i = 1; i <= 400; i++) distance[i] = infinity;     distance[start] = 0;     visitedtown[start] = true;     myQueue.push(start);     while (!myQueue.empty()) {       int town = myQueue.front();       myQueue.pop();       for (int i = 1; i <= end; i++)         if (i != town) {           if (bus) {             if (!railway[town][i])               if (!visitedtown[i])                 if (distance[town] + 1 < distance[i]) {                   distance[i] = distance[town] + 1;                   visitedtown[i] = true;                   myQueue.push(i);                 }           } else {             if (railway[town][i])               if (!visitedtown[i])                 if (distance[town] + 1 < distance[i]) {                   distance[i] = distance[town] + 1;                   visitedtown[i] = true;                   myQueue.push(i);                 }           }         }     }     return distance[end];   }   int main() {     int n, m, u, v;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) railway[i][j] = 0;     for (int i = 0; i < m; i++) {       cin >> u >> v;       railway[u][v] = 1;       railway[v][u] = 1;     }     int bdis = calculatedistance(1, n, true);     int tdis = calculatedistance(1, n, false);     if (bdis == infinity || tdis == infinity) {       cout <<  -1 ;       return 0;     }     if (bdis != tdis) {       cout << max(bdis, tdis);       return 0;     }     int disb = infinity;     for (int i = 2; i < n; i++)       disb = min(disb,                  calculatedistance(1, i, false) + calculatedistance(i, n, false));     int dist;     for (int i = 2; i < n; i++)       dist = min(dist,                  calculatedistance(1, i, true) + calculatedistance(i, n, true));     cout << min(disb, dist);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int limit[100005] = {0};   int main() {     ios::sync_with_stdio(false);     memset(limit, 0, sizeof(limit));     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, k;       cin >> x >> k;       if (x == limit[k])         limit[k]++;       else if (x > limit[k]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, w, h;     string temp;     vector<string> img;     cin >> w >> h;     for (i = 0; i < h; i++) {       cin >> temp;       img.push_back(temp);     }     for (j = 0; j < w; j++) {       for (i = 0; i < h; i++) cout << img[i][j] << img[i][j];       cout << endl;       for (i = 0; i < h; i++) cout << img[i][j] << img[i][j];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int a[1005][1005];   int main() {     int h, w;     cin >> h >> w;     vector<int> r(h), c(w);     for (int i = 0; i < h; i++) {       cin >> r[i];     }     for (int i = 0; i < w; i++) {       cin >> c[i];     }     memset(a, -1, sizeof(a));     for (int i = 0; i < h; i++) {       for (int j = 0; j < r[i]; j++) {         a[i][j] = 1;       }       a[i][r[i]] = 0;     }     for (int i = 0; i < w; i++) {       for (int j = 0; j < c[i]; j++) {         if (a[j][i] == 0) {           cout << 0 << endl;           return 0;         }         a[j][i] = 1;       }       if (a[c[i]][i] == 1) {         cout << 0 << endl;         return 0;       }       a[c[i]][i] = 0;     }     int ans = 1;     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         if (a[i][j] == -1) {           ans = (1ll * 2 * ans) % mod;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int l[N], r[N], n, i, ans, a[N], w, j;   char c[N];   bool bb[N];   set<int> s;   set<int>::iterator it;   inline void maintain(int i) {     if ((l[i] && c[i] != c[l[i]]) || (r[i] <= n && c[r[i]] != c[i]))       s.insert(i);     else if (s.count(i))       s.erase(i);   }   int main() {     scanf( %s , c + 1);     n = strlen(c + 1);     for (i = 1; i <= n; ++i) {       l[i] = i - 1, r[i] = i + 1;       r[0] = 1, l[n + 1] = n;       if ((i > 1 && c[i] != c[i - 1]) || (i < n && c[i] != c[i + 1])) a[++w] = i;     }     ans = bool(w);     for (;;) {       for (i = 1; i <= w; ++i) bb[a[i]] = 1;       s.clear();       for (i = 1; i <= w; ++i) {         j = a[i];         l[r[j]] = l[j];         r[l[j]] = r[j];         if (!bb[l[j]] && l[j]) maintain(l[j]);         if (!bb[r[j]] && r[j] <= n) maintain(r[j]);       }       for (i = 1; i <= w; ++i) bb[a[i]] = 0;       if (s.empty()) break;       ++ans;       for (it = s.begin(), w = 0; it != s.end(); ++it) a[++w] = *it;       s.clear();     }     return printf( %d n , ans), 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<int> A(91, 0);     for (int i = 0; s[i]; i++) {       A[(int)s[i]]++;     }     for (int i = 65; i < 65 + k; i++)       if (A[i] == 0) {         cout <<  0 ;         return 0;       }     cout << k * (*min_element(A.begin() + 65, A.begin() + 65 + k));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   struct Matrix {     long long coef[105][105];     Matrix() {       for (int i = (0); i <= (101); ++i)         for (int j = (0); j <= (101); ++j) coef[i][j] = 0;     }     Matrix operator*(Matrix a) {       Matrix res;       for (int i = (0); i <= (101); ++i) {         for (int j = (0); j <= (101); ++j) {           for (int k = (0); k <= (101); ++k) {             res.coef[i][j] =                 (res.coef[i][j] + coef[i][k] * a.coef[k][j] % mod) % mod;           }         }       }       return res;     }   };   Matrix expo(Matrix A, long long n) {     if (n == 1) return A;     Matrix Q = expo(A, n / 2);     if (n % 2 == 0) return Q * Q;     return Q * Q * A;   }   int a[50001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, b, k, x;     cin >> n >> b >> k >> x;     Matrix A;     for (int i = 1; i <= int(n); i++) cin >> a[i];     for (int i = 1; i <= int(n); i++) {       for (int m = 0; m < int(x); m++) {         int newm = (m * 10 + a[i]) % x;         A.coef[m][newm]++;       }     }     Matrix B = expo(A, b);     cout << B.coef[0][k] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long int INF = 1e18 + 2;   bool compareBysecond(pair<long long int, long long int> a,                        pair<long long int, long long int> b) {     return a.second > b.second;   }   int log(long long int x) {     int cnt = 0;     while (x > 0) {       cnt++;       x = x >> 1;     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, x, y;       cin >> n >> x >> y;       int k = n;       while (((y - x) % (k - 1)) != 0) k--;       int d = (y - x) / (k - 1);       vector<int> ans;       for (int i = 0; x + i * d <= y; ++i) {         ans.push_back(x + i * d);       }       if (ans.size() != n) {         int temp = x - d;         while (temp > 0 && ans.size() != n) {           ans.push_back(temp);           temp -= d;         }       }       if (ans.size() != n) {         int temp = y + d;         while (ans.size() != n) {           ans.push_back(temp);           temp += d;         }       }       for (auto it : ans) cout << it <<    ;       cout <<   n ;       ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 10;   const int MAXM = 10000 + 10;   const int INF = 1000 * 1000 * 1000;   int n, m, a[MAXM], b[MAXM], c[MAXM], q[MAXN], d[MAXN][MAXN], s, minimum[MAXN];   int main() {     int check = 0;     int sum = 0;     int pt = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       minimum[i] = INF;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> c[i];       d[a[i]][b[i]] = c[i];       minimum[b[i]] = min(c[i], minimum[b[i]]);     }     for (int i = 1; i <= n; i++) {       if (minimum[i] != INF) {         sum += minimum[i];         check++;       }     }     if (check == n - 1)       cout << sum;     else       cout << -1;     cin >> s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char arr[2][100010];   int vis[2][100010];   int k, n, curj1, curj2;   bool valid(int i, int j) {     if (i >= 0 && i < 2 && j >= 0 && j >= n) return true;     if (i >= 0 && i < 2 && j >= 0 && j < n && arr[i][j] !=  X  && vis[i][j] == 0)       return true;     return false;   }   void bfs(int i, int j) {     queue<pair<int, int> > q;     q.push(make_pair(i, j));     vis[i][j] = 1;     while (!q.empty()) {       int toi = q.front().first;       int toj = q.front().second;       q.pop();       if (toj >= n) {         cout <<  YES  << endl;         return;       }       if (valid(toi + 1, toj + k)) {         q.push(make_pair(toi + 1, toj + k));         vis[toi + 1][toj + k] = vis[toi][toj] + 1;       }       if (valid(toi - 1, toj + k)) {         q.push(make_pair(toi - 1, toj + k));         vis[toi - 1][toj + k] = vis[toi][toj] + 1;       }       if (valid(toi, toj + 1)) {         q.push(make_pair(toi, toj + 1));         vis[toi][toj + 1] = vis[toi][toj] + 1;       }       if (valid(toi, toj - 1) && toj - 1 > vis[toi][toj] - 1) {         q.push(make_pair(toi, toj - 1));         vis[toi][toj - 1] = vis[toi][toj] + 1;       }     }     cout <<  NO  << endl;   }   int main() {     int i, j;     cin >> n >> k;     for (i = 0; i < 2; i++) {       for (j = 0; j < n; j++) cin >> arr[i][j];     }     bfs(0, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Res[2][7010], N[2][7010], Loss[2][7010];   int n, m, k, OpN[2];   queue<pair<int, int> > Q;   int main() {     srand((unsigned)time(0));     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     cin.get();     for (int i = 0; i < 2; i++) {       cin >> m;       OpN[i] = m;       for (int j = 0; j < m; j++) {         cin >> k;         N[i][j] = k;         Res[i][n + 1 - k] = 1;         Q.push({i, n + 1 - k});       }     }     pair<int, int>* P;     while (!Q.empty()) {       P = &Q.front();       int k = !P->first, i = P->second;       Q.pop();       for (int j = 0; j < OpN[k]; j++) {         int h = N[k][j], l = ((i - h < 1) ? (i - h + n) : (i - h));         if (Res[k][l] == 0) {           Loss[k][l]++;         }       }       for (int i = 2; i < n + 1; i++) {         if (Res[k][i] == 0) {           if (Loss[k][i] == OpN[k]) {             Res[k][i] = 2;             for (int t = 0; t < OpN[!k]; t++) {               int h = N[!k][t], l = ((i - h < 1) ? (i - h + n) : (i - h));               if (Res[!k][l] == 0) {                 Res[!k][l] = 1;                 Q.push({!k, l});               }             }           }         }       }     }     string Out[3] = { Loop ,  Win ,  Lose };     for (int k = 0; k < 2; k++) {       for (int i = 2; i < n + 1; i++) {         cout << Out[Res[k][i]].c_str() <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       bool prob[5];       for (bool& i : prob) {         i = true;       }       if ((a == 0 && b == 0) || (a + b) % 2 == 0) {         prob[1] = prob[2] = false;         if (a == 0 && d == 0) {           prob[4] = false;         } else if (b == 0 && c == 0) {           prob[3] = false;         }       } else {         prob[3] = prob[4] = false;         if (a == 0 && d == 0) {           prob[1] = false;         } else if (b == 0 && c == 0) {           prob[2] = false;         }       }       for (int i = 1; i <= 4; i++) {         cout << (prob[i] ?  Ya   :  Tidak  );       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> p[3030];   long long dist[3030][3030];   pair<long long, long long> out[3030][5];   pair<long long, long long> in[3030][5];   void bfs(int x) {     dist[x][x] = 0;     queue<pair<long long, long long> > q;     q.push(make_pair(0, x));     pair<long long, long long> t;     while (!q.empty()) {       t = q.front();       q.pop();       for (int i = 0; i < p[t.second].size(); i++) {         if (dist[x][p[t.second][i]] > 1 + t.first) {           dist[x][p[t.second][i]] = 1 + t.first;           out[x][0] = make_pair(dist[x][p[t.second][i]], p[t.second][i]);           sort(out[x], out[x] + 5);           in[p[t.second][i]][0] = make_pair(dist[x][p[t.second][i]], x);           sort(in[p[t.second][i]], in[p[t.second][i]] + 5);           q.push(make_pair(dist[x][p[t.second][i]], p[t.second][i]));         }       }     }   }   int main() {     int n, m, x, y;     cin >> n >> m;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       p[x].push_back(y);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         dist[i][j] = 1e18;       }       for (int j = 0; j <= 4; j++) {         out[i][j] = make_pair(-1, -1);         in[i][j] = make_pair(-1, -1);       }     }     for (int i = 1; i <= n; i++) bfs(i);     long long l1, l2;     int res[5];     long long maxx = -1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         l2 = dist[i][j];         if (l2 == 1e18) continue;         for (int k = 4; k >= 0; k--) {           for (int k1 = 4; k1 >= 0; k1--) {             l1 = l2;             x = in[i][k].second;             y = out[j][k1].second;             if (x == y) continue;             if (x == i || x == j) continue;             if (y == i || y == j) continue;             if (x == -1 || y == -1) continue;             l1 += in[i][k].first;             l1 += out[j][k1].first;             if (maxx < l1) {               maxx = l1;               res[0] = x;               res[1] = i;               res[2] = j;               res[3] = y;             }           }         }       }     }     for (int i = 0; i < 4; i++) printf( %d  , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int ans = 0;     for (int i = 1; i < n; ++i) {       if (a[i] == 3 && a[i - 1] == 1) {         ans += 4;       } else if (a[i] == 1 && a[i - 1] == 3) {         ans += 4;       } else if (a[i] == 2 && a[i - 1] == 1) {         if (i > 1 && a[i - 2] == 3) {           ans += 2;         } else {           ans += 3;         }       } else if (a[i] == 1 && a[i - 1] == 2) {         ans += 3;       } else if (a[i] == 3 && a[i - 1] == 2) {         cout <<  Infinite  << endl;         return;       } else if (a[i] == 2 && a[i - 1] == 3) {         cout <<  Infinite  << endl;         return;       }     }     cout <<  Finite  << endl;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }