/* I solemnly swear that I am upto no good. */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define MAXN 100005
 #define INF (int)1E10+1
 #define MOD (int)1E9+7
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef
 vector<VPII > VVPII ;

 ll mod1 = 999983 ;
 ll p1 = 971 ;
 ll mod2 = 999931 ;
 ll p2 = 953 ;

 ll add1(ll a, ll b, int fl){
     return (a%mod1+fl*b%mod1+mod1)%mod1 ;
 }
 ll add2(ll a, ll b, int fl){
     return (a%mod2+fl*b%mod2+mod2)%mod2 ;
 }
 ll mul1(ll a , ll b){
     return ((a%mod1)*(b*mod1))%mod1 ;
 }
 ll mul2(ll a, ll b){
     return ((a%mod2)*(b%mod2))%mod2 ;
 }
 ll pow1(ll a, ll x){
     if(x == 0) return 1LL ;
     ll temp = pow(a,x/2) ;
     if (x&1){
         return mul1(mul1(temp,temp),a) ;
     }
     return temp ;
 }

 ll F[5002] ;
 ll B[5002] ;
 //ll pal[5002][5002] ;
 ll dp[5002][5002] ;

 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;

    string s ; cin >> s ;
    F[0] = (int)s[0] ;
    for(int i = 1 ; i < s.size() ; i++){
        F[i] = add1(mul1(F[i-1],p1),(int)s[i],1)  ;
    }
    int sz = s.size() ;
    B[sz-1] = (int)s[sz-1];
    for(int i = sz-2 ; i >= 0 ; i--){
        B[i] = add1(mul1(B[i+1],p1),(int)s[i],1) ;
    }

    //memset(pal,0,sizeof(pal)) ;
    memset(dp,0,sizeof(dp)) ;
    for(int i = 0 ; i < sz; i++){
        //pal[i][i] = 1 ;
        dp[i][i] = 1 ;
    }

    for(int i = sz-1 ; i >= 0 ; i--){
        for(int j = i ; j < sz ; j++){
            if (i > j) continue ;
            if (j == 0){
                dp[i][j] = (add1(F[j],mul1(F[i-1],pow1(p1,j-i+1)),-1) == add1(B[i],mul1(B[j+1],pow1(p1,j-i+1)),-1)) ;
            }
            else{
                dp[i][j] = dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]+ (add1(F[j],mul1(F[i-1],pow1(p1,j-i+1)),-1) == add1(B[i],mul1(B[j+1],pow1(p1,j-i+1)),-1)) ;
            }
        }
    }

    int q ; cin >> q ;
    while (q--){
        int x , y ;
        cin >> x >> y ; x-- ; y-- ;
        cout << dp[x][y] << el ;
    }

 }


/* I solemnly swear that I am upto no good. */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define MAXN 100005
 #define INF (int)1E10+1
 #define MOD (int)1E9+7
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef
 vector<VPII > VVPII ;

 ll mod1 = 999983 ;
 ll p1 = 171 ;
 ll mod2 = 999931 ;
 ll p2 = 953 ;

 ll add1(ll a, ll b, int fl){
     return (a%mod1+fl*b%mod1+mod1)%mod1 ;
 }
 ll add2(ll a, ll b, int fl){
     return (a%mod2+fl*b%mod2+mod2)%mod2 ;
 }
 ll mul1(ll a , ll b){
     return ((a%mod1)*(b*mod1))%mod1 ;
 }
 ll mul2(ll a, ll b){
     return ((a%mod2)*(b%mod2))%mod2 ;
 }
 ll pow1(ll a, ll x){
     if(x == 0) return 1LL ;
     ll temp = pow(a,x/2) ;
     if (x&1){
         return mul1(mul1(temp,temp),a) ;
     }
     return temp ;
 }

 ll F[5002] ;
 ll B[5002] ;
 char pal[5002][5002] ;
 int dp[5002][5002] ;

 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;

    string s ; cin >> s ;
    F[0] = (int)s[0] ;
    for(int i = 1 ; i < s.size() ; i++){
        F[i] = add1(mul1(F[i-1],p1),(int)s[i],1)  ;
    }
    int sz = s.size() ;
    B[sz-1] = (int)s[sz-1];
    for(int i = sz-2 ; i >= 0 ; i--){
        B[i] = add1(mul1(B[i+1],p1),(int)s[i],1) ;
    }

    memset(pal,0,sizeof(pal)) ;
    memset(dp,0,sizeof(dp)) ;
    for(int i = 0 ; i < sz; i++){
        pal[i][i] = 1 ;
    }
    for(int i = 0 ; i < sz ; i++){
        for(int j = i+1 ; j < sz ; j++){
            if (add1(F[j],mul1(F[i-1],pow1(p1,j-i+1)),-1) == add1(F[i],mul1(F[j+1],pow1(p1,j-i+1)),-1)){
                pal[i][j] = 1 ;
            }
        }
    }
    for(int i = sz-1 ; i >= 0 ; i--){
        for(int j = i ; j<sz ; j++){
            dp[i][j] = dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1] + pal[i][j] ;
        }
    }

    int q ; cin >> q ;
    while (q--){
        int x , y ; cin >> x >> y ;
        x-- ; y-- ;
        cout << dp[x][y] << el ;
    }

 }


/* I solemnly swear that I am upto no good. */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define MAXN 100005
 #define INF (int)1E10+1
 #define MOD (int)1E9+7
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef
 vector<VPII > VVPII ;

 ll mod1 = 903303 ;
 ll p1 = 171 ;
 ll mod2 = 999931 ;
 ll p2 = 953 ;

 ll add1(ll a, ll b, int fl){
     return (a%mod1+fl*b%mod1+mod1)%mod1 ;
 }
 ll add2(ll a, ll b, int fl){
     return (a%mod2+fl*b%mod2+mod2)%mod2 ;
 }
 ll mul1(ll a , ll b){
     return ((a%mod1)*(b*mod1))%mod1 ;
 }
 ll mul2(ll a, ll b){
     return ((a%mod2)*(b%mod2))%mod2 ;
 }
 ll pow1(ll a, ll x){
     if(x == 0) return 1LL ;
     ll temp = pow1(a,x/2) ;
     if (x&1){
         return mul1(mul1(temp,temp),a) ;
     }
     return temp ;
 }
 ll pow2(ll a, ll x){
     if(x == 0) return 1LL ;
     ll temp = pow2(a,x/2) ;
     if (x&1){
         return mul2(mul2(temp,temp),a) ;
     }
     return temp ;
 }

 ll F[5002] ;
 ll B[5002] ;
 ll F2[5002] ;
 ll B2[5002] ;
 char pal[5002][5002] ;
 int dp[5002][5002] ;

 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;

    string s ; cin >> s ;
    F[0] = (int)s[0] ;
    F2[0]  = (int)s[0] ;
    for(int i = 1 ; i < s.size() ; i++){
        F[i] = add1(mul1(F[i-1],p1),(int)s[i],1)  ;
        F2[i] = add2(mul2(F2[i-1],p2),(int)s[i],1)  ;
    }
    int sz = s.size() ;
    B[sz-1] = (int)s[sz-1];
    B2[sz-1] = (int)s[sz-1];
    for(int i = sz-2 ; i >= 0 ; i--){
        B[i] = add1(mul1(B[i+1],p1),(int)s[i],1) ;
        B2[i] = add2(mul2(B2[i+1],p2),(int)s[i],1) ;

    }

    memset(pal,0,sizeof(pal)) ;
    memset(dp,0,sizeof(dp)) ;
    for(int i = 0 ; i < sz; i++){
        pal[i][i] = 1 ;
    }
    for(int i = 0 ; i < sz ; i++){
        for(int j = i+1 ; j < sz ; j++){
            if ((add1(F[j],mul1(F[i-1],pow1(p1,j-i+1)),-1) == add1(F[i],mul1(F[j+1],pow1(p1,j-i+1)),-1)) ){
                pal[i][j] = 1 ;
            }
        }
    }
    for(int i = sz-1 ; i >= 0 ; i--){
        for(int j = i ; j<sz ; j++){
            dp[i][j] = dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1] + pal[i][j] ;
        }
    }

    int q ; cin >> q ;
    while (q--){
        int x , y ; cin >> x >> y ;
        x-- ; y-- ;
        cout << dp[x][y] << el ;
    }

 }


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
int n;
vector<int> a;

int main(){
    cin >> n;

    if (n == 2 || n == 3 || n % 4 == 2) {
        puts("-1");
        return 0;
    }

    a.resize(n + 1);

    for (int i = 1;i <= n / 2;i += 2) {
        a[i] = i + 1;
        a[n - i + 1] = n - i;
        a[i + 1] = n - i + 1;
        a[n - i] = i;
    }
    if (n & 1 > 0) {
        a[n / 2 + 1] = n / 2 + 1;
    }
    for (int i=1;i<=n;++i) {
        printf("%d ", a[i]);
    }
    puts("");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
int n;
vector<int> a;

int main(){
    cin >> n;

    if (n % 4 == 3 || n % 4 == 2) {
        puts("-1");
        return 0;
    }

    a.resize(n + 1);

    for (int i = 1;i <= n / 2;i += 2) {
        a[i] = i + 1;
        a[n - i + 1] = n - i;
        a[i + 1] = n - i + 1;
        a[n - i] = i;
    }
    if (n & 1 > 0) {
        a[n / 2 + 1] = n / 2 + 1;
    }
    for (int i=1;i<=n;++i) {
        printf("%d ", a[i]);
    }
    puts("");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
int n;
vector<int> a;

int main(){
    cin >> n;

    if (n == 2 || n == 3) {
        puts("-1");
        return 0;
    }

    a.resize(n + 1);

    for (int i = 1;i <= n / 2;i += 2) {
        a[i] = i + 1;
        a[n - i + 1] = n - i;
        a[i + 1] = n - i + 1;
        a[n - i] = i;
    }
    if (n & 1 > 0) {
        a[n / 2 + 1] = n / 2 + 1;
    }
    for (int i=1;i<=n;++i) {
        printf("%d ", a[i]);
    }
    puts("");

    return 0;
}


#include<iostream>

using namespace std;

int n;

int main()
{
	cin>>n;
	for ( int i = 0 ; i < n ; i++ ) cout<<n-i<<" ";
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>

using namespace std;
const int MAXn = 1000*100+1000;
int n, a[MAXn];

void make( int beg , int end )
{
    if ( end < beg ) return;
    if ( end == beg )
    {
        a[end] = end;
        return;
    }

    a[beg] = beg+1;
    a[beg+1] = end;
    a[end-1] = beg;
    a[end] = end-1;

    make( beg+2, end-2 );
    return;
}

int main()
{
  ios::sync_with_stdio(0);
    cin>>n;
    if ( n%4==2 || n%4==3 )
    {
        cout<<-1;
        return 0;
    }

    make(0, n-1);
    for ( int i = 0 ; i<n ; i++ ) cout<<a[i]+1<<" ";
}


/*
 * LuckyPermutation.cpp
 *
 *  Created on: Apr 4, 2014
 *      Author: abdelkarim
 */

#include <bits/stdc++.h>

using namespace std;

int arr[100000 + 80];
bool vis[100000 + 80];
int n;

int smiulation(int a) {
	memset(arr, 0, sizeof arr);
	memset(vis, 0, sizeof vis);

	int cnt = 1, idx = 1;
	arr[idx] = a;
	vis[a] = 1;
	vis[0] = vis[n + 1] = 1;
	if (n == 1)
		return 1;
	while (true) {

		arr[arr[idx]] = n - idx + 1;

		if (vis[n - idx + 1])
			 break;
		else
			vis[n - idx + 1] = 1;

		idx = arr[idx];
		cnt++;
		if (cnt == n)
			break;
	}
	for(int i = 1 ; i <= n ; i++){
		if(arr[i] == 0){
			arr[i]  = i ;
			if(arr[arr[i]] == i)cnt++;
		}
	}
	return cnt;
}

int main() {
	/*n = 5 ;
	smiulation(2);
	for (int i = 1; i <= n; i++)
		cout << arr[i] << " \n"[i == n];
	return 0;*/

	cin >> n;
	for (int i = 1; i <= min(n, 10); i++) {
		if (smiulation(i) == n) {
			for (int i = 1; i <= n; i++)
				cout << arr[i] << " \n"[i == n];
			return 0;
		}
	}
	puts("-1");
}


/*
 * A. Lucky Permutation.cpp
 *
 *  Created on: May 12, 2014
 *      Author: abdelkarim
 */
#include <bits/stdc++.h>

using namespace std;
int arr[100005];
int main() {
    memset(arr, -1 , sizeof arr);
    int n;
    cin>>n;
    if (n & 1)
        arr[n / 2 + 1] = n / 2 + 1;
    for (int i = 1; i < n / 2; i += 2) {
        arr[i] = i + 1;
        arr[i + 1] = n - i + 1;
        arr[n - i] = i;
        arr[n - i + 1] = n - i;
    }

    for(int i = 1 ; i <= n ; i++){
        if(arr[i] == -1){
            puts("-1");
            exit(0);
        }
    }

    for(int i = 1 ; i <= n ; i++)cout<<arr[i]<<" ";
}


/*
 * LuckyPermutation.cpp
 *
 *  Created on: Apr 4, 2014
 *      Author: abdelkarim
 */

#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 80 ];
int main() {
    int n ;
    cin>>n;
    if(n == 1){
        cout<<1<<endl;
        return 0 ;
    }
    int cnt = 1 , idx = 1;
    arr[1] = 2 ;
    set<int>S ;
    S.insert(2);
    while(cnt++ < n){
        int cur = arr[idx] ;
        arr[cur] = n  - idx + 1;
        S.insert(arr[cur]);
        idx = cur;
    }
    if(n&1){
        arr[(n+1)/2] = (n+1)/2 ;
        S.insert((n+1)/2);
    }

    if(S.size() != n){
        cout<<-1<<endl;
        return 0;
    }
    for(int i = 1 ; i <= n ; i++)cout<<arr[i]<<" \n"[i == n];
}


/*
 * LuckyPermutation.cpp
 *
 *  Created on: Apr 4, 2014
 *      Author: abdelkarim
 */

#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 80 ];
int main() {
    int n ;
    cin>>n;
    if(n == 1){
        cout<<1<<endl;
        return 0 ;
    }
    int cnt = 1 , idx = 1;
    arr[1] = 2 ;
    set<int>S ;
    S.insert(2);
    while(cnt++ < n){
        int cur = arr[idx] ;
        if(arr[cur] != 0){
            cur = 0 ;
            idx = n ;
            for(int k = cur+1 ;cur != k ; k++ , k%=n){
                if(arr[k] == 0){cur = max(k,cur) ;idx = min(idx , cur);}
            }
        }
        arr[cur] = n  - idx + 1;
        S.insert(arr[cur]);
        idx = cur;
    }

    if(n&1){
        arr[(n+1)/2] = (n+1)/2 ;
        S.insert((n+1)/2);
    }

    if(S.size() != n){
        cout<<-1<<endl;
        return 0;
    }
    for(int i = 1 ; i <= n ; i++)cout<<arr[i]<<" \n"[i == n];
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int ans[ 100010 ];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);
    int n;
    cin >> n;
    if( n == 1 )
    {
        cout << 1 << endl;
        return 0;
    }

    set<int> s;
    set<int> s1;
    set<int> s2;
    for(int i = 0 ; i < n ; ++i)
        s1.insert(i+1),s2.insert(i+1);

    bool f = true;
    while(s.size() < n)
    {
        int pos = *s1.begin();
        s1.erase(pos);
        int i = *s2.begin();
        while( s.find(i) != s.end() || (pos == i&&2*i!=(n+1)) ) ++i;
        ans[ pos ] = i;
        s2.erase(i);
        s.insert(i);
        f = false;
        while(1)
        {
            if( ans[ans[pos]] != 0 ) break;
            f = true;
            ans[ans[pos]] = n-pos+1;
            pos = ans[pos];
            s.insert(ans[pos]);
            s2.erase(ans[pos]);
            s1.erase(pos);
        }
    }

    ///9
    ///1 2 3 4 5 6 7 8 9
    ///2 9 4 7 5 3 6 1 8
    s.clear();
    for( int i = 1 ; i <= n ; ++i )
        if(ans[i] >= 1 && ans[i] <= n)
        s.insert(ans[i]);
    if( s.size() != n )
    {
        cout << -1 << endl;
        return 0;
    }

    for( int i = 1 ; i <= n ; ++i )
        cout << ans[i] << " ";
    cout << endl;

    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int ans[ 100010 ];
set<int> s;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);
    int n;
    cin >> n;
    if( n == 1 )
    {
        cout << 1 << endl;
        return 0;
    }
    ans[1] = 2;
    s.insert(2);
    int p = 1;
    int k = 1;
    while(k < n)
    {
        if( ans[ans[p]] != 0 )
        {
            cout << -1 << endl;
            return 0;
        }
        ans[ans[p]] = n-p+1;
        s.insert(ans[p]);
        p = ans[p];
        s.insert(ans[p]);
        ++k;
    }
    if( s.size() != n )
    {
        cout << -1 << endl;
        return 0;
    }
    for( int i = 1;  i <= n ; ++i )
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int ans[ 100010 ];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);
    int n;
    cin >> n;
    for( int k = 1 ; k <= n ; ++k )
    {
        set<int> s;
        ans[1] = k;
        s.insert(k);
        int p = 1;
        bool f = true;
        for( int i = 0 ; i < n-1 && f ; ++i )
        {
            if(ans[ans[p]] != 0 || s.find(n-p+1)!=s.end())
                f = false;
            else
            {
                ans[ans[p]] = n-p+1;
                p = ans[p];
                s.insert(ans[p]);
            }
        }
        if(f)
        {
            for( int i = 1;  i <= n ; ++i )
                cout << ans[i] << " ";
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int ans[ 100010 ];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);
    int n;
    cin >> n;
    if( n == 1 )
    {
        cout << 1 << endl;
        return 0;
    }
    if( n == 4 )
    {
        cout << "2 4 1 3\n";
        return 0;
    }
    if( n % 2 == 0 )
    {
        cout << "-1\n";
        return 0;
    }

    set<int> s;
    set<int> s1;
    for(int i = 0 ; i < n ; ++i)
        s1.insert(i+1);

    while(s.size()<n)
    {
        int pos = *s1.begin();
        s1.erase(pos);
        int i = 1;
        while( s.find(i) != s.end() || (pos == i&&2*i!=(n+1)) ) ++i;
        ans[ pos ] = i;
        s.insert(i);

        while(1)
        {
            if( ans[ans[pos]] != 0 ) break;

            ans[ans[pos]] = n-pos+1;
            pos = ans[pos];
            s.insert(ans[pos]);
            s1.erase(pos);
        }

    }

    ///9
    ///1 2 3 4 5 6 7 8 9
    ///2 9 4 7 5 3 6 1 8
    s.clear();
    for( int i = 1 ; i <= n ; ++i )
        s.insert(ans[i]);
    if( s.size() != n )
    {
        cout << -1 << endl;
        return 0;
    }

    for( int i = 1 ; i <= n ; ++i )
        cout << ans[i] << " ";
    cout << endl;

    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int ans[ 100010 ];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);
    int n;
    cin >> n;
    if( n == 1 )
    {
        cout << 1 << endl;
        return 0;
    }

    set<int> s;
    set<int> s1;
    for(int i = 0 ; i < n ; ++i)
        s1.insert(i+1);

    bool f = true;
    while(s.size() < n&&f)
    {
        int pos = *s1.begin();
        s1.erase(pos);
        int i = 1;
        while( s.find(i) != s.end() || (pos == i&&2*i!=(n+1)) ) ++i;
        ans[ pos ] = i;
        s.insert(i);
        f = false;
        while(1)
        {
            if( ans[ans[pos]] != 0 ) break;
            f = true;
            ans[ans[pos]] = n-pos+1;
            pos = ans[pos];
            s.insert(ans[pos]);
            s1.erase(pos);
        }
    }

    ///9
    ///1 2 3 4 5 6 7 8 9
    ///2 9 4 7 5 3 6 1 8
    s.clear();
    for( int i = 1 ; i <= n ; ++i )
        if(ans[i] >= 1 && ans[i] <= n)
        s.insert(ans[i]);
    if( s.size() != n )
    {
        cout << -1 << endl;
        return 0;
    }

    for( int i = 1 ; i <= n ; ++i )
        cout << ans[i] << " ";
    cout << endl;

    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int ans[ 100010 ];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);
    int n;
    cin >> n;
    if( n == 1 )
    {
        cout << 1 << endl;
        return 0;
    }

    set<int> s;
    set<int> s1;
    for(int i = 0 ; i < n ; ++i)
        s1.insert(i+1);

    bool f = true;
    while(s.size() < n)
    {
        int pos = *s1.begin();
        s1.erase(pos);
        int i = 1;
        while( s.find(i) != s.end() || (pos == i&&2*i!=(n+1)) ) ++i;
        ans[ pos ] = i;
        s.insert(i);
        f = false;
        while(1)
        {
            if( ans[ans[pos]] != 0 ) break;
            f = true;
            ans[ans[pos]] = n-pos+1;
            pos = ans[pos];
            s.insert(ans[pos]);
            s1.erase(pos);
        }
    }

    ///9
    ///1 2 3 4 5 6 7 8 9
    ///2 9 4 7 5 3 6 1 8
    s.clear();
    for( int i = 1 ; i <= n ; ++i )
        if(ans[i] >= 1 && ans[i] <= n)
        s.insert(ans[i]);
    if( s.size() != n )
    {
        cout << -1 << endl;
        return 0;
    }

    for( int i = 1 ; i <= n ; ++i )
        cout << ans[i] << " ";
    cout << endl;

    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int ans[ 100010 ];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);
    int n;
    cin >> n;
    if( n == 1 )
    {
        cout << 1 << endl;
        return 0;
    }
    if( n == 4 )
    {
        cout << "2 4 1 3\n";
        return 0;
    }
    if( n % 2 == 0 )
    {
        cout << "-1\n";
        return 0;
    }
    for( int i = 1 ; 2*i <= (n+1) ; ++i )
        ans[i] = n-i+1 , ans[ans[i]] = n+1-ans[i];
    for( int i = 1 ; i <= n ; ++i )
        cout << ans[i] << " ";
    cout << endl;

    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;
