malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int bus_bin(int[], int, int, int);   int main() {     int n, k, q, i, j, l, y, aux, existeB;     scanf( %d%d , &n, &k);     int monedas[n];     for (i = 0; i < n; i++) scanf( %d , &monedas[i]);     scanf( %d , &q);     int cant[q];     for (i = 0; i < q; i++) scanf( %d , &cant[i]);     for (i = 0; i < q; i++) {       aux = cant[i];       existeB = bus_bin(monedas, 0, n - 1, aux);       if (existeB) {         cant[i] = 1;       } else {         cant[i] = k + 1;         for (y = 0; y < n && monedas[y] <= aux; y++) {           for (j = 1; j <= k && j * monedas[y] <= aux; j++) {             if (aux - j * monedas[y] == 0) {               if (j < cant[i]) cant[i] = j;             } else {               for (l = 1; l + j <= k; l++) {                 existeB = bus_bin(monedas, 0, n - 1, (aux - j * monedas[y]) / l);                 if ((aux - j * monedas[y]) % l == 0 && existeB) {                   if (j + l < cant[i]) cant[i] = j + l;                   break;                 }               }             }           }         }       }     }     for (i = 0; i < q; i++) {       printf( %d n , cant[i] > k ? -1 : cant[i]);     }     return 0;   }   int bus_bin(int v[], int ini, int fin, int x) {     int medio;     medio = (ini + fin) / 2;     if (v[medio] == x)       return 1;     else if (ini > fin)       return 0;     else if (x > v[medio])       return bus_bin(v, medio + 1, fin, x);     else if (x < v[medio])       return bus_bin(v, ini, medio - 1, x);   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   bool IsPowerOfTwo(long long int x) { return (x != 0) && ((x & (x - 1)) == 0); }   long long int poer(long long int a, long long int b) {     long long int rs = 1;     while (b > 0) {       if (b & 1) rs *= a;       a *= a;       b /= 2;     }     return rs;   }   long long int mod_poer(long long int a, long long int b, long long int mo) {     long long int rs = 1;     while (b > 0) {       if (b & 1) rs = (rs * a) % mo;       a = (a * a) % mo;       b /= 2;     }     return rs % mo;   }   long long int d, x, y;   void ext_euclid(long long int a, long long int b) {     if (b == 0) {       d = a;       x = 1;       y = 0;     } else {       ext_euclid(b, a % b);       long long int temp = x;       x = y;       y = temp - (a / b) * y;     }   }   long long int mod_inverse1(long long int a, long long int m) {     ext_euclid(a, m);     return (x % m + m) % m;   }   long long int mod_inverse2(long long int a, long long int m) {     return mod_poer(a, m - 2, m);   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int fact[200005];   void fac() {     fact[1] = fact[0] = 1;     for (long long int i = 2; i <= 200005; ++i) {       fact[i] = ((fact[i - 1] % mod) * i) % mod;     }   }   long long int combi(long long int a, long long int b) {     if (b > a) return 0;     if (b == a)       return 1;     else {       long long int x = mod_poer(fact[b], mod - 2, mod) % mod;       long long int y = mod_poer(fact[a - b], mod - 2, mod) % mod;       return ((((fact[a]) * x) % mod) * y) % mod;     }   }   long long int len[54];   string str1 =  What are you doing while sending   ;   string str2 =   ? Are you busy? Will you send   ;   string str3 =   ? ;   long long int len1 = str1.size();   long long int len2 = str2.size();   long long int len3 = str3.size();   string f0 =        What are you doing at the end of the world? Are you busy? Will you save          us? ;   char get(long long int n, long long int k) {     if (n > 54) {       if (k <= len1) return str1[k - 1];       return get(n - 1, k - len1);     }     if (n < 54 && k > len[n]) return  . ;     if (n == 0) return f0[k - 1];     if (k <= len1) return str1[k - 1];     if (k <= len1 + len[n - 1]) return get(n - 1, k - len1);     if (k <= len1 + len[n - 1] + len2) return str2[k - len1 - len[n - 1] - 1];     if (k <= len1 + len[n - 1] * 2 + len2)       return get(n - 1, k - len1 - len[n - 1] - len2);     return str3[k - len1 - len[n - 1] * 2 - len2 - 1];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     len[0] = f0.size();     for (long long int i = 1; i < 54; ++i) {       len[i] = (len[i - 1] * 2) + len1 + len2 + len3;     }     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       cout << get(n, k);     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void getint(int &v) {     char ch, fu = 0;     for (ch =  * ; (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) fu = 1, ch = getchar();     for (v = 0; ch >=  0  && ch <=  9 ; ch = getchar()) v = v * 10 + ch -  0 ;     if (fu) v = -v;   }   int n, k, a[1000010], ans;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     for (int i = 1; i <= k; ++i) ans += a[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[28 * 2];   bitset<1250005> bleh[28][28 * 2];   int sm;   vector<int> in[2];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < (signed)(n); i++) {       cin >> a[i];       sm += a[i];     }     for (int i = 0; i < (signed)(n); i++) {       cin >> a[i + n];       sm += a[i + n];     }     sort(a, a + 2 * n);     bleh[0][1][0] = true;     for (int i = (2); i <= (signed)(2 * n - 1); i++) {       bleh[0][i] = bleh[0][i - 1];       for (int j = (n - 1); j >= 1; j--) {         bleh[j][i] = bleh[j][i - 1] | (bleh[j - 1][i - 1] << a[i]);         for (int k = (0); k <= (signed)(400); k++) {           if (bleh[j][i][k]) {           }         }       }     }     int tot = sm - a[0] - a[1];     int wtmoo = tot / 2;     while (!bleh[n - 1][2 * n - 1][wtmoo]) {       --wtmoo;     }     int cur = wtmoo;     int cnt = n - 1;     for (int i = (2 * n - 2); i >= 1; i--) {       if (bleh[cnt][i][cur]) {         in[0].push_back(a[i + 1]);       } else {         in[1].push_back(a[i + 1]);         --cnt;         cur -= a[i + 1];       }     }     in[0].push_back(a[0]);     in[1].push_back(a[1]);     sort(in[0].begin(), in[0].end());     sort(in[1].begin(), in[1].end(), greater<int>());     for (int i = 0; i < (signed)(2); i++) {       for (int j = 0; j < (signed)(n); j++) {         cout << in[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   const double eps = (1e-5);   long long isGreater(long double x, long double y) {     if (abs(x - y) < eps) return 0;     if (x > y) return 1;     return -1;   }   long long n;   bool valid(long long i) { return i >= 0 && i < n; }   long long getSum(const vector<long long> &cum, long long l, long long r) {     long long ret = 0;     if (valid(r)) ret += cum[r];     if (valid(l - 1)) ret -= cum[l - 1];     return ret;   }   long long bestAns;   long long solve(vector<long long> a, long long d) {     long long sum = 0;     for (long long i = 0; i < (long long)(a).size(); ++i) {       a[i] = a[i] % d;       sum += a[i];       sum %= d;     }     if (sum != 0) return LLONG_MAX;     sum = 0;     long long size = 0;     long long ans = 0;     for (long long i = 0; i < (long long)(a).size(); ++i) {       sum += a[i];       size++;       if (sum >= d) {         long long extra = sum - d;         a[i] -= extra;         long long st = i - size + 1, en = i;         long long minSum = LLONG_MAX, temp = 0, inc = 0, dec = d;         for (long long j = st; j <= en; ++j) temp += 1LL * a[j] * (j - st + 1);         for (long long mid = st; mid <= en; ++mid) {           temp += inc;           temp -= dec;           dec -= a[mid];           inc += a[mid];           minSum = min(minSum, temp);         }         ans += minSum;         if (ans > bestAns) break;         a[i] = extra;         size = 0;         sum = 0;         --i;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<long long> a(n);     long long sum = 0;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];     }     if (sum == 1) {       cout << -1;       return 0;     }     bestAns = solve(a, sum);     for (long long i = 2; i <= sum / i; ++i) {       if (sum % i == 0) {         bestAns = min(bestAns, solve(a, i));         while (sum % i == 0) {           sum /= i;         }       }     }     if (sum > 1) bestAns = min(bestAns, solve(a, sum));     cout << bestAns;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + f * (c -  0 ), c = getchar();     return x;   }   const long long MAXN = 1e5 + 10;   long long n, m;   double f[MAXN];   double ans;   void ycl() {     long long x = n;     double a[MAXN], b[MAXN];     for (long long i = 1; i <= m; i++) a[i] = (double)i / m, b[i] = 1;     while (x > 0) {       if (x % 2 == 1) {         for (long long i = 1; i <= m; i++) b[i] *= a[i];       }       for (long long i = 1; i <= m; i++) a[i] *= a[i];       x /= 2;     }     for (long long i = 1; i <= m; i++) f[i] = b[i];   }   signed main() {     m = read();     n = read();     ycl();     for (long long i = 1; i <= m; i++) ans += (double)(f[i] - f[i - 1]) * i;     printf( %lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v(110, 0);   int main() {     int n, a, flag = 0, b;     vector<int> m;     cin >> n;     b = n;     while (n--) {       cin >> a;       m.push_back(a);       v[a]++;     }     sort(m.begin(), m.end());     for (int i = m[0]; i <= m[b - 1]; i++) {       for (int j = m[0]; j <= m[b - 1]; j++) {         if (i != j && v[i] == v[j] && (v[i] + v[j]) == b) {           flag = 1;           cout <<  YES  << endl << i <<     << j << endl;           break;         }       }       if (flag) break;     }     if (!flag) cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int time = INT_MAX, check = 0;     for (int i = 0; i < n; i++) {       check = 0;       int no = a[i];       for (int j = 0; j < no; j++) {         int item;         cin >> item;         check += item * 5;       }       check += no * 15;       time = min(time, check);     }     cout << time;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 12);   int cnt[maxn];   pair<int, int> res[maxn][maxn];   int pr[maxn][maxn];   int w[13];   int len;   int bsearch(int i, int k) {     int l = 0, r = len;     while (r - l > 1) {       int mid = (r + l) / 2;       if (res[i][mid].first <= k)         l = mid;       else         r = mid;     }     return l;   }   bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }   void counting_sort(int i) {     vector<int> cnts[1205];     for (int j = 0; j < len; j++) {       cnts[res[i][j].first].push_back(res[i][j].second);     }     int j = 0;     for (int k = 0; k < 1204; k++) {       while (!cnts[k].empty()) {         res[i][j] = {k, cnts[k].back()};         cnts[k].pop_back();         j++;       }     }   }   int main() {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     len = (1 << n);     for (int i = 0; i < n; i++) {       scanf( %d , &w[n - i - 1]);     }     for (int i = 0; i < m; i++) {       int num = 0;       for (int j = 0; j < n; j++) {         char c = getchar();         while (c !=  0  && c !=  1 ) {           c = getchar();         }         num *= 2;         num += (c -  0 );       }       cnt[num]++;     }     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < (1 << n); j++) {         int ans = 0;         for (int k = 0; k < n; k++) {           if (((1 << k) & i) == ((1 << k) & j)) ans += w[k];         }         res[i][j] = {ans, cnt[j]};       }       counting_sort(i);       pr[i][0] = res[i][0].second;       for (int j = 1; j < (1 << n); j++) {         pr[i][j] = pr[i][j - 1] + (res[i][j].second);       }     }     for (int i = 0; i < q; i++) {       int num = 0;       for (int j = 0; j < n; j++) {         char c = getchar();         while (c !=  0  && c !=  1 ) {           c = getchar();         }         num *= 2;         num += (c -  0 );       }       int k;       scanf( %d , &k);       int ind = bsearch(num, k);       printf( %d n , pr[num][ind]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int m, n, i;   long long int a[1000000], ans, sum[1000000] = {0}, x;   int check(long long int k) {     x = 0;     for (i = 1; i <= n; i++) {       if (a[i] - (i - 1) / k > 0) x = x + a[i] - (i - 1) / k;     }     if (x >= m)       return 1;     else       return 0;   }   int binsearch(long long int low, long long int high) {     while (low < high) {       long long int mid = (low + high) / 2;       if (check(mid))         high = mid;       else         low = mid + 1;     }     if (!check(low)) low = -1;     return low;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + 1 + n, greater<int>());     for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];     ans = binsearch(1, n);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str[101];     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> str[i];     int maxi = 1;     for (int i = 0; i < n - 1; ++i) {       int m = 1;       for (int j = i + 1; j < n; ++j) {         if (str[i] == str[j]) ++m;       }       maxi = max(m, maxi);     }     cout << maxi << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5, INF = 1e9;   string s2, s;   struct data {     int next[30];     int cnt;     bool least;   };   data t[N];   int sz = 1, ans;   string p;   inline void add(string s) {     int v = 0;     t[v].cnt++;     for (int i = 0; i < s.size(); ++i) {       int x = s[i] -  a ;       if (t[v].next[x] == -1) {         t[v].next[x] = sz;         sz++;       }       v = t[v].next[x];       t[v].cnt++;     }     t[v].least = true;   }   map<string, bool> usd;   bool flag;   inline void f(int &pos) {     int v = 0;     int c = -1;     int k = 0;     if (t[v].next[s[pos] -  a ] == -1) {       pos--;       return;     }     while (s[pos] >=  a  && s[pos] <=  z ) {       int x = s[pos] -  a ;       if (t[v].next[x] == -1) break;       k++;       if (k >= 2 && t[v].cnt == 1) c++;       p += s[pos];       v = t[v].next[x];       pos++;     }     pos--;     ans += k;     if (c != -1 && t[v].least == 1) ans -= c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     for (int i = 0; i <= 300000; ++i) {       for (int j = 0; j <= 26; ++j) {         t[i].next[j] = -1;       }       t[i].cnt = 0;       t[i].least = false;     }     while (getline(cin, s2)) {       s += s2;       s +=    ;     }     for (int i = 0; i < s.size(); ++i) {       if (!flag && s[i] >=  a  && s[i] <=  z )         flag = true, f(i);       else {         ans++;         if (s[i] >=  a  && s[i] <=  z )           p += s[i];         else if (p !=   ) {           if (!usd[p]) add(p), usd[p] = true;           p =   ;         }         if (s[i] <  a  || s[i] >  z ) flag = false;       }     }     cout << ans;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   const int MAXN = 1e5 + 9;   const int MOD = (int)(1e9 + 7);   const int LOG2MAXN = 17;   const int INF = 1e9;   const long double eps = 1e-9;   int di[] = {0, 1, 0, -1};   int dj[] = {1, 0, -1, 0};   char ddir[] = { R ,  U ,  L ,  D };   mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   int n, m;   vector<vector<int> > gg;   bool used[MAXN];   void cry() {     cout <<  NO ;     exit(0);   }   int ans[111][111];   char cc[111][111];   void solve() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> cc[i][j];     int mx = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         bool ok = 1;         for (int tmp = 0; tmp < k; tmp++)           if (i + tmp >= n || cc[i + tmp][j] ==  # ) ok = 0;         if (ok)           for (int tmp = 0; tmp < k; tmp++) ans[i + tmp][j]++;         ok = 1;         for (int tmp = 0; tmp < k; tmp++)           if (j + tmp >= n || cc[i][j + tmp] ==  # ) ok = 0;         if (ok)           for (int tmp = 0; tmp < k; tmp++) ans[i][j + tmp]++;         mx = max(mx, ans[i][j]);       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (ans[i][j] == mx) {           cout << i + 1 <<     << j + 1 << endl;           return;         }   }   void input() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, f[105], s[105], ans;   int Getf(int x) { return (f[x] == x ? x : Getf(f[x])); }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) f[i] = i, s[i] = 1;     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       int tx = Getf(x), ty = Getf(y);       if (tx == ty && (s[ty] & 1)) ans++;       f[tx] = ty;       s[ty] += s[tx];     }     if ((n - ans) % 2 != 0) ans++;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, i, left, right, p[52];     vector<long long> bin;     cin >> n >> m;     m--;     while (m) {       if (m & 1)         bin.push_back(1);       else         bin.push_back(0);       m /= 2;     }     for (i = bin.size(); i < n - 1; i++) bin.push_back(0);     reverse(bin.begin(), bin.end());     left = 0;     right = n - 1;     for (i = 0; i < n - 1; i++) {       if (bin[i]) {         p[right] = i + 1;         right--;       } else {         p[left] = i + 1;         left++;       }     }     p[left] = i + 1;     for (i = 0; i < n - 1; i++) cout << p[i] <<    ;     cout << p[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, l, r;     cin >> n >> l >> r;     long long mn[l], t1 = 1, mx[r], sum1 = 0, sum2 = 0;     for (int i = 0; i < l; i++) {       mn[i] = t1;       sum1 += mn[i];       t1 *= 2;     }     for (int i = 0; i < n - l; i++) {       sum1 += mn[0];     }     t1 = 1;     for (int i = 0; i < r; i++) {       mx[i] = t1;       t1 *= 2;       sum2 += mx[i];     }     for (int i = 0; i < n - r; i++) {       sum2 += mx[r - 1];     }     cout << sum1 <<     << sum2;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m;   void solve() {     cin >> n >> m;     vector<vector<long long int>> v(m, vector<long long int>(n));     vector<long long int> sum(n);     for (long long int i = 0; i < (m); i++) {       for (long long int j = 0; j < (n); j++) {         cin >> v[i][j];       }     }     vector<long long int> ans(m);     for (long long int i = 1; i < (m + 1); i++) ans[i - 1] = i;     for (long long int i = 0; i < (n - 1); i++) {       vector<pair<long long int, long long int>> p(m);       long long int diff = 0;       for (long long int j = 0; j < (m); j++) {         p[j] = make_pair(v[j][i] - v[j][n - 1], j);         diff += p[j].first;       }       sort((p).begin(), (p).end());       vector<long long int> newans;       for (long long int w = 0; w < (m); w++) {         if (diff >= 0) break;         newans.push_back(p[w].second + 1);         diff -= p[w].first;       }       if (newans.size() < ans.size()) {         ans = newans;       }     }     cout << ans.size() << endl;     for (long long int x : ans) {       cout << x <<    ;     }     cout << endl;   }   int main() {     long long int t;     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long A, B, C, D, X, Y;   inline long long gcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long res = gcd(b, a % b, x, y);     long long t = x;     x = y;     y = t - (a / b) * y;     return res;   }   int main() {     scanf( %lld %lld %lld , &A, &B, &C);     C = -C;     D = gcd(A, B, X, Y);     if (C % D)       puts( -1 );     else {       C /= D;       printf( %lld %lld n , X * C, Y * C);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > z[200010], f[200010];   map<int, int> use[200010];   int n, m, k, dir;   int sx, sy;   inline void insert(int x, int y) {     z[x - y + m + 1].insert(make_pair(x, y));     f[x + y].insert(make_pair(x, y));     use[x][y] = 1;   }   void init() {     char s[3];     scanf( %d%d%d , &n, &m, &k);     for (int i = 1, x, y; i <= k; i++) {       scanf( %d%d , &x, &y);       insert(x, y);     }     scanf( %d%d%s , &sx, &sy, s);     dir = (s[1] ==  E ) | ((s[0] ==  S ) << 1);     for (int i = 0; i <= n + 1; i++) insert(i, 0), insert(i, m + 1);     for (int i = 0; i <= m + 1; i++) insert(0, i), insert(n + 1, i);   }   void go(int x, int y, int d, int &x1, int &y1, int &d1, int &px, int &py) {     int a, b;     if (d == 0) {       set<pair<int, int> >::iterator p =           z[x - y + m + 1].lower_bound(make_pair(x, y));       p--;       px = p->first;       py = p->second;       a = use[px + 1].count(py);       b = use[px].count(py + 1);       if (!a && b) {         x1 = px + 1;         y1 = py;         d1 = 2;       } else if (a && !b) {         x1 = px;         y1 = py + 1;         d1 = 1;       } else {         x1 = px + 1;         y1 = py + 1;         d1 = 3;       }     } else if (d == 1) {       set<pair<int, int> >::iterator p = f[x + y].lower_bound(make_pair(x, y));       p--;       px = p->first;       py = p->second;       a = use[px + 1].count(py);       b = use[px].count(py - 1);       if (!a && b) {         x1 = px + 1;         y1 = py;         d1 = 3;       } else if (a && !b) {         x1 = px;         y1 = py - 1;         d1 = 0;       } else {         x1 = px + 1;         y1 = py - 1;         d1 = 2;       }     } else if (d == 2) {       set<pair<int, int> >::iterator p = f[x + y].upper_bound(make_pair(x, y));       px = p->first;       py = p->second;       a = use[px - 1].count(py);       b = use[px].count(py + 1);       if (!a && b) {         x1 = px - 1;         y1 = py;         d1 = 0;       } else if (a && !b) {         x1 = px;         y1 = py + 1;         d1 = 3;       } else {         x1 = px - 1;         y1 = py + 1;         d1 = 1;       }     } else {       set<pair<int, int> >::iterator p =           z[x - y + m + 1].upper_bound(make_pair(x, y));       px = p->first;       py = p->second;       a = use[px - 1].count(py);       b = use[px].count(py - 1);       if (!a && b) {         x1 = px - 1;         y1 = py;         d1 = 1;       } else if (a && !b) {         x1 = px;         y1 = py - 1;         d1 = 2;       } else {         x1 = px - 1;         y1 = py - 1;         d1 = 0;       }     }   }   void solve() {     long long ans = 0;     int rep = 0;     int xx, yy, dd, px, py;     go(sx, sy, dir, sx, sy, dir, px, py);     for (int x = sx, y = sy, d = dir;; x = xx, y = yy, d = dd) {       go(x, y, d, xx, yy, dd, px, py);       ans += abs(x - px);       if (xx == sx && yy == sy && dd == dir) break;       if (dd + d == 3) rep = 1;     }     if (rep) ans >>= 1;     printf( %I64d n , ans);   }   int main() {     init();     solve();     return 0;   }