malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 10;   inline long long add(long long x, long long y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline long long mul(long long x, long long y) {     x = (1LL * x * y) % mod;     return x;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     n--;     cout <<  0 0  << endl;     fflush(stdout);     if (n == 0) {       cout <<  1 0 1 1 ;       fflush(stdout);       return 0;     }     string prev;     cin >> prev;     long long l = 0;     long long r = 1e9;     long long i = 1;     while (i <= n) {       long long m = (l + r) / 2;       cout << m <<                <<  0  << endl;       fflush(stdout);       string s;       cin >> s;       if (s == prev) {         l = m;       } else {         r = m;       }       i++;     }     if (r - l < 2) {       cout << r <<   1   << (r + 1) <<     << (2 * (r + 1) - 2 * l - 1);       fflush(stdout);       return 0;     }     long long m = (l + r) / 2;     cout << m <<   0   << m <<   1 ;     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> c;   vector<bool> used;   void dfs(int u, vector<vector<int>>& v) {     used[u] = 1;     for (int i = 0; i < v[u].size(); i++) {       if (c[u] == c[v[u][i]] && !used[v[u][i]]) {         dfs(v[u][i], v);       }     }   }   int main() {     int n;     cin >> n;     vector<vector<int>> v(n);     c.resize(n);     used.resize(n, 0);     vector<int> cnt(110000);     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 0; i < n; i++) {       cin >> c[i];     }     for (int i = 0; i < n; i++) {       if (!used[i]) {         cnt[c[i]]++;         dfs(i, v);       }     }     multiset<int> data;     for (int i = 0; i < 100010; i++) {       for (int j = 0; j < cnt[i]; j++) {         data.insert(i);       }     }     for (int i = 0; i < n; i++) {       bool check = 0;       multiset<int> tmp;       for (int j = 0; j < v[i].size(); j++) {         if (c[v[i][j]] == c[i]) {           check = 1;         }         tmp.insert(c[v[i][j]]);       }       if (!check) {         tmp.insert(c[i]);       }       if (tmp == data) {         cout <<  YES  << endl;         cout << i + 1 << endl;         return 0;       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long power(long long a, long long b) {     if (b == 0) {       return 1;     } else {       if (b % 2 == 0) {         return (a * power((a * a) % 1000000007, b / 2)) % 1000000007;       } else {         return power((a * a) % 1000000007, b / 2);       }     }   }   int main() {     fastio();     long long l, r;     cin >> l >> r;     long long even1 = 0, odd1 = 0;     long long p = 0;     l--;     while (l > 0) {       long long t = min((long long)pow(2LL, p), l);       if (p % 2 == 0) {         odd1 += t;         odd1 %= 1000000007;       } else {         even1 += t;         even1 %= 1000000007;       }       p++;       l -= t;     }     long long even2 = 0, odd2 = 0;     p = 0;     while (r > 0) {       long long t = min((long long)pow(2LL, p), r);       if (p % 2 == 0) {         odd2 += t;         odd2 %= 1000000007;       } else {         even2 += t;         even2 %= 1000000007;       }       p++;       r -= t;     }     long long sum1 = (even1 * (even1 + 1)) % 1000000007;     sum1 = (sum1 + (odd1 * odd1) % 1000000007) % 1000000007;     long long sum2 = (even2 * (even2 + 1)) % 1000000007;     sum2 = (sum2 + (odd2 * odd2) % 1000000007) % 1000000007;     cout << (sum2 - sum1 + 1000000007) % 1000000007;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   struct node {     double x, y;   } po[1010];   double dis(node a, node b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   node mark;   double cha(node a, node b, node c) {     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   double get(node a, node b, node c) {     return abs(cha(a, b, c)) / dis(a, b) / 2.0;   }   int main() {     int n;     cin >> n;     double ans = 1e9;     for (int i = (0); i < (n); ++i) cin >> po[i].x >> po[i].y;     for (int i = (0); i < (n); ++i) {       ans = min(ans, get(po[(i - 1 + n) % n], po[(i + 1) % n], po[i]));     }     cout << fixed << setprecision(10) << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, c, cnt;   vector<long long> v1, v2;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     while (n--) {       cin >> x;       if (x > 0)         v1.push_back(x), c += x;       else         v2.push_back(abs(x)), cnt += abs(x);     }     if (c > cnt) {       cout <<  first n ;       return 0;     }     if (cnt > c) {       cout <<  second n ;       return 0;     }     bool a = 0;     for (int i = 0; i < min(v1.size(), v2.size()); i++) {       if (v1[i] > v2[i]) {         cout <<  first n ;         return 0;       } else if (v1[i] < v2[i]) {         cout <<  second n ;         return 0;       }     }     if (x < 0)       cout <<  second  << endl;     else       cout <<  first  << endl;     return 0;   }
#include <bits/stdc++.h>   long long n, t, ans;   short i, j, k;   char cnt, l;   long long C[43][43];   int main() {     scanf( %I64d %I64d , &n, &t);     for (i = 0; (1ll << i) < t; ++i)       ;     if ((1ll << i) ^ t) {       puts( 0 );       return 0;     }     k = i + 1;     for (i = 0; i < 43; ++i) C[0][i] = 1ll;     for (i = 1; i < 43; ++i)       for (j = 1; j <= i; ++j) C[j][i] = C[j - 1][i - 1] + C[j][i - 1];     ++n;     for (cnt = i = 0; (1ll << i) <= n; ++i)       if ((1ll << i) & n) ++cnt;     for (l = i = 0; (1ll << i) <= n; ++i)       if (n & (1ll << i)) {         ++l;         if (k - cnt + l >= 0) ans += C[k - cnt + l][i];       }     if (cnt == k) ++ans;     if (k == 1) --ans;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1001;   int dp2[MAX_N][MAX_N], dp5[MAX_N][MAX_N];   int n;   string findPath(int (*p)[MAX_N]) {     int i = n - 1, j = n - 1;     string path =   ;     while (i != 0 && j != 0) {       if (p[i - 1][j] > p[i][j - 1]) {         path.insert(0,  R );         j--;       } else {         path.insert(0,  D );         i--;       }     }     if (i == 0) {       while (j != 0) {         path.insert(0,  R );         j--;       }     } else {       while (i != 0) {         path.insert(0,  D );         i--;       }     }     return path;   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     int temp1, temp2, zeroI = -1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         cin >> temp1;         if (!temp1) {           zeroI = i;           continue;         }         temp2 = temp1;         while (!(temp1 & 1)) {           dp2[i][j]++;           temp1 >>= 1;         }         while (!(temp2 % 5)) {           dp5[i][j]++;           temp2 /= 5;         }       }     for (int i = 1; i < n; i++) {       dp2[i][0] += dp2[i - 1][0];       dp5[i][0] += dp5[i - 1][0];       dp2[0][i] += dp2[0][i - 1];       dp5[0][i] += dp5[0][i - 1];     }     for (int i = 1; i < n; i++) {       for (int j = 1; j < n; j++) {         dp2[i][j] += min(dp2[i - 1][j], dp2[i][j - 1]);         dp5[i][j] += min(dp5[i - 1][j], dp5[i][j - 1]);       }     }     int(*p)[MAX_N] = (dp2[n - 1][n - 1] < dp5[n - 1][n - 1]) ? dp2 : dp5;     if ((~zeroI) && p[n - 1][n - 1] > 1) {       cout <<  1  << endl;       for (int i = 0; i < zeroI; i++) cout <<  D  << flush;       for (int j = 1; j < n; j++) cout <<  R  << flush;       for (int i = zeroI + 1; i < n; i++) cout <<  D  << flush;       return 0;     } else {       cout << p[n - 1][n - 1] << endl;       cout << findPath(p) << flush;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   long long a[N];   int n;   bool check(long long x) {     long long sum = 0;     for (int i = 2; i <= n; ++i) {       if (x - a[i] < 0) return false;       sum += x - a[i];     }     return (sum >= a[1]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]);     sort(a + 1, a + n + 1);     long long l = 0, r = (long long)1e14 + 1;     while (l + 1 < r) {       long long mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     if (check(l))       printf( %I64d , l);     else       printf( %I64d , r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPowerOfTwo(int n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   void asquare() {     long long n, c = 0, ans = LONG_LONG_MAX;     cin >> n;     string sn;     if (isPowerOfTwo(n) == true)       cout <<  0 n ;     else {       long long j = 0, k = 0, nn = 1;       string s = to_string(n);       for (int i = 0; i <= 60; i++) {         nn = (long long)pow(2, i);         sn = to_string(nn);         c = 0, j = 0, k = 0;         bool bb;         while (j != s.length() && k != sn.length()) {           if (s[j] == sn[k]) {             j++;             k++;             bb = true;           } else {             j++;             c++;             bb = false;           }         }         if (bb = true) {           if (j == s.length()) {             k--;             c += sn.length() - k - 1;           } else if (k == sn.length()) {             j--;             c += s.length() - j - 1;           }         } else {           k--;           c += sn.length() - k - 1;         }         if (c == 1) {           ans = 1;           break;         } else           ans = min(ans, c);       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       asquare();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int x, y;     cin >> x >> y;     int ans = 0;     int d = max(abs(x), abs(y));     if (d == 0) {       cout << 0 <<   n ;       return 0;     } else       ans = (d - 1) * 4;     if (x == d && y != -1 * (d - 1) && y != -1 * (d)) ans++;     if (y == d && x != d) ans += 2;     if (x == -1 * d && y != d) ans += 3;     if (y == -1 * d && x != -1 * d) ans += 4;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct Aho {     Aho *son[26];     Aho *fail;     int cntstr, faildp;     Aho() {       for (int i = 0; i < 26; ++i) son[i] = NULL;       fail = NULL;       cntstr = 0;       faildp = -1;     }   };   void insert(Aho *x, int i, const string &str) {     if (i < str.size()) {       if (x->son[str[i] -  a ] == NULL) {         x->son[str[i] -  a ] = new Aho();       }       insert(x->son[str[i] -  a ], i + 1, str);     } else {       x->cntstr++;     }   }   void calcFailEdges(Aho *root) {     deque<Aho *> q;     root->fail = root;     q.push_back(root);     while (!q.empty()) {       Aho *x = q.front();       q.pop_front();       for (int i = 0; i < 26; ++i) {         if (x->son[i] != NULL) {           q.push_back(x->son[i]);           Aho *pnt = x->fail;           if (x == root)             x->son[i]->fail = root;           else {             while (pnt != root && pnt->son[i] == NULL) {               pnt = pnt->fail;             }             if (pnt->son[i] != NULL)               x->son[i]->fail = pnt->son[i];             else               x->son[i]->fail = root;           }         }       }     }   }   int getDp(Aho *t) {     if (t->faildp == -1) {       t->faildp = t->cntstr;       t->faildp += getDp(t->fail);     }     return t->faildp;   }   const int MAX_N = 200000;   Aho *state[1 + MAX_N];   Aho *advance(Aho *t, char ch) {     while (t->fail != t && t->son[ch -  a ] == NULL) t = t->fail;     if (t->son[ch -  a ] == NULL) return t;     return t->son[ch -  a ];   }   Aho *state1[MAX_N], *state2[MAX_N];   void doStuff(int n, Aho **state, const string &str, const vector<string> &vec) {     Aho *T = new Aho();     for (int i = 0; i < n; ++i) insert(T, 0, vec[i]);     T->faildp = T->cntstr;     calcFailEdges(T);     Aho *pnt = T;     for (int i = 1; i <= str.size(); ++i) {       pnt = advance(pnt, str[i - 1]);       state[i] = pnt;     }   }   int main() {     int n;     string str;     cin >> str >> n;     vector<string> vec;     for (int i = 0; i < n; ++i) {       string p;       cin >> p;       vec.push_back(p);     }     doStuff(n, state1, str, vec);     for (int i = 0; i < n; ++i) reverse(vec[i].begin(), vec[i].end());     reverse(str.begin(), str.end());     doStuff(n, state2, str, vec);     long long rez = 0LL;     for (int i = 1; i < str.size(); ++i)       rez = (long long)getDp(state1[i]) * getDp(state2[str.size() - i]) + rez;     printf( %lld , rez);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int base = 101;   inline void chmax(int& x, int y) {     if (x < y) x = y;   }   inline void chmin(int& x, int y) {     if (x > y) x = y;   }   inline int LSB(int i) { return (i & -i); }   int n, m, dp[10005];   char s[10005], str[10005];   map<long long, string> mp;   vector<string> v;   inline long long Hash(int a, int b) { return (1LL * a * base + b) % MOD; }   int main() {     scanf( %d%s%d , &n, &s, &m);     for (int i = 0; i < m; i++) {       scanf( %s , &str);       long long h = 1;       for (int j = 0; j < strlen(str); j++) {         h = Hash(h, tolower(str[j]));       }       mp[h] = str;     }     fill(dp, dp + n, -1);     dp[0] = 0;     for (int i = 0; i < n; i++) {       long long h = 1;       for (int j = i; j >= 0; j--) {         h = Hash(h, s[j]);         if (dp[j] != -1 && mp.find(h) != mp.end()) {           dp[i + 1] = h;           break;         }       }     }     int p = n;     while (p > 0) {       v.push_back(mp[dp[p]]);       p -= mp[dp[p]].length();     }     reverse(v.begin(), v.end());     for (string& i : v) printf( %s  , &i[0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   int mk[705][705][3][3];   char s[705];   long long ck(int l, int r, int lc, int rc) {     if (l > r) return !lc || !rc || lc != rc;     if (mk[l][r][lc][rc]) return mk[l][r][lc][rc];     for (int i = l, cnt = 0;; i++) {       if (s[i] ==  ) )         cnt++;       else         cnt--;       if (!cnt) {         long long m = ck(l + 1, i - 1, 0, 1) * ck(i + 1, r, 1, rc) % p +                       ck(l + 1, i - 1, 0, 2) * ck(i + 1, r, 2, rc);         if (lc != 1) m += ck(l + 1, i - 1, 1, 0) * ck(i + 1, r, 0, rc);         if (lc != 2) m += ck(l + 1, i - 1, 2, 0) * ck(i + 1, r, 0, rc);         return mk[l][r][lc][rc] = m % p;       }     }   }   int main() {     scanf( %s , s + 1);     printf( %lld , ck(1, strlen(s + 1), 0, 0));   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   using ll = long long;   using ull = unsigned long long;   template <typename T>   void print(vector<T> v) {     for (T i : v) cout << i <<    ;     cout <<   n ;   }   template <typename T>   void print(vector<vector<T>>& v) {     for (vector<T>& vv : v) {       for (T& i : vv) cout << i <<    ;       cout <<   n ;     }   }   template <typename T>   void print(T&& t) {     cout << t <<   n ;   }   template <typename T, typename... Args>   void print(T&& t, Args&&... args) {     cout << t <<    ;     print(forward<Args>(args)...);   }   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto& i : v) os << i <<    ;     return os;   }   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void loop() {     ll n;     cin >> n;     vector<ll> a(n);     cin >> a;     if (n == 1) {       print( Alice );       return;     }     vector<ll> inc, dec;     inc.push_back(a[0]);     for (ll i = 0; i < n - 1; i++) {       if (a[i] < a[i + 1]) {         inc.push_back(a[i + 1]);       } else         break;     }     dec.push_back(a[n - 1]);     for (ll i = n - 1; i > 0; i--) {       if (a[i] < a[i - 1]) {         dec.push_back(a[i - 1]);       } else         break;     }     if (dec.size() % 2) {       print( Alice );       return;     } else if ((inc.size() - 1 + dec.size()) % 2 == 0) {       print( Alice );       return;     }     print( Bob );   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll t;     t = 1;     while (t--) {       loop();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int INF = 0x3f3f3f3f;   int n, m, a[maxn], b[maxn], f[maxn], g[maxn], l[maxn], p[maxn], ans[maxn];   bool vis[maxn];   int main() {     scanf( %d , &n);     for (int i = (1), _end_ = (n); i <= _end_; ++i) scanf( %d , &a[i]);     a[++n] = INF;     scanf( %d , &m);     for (int i = (1), _end_ = (m); i <= _end_; ++i) scanf( %d , &b[i]);     sort(b + 1, b + m + 1);     for (int i = (1), _end_ = (n + 1); i <= _end_; ++i) f[i] = INF;     for (int i = (1), _end_ = (n); i <= _end_; ++i)       if (a[i] != -1) {         int L = 1, R = n, pos = 0;         while (L <= R) {           int Mid = L + R >> 1;           if (f[Mid] < a[i]) {             pos = Mid;             L = Mid + 1;           } else             R = Mid - 1;         }         f[pos + 1] = a[i];         g[pos + 1] = i;         l[i] = pos + 1;         p[i] = g[pos];       } else {         int pos = n;         for (int j = m; j >= 1; --j) {           while (f[pos] >= b[j]) --pos;           f[pos + 1] = b[j];           g[pos + 1] = i;         }       }     for (int len = l[n], pos = n, val = a[n]; len >= 1; --len)       if (a[pos] != -1) {         if (a[p[pos]] != -1) {           pos = p[pos];           val = a[pos];         } else {           int t = lower_bound(b + 1, b + m + 1, val) - b - 1;           vis[t] = true;           pos = p[pos];           val = ans[pos] = b[t];         }       } else {         for (int i = pos - 1; i >= 1; --i)           if (a[i] != -1 && l[i] == len - 1 && a[i] < val) {             pos = i;             val = a[i];             goto Next;           }         for (int i = pos - 1; i >= 1; --i)           if (a[i] == -1) {             int t = lower_bound(b + 1, b + m + 1, val) - b - 1;             vis[t] = true;             pos = i;             val = ans[pos] = b[t];             goto Next;           }       Next:;       }     int pos = 1;     for (int i = (1), _end_ = (n - 1); i <= _end_; ++i)       if (a[i] != -1)         ans[i] = a[i];       else if (!ans[i]) {         while (vis[pos]) ++pos;         ans[i] = b[pos];         ++pos;       }     for (int i = (1), _end_ = (n - 1); i <= _end_; ++i) printf( %d  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getChar(char c) {     if (c ==  + ) return 1;     return 0;   }   string s;   stack<int> mystack;   int main() {     cin >> s;     int n = s.size();     int temp;     for (int i = 0; i < n; i++) {       temp = getChar(s[i]);       if (mystack.empty())         mystack.push(temp);       else {         if (mystack.top() == temp)           mystack.pop();         else           mystack.push(temp);       }     }     if (mystack.empty()) {       cout <<  Yes  << endl;       return 0;     }     cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   const double eps = 1e-9, Pi = 2 * acos(0);   int main() {     ifstream fin( input.txt );     ofstream fout( output.txt );     string s;     cin >> s;     map<string, int> make_pair;     for (int i = 0; i <= 9; i++) {       string x;       cin >> x;       make_pair[x] = i;     }     for (int i = 0; i < 8; i++) {       string x =   ;       for (int j = i * 10; j < (i + 1) * 10; j++) x += s[j];       cout << make_pair[x];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, memo[1 << 25];   pair<int, int> arr[30];   int dist(int a, int n) {     int k1 = arr[n].first - arr[a].first;     int k2 = arr[n].second - arr[a].second;     return k1 * k1 + k2 * k2;   }   int dp(int mask) {     if (__builtin_popcount(mask) == N) {       return 0;     }     if (memo[mask] != 0) return memo[mask];     int res = 1e9;     for (int i = 1; i <= N; i++) {       if (!((mask >> (i - 1) & 1))) {         res = min(res, dp(mask | (1 << (i - 1))) + 2 * dist(i, 0));         for (int j = i + 1; j <= N; j++) {           if (!(mask >> (j - 1) & 1) and i != j) {             res = min(res, dp(mask | (1 << (i - 1)) | (1 << (j - 1))) +                                dist(i, 0) + dist(i, j) + dist(j, 0));           }         }         break;       }     }     memo[mask] = res;     return res;   }   void backtrack(int mask) {     if (__builtin_popcount(mask) == N) {       return;     }     for (int i = 1; i <= N; i++) {       if (!((mask >> (i - 1) & 1))) {         if (dp(mask | (1 << (i - 1))) + 2 * dist(i, 0) == dp(mask)) {           cout << 0 <<     << i <<    ;           backtrack(mask | (1 << (i - 1)));           return;         }         for (int j = i + 1; j <= N; j++) {           if (!(mask >> (j - 1) & 1) and i != j) {             if (dp(mask | (1 << (i - 1)) | (1 << (j - 1))) + dist(i, 0) +                     dist(i, j) + dist(j, 0) ==                 dp(mask)) {               cout << 0 <<     << i <<     << j <<    ;               backtrack(mask | (1 << (i - 1)) | (1 << (j - 1)));               return;             }           }         }         break;       }     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> arr[0].first >> arr[0].second;     cin >> N;     for (int i = 1; i <= N; i++) cin >> arr[i].first >> arr[i].second;     cout << dp(0) << endl;     backtrack(0);     cout << 0 << endl;   }
#include <bits/stdc++.h>   using namespace std;   char a[51][51];   int main() {     memset(a,  0 , sizeof(a));     int n;     cin >> n;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         int x = a[i][j] -  0 ;         if (x != 0) {           if (a[i - 1][j - 1] !=  0 ) x--;           if (a[i - 1][j + 1] !=  0 ) x--;           if (a[i + 1][j - 1] !=  0 ) x--;           if (a[i + 1][j + 1] !=  0 ) x--;           if (x != 0) return cout <<  No , 0;         }       }     cout <<  Yes ;     return 0;   }