// Arup Guha
// 1/1/2025
// Solution to 2024 SER D1 Problem F: Finding Keys

using namespace std;
#include <bits/stdc++.h>

typedef struct mypair {

    int index;
    int first;
    int second;

    inline bool operator < (const mypair& other) {
        if (first < other.first) return true;
        if (first == other.first && second < other.second) return true;
        return false;
    }

    inline bool operator == (const mypair& other) {
        return first == other.first && second == other.second;
    }
} mypair;

vector< vector<int> > getSuffixArray(string& s);
vector<int> getInitPos(string& s);
int lcp(vector< vector<int> >& sArray, int x, int y);

int main() {

    int n;
    cin >> n;
    vector<int> vals(n);

    // Read in values.
    for (int i=0; i<n; i++)
        cin >> vals[i];

    // Make cyclic string.
    string arr(2*n-1, 'a');
    for (int i=0; i<2*n-1; i++) {
        if (vals[i%n] < vals[(i+1)%n])
            arr[i] = 'b';
        else
            arr[i] = 'a';
    }

	// Get suffix array.
    vector< vector<int> > sa = getSuffixArray(arr);

    // Get my suffixes and sort them. I have a feeling this is redundant.
	vector< pair<int,int> > mine(n);
    int idx = sa.size()-1;
    for (int i=0; i<n; i++) {
        mine[i].first = sa[idx][i]; mine[i].second = i;
    }
    sort(mine.begin(), mine.end());

    // Store results here. Basically, for both neighbors (alphabetically), find
    // the max of the 2 LCPs and add 1 (unique).
    vector<int> res(n);
    for (int i=0; i<n; i++) {
        int tmpR = i<n-1 ? lcp(sa, mine[i].second, mine[i+1].second) : 0;
        int tmpL = i>0   ? lcp(sa, mine[i].second, mine[i-1].second) : 0;
        res[mine[i].second] = max(tmpR, tmpL) + 1;

        // Cyclic wrap around...
        if (res[mine[i].second] >= n) res[mine[i].second] = -1;
    }

    // Ta da!
    for (int i=0; i<n; i++)
        cout << res[i] << "\n";

    return 0;
}

// Returns power of 2 >= n.
int getIter(int n) {
    int cnt = 1, ans = 1;
    while (cnt < n) {
        ans++;
        cnt = (cnt<<1);
    }
    return ans;
}

// My converted suffix array code from Java --> C++.
vector< vector<int> > getSuffixArray(string& s) {

    vector< vector<int> > ans;
    int n = s.size();
    int levels = getIter(n);

    vector<int> tmp = getInitPos(s);
    ans.push_back(tmp);

    int cnt = 1, iter = 0;

    while (cnt < n) {

        // Create pairs of values.
		vector<mypair> temp(n);
        for (int i=0; i<n; i++) {
            temp[i].index = i;
            temp[i].first = ans[iter][i];
            temp[i].second = -1;
            if (i+cnt < n)
                temp[i].second = ans[iter][i+cnt];
        }

        // Sort these.
        sort(temp.begin(), temp.end());
        vector<int> newRanks(n);

        int newCnt = 0;
        newRanks[0] = 0;
        for (int i=1; i<n; i++) {
            if (temp[i] == temp[i-1])
                newRanks[i] = newRanks[i-1];
            else
                newRanks[i] = newRanks[i-1] + 1;
        }

        // These are the new ranks where they should go.
        vector<int> newarr(n);
        for (int i=0; i<n; i++)
            newarr[temp[i].index] = newRanks[i];

        // Add get ready for next iteration.
        ans.push_back(newarr);
        iter++;
        cnt = (cnt<<1);
    }

    return ans;
}

// Written just for this problem...
vector<int> getInitPos(string& s) {
    vector<int> res(s.size());
    for (int i=0; i<res.size(); i++)
        res[i] = s[i]-'a';
    return res;
}

int lcp(vector< vector<int> > & sArray, int x, int y) {

    int k, ret = 0, n = sArray[0].size();
    if (x == y) return n - x;

    // Go through and find each matching substring of length perfect power of 2
    // and iteratively try to "grow" the matching substrings.
    for (k = sArray.size() - 2; k >= 0 && x < n && y < n; k --) {

        // These 2^k characters match, update answer and try to match what's left.
        if (sArray[k][x] == sArray[k][y]) {
            x   += (1 << k);
            y   += (1 << k);
            ret += (1 << k);
        }
    }

    return ret;
}
