malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long const mod = 1000000007;   long long const md = 998244353;   long long mypow(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   ifstream in( txt.in );   ofstream out( txt.out );   int f[105];   int main() {     cout << fixed << setprecision(12);     cin.tie(0);     ios_base::sync_with_stdio(0);     cout.tie(0);     long long n, x, y;     cin >> n >> x >> y;     for (int i = 1; i <= n; ++i) {       cin >> f[i];     }     sort(f + 1, f + n + 1);     if (x > y) return cout << n, 0;     int u = 0;     for (int i = 1; i <= n; ++i) {       if (x >= f[i]) u = i;     }     cout << (u + 1) / 2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long resp, n, m, tt;   int main() {     cin >> n >> m;     if (m % 2 == 0) {       tt = m / 2;       tt = tt * (tt + 1) - tt;     } else {       tt = m / 2;       tt = tt * (tt + 1);     }     for (long long i = 2; i <= n; i += 2) {       resp += tt * (n - i + 1);     }     cout << resp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   int INF = 1e6;   long long int n, m;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int i, j, t, k, x, y, z, N;     cin >> n;     long long int a[n], b[n], c[n];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < n; i++) cin >> c[i];     long long int dp[n][2];     memset(dp, 0, sizeof(dp));     ;     dp[n - 1][0] = a[n - 1];     dp[n - 1][1] = b[n - 1];     for (i = n - 2; i >= 0; i--) {       dp[i][0] = max(dp[i + 1][0] + b[i], dp[i + 1][1] + a[i]);       dp[i][1] = max(dp[i + 1][0] + c[i], dp[i + 1][1] + b[i]);     }     cout << dp[0][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[1000010];   char ch[1000010];   map<int, int> mp, mp1;   vector<int> vec(1000010);   int main() {     int i, j, k, n, m, t, p, cas = 1;     memset(arr, 0, sizeof arr);     vec.clear();     mp.clear();     mp1.clear();     int cnt = 0, l = 0, r = 0;     stack<int> st;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       mp[arr[i]] = i + 1;     }     getchar();     scanf( %s , &ch);     sort(arr, arr + n);     int len = strlen(ch);     for (i = 0; i < len; i++) {       if (ch[i] ==  0 ) {         cnt++;         st.push(cnt - 1);         vec.push_back(mp[arr[cnt - 1]]);       } else {         int n1 = st.top();         st.pop();         vec.push_back(mp[arr[n1]]);       }     }     for (i = 0; i < vec.size(); i++) {       if (i == 0)         printf( %d , vec[i]);       else         printf(  %d , vec[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, flag = 0;       cin >> n;       vector<int> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];       }       sort(v.begin(), v.end());       if (v[0] == 0) {         vector<int> v1(n);         for (int k = 1; k < 2000; k++) {           for (int i = 0; i < n; i++) {             v1[i] = (v[i] ^ k);           }           sort(v1.begin(), v1.end());           if (v1 == v) {             cout << k << endl;             flag++;             break;           }         }       } else {         vector<int> v1(n);         for (int k = 1; k < 2000; k++) {           for (int i = 0; i < n; i++) {             v1[i] = (v[i] ^ k);           }           sort(v1.begin(), v1.end());           if (v1 == v) {             cout << k << endl;             flag++;             break;           }         }       }       if (flag == 0) {         cout <<  -1  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, a, b, count = 0;     ;     cin >> n >> m;     while (cin >> a >> b) {       if (a == 1 || b == 1) {         count++;       }     }     cout << count;   }   signed main() {     long long test = 1;     while (test--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c = 0;     cin >> n;     bool* V = new bool[n];     bool Back = false;     for (int i = 0; i < n; ++i) {       cin >> V[i];       if (V[i]) {         if (Back && c) c++;         c++;         Back = false;       } else {         Back = true;       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o,       p = 0, q = 0, r, s, t, u, v, w, x, y, z, temp = 0, ans = 0, t1, t2, sum = 0;   vector<long long int> v1, v2, v3, v4, v5, v6;   vector<string> vs1, vs2, vs3, vs4;   double f1, f2 = 0, f3, f4;   vector<double> v10;   vector<pair<long long int, long long int>> v11, v12, v13, v14;   string s1, s2, s3, s4, s5, s6;   long long int a10[100][3];   long long int a1[1000000], a2[1000000];   char c1, c2, c3;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (i = 0; i < n; i++) {       p = 0;       cin >> g >> h;       while (g != 0) {         if (g % h == 0) {           g = g / h;           p++;         } else {           p = p + g % h;           g = g - g % h;         }       }       cout << p << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool vis[1000][1000];   bool lab[1000][1000];   vector<int> ans;   int comp[1000][1000];   int cur_ans;   int cur_comp = 0;   int dfs(int x, int y) {     if (!lab[x][y]) {       ++cur_ans;       return 0;     }     if (!vis[x][y]) {       comp[x][y] = cur_comp;       vis[x][y] = true;       dfs(x + 1, y);       dfs(x, y + 1);       dfs(x - 1, y);       dfs(x, y - 1);     }     return 0;   }   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         char c;         cin >> c;         if (c ==  * ) {           lab[i][j] = false;         } else {           lab[i][j] = true;         }       }     }     for (int i = 0; i < k; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       if (!vis[x][y]) {         cur_ans = 0;         dfs(x, y);         cur_comp++;         ans.push_back(cur_ans);         cout << cur_ans << endl;       } else {         cout << ans[comp[x][y]] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long readLL() {     long long n = 0;     int ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) n = n * 10 + ch -  0 , ch = getchar();     return n;   }   const int MAX_N = 500000 + 3, MAX_LOG_V = 61;   int n;   long long a[MAX_N], b[MAX_LOG_V];   int main() {     n = readLL();     long long v = 0;     for (int i = 0; i < n; ++i) {       a[i] = readLL(), v ^= a[i];       a[i] ^= readLL();     }     int cnt = 0;     for (int i = 0; i < n; ++i)       for (int j = MAX_LOG_V - 1; j >= 0; --j)         if (a[i] >> j & 1) {           if (b[j])             a[i] ^= b[j];           else {             b[j] = a[i];             ++cnt;             break;           }         }     long long nowV = 0;     for (int i = MAX_LOG_V - 1; i >= 0; --i)       if ((v >> i & 1) != (nowV >> i & 1)) nowV ^= b[i];     if (nowV != v)       puts( 1/1 );     else       printf( %lld/%lld , (1LL << cnt) - 1, 1LL << cnt);     return 0;   }
#include <bits/stdc++.h>   long long A[100000];   using namespace std;   int main() {     long long n, s = 0, m = -100000, a = 0, p;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];       if (A[i] % 2 == 0 && A[i] > 0) s += A[i];     }     std::sort(A, A + n);     for (int i = n - 1; i >= 0; i--) {       if (A[i] % 2 != 0 && (A[i] > 0 || (A[i] < 0 && a == 0) ||                             (A[i] < 0 && a % 2 == 0 && A[i] + p > 0))) {         a++;         p = A[i];         s += p;       }     }     if (a % 2 == 0) s -= p;     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int i, n, k;   string Yes_No,       names[] = { a ,   b ,   c ,   d ,   e ,   f ,   g ,   h ,   i ,   j ,   k ,                   l ,   m ,   n ,   o ,   p ,   q ,   r ,   s ,   t ,   u ,   v ,                   w ,   x ,   y ,   z ,   aa ,  bb ,  cc ,  dd ,  ee ,  ff ,  gg ,                   hh ,  ii ,  jj ,  kk ,  ll ,  mm ,  nn ,  oo ,  pp ,  qq ,  rr ,                   ss ,  tt ,  uu ,  vv ,  ww ,  xx ,  yy ,  zz };   int main() {     for (i = 0; i < 52; i++) names[i] =  A  + names[i];     cin >> n >> k;     for (i = 1; i <= n - k + 1; i++) {       cin >> Yes_No;       if (Yes_No ==  NO ) names[i + k - 1] = names[i];     }     for (i = 1; i <= n; i++) cout << names[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   string gd, str, ask;   int q, n, t, ans, tmp, cnt, ara[1000];   int main() {     cin >> gd >> str >> n;     for (int i = 0; i < gd.size(); i++) ara[gd[i] -  a ] = 1;     while (n--) {       cin >> ask;       int in = -1, fin = -1;       ans = 0;       for (int i = 0; i < max(str.size(), ask.size()); i++) {         if (str[i] ==  ? ) {           if (ara[ask[i] -  a ] != 1) {             ans = 2;             break;           }         } else if (str[i] ==  * ) {           in = i;           break;         } else {           if (str[i] != ask[i]) {             ans = 2;             break;           }         }       }       if (ans == 2) {         printf( NO n );         continue;       } else if (in == -1) {         printf( YES n );         continue;       } else {         for (int i = str.size() - 1, j = ask.size() - 1; i >= 0; i--, j--) {           if (str[i] ==  ? ) {             if (ara[ask[j] -  a ] != 1) {               ans = 2;               break;             }           } else if (str[i] ==  * ) {             fin = j + 1;             break;           } else {             if (str[i] != ask[j]) {               ans = 2;               break;             }           }         }       }       if (ans == 2 || fin == -1 || in > fin) {         printf( NO n );         continue;       } else {         for (int i = in; i < fin; i++) {           if (ara[ask[i] -  a ] == 1) {             ans = 2;             break;           }         }       }       if (ans == 2) {         printf( NO n );       } else         printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t1, t2, x1, x2, t0, ans1 = 1000000000, ans2 = 1000000000;   double best = 1e16;   int main() {     cin >> t1 >> t2 >> x1 >> x2 >> t0;     if (t1 == t2 && t1 == t0) {       cout << x1 <<     << x2 <<   n ;       return 0;     }     if (t2 == t0) {       cout <<  0   << x2 <<   n ;       return 0;     }     for (int y1 = 0; y1 <= x1; y1++) {       int temp = y1 * double(t0 - t1) / double(t2 - t0);       for (int y2 = temp - 3; y2 <= temp + 2; y2++) {         if (y1 == 0 && y2 == temp - 3) {           y2 = x2;         }         if (y2 < 0 || y2 > x2) {           continue;         }         double cur =             ((long long)y1 * t1 + (long long)y2 * t2) / (double)(y1 + y2);         if (cur < t0) {           continue;         }         if (cur < best) {           best = cur;           ans1 = y1;           ans2 = y2;         } else if (cur == best) {           if (y1 + y2 > ans1 + ans2) {             ans1 = y1;             ans2 = y2;           }         }       }     }     cout << ans1 <<     << ans2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXR = 1e6 + 1e3;   int n;   vector<int> b, dp, s;   vector<pair<int, int> > v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     while (cin >> n) {       b = vector<int>(MAXR, 0);       s = vector<int>(MAXR, 0);       dp = vector<int>(MAXR, 0);       for (int i = 0; i < n; ++i) {         int x, y;         cin >> x >> y;         b[x] = y;         s[x] = 1;       }       int ans = 0;       dp[0] = s[0];       for (int i = 1; i <= MAXR; ++i) {         if (b[i])           dp[i] = i - b[i] <= 0 ? 1 : dp[i - b[i] - 1] + 1;         else           dp[i] = dp[i - 1];         ans = max(ans, dp[i]);       }       cout << n - ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, i;     cin >> n;     int la, ra;     int cnt00 = 0, cnt01 = 0, cnt10 = 0, cnt11 = 0;     for (i = 0; i < n; i++) {       cin >> la >> ra;       if (la == 1) {         if (ra == 0)           cnt10++;         else           cnt11++;       } else {         if (ra == 0)           cnt00++;         else           cnt01++;       }     }     int a00 = cnt01 + cnt10 + 2 * cnt11;     int a01 = cnt11 + cnt00 + 2 * cnt10;     int a10 = cnt11 + cnt00 + 2 * cnt01;     int a11 = cnt01 + cnt10 + 2 * cnt00;     cout << min(a00, min(a01, min(a10, a11)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1e9;   const long long LINF = INF * (long long)INF;   const double EPS = 1e-7;   const int MAX = 20 * 1000 + 47;   const int MAS = 2 * 1e5 + 10;   const int MOD = 998244353;   long long haves, haveb, havec;   long long priceb, prices, pricec;   long long money;   long long cntS, cntB, cntC;   bool check(long long cnt) {     long long a1 = max(0LL, (cntS * cnt - haves) * prices);     long long a2 = max(0LL, (cntB * cnt - haveb) * priceb);     long long a3 = max(0LL, (cntC * cnt - havec) * pricec);     return a1 + a2 + a3 <= money;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     cntC = cntB = cntC = 0;     for (int i = (0); i < ((int)s.size()); i++) {       if (s[i] ==  S ) cntS++;       if (s[i] ==  B ) {         cntB++;       }       if (s[i] ==  C ) cntC++;     }     cin >> haveb >> haves >> havec;     cin >> priceb >> prices >> pricec;     cin >> money;     long long l = 0;     long long r = 1e14 + 10;     for (int i = (0); i < (200); i++) {       long long m = (l + r) / 2;       if (check(m)) {         l = m;       } else {         r = m;       }     }     cout << l << endl;   }
#include <bits/stdc++.h>   using namespace std;   int hc(int a, int b) {     if (b == 0) return a;     return hc(b, a % b);   }   int main() {     int n, a[10010], i, sum = 0;     cin >> n;     int k = n;     for (i = 2; i < n; i++) {       a[i] = i;     }     for (i = 2; i < n; i++) {       while (n != 0) {         sum = sum + n % a[i];         n = n / a[i];       }       n = k;     }     int q = k - 2;     int h = hc(sum, k - 2), b;     sum = sum / h;     b = q / h;     cout << sum <<  /  << b << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   template <typename T>   void debug(vector<T> x) {     for (auto e : x) {       cout << e <<    ;     }     cout <<   n ;   }   void solve() {     long long n;     cin >> n;     long long x = n / 4;     long long y = n % 4;     if (y % 4 == 0) {       for (long long i = 0; i < n - x; i++) {         cout <<  9 ;       }       for (long long i = 0; i < x; i++) {         cout <<  8 ;       }       cout <<   n ;       return;       ;     } else {       for (long long i = 0; i < n - (x + 1); i++) {         cout <<  9 ;       }       for (long long i = 0; i < x + 1; i++) {         cout <<  8 ;       }       cout <<   n ;       return;       ;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cur;   int fa[1005];   set<int> s1, s2;   struct edge {     int from, to;     char color[2];   } e[100005];   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void init() {     for (int i = 1; i <= n; i++) {       fa[i] = i;     }     cur = n;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> e[i].from >> e[i].to >> e[i].color;     }     if (n % 2 == 0) {       cout << -1 << endl;       return 0;     }     init();     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  S ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;         }       }     }     if (cur - 1 > (n - 1) / 2) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  M ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s2.insert(i);         }       }     }     if (cur != 1) {       cout << -1 << endl;       return 0;     }     init();     for (auto i : s2) {       int fx = find(e[i].from);       int fy = find(e[i].to);       if (fx != fy) {         fa[fx] = fy;         cur--;       }     }     for (int i = 1; i <= m; i++) {       if (s2.size() == (n - 1) / 2) break;       if (e[i].color[0] ==  M ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s2.insert(i);         }       }     }     if (s2.size() != (n - 1) / 2) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  S ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s1.insert(i);         }       }     }     cout << n - 1 << endl;     for (auto i : s1) cout << i <<    ;     for (auto i : s2) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long MOD = 998244353ll;   enum RESULT { OK, WIN };   int n, v[N], nxt[N], prv[N];   long long dp[N][2], acc[N], inv[N];   long long expr(long long e, long long n) {     if (n == 0) return 1ll;     long long tp = expr(e, n / 2ll);     tp = (tp * tp) % MOD;     if (n % 2ll) tp = (tp * e) % MOD;     return tp;   }   void ok(int t, int p) {     int h = prv[p - 1];     dp[p][OK] = (acc[h] * inv[n - t + 1]) % MOD;   }   void win(int t, int p) {     int r = nxt[p - 1];     int l = prv[p - 1];     dp[p][WIN] =         (((acc[r] - acc[l] - dp[p][OK] + 2ll * MOD) % MOD) * inv[n - t + 1]) %         MOD;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v[i - 1]);       dp[i][OK] = expr(n, MOD - 2) % MOD;       acc[i] = (acc[i - 1] + dp[i][OK]) % MOD;     }     sort(v, v + n);     long long resp = 0ll;     for (int t = 1; t <= n; t++) inv[t] = expr(t, MOD - 2);     for (int i = 0; i < n; i++) {       prv[i] = lower_bound(v, v + n, v[i]) - v;       nxt[i] = upper_bound(v, v + n, v[i]) - v;     }     for (int t = 2; t <= n; t++) {       for (int p = 1; p <= n; p++) {         win(t, p);         ok(t, p);         resp = (resp + dp[p][WIN]) % MOD;       }       for (int p = 1; p <= n; p++) acc[p] = (acc[p - 1] + dp[p][OK]) % MOD;     }     printf( %lld n , resp);   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, i, j;     cin >> n >> m;     int x, y;     vector<vector<int> > adj(n);     vector<int> ncon(n, 0);     for (i = (0); i < (m); i++) {       cin >> x >> y;       adj[x - 1].push_back(y - 1);       adj[y - 1].push_back(x - 1);       ncon[x - 1]++;       ncon[y - 1]++;     }     vector<int> onecon;     for (i = (0); i < (n); i++)       if (ncon[i] == 1) onecon.push_back(i);     int maxd = 0;     queue<int> q;     vector<int> dist(n, 0), rem(n, 0);     for (auto i : onecon) {       q.push(i);       dist[i] = 1;     }     if ((int)((onecon).size()) != 0) maxd = 1;     while (!q.empty()) {       int cur = q.front();       q.pop();       rem[cur] = 1;       if (ncon[cur] == 1) maxd = max(maxd, dist[cur]);       for (auto next : adj[cur]) {         if (rem[next] == 1) continue;         ncon[next]--;         if (ncon[next] == 1) {           dist[next] = dist[cur] + 1;           q.push(next);         }       }     }     cout << maxd <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   const int M = 1e4 + 5;   int n, m, w, vis[N], l[N], r[N];   long long a[N], ans[N], s;   int main() {     cin >> n >> s;     long long sum = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum < s) {       cout << -1 << endl;       return 0;     } else if (sum == s) {       cout << 0 << endl;       return 0;     }     sort(a + 1, a + 1 + n);     int now = 1;     sum = s;     while (a[now] == a[1]) {       now++;     }     for (int i = n; i >= now; i--) {       sum -= (a[i] - a[1]);     }     if (sum) {       int cnt = 0;       while (sum > 0) {         sum -= n;         cnt++;       }       cout << a[1] - cnt << endl;     } else {       cout << a[1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int S, C, Ha, Hb, Wa, Wb;   long long Ans;   int main() {     scanf( %d%d%d%d%d , &C, &Ha, &Hb, &Wa, &Wb);     S = sqrt(C);     if (Wa > Wb) swap(Ha, Hb), swap(Wa, Wb);     if (Wb > S)       for (int i = 0; 1LL * i * Wb <= C; i++)         Ans = max(Ans, 1LL * i * Hb + 1LL * (C - i * Wb) / Wa * Ha);     else {       if (1LL * Ha * Wb > 1LL * Hb * Wa) swap(Ha, Hb), swap(Wa, Wb);       for (int i = 0; i < Wb; i++)         Ans = max(Ans, 1LL * i * Ha + 1LL * (C - i * Wa) / Wb * Hb);     }     printf( %I64d n , Ans);   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char a[109][109], b[109][109];   void add(int x, int y) {     if (a[x][y] ==  * ) return;     if (b[x][y] ==   0 )       b[x][y] =  1 ;     else       ++b[x][y];   }   void fill(int x, int y) {     if (x > 0 && y > 0) add(x - 1, y - 1);     if (x > 0) {       add(x - 1, y);       add(x - 1, y + 1);     }     if (y > 0) {       add(x, y - 1);       add(x + 1, y - 1);     }     add(x, y + 1);     add(x + 1, y);     add(x + 1, y + 1);   }   bool check() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if ((a[i][j] >=  1  && a[i][j] <=  8 ) ||             (b[i][j] >=  1  && b[i][j] <=  8 )) {           if (a[i][j] != b[i][j]) {             return false;           }         }       }     }     return true;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %s , a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  * ) {           fill(i, j);         }       }     }     if (check())       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }