malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const unsigned long long inf = 1LL << 61;   const double eps = 1e-5;   using namespace std;   bool cmp(int a, int b) { return a > b; }   string itoa(long long a) {     string t =   ;     while (a > 0) {       t += (char)(a % 10 +  0 );       a /= 10;     }     string s =   ;     for (int i = t.size() - 1; i >= 0; i--) s += t[i];     return s;   }   long long atoi(string s) {     long long t = 1;     long long ans = 0;     for (int i = s.size() - 1; i >= 0; i--) {       long long b = (long long)(s[i] -  0 );       ans += b * t;       t *= 10;     }     return ans;   }   int main() {     int n, m;     while (cin >> n >> m) {       long long c = m + n;       string c1 = itoa(c);       string c2 =   ;       for (int i = 0; i < c1.size(); i++) {         if (c1[i] !=  0 ) c2 += c1[i];       }       long long cc = atoi(c2);       string a = itoa(n);       string b = itoa(m);       string a1 =   ;       string b1 =   ;       for (int i = 0; i < a.size(); i++) {         if (a[i] !=  0 ) a1 += a[i];       }       for (int j = 0; j < b.size(); j++) {         if (b[j] !=  0 ) b1 += b[j];       }       long long aa = atoi(a1);       long long bb = atoi(b1);       if (aa + bb == cc)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int ans[100005];   string s[100005];   map<string, int> h;   vector<pair<int, int> > v;   string res[6] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };   int main() {     memset(ans, -1, sizeof(ans));     ios_base::sync_with_stdio(false);     cin.tie(NULL);     h[ S ] = 0;     h[ M ] = 1;     h[ L ] = 2;     h[ XL ] = 3;     h[ XXL ] = 4;     h[ XXXL ] = 5;     for (int i = 0; i < 6; i++) cin >> a[i];     int n;     cin >> n;     bool ok = 1;     for (int i = 1; i <= n; i++) {       cin >> s[i];       string t[2];       t[0] =   ;       t[1] =   ;       int k = 0;       int m = s[i].length();       for (int j = 0; j < m; j++) {         if (s[i][j] ==  , )           k++;         else           t[k] += s[i][j];       }       if (t[1] ==   ) {         ans[i] = h[t[0]];         a[h[t[0]]]--;         if (a[h[t[0]]] < 0) ok = 0;       } else         v.push_back(pair<int, int>(h[t[0]], i));     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       int j = v[i].second, x = v[i].first;       if (a[x] > 0)         ans[j] = x, a[x]--;       else         ans[j] = x + 1, a[x + 1]--;     }     for (int i = 0; i < 6; i++)       if (a[i] < 0) ok = 0;     if (!ok)       printf( NO n );     else {       cout <<  YES             <<   n ;       for (int i = 1; i <= n; i++) cout << res[ans[i]] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[103], n, x, y, m, ans;   int main() {     cin >> x >> y >> n;     m = x * y;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       int x, j;       cin >> x;       for (j = 0; j < n; j++) {         if (a[j] == x) break;       }       ans = ans + j + 1;       for (int k = j - 1; k >= 0; k--) a[k + 1] = a[k];       a[0] = x;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   void runcase() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int changes = 0;     k--;     for (int i = 1; i < n; i++)       if (a[i] != a[i - 1]) changes++;     int ans = 0;     if (k == 0) {       if (changes == 0)         ans = 1;       else         ans = -1;     } else {       ans = max(1, (changes + k - 1) / k);     }     cout << ans << endl;   }   int main() {     int t;     cin >> t;     while (t--) runcase();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[10];   void ge() {     f[0] = 1;     for (int i = 1; i <= 9; i++) {       f[i] = f[i - 1] * 10;     }   }   long long a[100005], b[100005];   int main() {     ge();     int n, k;     long long ans = 1;     int i, j;     scanf( %d%d , &n, &k);     for (i = 0; i < n / k; i++) {       scanf( %I64d , &a[i]);     }     for (i = 0; i < n / k; i++) {       scanf( %I64d , &b[i]);     }     for (i = 0; i < n / k; i++) {       long long n1 = (f[k] - 1) / a[i] + 1;       long long n2 = (f[k - 1] - 1) / a[i] + 1;       long long n3 = (f[k - 1] * (b[i] + 1) - 1) / a[i] + 1 -                      (f[k - 1] * b[i] - 1) / a[i] - 1;       if (b[i] == 0)         ans *= n1 - n2;       else         ans *= n1 - n3;       ans %= 1000000007;     }     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<long long int> a(n);     vector<long long int> mp(n + 1, 0);     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     vector<long long int> ans(n + 1);     priority_queue<pair<long long, long long>> pq;     long long cost = 0;     for (int i = 0; i < n + 1; i++) {       ans[i] = mp[i] + cost;       if (mp[i] == 0) {         if (pq.empty()) {           for (int j = i + 1; j < n + 1; j++) ans[j] = -1;           break;         }         auto tp = pq.top();         pq.pop();         cost += (long long)(i - tp.first);         tp.second--;         if (tp.second > 1) pq.push({tp.first, tp.second});       }       if (mp[i] > 1) pq.push({i, mp[i]});     }     for (int i = 0; i < n + 1; i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> in[101000];   int n, m, k, curt;   int up[101000], t[101000], tout[101000], ans[101000];   int jmp[101000][20];   char used[101000];   void dfs(int v, int p) {     if (used[v]) return;     used[v] = 1;     t[v] = curt++;     up[v] = t[v];     for (unsigned int i = 0; i < in[v].size(); i++)       if (used[in[v][i]]) {         if (p != in[v][i]) up[v] = min(up[v], t[in[v][i]]);       } else {         dfs(in[v][i], v);         up[v] = min(up[v], up[in[v][i]]);       }   }   void dfs2(int v, int cur) {     if (used[v]) return;     used[v] = 1;     ans[v] = cur;     for (unsigned int i = 0; i < in[v].size(); i++)       if (!used[in[v][i]] && !((t[v] < t[in[v][i]] && up[in[v][i]] > t[v]) ||                                (t[v] > t[in[v][i]] && up[v] > t[in[v][i]])))         dfs2(in[v][i], cur);     for (unsigned int i = 0; i < in[v].size(); i++)       if (!used[in[v][i]] && ((t[v] < t[in[v][i]] && up[in[v][i]] > t[v]) ||                               (t[v] > t[in[v][i]] && up[v] > t[in[v][i]])))         dfs2(in[v][i], cur + 1);   }   void getLCA(int v, int p) {     if (used[v]) return;     used[v] = 1;     t[v] = curt++;     jmp[v][0] = p;     for (int i = 1; i <= 18; ++i) jmp[v][i] = jmp[jmp[v][i - 1]][i - 1];     for (unsigned int i = 0; i < in[v].size(); i++)       if (in[v][i] != p) getLCA(in[v][i], v);     tout[v] = curt++;   }   char upp(int a, int b) { return t[a] <= t[b] && tout[a] >= tout[b]; }   int lca(int a, int b) {     if (upp(a, b)) return a;     if (upp(b, a)) return b;     for (int i = 18; i >= 0; --i)       if (!upp(jmp[a][i], b)) a = jmp[a][i];     return jmp[a][0];   }   int main(void) {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int q, w;       cin >> q >> w;       in[q].push_back(w);       in[w].push_back(q);     }     dfs(1, -1);     memset(used, 0, sizeof(used));     curt = 0;     dfs2(1, 0);     curt = 0;     memset(used, 0, sizeof(used));     getLCA(1, 1);     cin >> k;     for (int i = 0; i < k; i++) {       int q, w;       cin >> q >> w;       int l = lca(q, w);       cout << ans[q] + ans[w] - 2 * ans[l] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double x, y, r, x1, y1;     cin >> r >> x >> y >> x1 >> y1;     double diam = 2 * r;     double dist = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));     int q = 0;     if (dist == 0) {       cout << 0 << endl;     } else {       while (dist >= diam) {         dist -= diam;         q++;       }       if (dist == 0) {         cout << q << endl;       } else {         cout << q + 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int MAX = 1e5 + 7;   using namespace std;   string st =  fedabc ;   void solve(unsigned long long n, char c) {     n--;     unsigned long long res = 16LL * (n / 4LL);     if (n % 2) res += 7;     res += st.find(c) + 1;     cout << res;   }   void mysolve(unsigned long long n, char c) {     unsigned long long l = 0, r = n / 2;     unsigned long long res = 0;     while (l <= r) {       unsigned long long mid = (l + r) / 2;       if ((1 + (mid + (mid * 3LL))) <= n) {         res = mid;         l = mid + 1;       } else {         r = mid - 1;       }     }     unsigned long long currF = (1 + (res + (res * 3)));     unsigned long long served = 2LL * res;     unsigned long long sec = 6;     if ((currF == n) || (currF + 2 == n)) {       sec += ((served - 1) * 6) + (currF - 1);     } else if (currF + 1 == n || currF + 3 == n) {       sec += (served * 6) + (currF);     } else if (currF + 4 == n || currF + 6 == n) {       sec += ((served + 1) * 6) + (currF + 1);     }     for (auto i : st) {       sec++;       if (i == c) break;     }     cout << sec;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     unsigned long long n = stoll(s.substr(0, s.size() - 1));     char seat = s[s.size() - 1];     solve(n, seat);   }
#include <bits/stdc++.h>   using namespace std;   int ar[1002][1002];   char buf[20];   int main() {     int n, m, k, w;     int res = 0;     vector<pair<int, int> > r;     scanf( %d %d %d %d n , &n, &m, &k, &w);     vector<vector<string> > f(k);     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         fgets(buf, 20, stdin);         string s = buf;         s = s.substr(0, s.size() - 1);         f[i].push_back(s);       }     }     for (int i = 0; i < f.size(); i++) {       for (int j = i + 1; j < f.size(); j++) {         int d = 0;         for (int e = 0; e < n; e++) {           for (int l = 0; l < m; l++) {             if (f[i][e][l] != f[j][e][l]) d++;           }         }         if (d * w < n * m) {           ar[i + 1][j + 1] = d * w;           ar[j + 1][i + 1] = d * w;         } else {           ar[i + 1][j + 1] = 1000;           ar[j + 1][i + 1] = 1000;         }       }     }     for (int i = 0; i < k + 1; i++) {       ar[0][i] = n * m;       ar[i][0] = n * m;     }     vector<char> used(k + 1, false);     vector<int> min_edge(k + 1, 1000), end_edge(k + 1, -1);     min_edge[0] = 0;     for (int i = 0; i < k + 1; i++) {       int v = -1;       for (int j = 0; j < k + 1; j++) {         if (!used[j] && (v == -1 || min_edge[j] < min_edge[v])) v = j;       }       used[v] = true;       if (end_edge[v] != -1) {         res += ar[v][end_edge[v]];         r.push_back(pair<int, int>(v, end_edge[v]));       }       for (int j = 0; j < k + 1; j++) {         if (ar[v][j] < min_edge[j]) {           min_edge[j] = ar[v][j];           end_edge[j] = v;         }       }     }     printf( %d n , res);     for (int i = 0; i < r.size(); i++) {       printf( %d %d n , r[i].first, r[i].second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   size_t ham_dist(const string &a, const string &b) {     size_t ct = 0;     for (size_t i = 0; i < a.size(); ++i)       if (a[i] != b[i]) ++ct;     return ct;   }   string opp(const string &a) {     string r =   ;     for (size_t i = 0; i < a.size(); ++i) r += (a[i] ==  0  ?  1  :  0 );     return r;   }   string read_line(size_t m) {     string r;     for (size_t j = 0; j < m; ++j) {       char c[2];       cin >> c;       r += string(c);     }     return r;   }   string string_from_int(size_t len, size_t z) {     string o;     for (size_t i = 0; i < len; ++i) {       if (z & (1 << i))         o +=  1 ;       else         o +=  0 ;     }     return o;   }   int main() {     size_t n, m, k;     cin >> n >> m >> k;     map<string, size_t> counts;     vector<string> mat;     mat.reserve(n);     for (size_t i = 0; i < n; ++i) {       string l = read_line(m);       mat.push_back(l);     }     if (n < m) {       vector<string> newmat = mat;       swap(n, m);       mat.clear();       mat.reserve(n);       for (size_t i = 0; i < n; ++i) {         string p;         for (size_t j = 0; j < m; ++j) {           p += newmat[j][i];         }         mat.push_back(p);       }     }     for (size_t i = 0; i < n; ++i) {       string &l = mat[i];       if (counts.find(l) == counts.end()) counts[l] = 0;       ++counts[l];     }     bool feasible = false;     if (counts.size() <= k + 2) {       if (n <= k) {         for (size_t z = 0; z < ((size_t)1 << m); ++z) {           string l = string_from_int(m, z);           if (counts.find(l) == counts.end()) counts[l] = 0;         }       }       for (map<string, size_t>::iterator it = counts.begin(); it != counts.end();            ++it) {         size_t cost = 0;         for (map<string, size_t>::iterator jt = counts.begin();              jt != counts.end(); ++jt) {           if (jt->second == 0) continue;           size_t cost_per = ham_dist(it->first, jt->first);           cost_per = min(cost_per, ham_dist(opp(it->first), jt->first));           cost += cost_per * jt->second;         }         if (cost <= k) {           feasible = true;           k = cost;         }       }     }     if (!feasible) {       cout <<  -1  << endl;     } else {       cout << k << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, num;     cin >> n;     if (n % 2 == 0) {       num = n / 2;       cout << num << endl;       for (int i = 0; i < num; i++) {         cout <<  2  ;       }     } else {       num = ((n - 3) / 2) + 1;       cout << num << endl;       for (int i = 0; i < num - 1; i++) {         cout <<  2  ;       }       cout <<  3 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> data(n + 1);     for (int i = 1; i <= n; i++) cin >> data[i];     int i = 1, j = n;     while (j > i && data[j] == data[1]) j--;     while (i < j && data[i + 1] == data[1]) i++;     cout << max(j - 1, max(j - i, n - i - 1)) << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n = 0, k = 0, s = 0;     cin >> n >> k >> s;     int sz = min(n * (n - 1), k * (k - 1) / 2 + s);     vector<vector<int> > dp(k + 1, vector<int>(sz + 1, 1e9 + 42));     dp[0][0] = 0;     for (int pos = 0; pos < n; pos++) {       int q;       cin >> q;       for (int i = k - 1; i >= 0; i--)         for (int j = sz - pos; j >= 0; j--)           dp[i + 1][j + pos] = min(dp[i + 1][j + pos], dp[i][j] + q);     }     int ans = 1e9 + 42;     for (int i = k * (k - 1) / 2; i <= sz; i++) ans = min(ans, dp[k][i]);     cout << ans;     return 0;   }
//  “Alhamdulillah for Everything”   #include<bits/stdc++.h>   using namespace std;      #define      pai              acos(-1)   #define      ff               first   #define      ss               second   #define      ll               long long   #define      pb               push_back   #define      mp               make_pair   #define      pll              pair<ll,ll>   #define      sz(a)            (ll)a.size()   #define      endl               n    #define      gcd(a, b)        __gcd(a, b)   #define      lcm(a, b)        ((a*b)/gcd(a,b))   #define      all(vec)         vec.begin(),vec.end()   #define      ms(a, b)         memset(a,b,sizeof(a))   #define      rep(i,n)         for(int i= 0; i < int(n); i++)   #define      rep1(i,n)        for(int i= 1; i <= n; i++)   #define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)   #define      PRINT_CASE       printf( Case %d:  ,zz)   #define      fii              freopen( input.txt , r ,stdin);   #define      foo              freopen( output.txt , w ,stdout);   #define      boom             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);      const ll M   = 1e9+7;   const ll mxn = 1e5+7;   const ll inf = 1e18;      int  main()   {       //boom;       ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;       cin>>t;       TEST_CASE(t)       {           cin>>n>>k;           vector<ll>vec(n);           for(i=0;i<n;i++)           {               cin>>vec[i];           }           ll ans=0,sum=vec[0];           for(i=1;i<n;i++)           {               a=vec[i]*100;               b=sum*k;               if(a<b)               {                   sum+=vec[i];               }               else               {                   ll tem=a-b+k-1;                   tem/=k;                   sum+=(vec[i]+tem);                   ans+=tem;               }               //cout<<i<< === <<sum<< ==== <<ans<<endl;           }           cout<<ans<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return SQR(POW(B, P / 2));   }   template <typename T>   inline T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   inline T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T BMOD(T p, T e, T m) {     T ret = 1;     while (e) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;       e >>= 1;     }     return (T)ret;   }   int n, T;   int wt[200005], bit[200005];   set<pair<int, int> > st;   void update(int pos) {     while (pos < 200001) {       bit[pos] += 1;       pos += (pos & -pos);     }     return;   }   int query(int pos) {     int sum = 0;     while (pos > 0) {       sum += bit[pos];       pos -= (pos & -pos);     }     return sum;   }   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) {       scanf( %d , &wt[i]);       st.insert(make_pair(wt[i] - i, i));     }     int ans = 0;     for (auto &i : st) {       int xx = i.first;       int yy = i.second;       update(yy);       int rng = T - 1 - xx;       rng = min(n, rng);       rng = min(rng, T - 1);       if (rng <= 0) continue;       int id = query(rng);       ans = max(ans, id);     }     printf( %d , ans), puts(  );     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1025;   const int maxm = 10;   using namespace std;   int main() {     int n;     string s;     cin >> n;     cin >> s;     int ans1 = 0, ans2 = 0;     int cnt1 = 0;     int f = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ( ) {         f = 1;         ans1 = max(ans1, cnt1);         cnt1 = 0;         continue;       }       if (s[i] ==  ) ) {         f = 0;         continue;       }       if (!f) {         if (s[i] !=  _ ) {           cnt1++;         } else {           ans1 = max(ans1, cnt1);           cnt1 = 0;         }       }       if (f) {         if ((s[i - 1] ==  (  || s[i - 1] ==  _ ) && s[i] !=  _ ) {           ans2++;         }       }     }     ans1 = max(ans1, cnt1);     cnt1 = 0;     cout << ans1 <<     << ans2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int arr[110][110], r[10010], c[10010], v[10010], t[10010];   int main() {     scanf( %d , &n), scanf( %d , &m), scanf( %d , &q);     for (int z = 0; z < q; ++z) {       scanf( %d , &t[z]);       if (t[z] == 1) scanf( %d , &r[z]);       if (t[z] == 2) scanf( %d , &c[z]);       if (t[z] == 3) scanf( %d , &r[z]), scanf( %d , &c[z]), scanf( %d , &v[z]);     }     reverse(t, t + q);     reverse(c, c + q);     reverse(r, r + q);     reverse(v, v + q);     for (int z = 0; z < q; ++z) {       if (t[z] == 1) {         --r[z];         v[z] = arr[r[z]][m - 1];         for (int j = m - 1; j > 0; --j) arr[r[z]][j] = arr[r[z]][j - 1];         arr[r[z]][0] = v[z];       } else if (t[z] == 2) {         --c[z];         v[z] = arr[n - 1][c[z]];         for (int i = n - 1; i > 0; --i) arr[i][c[z]] = arr[i - 1][c[z]];         arr[0][c[z]] = v[z];       } else {         arr[r[z] - 1][c[z] - 1] = v[z];       }     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) printf( %d%c , arr[i][j],    n [j == m - 1]);   }
#include <bits/stdc++.h>   using namespace std;   const int p = 1000000007;   int K;   struct Ma {     int g[31][31];     Ma() { memset(g, 0, sizeof(g)); }     int* operator[](int x) { return g[x]; }     Ma operator*(const Ma& b) const {       Ma res;       for (int i = 0; i <= K; i++)         for (int k = 0; k <= K; k++)           if (g[i][k])             for (int j = 0; j <= K; j++)               res.g[i][j] = (res.g[i][j] + (long long)g[i][k] * b.g[k][j]) % p;       return res;     }     void w() {       for (int i = 0; i <= K; i++) g[i][i] = 1;     }   } A[105][30], res, pre[105][30], sub[105][30];   int num[105], tot;   int main() {     ios::sync_with_stdio(0);     long long n;     cin >> n >> K;     while (n) num[tot++] = n % K, n /= K;     for (int i = 0; i < K; i++) {       for (int j = 0; j <= K; j++) A[0][i][j][j] = 1;       for (int j = 0; j <= K; j++) A[0][i][j][i] = 1;     }     for (int i = 1; i <= tot; i++) {       pre[i - 1][0] = A[i - 1][0];       for (int j = 1; j < K; j++) pre[i - 1][j] = pre[i - 1][j - 1] * A[i - 1][j];       sub[i - 1][K - 1] = A[i - 1][K - 1];       for (int j = K - 2; ~j; j--)         sub[i - 1][j] = A[i - 1][j] * sub[i - 1][j + 1];       for (int j = 0; j < K; j++) {         A[i][j].w();         A[i][j] = sub[i - 1][j];         if (j) A[i][j] = A[i][j] * pre[i - 1][j - 1];       }     }     res.g[K][K] = 1;     for (int i = tot - 1, j = 0; ~i; i--)       while (num[i]--) res = res * A[i][j], j = (j + 1) % K;     int ans = 0;     for (int i = 0; i <= K; i++) ans = (ans + res[K][i]) % p;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int l[6][6], h[6][6], a[6][6];   int in[6];   int cost;   int rec(int inNode, int outNode) {     if (inNode == n - 1) return 0;     int bestCost = -1;     for (int f = l[inNode][outNode]; f <= h[inNode][outNode]; f++) {       if (in[inNode] >= f && (outNode != n - 1 || in[inNode] == f)) {         int nextIn = inNode, nextOut = outNode + 1;         if (outNode == n) {           nextIn = inNode + 1;           nextOut = 0;         };         if (nextIn == nextOut) nextOut++;         in[inNode] -= f;         in[outNode] += f;         int val = rec(nextIn, nextOut);         if (val != -1) {           val += f * f;           if (f > 0) val += a[inNode][outNode];           bestCost = max(bestCost, val);         }         in[inNode] += f;         in[outNode] -= f;       }     }     return bestCost;   }   int s, f;   int main() {     cin >> n;     for (int i = 0; i < n * (n - 1) / 2; i++) {       cin >> s >> f;       s--, f--;       cin >> l[s][f] >> h[s][f] >> a[s][f];     }     int maxCost = -1;     int f;     for (f = 0; f <= 25; f++) {       memset(in, 0, sizeof in);       in[0] = f;       maxCost = rec(0, 1);       if (maxCost != -1) break;     }     if (maxCost != -1)       cout << f <<     << maxCost << endl;     else       cout << -1 <<     << -1 << endl;     return 0;   }