malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int a1[4] = {1, -1, 0, 0}, a2[4] = {0, 0, 1, -1};   struct ww {     int a, b;   } g[1610 * 1610], h[1610 * 1610];   int i, j, k, n, m, s, l, r;   int a[1610][1610], f[1610][1610], d[1610][1610], F[1610][1610],       ans[1610 * 1610];   inline void bfs(int x, int y) {     int i;     g[l = r = 1].a = x, g[1].b = y;     f[x][y] = 1;     for (; l <= r; l++) {       int X = g[l].a, Y = g[l].b;       for (i = 0; i <= 3; i++) {         int A = X + a1[i], B = Y + a2[i];         if (a[A][B] && !f[A][B]) {           f[A][B] = 1;           g[++r].a = A, g[r].b = B;         }       }     }   }   inline int cal(int x, int y) {     int l, r, i;     h[l = r = 1].a = x, h[1].b = y, d[x][y] = 0, F[x][y] = 1;     for (; l <= r; l++) {       int X = h[l].a, Y = h[l].b;       if (d[X][Y] == d[h[r].a][h[r].b] && l < r - 5) break;       for (i = 0; i <= 3; i++) {         int A = X + a1[i], B = Y + a2[i];         if (a[A][B] && !F[A][B]) {           F[A][B] = 1;           h[++r].a = A, h[r].b = B;           d[A][B] = d[X][Y] + 1;         }       }     }     int D = d[h[r].a][h[r].b];     if (D <= 10)       for (i = 1; i <= r; i++) F[h[i].a][h[i].b] = 0;     return D > 10;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++)         if (a[i][j] && !f[i][j]) {           bfs(i, j);           s = cal(i, j);           for (k = r; k > 1; k--) {             int A = g[k].a, B = g[k].b;             if (!F[A][B]) s += cal(A, B);           }           ans[++*ans] = s;         }     sort(ans + 1, ans + *ans + 1);     printf( %d n , *ans);     for (i = 1; i <= *ans; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 123, inf = 1e9 + 123, mod = 1e9 + 7;   const long long INF = 1e18;   int n, a[N];   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     reverse(a + 1, a + n + 1);     int mn = inf;     for (int i = 1; i <= n; i++) {       if (a[i] + 1 < mn) {         a[i]++;         mn = a[i];       } else {         if (a[i] < mn) {           mn = a[i];         } else if (a[i] - 1 < mn && a[i] > 1) {           mn = a[i] - 1;           a[i]--;         }       }     }     set<int> st;     for (int i = 1; i <= n; i++) {       st.insert(a[i]);     }     cout << st.size();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void rd(T &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     x *= f;   }   const int maxn = 1e5 + 5;   int n, m;   int ans[maxn];   struct node {     int x, op, id;     bool operator<(const node &b) const { return x == b.x ? id < b.id : x < b.x; }   } p[maxn];   struct segment_tree {     int op[maxn << 2], tag[maxn << 2];     void pushdown(int u) {       if (tag[u]) {         op[u << 1] = op[u << 1 | 1] = 1;         tag[u << 1] = tag[u << 1 | 1] = tag[u];         tag[u] = 0;       }       if (op[u] == -1) {         op[u << 1] *= -1;         op[u << 1 | 1] *= -1;         op[u] = 1;       }     }     void build(int u, int l, int r) {       op[u] = 1;       if (l == r) return (void)(op[u] = p[l].op);       int mid = l + r >> 1;       build(u << 1, l, mid);       build(u << 1 | 1, mid + 1, r);     }     void cover(int u, int l, int r, int ql, int qr, int v) {       if (ql <= l && r <= qr) return (void)(op[u] = 1, tag[u] = v);       int mid = l + r >> 1;       pushdown(u);       if (ql <= mid) cover(u << 1, l, mid, ql, qr, v);       if (qr > mid) cover(u << 1 | 1, mid + 1, r, ql, qr, v);     }     void change(int u, int l, int r, int ql, int qr) {       if (ql <= l && r <= qr) return (void)(op[u] *= -1);       int mid = l + r >> 1;       pushdown(u);       if (ql <= mid) change(u << 1, l, mid, ql, qr);       if (qr > mid) change(u << 1 | 1, mid + 1, r, ql, qr);     }     void query(int u, int l, int r) {       if (l == r) {         int res = tag[u] ? tag[u] * op[u] : op[u];         ans[p[l].id] = res * p[l].x;         return;       }       int mid = l + r >> 1;       pushdown(u);       query(u << 1, l, mid);       query(u << 1 | 1, mid + 1, r);     }   } seg;   int main() {     rd(n), rd(m);     for (int i = (1); i <= (n); ++i) {       int x;       rd(x);       p[i] = (node){abs(x), x > 0 ? 1 : -1, i};     }     sort(p + 1, p + n + 1);     seg.build(1, 1, n);     while (m--) {       char s[5];       int x;       scanf( %s , s);       rd(x);       if (s[0] ==  < ) {         if (x < 0) {           int pos = (lower_bound(p + 1, p + n + 1, (node){abs(x) + 1, 0, 0}) - p);           if (pos <= n) seg.cover(1, 1, n, pos, n, 1);         } else {           int pos = (lower_bound(p + 1, p + n + 1, (node){abs(x), 0, 0}) - p);           if (pos <= n) seg.cover(1, 1, n, pos, n, 1);           if (pos > 1) seg.change(1, 1, n, 1, pos - 1);         }       } else {         if (x > 0) {           int pos = (lower_bound(p + 1, p + n + 1, (node){abs(x) + 1, 0, 0}) - p);           if (pos <= n) seg.cover(1, 1, n, pos, n, -1);         } else {           int pos = (lower_bound(p + 1, p + n + 1, (node){abs(x), 0, 0}) - p);           if (pos <= n) seg.cover(1, 1, n, pos, n, -1);           if (pos > 1) seg.change(1, 1, n, 1, pos - 1);         }       }     }     seg.query(1, 1, n);     for (int i = (1); i <= (n); ++i) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pic[610][610];   int ABS(int x) {     if (x < 0) return -x;     return x;   }   int main(int argc, char const *argv[]) {     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int n, m, pix = 0, sum1 = 0, sum2 = 0;       scanf( %d%d , &n, &m);       for (int k = 0; k < n; k++)         for (int j = 0; j < m; j++) {           scanf( %d , &pic[k][j]);         }       int dif = 0;       for (int j = 0; j < m; j++)         dif = dif + ABS(pic[n / 2][j] - pic[n / 2 - 1][j]);       if (dif < 6000)         printf( NO n );       else         printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 50;   int n, m, a[N], b[N];   vector<int> G[N];   int in[N], out[N], tim, dep[N];   int mn[20][N], lg[N], p[N], k;   void dfs(int u, int f) {     dep[u] = dep[f] + 1;     in[u] = ++tim;     mn[0][p[u] = ++k] = u;     for (int v : G[u])       if (v != f) dfs(v, u), mn[0][++k] = u;     out[u] = tim;   }   int chk(int x, int y) { return dep[x] < dep[y] ? x : y; }   int LCA(int x, int y) {     x = p[x], y = p[y];     if (x > y) swap(x, y);     int z = lg[y - x + 1];     return chk(mn[z][x], mn[z][y - (1 << z) + 1]);   }   int D(int x, int y) { return dep[x] + dep[y] - 2 * dep[LCA(x, y)]; }   struct lll {     int x, y, o;     lll(int _x = 0, int _y = 0, int _o = 0) { x = _x, y = _y, o = _o; }     friend lll operator+(const lll &a, const lll &b) {       if (!a.o) return a;       if (!b.o) return b;       if (!a.x) return b;       if (!b.x) return a;       lll t = b;       int A = D(a.x, t.x), B = D(a.x, t.y), C = D(t.x, t.y);       if (A + B == C)         t = lll(t.x, t.y, 1);       else if (B + C == A)         t = lll(a.x, t.x, 1);       else if (A + C == B)         t = lll(a.x, t.y, 1);       else         return lll(0, 0, 0);       A = D(a.y, t.x), B = D(a.y, t.y), C = D(t.x, t.y);       if (A + B == C)         t = lll(t.x, t.y, 1);       else if (B + C == A)         t = lll(a.y, t.x, 1);       else if (A + C == B)         t = lll(a.y, t.y, 1);       else         return lll(0, 0, 0);       return t;     }   };   namespace SGT {   const int N = ::N << 2;   lll t[N];   void up(int x) { t[x] = t[x << 1] + t[x << 1 | 1]; }   void build(int x, int l, int r) {     if (l == r) return t[x] = lll(b[l], b[l], 1), void();     build(x << 1, l, ((l + r) >> 1)), build(x << 1 | 1, ((l + r) >> 1) + 1, r);     up(x);   }   void mdf(int x, int l, int r, int p, int v) {     if (l == r) return t[x] = lll(v, v, 1), void();     if (p <= ((l + r) >> 1))       mdf(x << 1, l, ((l + r) >> 1), p, v);     else       mdf(x << 1 | 1, ((l + r) >> 1) + 1, r, p, v);     up(x);   }   int ask(int x, int l, int r, lll z) {     if (l == r) {       lll y = z + t[x];       if (y.o) return l + 1;       return l;     }     lll y = z + t[x << 1];     if (!y.o) return ask(x << 1, l, ((l + r) >> 1), z);     return ask(x << 1 | 1, ((l + r) >> 1) + 1, r, y);   }   }  // namespace SGT   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[a[i]] = i;     for (int i = 2, x; i <= n; i++) scanf( %d , &x), G[x].push_back(i);     dfs(1, 0);     for (int i = 2; i <= k; i++) lg[i] = lg[i >> 1] + 1;     for (int i = 1; (1 << i) <= k; i++)       for (int j = 1; j + (1 << i) - 1 <= k; j++)         mn[i][j] = chk(mn[i - 1][j], mn[i - 1][j + (1 << i - 1)]);     SGT ::build(1, 0, n - 1);     cin >> m;     while (m--) {       int o, x, y;       scanf( %d , &o);       if (o == 1) {         scanf( %d%d , &x, &y);         swap(a[x], a[y]);         x = a[x], y = a[y];         swap(b[x], b[y]);         SGT ::mdf(1, 0, n - 1, x, b[x]);         SGT ::mdf(1, 0, n - 1, y, b[y]);       }       if (o == 2) cout << SGT ::ask(1, 0, n - 1, lll(0, 0, 1)) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     char def =  a ;     int pos = 0;     string ans =   ;     for (int i = 0; i < n; i++) {       ans += def + pos;       pos = (pos + 1) % k;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007LL;   long long base = 10000007;   long long large = 1000000000000000000LL;   class UnionFind {    private:     vector<int> p, rank;       public:     UnionFind(int n) {       rank.assign(n, 0);       p.assign(n, 0);       for (int i = 0; i < n; i++) {         p[i] = i;       }     }     int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;         } else {           p[x] = y;           if (rank[x] == rank[y]) {             rank[y]++;           }         }       }     }   };   vector<vector<pair<int, int> > > adj;   int n, m;   vector<pair<pair<int, int>, int> > e;   vector<int> dp;   void dfs(int u, int pa, int val) {     dp[u] = val;     for (int j = 0; j < (int)adj[u].size(); j++) {       int v = adj[u][j].first;       int d = adj[u][j].second;       if (v != pa) {         dfs(v, u, val ^ d);       }     }   }   int main() {     cin >> n >> m;     UnionFind uf(n);     adj.assign(n, vector<pair<int, int> >());     for (int i = 0; i < m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       x--;       y--;       if (uf.isSameSet(x, y)) {         e.push_back(pair<pair<int, int>, int>(pair<int, int>(x, y), z));       } else {         uf.unionSet(x, y);         adj[x].push_back(pair<int, int>(y, z));         adj[y].push_back(pair<int, int>(x, z));       }     }     dp.assign(n, 0);     dfs(0, -1, 0);     vector<int> mask;     for (int i = 0; i < (int)e.size(); i++) {       int x = e[i].first.first;       int y = e[i].first.second;       int z = e[i].second;       int lo = dp[x] ^ dp[y] ^ z;       mask.push_back(lo);     }     int cur = 0;     for (int l = 30; l >= 0; l--) {       int c = -1;       for (int i = cur; i < (int)mask.size(); i++) {         if (mask[i] & (1 << l)) {           c = i;           break;         }       }       if (c == -1) continue;       swap(mask[cur], mask[c]);       for (int i = cur + 1; i < (int)mask.size(); i++) {         if (mask[i] & (1 << l)) mask[i] ^= mask[cur];       }       cur++;     }     vector<int> basis;     for (int i = 0; i < cur; i++) {       basis.push_back(mask[i]);     }     int l = 30;     int dis = dp[n - 1];     for (int i = 0; i < (int)basis.size(); i++) {       while (((1 << l) & basis[i]) == 0) l--;       if ((1 << l) & dis) dis ^= basis[i];     }     cout << dis << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int input[100000];   int output[100000];   pair<pair<int, int>, int> queries[100000];   int blockSize;   bool mo_compare(pair<pair<int, int>, int>& x, pair<pair<int, int>, int>& y) {     int firstBlockIndex = x.first.first / blockSize;     int secondBlockIndex = y.first.first / blockSize;     if (firstBlockIndex == secondBlockIndex) {       return x.first.second < y.first.second;     }     return firstBlockIndex < secondBlockIndex;   }   void inline removeElement(unordered_map<int, int>& lookup, int val,                             int& result) {     unordered_map<int, int>::iterator itr = lookup.find(val);     if (itr != lookup.end()) {       if (itr->first == itr->second) {         result--;       }       itr->second--;       if (itr->first == itr->second) {         result++;       }     } else {       lookup[val]--;     }   }   void inline addElement(unordered_map<int, int>& lookup, int val, int& result) {     unordered_map<int, int>::iterator itr = lookup.find(val);     if (itr != lookup.end()) {       if (itr->first == itr->second) {         result--;       }       itr->second++;       if (itr->first == itr->second) {         result++;       }     } else {       lookup[val]++;       if (val == 1) {         result++;       }     }   }   int main() {     cin.tie(NULL);     int n, m;     cin >> n >> m;     blockSize = static_cast<int>(sqrt(n));     for (int i = 0; i < n; i++) {       cin >> input[i];     }     for (int i = 0; i < m; i++) {       pair<pair<int, int>, int>& query = queries[i];       cin >> query.first.first >> query.first.second;       query.first.first--;       query.first.second--;       query.second = i;     }     sort(queries, queries + m, mo_compare);     unordered_map<int, int> lookup;     int result = 0;     int prev_l = 0, prev_r = -1, left, right, index;     unordered_map<int, int>::iterator itr;     for (int i = 0; i < m; i++) {       left = queries[i].first.first;       right = queries[i].first.second;       index = queries[i].second;       while (left > prev_l) {         removeElement(lookup, input[prev_l], result);         prev_l++;       }       while (left < prev_l) {         prev_l--;         addElement(lookup, input[prev_l], result);       }       while (right < prev_r) {         removeElement(lookup, input[prev_r], result);         prev_r--;       }       while (right > prev_r) {         prev_r++;         addElement(lookup, input[prev_r], result);       }       output[index] = result;     }     for (int i = 0; i < m; i++) {       cout << output[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M, K;   char a[1001], b[1001];   int mem[1001][1001][11][2];   int main() {     scanf( %d %d %d , &N, &M, &K);     scanf( %s %s , a, b);     memset(mem, 0, sizeof(mem));     int ans = 0;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         for (int k = 1; k <= K; k++) {           if (a[i - 1] == b[j - 1]) {             mem[i][j][k][1] =                 max(mem[i - 1][j - 1][k][1] + 1, mem[i - 1][j - 1][k - 1][0] + 1);             mem[i][j][k][0] =                 max(mem[i][j][k][1],                     max(max(mem[i - 1][j][k][1], mem[i - 1][j][k][0]),                         max(mem[i][j - 1][k][1], mem[i][j - 1][k][0])));           } else {             mem[i][j][k][1] = 0;             mem[i][j][k][0] = max(max(mem[i - 1][j][k][1], mem[i - 1][j][k][0]),                                   max(mem[i][j - 1][k][1], mem[i][j - 1][k][0]));           }           if (k == K) {             ans = max(ans, max(mem[i][j][k][0], mem[i][j][k][1]));           }         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long k, n, m;   int answ = 1;   bool flag = 0;   int main() {     cin >> n >> m;     k = 2;     for (int i = 2; i <= m; i++) k = (k * 2) % 1000000009;     if (k > n) {       for (int i = 1; i <= n; i++) answ = (answ * (k - i)) % 1000000009;       cout << answ;     } else       cout << 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   long long int path[100001];   long long int dist[100001];   void shortest_path(vector<pair<long long int, long long int>> v[],                      long long int start) {     long long int i;     for (i = 0; i < 100001; i++) dist[i] = 1e18 + 1;     priority_queue<long long int> q;     q.push(start);     dist[start] = 0;     while (!q.empty()) {       long long int x = q.top();       q.pop();       for (i = 0; i < v[x].size(); i++) {         if (dist[v[x][i].first] > dist[x] + v[x][i].second) {           dist[v[x][i].first] = dist[x] + v[x][i].second;           path[v[x][i].first] = x;           q.push(v[x][i].first);         }       }     }   }   void solve() {     long long int ver, edge, i, x, y, w, start = 1;     cin >> ver >> edge;     vector<pair<long long int, long long int>> v[ver + 1];     vector<long long int> ans;     for (i = 0; i < edge; i++) {       cin >> x >> y >> w;       v[x].push_back(make_pair(y, w));       v[y].push_back(make_pair(x, w));     }     shortest_path(v, start);     if (dist[ver] == 1e18 + 1)       cout <<  -1             <<   n ;     else {       cout <<  1  ;       while (ver != 1) {         ans.push_back(ver);         ver = path[ver];       }       for (i = ans.size() - 1; i >= 0; i--) {         cout << ans[i] <<    ;       }       cout <<   n ;     }   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fast();     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long n;     cin >> n;     vector<unsigned long long> a(n);     for (unsigned long long i = 0; i < n; i++) cin >> a[i];     unsigned long long total = 0;     for (unsigned long long i = 0; i < n; i++) total += a[i];     vector<unsigned long long> f;     unsigned long long zd = total;     for (unsigned long long i = 2; (i * i) <= zd; i++) {       if (zd % i == 0) {         f.push_back(i);         while (zd % i == 0) {           zd /= i;         }       }     }     if (zd != 1) f.push_back(zd);     if (total == 1) {       cout << -1 <<   n ;       return 0;     }     unsigned long long is = 900000000000000000;     for (unsigned long long i = 0; i < f.size(); i++) {       unsigned long long x = f[i];       unsigned long long temp = 0;       vector<pair<unsigned long long, unsigned long long>> z;       unsigned long long tt = 0;       for (unsigned long long j = 0; j < n; j++) {         tt += a[j] % x;         z.push_back(make_pair(j, a[j] % x));         if (tt >= x) {           unsigned long long left = 0;           unsigned long long right = 0;           unsigned long long Sr = 0;           unsigned long long Sl = 0;           z[z.size() - 1].second -= (tt - x);           for (unsigned long long k = 0; k < z.size(); k++) {             right +=                 (unsigned long long)z[k].first * (unsigned long long)z[k].second;           }           Sr = x;           unsigned long long ttt = 900000000000000000;           for (unsigned long long k = 0; k < z.size(); k++) {             unsigned long long t2 = 0;             right -= ((unsigned long long)z[k].first *                       (unsigned long long)z[k].second);             left += ((unsigned long long)z[k].first *                      (unsigned long long)z[k].second);             Sr -= z[k].second;             Sl += z[k].second;             t2 += (right - Sr * z[k].first) + (Sl * z[k].first - left);             ttt = min(ttt, t2);           }           temp += ttt;           z.clear();           tt %= x;           z.push_back(make_pair(j, tt));         }       }       is = min(is, temp);     }     cout << is <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cnt[200005 * 5], E2[200005], f[200005 * 5];   signed main() {     scanf( %d , &n);     int mx = 0;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       cnt[x]++;       mx = max(mx, x);     }     E2[0] = 1;     for (int i = 1; i < 200005; i++) E2[i] = E2[i - 1] * 2 % 1000000007;     for (int i = mx; i >= 2; i--) {       int tot = 0;       for (int j = i; j <= mx; j += i) tot += cnt[j];       f[i] = 1ll * tot * E2[tot - 1] % 1000000007;       for (int j = i + i; j <= mx; j += i)         f[i] = (f[i] - f[j] + 1000000007) % 1000000007;     }     int ans = 0;     for (int i = 2; i <= mx; i++)       ans = (ans + 1ll * f[i] * i % 1000000007) % 1000000007;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   constexpr int MAXN = 100005;   int n;   string type[MAXN], word[MAXN];   bitset<30> to_bs(const string& s) {     bitset<30> res;     for (char c : s) {       res[c -  a ] = true;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     bitset<30> all = to_bs( abcdefghijklmnopqrstuvwxyz );     int ans = 0;     for (int i = 0; i < n; ++i) {       cin >> type[i] >> word[i];       bitset<30> cur = to_bs(word[i]);       if (type[i][0] ==  ! ) {         if (all.count() <= 1) {           ans += 1;         }         all = all & cur;       } else if (type[i][0] ==  . ) {         all = all & cur.flip();       } else {         if (all.count() == 1) ans += 1;         all.reset(word[i][0] -  a );       }     }     cout << max(0, ans - 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   bool lucky[10010];   int n, m;   int a[N];   int t[N + N];   void init() {     memset(lucky, false, sizeof(lucky));     lucky[0] = true;     for (int i = 1; i <= 10000; i++)       if (i % 10 == 4 || i % 10 == 7) lucky[i] = lucky[i / 10];   }   void update(int i, int v) {     if (!v) return;     i += n;     while (i >= 1) {       t[i] += v;       i >>= 1;     }   }   int query(int Left, int Right) {     int res = 0;     Left += n;     Right += n;     while (Left <= Right) {       if (Left % 2) res += t[Left];       if ((~Right) % 2) res += t[Right];       Left = (Left + 1) >> 1;       Right = (Right - 1) >> 1;     }     return res;   }   int main() {     init();     scanf( %d%d , &n, &m);     memset(t, 0, sizeof(t));     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       update(i, lucky[a[i]]);     }     char x[10];     int Left, Right, temp;     while (m--) {       scanf( %s , &x);       if (strcmp(x,  count ) == 0) {         scanf( %d%d , &Left, &Right);         Left--;         Right--;         printf( %d n , query(Left, Right));       } else {         scanf( %d%d%d , &Left, &Right, &temp);         Left--;         Right--;         for (int i = Left; i <= Right; i++) {           a[i] += temp;           update(i, lucky[a[i]] - lucky[a[i] - temp]);         }       }     }     return 0;   }