int n;
int re[100009];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    scanf("%d",&n);
    if(n%4==2||n%4==3)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=n/2;i++)
    {

        if((i%2)==1)
        {
            re[i] = i+1;
            re[n+1-i] = n-i;
        }
        if((i%2)==0)
        {
            re[i] = n-i+2;
            re[n+1-i] = i-1;
        }
    }
    if(n%4==1)
    {
        re[n/2+1] = n/2+1;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d ",re[i]);
    }printf("\n");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;
int n;
int re[1000009];
void solve()
{
    for(int i=0;i<n;i++) re[i] = i+1;
    for(int i=2;i<=n;i++)
    {
        int j;
        for(j=i;j<n;j+=i)
        {
            int tmp = re[j-i];
            for(int k=0;k<i;k++)
            re[j+k-i] = re[j+k+1-i];
            re[j-1] = tmp;
        }
        if(j<n+i)
        {
            j-=i;
            int tmp = re[j];
            for(int k=j;k<n;k++)
            re[k] = re[k+1];
            re[n-1] = tmp;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        printf("%2d",re[i]);
    }printf("\n");
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    scanf("%d",&n);solve();
   // for(int i=1;i<=30;i++)
   // {
    //    cout<<i<<" ";
   //     n=i,solve();
   // }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;
int n;
int re[100009];
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    scanf("%d",&n);
    if(n%4==2||n%4==3)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=n/2;i++)
    {
        if(i%4==1)
        {
            re[i] = i+1;
            re[n+1-i] = n-i;
        }
        if(i%4==2)
        {
            re[i] = n-i+2;
            re[n+1-i] = i-1;
        }
    }
    if(n%4==1)
    {
        re[n/2+1] = n/2+1;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d ",re[i]);
    }printf("\n");
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define REP(i,a,b) for (int i=a;i<=b;++i)
#define REPD(i,a,b) for (int i=b;i>=a;--i)
#define FOR(i,n) for (int i=0;i<n;++i)
#define X first
#define Y second
using namespace std;
typedef long long ll;
const int N = 100010;
int n, a[N] = {0};
int main()
{
    scanf("%d",&n);
    if (n == 1) {printf("1"); return 0;}
    if (n == 2) {printf("-1"); return 0;}
    if (n == 3) {printf("-1"); return 0;}
    if (n%4==0 || (n-1)%4==0) {
        int m = n/4, l = 1, r = n;
        if (n%2) a[n/2+1] = n/2+1;
        FOR(i,m) {
            a[i*2+1] = l+1;
            a[i*2+2] = r;
            a[n-i*2] = r-1;
            a[n-i*2-1] = l;
            l += 2; r -= 2;
        }
        REP(i,1,n) printf("%d ",a[i]);
    }
    else printf("-1");
    /*
    if (n != 4 && n != 5) {printf("-1"); return 0;}
    if (n%2) a[n/2+1] = n/2+1;
    int p, fp, pnext, fpnext, cnt, ok;
    REP(start,1,n) {
        p = 1; fp = start; cnt = n%2; ok = 1;
        memset(a,0,sizeof(a));
        if (n%2) a[n/2+1] = n/2+1;
        while (cnt < n) {
            if (a[p] > 0) {ok = 0; break;}
            cnt++;
            a[p] = fp;
            pnext = n - fp + 1;
            fp = p; p = pnext;
        }
        if (ok) {REP(i,1,n) printf("%d ",a[i]); return 0;}
        //printf("%d\n",cnt);
    }
    printf("-1\n");
    */
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define REP(i,a,b) for (int i=a;i<=b;++i)
#define REPD(i,a,b) for (int i=b;i>=a;--i)
#define FOR(i,n) for (int i=0;i<n;++i)
#define X first
#define Y second
using namespace std;
typedef long long ll;
const int N = 100010;
int n, a[N] = {0};
int main()
{
    scanf("%d",&n);
    if (n == 1) {printf("1"); return 0;}
    if (n == 2) {printf("-1"); return 0;}
    if (n == 3) {printf("3 2 1"); return 0;}
    if (n%2) a[n/2+1] = n/2+1;
    int p, fp, pnext, fpnext, cnt, ok;
    REP(start,1,n) {
        p = 1; fp = start; cnt = n%2; ok = 1;
        memset(a,0,sizeof(a));
        if (n%2) a[n/2+1] = n/2+1;
        while (cnt < n) {
            if (a[p] > 0) {ok = 0; break;}
            cnt++;
            a[p] = fp;
            pnext = n - fp + 1;
            fp = p; p = pnext;
        }
        if (ok) {REP(i,1,n) printf("%d ",a[i]); return 0;}
        //printf("%d\n",cnt);
    }
    printf("-1\n");
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define REP(i,a,b) for (int i=a;i<=b;++i)
#define REPD(i,a,b) for (int i=b;i>=a;--i)
#define FOR(i,n) for (int i=0;i<n;++i)
#define X first
#define Y second
using namespace std;
typedef long long ll;
const int N = 100010;
int n, a[N] = {0};
int main()
{
    scanf("%d",&n);
    if (n == 1) {printf("1"); return 0;}
    if (n == 2) {printf("-1"); return 0;}
    if (n == 3) {printf("-1"); return 0;}
    if (n%2) a[n/2+1] = n/2+1;
    int p, fp, pnext, fpnext, cnt, ok;
    REP(start,1,n) {
        p = 1; fp = start; cnt = n%2; ok = 1;
        memset(a,0,sizeof(a));
        if (n%2) a[n/2+1] = n/2+1;
        while (cnt < n) {
            if (a[p] > 0) {ok = 0; break;}
            cnt++;
            a[p] = fp;
            pnext = n - fp + 1;
            fp = p; p = pnext;
        }
        if (ok) {REP(i,1,n) printf("%d ",a[i]); return 0;}
        //printf("%d\n",cnt);
    }
    printf("-1\n");
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define REP(i,a,b) for (int i=a;i<=b;++i)
#define REPD(i,a,b) for (int i=b;i>=a;--i)
#define FOR(i,n) for (int i=0;i<n;++i)
#define X first
#define Y second
using namespace std;
typedef long long ll;
const int N = 100010;
int n, a[N] = {0};
int main()
{
    scanf("%d",&n);
    if (n == 1) {printf("1"); return 0;}
    if (n == 2) {printf("-1"); return 0;}
    if (n == 3) {printf("-1"); return 0;}
    if (n != 4 && n != 5) {printf("-1"); return 0;}
    if (n%2) a[n/2+1] = n/2+1;
    int p, fp, pnext, fpnext, cnt, ok;
    REP(start,1,n) {
        p = 1; fp = start; cnt = n%2; ok = 1;
        memset(a,0,sizeof(a));
        if (n%2) a[n/2+1] = n/2+1;
        while (cnt < n) {
            if (a[p] > 0) {ok = 0; break;}
            cnt++;
            a[p] = fp;
            pnext = n - fp + 1;
            fp = p; p = pnext;
        }
        if (ok) {REP(i,1,n) printf("%d ",a[i]); return 0;}
        //printf("%d\n",cnt);
    }
    printf("-1\n");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf = 100000;
int a[100010];
int main()
{
    int n;
    cin>>n;
    if(n == 2 || n == 3)
    {
        puts("-1");
    }
    else
    {
        if(n == 1) puts("1");
        else
        {
            if(n%2==0)
            {
                for(int i = 1; i <= n/2; i+=2)
                {
                    a[i] = 2 * i;
                }
                int tot = 0;
                for(int i = n-1; i > n/2; i-=2 )
                {
                    tot ++;
                    a[i] = tot * 2 - 1;
                }
                tot = n;
                for(int i = 2 ; i <= n/2; i+=2)
                {
                    a[i] = tot;
                    tot -=2;
                }
                tot = n-1;
                for(int i = n; i > n/2; i-=2)
                {
                    a[i] = tot;
                    tot -= 2;
                }
                for(int i = 1; i <= n; i++) printf("%d ",a[i]);
            }
            else
            {
                a[n/2+1] = n/2 + 1;
                for(int i = 1; i <= n/2; i+=2)
                {
                    a[i] = 2 * i;
                }
                int tot = 0;
                for(int i = n-1; i > n/2+1; i-=2 )
                {
                    tot ++;
                    a[i] = tot * 2 - 1;
                }
                tot = n;
                for(int i = 2 ; i <= n/2; i+=2)
                {
                    a[i] = tot;
                    tot -=2;
                }
                tot = n-1;
                for(int i = n; i > n/2+1; i-=2)
                {
                    a[i] = tot;
                    tot -= 2;
                }
                for(int i = 1; i <= n; i++) printf("%d ",a[i]);
            }
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf = 100000;
int a[100010];
int main()
{
    int n;
    cin>>n;
    if(n == 2 || n == 3)
    {
        puts("-1");
    }
    else
    {
        if(n == 1) puts("1");
        else
        {
            if(n%4==0)
            {
                int tot = 1;
                for(int i = 1; i <= n/2; i+=2)
                {
                    a[i] = 2 * tot;
                    tot++;
                }
                tot = 0;
                for(int i = n-1; i > n/2; i-=2 )
                {
                    tot ++;
                    a[i] = tot * 2 - 1;
                }
                tot = n;
                for(int i = 2 ; i <= n/2; i+=2)
                {
                    a[i] = tot;
                    tot -=2;
                }
                tot = n-1;
                for(int i = n; i > n/2; i-=2)
                {
                    a[i] = tot;
                    tot -= 2;
                }
                for(int i = 1; i <= n; i++) printf("%d ",a[i]);
            }
            else
            {
                int mod = n % 4;
                if(mod==1 || mod==3)
                {
                    a[n/2+1] = n/2 + 1;
                    int tot=1;
                    for(int i = 1; i <= n/2; i+=2)
                    {
                        a[i] = 2 * tot;
                        tot++;
                    }
                    tot = 0;
                    for(int i = n-1; i > n/2+1; i-=2 )
                    {
                        tot ++;
                        a[i] = tot * 2 - 1;
                    }
                    tot = n;
                    for(int i = 2 ; i <= n/2; i+=2)
                    {
                        a[i] = tot;
                        tot -=2;
                    }
                    tot = n-1;
                    for(int i = n; i > n/2+1; i-=2)
                    {
                        a[i] = tot;
                        tot -= 2;
                    }
                    if(mod==3)
                    {
                        swap(a[n/2],a[n/2+2]);
                    }
                    for(int i = 1; i <= n; i++) printf("%d ",a[i]);
                }
                else
                {
                    int tot = 1;
                    a[n/2] = n/2 + 1;
                    a[n/2+1] = n/2 ;
                    for(int i = 1; i < n/2; i+=2)
                    {
                        a[i] = 2 * tot;
                        tot++;
                    }
                    tot = 0;
                    for(int i = n-1; i > n/2+1; i-=2 )
                    {
                        tot ++;
                        a[i] = tot * 2 - 1;
                    }
                    tot = n;
                    for(int i = 2 ; i < n/2 ; i+=2)
                    {
                        a[i] = tot;
                        tot -=2;
                    }
                    tot = n-1;
                    for(int i = n; i > n/2+1; i-=2)
                    {
                  //      printf("i=%d\n",i);
                        a[i] = tot;
                        tot -= 2;
                    }
                    for(int i = 1; i <= n; i++) printf("%d ",a[i]);
                }
            }
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf = 100000;
int a[100010];
int main()
{
    int n;
    cin>>n;
    if(n%4== 2 || n%4 == 3)
    {
        puts("-1");
    }
    else
    {
        if(n == 1) puts("1");
        else
        {
            if(n%4==0)
            {
                int tot = 1;
                for(int i = 1; i <= n/2; i+=2)
                {
                    a[i] = 2 * tot;
                    tot++;
                }
                tot = 0;
                for(int i = n-1; i > n/2; i-=2 )
                {
                    tot ++;
                    a[i] = tot * 2 - 1;
                }
                tot = n;
                for(int i = 2 ; i <= n/2; i+=2)
                {
                    a[i] = tot;
                    tot -=2;
                }
                tot = n-1;
                for(int i = n; i > n/2; i-=2)
                {
                    a[i] = tot;
                    tot -= 2;
                }
                for(int i = 1; i <= n; i++) printf("%d ",a[i]);
            }
            else
            {
                int mod = n % 4;
                if(mod==1)
                {
                    a[n/2+1] = n/2 + 1;
                    int tot=1;
                    for(int i = 1; i <= n/2; i+=2)
                    {
                        a[i] = 2 * tot;
                        tot++;
                    }
                    tot = 0;
                    for(int i = n-1; i > n/2+1; i-=2 )
                    {
                        tot ++;
                        a[i] = tot * 2 - 1;
                    }
                    tot = n;
                    for(int i = 2 ; i <= n/2; i+=2)
                    {
                        a[i] = tot;
                        tot -=2;
                    }
                    tot = n-1;
                    for(int i = n; i > n/2+1; i-=2)
                    {
                        a[i] = tot;
                        tot -= 2;
                    }
                    if(mod==3)
                    {
                        swap(a[n/2],a[n/2+2]);
                    }
                    for(int i = 1; i <= n; i++) printf("%d ",a[i]);
                }
                else
                {
                    int tot = 1;
                    a[n/2] = n/2 + 1;
                    a[n/2+1] = n/2 ;
                    for(int i = 1; i < n/2; i+=2)
                    {
                        a[i] = 2 * tot;
                        tot++;
                    }
                    tot = 0;
                    for(int i = n-1; i > n/2+1; i-=2 )
                    {
                        tot ++;
                        a[i] = tot * 2 - 1;
                    }
                    tot = n;
                    for(int i = 2 ; i < n/2 ; i+=2)
                    {
                        a[i] = tot;
                        tot -=2;
                    }
                    tot = n-1;
                    for(int i = n; i > n/2+1; i-=2)
                    {
                  //      printf("i=%d\n",i);
                        a[i] = tot;
                        tot -= 2;
                    }
                    for(int i = 1; i <= n; i++) printf("%d ",a[i]);
                }
            }
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf = 100000;
int a[100010];
int main()
{
    int n;
    cin>>n;
    if(n%4= 2 || n%4 == 3)
    {
        puts("-1");
    }
    else
    {
        if(n == 1) puts("1");
        else
        {
            if(n%4==0)
            {
                int tot = 1;
                for(int i = 1; i <= n/2; i+=2)
                {
                    a[i] = 2 * tot;
                    tot++;
                }
                tot = 0;
                for(int i = n-1; i > n/2; i-=2 )
                {
                    tot ++;
                    a[i] = tot * 2 - 1;
                }
                tot = n;
                for(int i = 2 ; i <= n/2; i+=2)
                {
                    a[i] = tot;
                    tot -=2;
                }
                tot = n-1;
                for(int i = n; i > n/2; i-=2)
                {
                    a[i] = tot;
                    tot -= 2;
                }
                for(int i = 1; i <= n; i++) printf("%d ",a[i]);
            }
            else
            {
                int mod = n % 4;
                if(mod==1)
                {
                    a[n/2+1] = n/2 + 1;
                    int tot=1;
                    for(int i = 1; i <= n/2; i+=2)
                    {
                        a[i] = 2 * tot;
                        tot++;
                    }
                    tot = 0;
                    for(int i = n-1; i > n/2+1; i-=2 )
                    {
                        tot ++;
                        a[i] = tot * 2 - 1;
                    }
                    tot = n;
                    for(int i = 2 ; i <= n/2; i+=2)
                    {
                        a[i] = tot;
                        tot -=2;
                    }
                    tot = n-1;
                    for(int i = n; i > n/2+1; i-=2)
                    {
                        a[i] = tot;
                        tot -= 2;
                    }
                    if(mod==3)
                    {
                        swap(a[n/2],a[n/2+2]);
                    }
                    for(int i = 1; i <= n; i++) printf("%d ",a[i]);
                }
                else
                {
                    int tot = 1;
                    a[n/2] = n/2 + 1;
                    a[n/2+1] = n/2 ;
                    for(int i = 1; i < n/2; i+=2)
                    {
                        a[i] = 2 * tot;
                        tot++;
                    }
                    tot = 0;
                    for(int i = n-1; i > n/2+1; i-=2 )
                    {
                        tot ++;
                        a[i] = tot * 2 - 1;
                    }
                    tot = n;
                    for(int i = 2 ; i < n/2 ; i+=2)
                    {
                        a[i] = tot;
                        tot -=2;
                    }
                    tot = n-1;
                    for(int i = n; i > n/2+1; i-=2)
                    {
                  //      printf("i=%d\n",i);
                        a[i] = tot;
                        tot -= 2;
                    }
                    for(int i = 1; i <= n; i++) printf("%d ",a[i]);
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,pr[1010];
int main()
{
    //freopen("r.txt","r",stdin);
    scanf("%d",&n);
    int st=1 , End=n;
    if(n%4>1)
    {
        printf("-1");
        return 0;
    }
    for(int i=1;i<=n/2;i+=2)
    {
        pr[End-1]=i;
        pr[st]=i+1;
        pr[End]=End-1;
        pr[st+1]=End;
        st+=2 , End-=2;
    }
    if(st==End)
        pr[End]=End;
    for (int j=1;j<=n;j++)
        printf("%d ",pr[j]);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,pr[100010];
int main()
{
    //freopen("r.txt","r",stdin);
    scanf("%d",&n);
    int st=1 , End=n;
    if(n%4>1)
    {
        printf("-1");
        return 0;
    }
    for(int i=1;i<=n/2;i+=2)
    {
        pr[End-1]=i;
        pr[st]=i+1;
        pr[End]=End-1;
        pr[st+1]=End;
        st+=2 , End-=2;
    }
    if(st==End)
        pr[End]=End;
    for (int j=1;j<=n;j++)
        printf("%d ",pr[j]);

    return 0;
}


// Warning! It's HadronWave code (c)
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#include <stack>
using namespace std;

typedef long long ll;

const long double pi = 3.14159265358979;
const int INF = 1<<28;

bool go[100001];

int main()
{
    //freopen("horse.in","r",stdin);
    //freopen("horse.out","w",stdout);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n;
    cin >> n;

    vector<int> A(n+1);
    A[1] = 2;
    int used = 1;
    int prev = 1;

    go[2] = true;
    if(n==1){
        cout << 1;
    }else if(n==2 || n%3==0){
        cout << -1;
    }else{
        while(used<n-n%2){
            A[A[prev]] = n-prev+1;
            go[n-prev+1] = true;
            prev = A[prev];
            ++used;
        }
        if(n%2)A[(n+1)/2]=(n+1)/2;
        for(int i=1;i<=n;++i){
            cout << A[i] << ' ';
        }
    }
    return 0;
}


// Warning! It's HadronWave code (c)
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#include <stack>
using namespace std;

typedef long long ll;

const long double pi = 3.14159265358979;
const int INF = 1<<28;

int A[100001];

int main()
{
    //freopen("horse.in","r",stdin);
    //freopen("horse.out","w",stdout);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n;
    cin >> n;

    if(n==1){
        cout << 1;
    }else if((n-3)%4==0 || (n-2)%4==0){
        cout << -1;
    }else{
        for(int i=1;i<=n;++i){
            if(i==(n+1)/2){
                if(n%2) A[i] = (n+1)/2;
                else  A[i] = n - 4*((i-1)/2);
            }else if(i<(n+1)/2){
                if(i%2) A[i] = 2*(i/2) + 2;
                else  A[i] = n - 4*((i-1)/2);
            }
        }
        for(int i=1;i<=n;++i){
            A[A[i]] = n-i+1;
        }

        for(int i=1;i<=n;++i){
            cout << A[i] << ' ';
        }
    }
    return 0;
}


// Warning! It's HadronWave code (c)
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#include <stack>
using namespace std;

typedef long long ll;

const long double pi = 3.14159265358979;
const int INF = 1<<28;

int main()
{
    //freopen("horse.in","r",stdin);
    //freopen("horse.out","w",stdout);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n;
    cin >> n;

    vector<int> A(n+1);

    if(n==1){
        cout << 1;
    }else if((n-3)%4==0 || (n-2)%4==0){
        cout << -1;
    }else{
        for(int i=1;i<=n;++i){
            if(i==(n+1)/2 && n%2){
                A[i] = (n+1)/2;
            }else if(i<(n+1)/2){
                if(i%2) A[i] = i*((i+1)/2) + 1;
                else  A[i] = 4*((i-1)/2) + 4;
            }
        }
        for(int i=1;i<=n;++i){
            A[A[i]] = n-i+1;
        }

        for(int i=1;i<=n;++i){
            cout << A[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <algorithm>
#include <fstream>
using namespace std;

#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()

#define mod 1000000007
#define int_max 200000000000
#define LL long long

int main()
{
	int n;
	cin>> n;
	if(n==1)
	{
		cout << "1"<< endl;
		return 0;
	}
	int p[n+1], vis[n+1];
	memset(p,0, sizeof(p));
	memset(vis, 0, sizeof(vis));
	int i=1;
	p[i]=2;
	vis[2]=1;
	int cnt=1;
	while(true)
	{
		if(cnt==n)
			break;
		p[p[i] ]=n-i+1;
		vis[ p[p[i]] ]=1;
		i=p[i];
		cnt++;
	}
	if(n%2==1)
	{
		p[n/2+1]=n/2+1;
		vis[n/2+1]=1;
	}
	int flag=0;
	for(int i=1; i<=n; i++)
		if(vis[i]==0)
		{
			flag=1;
			break;
		}
	if(flag==1)
	{
		cout << "-1"<< endl;
	}
	else
	{
		for(int i=0; i<n; i++)
			cout << p[i+1]<< " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <algorithm>
#include <fstream>
using namespace std;

#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()

#define mod 1000000007
#define int_max 200000000000
#define LL long long
LL a[200005];
LL sum[200005][2],check[200005][2];
int n;
LL recurse(int x,int c)
{
    if(sum[x][c]!=0)
		return sum[x][c];
    if(check[x][c]==1)
		return -1;
    check[x][c]=1;
    int xx;
    if(c)
		xx=x+a[x];
    else
		xx=x-a[x];
    if(xx<=0||xx>n)
		sum[x][c]=0;
    else{
    	int cc;
		if(c==0) cc=1;
		else cc=0;
		sum[x][c]=recurse(xx, cc);
    }
    if(sum[x][c]!=-1)
		sum[x][c]+=a[x];
    return sum[x][c];
}
int main()
{
	scanf("%d",&n);
	memset(sum,0,sizeof(sum));
	memset(check,0,sizeof(check));
	for(int i=2;i<=n;i++)
		scanf("%I64d",&a[i]);
	for(int i=2;i<=n;i++)
		recurse(i,0);
	for(int i=1;i<n;i++)
		if(sum[i+1][0]==-1)
			printf("-1\n");
		else
			printf("%I64d\n",sum[i+1][0]+i);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <algorithm>
#include <fstream>
using namespace std;

#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()

#define mod 1000000007
#define int_max 200000000000
#define LL long long

int main()
{
	int i, n;
	cin>> n;
	int P[n+1];
	memset(P, 0, sizeof(P));
	if (n%4==2 || n%4==3)
	{
		cout << "-1"<< endl;
		return 0;
	}
	for (i=0; i<n/2; i+=2)
	{
		P[i]=i+2;
		P[i+1]=n-i;
		P[n-i-1]=n-i-1;
		P[n-i-2]=i+1;
	}
	if (n%2==1)
		P[n/2]=n/2+1;
	for (i=0; i<n; i++)
		cout << P[i]<< " ";
	cout << endl;
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int i,p[120000],n;
int main(){
	scanf("%d",&n);
	if(n%4!=0 && n%4!=1)return puts("-1"),0;
	for(i=1;i+i<=n;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)p[n/2+1]=n/2+1;
	for(i=1;i<=n;++i)printf("%d ",p[i]);
}


#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
using namespace std;
int i,p[120000],n;
int main(){
	scanf("%d",&n);
	if(n%4!=0 && n%4!=1)return puts("-1"),0;
	for(i=1;i+i<=n;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)p[n/2+1]=n/2+1;
	for(i=1;i<=n;++i)printf("%d ",p[i]);
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define abs(x) ((x)>0?(x):-(x))
#define MOD 1000000007
#define lld signed long long int
#define pp pop_back()
#define ps(x) push_back(x)
#define mpa make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)
#define boost ios_base::sync_with_stdio(0)
//vector<int> g[2*100000+5];int par[2*100000+5];
int P[100000+5];
int main()
{
    //fre;
    int N;
    cin>>N;

    if(N==1)
    {
        cout<<1;
        return 0;
    }
    if(N%4==2)
    {
        cout<<-1;
        return 0;
    }
    if(N%2==1)
    {
        P[N/2+1] = (N+1)/2;
    }
    int L=1;
    int R=N;
    int toggle = 0;
    int at = 1;

    while(L+1<R-1)
    {
        P[L] = at+1;
        P[R-1] = at;
        P[L+1] = N+1-at;
        P[R] = N-at;
        at+=2;
        L+=2;
        R-=2;
    }
    for(int i=1;i<=N;++i)
    {
        cout<<P[i]<<' ';
    }
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define fre     freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define abs(x) ((x)>0?(x):-(x))
#define MOD 1000000007
#define lld signed long long int
#define pp pop_back()
#define ps(x) push_back(x)
#define mpa make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)
#define boost ios_base::sync_with_stdio(0)
//vector<int> g[2*100000+5];int par[2*100000+5];
int P[100000+5];
int main()
{
    //fre;
    int N;
    cin>>N;
    if(N%4==2 or N%4==3)
    {
        cout<<-1;
        return 0;
    }
    if(N%2==1)
    {
        P[N/2+1] = (N+1)/2;
    }
    int L=1;
    int R=N;
    int toggle = 0;
    int at = 1;

    while(L+1<R-1)
    {
        P[L] = at+1;
        P[R-1] = at;
        P[L+1] = N+1-at;
        P[R] = N-at;
        at+=2;
        L+=2;
        R-=2;
    }
    if(L+1==R)
    {
        P[R]=at;
        P[L]=at+1;
    }
    for(int i=1;i<=N;++i)
    {
        cout<<P[i]<<' ';
    }
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string.h>
#include <set>
#include <map>
using namespace std;

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
typedef pair<int, int> ii;
typedef long long int ll;
typedef pair<ll, ll> pl;
typedef pair<ii, int> pi;
#define x first
#define y second

int N;

int main() {
	scanf("%d", &N);
	if (N%4 != 1) {
		printf("-1\n");
		return 0;
	}
	for(int i=1; i<=N/2; i+=2) {
		printf("%d %d ", i+1, N-i+1);
	}
	printf("%d ", (N+1)/2);
	for(int i=(N+3)/2; i<=N; i+=2) {
		printf("%d %d ", N-i, i);
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string.h>
using namespace std;

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
typedef pair<int, int> ii;
typedef long long ll;

int N, t;
vector<int> A;
ll tot;
int x, a;

int main() {
	scanf("%d", &N);
	A.push_back(0);
	REP(i, N) {
		scanf("%d", &t);
		if (t==1) {
			scanf("%d%d", &a, &x);
			REP(i, a) A[i] += x;
			tot += (a*x);
		}
		else if (t==2) {
			scanf("%d", &x);
			A.push_back(x);
			tot += x;
		}
		else if (t==3) {
			tot -= A.back();
			A.pop_back();
		}
		printf("%f\n", tot/(double)A.size());
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string.h>
#include <set>
#include <map>
using namespace std;

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
typedef pair<int, int> ii;
typedef long long int ll;
typedef pair<ll, ll> pl;
typedef pair<ii, int> pi;
#define x first
#define y second

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/2; i+=2) {
		printf("%d %d ", i+1, N-i+1);
	}
	if (N%4==1) printf("%d ", (N+1)/2);
	for(int i=(N+3)/2; i<=N; i+=2) {
		printf("%d %d ", N-i, i);
	}
}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 100010

int p[NN];

int main() {

	int N;

	cin>>N;

	if(N%4>1){

		puts("-1");

		return 0;

	}

	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&1) p[N/2+1]=N/2+1;

	for(int i=1; i<=N; i++) cout<<p[i]<<' ';

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 101000

int p[NN];

int main() {

	int n;

	scanf("%d", &n);

	if (n==1) {

		puts("1");

		return 0;

	}

	if (n==2) {

		puts("-1");

		return 0;

	}

	if (n==3) {

		puts("-1");

		return 0;

	}

	int ok=1;

	if (n%4==3) ok=-1;

	for (int i=1; i<=n; i++) {

		if (p[i]) continue;

		int cc=i+ok;

		if (!cc) cc=n;

		while (p[cc]) cc++;

		p[i]=cc;

		int cur=i;

		while (1) {

			p[p[cur]]=n-cur+1;

			cur=p[cur];

			if (cur==i) break;

		}

	}

	if (n&1) p[n/2+1]=n/2+1;

	for (int i=1; i<=n; i++) printf("%d ", p[i]);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 101000

int p[NN];

int main() {

	int n;

	scanf("%d", &n);

	if (n==1) {

		puts("1");

		return 0;

	}

	if (n==2) {

		puts("-1");

		return 0;

	}

	if (n%4==3) {

		puts("-1");

		return 0;

	}

	for (int i=1; i<=n; i++) {

		if (p[i]) continue;

		int cc=i+1;

		while (p[cc]) cc++;

		p[i]=cc;

		int cur=i;

		while (1) {

			p[p[cur]]=n-cur+1;

			cur=p[cur];

			if (cur==i) break;

		}

	}

	if (n&1) p[n/2+1]=n/2+1;

	for (int i=1; i<=n; i++) printf("%d ", p[i]);

	return 0;

}


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator

#define MOD 1000000009LL
#define EPS 1e-8

int main(){
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        a[i] = i + 1;
    }

    if(n == 2){
        a.assign(1, -1);
    }
    else if(n > 2){
        int k = n - 1;
        for(int i = 0; i < k; i += 2, k -= 2){
            swap(a[i], a[i+1]);
            swap(a[i+1], a[k]);
            swap(a[k], a[k-1]);
        }
    }

    for(int i = 0; i < a.size(); ++i){
        if(i != 0){ putchar(' '); }
        printf("%d", a[i]);
    }
    puts("");
}


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator

#define MOD 1000000009LL
#define EPS 1e-8

int main(){
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        a[i] = i + 1;
    }

    if(n % 4 > 1){
        a.assign(1, -1);
    }
    else if(n > 2){
        int k = n - 1;
        for(int i = 0; i < k; i += 2, k -= 2){
            swap(a[i], a[i+1]);
            swap(a[i+1], a[k]);
            swap(a[k], a[k-1]);
        }
    }

    for(int i = 0; i < a.size(); ++i){
        if(i != 0){ putchar(' '); }
        printf("%d", a[i]);
    }
    puts("");
}


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator

#define MOD 1000000009LL
#define EPS 1e-8

int main(){
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        a[i] = i + 1;
    }

    if(n % 4 == 2){
        a.assign(1, -1);
    }
    else if(n > 2){
        int k = n - 1;
        for(int i = 0; i < k; i += 2, k -= 2){
            swap(a[i], a[i+1]);
            swap(a[i+1], a[k]);
            swap(a[k], a[k-1]);
        }
    }

    for(int i = 0; i < a.size(); ++i){
        if(i != 0){ putchar(' '); }
        printf("%d", a[i]);
    }
    puts("");
}


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator

#define MOD 1000000009LL
#define EPS 1e-8

int main(){
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        a[i] = i + 1;
    }

    if(n == 2){
        a.assign(1, -1);
    }
    else if(n > 2){
        swap(a[0], a[1]);
        swap(a[1], a.back());
    }

    for(int i = 0; i < a.size(); ++i){
        if(i != 0){ putchar(' '); }
        printf("%d", a[i]);
    }
    puts("");
}


//zzy.2013.3.23
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define ll long long
#define INF 0x7fffffff
#define EPS (1e-10)
#define PI (acos(-1.0))

int a[100001];
bool flag;

bool check(int n){
    for(int i=1; i<=n; ++i){
        int j = a[i];
        if(!j || a[j] != n-i+1)
            return false;
    }
    return true;
}

bool solve(int n){
    for(int ii=2; ii<=n; ii++){
        int id = 1,cnt = 0;
        for(int i=1; i<=n; i++)
            a[i] = 0;
        a[1] = ii;
        cnt = 1;
        while(1){
            int id2 = a[id];
            if(a[id2] != 0){
                break;
            }
            a[id2] = n - id + 1;
            id = id2;
            ++cnt;
        }
        if(n % 2 == 1){
            a[n/2+1] = n/2+1;
            cnt ++;
        }
        if(cnt == n && check(n))
            return true;
    }
    return false;
}

void print(int n){
    for(int i=1; i<=n; i++)
        printf("%d ",a[i]);
}

int main()
{
    int n;
    flag = true;
    scanf("%d",&n);
    if(solve(n))
        print(n);
    else
        printf("-1");
    return 0;
}


//zzy.2013.3.23
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define ll long long
#define INF 0x7fffffff
#define EPS (1e-10)
#define PI (acos(-1.0))

int a[100001];

int main()
{
    int n;
    cin >> n;
    if(n % 4 == 0 || (n-1)%4 == 0){
        if(n % 2 == 1) a[n / 2 + 1] = n / 2 + 1;
        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;
        }
        for(int i=1; i<=n; i++)
            printf("%d ",a[i]);
    }
    else
        printf("-1");
    return 0;
}


//zzy.2013.3.23
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define ll long long
#define INF 0x7fffffff
#define EPS (1e-10)
#define PI (acos(-1.0))

int a[100001];
bool flag;

bool check(int n){
    for(int i=1; i<=n; ++i){
        int j = a[i];
        if(!j || a[j] != n-i+1)
            return false;
    }
    return true;
}

bool solve(int n){
    for(int ii=2; ii<=n; ii++){
        int id = 1,cnt = 0;
        for(int i=1; i<=n; i++)
            a[i] = 0;
        a[1] = ii;
        cnt = 1;
        while(1){
            int id2 = a[id];
            if(a[id2] != 0){
                break;
            }
            a[id2] = n - id + 1;
            id = id2;
            ++cnt;
        }
        if(n % 2 == 1){
            a[n/2+1] = n/2+1;
            cnt ++;
        }
        if(cnt == n && check(n))
            return true;
    }
    return false;
}

void print(int n){
    for(int i=1; i<=n; i++)
        printf("%d ",a[i]);
}

int main()
{
    int n;
    flag = true;
    scanf("%d",&n);
    if(n == 1)
        printf("1");
    else if(solve(n))
        print(n);
    else
        printf("-1");
    return 0;
}


//zzy.2013.3.23
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define ll long long
#define INF 0x7fffffff
#define EPS (1e-10)
#define PI (acos(-1.0))

int a[100001];
bool flag;

bool check(int n){
    for(int i=1; i<=n; ++i){
        int j = a[i];
        if(!j || a[j] != n-i+1)
            return false;
    }
    return true;
}

bool solve(int n){
    for(int ii=2; ii<=2; ii++){
        int id = 1,cnt = 0;
        for(int i=1; i<=n; i++)
            a[i] = 0;
        a[1] = ii;
        cnt = 1;
        while(1){
            int id2 = a[id];
            if(a[id2] != 0){
                break;
            }
            a[id2] = n - id + 1;
            id = id2;
            ++cnt;
        }
        if(n % 2 == 1){
            a[n/2+1] = n/2+1;
            cnt ++;
        }
        if(cnt == n && check(n))
            return true;
    }
    return false;
}

void print(int n){
    for(int i=1; i<=n; i++)
        printf("%d ",a[i]);
}

int main()
{
    int n;
    flag = true;
    scanf("%d",&n);
    if(n == 1)
        printf("1");
    else if(solve(n))
        print(n);
    else
        printf("-1");
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);
int ara[100005];
int main()
{
    int n;
    cin >> n;
    if(n % 4 <= 1){
        int in = 2;
        for(int i = 1;i<=n/2;i+=2,in+=2){
                ara[i] = in;
                ara[n-i+1] = n - in + 1;
        }
        in = n;
        for(int i = 2;i<=n/2;i+=2,in-=2){
            ara[i] = in;
            ara[n-i+1] = n+1-in;
        }
        if(n%4==1)ara[n/2 + 1] = n/2 + 1;
        FOR(i,1,n)cout << ara[i] << " ";
    }
    else{
        cout << -1;

    }
//    int n;
//    cin >> n;
//    FOR(i,1,n)ara[i] = i;
//
//    do
//    {
//        int ok = 1;
//        for(int i = 1;i<=n;i++){
//            if(ara[ara[i]]!=n - i +1)ok = 0;
//            if(!ok)break;
//        }
//        if(ok){
//            FOR(i,1,n)cout << ara[i] << " ";
//            cout << endl;
//        }
//    }while(next_permutation(ara+1,ara+n+1));

}


#include<bits/stdc++.h>
#define MAXN 100010
using namespace std;
int arr[MAXN+1];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	if(n%4==2||n%4==3)
		cout<<-1<<"\n";
	else{
		for(int i=1;i<(n/2);i+=2){
			arr[i]=i+1;
			arr[i+1]=n-i+1;
			arr[n-i+1]=n-i;
			arr[n-i]=i;
		}
		if(n%4)
			arr[(n+1)/2]=(n+1)/2;
		for(int i=1;i<=n;i++)
			cout<<arr[i]<<" ";
		cout<<"\n";
	}
	return 0;
}


//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = 1e5+5;

int n, p[N];

int main() {
  init_ios();
  cin >> n;
  if (n%4 > 1) {
    cout<<"-1\n";
    return 0;
  }
  int a = 2, b = n;
  for (int i = 1; i < n/2; i += 2) {
    p[i] = a, p[i+1] = b;
    p[n+1-i] = b-1, p[n-i] = a-1;
    a += 2;
    b -= 2;
  }
  if (n%4 == 1)
    p[(n+1)/2] = (n+1)/2;
  for (int i = 1; i <= n; ++i)
    cout<<p[i]<<" ";
  cout<<"\n";
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define PI 			3.14159265358979323
#define endl '\n'
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N=1000006;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
const ll MOD=1000000007LL;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
int p[N];
void go(int l,int r,int mini,int maxi){
	if(r==l){
		p[l]=mini; return;
	}
	//trace4(l,r,mini,maxi);
	if(r-l+1<4) return;
	p[l]=mini+1;
	p[l+1]=maxi;
	p[r]=maxi-1;
	p[r-1]=mini;
	go(l+2,r-2,mini+2,maxi-2);
}
int32_t main(){
	int n; cin>>n;
	if(n==1){
		cout<<"1"; return 0;
	}
	else if(n==2 || n==3){
		cout<<"-1"; return 0;
	}
	go(1,n,1,n);
	rep(i,1,n+1){
		if(p[i]<=0 || p[p[i]]!=n-i+1){
			cout<<"-1"; return 0;
		}
	}
	rep(i,1,n+1) cout<<p[i]<<" ";
}


#include<iostream>

using namespace std;

int main(){
int n;
cin>>n;
int ans[n];
if(n%4==2||n%4==3){
cout<<"-1"<<endl;return 0;
}

int cnt=0;
int st=0;
while(cnt<n/4){
ans[st]=st+2;
ans[st+1]=n-st;
ans[n-1-st]=n-1-st;
ans[n-1-st-1]=st+1;
cnt++;
st+=2;
}

if(n%4==1){
ans[(n+1)/2-1]=(n+1)/2;
}

for(int i=0;i<n;i++){
cout<<ans[i];if(i!=n-1){cout<<" ";}
}

cout<<endl;

return 0;
}


#include<iostream>

using namespace std;

int main(){
int n;
cin>>n;
int ans[n];
if(n%4==2||n%4==3){
cout<<"-1"<<endl;return 0;
}

int cnt=0;
int st=0;
while(cnt<n/4){
ans[st]=st+2;
ans[st+1]=n-st;
ans[n-1-st]=n-1-st;
ans[n-1-st-1]=st+1;
cnt++;
}

if(n%4==1){
ans[(n+1)/2-1]=(n+1)/2;
}

for(int i=0;i<n;i++){
cout<<ans[i];if(i!=n-1){cout<<" ";}
}

cout<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define speedgeek ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c) min(a,min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a,max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))//never use lli_MAX and lli_MIN with memeset function
#define ll long long int
#define N 1000000007

int main()
{
  speedgeek;
  int n;cin>>n;
  if(n%4==2 || n%4==3)
  	 { cout<<-1<<endl;
  	  return 0;}
  long a[n+1];
  fill(a,-1);
  int i = 1;

  while(i<n+1)
     {
       if(a[i]==-1 && a[i+1]==-1)
       	  {a[i] = i+1;
             int t = n-i+1;
              a[i+1] = t;
              a[t] = n-i-1+1;
              a[n-i] = i;
          }
       else if(a[i]==-1 && a[i+1]!=-1)
          {
               a[i] = i;
          }
          i+=2;
     }
     for(int i=1;i<=n;i++)
     	 cout<<a[i]<<" ";
     	 cout<<endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define speedgeek ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c) min(a,min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a,max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))//never use lli_MAX and lli_MIN with memeset function
#define ll long long int
#define N 1000000007

int main()
{
  speedgeek;
  int n;cin>>n;
  if(n==2 || n%4==3)
  	 { cout<<-1<<endl;
  	  return 0;}
  long a[n+1];
  fill(a,-1);
  int i = 1;
  if(n%4==2)
  	 {
  	 	 a[n/2] = n/2+1;
  	 	 a[n/2+1] = n/2;
  	 }
  while(i<n+1)
     {
       if(a[i]==-1 && a[i+1]==-1)
       	  {a[i] = i+1;
             int t = n-i+1;
              a[i+1] = t;
              a[t] = n-i-1+1;
              a[n-i] = i;
          }
       else if(a[i]==-1 && a[i+1]!=-1)
          {
               a[i] = i;
          }
          i+=2;
     }
     for(int i=1;i<=n;i++)
     	 cout<<a[i]<<" ";
     	 cout<<endl;

  return 0;
}


//IN THE NAME OF GOD
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <map>
#define  pb push_back
#define  S second
#define  F first
#define ra ragham
#define ll long long
using namespace std;
typedef pair<ll,ll> pii ;
typedef pair<char,char> cii ;
int a[100000+100];
int main()
{
 ll n ;
 cin>> n ;
 if(!((n%4==0)+(n%4==1)))
 {
     cout<<-1;
     return 0;
 }
 if(n%4==1)
    a[(n+1)/2]=(n+1)/2;
 for(ll y = 1 ; y <= (n+1)/2;y++)
 {
     if(!(a[y]))
     {
         a[y] = y+1;
         a[y+1] = n - y  + 1 ;
         a[n-y+1] = n-y;
         a[n-y] = y ;
     }
 }
 for(ll y = 1 ; y <= n ; y++)
    cout<<a[y]<<' ';

}


//IN THE NAME OF GOD
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <map>
#define  pb push_back
#define  S second
#define  F first
#define ra ragham
#define ll long long
using namespace std;
typedef pair<ll,ll> pii ;
typedef pair<char,char> cii ;
int a[100000+100];
int main()
{
 ll n ;
 cin>> n ;
 if(!((n%4==0)+(n%4==1)))
 {
     cout<<-1;
     return 0;
 }
 if(n%4==1)
    a[(n+1)/2]=(n+1)/2;
 for(ll y = 1 ; y <= (n+1)/2;y++)
 {
     if(!(a[y]))
     {
         a[y] = y+1;
         a[y+1] = n - y  + 1 ;
         a[n-y+1] = n-y;
         a[n-y] = y ;
     }
 }
 for(ll y = 1 ; y <= n ; y++)
    cout<<a[y];

}


#include<bits/stdc++.h>
using namespace std;
//      std macros
typedef long long ll;
typedef vector<list<ll> > vli;
typedef vector<ll > vi;
typedef vector<pair<ll,ll> > vpll;
typedef vector<pair<int,int> > vpii;
typedef pair<int ,int> pii;
//      dereference
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define in insert
#define pu push
#define fr front
//      loops
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define PER(i,b,a) for(int i=b;i>=a;--i)
#define all(X) (X).begin(), (X).end()
//      I/O
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define sd(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define oll(n) printf("%lld\n",n)
//      debug
#define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
//      set values
#define mset(n,k) memset(n,k,sizeof(n))
#define MOD 1000000007
ll INV2=500000004;
ll INV6=166666668;
//modular expo
ll power(ll a,ll b, ll c){
    ll x=1,y=a;
    while(b>0){
        if(b&1)
            x=(x*y)%c;
        y=(y*y)%c;
        b/=2;
    }
    return x%c;
}
//perfect numbers till 10^6 6, 28, 496, 8128
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};//clockwise from left
int dr[]={1,1,0,-1,-1,-1, 0, 1};
int dc[]={0,1,1, 1, 0,-1,-1,-1};//anticlockwise from down
int ans[100005];
int main(){

	int n;
	sd(n);
	if(n==2 || n==6 || n==3)
	{
		printf("-1\n");
	}
	else
	{
		int mid=n/2 +1;
		if(n&1)
		{
			ans[mid]=mid;
			for(int i=1;i<mid;i+=2)
			{
				ans[i]=i+1;
			}
			int val=n;
			for(int i=2;i<mid;i+=2)
			{
				ans[i]=val;
				val-=2;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				val+=2;
			}
		}
		else
		{
			mid=n/2;
			for(int i=1;i<=mid;i+=2)
			{
				ans[i]=i+1;
			}
			int val=n;
			for(int i=2;i<=mid;i+=2)
			{
				ans[i]=val;
				val-=2;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				val+=2;
			}
		}
		REP(i,1,n)
		{
			printf("%d ",ans[i]);
		}
		printf("\n");
	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
//      std macros
typedef long long ll;
typedef vector<list<ll> > vli;
typedef vector<ll > vi;
typedef vector<pair<ll,ll> > vpll;
typedef vector<pair<int,int> > vpii;
typedef pair<int ,int> pii;
//      dereference
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define in insert
#define pu push
#define fr front
//      loops
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define PER(i,b,a) for(int i=b;i>=a;--i)
#define all(X) (X).begin(), (X).end()
//      I/O
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define sd(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define oll(n) printf("%lld\n",n)
//      debug
#define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
//      set values
#define mset(n,k) memset(n,k,sizeof(n))
#define MOD 1000000007
ll INV2=500000004;
ll INV6=166666668;
//modular expo
ll power(ll a,ll b, ll c){
    ll x=1,y=a;
    while(b>0){
        if(b&1)
            x=(x*y)%c;
        y=(y*y)%c;
        b/=2;
    }
    return x%c;
}
//perfect numbers till 10^6 6, 28, 496, 8128
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};//clockwise from left
int dr[]={1,1,0,-1,-1,-1, 0, 1};
int dc[]={0,1,1, 1, 0,-1,-1,-1};//anticlockwise from down
int ans[100005];
bool fl;
int has[100005];
int main(){

	int n;
	sd(n);
	if(n==2 || n==3 || n==6)
	{
		printf("-1\n");
	}
	else
	{
		int mid=n/2 +1;
		if(n&1)
		{
			ans[mid]=mid;
			for(int i=1;i<mid;i+=2)
			{
				ans[i]=i+1;
				has[i+1]++;
				if(has[i+1]>1)
					fl=1;
			}
			int val=n;
			for(int i=2;i<mid;i+=2)
			{
				ans[i]=val;
				val-=2;
				has[val]++;
				if(has[val]>1)
					fl=1;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
				has[i-1]++;
				if(has[i-1]>1)
					fl=1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				has[val]++;
				if(has[val]>1)
					fl=1;
				val+=2;
			}
		}
		else
		{
			mid=n/2;
			for(int i=1;i<=mid;i+=2)
			{
				ans[i]=i+1;
				has[i+1]++;
				if(has[i+1]>1)
					fl=1;
			}
			int val=n;
			for(int i=2;i<=mid;i+=2)
			{
				ans[i]=val;
				has[val]++;
				if(has[val]>1)
					fl=1;
				val-=2;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
				has[i-1]++;
				if(has[i-1]>1)
					fl=1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				has[val]++;
				if(has[val]>1)
					fl=1;
				val+=2;
			}
		}
		REP(i,1,n)
		{
			if(ans[ans[i]]!=(n-i+1))
			{
				fl=1;
				break;
			}
		}
		if(fl)
		{
			printf("-1\n");
			return 0;
		}
		REP(i,1,n)
		{
			printf("%d ",ans[i]);
		}
		printf("\n");
	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
//      std macros
typedef long long ll;
typedef vector<list<ll> > vli;
typedef vector<ll > vi;
typedef vector<pair<ll,ll> > vpll;
typedef vector<pair<int,int> > vpii;
typedef pair<int ,int> pii;
//      dereference
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define in insert
#define pu push
#define fr front
//      loops
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define PER(i,b,a) for(int i=b;i>=a;--i)
#define all(X) (X).begin(), (X).end()
//      I/O
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define sd(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define oll(n) printf("%lld\n",n)
//      debug
#define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
//      set values
#define mset(n,k) memset(n,k,sizeof(n))
#define MOD 1000000007
ll INV2=500000004;
ll INV6=166666668;
//modular expo
ll power(ll a,ll b, ll c){
    ll x=1,y=a;
    while(b>0){
        if(b&1)
            x=(x*y)%c;
        y=(y*y)%c;
        b/=2;
    }
    return x%c;
}
//perfect numbers till 10^6 6, 28, 496, 8128
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};//clockwise from left
int dr[]={1,1,0,-1,-1,-1, 0, 1};
int dc[]={0,1,1, 1, 0,-1,-1,-1};//anticlockwise from down
int ans[100005];
bool fl;
int has[100005];
int main(){

	int n;
	sd(n);
	if(n==2 || n==3 || n==6)
	{
		printf("-1\n");
	}
	else
	{
		int mid=n/2 +1;
		if(n&1)
		{
			ans[mid]=mid;
			for(int i=1;i<mid;i+=2)
			{
				ans[i]=i+1;
				has[i+1]++;
				if(has[i+1]>1)
					fl=1;
			}
			int val=n;
			for(int i=2;i<mid;i+=2)
			{
				ans[i]=val;
				val-=2;
				has[val]++;
				if(has[val]>1)
					fl=1;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
				has[i-1]++;
				if(has[i-1]>1)
					fl=1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				has[val]++;
				if(has[val]>1)
					fl=1;
				val+=2;
			}
		}
		else
		{
			mid=n/2;
			for(int i=1;i<=mid;i+=2)
			{
				ans[i]=i+1;
				has[i+1]++;
				if(has[i+1]>1)
					fl=1;
			}
			int val=n;
			for(int i=2;i<=mid;i+=2)
			{
				ans[i]=val;
				has[val]++;
				if(has[val]>1)
					fl=1;
				val-=2;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
				has[i-1]++;
				if(has[i-1]>1)
					fl=1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				has[val]++;
				if(has[val]>1)
					fl=1;
				val+=2;
			}
		}
		if(fl)
		{
			printf("-1\n");
			return 0;
		}
		REP(i,1,n)
		{
			printf("%d ",ans[i]);
		}
		printf("\n");
	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
//      std macros
typedef long long ll;
typedef vector<list<ll> > vli;
typedef vector<ll > vi;
typedef vector<pair<ll,ll> > vpll;
typedef vector<pair<int,int> > vpii;
typedef pair<int ,int> pii;
//      dereference
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define in insert
#define pu push
#define fr front
//      loops
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define PER(i,b,a) for(int i=b;i>=a;--i)
#define all(X) (X).begin(), (X).end()
//      I/O
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define sd(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define oll(n) printf("%lld\n",n)
//      debug
#define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
//      set values
#define mset(n,k) memset(n,k,sizeof(n))
#define MOD 1000000007
ll INV2=500000004;
ll INV6=166666668;
//modular expo
ll power(ll a,ll b, ll c){
    ll x=1,y=a;
    while(b>0){
        if(b&1)
            x=(x*y)%c;
        y=(y*y)%c;
        b/=2;
    }
    return x%c;
}
//perfect numbers till 10^6 6, 28, 496, 8128
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};//clockwise from left
int dr[]={1,1,0,-1,-1,-1, 0, 1};
int dc[]={0,1,1, 1, 0,-1,-1,-1};//anticlockwise from down
int ans[100005];
int main(){

	int n;
	sd(n);
	if(n==2 || n==6)
	{
		printf("-1\n");
	}
	else
	{
		int mid=n/2 +1;
		if(n&1)
		{
			ans[mid]=mid;
			for(int i=1;i<mid;i+=2)
			{
				ans[i]=i+1;
			}
			int val=n;
			for(int i=2;i<mid;i+=2)
			{
				ans[i]=val;
				val-=2;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				val+=2;
			}
		}
		else
		{
			mid=n/2;
			for(int i=1;i<=mid;i+=2)
			{
				ans[i]=i+1;
			}
			int val=n;
			for(int i=2;i<=mid;i+=2)
			{
				ans[i]=val;
				val-=2;
			}
			for(int i=n;i>mid;i-=2)
			{
				ans[i]=i-1;
			}
			val=1;
			for(int i=n-1;i>mid;i-=2)
			{
				ans[i]=val;
				val+=2;
			}
		}
		REP(i,1,n)
		{
			printf("%d ",ans[i]);
		}
		printf("\n");
	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
//      std macros
typedef long long ll;
typedef vector<list<ll> > vli;
typedef vector<ll > vi;
typedef vector<pair<ll,ll> > vpll;
typedef vector<pair<int,int> > vpii;
typedef pair<int ,int> pii;
//      dereference
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define in insert
#define pu push
#define fr front
//      loops
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define PER(i,b,a) for(int i=b;i>=a;--i)
#define all(X) (X).begin(), (X).end()
//      I/O
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define sd(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define oll(n) printf("%lld\n",n)
//      debug
#define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
//      set values
#define mset(n,k) memset(n,k,sizeof(n))
#define MOD 1000000007
ll INV2=500000004;
ll INV6=166666668;
//modular expo
ll power(ll a,ll b, ll c){
    ll x=1,y=a;
    while(b>0){
        if(b&1)
            x=(x*y)%c;
        y=(y*y)%c;
        b/=2;
    }
    return x%c;
}
//perfect numbers till 10^6 6, 28, 496, 8128
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};//clockwise from left
int dr[]={1,1,0,-1,-1,-1, 0, 1};
int dc[]={0,1,1, 1, 0,-1,-1,-1};//anticlockwise from down
int ans[1000005];
int main(){

 	int n;
 	sd(n);
 	if(n&1)
 	{
 		REP(i,1,n)
 		{
 			printf("%d ",i);
 		}
 		printf("\n");
 	}
 	else
 	{
 		if(n==2)
 		{
 			printf("-1\n");
 		}
 		else if(n==4)
 		{
 			printf("1 3 4 2\n");
 		}
 		else
 		{
 			int cnt=0;
 			for(int i=1;i<=n;i+=2)
 			{
 				printf("%d ",i);
 				cnt++;
 			}
 			int mid=n/2,val;
 			if(mid&1)
 			{
 				val=n-mid+1;
 			}
 			else
 			{
 				mid--;
 				val=n-mid+1;
 			}
 			int idx=2*mid-1;
 			ans[idx]=val;
 			vector<int>aux;
 			for(int i=2;i<=n;i+=2)
 			{
 				if(i==val)
 					continue;
 				aux.pb(i);
 			}
 			int cn=0;
 			for(int i=cnt+1;i<=n;++i)
 			{
 				if(i==idx)
 				{
 					printf("%d ",val);
 				}
 				else
 				{
 					printf("%d ",aux[cn]);
 					cn++;
 				}
 			}
 			printf("\n");
 		}
 	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[1000000];
int main(){
int n;
cin>>n;
if(n%4>=2){
    cout<<-1;
    return 0;
}
for(int i=1; i<=n/2; i+=2){
    arr[i]=i+1;
    arr[i+1]=n-i+1;
    arr[n-i+1]=n-i;
    arr[n-i]=i;
}
if(n%2==1)
    arr[n/2+1]=n/2+1;
for(int i=1; i<=n; i++)
    cout<<arr[i]<<" ";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[2000000]={0}, brr[2000000]={0};
vector < ll > vec;
string str;
ll mod=1000000007;
map< ll, ll> mp;
ll fac(ll n)
{
	ll i, prod=1;
	for(i=1;i<=n;i++)
		prod=((i%mod)*(prod%mod))%mod;
	return prod;
}
ll power(ll x, ll y, ll p)
{
	ll res = 1;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res*x) % p;
		y = y>>1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
ll gcd(ll a, ll b)
{
	if (a == 0 || b == 0)
		return 0;
	if (a == b)
		return a;
	if (a > b)
		return gcd(a-b, b);
	return gcd(a, b-a);
}
int main()
{
	ll x, y, i, j, k, n, m, num, temp, fn, cnt=0, d, l, r, flag=0, sum1=0, a, b, len1=0, t;
	cin >> n;
	if(n==1)
	{printf("1\n");return 0;}
	if(n==2)
	{printf("-1\n");return 0;}
	if(n%4==3 || n%4==2)
	{printf("-1\n");return 0;}
	i=1;j=n;
	while(1)
	{
		arr[i]=i+1;
		arr[i+1]=j;
		arr[j-1]=i;
		arr[j]=j-1;
		i=i+2;
		j=j-2;
		if(i>=n/2)
			break;
	}
	if(n%4==1)
		arr[n/2+1]=n/2+1;
	for(i=1;i<=n;i++)
		printf("%lld\n",arr[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[2000000]={0}, brr[2000000]={0};
vector < ll > vec;
string str;
ll mod=1000000007;
map< ll, ll> mp;
ll fac(ll n)
{
	ll i, prod=1;
	for(i=1;i<=n;i++)
		prod=((i%mod)*(prod%mod))%mod;
	return prod;
}
ll power(ll x, ll y, ll p)
{
	ll res = 1;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res*x) % p;
		y = y>>1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
ll gcd(ll a, ll b)
{
	if (a == 0 || b == 0)
		return 0;
	if (a == b)
		return a;
	if (a > b)
		return gcd(a-b, b);
	return gcd(a, b-a);
}
int main()
{
	ll x, y, i, j, k, n, m, num, temp, fn, cnt=0, d, l, r, flag=0, sum1=0, a, b, len1=0, t;
	cin >> n;
	if(n==1)
	{printf("1\n");return 0;}
	if(n==2)
	{printf("-1\n");return 0;}
	if(n%4==3)
	{printf("-1\n");return 0;}
	i=1;j=n;
	while(1)
	{
		arr[i]=i+1;
		arr[i+1]=j;
		arr[j-1]=i;
		arr[j]=j-1;
		i=i+2;
		j=j-2;
		if(i>=n/2)
			break;
	}
	if(n%4==1)
		arr[n/2+1]=n/2+1;
	if(n%4==2)
	{arr[n/2]=n/2+1;arr[n/2+1]=n/2;}
	for(i=1;i<=n;i++)
		printf("%lld\n",arr[i]);
	return 0;
}


#include<bits/stdc++.h>

#define X  first
#define Y  second
typedef long long ll;

#define FOR(i,a,b) for(ll i = a;i<=b;i++)
#define FOD(i,a,b) for(ll i = a;i>=b;i--)
#define pb push_back
#define mp make_pair

using namespace std;

typedef pair<ll,ll>ii;
typedef priority_queue<ll,vector<ll>,greater<ll> > heap_min;
const ll maxN = 1e6+5;
const ll inf = 1e10;
const ll mod = 1e9+7;
ll n;
ll a[maxN];
int main()
{
    ios_base::sync_with_stdio(0);
	cin>>n;
	ll sum = 0;
	FOR(i,1,n)cin>>a[i],sum+=a[i];
	sort(a+1,a+n+1);
	ll mau = n;
	ll tu = sum;
	FOR(i,2,n)
	{
		tu += 2*(i-1)*(n-i+1)*(a[i]-a[i-1]);
	}
//	cout<<tu<<" "<<mau<<endl;
	ll g = __gcd(tu,mau);
	cout<<tu/g<<" "<<mau/g;

	return 0;
}


#include<bits/stdc++.h>

#define X  first
#define Y  second
typedef long long ll;

#define FOR(i,a,b) for(ll i = a;i<=b;i++)
#define FOD(i,a,b) for(ll i = a;i>=b;i--)
#define pb push_back
#define mp make_pair

using namespace std;

typedef pair<ll,ll>ii;
typedef priority_queue<ll,vector<ll>,greater<ll> > heap_min;
const ll maxN = 1e6+5;
const ll inf = 1e10;
const ll mod = 1e9+7;
ll n;
ll res[maxN];
int main()
{
    ios_base::sync_with_stdio(0);
	cin>>n;
	if(n == 1)
	{
		cout<<1;
		return 0;
	}
	if(n == 2)
	{
		cout<<-1;
		return 0;
	}
	if(n/2 % 2 != 0)
	{
		cout<<-1;
		return 0;
	}
	res[(n+1)/2] = (n+1)/2;
	for(int i = 1;i<=n/2;i+=2)
	{
		if(res[i] == 0)
		{
			res[i] = i+1;
			res[i+1] = n-i+1;
			res[n-i+1] = n-i;
			res[n-i] = i;
		}
	}
	FOR(i,1,n)cout<<res[i]<<" ";
	return 0;
}


#include <iostream>
using namespace std;
const int MN=1e5+100;
int p[MN];
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    if(n%4==2 || n%4==3)
        return cout<<-1,0;
    for(int i=0;i<n/2;i+=2){
        p[i]=i+2;
        p[i+1]=n-i;
        p[n-i-1]=n-i-1;
        p[n-i-2]=i+1;
    }
    if(n%4)
        p[n/2]=n/2+1;
    for(int i=0;i<n;i++){
        cout<<p[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define rev(i,a,b) for(i=(a);i>=(b);--i)
#define max2(a,b)  ((a)>(b)?(a):(b))
#define min2(a,b)  ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (long long)x.size()
#define fi first
#define se second
#define pb emplace_back // push_back
#define mp make_pair
#define endl '\n'

#ifdef Wild4Stone
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.fi); __p(a.se); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define autra(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#else
#define trace(...) {}
#define autra(...) {}
#endif

typedef long long int ll;
typedef pair<ll, ll> pll;

const ll mod = 1000000007;  //998244353;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);

ll i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
// inline ll gcd(ll a, ll b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); }
// inline ll power(ll x, ll n, ll m = LLONG_MAX)
//        {  ll res=1; x = (x%m + m)%m;
//             while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
//        }

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	int t = 1;
	// cin>>t;
	while (t--)  solve();
	return 0;
}

//***************** Code Starts Here *******************//

void solve()
{
	int n; cin >> n;
	int p[n + 1] = {0};

	if (n == 1)
	{
		cout << "1\n";
		return;
	}

	if (n == 2 || (n / 2) % 2 == 1)
	{
		cout << "-1\n";
		return;
	}

	rep(i, 1, n) p[i] = i;
	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;
	}

	rep(i, 1, n) cout << p[i] << " "; cout << endl;
}