malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long int inf = INT_MAX;   const long long int mod = 1000000007;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a / gcd(a, b)) * b;   }   int factorial(long long int n) {     return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);   }   long long int sm(long long int n) {     long long int ans = n * (n + 1) / 2;     return ans;   }   bool isprime(long long int x) {     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   bool perfectSquare(long double x) {     long double sr = sqrt(x);     return ((sr - floor(sr)) == 0);   }   void solve() {     int64_t w, h, i;     cin >> w >> h;     int64_t ans1 = 0, ans2 = 0;     for (i = 2; i <= w; i += 2) ans1 += (w - i + 1);     for (i = 2; i <= h; i += 2) ans2 += (h - i + 1);     cout << ans1 * ans2 <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int test_case = 1;     while (test_case--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long b = 0, s = 0, c = 0;   long long nb, ns, nc;   long long pb, ps, pc;   long long r;   bool isPoss(long long m) {     long long rnb = b * m - nb < 0 ? 0 : b * m - nb;     long long rns = s * m - ns < 0 ? 0 : s * m - ns;     long long rnc = c * m - nc < 0 ? 0 : c * m - nc;     long long rs = rnb * pb + rns * ps + rnc * pc;     if (rs <= r && rs >= 0) {       return true;     }     return false;   }   int main() {     string st;     cin >> st;     long long n = st.size();     for (long long i = 0; i < n; i++) {       if (st[i] ==  B ) {         b++;       }       if (st[i] ==  S ) {         s++;       }       if (st[i] ==  C ) {         c++;       }     }     cin >> nb >> ns >> nc;     cin >> pb >> ps >> pc;     cin >> r;     long long l = 0;     long long h = 1e16;     long long m = (h + l) / 2;     int flag = 0;     while (l <= h) {       m = (h + l) / 2;       if (isPoss(m)) {         if (!isPoss(m + 1)) {           flag = 1;           cout << m << endl;           break;         } else {           l = m + 1;         }       } else {         h = m - 1;       }     }     if (flag == 0) cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 23, M = 2e4 + 1e3 + 7, P = 998244353;   int n;   int cnt[N][26], pw[M];   char s[M];   int f[1 << N];   int mn[26];   int main() {     pw[0] = 1;     for (int i = 1; i < M; i++) pw[i] = pw[i - 1] * 2 % P;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , s);       int m = strlen(s);       for (int j = 0; j < m; j++) cnt[i][s[j] -  a ]++;     }     for (int S = 1; S < (1 << n); S++) {       for (int j = 0; j < 26; j++) mn[j] = 1e9;       int flag = P - 1;       for (int i = 0; i < n; i++)         if (S & (1 << i)) {           flag = P - flag;           for (int j = 0; j < 26; j++) mn[j] = min(mn[j], cnt[i][j]);         }       f[S] = flag;       for (int i = 0; i < 26; i++) f[S] = 1ll * f[S] * (mn[i] + 1) % P;     }     for (int i = 0; i < n; i++)       for (int S = 0; S < (1 << n); S++)         if (S & (1 << i)) f[S] = (f[S] + f[S ^ (1 << i)]) % P;     long long ans = 0;     for (int S = 0; S < (1 << n); S++) {       int b = 0, a = 0;       for (int i = 0; i < n; i++)         if (S & (1 << i)) b++, a += i + 1;       ans ^= 1ll * a * b * f[S];     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   string S;   int ans;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 1; i <= 3; i++) {       getline(cin, S);       ans = 0;       for (int j = 0; j < S.length(); j++) {         if (S[j] ==  a  || S[j] ==  i  || S[j] ==  u  || S[j] ==  e  ||             S[j] ==  o )           ans++;       }       if (ans == 5 && i == 2) {         cout <<  NO n ;         return 0;       } else if (ans == 7 && i % 2 == 1) {         cout <<  NO n ;         return 0;       } else if (ans != 5 && ans != 7) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[200000];   long long int left1[200000][2];   long long int right1[200000][2];   long long int ans[200000];   int main() {     long long int n;     cin >> n;     left1[1][0] = 0;     right1[n][0] = 0;     for (long long int i = 1; i <= n; i++) cin >> a[i];     left1[1][1] = a[1];     right1[n][1] = a[n];     for (long long int i = 2; i <= n; i++) {       left1[i][1] = max(a[i], left1[i - 1][1] + 1);       left1[i][0] = left1[i - 1][0] + (left1[i][1] - a[i]);     }     for (long long int i = n - 1; i >= 0; i--) {       right1[i][1] = max(a[i], right1[i + 1][1] + 1);       right1[i][0] = right1[i + 1][0] + right1[i][1] - a[i];     }     for (long long int i = 1; i <= n; i++)       ans[i] = left1[i - 1][0] + right1[i + 1][0] +                max(left1[i][1], right1[i][1]) - a[i];     long long int j = 1e18;     for (long long int i = 1; i <= n; i++) {       j = min(ans[i], j);     }     cout << j;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> poz[100];   int main() {     string s;     cin >> s;     for (int i(0); i <= 26; i++) poz[i].push_back(-1);     for (int i(0); i < s.size(); i++) poz[s[i] -  a ].push_back(i);     for (int i(0); i <= 26; i++) poz[i].push_back(s.size());     int kmin = s.size();     for (int i(0); i < 26; i++) {       int dmax = 0;       for (int j(0); j < poz[i].size() - 1; j++)         dmax = max(dmax, poz[i][j + 1] - poz[i][j]);       kmin = min(kmin, dmax);     }     cout << kmin;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   using vll = vector<ll>;   using vvll = vector<vll>;   using pll = pair<ll, ll>;   using vpll = vector<pll>;   using vvpll = vector<vpll>;   bool sorted(int arr[], int n) {     bool f1 = 1, f2 = 1;     for (int i = 0; i < n - 1; i++) {       if (arr[i + 1] >= arr[i]) {         f1 = 0;         break;       }     }     for (int i = 0; i < n - 1; i++) {       if (arr[i + 1] <= arr[i]) {         f2 = 0;         break;       }     }     return f1 || f2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     ;     cout.setf(ios::fixed);     cout.precision(32);     ;     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       int index = -1;       for (int i = 0; i < n - 1; i++) {         if (abs(arr[i] - arr[i + 1]) != 1) {           index = i;           break;         }       }       if (index != -1) {         reverse(arr, arr + index + 1);         reverse(arr + index + 1, arr + n);       }       if (sorted(arr, n))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     long long int n;     cin >> n;     getline(cin, s);     getline(cin, s);     long long int l = s.length();     long long int a = 0, ii = 0, f = 0;     for (long long int i = 0; i < l; i++) {       if (s[i] ==  A ) {         a++;       } else {         if (s[i] ==  I ) {           ii++;         } else {           f++;         }       }     }     if (ii == 0) {       cout << a << endl;     } else {       if (ii == 1) {         cout << 1 << endl;       } else {         cout << 0 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long mul(long long a, long long b) { return (a * b) % MOD; }   long long bin_pow(long long a, long long p) {     if (p == 0) return 1;     long long ans = bin_pow(mul(a, a), p / 2);     if (p % 2) ans = mul(ans, a);     return ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, a;     cin >> n >> m >> a;     vector<long long> b(m + 1);     b[0] = 0;     for (long long i = 0; i < m; i++) cin >> b[i + 1];     long long ans = 1;     for (long long i = 0; i < (long long)(b).size() - 1; i++) {       long long seg = b[i + 1] - b[i];       long long p = bin_pow(a, seg);       long long p1 = (p * (p - 1) / 2) % MOD;       long long delta = (p1 + p) % MOD;       ans = mul(ans, delta);     }     long long ost = n - b.back() * 2;     ans = mul(ans, bin_pow(a, ost));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x[101] = {0}, i, a, m = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       x[a]++;     }     for (i = 0; i <= 100; i++) {       if (x[i] > m) m = x[i];     }     cout << m;   }
#include <bits/stdc++.h>   using namespace std;   int a[100 + 10];   int main() {     int n;     while (~scanf( %d , &n)) {       int p1, p2, p3, t1, t2;       scanf( %d%d%d%d%d , &p1, &p2, &p3, &t1, &t2);       int ans = 0;       int temp, len = 0;       for (int i = 1; i <= n; i++) {         int x, y;         scanf( %d%d , &x, &y);         ans += (y - x) * p1;         if (i > 1) {           a[len++] = x - temp;         }         temp = y;       }       for (int i = 0; i < len; i++) {         if (a[i] < t1) {           ans += a[i] * p1;         } else if (a[i] < t1 + t2) {           ans += t1 * p1 + (a[i] - t1) * p2;         } else {           ans += t1 * p1 + t2 * p2 + (a[i] - t1 - t2) * p3;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int MAX_L = 2005;   const int INF_INT = 0x3f3f3f3f;   const long long INF_LL = 0x7fffffff;   const int MOD = 1e9 + 7;   const double eps = 1e-9;   const double pi = acos(-1);   using namespace std;   int n;   int a[26], b[26][26];   int main() {     while (cin >> n) {       string s;       memset(a, 0, sizeof(a));       memset(b, 0, sizeof(b));       for (int i = 1; i <= n; i++) {         cin >> s;         set<char> st;         for (int i = 0; i < s.size(); i++) st.insert(s[i]);         if (st.size() > 2) continue;         if (st.size() == 1)           a[s[0] -  a ] += s.size();         else if (st.size() == 2) {           char tmp[2];           int t = 0;           for (auto &i : st) {             tmp[t++] = i;           }           b[tmp[0] -  a ][tmp[1] -  a ] += s.size();           b[tmp[1] -  a ][tmp[0] -  a ] += s.size();         }       }       int ans = 0;       for (int i = 0; i < 26; i++) {         for (int j = 0; j < 26; j++) {           if (i == j) continue;           ans = max(ans, a[i] + a[j] + b[i][j]);         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     srand(time(0));     ios_base::sync_with_stdio(0);     task();     return 0;   }   const int INF = 0x3f3f3f3f;   const int N = 1e6 + 10;   const int M = 1e5 + 10;   struct SufAutomaton {     struct State {       int len;       int link;       int cnt;       map<char, int> next;       State() : len(0), link(-1), cnt(0){};     };     State st[2 * N];     int sz = 1;     int last = 0;     void push(char ch) {       int cur = sz++;       st[cur].len = st[last].len + 1;       st[cur].cnt = 1;       int p = last;       last = cur;       for (; p != -1 && !st[p].next.count(ch); p = st[p].link)         st[p].next[ch] = cur;       if (p == -1) {         st[cur].link = 0;         return;       }       int q = st[p].next[ch];       if (st[p].len + 1 == st[q].len) {         st[cur].link = q;         return;       }       int clone = sz++;       st[clone].len = st[p].len + 1;       st[clone].next = st[q].next;       st[clone].link = st[q].link;       st[q].link = st[cur].link = clone;       for (; p != -1 && st[p].next.count(ch) && st[p].next[ch] == q;            p = st[p].link)         st[p].next[ch] = clone;     }     void calc() {       vector<pair<int, int> > v;       for (int i = 0; i < sz; ++i) v.push_back(pair<int, int>{st[i].len, i});       sort((v.begin()), (v.end()));       reverse((v.begin()), (v.end()));       for (pair<int, int> p : v) st[st[p.second].link].cnt += st[p.second].cnt;     }     int prefix_function(const string&& s) {       int n = s.length();       vector<int> p(n, 0);       for (int i = 1; i < n; ++i) {         int j = p[i - 1];         while (j && s[i] != s[j]) j = p[j - 1];         if (s[i] == s[j]) p[i] = j + 1;         if (p[i] == n / 2) return i;       }     }     int solve(string& s) {       int n = s.length();       int yet = prefix_function(s + s) - n;       int len = 0;       int ans = 0;       int cur = 0;       for (int i = 0; i < n; ++i) {         while (cur != -1 && st[cur].next.count(s[i]) == 0) {           cur = st[cur].link;           len = cur == -1 ? 0 : st[cur].len;         }         if (cur == -1) {           cur = 0;           len = 0;         } else {           ++len;           cur = st[cur].next[s[i]];         }       }       if (len == n) ans += st[cur].cnt;       for (int i = 0; i < yet; ++i) {         if (len == n) {           --len;           if (len <= st[st[cur].link].len) cur = st[cur].link;         }         while (cur != -1 && st[cur].next.count(s[i]) == 0) {           cur = st[cur].link;           len = cur == -1 ? 0 : st[cur].len;         }         if (cur == -1) {           cur = 0;           len = 0;         } else {           ++len;           cur = st[cur].next[s[i]];         }         if (len == n) {           ans += st[cur].cnt;         }       }       return ans;     }   };   string s;   SufAutomaton sa;   void task() {     cin >> s;     for (int i = 0; i < s.length(); ++i) sa.push(s[i]);     sa.calc();     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s;       cout << sa.solve(s) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int a, v, c, next;     node() {}     node(int a, int v, int c, int next) : a(a), v(v), c(c), next(next) {}   } edge[200010];   struct pp {     int v, d1, d2;   };   queue<int> q;   int n, m, tot;   int dis[100010], d[100010], pre[100010], ans[100010], head[100010];   int vis[100010];   void add(int x, int y, int z) {     edge[++tot] = node(x, y, z, head[x]);     head[x] = tot;   }   void SPFA() {     memset(d, 0, sizeof d);     memset(ans, 0, sizeof ans);     memset(vis, 0, sizeof vis);     for (int i = 1; i <= 100010; i++) dis[i] = 111111;     dis[1] = 0;     vis[1] = 1;     q.push(1);     while (!q.empty()) {       int v = q.front();       q.pop();       vis[v] = 0;       for (int i = head[v]; i != -1; i = edge[i].next)         if (dis[v] + 1 < dis[edge[i].v] ||             (dis[v] + 1 == dis[edge[i].v] && d[v] + edge[i].c > d[edge[i].v])) {           dis[edge[i].v] = dis[v] + 1;           d[edge[i].v] = d[v] + edge[i].c;           pre[edge[i].v] = i;           if (!vis[edge[i].v]) {             q.push(edge[i].v);             vis[edge[i].v] = 1;           }         }     }     int xx = n;     while (xx != 1) {       ans[(pre[xx] + 1) / 2] = 1;       xx = edge[pre[xx]].a;     }   }   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       tot = 0;       int sum = 0, x, y, z;       memset(head, -1, sizeof head);       for (int i = 1; i <= m; i++) {         scanf( %d %d %d , &x, &y, &z);         add(y, x, z);         add(x, y, z);         if (z) sum++;       }       SPFA();       printf( %d n , sum + dis[n] - 2 * d[n]);       for (int i = 2; i <= 2 * m; i += 2)         if (ans[i / 2] ^ edge[i].c)           printf( %d %d %d n , edge[i].a, edge[i].v, edge[i].c ^ 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long pow1(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long ab = pow1(a, b / 2) % 1000000007;     if (b % 2 == 0)       return (ab * ab) % 1000000007;     else       return ((ab * ab) % 1000000007 * a) % 1000000007;   }   int main() {     string s;     long long k;     cin >> s >> k;     long long ans = 0;     for (int i = (int)(s.size()) - 1; i >= 0; i--) {       if (s[i] ==  0  || s[i] ==  5 ) {         ans = (ans + pow1(2, i)) % 1000000007;       }     }     long long ha = pow1(2, (int)(s.size()) * k) - 1;     ha = (ha * pow1(pow1(2, (int)(s.size())) - 1, 1000000007 - 2)) % 1000000007;     ans = (ans * ha) % 1000000007;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     vector<long long> arr(n, 0);     vector<long long> pref(n, 0);     vector<long long> suff(n, 0);     map<long long, long long> pre;     map<long long, long long> suf;     for (long long i = 0; i < n; i++) cin >> arr[i];     pref[0] = arr[0];     suff[n - 1] = arr[n - 1];     for (long long i = 1; i < n; i++) pref[i] = pref[i - 1] + arr[i];     for (long long i = n - 2; i >= 0; i--) suff[i] = suff[i + 1] + arr[i];     if (pref[n - 1] % 2 != 0) {       cout <<  NO n ;       return 0;     }     for (long long i = n - 1; i >= 0; i--) suf[arr[i]]++;     long long fl = 0;     for (long long i = 0; i < n - 1; i++) {       long long a = pref[i];       if (suf[arr[i]] == 1)         suf.erase(suf.find(arr[i]));       else         suf[arr[i]]--;       pre[arr[i]]++;       long long b = suff[i + 1];       if (1) {         long long temp = suff[i + 1] + arr[i];         long long diff = temp - pref[n - 1] / 2;         if (suf.find(diff) != suf.end()) {           fl = 1;           break;         }       }       if (a == b) {         fl = 1;         break;       }       if (1) {         long long temp = pref[i] + arr[i + 1];         long long diff = temp - pref[n - 1] / 2;         if (pre.find(diff) != pre.end()) {           fl = 1;           break;         }       }     }     if (!fl)       cout <<  NO n ;     else       cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   namespace FASTIO {   char buf[1 << 21];   char *p1, *p2;   template <typename T>   inline void wt(T x, char c =   n ) {     if (x < 0) {       x = -x;       putchar( - );     }     static char sta[sizeof(T) * 8];     T top = 0;     do {       sta[top++] = x % 10;       x /= 10;     } while (x);     while (top) putchar(sta[--top] +  0 );     putchar(c);   }   template <typename T>   inline T rd() {     T sum = 0, fl = 1;     char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     for (; ch <  0  || ch >  9 ;          ch = (p1 == p2 &&                        (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                    ? EOF                    : *p1++))       if (ch ==  - )         fl = -1;       else if (ch == EOF)         exit(0);     for (;  0  <= ch && ch <=  9 ;          ch = (p1 == p2 &&                        (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                    ? EOF                    : *p1++))       sum = sum * 10 + ch -  0 ;     return sum * fl;   }   }  // namespace FASTIO   using namespace FASTIO;   const int N = 3e5 + 2, logN = 19;   int dep[N], anc[N][logN];   inline int lca(int x, int y) {     if (dep[x] < dep[y]) std::swap(x, y);     {       int dt = dep[x] - dep[y];       if (dt)         for (int i = (31 - __builtin_clz(dt)); i >= 0; i--)           if (dt & 1 << i) x = anc[x][i];     }     if (x == y) return x;     for (int i = (31 - __builtin_clz(dep[x])); i >= 0; i--)       if (anc[x][i] != anc[y][i]) {         x = anc[x][i];         y = anc[y][i];       }     return anc[x][0];   }   inline int dist(const int x, const int y) {     return dep[x] + dep[y] - dep[lca(x, y)] * 2;   }   std::vector<int> s1, s2;   int main() {     const int n = rd<int>() + 1;     s1.reserve(n + 1);     s2.reserve(n + 1);     s1.push_back(1);     dep[1] = 1;     for (int i = 2, maxd = 0, d1, d2; i <= n; i++) {       dep[i] = dep[anc[i][0] = rd<int>()] + 1;       for (int j = 1; 1 << j <= dep[i]; j++)         anc[i][j] = anc[anc[i][j - 1]][j - 1];       d1 = s1.empty() ? 0 : dist(i, s1.back());       d2 = s2.empty() ? 0 : dist(i, s2.back());       if (std::max(d1, d2) > maxd) {         maxd = std::max(d1, d2);         if (maxd != d1) {           s1.swap(s2);           std::swap(d1, d2);         }         for (const int &x : s2)           if (dist(x, i) == d1) s1.push_back(x);         s2.clear();       }       if (std::max(d1, d2) == maxd) (maxd == d1 ? s2 : s1).push_back(i);       wt(s1.size() + s2.size());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   int n, pre[maxn], son[maxn], dep[maxn], Ans[maxn], cnt, lis[maxn];   vector<int> g[maxn];   int main() {     scanf( %d , &n);     dep[1] = 1;     for (int i = 1; i < n; i++) {       scanf( %d , &pre[i + 1]);       pre[i + 1]++;       g[pre[i + 1]].push_back(i + 1);       son[pre[i + 1]]++;       dep[i + 1] = dep[pre[i + 1]] + 1;     }     int p = 1;     for (int i = 2; i <= n; i++)       if (dep[i] > dep[p]) p = i;     int from = p;     cnt = 0;     int lim = n - dep[p];     for (int i = 1; i <= lim; i++) {       while (pre[p] && son[pre[p]] <= 1) p = pre[p];       if (!pre[p]) break;       Ans[++cnt] = p;       int f = pre[p];       pre[p] = 0;       while (pre[g[f].back()] != f) g[f].pop_back();       pre[p] = g[f].back();       g[pre[p]].push_back(p);       son[pre[p]]++;       son[f]--;     }     int lcnt = 0;     p = from;     lis[++lcnt] = p;     while (pre[p]) {       lis[++lcnt] = pre[p];       p = pre[p];     }     for (int i = lcnt; i >= 1; i--) printf( %d  , lis[i] - 1);     puts(  );     printf( %d n , cnt);     for (int i = cnt; i >= 1; i--) {       int x = Ans[i] - 1;       printf( %d  , x);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[110][110];   void work1() {     if (n % 3) {       puts( NO );       return;     }     int k = n / 3;     if (s[0][0] == s[k][0] || s[0][0] == s[k * 2][0] || s[k][0] == s[k * 2][0]) {       puts( NO );       return;     }     for (int h = 0; h < 3; h++) {       for (int i = 0; i < k; i++) {         for (int j = 0; j < m; j++) {           if (s[h * k][0] != s[h * k + i][j]) {             puts( NO );             return;           }         }       }     }     puts( YES );   }   void work2() {     if (m % 3) {       puts( NO );       return;     }     int k = m / 3;     if (s[0][0] == s[0][k] || s[0][0] == s[0][k * 2] || s[0][k] == s[0][k * 2]) {       puts( NO );       return;     }     for (int h = 0; h < 3; h++) {       for (int i = 0; i < k; i++) {         for (int j = 0; j < n; j++) {           if (s[0][h * k] != s[j][h * k + i]) {             puts( NO );             return;           }         }       }     }     puts( YES );   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     bool f = true;     for (int i = 1; i < m; i++) {       if (s[0][i] != s[0][i - 1]) {         f = false;         break;       }     }     if (f) {       work1();     } else {       work2();     }     return 0;   }