malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e4 + 9;   long long a[maxn];   long long n;   void solve() {     cin >> n;     long long sum = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % n != 0) {       cout <<  -1 n ;       return;     }     sum /= n;     long long j = -1;     for (long long i = n - 1; i >= 1; i--) {       if (a[i] >= i + 1) {         j = i;         break;       }     }     vector<pair<pair<long long, long long>, long long> > ans;     if (j != -1) {       ans.emplace_back(make_pair(j, 0), 1);       a[j] -= j + 1;       a[0] += j + 1;       for (long long e = j; e >= 1; e--) {         if (a[e] % (e + 1) != 0) {           long long x = (e + 1) - a[e] % (e + 1);           ans.emplace_back(make_pair(0, e), x);           a[0] -= x;           a[e] += x;         }         ans.emplace_back(make_pair(e, 0), a[e] / (e + 1));         a[0] += a[e];         a[e] = 0;       }     } else {       j = 0;     }     vector<pair<long long, long long> > kek;     for (long long e = j + 1; e < n; e++) {       kek.emplace_back((e + 1) - a[e], e);     }     sort(kek.begin(), kek.end());     for (auto x : kek) {       if (a[0] >= x.first) {         ans.emplace_back(make_pair(0, x.second), x.first);         ans.emplace_back(make_pair(x.second, 0), 1);         a[0] += a[x.second];         a[x.second] = 0;       } else {         cout <<  -1 n ;         return;       }     }     for (long long i = 1; i < n; i++) {       ans.emplace_back(make_pair(0, i), sum);     }     if ((long long)ans.size() > 3 * n) {       cout <<  -1 n ;       return;     }     cout << ans.size() <<   n ;     for (auto x : ans)       cout << x.first.first + 1 <<     << x.first.second + 1 <<     << x.second            <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int k[n][n];     for (int j = 0; j < n; j++)       for (int i = 0; i < n; i++) k[i][j] = (i)*n + j + 1;     for (int i = 0; i < n; i += 2) reverse(k[i], k[i] + n);     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < n; i++) cout << k[i][j] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     ;     long long t = 1;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n];       for (long long i = 0; i < n; i++) cin >> a[i];       multiset<long long> s;       for (long long i = 0; i < n; i++) cin >> b[i], s.insert(b[i]);       vector<long long> c(n);       for (long long i = 0; i < n; i++) {         multiset<long long>::iterator it = s.begin();         long long ans = (a[i] + *it) % n, num = *it;         it = s.lower_bound(n - a[i]);         if (it != s.end() && (a[i] + *it) % n < ans) {           ans = (a[i] + *it) % n;           num = *it;         }         c[i] = ans;         s.erase(s.find(num));       }       for (long long i = 0; i < n; i++) cout << c[i] <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int ans = 9999;   string s, t;   int main() {     cin >> s >> t;     for (int i = 0; i < t.size(); i++) s =  .  + s +  . ;     for (int i = 0; i + t.size() - 1 < s.size(); i++) {       int temp = 0;       for (int j = 0; j < t.size(); j++) temp += (s[i + j] != t[j]);       if (ans > temp) ans = temp;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[200005];   vector<long long int> g[200005];   vector<long long int> c[200005];   multiset<long long int> st[200005];   long long int idx[200005], toAdd[200005], ans[200005];   void mergeTree(long long int id1, long long int id2) {     multiset<long long int>::iterator it;     long long int x;     for (it = st[id2].begin(); it != st[id2].end(); it++) {       x = *it + toAdd[id2] - toAdd[id1];       st[id1].insert(x);     }     return;   }   void dfs(long long int u) {     idx[u] = u;     long long int i, j, k, mx;     mx = st[idx[u]].size();     long long int id = idx[u];     for (i = 0; i < g[u].size(); i++) {       long long int v = g[u][i];       dfs(v);       if (st[idx[v]].size() > mx) {         mx = st[idx[v]].size();         id = idx[v];       }       toAdd[idx[v]] -= c[u][i];     }     idx[u] = id;     for (i = 0; i < g[u].size(); i++) {       long long int v = g[u][i];       if (id != idx[v]) mergeTree(id, idx[v]);       st[id].insert((a[v] - c[u][i]) - toAdd[id]);     }     multiset<long long int>::iterator it;     while (!st[id].empty()) {       it = st[id].begin();       if ((*it + toAdd[id]) < 0)         st[id].erase(it);       else         break;     }     ans[u] = (long long int)st[id].size();     return;   }   int main() {     long long int i, j, k, l, m, n;     cin >> n;     for (i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (i = 2; i <= n; i++) {       scanf( %lld %lld , &k, &l);       g[k].push_back(i);       c[k].push_back(l);     }     memset(toAdd, 0, sizeof(toAdd));     dfs(1);     for (i = 1; i <= n; i++) {       printf( %lld , ans[i]);       if (i < n)         printf(   );       else         printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mas[100500];   int main() {     int n, k, p = 1, t;     bool cur = false;     char q;     string s =   , s1;     cin >> n >> k;     mas[1] = 1;     for (int i = 2; i <= n; i++) {       if (p < k) {         if (!cur)           mas[i] = n - mas[i - 1] + 1;         else           mas[i] = mas[i - 2] + 1;         if (!cur)           cur = true;         else           cur = false;         p++;       } else {         if (!cur) {           mas[i] = mas[i - 1] + 1;         } else {           mas[i] = mas[i - 1] - 1;         }       }     }     for (int i = 1; i <= n; i++) {       s1 =   ;       while (mas[i] > 0) {         q = mas[i] % 10 +  0 ;         mas[i] /= 10;         s1 = q + s1;       }       s += s1 +    ;     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gr[1000005];   int was[1000005];   long long GetPow(long long val, int deg) {     long long ret = 1;     for (int i = 0; i < deg; ++i) {       ret *= val;     }     return ret;   }   long long arr[100000];   int main() {     long long sq4 = 2, sq2 = 2, val4 = 16, val2 = 4;     int least = 0;     for (int i = 4; i < 1000005; ++i) {       if (val2 == i) {         was[gr[sq2]]++;         ++sq2;         val2 = GetPow(sq2, 2);         while (was[least]) {           ++least;         }       }       gr[i] = least;       if (val4 == i) {         was[gr[sq4]]--;         if (!was[gr[sq4]] && gr[sq4] < least) {           least = gr[sq4];         }         ++sq4;         val4 = GetPow(sq4, 4);       }     }     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr, arr + n);     sq2 = 1;     sq4 = 1;     val2 = 1;     val4 = 1;     long long xr = 0, cur = 0;     memset(was, 0, sizeof was);     least = 0;     for (int i = 0; i < n; ++i) {       if (arr[i] == 1) {         continue;       }       while (val2 <= arr[i]) {         was[gr[sq2]]++;         ++sq2;         val2 = GetPow(sq2, 2);       }       while (val4 < arr[i]) {         was[gr[sq4]]--;         if (!was[gr[sq4]] && least > gr[sq4]) {           least = gr[sq4];         }         ++sq4;         val4 = GetPow(sq4, 4);       }       while (was[least]) {         ++least;       }       xr ^= least;     }     if (xr) {       puts( Furlo );     } else {       puts( Rublo );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   long long m, n;   void solve() {     cin >> n >> m;     bool visited[n + 5];     memset(visited, 0, sizeof(visited));     for (long long i = 0; i < m; i++) {       long long a, b, c;       cin >> a >> b >> c;       visited[b] = 1;     }     long long node = -1;     for (long long i = 1; i < n + 1; i++)       if (!visited[i]) {         node = i;         break;       }     for (long long i = 1; i < n + 1; i++) {       if (i == node) continue;       cout << node <<     << i <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long solve(long long n, string str1, string str2) {     long long t1 = 0, t2 = 0;     for (long long i = 0; i < n; i++) {       if (str1[i] != str2[i]) {         if (str1[i] ==  1 )           t1++;         else           t2++;       }     }     if (t1 != t2)       return -1;     else       return 2 * t1;   }   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       string str1, str2;       cin >> n;       cin >> str1 >> str2;       long long a1 = solve(n, str1, str2);       long long ind = -1;       for (long long i = 0; i < n; i++) {         if (str1[i] ==  1  && str2[i] ==  1 ) {           ind = i;           break;         }       }       long long a2 = -1;       string temp = str1;       if (ind != -1) {         for (long long i = 0; i < n; i++) {           if (str1[i] ==  1  && i != ind)             str1[i] =  0 ;           else if (str1[i] ==  0 )             str1[i] =  1 ;         }         a2 = solve(n, str1, str2);       }       long long a3 = -1;       str1 = temp;       long long ind2 = -1;       for (long long i = 0; i < n; i++) {         if (str1[i] ==  1  && str2[i] ==  0 ) {           ind2 = i;           break;         }       }       if (ind2 != -1) {         for (long long i = 0; i < n; i++) {           if (str1[i] ==  1  && i != ind2)             str1[i] =  0 ;           else if (str1[i] ==  0 )             str1[i] =  1 ;         }         a3 = solve(n, str1, str2);       }       if (a1 == -1 && a2 == -1 && a3 == -1) {         cout <<  -1  << endl;       } else {         if (a1 == -1 && a2 == -1)           cout << (a3 + 1) << endl;         else if (a1 == -1 && a3 == -1)           cout << (a2 + 1) << endl;         else if (a2 == -1 && a3 == -1)           cout << a1 << endl;         else if (a1 == -1)           cout << min(a2 + 1, a3 + 1) << endl;         else if (a2 == -1)           cout << min(a1, a3 + 1) << endl;         else if (a3 == -1)           cout << min(a1, a2 + 1) << endl;         else {           long long b = min(a2 + 1, a3 + 1);           long long ans = min(b, a1);           cout << ans << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double PI = acos(-1);   vector<int> adj[100005];   bool vis[100005];   map<pair<int, int>, long long> edge;   map<pair<int, int>, pair<long long, int>> weight;   long long mod = 1e9 + 7;   int n, k;   long long dfs(int node) {     vis[node] = 1;     long long ans = 1;     for (auto v : adj[node]) {       if (!vis[v]) {         long long a = dfs(v);         edge[{v, node}] = a;         edge[{node, v}] = a;         ans += a;       }     }     if (ans > 1) ans--;     return ans;   }   void clc() {     for (int i = 0; i <= n; i++) {       adj[i].clear();       vis[i] = 0;     }     edge.clear();     weight.clear();   }   void test_case() {     long long sum = 0, ans = 1e8, s;     cin >> n >> s;     pair<int, int> arr[n];     vector<long long> v1, v2;     v1.push_back(0), v2.push_back(0);     for (int i = 0; i < n - 1; i++) {       int x, y, c, w;       cin >> x >> y >> c >> w;       adj[x].push_back(y), adj[y].push_back(x);       arr[i] = {x, y};       weight[{x, y}] = {c, w}, weight[{y, x}] = {c, w};     }     dfs(1);     for (int i = 0; i < n; i++) {       long long x = edge[{arr[i].first, arr[i].second}],                 y = weight[{arr[i].first, arr[i].second}].first;       sum += x * y;       while (y) {         if (weight[{arr[i].first, arr[i].second}].second == 1)           v1.push_back(x * y - x * (y / 2));         else           v2.push_back(x * y - x * (y / 2));         y /= 2;       }     }     sort(v1.begin() + 1, v1.end());     sort(v2.begin() + 1, v2.end());     reverse(v1.begin() + 1, v1.end());     reverse(v2.begin() + 1, v2.end());     for (int i = 1; i < v1.size(); i++) v1[i] += v1[i - 1];     for (int i = 1; i < v2.size(); i++) v2[i] += v2[i - 1];     for (int i = 0; i < v2.size(); i++) {       long long pos =           lower_bound(v1.begin(), v1.end(), sum - s - v2[i]) - v1.begin();       if (pos == v1.size()) continue;       ans = min(ans, pos + 2 * i);     }     cout << ans <<   n ;     clc();   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       test_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long min(long long x, long long y) { return (x < y) ? x : y; }   long long max(long long x, long long y) { return (x > y) ? x : y; }   const int N = 1000009;   const int E = 1000000;   int x, y, n, m, e, i, u, w, mx, z, sum, l, r, best, cnt, g, j, k, t;   int a[N], flag[N], mark[N];   string s;   vector<int> pos, ans;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       flag[a[i]] = true;     }     for (int i = 1; i <= E / 2; i++)       if (!flag[i] && !flag[E - i + 1]) pos.push_back(i);     for (int i = 0; i < n; i++) {       if (mark[a[i]]) continue;       mark[a[i]] = true;       k = a[i];       if (!flag[E - k + 1])         ans.push_back(E - k + 1);       else {         w = pos[cnt];         cnt++;         ans.push_back(w);         ans.push_back(E - w + 1);         mark[E - k + 1] = true;       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int ma = -1, mi = 1000000000000000;   inline long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   inline long long int lcm(long long int a, long long int b, long long int MOD) {     return a / gcd(a, b) * b % MOD;   }   long long int power(long long int x, unsigned int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k, a[100009] = {0}, b[100009] = {0}, c = 0, d = 0;     string n, m;     cin >> n >> m;     if (n ==  monday ) {       if (m ==  monday  || m ==  wednesday  || m ==  thursday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  tuesday ) {       if (m ==  tuesday  || m ==  friday  || m ==  thursday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  wednesday ) {       if (m ==  friday  || m ==  wednesday  || m ==  saturday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  thursday ) {       if (m ==  saturday  || m ==  sunday  || m ==  thursday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  friday ) {       if (m ==  friday  || m ==  sunday  || m ==  monday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  saturday ) {       if (m ==  saturday  || m ==  monday  || m ==  tuesday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  sunday ) {       if (m ==  sunday  || m ==  wednesday  || m ==  tuesday ) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   void rr(vector<vector<long long>> &m, long long r, long long nr, long long nc) {     long long t = m[r - 1][nc - 1];     for (long long i = nc - 2; i >= 0; i--) m[r - 1][i + 1] = m[r - 1][i];     m[r - 1][0] = t;     return;   }   void rc(vector<vector<long long>> &m, long long c, long long nr, long long nc) {     long long t = m[nr - 1][c - 1];     for (long long i = nr - 2; i >= 0; i--) m[i + 1][c - 1] = m[i][c - 1];     m[0][c - 1] = t;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, q, t;     cin >> n >> m >> q;     vector<vector<long long>> mat(n, vector<long long>(m, 0));     vector<vector<long long>> op;     for (long long i = 0; i < q; i++) {       cin >> t;       if (t == 1 || t == 2) {         long long roc;         cin >> roc;         op.push_back({t, roc});       } else {         long long r, c, x;         cin >> r >> c >> x;         op.push_back({t, r, c, x});       }     }     bool f3 = false;     for (long long i = op.size() - 1; i >= 0; i--) {       if (!f3) {         if (op[i][0] == 3) {           f3 = true;           mat[op[i][1] - 1][op[i][2] - 1] = op[i][3];         }       } else {         if (op[i][0] == 1) {           rr(mat, op[i][1], n, m);         } else if (op[i][0] == 2) {           rc(mat, op[i][1], n, m);         } else {           mat[op[i][1] - 1][op[i][2] - 1] = op[i][3];         }       }     }     for (auto i : mat) {       for (auto j : i) cout << j <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10004;   long long a[N], b[N], c, sa = 0, mb = 0, M;   int n;   bool ok1(long long x) {     long long s = 0;     for (int i = 1; i <= n; i++) {       if (a[i] > 0 && x / b[i] > c / a[i]) return 0;       s += a[i] * x / b[i] + 1;       if (s >= c) return 0;     }     return 1;   }   bool ok2(long long x) {     long long s = 0;     for (int i = 1; i <= n; i++) {       if (a[i] > 0 && x / b[i] > c / a[i]) return 1;       s += a[i] * x / b[i] + 1;       if (s > c) return 1;     }     return 0;   }   int main() {     scanf( %d %lld , &n, &c);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &a[i], &b[i]);       sa += a[i];       mb = max(mb, b[i]);     }     long long u, v;     M = c * mb;     if (sa == 0) return puts(n == c ?  -1  :  0 ), 0;     long long l = 0, r = M;     while (l < r) {       long long mid = (l + r + 1) / 2;       if (ok1(mid))         l = mid;       else         r = mid - 1;     }     u = l;     l = 0, r = M;     while (l < r) {       long long mid = (l + r) / 2;       if (ok2(mid))         r = mid;       else         l = mid + 1;     }     v = r;     printf( %lld n , max(v - u - 1, 0ll));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   long long ara[N];   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       long long x;       cin >> x;       ++ara[x];     }     vector<long long> v;     for (long long i = 1; i <= 100; ++i) {       if (ara[i] != 0) v.push_back(ara[i]);     }     long long mx = 0;     for (long long i = 1; i <= 100; ++i) {       long long s = 0;       for (long long j = 0; j < v.size(); ++j) {         s += v[j] / i;       }       if (s >= n) mx = max(mx, i);     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   int main() {     long long a[maxn], b[maxn];     int n, m;     while (cin >> n >> m) {       for (int i = 1; i <= n; ++i) {         cin >> a[i];       }       for (int i = 1; i <= m; ++i) {         cin >> b[i];       }       sort(a + 1, a + n + 1);       sort(b + 1, b + m + 1);       long long ans1 = a[1] * b[1], ans2 = a[n] * b[m], ans3 = a[1] * b[m],                 ans4 = a[n] * b[1];       long long maxx = max(ans1, max(ans2, max(ans3, ans4)));       if (maxx == ans1)         cout << max(a[2] * b[1], max(ans2, max(a[2] * b[m], ans4))) << endl;       else if (maxx == ans2)         cout << max(a[n - 1] * b[m], max(ans1, max(ans3, a[n - 1] * b[1])))              << endl;       else if (maxx == ans3)         cout << max(a[2] * b[1], max(ans2, max(a[2] * b[m], ans4))) << endl;       else         cout << max(ans1, max(a[n - 1] * b[m], max(ans3, a[n - 1] * b[1])))              << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = true;   long long n, m, a, b;   int main(int argc, char* argv[]) {     cin >> n >> m >> a >> b;     long long r = n % m;     cout << min(r * b, (m - r) * a);     while (clock() <= 300) {     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct seq {     int num;     char color;   };   int main() {     string s;     cin >> s;     int i = 1, N = 0, j;     seq temp;     vector<seq> arr;     temp.num = 1;     temp.color = s[0];     while (s[i] !=   0 ) {       if (s[i] == temp.color) {         temp.num++;       } else {         arr.push_back(temp);         temp.num = 1;         temp.color = s[i];         N++;       }       i++;     }     arr.push_back(temp);     N++;     if (N % 2 == 0) {       cout << 0 << endl;       return 0;     }     i = 0;     j = N - 1;     while (i < j) {       if (arr[i].color == arr[j].color) {         if (arr[i].num + arr[j].num >= 3) {           i++;           j--;         } else {           break;         }       } else {         break;       }     }     if (i == j) {       if (arr[i].num + 1 >= 3) {         cout << arr[i].num + 1 << endl;       } else {         cout << 0 << endl;       }     } else {       cout << 0 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     char tramp;     cin >> tramp;     string rank =  6789TJQKA ;     char c1_s, c1_r;     cin >> c1_r >> c1_s;     char c2_s, c2_r;     cin >> c2_r >> c2_s;     if (c1_s == tramp && c2_s != tramp) {       cout <<  YES  << endl;       return 0;     }     if (c1_s == c2_s && rank.find(c1_r) > rank.find(c2_r)) {       cout <<  YES  << endl;       return 0;     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int true_mod(int A, int N) {     A %= N;     if (A < 0) A += N;     return A;   }   const long long MOD = 1000LL * 1000LL * 1000LL + 7LL;   const int MX = 109;   struct matrix {     long long A[MX][MX];   };   int x;   void output(const matrix& A) {     for (int i = 0; i < x; i++) {       for (int j = 0; j < x; j++) cout << A.A[i][j] <<    ;       cout << endl;     }   }   matrix operator*(const matrix& A, const matrix& B) {     matrix R;     for (int i = 0; i < x; i++) {       for (int k = 0; k < x; k++) {         long long t = 0;         for (int j = 0; j < x; j++) t += A.A[i][j] * B.A[j][k] % MOD;         R.A[i][k] = t % MOD;       }     }     return R;   }   matrix unity() {     matrix R;     for (int i = 0; i < x; i++)       for (int j = 0; j < x; j++) R.A[i][j] = (i == j ? 1 : 0);     return R;   }   matrix power(const matrix& A, int N) {     matrix R = unity(), A_pow = A;     while (N != 0) {       if (N % 2 == 1) R = R * A_pow;       A_pow = A_pow * A_pow;       N /= 2;     }     return R;   }   int n, b, k;   const long long B = 10;   int cnt_D[MX] = {0};   matrix get_A() {     matrix R;     for (int i = 0; i < x; i++) {       for (int j = 0; j < x; j++) {         int smth = true_mod(j - 10 * i, x);         R.A[i][j] = cnt_D[smth];       }     }     return R;   }   int main() {     cin >> n >> b >> k >> x;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       cnt_D[a % x]++;     }     matrix A = get_A();     matrix A_pow = power(A, b);     cout << A_pow.A[0][k];     return 0;   }