output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; long long INV2 = 500000004; long long INV6 = 166666668; long long power(long long a, long long b, long long c) { long long x = 1, y = a; while (b > 0) { if (b & 1) x = (x * y) % c; y = (y * y) % c; b /= 2; } return x % c; } int dx[] = {0, -1, 0, 1}; int ...
### Prompt Construct a cpp code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; inline bool iseq(double x, double y) { if (fabs(x - y) < 1e-8) return true; return false; } template <typename T> inline T hpt(T x1, T y1, T x2, T y2) { return hypot(x1 - x2, y1 - y2); } template <typename T> inline T gcd(T a, T b) { if (!b) return a; else ...
### Prompt Construct a CPP code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> int a[100001]; int main() { int i, n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) puts("-1"); else { for (i = 1; i <= n / 4; i++) { a[2 * i - 1] = 2 * i; a[2 * i] = n - 2 * i + 2; a[n - 2 * i + 2] = n - 2 * i + 1; a[n - 2 * i + 1] = 2 * i - 1; } ...
### Prompt Develop a solution in cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int n, num[100005]; int main() { cin >> n; if (!(n % 4 == 0 || n % 4 == 1)) { cout << -1 << endl; return 0; } int st = 1, en = n, cnt = 0; while (1) { if (cnt * 4 == n) break; if (cnt * 4 + 1 == n) { num[st] = st; break; } num[s...
### Prompt In cpp, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> int n; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } if (n % 4) { for (int i = 0; i < n / 2; ++i) { if (i) printf(" "); if (i & 1) printf("%d", n - i + 1); else printf("%d", i + 2); } if (n...
### Prompt Please provide a Cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, 0, -1, -1, -1, 1, 1}; int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; int res[100010]; bool vis[100010]; int main() { ios::sync_with_stdio(false); int n; cin >> n; if (n == 1) cout << 1; else { int co = 1; if (n & 1) vis[n / 2 + 1] = res[n / ...
### Prompt Create a solution in CPP for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, p[N]; void Read_in() { scanf("%d", &n); return; } void Put_out() { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return; } for (int i = 1; i <= n; i++) { printf("%d", p[i]); if (i != n) printf(" "); else ...
### Prompt Please formulate a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; int a[maxn]; int n; int main() { ios_base::sync_with_stdio(0); cin >> n; int t = n % 4; for (int i = 1; i <= n; i++) a[i] = i; if (t == 1 or !t) { int pt1 = 1; int pt2 = n; while (pt1 < pt2) { swap(a[pt1], a[pt1 + 1]); ...
### Prompt In cpp, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> using namespace std; int n; int a[1000020]; int main() { cin >> n; if (n == 1) { puts("1"); } else if (n % 4 == 2 || n % 4 == 3) { puts("-1"); } else { for (int i = 0; i < n / 2; i++) if (i % 2 == 0) { a[i] = i + 1; a[i + 1] = n - 1 - i; a[n - 2...
### Prompt Generate a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; if (n == 1) return cout << "1", 0; if (n % 4 > 1) return cout << "-1", 0; vector<int> ats, le, ri, add(n + 5); int mx, l, r; if (n % 4 == 0) { ats = {2, 4, 1, 3}; n -...
### Prompt In cpp, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } int main() { int n, i, p[100005]; scanf("%d", &n); if (n == 1) { puts("1"); return 0; } if (n % 4...
### Prompt Develop a solution in Cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int f[100500]; int main() { int n; while (~scanf("%d", &n)) { if (n == 1) { printf("1\n"); continue; } else if (n <= 3) { printf("-1\n"); continue; } f[1] = 2; if (n % 2 == 0) { int x = n - 2; for (int i = 2; i <= ...
### Prompt Construct a cpp code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; int flag[111111]; int main() { int n; cin >> n; if (n % 4 == 3 || n % 4 == 2) { cout << -1 << endl; return 0; } int m = n / 4; for (int i = 1, j = 1; i <= m; i++, j = j + 2) { flag[j] = j + 1; flag[j + 1] = n - j + 1; flag[n - j + 1] = n + 1 ...
### Prompt Develop a solution in Cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int res[110000]; int main() { int n; while (cin >> n) { if (n / 2 % 2) { cout << -1 << endl; continue; } res[n / 2] = n / 2; for (int i = 0; i < n / 2; i += 2) { res[i] = i + 1; res[i + 1] = n - i - 1; res[n - i - 1] = n - i...
### Prompt Please formulate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int p[1111111]; int main() { int n; int cnt = 1; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } if (n == 1) { printf("1\n"); return 0; } int tmp = n / 2; for (int i = 1; i <= tmp; i += 2) { p[i] = i + 1; ...
### Prompt Develop a solution in CPP to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1"; return 0; } int p[n + 1]; for (int i = 1; i < n / 2; i += 2) { p[i] = i + 1; p[i + 1] = n - i + 1; p[n - i + 1] = n - i; p[n - i] = i; } if (n % 4 == 1) { ...
### Prompt In CPP, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; if (n % 4 >= 2) { puts("-1"); return 0; } vector<long long> p(n); long long k = 1; for (long long i = 0; i < n / 2; i += 2) { p[n - i - 2] = k; p[i]...
### Prompt Your task is to create a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; int ax[100010]; int main(void) { int n; scanf("%d", &n); if (!(n % 4 == 0 || n % 4 == 1)) { printf("-1\n"); return 0; } for (int i = 1; i <= n / 2; i += 2) { ax[i] = i + 1; ax[i + 1] = n - i + 1; ax[n - i] = i; ax[n - i + 1] = n - i; } ...
### Prompt Please provide a Cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; vector<long long> v[301], vv, v1; long long a, b, c[1234567], c1[1234][1234], e, i, j, n, x, y, l, r, k; string s, s1; long long used[301]; long long ans; bool ok[123]; int main() { cin >> n; if (n / 2 % 2 == 1) { cout << -1; exit(0); } a = 2; for (int i =...
### Prompt Construct a CPP code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int p[maxn]; int n; int main() { while (~scanf("%d", &n)) { if (n == 1) { printf("1\n"); continue; } if (n <= 3) { printf("-1\n"); continue; } memset(p, 0, sizeof(p)); ; if (n & 1) { if ((...
### Prompt Create a solution in Cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 4 && (n - 1) % 4) { cout << -1 << endl; return 0; } int ara[n + 1], i; for (i = 1; i <= n / 2; i += 2) { ara[i] = i + 1; } for (i = 2; i <= n / 2; i += 2) { ara[i] = n - i + 2; } for (i = n; i > (n + ...
### Prompt In CPP, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> const bool debug = false; using namespace std; long long powmod(long long a, long long b, long long MOD) { long long res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } void buginfo(const char* f, ...) { if (!debug) return...
### Prompt Please provide a cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; template <class T> inline void checkmin(T& a, const T& b) { if (a > b) a = b; }; template <class T> inline void checkmax(T& a, const T& b) { if (a < b) a = b; }; int main() { for (int n; cin >> n;) { vector<int> ans(n + 1); if (n % 4 == 2 || n % 4 == 3) { ...
### Prompt Your challenge is to write a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; namespace Flandre_Scarlet { int n; void Input() { cin >> n; } int a[155555]; void Soviet() { memset(a, 0, sizeof(a)); if (n % 4 == 0) { for (int i = 1; i <= n; ++i) { if (!a[i]) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i...
### Prompt Generate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; int f[100010]; int N; bool dfs(int l, int r, int k) { if (r - l + 1 >= 4) { f[l] = 2 + k * 2; f[l + 1] = N - k * 2; f[r] = N - 1 - k * 2; f[r - 1] = 1 + k * 2; return dfs(l + 2, r - 2, k + 1); } else if (r - l + 1 == 1) { f[r] = r; return tru...
### Prompt Create a solution in Cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1; return 0; } if (n % 4 == 3 || n % 4 == 2) { cout << -1 << endl; return 0; } int a[n + 1]; int i = 1, j = n, l = 1, r = n; while (i < j) { a[i] = l + 1; a[j] = r - 1; a[i + 1...
### Prompt Your task is to create a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; int a[100002]; int main() { int n; cin >> n; if (n % 4 > 1) return cout << -1, 0; if (n % 4 == 1) a[(n - 1) / 2 + 1] = (n - 1) / 2 + 1; int e = n / 2; for (int i = 1; i < e; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[n ...
### Prompt Create a solution in cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; int a[100005], n, p, x, k; bool test() { for (int i = 1; i <= n; i++) if (a[a[i]] != n - i + 1) return 0; return 1; } int main() { scanf("%d", &n); k = ceil(n / 2.0); int x = 1, p = 2; while (x <= k) { a[x] = p; p += 2; x += 2; } x = n; p =...
### Prompt Generate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n % 4 > 1) { cout << "-1\n"; return 0; } for (int i = 1; i <= n / 2; i++) { if (i % 2) cout << i + 1 << ' '; else cout << (n - i + 2) << ' '; } int m = n / 2; if (n % 4 == 1) { cout << m + 1; ...
### Prompt Please provide a Cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:666000000") using namespace std; const int inf = (1 << 30) - 1; const long double eps = 1e-9; const long double pi = fabs(atan2(0.0, -1.0)); void ML() { int *ass; for (;;) { ass = new int[2500000]; for (int i = 0; i < 2500000; i++) ass[i] = rand(); ...
### Prompt Please formulate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int seq[111111]; int main(void) { int n = 0; scanf("%d", &n); if (n % 4 > 1) puts("-1"); else { for (int i = 0; i < n / 4; i++) { int t = i * 2 + 1; int l = n + 1 - t; seq[t] = t + 1; seq[t + 1] = l; seq[l] = l - 1; seq[l ...
### Prompt Please provide a Cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; int main() { cin >> n; if (n % 4 > 1) { cout << -1; return 0; } for (int i = 1; i < n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[n - i] = i; } if (n % 2 == 1) a[n / 2 + 1] = n / 2 + 1;...
### Prompt Develop a solution in cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int arr[100009] = {0}; bool vis[100009] = {0}; set<int> st; bool f = 1; int n = 0; cin >> n; if (n == 1) { cout << n; return 0; } if (n <= 3) { cout << -1; return 0; } for (int i = 1; i <= n; i++) st.insert(i); while (st....
### Prompt Develop a solution in Cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; FILE *f, *g; int v[100100]; int i, j, q; int n; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1"); return 0; } for (i = 1, j = n; i <= (n / 4) * 2; i += 2, j -= 2) { v[i] = i + 1; v[i + 1] = j; v[j - 1] = i; v[j] = j ...
### Prompt Please create a solution in cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int n; int a[100005]; int used[10005]; bool check(int i) { if (a[i] == -1) return true; if (a[a[i] - 1] == -1) { a[a[i] - 1] = n - i; used[n - i] = true; } else return a[a[i] - 1] == n - i; return check(a[i] - 1); } bool checkans() { for (int i = 0; i ...
### Prompt Your challenge is to write a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; set<int> st; int ans[100007]; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1" << endl; return 0; } for (int i = 1; i <= n; i++) st.insert(i); if (n % 4 == 1) { int idx = (n + 1) / 2; st.erase(idx); ans[idx] = idx; ...
### Prompt In CPP, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535; int n; int main() { cin >> n; if (n % 4 > 1) cout << -1; else { int x = n / 4; for (int i = 0; i < x; ++i) printf("%d %d ", 2 + i * 2, n - i * 2); if (n % 4 == 1) printf("%d ", n / 2 + 1); for (int i = x - 1; i >= 0;...
### Prompt Create a solution in cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; int main() { int n; int p[100005], parent[100005]; scanf("%d", &n); if (n % 4 > 1) { printf("-1\n"); return 0; } memset(parent, 0, sizeof(parent)); for (int i = 1; i <= n / 2; i += 2) { p[i] = 1 + i; p[i + 1] = n - i + 1; p[n - i + 1] = n -...
### Prompt Please create a solution in Cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; if (n % 4 > 1) { cout << "-1\n"; return 0; } int p[n]; if (n % 4 == 1) { p[n / 2] = (n + 1) / 2; } for (int i = 0, j = n - 2; i < n / 2; i += 2, j -= 2) { if (i == 0) { ...
### Prompt Construct a CPP code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const double EPS = 1e-7; const int MAX = 100005; int p[MAX]; int main() { ios::sync_with_stdio(false); int n; cin >> n; if (n % 4 > 1) cout << -1 << endl; else { for (int i = 1; i <= n / 2; i += 2) { p[i] = i + 1; p[i +...
### Prompt Please create a solution in Cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); if (n % 4 == 0 || n % 4 == 1) { if (n % 4 == 0) { for (int i = 1; i <= n / 2; i += 2) { printf("%d ", i + 1); printf("%d ", (n - i + 1)); } for (int i = n / 2 + 1; i <= n; i += 2) { pri...
### Prompt Your task is to create a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1}; const int dc[]{0, 1, 1, 1, 0, -1, -1, -1}; void run() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } deque<int> solve(int n, int add) { if (n == 0) return {}; if (n == 1) return {1 + add}; deque<int> q ...
### Prompt Your challenge is to write a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; long a[100005]; int main() { long n; cin >> n; if (n == 1) cout << "1" << endl; else if (n % 4 == 0) { for (int i = 1; i <= n / 2; i += 2) a[n - i] = i; for (int i = 2; i <= n / 2; i += 2) a[i - 1] = i; for (int i = n; i > n / 2; i -= 2) a[n + 2 - i]...
### Prompt Develop a solution in Cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> const double eps = 1e-6; const double PI = acos(-1.0); const int inf = ~0u >> 2; using namespace std; const int N = 100010; int p[N]; int main() { int n, i; while (~scanf("%d", &n)) { if (n == 1) { puts("1"); continue; } if (n < 4) { puts("-1"); continue;...
### Prompt Create a solution in CPP for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; int n, p[N], ans1, ans2, ans3, ans4, k1, k2, k3, k4, m; int main() { cin >> n; if (n % 4 != 0 && (n - 1) % 4 != 0) { cout << -1; return 0; } if (n % 4 == 0) { m = n / 4; k1 = 1; k2 = 2; k3 = n - 1; k4 = n; ans1...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { ifstream fin("input.txt", ios::in); ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cout << setprecision(10); cout << fixed; int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) return cout << -1, 0; if (n == 1) return cout << 1, 0; i...
### Prompt Develop a solution in Cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; vector<int> vec; void cal(int l, int r) { if (r < l) return; if (l == r) { vec.push_back(l); return; } vec.push_back(l + 1); vec.push_back(r); cal(l + 2, r - 2); vec.push_back(l); vec.push_back(r - 1); } int main() { int n; cin >> n; if (n % 4 ...
### Prompt Please formulate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int i, n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } if (n % 2 == 1) a[(n + 1) / 2] = (n + 1) / 2; for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i] = i; ...
### Prompt Please formulate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> const int MAXN = 100010; int n, a[MAXN]; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1"); return 0; } if (n % 4 == 0) { for (int i = 1; i <= n / 2 - 1; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[n ...
### Prompt Your task is to create a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100005] = {0}, i, j; cin >> n; if (n % 4 > 1) { cout << -1; return 0; } a[n / 2 + 1] = n / 2 + 1; for (j = 1; j <= n / 4; j++) { a[n - j * 2 + 1] = j * 2 - 1; i = n - j * 2 + 1; do { a[a[i]] = n - i + 1; i = ...
### Prompt Generate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; long long n, a[100005]; int main() { cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1\n"; return 0; } long long f = 1; long long b = n; while (f < b) { if (f == b) { a[f] = f; break; } a[f] = f + 1; a[f + 1] = b; a[b ...
### Prompt Please provide a Cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int d[100100]; int main() { int n; while (scanf(" %d", &n) == 1) { if (n % 4 == 0) { int r = n; for (int i = 1; i < n;) { d[i] = i + 1; d[i + 1] = n; d[n] = n - 1; d[n - 1] = i; i += 2; n -= 2; } ...
### Prompt Please formulate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int a[200009]; int main() { int i, j, k, n; scanf("%d", &n); if (n == 1) { printf("1\n"); } else if (n % 4 > 1) { printf("-1\n"); } else { for (i = 1; i < n / 2; i += 2) { a[i] = i + 1; j = i; while (!a[a[j]]) { a[a[j]] = n - ...
### Prompt Please provide a CPP coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int p[100500]; set<int> nused; int n; void sol() { if (n == 1) cout << 1; else if (((n - 1) % 4 == 0) || (n % 4 == 0)) { for (int i = (1); i <= (n); i++) nused.insert(i); memset(p, 0, sizeof(p)); int i = 1; for (int i = (1); i <= (n / 2); i++) { ...
### Prompt Please formulate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> #pragma comment(linker, "/stack:336777216") #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using ui = unsigned int; template <typename T> ...
### Prompt Your challenge is to write a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int p[n + 1]; if (n % 4 <= 1) { if (n % 2 == 1) p[(n + 1) / 2] = (n + 1) / 2; for (int s = 1, e = n; s < e; s += 2, e -= 2) { p[s] = s + 1; p[s + 1] = e; p[e] = e - 1; p[e - 1] = s; } for (...
### Prompt Develop a solution in Cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> int main() { int n, m, i, x, y; scanf("%d", &n); m = n / 2; if (m % 2 == 0) { x = m / 2; for (i = 0; i < x; i++) printf("%d ", m - i); for (i = x - 1; i >= 0; i--) printf("%d ", n - i); if (n % 2 == 1) printf("%d ", m + 1); for (i = 1; i <= x; i++) printf("%d ", i); ...
### Prompt Generate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> const int N = 100010; int p[N]; int L[N]; int cnt[N]; int partner[N]; int list[N]; void combine(int i, int j) { assert(L[i] == L[j]); assert(L[i] > 0 && !(L[i] & 1)); int flag = 0; list[0] = i; list[1] = j; int n = 2; int ci = p[i], cj = p[j]; while (ci != i && cj != j) { li...
### Prompt Please provide a cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n; cin >> n; if (n % 4 == 0 || n % 4 == 1) { int a[n]; int low = 1, high = n; int i = 0; while (low < high) { a[i] = low + 1; a[i + 1] = high; a[n - i - 1] = high - 1; a[n - i - 2] = low; ...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int a[100000 + 10]; int main() { int n; while (scanf("%d", &n) != EOF) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i;...
### Prompt Your challenge is to write a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int N, P[100010]; int main(int argc, char *argv[]) { scanf("%d", &N); if (N % 4 == 2 || N % 4 == 3) { printf("-1\n"); return 0; } int K = N >> 1; for (int i = 1; i <= K; i++) if (P[i] == 0) { P[i] = i + 1; P[i + 1] = N - i + 1; P[N - ...
### Prompt Generate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; int mark[100002], p[100002]; int main() { int t, n; while (scanf("%d", &n) != EOF) { int next = 2; mark[0] = 0; for (int i = 1; i <= n; i++) { mark[i] = 0; p[i] = 0; } int f = 0; for (int i = 1; i <= n; i++) { if (p[i] != 0) con...
### Prompt Please create a solution in cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double pi = acos(-1); const double EPS = 1e-9; long long binpowmod(long long a, long long b) { a %= MOD; long long ret = 1; while (b) { if (b & 1) ret = ret * a % MOD; a = a * a % MOD; b >>= 1; } return ret % MOD; } long ...
### Prompt Generate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:250777216") using namespace std; const int MOD = int(1e9) + 7; const int HMOD = (1 << 22) - 1; int p1[110000] = {}; int n; int main() { scanf("%d", &n); int num = n; int i = 1; for (i = 1; num > 3; i += 2) { p1[i + 1] = i; p1[i] = n - i; p1[n ...
### Prompt In CPP, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> using namespace std; template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double pi = 3.1415926535897932384626433832795; const long double eps = 1e-9; const int INF = (int)1e9; const int N = (int)1e5 + 10; long long n, k; int ...
### Prompt Develop a solution in cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; int main() { int n; scanf("%d", &n); if (n & 1) { if ((n - 1) % 4) { puts("-1"); return 0; } else { for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n + 1 - i; a[n ...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, res[N]; int main() { scanf("%d", &n); if ((n / 2) % 2 == 1) { puts("-1"); } else { res[n / 2] = n / 2; for (int i = 0; i < n / 2; i += 2) { res[i] = i + 1; res[i + 1] = n - i - 1; res[n - i - 1] = n - i - 2; ...
### Prompt Create a solution in Cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; int n, i, a[100005]; int main() { scanf("%d", &n); if (n % 4 != 0 && n % 4 != 1) { printf("-1\n"); return 0; } for (i = 1; i <= n / 4; i++) { a[(i - 1) * 2 + 1] = i * 2; a[i * 2] = n - (i - 1) * 2; a[n - (i - 1) * 2] = n - (i - 1) * 2 - 1; a[...
### Prompt Your task is to create a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100000; int main() { int n; static int p[MaxN + 1]; cin >> n; if ((n / 2) % 2 != 0) cout << "-1" << endl; else { for (int i = 1; i <= n - i + 1; i += 2) { if (i == n - i + 1) p[i] = i; else { p[i] = i + 1; ...
### Prompt Construct a cpp code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; int n, a[100009]; int main() { cin >> n; if (n == 1) cout << 1; else if ((n / 2) % 2 == 1) cout << -1; else { for (int i = 1; i <= (n / 2 / 2); i++) { a[i * 2 - 1] = i * 2; a[i * 2] = n - (i - 1) * 2; a[n - i * 2 + 1] = i * 2 - 1; ...
### Prompt Your task is to create a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> const int N = 1e5 + 10; int n, m, i, t, x, a[N]; bool e[N]; int check() { int i, x; for (i = 1; i <= n; i++) { x = a[a[i]]; if (x + i == n + 1) ; else return 0; } return 1; } void print() { int i; for (i = 1; i < n; i++) printf("%d ", a[i]); printf("%d\n", ...
### Prompt Please formulate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; if (n == 4) { cout << "2 4 1 3" << endl; return; } int a[n]; if (n % 4 == 0 || (n - 1) % 4 == 0) { a[n - 3] = n + 1 - 4; a[0] = 2; a[n - 2] = 1; a[2] = 4; a[n - 1] = n - 1; a[1] = n; if (n % 2 =...
### Prompt Please create a solution in cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int n; int mas[100005]; int main() { cin >> n; if (n % 4 >= 2) { cout << "-1\n"; return 0; } for (int i = 0; i < n; ++i) mas[i] = i; for (int l = 0, r = n - 1; l < r; l += 2, r -= 2) { mas[l] = l + 1; mas[l + 1] = r; mas[r] = r - 1; mas[r -...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int n, p[1010000]; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { puts("-1"); return 0; } if (n % 4 == 0) { for (int i = 1; i <= n / 2; i++) { if (i % 2 == 1) p[i] = i + 1, p[n + 1 - i] = n - i; else p[i] = n + ...
### Prompt Construct a CPP code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; int n; int p[100010]; bool used[100010]; int main() { scanf("%d", &n); memset(p, 0, sizeof(p)); memset(used, false, sizeof(used)); if (n == 1) { printf("1\n"); return 0; } if (n % 2 == 0) { if (n % 4 != 0) { printf("-1\n"); return 0; ...
### Prompt Your task is to create a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const int MAXN = 100005; int n, a[MAXN]; void Inp() { scanf("%d", &n); } void Outp() {} void Run() { if (n % 4 == 2 || n % 4 == 3) { printf("-1"); exit(0); } for (int i = 0; i < n / 4; ++i) { a[i * 2] = i * 2 + 1;...
### Prompt Please create a solution in cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf("%d", &n) == 1) { if ((n / 2) & 1) printf("-1\n"); else { if (n & 1) { int t = n; for (int i = 1; i <= n; i++) { if (i == n / 2 + 1) { printf("%d", i); t -= 2; ...
### Prompt Please create a solution in cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf("%d", &n) != EOF) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } for (int i = 0; i < n; ++i) { if (i) printf(" "); if (n % 2) { if (i == (n - 1) / 2) printf("%d", (n + ...
### Prompt Please formulate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; long long n, p[5000000], i; int main() { cin >> n; if (n % 4 >= 2) { cout << -1 << endl; return 0; } for (i = 1; i <= n / 2; i += 2) { p[i] = i + 1; p[i + 1] = n - i + 1; p[n - i + 1] = n - i; p[n - i] = i; } if (n % 2) p[n / 2 + n % 2] =...
### Prompt Create a solution in cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; int a[N]; int main() { scanf("%d", &n); if (n % 4 >= 2) { printf("-1\n"); return 0; } for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1, a[i + 1] = n - i + 1; a[n - i + 1] = n - i, a[n - i] = i; } if (n % 4) a[n / 2 ...
### Prompt Please create a solution in cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int res[100010]; int main() { int n; cin >> n; if (n % 4 == 1) { for (int i = 0; i < n / 2 - 1; i += 2) { res[i] = i + 2; res[i + 1] = n - i; } res[n / 2] = n / 2 + 1; for (int i = n / 2 + 1; i < n - 1; i += 2) { res[i] = n - i - 1; ...
### Prompt Construct a Cpp code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; const long maxn = 60000; const long maxm = 15000000; const long oo = 100000000; const long mod = 1000000007; const double le = 1e-10; long i, j, k, n, m; long a[1000000]; int main() { scanf("%ld", &n); if (n % 4 == 3 || n % 4 == 2) { puts("-1"); return 0; } ...
### Prompt Your challenge is to write a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int main() { int n, tam; cin >> n; vector<int> v; if (((n % 4) == 2) || ((n % 4) == 3)) { cout << -1 << endl; return 0; } else if (n % 4 == 0) { tam = (int)v.size(); v.push_back(2); v.push_back(4); v.push_back(1); v.push_back(3); in...
### Prompt In CPP, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; int p[mx]; int main() { int n; cin >> n; if (n % 4 > 1) { puts("-1"); return 0; } int l = 1, r = n; while (l < r) { p[l] = l + 1; p[l + 1] = r; p[r] = r - 1; p[r - 1] = l; l += 2; r -= 2; } if (l == r)...
### Prompt Create a solution in Cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; int ans[200000], was[200000]; int link[200000]; int main() { int n; scanf("%d", &n); if (n % 2 == 1) { ans[n / 2 + 1] = n / 2 + 1; was[n / 2 + 1] = 1; } for (int i = 1; i <= n; i++) link[i] = n - i + 1; int x = 1; for (int i = 1; i <= n; i++) { if ...
### Prompt Generate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; bool good(vector<int> p) { for (int i = 0; i < p.size(); ++i) if (p[p[i]] != p.size() - i - 1) return false; return true; } void print(vector<int> p) { for (int i = 0; i < p.size(); ++i) cout << p[i] + 1 << " "; cout << endl; } void solve() { int n; cin >> n...
### Prompt Construct a cpp code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; int n, i, j, p[100011]; set<int> a; set<int>::iterator b; int main() { scanf("%d", &n); if (n == 1) { printf("1\n"); return 0; } if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } for (i = 1; i <= n; ++i) a.insert(i); for (j = 1; j <= ...
### Prompt Develop a solution in cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> int n, i, a[100005], t1, t2; int main() { scanf("%d", &n); if (n % 4 > 1) { printf("-1\n"); return 0; }; t1 = n - 1; t2 = -1; while (t1 > (n + 1) / 2) { a[t1] = (t2 += 2); t1 -= 2; }; if (n % 4 == 1) { a[(n + 1) / 2] = (n + 1) / 2; t2++; }; for (t1 = ...
### Prompt Please provide a cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; template <class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; } template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } ret...
### Prompt Please formulate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; const int N = 100500; int A[N]; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } for (int i = 0; i < n; i++) A[i] = i; for (int i = 0; i < n / 2; i += 2) { A[i] = i + 1; A[i + 1] = n - i - 1; A[...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << "1" << endl; return 0; } if (((n / 2) * 2) % 4 == 0) { int p[n]; int temp; if (n % 2 != 0) p[n / 2] = (n + 1) / 2; for (int i = 0; i < n / 4; i++) { temp = i + n / 2 + (n % 2 != 0 ? ...
### Prompt Create a solution in Cpp for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> const int maxn = 110000; int a[maxn]; int n; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } for (int i = 1; i <= n / 4; i++) { a[2 * i - 1] = 2 * i; a[2 * i] = n - 2 * i + 2; a[n - 2 * i + 2] = n - 2 * i + 1; a[n - 2 * i...
### Prompt Please create a solution in cpp to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> const long long INF = 2009000999; const float cp = 2 * acos(0.0); const float eps = 1e-18; using namespace std; int main() { long long n, p[1010000]; cin >> n; if (n % 4 == 2 || n % 4 == 3) { puts("-1"); return 0; } if (n % 4 == 0) { for (int i = 1; i <= n / 2; i++) { ...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int ans[100000]; int main() { int n; scanf("%d", &n); if (n / 2 % 2) puts("-1"); else { bool flag = 0; if (n & 1) { --n; flag = 1; } for (int i = 0; i < n / 2; i += 2) ans[i] = i + 2; for (int i = n / 2; i < n; i += 2) ans[i] = n ...
### Prompt Please provide a CPP coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; bool used[123456]; int main() { int n; cin >> n; vector<pair<int, int> > v1, v2; vector<int> ans; int a = 2, b = n; while (a < b) { used[a] = used[b] = 1; v1.push_back(make_pair(a, b)); a += 2; b -= 2; } a = 1, b = n - 1; while (a < b) { ...
### Prompt Please provide a cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int a[100007]; int n; int main() { int i, j; while (~scanf("%d", &n)) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } for (i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; ...
### Prompt Please formulate a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; int p[100010]; int main() { int n, i; int a, b; while (cin >> n) { if (n % 4 == 0 || n % 4 == 1) { for (i = 1; i <= n; i++) p[i] = i; a = 1; b = n; for (i = 1; i < n / 2; i += 2) { p[i] = a + 1; ...
### Prompt Your task is to create a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; int p[100000 + 11]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; if (n % 4 >= 2) { cout << -1; return 0; } if (n == 1) { cout << 1; return 0; } p[n - 1] = 1; int fill = 1; int prev = n - 1; while (fill < n) {...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int a[100010]; int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1" << endl; return 0; } if (n % 4 == 1) a[(n + 1) / 2] = (n + 1) / 2; int i = 1; int end = n; while (i < end) { a[i] = end - 1; a[end - 1] = (n - i + 1);...
### Prompt Please provide a Cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d", &n); m = n; int A[n]; if ((n - 2) % 4 == 0 || (n - 3) % 4 == 0) { printf("-1\n"); return 0; } int i = 2; int p = 0; while (n > 0) { if (n == 1) { A[p] = p + 1; n -= 1; } else { A[p] = i; ...
### Prompt Construct a CPP code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. Yo...