//* Jai shree Ram
#include <bits/stdc++.h>  
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli                                 long long int
#define ll                                  long long
#define FOR(i,a,b)                          for(int i=a;i<b;i++)
#define pi                                  pair<int,int>
#define vi                                  vector<int>
#define vll                                 vector<ll>
#define all(a)                              a.begin(),a.end()
#define sz(a)                               (int)a.size()
#define pb                                  push_back
#define ppb                                 pop_back
#define pf                                  push_front
#define fr                                  first
#define sc                                  second
#define uniq(v)                             (v).erase(unique(all(v)),(v).end())
using namespace std;

void __print(int x) {cerr << x;}void __print(long x) {cerr << x;}void __print(long long x) {cerr << x;}void __print(unsigned x) {cerr << x;}void __print(unsigned long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(float x) {cerr << x;}void __print(double x) {cerr << x;}void __print(long double x) {cerr << x;}void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}void __print(const string &x) {cerr << '\"' << x << '\"';}void __print(bool x) {cerr << (x ? "true" : "false");}template<typename T, typename V>void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}void _print() {cerr << "]\n";}template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// __builtin_popcountll(x);
// __builtin_clz(x) // Count Leading zeros
// __builtin_ctz(x) // Trailing zeros
const int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
const int N = 1e5 + 5;


void solve() 
{
    int n;
    cin >> n;
    vector<vector<ll>> a(n,vector<ll>(5));
    FOR(i,0,n) {
        FOR(j,0,5) {
            cin >> a[i][j]; 
        }
    }
    auto fine = [&](int mid) {
        set<int> masks;
        FOR(i,0,n) {
            int mask = 0;
            FOR(j,0,5) {
                if(a[i][j] >= mid) {
                    mask |= (1 << j);
                }
            }
            masks.insert(mask);
        }
        for(int first : masks) {
            for(int second : masks) {
                for(int third : masks) {
                    if((first | second | third) == ((1 << 5)-1)) {
                        return 1;
                    }
                }
            }
        }
        return 0;
    };  
    ll L = 1,U = INF;
    ll ans = 1;
    while(L <= U) {
        ll mid = L + (U - L) / 2;
        if(fine(mid)) {
            amax(ans,mid);
            L = mid + 1; 
        }
        else {
            U = mid - 1;
        }
    }
    cout << ans << '\n';
}

signed main()
{
    ios;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
          sieve();
    #endif
    #ifdef NCR
          init();
    #endif
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
}
/* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * remember out of bounds case mainly in if else
  * do smth instead of nothing and stay organized
  * WRITE STUFF DOWN
*/
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <math.h>
using namespace std;


//#define int long long
#define all(x) x.begin(), x.end()

const int maxn = 6e5 + 13;
const int INF = 2e18 + 1;
const int MOD = 1e9 + 7;


struct treap {
	struct node {
		int key, pr, sz;
		node* left = 0, * right = 0;
		node(int k) : key(k), sz(1), pr(rand()) {}
	};
	node* root = 0;
	typedef pair<node*, node*> pnn;
	void upd(node* &root) {
		if (root == 0)return;
		root->sz = 1;
		if (root->left != 0)
			root->sz += root->left->sz;
		if (root->right != 0)
			root->sz += root->right->sz;
	}
	pnn split(node* root, int k) {
		if (root == 0)return { 0, 0 };
		upd(root);
		if (k < root->key) {
			pnn sp = split(root->left, k);
			root->left = sp.second;
			upd(root);
			return { sp.first, root };
		}
		else {
			pnn sp = split(root->right, k);
			root->right = sp.first;
			upd(root);
			return { root, sp.second };
		}
	}
	node* merge(node* left, node* right) {
		upd(left);
		upd(right);
		if (left == 0 || right == 0)
			return left == 0 ? right : left;
		if (left->pr < right->pr) {
			right->left = merge(left, right->left);
			upd(right);
			return right;
		}
		else {
			left->right = merge(left->right, right);
			upd(left);
			return left;
		}
	}
	void insert(int k) {
		node* nn = new node(k);
		pnn sp = split(root, k);
		root = merge(sp.first, merge(nn, sp.second));
	}
	int lowest(int x) {
		pnn sp = split(root, x - 1);
		int res = sp.first == 0 ? 0 : sp.first->sz;
		root = merge(sp.first, sp.second);
		return res;
	}
	int highest(int x) {
		pnn sp = split(root, x);
		int res = sp.second == 0 ? 0 : sp.second->sz;
		root = merge(sp.first, sp.second);
		return res;
	}
};
int a[maxn];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		a[i + n] = a[i];
	}
	treap dd;
	long long cur = 0;
	for (int i = 1; i <= n; ++i) {
		cur += dd.highest(a[i]);
		dd.insert(a[i]);
	}
	cout << cur << "\n";
	for (int i = 1; i < n; ++i) {
		int l = dd.lowest(a[i]);
		int h = dd.highest(a[i]);
		cur += h - l;
		cout << cur << "\n";
	}
	return 0;
}