malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:16777216 )   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:16777216 )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   const int inf = 2e9;   const long long linf = 5000000000000000000;   const long double LDINF = 2e18;   template <typename T>   void print(vector<T>& a) {     for (int i = 0; i < a.size(); i++) cout << a[i] <<    ;     cout <<   n ;   }   template <typename T>   void print(deque<T>& a) {     for (int i = 0; i < a.size(); i++) cout << a[i] <<    ;     cout <<   n ;   }   template <typename T>   void print(vector<vector<T>>& a) {     for (int i = 0; i < a.size(); i++) {       for (int j = 0; j < a[i].size(); j++) cout << a[i][j] <<    ;       cout <<   n ;     }   }   template <typename T>   void input(vector<T>& a) {     for (int i = 0; i < a.size(); i++) cin >> a[i];   }   template <typename T>   void input(deque<T>& a) {     for (int i = 0; i < a.size(); i++) cin >> a[i];   }   template <typename T>   void input(vector<vector<T>>& a) {     for (int i = 0; i < a.size(); i++)       for (int j = 0; j < a[i].size(); j++) cin >> a[i][j];   }   long long mod = 998244353;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   vector<int> p, rang;   void CreateSet(int v) {     p[v] = v;     rang[v] = 1;   }   int FindSet(int v) {     if (p[v] == v) return v;     return p[v] = FindSet(p[v]);   }   vector<pair<int, int>> ans;   void UnionSet(int a, int b) {     a = FindSet(a);     b = FindSet(b);     if (a == b) return;     if (rang[a] < rang[b]) swap(a, b);     p[b] = a;     if (rang[a] == rang[b]) rang[a]++;     ans.push_back({a, b});   }   void solve() {     long long n, d;     cin >> n;     long long a = 0, b = 0;     for (int i = 0; i < n; i++) {       cin >> d;       a |= d;     }     for (int i = 0; i < n; i++) {       cin >> d;       b |= d;     }     cout << a + b;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tst = 1;     while (tst--) solve();   }
#include <bits/stdc++.h>   struct Data {     std::vector<int> nums;     std::string str;   };   struct Interval {     int start;     int end;     std::string* data;   };   bool compareIntervals(const Interval& a, const Interval& b) {     if (a.start < b.start) return true;     if (a.start > b.start) return false;     return a.end < b.end;   }   int main() {     std::cin.tie(0);     std::ios_base::sync_with_stdio(0);     int numSteps;     std::cin >> numSteps;     size_t finalLength = 0;     std::vector<Data> steps(numSteps);     int numIntervals = 0;     for (int i = 0; i < steps.size(); ++i) {       std::cin >> steps[i].str;       int occurrences;       std::cin >> occurrences;       steps[i].nums.resize(occurrences);       numIntervals += occurrences;       for (int k = 0; k < occurrences; ++k) std::cin >> steps[i].nums[k];       finalLength =           std::max(finalLength, steps[i].nums.back() - 1 + steps[i].str.size());     }     std::vector<Interval> intervals(numIntervals);     int intervalsIdx = 0;     for (int i = 0; i < steps.size(); ++i) {       for (int j = 0; j < steps[i].nums.size(); ++j) {         Interval& curr = intervals[intervalsIdx];         curr.start = steps[i].nums[j] - 1;         curr.end = curr.start + steps[i].str.size();         curr.data = &steps[i].str;         ++intervalsIdx;       }     }     std::sort(intervals.begin(), intervals.end(), compareIntervals);     std::string out(finalLength,  a );     int doneIdx = 0;     for (int i = 0; i < intervals.size(); ++i) {       for (int idx = std::max(doneIdx, intervals[i].start);            idx < intervals[i].end; ++idx) {         out[idx] = (*intervals[i].data)[idx - intervals[i].start];       }       doneIdx = std::max(doneIdx, intervals[i].end);     }     std::cout << out <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<bool> isprime(1005, true);   vector<long long> spf(1005, 0);   vector<long long> prime;   void sieve() {     isprime[0] = isprime[1] = false;     for (long long i = 2; i < 1005; i++) {       if (isprime[i]) {         for (long long j = 2 * i; j < 1005; j += i) {           isprime[j] = false;           if (spf[j] == 0) {             spf[j] = i;           }         }         prime.push_back(i);       }     }   }   long long power(long long k, long long n, long long m = 1000000007) {     long long res = 1;     while (n) {       if (n % 2 != 0) {         res = (res * k) % m;       }       k = (k * k) % m;       n = n / 2;     }     return (res);   }   void READ(vector<long long> &v, long long n) {     long long a;     for (long long i = 0; i < n; i = i + 1) {       cin >> a;       v.push_back(a);     }   }   void PRINT(vector<long long> &v, long long a = 0) {     for (long long i = a; i < v.size(); i = i + 1) {       cout << v[i] <<    ;     }     cout <<   n ;   }   long long n, m, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     std::cout.unsetf(std::ios::floatfield);     std::cout.precision(12);     long long a, b, c, d, e, x, i, j, t, y, w, z, x1, y1, z1, f;     string str, str1, str2, str4;     cin >> n >> a >> b;     if (a * b >= 6 * n) {       cout << a * b <<   n  << a <<     << b;       exit(0);     }     x = y = 1e18;     d = 0;     for (j = 0;; j++) {       c = 0;       for (i = min(a, b); i * i <= 6 * n + j; i++) {         if ((6 * n + j) % i == 0) {           if (i >= a && (6 * n + j) / i >= b) {             x = i;             y = (6 * n + j) / i;             c = 1;             break;           }           if (i >= b && (6 * n + j) / i >= a &&               i - b + (6 * n + j) / i - a < x - a + y - b) {             y = i;             x = (6 * n + j) / i;             c = 1;             break;           }         }       }       if (c) {         break;       }     }     cout << x * y <<   n  << x <<     << y;   }
#include <bits/stdc++.h>   const double pi = 3.1415926535897932384626433832795;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   using namespace std;   void ifd() {}   void tme() {}   int n, k, h;   vector<pair<int, pair<int, int> > > l;   vector<int> answer;   bool can(double time) {     int cnt = 0;     int pos = 0;     while (pos < n && cnt < k) {       if (((double)l[pos].second.first * time) >= ((double)(cnt + 1) * h)) {         pos++;         cnt++;       } else {         pos++;       }     }     return cnt == k;   }   double bs() {     double low = 0, high = 1e10, mid;     for (int i = (0); i < (200); ++i) {       mid = (low + high) / 2;       if (can(mid))         high = mid;       else         low = mid;     }     return high;   }   int main() {     ifd();     cin >> n >> k >> h;     l.resize(n);     for (int i = (0); i < (n); ++i) {       cin >> l[i].first;     }     for (int i = (0); i < (n); ++i) {       cin >> l[i].second.first;       l[i].second.second = i + 1;     }     sort(l.begin(), l.end());     double time = bs();     int cnt = 0;     int pos = 0;     while (pos < n && cnt < k) {       if (((double)l[pos].second.first * time) >= ((double)(cnt + 1) * h)) {         answer.push_back(l[pos].second.second);         pos++;         cnt++;       } else {         pos++;       }     }     for (int i = (0); i < (k - 1); ++i) cout << answer[i] <<    ;     cout << answer[k - 1] << endl;     tme();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   const int INF = 1e9;   int _w;   int n, a[MAXN], b[MAXN];   namespace MCMF {   const int MAXV = 1000000;   const int MAXE = 1000000;   struct Edge {     int u, v, c, f, w;     Edge() {}     Edge(int u, int v, int c, int f, int w) : u(u), v(v), c(c), f(f), w(w) {}   };   int n, m, s, t;   int head[MAXV], nxt[MAXE << 1];   Edge edge[MAXE << 1];   void init(int nn) {     n = nn, m = 0;     for (int i = 1; i <= n; ++i) head[i] = -1;   }   void adde(int u, int v, int c, int w) {     edge[m] = Edge(u, v, c, 0, w);     nxt[m] = head[u], head[u] = m++;     edge[m] = Edge(v, u, 0, 0, -w);     nxt[m] = head[v], head[v] = m++;   }   queue<int> q;   int inq[MAXV], dis[MAXV], res[MAXV], pre[MAXV];   bool spfa() {     for (int i = 1; i <= n; ++i) inq[i] = 0, dis[i] = -INF;     q.push(s), inq[s] = 1, dis[s] = 0, res[s] = INF;     while (!q.empty()) {       int u = q.front();       q.pop();       inq[u] = 0;       for (int i = head[u]; ~i; i = nxt[i]) {         Edge &e = edge[i];         if (e.c > e.f && dis[e.v] < dis[u] + e.w) {           dis[e.v] = dis[u] + e.w;           res[e.v] = min(res[u], e.c - e.f);           pre[e.v] = i;           if (!inq[e.v]) {             inq[e.v] = 1;             q.push(e.v);           }         }       }     }     return dis[t] != -INF;   }   void augment() {     int u = t, f = res[t];     while (u != s) {       int i = pre[u];       edge[i].f += f;       edge[i ^ 1].f -= f;       u = edge[i].u;     }   }   int solve(int ss, int tt) {     s = ss, t = tt;     int ans = 0, flow = 0;     while (spfa()) {       augment();       ans += dis[t] * res[t];       flow += res[t];     }     return ans;   }   }  // namespace MCMF   int id1[27], id2[27][MAXN], id3[MAXN], s, t, nid;   void solve() {     for (int i = 1; i <= 26; ++i) id1[i] = ++nid;     for (int i = 1; i <= 26; ++i)       for (int j = 1; j <= n / 2; ++j) id2[i][j] = id2[i][n - j + 1] = ++nid;     for (int i = 1; i <= n; ++i) id3[i] = ++nid;     s = ++nid, t = ++nid;     MCMF::init(nid);     for (int i = 1; i <= n; ++i) MCMF::adde(s, id1[a[i]], 1, 0);     for (int i = 1; i <= 26; ++i)       for (int j = 1; j <= n / 2; ++j) MCMF::adde(id1[i], id2[i][j], 1, 0);     for (int i = 1; i <= 26; ++i)       for (int j = 1; j <= n; ++j)         MCMF::adde(id2[i][j], id3[j], 1, a[j] == i ? b[j] : 0);     for (int i = 1; i <= n; ++i) MCMF::adde(id3[i], t, 1, 0);     printf( %d n , MCMF::solve(s, t));   }   int main() {     _w = scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       char c;       _w = scanf(  %c , &c);       a[i] = c -  a  + 1;     }     for (int i = 1; i <= n; ++i) _w = scanf( %d , b + i);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef int *arrint;   const int maxn = 2e3 + 55;   int main() {     int h1, h2, a, b, i, j, k;     scanf( %d , &h1), scanf( %d , &h2);     scanf( %d , &a), scanf( %d , &b);     k = 0;     i = h1;     j = 1;     while (i < h2) {       if (j == 1) {         i = i + a * 8;         j = 0;         if (a <= b && i < h2) {           k = -1;           break;         }       } else {         i = i + a * 12;       }       if (i >= h2) {         break;       } else {         k++;         i -= b * 12;       }     }     printf( %d , k), printf( %c ,   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     long long n = s.length();     reverse(s.begin(), s.end());     set<string> ans;     vector<bool> dp2(n + 1, 0), dp3(n + 1, 0);     dp2[1] = 1;     dp3[2] = 1;     for (long long i = 3; i < n - 5; ++i) {       dp2[i] = dp3[i - 2] ||                (dp2[i - 2] && !(s[i] == s[i - 2] && s[i - 1] == s[i - 3]));       dp3[i] = dp3[i] || dp2[i - 3];       if (i - 5 >= 0)         dp3[i] =             dp3[i] || (dp3[i - 3] && !(s[i] == s[i - 3] && s[i - 1] == s[i - 4] &&                                        s[i - 2] == s[i - 5]));     }     for (long long i = 0; i < n - 5; ++i) {       if (dp2[i]) {         string temp = s.substr(i - 1, 2);         reverse(temp.begin(), temp.end());         ans.insert(temp);       }       if (dp3[i]) {         string temp = s.substr(i - 2, 3);         reverse(temp.begin(), temp.end());         ans.insert(temp);       }     }     cout << ans.size() <<   n ;     for (string i : ans) cout << i <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, i;     cin >> n;     int ara[n];     for (int i = 0; i < n; ++i) {       cin >> ara[i];     }     for (i = 1; i < n; i++) {       if (ara[i] != ara[i - 1]) {         cout <<  1 n ;         return;       }     }     cout << n << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using ll = long long;   using namespace std;   const int N = 1e6 + 10;   const int Mod = 0;   ll a[N], sum[N], p[N];   int n, m, T, q;   int Read();   void update(ll x) {     vector<ll> v;     x--;     int cnt = 0;     if (n <= 14) {       for (int i = 1; i <= 14; i++) v.push_back(i);     } else {       for (int i = 1; i <= 14; i++) v.push_back(n - 14 + i);     }     for (int i = min(13, n - 1); i >= 0; i--) {       int j = x / p[i];       a[++cnt] = v[j];       x %= p[i];       v.erase(v.begin() + j);     }     int st = max(n - 13, 1);     for (int i = st, xx = 1; i <= n; i++, xx++) {       sum[i] = sum[i - 1] + a[xx];     }   }   int main() {     n = Read(), q = Read();     for (int i = 1; i <= n; ++i) {       a[i] = i;       sum[i] = sum[i - 1] + i;     }     p[0] = 1;     for (int i = 1; i <= 14; i++) p[i] = p[i - 1] * i;     ll now = 1;     for (int i = 1; i <= q; i++) {       int opt;       opt = Read();       if (opt == 1) {         int x = Read(), y = Read();         printf( %lld n , sum[y] - sum[x - 1]);       } else {         int x = Read();         now += x;         update(now);       }     }     return 0;   }   int Read() {     int val = 0, opt = 1;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) opt = -1;     while (isdigit(ch)) (val *= 10) += ch -  0 , ch = getchar();     return val * opt;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     long long n, k;     cin >> n >> k;     string s;     long long lo = 1, hi = n;     while (1) {       long long mid = lo + hi >> 1;       if (hi - lo <= 50) {         long long guess = rng() % (hi - lo + 1) + lo;         cout << guess <<     << guess << endl;         cin >> s;         if (s ==  Yes ) exit(0);         lo = max(1ll, lo - k), hi = min(n, hi + k);         continue;       }       cout << lo <<     << mid << endl;       cin >> s;       if (s ==  Yes )         lo = max(lo - k, 1ll), hi = min(mid + k, n);       else         lo = max(mid - k, 1ll), hi = min(hi + k, n);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 50;   char s[N], t[N];   int n, a[N], b[N], c[N];   int main(void) {     scanf( %d , &n);     scanf( %s , s);     scanf( %s , t);     for (int i = 0; i < n; i++) {       a[i] = s[i] -  a ;       b[i] = t[i] -  a ;     }     for (int i = 0; i < n; i++) {       c[i] += (a[i] + b[i]) / 2;       if ((a[i] + b[i]) % 2) {         c[i + 1] += 13;       }     }     for (int i = n - 1; i >= 0; i--) {       c[i - 1] += c[i] / 26;       c[i] %= 26;     }     for (int i = 0; i < n; i++) {       printf( %c , (char)( a  + c[i]));     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     int dif;     int n, m;     bool ans = true;     char flag[100][101];     cin >> n >> m;     for (i = 0; i < n; i++) cin >> flag[i];     for (i = 0; i < n; i++) {       dif = flag[i][0];       for (j = 1; j < m; j++)         if (flag[i][j] != dif) ans = false;     }     for (i = 1; i < n - 1; i++)       for (j = 0; j < m; j++)         if (flag[i][j] == flag[i - 1][j] || flag[i][j] == flag[i + 1][j]) {           ans = false;           break;         }     if (ans)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, e[111111], x, y, s, t, l, r, c, cc, yy[555555], pp[555555],       xx[555555], f[111111], rr[111111], q1, q2, kk, p[111111], ll;   int qx[444444], qc[444444], ql[444444];   int find(int x) {     int y = x;     while (x != p[x]) x = p[x];     while (x != y) {       int t = p[y];       p[y] = x;       y = x;     }     return x;   }   void add(int x, int cc, int l) {     if (f[x]) {       if (rr[x] + l <= c) p[find(cc)] = find(f[x] - 1);       return;     }     rr[x] = l;     f[x] = cc + 1;     qx[q1] = x;     qc[q1] = cc;     ql[q1++] = l;   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) cin >> e[i], e[i]--;     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--;       y--;       yy[++kk] = y;       pp[kk] = xx[x];       xx[x] = kk;       yy[++kk] = x;       pp[kk] = xx[y];       xx[y] = kk;     }     cin >> s >> t;     e[k++] = t - 1;     l = 1;     r = n + 5;     while (l < r) {       c = (l + r) / 2;       for (int i = 0; i < n; i++) p[i] = i;       memset(f, 0, sizeof(f));       q1 = q2 = 0;       for (int i = 0; i < k; i++) add(e[i], e[i], 0);       while (q1 != q2) {         x = qx[q2];         cc = qc[q2];         ll = ql[q2++];         for (int w = xx[x]; w; w = pp[w]) add(yy[w], cc, ll + 1);       }       if (find(s - 1) == find(t - 1))         r = c;       else         l = c + 1;     }     if (l == n + 5)       puts( -1 );     else       cout << (l) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const unsigned long long MOD = 1e9 + 7;   const int INF = 1e9;   const unsigned long long INF64 = 9e18;   const long double EPS = 1e-9;   const long double PI = 3.14159265358979310000;   const unsigned long long MD = 535355424;   const unsigned long long T = 25342;   const int N = 200001;   const int M = 501;   int n, k;   bool prov(unsigned long long v) {     unsigned long long s = 0, kk = 1;     while (v / kk > 0) {       s += v / kk;       kk *= k;     }     if (s >= n)       return 1;     else       return 0;   }   int main() {     cin >> n >> k;     if (k == 1) {       cout << 1 << endl;       return 0;     }     unsigned long long l, r, m;     l = 0;     r = INF64;     while (l + 1 < r) {       m = (l + r) / 2;       if (prov(m))         r = m;       else         l = m;     }     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       int a;       cin >> a;       arr[i] = a;     }     sort(arr, arr + n);     for (int j = 0; j < n; j++) {       cout << arr[j] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100010];   vector<int> v;   int main(void) {     int n, k, i, j, totalcnt;     scanf( %d %d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       v.push_back(arr[i]);       ;     }     if (k == 1) {       sort(v.begin(), v.end());       printf( 1 n );     } else {       int cnt = 0, sum = 0, mn = (1 << 29), indx, flag = 0;       totalcnt = 0;       for (i = 1; i <= n; i++) {         sum = 0;         cnt = 0;         for (j = i;; j += k) {           if (j > n) j %= n;           sum += arr[j];           totalcnt++;           cnt++;           if (cnt == (n / k)) {             break;           }         }         if (mn > sum) {           indx = i;           mn = sum;         }         if (totalcnt == n) break;       }       printf( %d n , indx);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n;   int k;   map<int, int> mp;   int S;   long long res;   struct linetree {     map<int, int> rot;     int s[22 * N][2];     int v[22 * N];     int ct;     inline void ins(int p, int l, int r, int pos) {       v[p]++;       if (r - l == 1) {         return;       }       int mid = (l + r) / 2;       if (pos <= mid)         ins(s[p][0] = s[p][0] ? s[p][0] : ++ct, l, mid, pos);       else         ins(s[p][1] = s[p][1] ? s[p][1] : ++ct, mid, r, pos);     }     inline int qry(int p, int l, int r, int dl, int dr) {       if ((dl == l && dr == r) || p == 0) {         return v[p];       }       int mid = (l + r) / 2;       int res = 0;       if (dl < mid) res += qry(s[p][0], l, mid, dl, min(dr, mid));       if (mid < dr) res += qry(s[p][1], mid, r, max(dl, mid), dr);       return res;     }     inline void cins(int q, int x) {       if (rot.count(q) == 0) rot[q] = ++ct;       ins(rot[q], 0, S, x);     }     inline int cqr(int q, int dl, int dr) {       if (rot.count(q) == 0) return 0;       return qry(rot[q], 0, S, dl, dr);     }   } lt;   struct data {     int x;     int r;     int q;     friend bool operator<(data a, data b) { return a.r > b.r; }   } a[N];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d%d%d , &a[i].x, &a[i].r, &a[i].q);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       mp[a[i].x] = 1;       mp[a[i].x + a[i].r] = 1;       mp[a[i].x - a[i].r] = 1;     }     map<int, int>::iterator it, it1;     for (it = mp.begin(), it1 = it, ++it1; it1 != mp.end(); ++it, ++it1)       it1->second += it->second;     S = mp.size();     for (int i = 1; i <= n; i++) {       for (int j = a[i].q - k; j <= a[i].q + k; j++)         res += lt.cqr(j, mp[a[i].x - a[i].r] - 1, mp[a[i].x + a[i].r]);       lt.cins(a[i].q, mp[a[i].x]);     }     printf( %I64d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int OO = INT_MAX, P = 10000;   int xd[] = {1, 0, -1, 0, -1, 1, 1, -1};   int yd[] = {0, -1, 0, 1, 1, 1, -1, -1};   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long int t;     cin >> t;     while (t--) {       long long int l, r;       cin >> l >> r;       if (l * 2 > r)         cout << -1 <<     << -1 <<   n ;       else         cout << l <<     << 2 * l <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n + 1, 0), ans(n + 1, -1), visited(n + 1, 0);     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > a[i - 1]) {         ans[i] = a[i - 1];         visited[a[i]] = 1;       }     }     int j = 1;     for (int i = 1; i <= n; i++) {       if (ans[i] == -1) {         while (j <= n && visited[j]) j++;         ans[i] = j;         visited[j] = 1;       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, a[1005], b[1005], c[1005], d[1005], ans, tot;   ;   char s[1005];   long long calc() {     long long cc = 0;     for (long long i = 1; i <= n; i++)       if (c[i]) {         ans += (c[i] - 1) * (m - c[i]) * 4;         for (long long j = i + 1; j <= n; j++)           if (!c[j] || c[j] < c[j - 1])             break;           else             cc += (c[i] - 1) * (m - c[j]) * 4;         for (long long j = i + 1; j <= n; j++)           if (!c[j] || c[j] > c[j - 1])             break;           else             cc += (c[j] - 1) * (m - c[i]) * 4;       }     return cc;   }   int main() {     scanf( %I64d%I64d , &n, &m);     for (long long i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (long long j = 1; j <= m; j++)         if (s[j] ==  . )           tot++, a[i]++, b[j]++;         else           c[i] = j, d[j] = i;     }     long long o, ct, su;     o = ct = su = 0;     for (long long i = 1; i <= n; i++) o += su * a[i], ct += a[i], su += ct;     ans = o * 2;     o = ct = su = 0;     for (long long i = 1; i <= m; i++) o += su * b[i], ct += b[i], su += ct;     ans += o * 2;     ans += calc();     swap(n, m);     for (long long i = 1; i <= n; i++) c[i] = d[i];     ans += calc();     printf( %.16lf , ((double)ans) / tot / tot);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sa[1007], n, t, x, d[1007], s;   bool f[1007], c[1007];   int main() {     scanf( %d%d , &n, &x);     for (int i = 1; i <= n; ++i) {       scanf( %d , &t), sa[t] = i;       if (t == 0) c[i] = 1;     }     for (int i = 1; i <= n; ++i) {       if (!c[i]) continue;       int kt = 1, t2 = 1, j = i;       while (j) {         if (j == x) kt = 0, t = t2;         j = sa[j], ++t2;       }       if (kt) d[++s] = t2 - 1;     }     f[0] = 1;     for (int i = 1; i <= s; ++i)       for (int j = 1000; j >= d[i]; --j)         if (f[j - d[i]]) f[j] = 1;     for (int i = 0; i + t <= n; ++i)       if (f[i]) printf( %d n , t + i);     return 0;   }