malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   typedef struct Segment {     int start;     int last;     int Xor;   } segment;   using namespace std;   vector<segment> V;   int score(segment s) {     if (s.last == s.start)       return s.Xor;     else {       int value = 0;       for (int i = s.start + 1; i < s.last;) {         if (V[i].start == -1)           i++;         else {           value += score(V[i]);           i = V[i].last + 1;         }       }       return max(value, s.Xor);     }   }   int cities_final[5010];   int cities_first[5010];   int cities[5010];   int main() {     int n;     scanf( %d , &n);     int people[n];     int cumulativeXOR[n + 1];     cumulativeXOR[0] = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &people[i]);       if (!cities[people[i]])         cumulativeXOR[i + 1] = cumulativeXOR[i] ^ people[i];       else         cumulativeXOR[i + 1] = cumulativeXOR[i];       if (!cities[people[i]]) cities_first[people[i]] = i;       cities[people[i]] = 1;       cities_final[people[i]] = i;     }     int start;     int last;     int Xor;     for (int i = 0; i < n; i++) {       start = i;       last = i;       int flag = 0;       if (cities[people[i]]) {         for (int j = i; j <= last; j++) {           if (cities_first[people[j]] < start) {             flag = 1;           }           if (cities_final[people[j]] > last) last = cities_final[people[j]];         }         Xor = cumulativeXOR[last + 1] ^ cumulativeXOR[start];         segment s;         s.start = start;         s.last = last;         s.Xor = Xor;         if (flag) s.start = -1;         cities[people[i]] = 0;         V.push_back(s);       } else {         segment s;         s.start = -1;         V.push_back(s);       }     }     int ans = 0;     for (int i = 0; i < n;) {       ans += score(V[i]);       i = V[i].last + 1;     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   bool ch1(int t, int da, int db, int a, int b, int x) {     for (int i = 0; i <= t - 1; i++) {       for (int j = 0; j <= t - 1; j++) {         if (((a - i * da + b - j * db == x) &&              (a - i * da >= 0 && b - j * db >= 0)) ||             a - i * da == x || b - j * db == x)           return true;       }     }     return false;   }   int main() {     int x, a, b, t, da, db, total;     cin >> x >> t >> a >> b >> da >> db;     total = a + b;     if (x > total)       cout <<  NO n ;     else if (x == 0)       cout <<  YES n ;     else {       if (ch1(t, da, db, a, b, x)) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, f[2001] = {0};   bool p, a[2001][2001];   string st;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> st;       for (int j = 0; j < m; j++)         if (st[j] ==  1 ) {           a[i][j + 1] = true;           f[j + 1]++;         } else           a[i][j + 1] = false;     }     for (int i = 1; i <= n; i++) {       p = true;       for (int j = 1; j <= m; j++)         if (f[j] == 1 && a[i][j] == 1) p = false;       if (p) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int main() {     fast();     long long n;     cin >> n;     char a[n + 10];     for (int i = 1; i <= n; ++i) cin >> a[i];     long long func[15];     for (int i = 1; i <= 9; ++i) {       cin >> func[i];     }     for (int i = 1; i <= n; ++i) {       if (func[a[i] -  0 ] > a[i] -  0 ) {         for (int j = i; j <= n; ++j) {           if (a[j] -  0  <= func[a[j] -  0 ])             a[j] = func[a[j] -  0 ] +  0 ;           else             break;         }         for (int j = 1; j <= n; ++j) cout << a[j];         return 0;       }     }     for (int i = 1; i <= n; ++i) cout << a[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   int n, m, k, s, t, a[N], b[N];   int ans;   long long p;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int j = 0; j < 25; ++j) {       for (int i = 1; i <= n; ++i) p += ((a[i] >> j) & 1) * (n - 1);       if (p & 1) ans += 1 << j;       p = 0;       for (int i = 1; i <= n; ++i) b[i] = a[i] % (1 << (j + 1));       sort(b + 1, b + 1 + n);       int r = n;       for (int l = 1; l < n; ++l) {         while (r > l && b[l] + b[r] >= (1 << (j + 1))) --r;         if (r <= l) r = l;         p += n - r;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int t;   long long l[200002], c[200002];   long long minx, maxx, miny, maxy;   string s;   bool check(long long l[], int n) {     int Min = 0, Max = 0;     int last = 0, first = 0;     for (int i = 1; i <= n; i++) {       if (l[i] < Min) {         first = i;         Min = l[i];       }       if (l[i] >= Max) {         last = i;         Max = l[i];       }     }     if (last < first) return 1;     Min = 0, Max = 0;     first = last = 0;     for (int i = 1; i <= n; i++) {       if (l[i] > Max) {         first = i;         Max = l[i];       }       if (l[i] <= Min) {         Min = l[i];         last = i;       }     }     if (last < first) return 1;     return 0;   }   int main() {     cin >> t;     while (t--) {       cin >> s;       minx = maxx = miny = maxy = 0;       long long x = 0, y = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  D ) c[i + 1] = c[i] + 1;         if (s[i] ==  A ) c[i + 1] = c[i] - 1;         if (s[i] ==  W ) l[i + 1] = l[i] + 1;         if (s[i] ==  S ) l[i + 1] = l[i] - 1;         if (s[i] ==  W  || s[i] ==  S ) c[i + 1] = c[i];         if (s[i] ==  D  || s[i] ==  A ) l[i + 1] = l[i];         minx = min(minx, l[i + 1]);         miny = min(miny, c[i + 1]);         maxx = max(maxx, l[i + 1]);         maxy = max(maxy, c[i + 1]);       }       long long ans = (maxx - minx + 1) * (maxy - miny + 1);       if (check(l, s.size()) && maxx - minx + 1 > 2)         ans = min(ans, (maxx - minx) * (maxy - miny + 1));       if (check(c, s.size()) && maxy - miny + 1 > 2)         ans = min(ans, (maxx - minx + 1) * (maxy - miny));       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int dx[4] = {0, 0, 1, -1};   const int dy[4] = {1, -1, 0, 0};   int n, a, b, c;   string s;   map<pair<int, pair<int, int> >, int> dic;   bool bo1 = false, bo2 = false, bo3 = false;   void dfs(int a, int b, int c) {     pair<int, pair<int, int> > temp = make_pair(a, make_pair(b, c));     if (dic[temp]) return;     dic[temp] = 1;     if (a + b + c == 1) {       if (a == 1) bo1 = true;       if (b == 1) bo2 = true;       if (c == 1) bo3 = true;       return;     }     if (a > 0 && b > 0) dfs(a - 1, b - 1, c + 1);     if (a > 0 && c > 0) dfs(a - 1, b + 1, c - 1);     if (b > 0 && c > 0) dfs(a + 1, b - 1, c - 1);     if (a > 1) dfs(a - 1, b, c);     if (b > 1) dfs(a, b - 1, c);     if (c > 1) dfs(a, b, c - 1);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     cin >> s;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] ==  B ) a++;       if (s[i] ==  G ) b++;       if (s[i] ==  R ) c++;     }     dfs(a, b, c);     if (bo1) cout <<  B ;     if (bo2) cout <<  G ;     if (bo3) cout <<  R ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int MX = 3003;   const int M = 998244353;   char s[MX], t[MX];   int n, m, ans, dp[MX][MX];   int f(int i, int j) {     if (i < 1 && j > n) return 1;     if (dp[i][j] == -1) {       int p = 0, q = 0, r = (i == j);       int k = j - i + r, x = (i < 1 && j > m);       if (i) {         if (i <= m)           p = (s[k] == t[i]) ? f(i - 1, j + r) : 0;         else           p = f(i - 1, j + r);       }       if (j <= n) {         if (j <= m)           q = (s[k] == t[j]) ? f(i - r, j + 1) : 0;         else           q = f(i - r, j + 1);       }       int y = (p + q < M) ? (p + q) : (p + q - M);       dp[i][j] = (x + y < M) ? (x + y) : (x + y - M);     }     return dp[i][j];   }   int main() {     scanf( %s %s , s + 1, t + 1);     n = strlen(s + 1), m = strlen(t + 1);     memset(dp, -1, sizeof(dp));     for (int i = 1; i <= n; i++) ans = (ans + f(i, i)) % M;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int day[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};   int sec, n, k, dd, mm, h, s, m, now;   string str;   queue<int> q;   int main() {     cin >> sec >> k;     getline(cin, str);     while (scanf( 2012-%d-%d %d:%d:%d: , &mm, &dd, &h, &m, &s) != EOF) {       getline(cin, str);       now = (day[mm - 1] + dd - 1) * 24 * 60 * 60 + h * 60 * 60 + m * 60 + s;       q.push(now);       while (q.front() + sec <= now) q.pop();       if (q.size() >= k) {         printf( 2012-%02d-%02d %02d:%02d:%02d , mm, dd, h, m, s);         return 0;       }     }     cout << -1 << endl;     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:128000000 )   using namespace std;   map<string, int> a;   map<string, int>::iterator ii, jj;   string s;   int main() {     int k, i, v, u, j, n, m, d, d2, y, r, p, t1, t2, x, l, t, z, fl, to;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s >> p;       if (a[s] <= p) a[s] = p;     }     k = 0;     for (ii = a.begin(); ii != a.end(); ii++) k++;     cout << k << endl;     for (ii = a.begin(); ii != a.end(); ii++) {       t = 0;       p = 0;       for (jj = a.begin(); jj != a.end(); jj++) {         if ((*ii).second >= (*jj).second) t++;         if ((*ii).second < (*jj).second) p++;       }       if ((double)p / (double)k > 0.5) {         cout << (*ii).first <<                  <<  noob  << endl;         continue;       }       if ((double)t / (double)k >= 0.5 && (double)p / (double)k > 0.2) {         cout << (*ii).first <<                  <<  random  << endl;         continue;       }       if ((double)t / (double)k >= 0.8 && (double)p / (double)k > 0.1) {         cout << (*ii).first <<                  <<  average  << endl;         continue;       }       if ((double)t / (double)k >= 0.9 && (double)p / (double)k > 0.01) {         cout << (*ii).first <<                  <<  hardcore  << endl;         continue;       }       if ((double)t / (double)k >= 0.99) {         cout << (*ii).first <<                  <<  pro  << endl;         continue;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     priority_queue<int> pq{};     for (int i{1}; i <= n; ++i) pq.push(i);     vector<pair<int, int>> ans{};     for (int i{0}; i < n - 1; ++i) {       int mx1{pq.top()};       pq.pop();       int mx2{pq.top()};       pq.pop();       ans.push_back({mx1, mx2});       pq.push((mx1 + mx2 + 1) / 2);     }     cout << pq.top() <<   n ;     for (auto& x : ans) cout << x.first <<     << x.second <<   n ;   }   void solve2() {     int n;     cin >> n;     cout <<  2 n ;     cout << n <<     << n - 1 <<   n ;     for (int i{n}; i >= 3; --i) cout << i <<     << i - 2 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) solve2();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[200] = {0};   int main() {     string a;     int m;     cin >> m;     cin >> a;     int n = a.length();     for (int i = 0; i < n; i++) {       if (a[i] !=  ? ) p[a[i] -  a ] = 1;       if (a[i] !=  ?  && a[i] -  a  >= m) {         cout <<  IMPOSSIBLE  << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       if (a[i] ==  ?  && a[n - i - 1] !=  ? ) a[i] = a[n - i - 1];     }     for (int i = n / 2; i >= 0; i--) {       if (a[i] ==  ?  && a[n - i - 1] ==  ? ) {         for (int j = m - 1; j >= 0; j--) {           if (!p[j]) {             a[i] = j +  a ;             a[n - i - 1] = j +  a ;             p[j] = 1;             break;           }         }         if (a[i] ==  ? ) a[i] =  a , a[n - i - 1] =  a ;       }     }     for (int i = 0; i < n; i++) {       if (a[i] != a[n - i - 1]) {         cout <<  IMPOSSIBLE  << endl;         return 0;       }     }     for (int i = 0; i < m; i++)       if (!p[i]) {         cout <<  IMPOSSIBLE  << endl;         return 0;       }     cout << a << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   int v[MAXN], l[MAXN], r[MAXN];   int ST[4 * MAXN];   int L[4 * MAXN];   int n;   void _update(int node, int lo, int hi, int i, int j, int val) {     if (L[node]) {       ST[node] = max(ST[node], L[node]);       if (hi != lo) {         L[2 * node] = max(L[node], L[2 * node]);         L[2 * node + 1] = max(L[node], L[2 * node + 1]);       }       L[node] = 0;     }     if (lo > j || hi < i) return;     if (lo >= i && hi <= j) {       ST[node] = max(ST[node], val);       if (hi != lo) {         L[2 * node] = max(val, L[2 * node]);         L[2 * node + 1] = max(val, L[2 * node + 1]);       }       return;     }     int mid = (lo + hi) / 2;     _update(2 * node, lo, mid, i, j, val);     _update(2 * node + 1, mid + 1, hi, i, j, val);     ST[node] = max(ST[2 * node], ST[2 * node + 1]);   }   int _query(int node, int l, int r, int i, int j) {     if (L[node]) {       ST[node] = max(ST[node], L[node]);       L[2 * node] = max(L[2 * node], L[node]);       L[2 * node + 1] = max(L[2 * node + 1], L[node]);       L[node] = 0;     }     if (r < i || l > j) return -1;     if (l >= i && r <= j) return ST[node];     int mid = (l + r) / 2;     int p1 = _query(2 * node, l, mid, i, j);     int p2 = _query(2 * node + 1, mid + 1, r, i, j);     return max(p1, p2);   }   int query(int i, int j) { return _query(1, 0, n, i, j); }   void update(int i, int j, int val) { _update(1, 0, n, i, j, val); }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     l[0] = -1;     for (int i = 1; i < n; i++) {       l[i] = i - 1;       while (v[l[i]] >= v[i] && l[i] != -1) l[i] = l[l[i]];     }     r[n - 1] = -1;     for (int i = n - 2; i >= 0; i--) {       r[i] = i + 1;       while (v[r[i]] >= v[i] && r[i] != -1) {         r[i] = r[r[i]];       }     }     for (int i = 0; i < n; i++) {       int ri = r[i], li = l[i];       if (ri == -1) ri = n;       if (li == -1) li = -1;       int segment_length = (ri - 1) - (li + 1) + 1;       update(1, segment_length, v[i]);     }     bool first = true;     for (int i = 1; i <= n; i++) {       if (first)         first = false;       else         printf(   );       printf( %d , query(i, i));     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[4];   int main() {     cin >> a[0] >> a[1] >> a[2] >> a[3];     sort(a, a + 4);     if (a[0] + a[1] > a[2] || a[1] + a[2] > a[3]) {       cout <<  TRIANGLE ;       return 0;     } else if (a[0] + a[1] == a[2] || a[1] + a[2] == a[3]) {       cout <<  SEGMENT ;       return 0;     } else       cout <<  IMPOSSIBLE ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 400010;   inline int max(int a, int b) { return a > b ? a : b; }   int head[maxn], cnt, sz[maxn], n, mx_sz, top[maxn], ans[maxn];   vector<int> vt;   struct ed {     int to, next;   } e[maxn * 2];   void ad(int x, int y) {     e[cnt] = (ed){y, head[x]};     head[x] = cnt++;     e[cnt] = (ed){x, head[y]};     head[y] = cnt++;   }   void get_vt(int u, int last) {     sz[u] = 1;     int mx = 0;     for (int k = head[u]; ~k; k = e[k].next) {       int v = e[k].to;       if (v != last) {         get_vt(v, u);         sz[u] += sz[v];         mx = max(mx, sz[v]);       }     }     mx = max(mx, n - sz[u]);     if (mx <= mx_sz) vt.push_back(u);   }   void dfs(int u, int last, int tp) {     sz[u] = 1, top[u] = tp;     for (int k = head[u]; ~k; k = e[k].next) {       int v = e[k].to;       if (v != last) {         dfs(v, u, tp);         sz[u] += sz[v];       }     }   }   void work(int u) {     ans[u] = 1;     memset(sz, 0, sizeof(sz));     int mx = 0, _mx = 0;     for (int k = head[u]; ~k; k = e[k].next) {       int v = e[k].to;       dfs(v, u, v);       if (sz[v] >= sz[mx])         _mx = mx, mx = v;       else if (sz[v] > sz[_mx])         _mx = v;     }     for (int i = 1; i <= n; i++) {       if (top[i] == mx)         ans[i] |= (n - sz[i] - sz[_mx] <= mx_sz);       else         ans[i] |= (n - sz[i] - sz[mx] <= mx_sz);     }   }   int main() {     while (~scanf( %d , &n)) {       cnt = 0;       mx_sz = n / 2;       vt.clear();       memset(sz, 0, sizeof(sz));       memset(ans, 0, sizeof(ans));       memset(head, -1, sizeof(head));       int u, v;       for (int i = 1; i < n; i++) {         scanf( %d%d , &u, &v);         ad(u, v);       }       get_vt(1, 0);       for (int i = 0; i < vt.size(); i++) work(vt[i]);       for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[3010], y[3010];   vector<int> py[3010];   int L[3010], R[3010], q, k;   void nxt(int &u, int k = 1) {     while (k-- > 0) u = R[u];   }   void pre(int &u, int k = 1) {     while (k-- > 0) u = L[u];   }   long long res = 0;   struct node {     int x, y;     bool operator<(const node a) const { return x < a.x; }   } p[3010];   int n, m;   void solve() {     res = 0;     int l = 0, r = 0;     nxt(r, k);     if (r == q + 1) return;     for (; r != q + 1; nxt(r)) {       nxt(l);       res += 1ll * p[l].x * (p[R[r]].x - p[r].x);     }   }   void del(int u) { R[L[u]] = R[u], L[R[u]] = L[u]; }   void erase(int u) {     int l = u;     pre(l, k + 1);     int l0 = l;     int r = l;     nxt(r, k);     for (; l < u && r < q + 1; nxt(r)) {       nxt(l);       res -= 1ll * p[l].x * (p[R[r]].x - p[r].x);     }     del(u);     l = r = l0;     nxt(r, k);     for (; R[l] < u && r < q + 1; nxt(r)) {       nxt(l);       res += 1ll * p[l].x * (p[R[r]].x - p[r].x);     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &q, &k);     for (int i = 1; i <= q; i++) scanf( %d%d , &p[i].x, &p[i].y);     sort(p + 1, p + q + 1);     p[q + 1] = (node){n + 1, m + 1};     for (int i = 1; i <= q; i++) py[p[i].y].push_back(i);     long long ans = 0;     R[q + 1] = q + 1;     for (int y0 = 1; y0 <= m; y0++) {       int pr = 0;       for (int i = 1; i <= q; i++)         if (p[i].y <= y0)           L[i] = pr, pr = i;         else           L[i] = 0;       L[q + 1] = pr;       pr = q + 1;       for (int i = q; i >= 1; i--)         if (p[i].y <= y0)           R[i] = pr, pr = i;         else           R[i] = 0;       R[0] = pr;       solve();       ans += res;       for (int y = 1; y <= y0; y++) {         for (int u : py[y]) erase(u);         ans += res;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct flight {     int d, f, t, c;   };   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     vector<flight> flights(m);     for (int i = 0; i < m; i++) {       scanf( %d %d %d %d , &flights[i].d, &flights[i].f, &flights[i].t,             &flights[i].c);     }     sort(flights.begin(), flights.end(),          [](const flight &a, const flight &b) { return a.d < b.d; });     vector<long long> miniCostTo(n + 1, (1LL << 50));     vector<long long> totalTo(1000001, (1LL << 50));     vector<bool> haveTo(n + 1);     int toCounter = 0;     long long costTo = 0;     int toIndex = 0;     for (int i = 0; i <= 1000000; i++) {       if (toCounter == n) {         totalTo[i] = costTo;       }       while (toIndex < m && flights[toIndex].d == i) {         flight f = flights[toIndex];         if (!f.t) {           if (miniCostTo[f.f] > f.c) {             if (miniCostTo[f.f] != (1LL << 50)) costTo -= miniCostTo[f.f] - f.c;             miniCostTo[f.f] = f.c;           }           if (!haveTo[f.f]) {             haveTo[f.f] = true;             costTo += f.c;             toCounter++;           }         }         toIndex++;       }     }     vector<long long> miniCostFrom(n + 1, (1LL << 50));     vector<long long> totalFrom(1000001, (1LL << 50));     vector<bool> haveFrom(n + 1);     int fromCounter = 0;     long long costFrom = 0;     int fromIndex = m - 1;     for (int i = 1000000; i >= 0; i--) {       if (fromCounter == n) {         totalFrom[i] = costFrom;       }       while (fromIndex >= 0 && flights[fromIndex].d == i) {         flight f = flights[fromIndex];         if (!f.f) {           if (miniCostFrom[f.t] > f.c) {             if (miniCostFrom[f.t] != (1LL << 50))               costFrom -= miniCostFrom[f.t] - f.c;             miniCostFrom[f.t] = f.c;           }           if (!haveFrom[f.t]) {             haveFrom[f.t] = true;             costFrom += f.c;             fromCounter++;           }         }         fromIndex--;       }     }     long long cheapest = (1LL << 50);     for (int i = 0; i + k - 1 <= 1000000; i++) {       cheapest = min(cheapest, totalTo[i] + totalFrom[i + k - 1]);     }     if (cheapest == (1LL << 50))       printf( -1 n );     else       printf( %I64d n , cheapest);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class classcomp {    public:     bool operator()(const int &l, const int &r) const { return l < r; }   };   long long mod = 1000000007;   void matrixmul(int p, int q, int r, long long *a, long long *b, long long *c) {     int i, j, k;     for (i = 0; i < p; i++) {       for (j = 0; j < r; j++) {         c[i * r + j] = 0;         for (k = 0; k < q; k++)           c[i * r + j] = (c[i * r + j] + a[i * q + k] * b[k * r + j]) % mod;       }     }   }   void exp(int q, long long *a, long long *c, long long n) {     int i, j;     if (n == 0) {       for (i = 0; i < q; i++) {         for (j = 0; j < q; j++) c[i * q + j] = 0;         c[i * q + i] = 1;       }       return;     }     long long x[q * q];     exp(q, a, x, n / 2);     matrixmul(q, q, q, x, x, c);     if (n % 2 == 1) {       memcpy(x, c, sizeof(x));       matrixmul(q, q, q, a, x, c);     }     return;   }   int main() {     long long n, m, k;     cin >> n >> m >> k;     long long a[m * m];     int i, j, l;     char s[10];     for (i = 0; i < m; i++)       for (j = 0; j < m; j++) a[i * m + j] = 1;     for (i = 0; i < k; i++) {       scanf( %s , s);       if ( a  <= s[0] && s[0] <=  z )         j = s[0] -  a ;       else         j = s[0] -  A  + 26;       if ( a  <= s[1] && s[1] <=  z )         l = s[1] -  a ;       else         l = s[1] -  A  + 26;       a[l * m + j] = 0;     }     long long ans[m * m];     exp(m, a, ans, n - 1);     long long ret = 0;     for (i = 0; i < m; i++)       for (j = 0; j < m; j++) {         ret = (ret + ans[i * m + j]) % mod;       }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[1010][10], rez[1010];   int main() {     int n, nr = 0, l = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int p = 0;       for (int j = 1; j <= 5; j++) scanf( %d , &v[i][j]);     }     if (n > 200) {       printf( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       int p = 0;       for (int j = 1; j <= n; j++)         if (i != j) {           for (int k = 1; k <= n; k++)             if (j != k && i != k) {               int c = 0;               for (int m = 1; m <= 5; m++)                 c += (v[j][m] - v[i][m]) * (v[k][m] - v[i][m]);               if (c > 0) {                 p = 1;                 break;               }             }           if (p == 1) break;         }       if (p == 0) rez[++l] = i;     }     printf( %d n , l);     for (int i = 1; i <= l; i++) printf( %d n , rez[i]);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e5 + 1;   int n, m, l = 1;   long long a;   char s[maxn];   int main() {     scanf( %d%d%s , &n, &m, s + 1);     for (int i = 1; i <= n; i++)       if (s[i] != s[i - 1]) a += n * (m - 1);     for (int i = 2; i <= n; i++)       if (l == 1 && s[i] != s[i - 1] || l > 1 && s[i] == s[i - 2])         ++l;       else if (a -= 1ll * l * (l - 1) >> 1)         l = 1 + (s[i] != s[i - 1]);     printf( %lld n , a -= 1ll * l * (l - 1) >> 1);     return 0;   }