output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; int a[1 << 17]; int N; int go(int i) { a[i] = i + 1; while (a[a[i]] == 0) { a[a[i]] = N - i + 1; i = a[i]; } return i + a[a[i]] == N + 1; } int main() { scanf("%d", &N); int good = 1; for (int i = 1; i <= N; ++i) if (!a[i]) { if (i * 2 == 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 arr[100010]; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1"; return 0; } if (n % 4 == 1) { arr[(n + 1) / 2] = (n + 1) / 2; } int rep = n / 4; int start = 1; for (int i = 1; i <= rep; i++) { int tmp1 = i * 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; struct node {}; int a[100100]; int main() { int n, i; scanf("%d", &n); if (n % 4 > 1) { puts("-1"); } else if (n == 1) { puts("1"); } else { 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> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); int fh = 1; while (ch < '0' || ch > '9') { if (ch == '-') fh = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= fh; } template <typename...
### 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; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; void debugarr(int* arr, int n) { cout << "["; for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << "]" << endl; } int main() { 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; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) cout << "-1" << endl; else { int result[200000] = {0}; if (n % 4 == 0) { for (int i = 0; i < n / 4; i++) { result[2 * i] = 2 * i + 2; result[2 * i + 1] = 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> using namespace std; template <class T> inline T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> inline T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } template <class...
### 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[100001]; int main() { cin >> n; if (n % 4 < 2) { int m = n / 4; for (int i = 0; i < (m); i++) { a[2 * i] = 2 * i + 2; a[2 * i + 1] = n - 2 * i; a[n - 1 - 2 * i] = n - 1 - 2 * i; a[n - 1 - 2 * i - 1] = 2 * i + 1; } if ...
### 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, a[200006]; set<int> s; int main() { scanf("%d", &n); if (n == 2 || n == 3) { printf("-1\n"); return 0; } bool f = 1; int cur = n; int s = n + 1; for (int i = n / 2; i >= 1; i--) { if (f) { a[i] = cur; a[n - i + 1] = s - cur; ...
### 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; const long long inf = (long long)1e9 + 7; const int N = (int)1e5 + 4; const int M = 1005; const int K = 25; int a[N]; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1"); return 0; } if (n % 4 == 1) { a[n / 2] = n / 2 + 1;...
### 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; const int nm = 100005; const int mm = 100005; int n, k, m, t; int a[nm]; bool check[nm]; void DO() { int i, u = 1, j = n, c1 = 2, c2; int z = n / 4, y; for (y = 1; y <= z; y++) { i = u; a[i] = c1; c1 += 2; a[a[i]] = n - i + 1; i = a[i]; a[a[i]]...
### 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, V[100010], CrtPos; bool Used[100010]; int main() { int i; scanf("%i", &N); if (N == 1) { printf("1\n"); return 0; } CrtPos = 1; V[1] = 2; bool Move = 1; while (Move) { Move = 0; while (!Used[V[CrtPos]]) { Used[V[CrtPos]] = 1; ...
### 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; long long n, m, k, q, l, r, x, y; const long long N = 2e5 + 5; vector<long long> arr(N); string s, t; long long ans = 0; void solve() { cin >> n; map<long long, long long> mp, ans; for (long long i = 1; i <= n; i++) mp[i] = n - i + 1, ans[i] = mp[i]; if (n == 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; const double pi = acos(-1.0); const int intmax = 0x3f3f3f3f; const long long lldmax = 0x3f3f3f3f3f3f3f3fll; double eps = 1e-6; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b;...
### 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 main() { ios::sync_with_stdio(0); long long int n, i; cin >> n; if (n == 1) { cout << 1; return 0; } if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } long long int a[n]; if (n % 2 == 0) { for (i = 1; i <= n / 2; i += 2) { ...
### 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[100005]; int place[100005]; int main() { int n; cin >> n; if (n % 4 >= 2) cout << -1 << endl; else { for (int i = 0; i < n / 2; i += 2) { a[i] = i + 2; a[i + 1] = n + 2 - a[i]; } for (int i = n - 1; i > n / 2; i -= 2) { a[i] =...
### 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 main() { int n, i; scanf("%d", &n); if (n % 4 == 0) { for (i = 1; i <= n / 2; i += 2) { printf("%d %d ", i + 1, n + 1 - i); } for (i = n / 2 + 2; i < n; i += 2) { printf("%d %d ", n + 1 - i, i - 1); } printf("%d %d\n", n + 1 - i, i - 1); } else if (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; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } int n; int ar[100005]; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { puts("-1"); return 0; } for (int i = 0...
### 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> int a[100010]; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) printf("-1"); else { 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 - i] = 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; int n; int c[100001]; void init() { scanf("%d", &n); memset(c, 0, sizeof(c)); } void work() { if (n == 1) { printf("1"); return; } if ((n / 2) & 1) { printf("-1"); return; } for (int i = 1; i <= n / 2; i += 2) { c[i] = i + 1; c[i + 1] =...
### 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() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } int a[n + 1]; 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 - 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; template <class T, class U> bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) { return a.second < b.second; } pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first + b.first, a.second + b.second); } pair<int, int> ...
### 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 n; bool ans = true; int a[105000], p[105000]; bool u[105000]; queue<int> q; void dfs(int pos) { u[p[pos]] = true; int to = a[pos]; if (!u[to]) { p[p[pos]] = to; dfs(p[pos]); } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) a[i] = n - 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> const int MAXN = 100000 + 9; int a[MAXN]; int main() { int n, i; scanf("%d", &n); if (n % 4 > 1) { puts("-1"); return 0; } if (n % 4) { a[n / 2 + 1] = n / 2 + 1; } for (i = 1; i * 2 < n; i += 2) { a[n - i] = i; a[i] = i + 1; a[i + 1] = n - i + 1; a[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; const int maxn = 100000 + 100; int p[maxn]; int main() { int n; scanf("%d", &n); int i, j; if (n == 1) { printf("1\n"); return 0; } if (n % 2 == 0) { if (n % 4) { printf("-1\n"); return 0; } int l, r; l = 0; r = n - 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; cin >> n; if (n == 1) { cout << "1\n"; return 0; } else if (n % 4 == 2 || n % 4 == 3) { cout << "-1\n"; return 0; } int arr[n + 1], k = 2; if (n % 2 == 1) { arr[(n + 1) / 2] = (n + 1) / 2; } int i = 1; while (i < n...
### 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; __inline bool nextInt(int &val) { char ch; int sgn = 1; while ((ch = getchar()) != EOF) { if (ch == '-') sgn = -1; if (ch >= '0' && ch <= '9') break; } if (ch == EOF) return false; val = (int)(ch - '0'); while (true) { ch = getchar(); if (ch >=...
### 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 double eps(1e-8); int p[110000]; void did(int a, int b, int n) { for (int i = (1); i <= (4); ++i) { p[a] = b; int tmp = b; b = n - a + 1; a = tmp; } } bool solve(int n) { if (n % 4 == 2 || n % 4 == 3) return false; for (int i = (1); 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> using namespace std; int perm[100010]; int main(void) { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); } else { for (int i = 1; i <= n / 2; i++) { if (i % 2 == 1) { perm[i] = n - i; int iter = i; for (int j = 0; j < 3; j++) ...
### 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> bool func(T a, T b) { return a < b; } int main(int argc, const char *argv[]) { long long *a, b, i, j, n, k; cin >> n; if (n % 4 > 1) cout << "-1"; else { b = n / 4; a = new long long[n + 1]; for (k = 1; k <= b; k++) { j = 2...
### 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; #pragma comment(linker, "/STACK:102400000,102400000") template <class T> T _max(T x, T y) { return x > y ? x : y; } template <class T> T _min(T x, T y) { return x < y ? x : y; } template <class T> T _abs(T x) { return (x < 0) ? -x : x; } template <class T> T _mod(T x,...
### 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 double PI = acos(-1.0); const int MAXN = 100000 + 9; template <class T> inline T f_min(T a, T b) { return a < b ? a : b; } template <class T> inline T f_max(T a, T b) { return a > b ? a : b; } template <class T> inline T f_abs(T a) { return a > 0 ? a : -a; } tem...
### 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[100010]; int n; void work(int l, int r) { if (l > r) return; if (l == r) { a[l] = l; return; } a[l] = l + 1; a[l + 1] = r; a[r - 1] = l; a[r] = r - 1; work(l + 2, r - 2); } int main() { cin >> n; if (n == 1) { puts("1"); } else if (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 a[100010], n; int main() { while (scanf("%d", &n) != EOF) { if (n % 4 > 1) puts("-1"); else { int stpos = 1, edpos = n - 1; int stval = 2, edval = 1; for (int i = 0; i < n / 4; i++) { a[stpos] = stval; a[edpos] = edval; ...
### 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 p[100005]; bool m[100005]; int cnt; int n; void rec(int k) { if (m[k]) return; m[k] = true; p[p[k]] = (n - (k) + 1); cnt++; rec(p[k]); } int main() { scanf(" %d", &n); for (int i = 1; i <= n; i++) if ((n - (i) + 1) == i) p[i] = i, m[i] = true, cnt++; ...
### 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 P = 1e9 + 7, INF = 0x3f3f3f3f; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n) { long long r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } long lo...
### 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; const int OO = (int)2e9; const double eps = 1e-9; int arr[100005]; int main() { std::ios_base::sync_with_stdio(false); int i, n; cin >> n; if (!((n & 3) && ((n - 1) & 3))) { if (n & 1) arr[n / 2 + 1] = n / 2 + 1; for (i = 1; i < n / 2; i += 2) { arr[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 main() { int n; cin >> n; if (n % 4 == 3 || n % 4 == 2) { cout << "-1"; } if (n % 4 == 0) { for (int i = 0; i < n / 2; i += 2) { cout << (i + 2) << " "; cout << n - i << " "; } for (int i = 1; i < n / 2; i += 2) { cout << 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 n; int v[100005]; int main() { cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } for (int i = 2; i <= n / 2; i += 2) v[i - 1] = i, v[i] = n + 2 - i; if (n % 2) v[n / 2 + 1] = n / 2 + 1; for (int i = n / 2 - 1, j = 1; i >= 1; i -= 2, j...
### 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 solve() { int n; if (scanf("%d", &n) == EOF) return false; if (n % 4 > 1) { printf("-1\n"); return true; } vector<int> ans(n); for (int i = 0; i < n / 4; ++i) { ans[i * 2] = i * 2 + 1; ans[i * 2 + 1] = n - i * 2 - 1; ans[n - 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> using namespace std; const int N = 100010; int main() { int n; scanf("%d", &n); if (n % 4 > 1) { printf("-1\n"); return 0; } int p[N]; 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 % ...
### 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; const int maxn = 1e5 + 5; int arr[maxn]; int main() { int n; cin >> n; if ((n >> 1) & 1) return 0 * printf("-1\n"); for (int i = 0; i < n + 1; i++) arr[i] = i; for (int i = 1; i <= n; i += 2) { if (n & 1 && i == n / 2 + 1) i++; swap(arr[i], arr[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; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
### 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 num[100005] = {0}; int flag[100005] = {0}; int main() { int n; scanf("%d", &n); if (n == 1) printf("1\n"); else if (n >= 4) { int kflag; if (n % 2 == 1) num[(n + 1) / 2] = (n + 1) / 2; while (1) { int flags = 0; kflag = 0; for (...
### 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 vis[100006]; int a[100005]; int ans[100005]; int main() { ios_base::sync_with_stdio(false); int i, j, k, x, n, t; cin >> n; if (n % 4 != 1 && n % 4 != 0) { cout << -1 << endl; return 0; } for (i = 1; i <= (n + 1) / 2; i += 2) { if (i == (n + 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> int arr[100010]; int main() { int n, counts, index, to, i, j, a, b; scanf("%d", &n); if (n == 1) { printf("1\n"); return 0; } if (n == 2) { printf("-1\n"); return 0; } if ((n % 4) > 1) { printf("-1\n"); return 0; } a = 1; b = 2; for (i = 0; i < 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; long long pow(long long b, long long e, long long m) { long long t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; } template <class T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <class T> inline bool c...
### 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 m, k; int n; int p[100100]; int main() { scanf("%d", &n); if (n == 1) { printf("1\n"); return 0; } if (n == 2 || n == 3) { printf("-1\n"); return 0; } int a = 1; set<int> per; for (int i = 2; i <= n; i++) per.insert(i); for (int i = 1; ...
### 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; long long power(long long a, long long n, long long lelo) { if (n == 0) return 1; if (n == 1) return a; if (n == 2) return (a * a) % lelo; if (n % 2) return (a * power(a, n - 1, lelo)) % lelo; else return power(power(a, n / 2, lelo), 2, lelo) % lelo; } voi...
### 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 arr[100015]; int N; int main() { cin >> N; int s = 1, e = N; bool fail = false; int left = N; while (true) { if (left == 0) { break; } else if (left == 1) { arr[s] = s; break; } else if (left >= 4) { arr[s] = s + 1; ar...
### 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; struct Node { int k, x; }; int p[100010]; int N; bool doit(int s) { int i; for (i = 1; i <= N; i++) if (p[i] == 0) { static Node q[100010]; int head = 1, tail = 2; q[1].k = s, q[1].x = i; p[s] = i; bool flag = true; while (head ...
### 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 NMAX = 100005; int A[NMAX]; int main() { ios::sync_with_stdio(false); int n; cin >> n; bool ok = true; if (n % 2 == 1) { if ((n - 1) % 4 == 0) { for (int i = 1; i <= n / 2; i += 2) { A[i] = i + 1; A[i + 1] = n - i + 1; A...
### 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() { int n; cin >> n; if (n % 4 == 0 || n % 4 == 1) { int arr[n]; int j = 0; for (int i = 0; i < n / 4; i++) { arr[j] = j + 2; arr[j + 1] = n - j; arr[n - j - 1] = n - j - 1; arr[n - j - 2] = j + 1; j += 2; } i...
### 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> int num[100100]; int n; int main() { scanf("%d", &n); if (n % 4 != 0 && n % 4 != 1) { puts("-1"); return 0; } if (n % 2 == 1) num[n / 2] = n / 2 + 1; for (int i = 0, j = 0; j < n - n % 2; i += 2, j += 4) { num[i] = 2 + i; num[i + 1] = n - i; num[n - 1 - i] = n - 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 n, ans[100010]; int main() { while (scanf("%d", &n) == 1) { int i; if ((n & 3) == 2 || (n & 3) == 3) { puts("-1"); continue; } for (i = 1; i <= n / 2; i += 2) { ans[i] = i + 1, ans[n - i + 1] = n - i; ans[i + 1] = n - i + 1, ans...
### 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 v[100005]; int main() { int n; cin >> n; if (n % 4 == 1) { v[50001] = 1; int st = 50000; int dr = 50002; for (int i = 1, n1 = 1; i < n; i += 4, n1 += 4) { v[st] = n1 + 4; st--; v[st] = 2; st--; v[dr] = 1; dr++; ...
### 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() { long long int i, j, k, n, m, t, a[100001]; cin >> n; if ((n % 4 != 0) && (n - 1) % 4 != 0) { cout << "-1"; return 0; } if (n % 4 == 0) { for (i = 1, j = n; i <= n / 2; i += 2, j -= 2) { a[i] = i + 1; a[j - 1] = i; a[i + 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 n, l, r, i, j, k; int a[100005]; int main() { scanf("%d", &n); if ((n % 4 == 0) || ((n - 1) % 4 == 0)) { l = 1; r = n; for (k = 1; k <= n / 4; k++) { a[l] = l + 1; a[r] = r - 1; a[l + 1] = r; a[r - 1] = l; l += 2; 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 a[100006]; int main() { int n; while (scanf("%d", &n) != EOF) { if (n == 1) puts("1"); else if (n == 2) puts("-1"); else { int delta = n; for (int i = 1; i <= n && delta > 0; i++) { if (i == 1) a[1] = 2; ...
### 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, p[1000007]; int main() { scanf("%d", &n); if (n == 1) { puts("1"); return 0; } if (n % 4 == 2 || n % 4 == 3) { puts("-1"); return 0; } if (n % 4 == 0) { for (int i = 0; i < n / 2; i += 2) { int a1 = i; int a2 = i + 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* array; int n; cin >> n; if (n == 1) cout << 1 << endl; else if (n == 2 || n == 3 || ((n % 2 != 0) && ((n / 2) % 2 != 0)) || ((n % 2 == 0) && ((n / 2) % 2 != 0))) cout << -1 << endl; else { array = new int[n]; if (n & ...
### 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 long long int mx = 1e6 + 10, inf = 1e9 + 10; int n, a[mx], g, h; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; if (n % 4 > 1) { cout << -1; return 0; } g = 2; h = n - 2; a[n / 2] = n / 2 + 1; for (long long int 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 a[100005]; int main() { int n; int i; cin >> n; if (n % 4 == 3 || n % 4 == 2) { cout << -1; return 0; } for (i = 1; i <= n / 2; i = 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)...
### 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> int mas[(int)1e5 + 10]; int main() { int n; scanf("%d", &n); int m = n; int q = 0; int w = 0; while (n >= 4) { mas[q] = 2 + w; mas[q + 1] = n + w; mas[m - 1 - q] = n - 1 + w; mas[m - 2 - q] = 1 + w; q += 2; w += 2; n -= 4; } if (n == 1) { mas[q] =...
### 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; const int maxn = 100111; int p[maxn]; bool vist[maxn]; int n; void dfs(int cur) { vist[cur] = 1; if (p[p[cur]]) { return; } p[p[cur]] = n - cur + 1; dfs(p[cur]); } int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) puts("-1"); else { if ...
### 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 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 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> int perm[100010 + 1]; using namespace std; int main() { int n; cin >> n; int s = 1; int e = n; while (e - s > 0) { perm[s] = s + 1; perm[s + 1] = e; perm[e] = e - 1; perm[e - 1] = s; s += 2; e -= 2; } if (s == e) perm[s] = s; if ((n % 4) > 1) cout << ...
### 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; cin >> n; vector<int> arr(n + 1); for (int cnt = 1; cnt <= n; cnt++) { if (cnt * 2 == 1 + n) arr[cnt] = cnt; else if (cnt <= n / 2) { if (cnt % 2) arr[cnt] = cnt + 1; else arr[cnt] = n - cnt + 2; } el...
### 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 mas[100000]; int main() { int N; scanf("%d", &N); if (N % 4 > 1) printf("-1\n"); else { int start = 0; int finish = N - 1; while (finish - start > 0) { mas[start] = start + 1; mas[start + 1] = finish; mas[finish] = finish - 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; cin >> n; if (n % 4 == 1 || n % 4 == 0) { int *result = new int[n + 1]; if (n % 2 == 1) { result[(n + 1) / 2] = n / 2 + 1; } for (int i = 1; i < (n + 1) / 2; i += 2) { result[i] = i + 1; result[i + 1] = n + 1 - i; ...
### 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> int ans[100002]; int main() { int i, N, l, r; scanf("%d", &N); if (!(N % 4 <= 1)) { printf("-1\n"); return 0; } l = 2; r = N; for (i = 1; i <= N / 2; i += 2) { ans[i] = l; ans[i + 1] = r; ans[N + 1 - i] = r - 1; ans[N - i] = l - 1; l += 2; r -= 2; ...
### 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 INF = 1000000000; int t, n, m, i, j, l = 0, k, c = 0, v = 0, x, r = 0, used[1000001] = {0}, a[1000001], b[1000001]; char s[1000001], s2[1000001]; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-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 n; vector<int> a; int main() { cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; return 0; } a.resize(n + 1); if (n % 4 == 1) a[(n + 1) / 2] = (n + 1) / 2; int l = 1, r = n; while (r - l >= 3) { a[l] = l + 1; a[l + 1] = r; a...
### 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, ar[100005], mark[100005]; void sifir() { for (int i = 2, j = N; i <= N / 2; i += 2, j -= 2) printf("%d %d ", i, j); for (int i = N / 2 - 1, j = N / 2 + 1; i > 0; i -= 2, j += 2) printf("%d %d ", i, j); } void bir() { int orta = N / 2 + 1; for (int i = 2, ...
### 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, c, idx, a[100001]; int main() { scanf("%d", &n); if (n % 4 > 1) return printf("-1\n"), 0; c = 2, idx = 0; for (int i = 0; i < n / 4; ++i) { a[idx] = c; idx += 2, c += 2; } c = n, idx = 1; for (int i = 0; i < n / 4; ++i) { a[idx] = c; idx...
### 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 que[100010]; int main() { int n, i; scanf("%d", &n); if (!(n % 4 == 1 || n % 4 == 0)) { printf("-1\n"); return 0; } for (i = 1; i <= n / 2; i += 2) que[i] = i + 1; for (i = 2; i <= n / 2; i += 2) que[i] = n + 2 - i; for (i = n / 2 + 1; i <= n; 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 N = 1e5 + 7; int n, p[N]; void solve(int n) { if ((n & 1) && (n - 1) % 4) { puts("-1"); return; } if (!(n & 1) && n % 4) { puts("-1"); return; } if (n & 1) p[(n + 1) >> 1] = (n + 1) >> 1; for (int i = (1); i < ((n >> 1) + 1); ++i) 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 arr[1000000]; int main() { int n; while (scanf("%d", &n) != -1) { if (n == 1) { printf("1\n"); continue; } if ((n & 1) && (n - 1) % 4) { printf("-1\n"); continue; } if (!(n & 1) && n % 4) { printf("-1\n"); cont...
### 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; const int MAXN = 1e5 + 5; const long long INF = 1000000000000000; const long long m = 1000000007; int a[MAXN]; long long binpow(long long v, long long st) { long long ans = 1, a = v; for (; st; st >>= 1) { if (st & 1) ans *= a; a *= a; } return ans; } int ma...
### 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 a[100005]; int n; int main() { while (cin >> n) { if (n % 4 == 2 || n % 4 == 3) { puts("-1"); continue; } if (n % 4) a[n / 2 + 1] = n / 2 + 1; for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n + 1 - i; a[n -...
### 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 MAX = 1e5 + 5; int ans[MAX]; int main() { int n; scanf("%d", &n); if (n % 4 >= 2) return 0 * printf("-1\n"); int a = 2, b = n, idx = 1; for (int i = 1; i <= n / 4; ++i) { ans[idx] = a; ans[idx + 1] = b; ans[n - idx + 1] = b - 1; ans[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> #pragma comment(linker, "/stack:64000000") using namespace std; const int MOD = 1000000007; const int INF = 1000 * 1000 * 1000; const double EPS = 1e-9; const long double PI = acos(-1.0); int main() { int n; cin >> n; vector<int> a(n + 1); if (n % 4 == 2 || n % 4 == 3) { cout << -1 ...
### 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; string tostr(long long x) { stringstream ss; ss << x; return ss.str(); } long long toint(string &s) { stringstream ss; ss << s; long long x; ss >> x; return x; } void print(vector<int> p) { for (int i = 0; i < p.size(); i++) { cout << p[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 N; vector<int> v; void dog(int a, int b, int c, int d) { v[a - 1] = b; v[b - 1] = d; v[d - 1] = c; v[c - 1] = a; } int main() { cin >> N; v.resize(N); if (N % 4 > 1) { cout << -1 << endl; return 0; } if (N & 1) { int spc = N / 2 + 1; v[...
### 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 imod = 1e9 + 7; const long long lmod = 1e18 + 7; const int iinf = INT_MAX; const long long linf = LONG_MAX; const double pi = 2 * acos(0.0); const double eps = 1e-7; int n; int a[(int)1e6 + 134]; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); co...
### 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 long maxx = 1ll << 32; const int maxn = 100005; int n, k = 0, m, l, r, x, y, t; int a[maxn]; long long c[maxn]; int dp[maxn]; int vis[maxn]; int gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } struct lee { int num; int x, y; } lo[maxn]; s...
### 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 v[100010]; int main() { int n; while (cin >> n) { memset(v, 0, sizeof(v)); if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; continue; } if (n == 1) { cout << 1 << endl; continue; } int m = n / 4; m <<= 1; in...
### 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; void _ad(int &p) { static int i = 0; p = i++; } int n; int perm[100001] = {0}; bool checkit(vector<int> &a) { for (int i = 0; i < a.size(); i++) { if (a[a[i] - 1] != a.size() - i) return false; } return true; } void past(int l, int r, int mn, int mx) { perm[...
### 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 Maxn = 101000; int a[Maxn]; int n; int main() { scanf("%d", &n); if ((n / 2) % 2 == 1) { printf("-1\n"); return 0; } for (int i1 = 1, i2 = 2, i3 = n - 1, i4 = n; i2 < i3;) { a[i1] = i2; a[i2] = i4; a[i4] = i3; a[i3] = i1; i1 += ...
### 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, a[100005], i; void Solve(int left, int right) { if (left > right) return; if (right - left < 3) { if (left == right) a[left] = right; if (left + 1 == right) a[left] = left, a[right] = right; if (left + 2 == right) a[left] = right, a[left + 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; const int max_n = 1e5 + 15; int n, p[max_n]; int main() { cin >> n; if ((n & 3) > 1) { cout << -1; return 0; } if (n == 1) { cout << 1; return 0; } for (int i = 0; i + i + 1 < n; i += 2) { p[i] = i + 2; p[n - i - 1] = n + 1 - p[i]; p[...
### 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; long p[100001]; bool visit[100001]; long n; bool DFS(int i); int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; if (n > 1) { memset(p, -1, sizeof(p)); memset(visit, false, sizeof(visit)); bool key = true; for (int i = 1; i <= 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; const int N = 100005; int a[N]; int main() { int n, i; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) printf("-1\n"); else { for (i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i] = i; a[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> int ans[100000]; int main() { int a; scanf("%d", &a); if (a % 4 == 2 || a % 4 == 3) { printf("-1\n"); return 0; } if (a % 4 == 0) { for (int i = 0; i < a / 4; i++) { ans[i * 2] = i * 2 + 2; ans[i * 2 + 1] = a - i * 2; ans[a - 1 - i * 2] = a - 1 - i * 2; ...
### 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, b, c, d, n, m, i, j, ans, l, r, lcnt = 1, rcnt; int ar[100005]; int main() { scanf("%d\n", &n); if (n % 4 > 1) { printf("-1\n"); return 0; } lcnt = 1, rcnt = n; l = 1, r = n; for (i = 0; i <= n - 4; i += 4) { ar[l++] = lcnt + 1; ar[l++] = ...
### 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; int f[100002]; void DP() { int i, x, y; for (i = 1; 2 * i <= n; i += 2) { x = i; y = i + 1; f[x] = y; f[y] = n - x + 1; f[n - x + 1] = n - y + 1; f[n - y + 1] = x; } if (n % 4) f[(n + 1) / 2] = (n + 1) / 2; for (i = 1; i < n; i++) printf("%d ", f[i]); ...
### 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() { long long int n, i; cin >> n; if (n % 4 != 1 && n % 4 != 0) { cout << "-1"; return 0; } long long int a[n]; for (i = 0; i < n / 4; i++) { a[2 * i] = 2 * i + 2; a[2 * i + 1] = n - 2 * i; a[n - 2 * i - 1] = n - 2 * i - 1; a[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 DEBUG = 0; int main(int argc, char **argv) { DEBUG = (argc >= 2) ? atoi(argv[1]) : 0; int n; scanf("%d", &n); if (n == 1) { cout << 1 << endl; return 0; } if ((n % 4) == 0 || (n % 4) == 1) { int k = n / 4; for (int i = 1; i <= k; i++) { ...
### 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 P[100010]; int main(int argc, const char *argv[]) { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } for (int i = 1; i <= (n - 1) / 2; i += 2) { P[i] = i + 1; for (int j = i; P[P[j]] == 0; j = P[j]) { P[P[j]] = 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; int outpu[100001]; set<int> se; set<int>::iterator it; int n; int main() { cin >> n; bool k = 0; if ((n - 1) % 4 == 0) { k = 1; outpu[n / 2 + 1] = n / 2 + 1; } if (n % 4 == 0 || n % 4 == 1) { for (int i = 1; i <= n; i++) if (k == 0 || (k == 1 && ...
### 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...