/*****************/
/*

Sharma Ji Ka Ladka
MNNIT Allahabad

*/
/*****************/

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

#define For(i, a, b) for (int i = a; i < b; i++)
#define Forl(i, size) for (int i = 0; i < size; i++)
#define Forr(i, size) for (int i = size - 1; i >= 0; i--)
#define ForR(i, a, b) for (int i = a; i >= b; i--)
#define s(n) scanf("%d", &n)
#define p(n) printf("%d\n", n)
#define ps(n) printf("%s\n", n)
#define sd(n) \
    int n;    \
    scanf("%d", &n)
#define sl(n)        \
    long long int n; \
    scanf("%lld", &n)
#define pb(n) push_back(n)
#define clr(a) memset(a, 0, sizeof(a))
#define all(c) (c).begin(), (c).end()
#define len length()
#define size size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
typedef __int64 ull;
#define ret return 0;
#define PI 3.14159265
#define snuke(c, itr) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
const long long Mod = 1e9 + 7;
// string a,b,s,c,d;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
ll sum = 0, ans = 0, res = 0;
int i, j, k;

vector<string> vec_splitter(string s)
{
    s += ',';
    vector<string> res;
    while (!s.empty())
    {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx) { cerr << endl; }
void debug_out(
    vector<string> __attribute__((unused)) args,
    __attribute__((unused)) int idx,
    __attribute__((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T)
{
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define watch(x) cout << (#x) << " is " << (x) << endl;
/*************************************************/
//Comment down this line to hide debugging output;

#define XOX

//Uncomment above line to show debugging output
/************************************************/
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b)
{
    if (a.se == b.se)
        return (a.fi < b.fi);

    return (a.se < b.se);
}

// IS PRIME FUNCTION STARTS

bool isPrime(ll num)
{
    bool flag = true;
    if (num == 1)
        return false;
    for (int i = 2; i <= sqrt(num); i++)
    {
        if (num % i == 0)
        {
            flag = false;
            break;
        }
    }
    return flag;
}

//IS PRIME FUNCTION ENDS

//**Array Sum Function**

ll findSum(ll a[], int l, int r)
{
    ll sum = 0;
    For(i, l, r)
    {
        sum += a[i];
    }
    return sum;
}

//**Array Sum Function Ends**

//Prime Factors Of A Number

vector<pair<int, int>> vec1; //Prime Factors along with their exponents
void primeFactors(ll n)
{
    int c1 = 0;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        // printf("%d ", 2);
        n = n / 2;
        c1++;
    }
    if (c1)
        vec1.pb(mp(2, c1));
    c1 = 0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        c1 = 0;
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            // printf("%d ", i);

            n = n / i;
            c1++;
        }
        if (c1)
            vec1.pb(mp(i, c1));
    }
    c1 = 0;
    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        vec1.pb(mp(n, 1));
}

//Ends

//*** Power Function Starts
ll power(int x, unsigned int y)
{
    int temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}
//*** Power function ends

//nCr function starts

ull nCr(ll n, ll r)
{
    ull p = 1;
    ull k = 1;
    if (n - r < r)
        r = n - r;

    if (r != 0)
    {
        while (r)
        {
            p *= n;
            k *= r;
            ll m = __gcd(p, k);
            p /= m;
            k /= m; //Simplifying
            n--;
            r--;
        }
    }
    else
        p = 1;

    return p;
}

//nCr function ends

// ** LCM of two numbers
ll lcm(ll a, ll b)
{
    return a / __gcd(a, b) * b;
}
//** Ends //

//** Count Set Bits Functon

unsigned int countBits(ll n, int specify)
{
    unsigned int count = 0, total = 0;
    if (n == 0)
    {
        if (specify == 1)
            return 0;
        else
            return 1;
    }
    while (n)
    {
        total += 1;
        count += n & 1;
        n >>= 1;
    }
    if (specify == 1)
        return count;
    else
        return (total - count);
}

//** Ends //

//Array Scanner starts

void scar(ll a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
}

//Array Scanner ends
//  long long findTargetSumWays(vector<int>& vec, int S) {

//         long long sum=0;
//         for(int i=0;i<vec.size;i++)
//         {
//             sum+=vec[i];
//         }
//         // cout<<sum<<endl;
//         if(sum<S||(sum+S)%2!=0)return 0;
//         long long s1=(sum+S)/2;

//         long long dp[vec.size+10][s1+10]={0};
//         for(int j=0;j<s1+1;j++)
//         {
//             dp[0][j]=0;
//         }
//         for(int i=0;i<vec.size+1;i++)
//         {
//             dp[i][0]=1;
//         }
//         for(i=1;i<vec.size+1;i++)
//         {
//             For(j,0,s1+1)
//             {if(j>=vec[i-1])
//                 dp[i][j]=dp[i-1][j]+dp[i-1][j-vec[i-1]];
//                 else
//                 {
//                     dp[i][j]=dp[i-1][j];
//                 }

//             }
//         }
//         return dp[vec.size][s1];

//     }

signed main()
{
    boost

    // TO Enable Debugging Or Disable Debuuging Go To Line "73";
    string aux1, aux2, aux3;

    ll T = 1;

    // cin>>T;

    For(ZA, 1, T + 1)
    {

        int f = 0, fl1 = 0, fl2 = 0, c1 = 0, c2 = 0, cont = 0, cnt = 0, c3 = 0, auxi = 0, auxj = 0;
        ll mi = INT_MAX;
        ll ma = INT_MIN, sol = 0;
        sum = 0;
        ll sumBfr = 0;
        int n;
        cin >> n;
        ll a[n];
        For(i, 0, n)
        {
            cin >> a[i];sum+=a[i];
        }
        sort(a,a+n);
        ll sumLeft=0;
        For(i,0,n)
        {
          sumLeft+=(a[i]*i)-sumBfr;
          sumBfr+=a[i];
        }
        ll total=sum+2*sumLeft;
        ll ooo=__gcd(total,(ll)n);
        cout<<(total/ooo)<<" "<<(n/ooo)<<endl;

    }

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long  n ;
    cin>>n ;
    int arr[n+2];
    long long sum = 0;
    for(int i = 0 ;i < n ; i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n);
    long long arr2[n+2];
    arr2[0]=0;
    for(int i = 1 ;i<=n;i++ )arr2[i]=arr2[i-1]+arr[i-1];
    long long ans = 0 ;
    for(int i =0 ; i < n ; i++){
        ans+=(i*arr[i]-arr2[i])+(arr2[n]-arr2[i+1])-((n-i-1)*arr[i])+arr[i];
    }
     long long dem = 1  ;
     long long GCD =__gcd(ans,n);
     long long  num2 = n / GCD;
     ans/=GCD;
     dem*=num2;
    cout<<ans<<" "<<dem;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long  n ;
    cin>>n ;
    long long  arr[n+2];
    long long sum = 0;
    for(int i = 0 ;i < n ; i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n);
    long long arr2[n+2];
    arr2[0]=0;
    for(long long  i = 1 ;i<=n;i++ )arr2[i]=arr2[i-1]+arr[i-1];
    long long ans = 0 ;
    for(int i =0 ; i < n ; i++){
        ans+=(i*arr[i]-arr2[i])*2+arr[i];
    }
     long long dem = 1  ;
     long long GCD =__gcd(ans,n);
     long long  num2 = n / GCD;
     ans/=GCD;
     dem*=num2;
    cout<<ans<<" "<<dem;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long  n ;
    cin>>n ;
    int arr[n+2];
    long long sum = 0;
    for(int i = 0 ;i < n ; i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n);
    long long arr2[n+2];
    arr2[0]=0;
    for(int i = 1 ;i<=n;i++ )arr2[i]=arr2[i-1]+arr[i-1];
    long long ans = 0 ;
    for(int i =0 ; i < n ; i++){
        ans+=(i*arr[i]-arr2[i])*2+arr[i];
    }
     long long dem = 1  ;
     long long GCD =__gcd(ans,n);
     long long  num2 = n / GCD;
     ans/=GCD;
     dem*=num2;
    cout<<ans<<" "<<dem;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long gcd (long long a , long long b ){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main() {
    long long  n ;
    cin>>n ;
    int arr[n+2];
    long long sum = 0;
    for(int i = 0 ;i < n ; i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n);
    long long arr2[n+2];
    arr2[0]=0;
    for(int i = 1 ;i<=n;i++ )arr2[i]=arr2[i-1]+arr[i-1];
    long long ans = 0 ;
    for(int i =0 ; i < n ; i++){
        ans+=(i*arr[i]-arr2[i])*2+arr[i];
    }
     long long dem = 1  ;
     long long GCD =gcd(ans,n);
     long long  num2 = n / GCD;
     ans/=GCD;
     dem*=num2;
    cout<<ans<<" "<<dem;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
     long long  n ;
     cin>>n ;
     long long  arr[n+2], arr2[n+2];
     for(int i = 0 ;i < n ; i++){cin>>arr[i];}
     sort(arr,arr+n);
     arr2[0]=0;
     for(long long  i = 1 ;i<=n;i++ )arr2[i]=arr2[i-1]+arr[i-1];
     long long ans = 0 ;
     for(int i =0 ; i < n ; i++)ans+=(i*arr[i]-arr2[i])+(arr2[n]-arr2[i+1])-((n-i-1)*arr[i])+arr[i];
     long long dem = 1  ;
     long long GCD =__gcd(ans,n);
     long long  num2 = n / GCD;
     ans/=GCD;
     dem*=num2;
     cout<<ans<<" "<<dem<<endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long gcd (long long a , long long b ){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main() {
    long long  n ;
    cin>>n ;
    long long  arr[n+2];
    long long sum = 0;
    for(int i = 0 ;i < n ; i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n);
    long long arr2[n+2];
    arr2[0]=0;
    for(long long  i = 1 ;i<=n;i++ )arr2[i]=arr2[i-1]+arr[i-1];
    long long ans = 0 ;
    for(int i =0 ; i < n ; i++){
        ans+=(i*arr[i]-arr2[i])*2+arr[i];
    }
     long long dem = 1  ;
     long long GCD =gcd(ans,n);
     long long  num2 = n / GCD;
     ans/=GCD;
     dem*=num2;
    cout<<ans<<" "<<dem;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n ;
    cin>>n ;
    int arr[n+2];
    for(int i = 0 ;i < n ; i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    long long arr2[n+2];
    arr2[0]=0;
    for(int i = 1 ;i<=n;i++ )arr2[i]=arr2[i-1]+arr[i-1];
    long long ans = 0 ;
    for(int i =0 ; i < n ; i++)ans+=(i*arr[i]-arr2[i])+(arr2[n]-arr2[i+1])-((n-i-1)*arr[i])+arr[i];
    ans*=(n-1);
     long long dem = 1  ;
     for(long long  i = 2 ; i <=  n ;i ++ ){
         long long GCD =__gcd(ans,i);
         long long  num2 = i / GCD;
         ans/=GCD;
         dem*=num2;
     }
    cout<<ans<<" "<<dem;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long n;
    cin>>n;
    long arr[n];
    long ans = 0;
    for (long i=0;i<n;i++)
    {
        cin>>arr[i];
        ans+=arr[i];
    }
    sort(arr,arr+n);
    long t=0;
    for (int i=n-2;i>=0;i--)
    {
        t += (n-1-i)*(arr[i+1]-arr[i]);
        ans += 2*t;
    }
    long d = __gcd(ans,n);
    cout<<ans/d<<' '<<n/d;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long int gcd(long long int a,long long int b)
{
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}
int main()
{
    long long int n;
    cin>>n;
    long long int a[n];
    long long int s=0;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        s+=a[i];
    }
    sort(a,a+n);
    long long int x=1-n;
    for (int i = 0; i < n; ++i) {
    s+=2*a[i]*x;
    x+=2;
    }
    long long int z=gcd(s,n);
    cout<<s/z<<" "<<n/z;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    int ans = 0;
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        ans+=arr[i];
    }
    sort(arr,arr+n);
    int t=0;
    for (int i=n-2;i>=0;i--)
    {
        t += (n-1-i)*(arr[i+1]-arr[i]);
        ans += 2*t;
    }
    int d = __gcd(ans,n);
   printf("%I64d %d\n", ans/d, n/d);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    long ans = 0;
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        ans+=arr[i];
    }
    sort(arr,arr+n);
    long t=0;
    for (int i=n-2;i>=0;i--)
    {
        t += (n-1-i)*(arr[i+1]-arr[i]);
        ans += 2*t;
    }
    int d = __gcd(ans,n);
    cout<<ans/d<<' '<<n/d;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    int ans = 0;
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        ans+=arr[i];
    }
    sort(arr,arr+n);
    int t=0;
    for (int i=n-2;i>=0;i--)
    {
        t += (n-1-i)*(arr[i+1]-arr[i]);
        ans += 2*t;
    }
    int d = __gcd(ans,n);
    cout<<ans/d<<' '<<n/d;
    return 0;
}


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

int32_t main()
{
	int n;
	cin>>n;
	int a[n+1];
	a[0]=0;
	for(int i=1; i<=n; i++)
		cin>>a[i];

	sort(a,a+n);
	int presum[n+1];
	presum[0]=0;
	for(int i=1; i<n+1; i++)
		presum[i]=a[i]+presum[i-1];
	int ans=0;
	for(int i=1; i<=n; i++)
	{
		// cout<<"$: "<<(i-1)*a[i]-(presum[i]-a[i])<<" &: "<<presum[n]-presum[i]-(n-i)*a[i]<<"  "<<(i-1)*a[i]-(presum[i]-a[i])+presum[n]-presum[i]-(n-i)*a[i]<<endl;
		ans+=((2*i-n)*a[i] + (presum[n]-presum[i]) - (presum[i]));
		// cout<<i<<" "<<a[i]<<" "<<ans<<endl;
	}
	ans+=presum[n];
	// cout<<"ans: "<<ans<<endl;
	cout<<ans/__gcd(ans,n)<<" "<<n/__gcd(ans,n);
	return 0;
}


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

int32_t main()
{
	int n;
	cin>>n;
	int a[n+1];
	a[0]=0;
	for(int i=1; i<=n; i++)
		cin>>a[i];

	sort(a,a+n+1);
	int presum[n+1];
	presum[0]=0;
	for(int i=1; i<n+1; i++)
		presum[i]=a[i]+presum[i-1];
	int ans=0;
	for(int i=1; i<=n; i++)
	{

		// cout<<"$: "<<(i-1)*a[i]-(presum[i]-a[i])<<" &: "<<presum[n]-presum[i]-(n-i)*a[i]<<"  "<<(i-1)*a[i]-(presum[i]-a[i])+presum[n]-presum[i]-(n-i)*a[i]<<endl;
		ans+=((2*i-n)*a[i] + (presum[n]-presum[i]) - (presum[i]));
		// cout<<i<<" "<<a[i]<<" "<<ans<<endl;
	}
	ans+=presum[n];
	// cout<<"ans: "<<ans<<endl;
	cout<<ans/__gcd(ans,n)<<" "<<n/__gcd(ans,n);
	return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define sz 200005
using namespace std;
using ll=long long;

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,tot=0;
    cin>>n;
    ll a[n],diff[n];
    rep(i,0,n) cin>>a[i];
    rep(i,1,n) diff[i]=a[i]-a[i-1];
    rep(i,0,n){
        tot+=a[i];
        if(i!=0){
          tot+=2*abs(diff[i]);
          tot+=2*diff[i];
        }
    }
    ll g=__gcd(n,tot);
    n/=g;tot/=g;
    cout<<tot<<' '<<n<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long int
#define ld long double
#define For(i,a,b) for (ll i = (a); i!=(b); i = (a)<(b)? i+1 : i-1)
#define pb push_back
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll p[n+1]={0};
    For(i,0,n)
    cin>>a[i];
    sort(a,a+n);
    For(i,0,n)
      {p[i]=a[i];
      if(i!=0)
        p[i]+=p[i-1];
      }
      ll su[n]={0};
    For(i,n-1,-1)
      {    su[i]=a[i];
          if(i!=n-1)
            su[i]+=su[i+1];
      }
      ll ans=0;
      For(i,0,n)
      {
          ans+=(i+1)*a[i]-p[i]+su[i]-(n-i-1)*a[i];
      }
      ll w=__gcd(n,ans);
      n/=w;
      ans/=w;
      cout<<ans<<" "<<n;
}


#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long int
#define ld long double
#define For(i,a,b) for (ll i = (a); i!=(b); i = (a)<(b)? i+1 : i-1)
#define pb push_back
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll p[n+1]={0};
    For(i,0,n)
      {cin>>a[i];p[i]=a[i];
      if(i!=0)
        p[i]+=p[i-1];
      }
      ll su[n]={0};
    For(i,n-1,-1)
      {    su[i]=a[i];
          if(i!=n-1)
            su[i]+=su[i+1];
      }
      ll ans=0;
      For(i,0,n)
      {
          ans+=(i+1)*a[i]-p[i]+su[i]-(n-i-1)*a[i];
      }
      ll w=__gcd(n,ans);
      n/=w;
      ans/=w;
      cout<<ans<<" "<<n;
}


#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int ans=0,k=0;
  rep(i,0,n) ans+=a[i]*(n-1);

  for (int i=n-1; i>=0; i--)
        k += i*a[i] - (n-1-i)*a[i];

  ans+=4*k;
  //cout<<ans<<endl;
  int t=1;
  rep(i,2,n+1)
  {
    t=t*i;
    int u=t;
    t=t/__gcd(t,ans);
    ans=ans/__gcd(u,ans);
    //cout<<t<<" "<<ans<<endl;
  }
  cout<<ans<<" "<<t;

}


#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  sort(a,a+n);
  int ans=0,k=0;

  for (int i=n-1; i>=0; i--)
        k += i*a[i] - (n-1-i)*a[i];
      int sum=0;
      rep(i,0,n) sum+=a[i];
  ans=2*k+sum;
  int yu=n;
  int z=yu;
  yu=yu/__gcd(yu,ans);
  ans=ans/__gcd(ans,z);
  cout<<ans<<" "<<yu;

}


#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  sort(a,a+n);
  int ans=0,k=0;

  for (int i=n-1; i>=0; i--)
        k += i*a[i] - (n-1-i)*a[i];
      int sum=0;
      rep(i,0,n) sum+=a[i];
  ans=2*(n-1)*k+sum*(n-1);
  int yu=n*(n-1);
  int z=yu;
  yu=yu/__gcd(yu,ans);
  ans=ans/__gcd(ans,z);
  cout<<ans<<" "<<yu;

}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define pi acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

//#define inf 1<<30

// isupper() -> upper case check
// tolower() -> convert upper to lower case
// idx = str.find("bear", pos)) != string::npos =>substring find
// Tuple access -> get<0>(v[i])
// cmnt - ctrl []
// stoi("...") -> decimel
// istringstream ss(str) while(ss >> n)

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;

const ll inf = 2e18;
const ll mod = 998244353;

int dr[] = {-1, 0, 1,  0};// up, right, down, left
int dc[] = { 0, 1, 0, -1};

// King moves similar to 8 direction
//int dr[] = {-1, -1, 0, 1, 1,  1, 0, -1};
//int dc[] = { 0,  1, 1, 1, 0, -1,-1, -1};

// Knight moves
int kr[] = {-1,  1, -2, -2, -1, 1,  2,  2};
int kc[] = {-2, -2, -1,  1,  2, 2, -1,  1};
// diagonal moves
int dgr[] = {-1, -1,  1, 1};
int dgc[] = { 1, -1, -1, 1};

int main()
{
    ll n, sum = 0, pref = 0, suff = 0;
    cin>>n;

    vector<ll>v(n);
    for(int i=0; i<n ; i++) cin>>v[i], suff += v[i];

    sort(all(v));

    for(int i=0; i<n; i++){
        sum += (i*v[i]-((n-1-i)*v[i]));
        sum -= pref;
        sum += suff;
        pref += v[i];
        suff -= v[i];
    }

    ll gd = __gcd(sum, n);

    printf("%lld %lld\n", sum/gd, n/gd);

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define pi acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

//#define inf 1<<30

// isupper() -> upper case check
// tolower() -> convert upper to lower case
// idx = str.find("bear", pos)) != string::npos =>substring find
// Tuple access -> get<0>(v[i])
// cmnt - ctrl []
// stoi("...") -> decimel
// istringstream ss(str) while(ss >> n)

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;

const ll inf = 2e18;
const ll mod = 998244353;

int dr[] = {-1, 0, 1,  0};// up, right, down, left
int dc[] = { 0, 1, 0, -1};

// King moves similar to 8 direction
//int dr[] = {-1, -1, 0, 1, 1,  1, 0, -1};
//int dc[] = { 0,  1, 1, 1, 0, -1,-1, -1};

// Knight moves
int kr[] = {-1,  1, -2, -2, -1, 1,  2,  2};
int kc[] = {-2, -2, -1,  1,  2, 2, -1,  1};
// diagonal moves
int dgr[] = {-1, -1,  1, 1};
int dgc[] = { 1, -1, -1, 1};

int main()
{
    ll n, sum = 0; cin>>n;

    vector<ll>v(n);
    for(int i=0; i<n ; i++) cin>>v[i], sum += v[i];
    //sum *= (n-1);
    for(int i=0; i<n; i++){
        for(register int j = i+1; j<n; j++){
            sum += (2*abs(v[i]-v[j]));
        }
    }

    ll gd = __gcd(sum, n);

    printf("%lld %lld\n", sum/gd, n/gd);

    return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

//#include <unordered_set>
//#include <unordered_map>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int ll
typedef long long ll;
typedef long double ld;
//#pragma comment(linker, "/STACK:66777216")

using namespace std;

const ll INF = 1e18, MOD = 1e9 + 7, MAXN = 18, MAXM = 1e5 + 1;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    //ifstream  cin("success.in");
    //ofstream cout("success.out");
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> f(n);
    for (int i = 0; i < n; i++)
        cin >> f[i];
    sort(all(f));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (2 * i - n + 1) * f[i] * 2 + f[i];
    }
    cout << ans << ' ' << n;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

int A[1 << 20];
int B[1 << 20];

int F(priority_queue<int> Q[], int n)
{
	while(!Q[0].empty() && !Q[1].empty() && Q[0].top() == Q[1].top())
	{
		Q[0].pop();
		Q[1].pop();
	}

	if(Q[0].empty())
		return 4*n;

	return -Q[0].top();
}

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

	int i;
	FOR(i, 0, n)
	{
		int a;
		scanf("%d", &a);
		A[a - 1] = i;
	}

	FOR(i, 0, n)
	{
		int a;
		scanf("%d", &a);
		B[a - 1] = i;
	}

	vector< pair<PII, PII> > v;
	FOR(i, 0, n)
	{
		if(A[i] < B[i])
		{
			v.PB(MP(PII(0, 0), PII(B[i] - A[i], -1)));
			v.PB(MP(PII(B[i] - A[i], 1), PII(B[i] - A[i], -1)));

			v.PB(MP(PII(B[i] - A[i], 0), PII(A[i] - B[i], 1)));
			v.PB(MP(PII(n - A[i], 1), PII(A[i] - B[i], 1)));

			v.PB(MP(PII(n - A[i], 0), PII(n + B[i] - A[i], -1)));
			v.PB(MP(PII(n, 1), PII(n + B[i] - A[i], -1)));
		}
		else
		{
			v.PB(MP(PII(0, 0), PII(A[i] - B[i], 1)));
			v.PB(MP(PII(n - A[i], 1), PII(A[i] - B[i], 1)));

			v.PB(MP(PII(n - A[i], 0), PII(n + B[i] - A[i], -1)));
			v.PB(MP(PII(n + B[i] - A[i], 1), PII(n + B[i] - A[i], -1)));

			v.PB(MP(PII(n + B[i] - A[i], 0), PII(-(n + B[i] - A[i]), 1)));
			v.PB(MP(PII(n, 1), PII(-(n + B[i] - A[i]), 1)));
		}
	}

	sort(ALL(v));

	priority_queue<int> Q[2][2];
	int pos = 0;
	FOR(i, 0, n)
	{
		while(pos < SIZE(v) && v[pos].first.first <= i)
		{
			Q[ (v[pos].second.second + 1)/2 ][ v[pos].first.second ].push(-v[pos].second.first);
			++pos;
		}

		int a = F(Q[0], n) - i;
		int b = F(Q[1], n) + i;
		printf("%d\n", min(a, b));
	}

	return 0;
};


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

int A[1 << 20];
int B[1 << 20];

int F(priority_queue<int> Q[], int n)
{
	while(!Q[0].empty() && !Q[1].empty() && Q[0].top() == Q[1].top())
	{
		Q[0].pop();
		Q[1].pop();
	}

	if(Q[0].empty())
		return 4*n;

	return -Q[0].top();
}

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

	int i;
	FOR(i, 0, n)
	{
		int a;
		scanf("%d", &a);
		A[a - 1] = i;
	}

	FOR(i, 0, n)
	{
		int a;
		scanf("%d", &a);
		B[a - 1] = i;
	}

	vector< pair<PII, PII> > v;
	FOR(i, 0, n)
	{
		if(A[i] < B[i])
		{
			v.PB(MP(PII(0, 0), PII(B[i] - A[i], -1)));
			v.PB(MP(PII(B[i] - A[i] + 1, 1), PII(B[i] - A[i], -1)));

			v.PB(MP(PII(B[i] - A[i], 0), PII(A[i] - B[i], 1)));
			v.PB(MP(PII(n - A[i], 1), PII(A[i] - B[i], 1)));

			v.PB(MP(PII(n - A[i], 0), PII(n + B[i] - A[i], -1)));
			v.PB(MP(PII(n, 1), PII(n + B[i] - A[i], -1)));
		}
		else
		{
			v.PB(MP(PII(0, 0), PII(A[i] - B[i], 1)));
			v.PB(MP(PII(n - A[i], 1), PII(A[i] - B[i], 1)));

			v.PB(MP(PII(n - A[i], 0), PII(n + B[i] - A[i], -1)));
			v.PB(MP(PII(n + B[i] - A[i] + 1, 1), PII(n + B[i] - A[i], -1)));

			v.PB(MP(PII(n + B[i] - A[i], 0), PII(-(n + B[i] - A[i]), 1)));
			v.PB(MP(PII(n, 1), PII(-(n + B[i] - A[i]), 1)));
		}
	}

	sort(ALL(v));

	priority_queue<int> Q[2][2];
	int pos = 0;
	FOR(i, 0, n)
	{
		while(pos < SIZE(v) && v[pos].first.first <= i)
		{
			Q[ (v[pos].second.second + 1)/2 ][ v[pos].first.second ].push(-v[pos].second.first);
			++pos;
		}

		int a = F(Q[0], n) - i;
		int b = F(Q[1], n) + i;
		printf("%d\n", min(a, b));
	}

	return 0;
};


#include <stdio.h>
#include <queue>
#include <vector>
using namespace std;

#define MAXN 100005
typedef pair<int,int> pii;

int N,A[MAXN],B[MAXN],P[MAXN],Q[MAXN];

vector <int> list_out[MAXN],list_in[MAXN];
priority_queue <pii> que,que2;

int main()
{
    int i,j,k;
    scanf("%d",&N);
    for (i=0;i<N;i++) scanf("%d",A+i), P[A[i]] = i;
    for (i=0;i<N;i++) scanf("%d",B+i), Q[B[i]] = i;
    for (i=1;i<=N;i++){
        list_out[(Q[i]-P[i]+N)%N].push_back(i);
        list_in[Q[i]+1].push_back(i);
        if (Q[i] > P[i]){
            que.push(pii(-(Q[i]-P[i]),i));
        }else que2.push(pii(Q[i]-P[i],i));
    }
    for (i=0;i<N;i++){
        for (j=list_in[i].size();j--;){
            k = list_in[i][j];
            que.push(pii(-(N-P[k]+i-1),k));
        }
        for (j=list_out[i].size();j--;){
            k = list_out[i][j];
            que2.push(pii(i,k));
        }
        while (!que.empty()){
            k = que.top().second;
            if (-que.top().first <= i) que.pop();
            else break;
        }
        while (!que2.empty()){
            k = que2.top().second;
            if (P[k]-(i-que2.top().first) < 0) que2.pop();
            else break;
        }
        k = 1e9;
        if (!que.empty()) k = -que.top().first-i;
        if (!que2.empty() && k > i-que2.top().first)
            k = i-que2.top().first;
        printf("%d\n",k);
    }
}


#include <stdio.h>
#include <queue>
#include <vector>
using namespace std;

#define MAXN 100005
typedef pair<int,int> pii;

int N,A[MAXN],B[MAXN],P[MAXN],Q[MAXN];
int V[MAXN],T[MAXN];

vector <int> list_out[MAXN],list_in[MAXN];
priority_queue <pii> que,que2;

int main()
{
    int i,j,k,q;
    scanf("%d",&N);
    for (i=0;i<N;i++) scanf("%d",A+i), P[A[i]] = i;
    for (i=0;i<N;i++) scanf("%d",B+i), Q[B[i]] = i;
    for (i=1;i<=N;i++){
        list_out[(P[i]-Q[i]+N)%N].push_back(i);
        list_in[N-Q[i]].push_back(i);
        if (Q[i] < P[i]){
            que.push(pii(-(P[i]-Q[i]),i)), T[i] = 1, V[i] = -(P[i]-Q[i]);
        }else que2.push(pii(P[i]-Q[i],i)), T[i] = 2, V[i] = P[i]-Q[i];
    }
    for (i=0;i<N;i++){
        for (j=list_in[i].size();j--;){
            k = list_in[i][j];
            T[k] = 1;
            q = (Q[k]+i)%N; V[k] = -(P[k]-q+i);
            que.push(pii(-(P[k]-q+i),k));
        }
        for (j=list_out[i].size();j--;){
            k = list_out[i][j];
            T[k] = 2;
            q = (Q[k]+i)%N; V[k] = (P[k]-q)+i;
            que2.push(pii((P[k]-q)+i,k));
        }
        k = 1e9;
        while (!que.empty()){
            k = que.top().second;
            if (T[k] == 2 || V[k] != que.top().first) que.pop();
            else break;
        }
        while (!que2.empty()){
            k = que2.top().second;
            if (T[k] == 1 || V[k] != que2.top().first) que2.pop();
            else break;
        }
        if (!que.empty()) k = -que.top().first-i;
        if (!que2.empty() && k > i-que2.top().first)
            k = i-que2.top().first;
        printf("%d\n",k);
    }
}


#include <stdio.h>
#include <set>
using namespace std;

#define MAXN 100005

int N,A[MAXN],B[MAXN],P[MAXN];

multiset <int> S;
multiset <int>::iterator it;

int main()
{
    int i,j,k;
    scanf("%d",&N);
    for (i=0;i<N;i++) scanf("%d",A+i), P[A[i]] = i;
    for (i=0;i<N;i++) scanf("%d",B+i), S.insert(i-P[B[i]]);
    for (i=0;i<N;i++){
        it = S.lower_bound(i);
        k = 1e9;
        if (it != S.end()) k = *it-i;
        if (it != S.begin()) k = min(k,i-*(--it));
        printf("%d\n",k);
        S.erase(S.find(i-P[B[i]]));
        S.insert(i+N-P[B[i]]);
    }
}


#include <stdio.h>
#include <queue>
#include <vector>
using namespace std;

#define MAXN 100005
typedef pair<int,int> pii;

int N,A[MAXN],B[MAXN],P[MAXN],Q[MAXN];

vector <int> list_out[MAXN],list_in[MAXN];
priority_queue <pii> que,que2;

int main()
{
    int i,j,k;
    scanf("%d",&N);
    for (i=0;i<N;i++) scanf("%d",A+i), P[A[i]] = i;
    for (i=0;i<N;i++) scanf("%d",B+i), Q[B[i]] = i;
    for (i=1;i<=N;i++){
        list_out[(P[i]-Q[i]+N)%N].push_back(i);
        list_in[N-Q[i]].push_back(i);
        if (Q[i] < P[i]){
            que.push(pii(-(P[i]-Q[i]),i));
        }else que2.push(pii(P[i]-Q[i],i));
    }
    for (i=0;i<N;i++){
        for (j=list_in[i].size();j--;){
            k = list_in[i][j];
            que.push(pii(-(P[k]+i),k));
        }
        for (j=list_out[i].size();j--;){
            k = list_out[i][j];
            que2.push(pii(i,k));
        }
        while (!que.empty()){
            k = que.top().second;
            if (-que.top().first <= i) que.pop();
            else break;
        }
        while (!que2.empty()){
            k = que2.top().second;
            if (P[k]+i-que2.top().first >= N) que2.pop();
            else break;
        }
        k = 1e9;
        if (!que.empty()) k = -que.top().first-i;
        if (!que2.empty() && k > i-que2.top().first)
            k = i-que2.top().first;
        printf("%d\n",k);
    }
}


#pragma comment(linker, "/STACK:67108864")

#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <cassert>
#include <complex>
#include <bitset>
#include <map>
#include <set>

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define FORN(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define FORD(i, n, k) for(int i = (int)(n) - 1; i >= (int)(k); i--)

#define vi vector<int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x)*(x))
#define fi first
#define se second

using namespace std;

typedef long long int64;

const long double pi = 3.1415926535897932384626433832795;
const long double eps = 0.000000001;
const int INF = 1E9;
const int MAXN = 100500;

int n, id, k;
vi a, b, ida, idb, jmp, change, cur, wh, ans;
vector<pii> emptyv;
vector<vector<pii> > q;
pii c;
set<pii> s1, s2;

void init() {
	a.resize(n);
	b.resize(n);
	ida.resize(n);
	idb.resize(n);
	jmp.resize(n);
	change.resize(n);
	cur.resize(n);
	ans.resize(n);
	wh.resize(n);
	emptyv.clear();
	forn(i, n + 2)
		q.push_back(emptyv);

	s1.clear();
	s2.clear();
}

int main() {

    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

	scanf("%d", &n);
	init();
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
	}
	forn(i, n) {
		ida[a[i]] = i;
		idb[b[i]] = i;
	}

	//calc jumps and flips
	forn(i, n) {
		jmp[a[i]] = (n + idb[a[i]] - ida[a[i]]) % n;
		change[a[i]] = n - ida[a[i]];
		q[change[a[i]]].push_back(make_pair(0, a[i]));
		q[jmp[a[i]]].push_back(make_pair(1, a[i]));
	}
	forn(i, n)
		sort(all(q[i]));

	//insert elements
	forn(i, n) {
		if (ida[i] <= idb[i]) {
			s1.insert(make_pair(idb[i] - ida[i], i));
			wh[i] = 0;
		} else {
			s2.insert(make_pair(ida[i] - idb[i], i));
			wh[i] = 1;
		}
		cur[i] = abs(idb[i] - ida[i]);
	}

	//go!
	forn(i, n) {
		forn(j, q[i].size()) {
			k = q[i][j].se;
			if (q[i][j].fi == 1) {
				if (wh[k] == 0) {
					s1.erase(make_pair(cur[k], k));
					cur[k] = -i;
					s2.insert(make_pair(cur[k], k));
				} else {
					s2.erase(make_pair(cur[k], k));
					cur[k] = i;
					s1.insert(make_pair(cur[k], k));
				}
				wh[k] = 1 - wh[k];
			} else {
				if (wh[k] == 0) {
					s1.erase(make_pair(cur[k], k));
					cur[k] = idb[k] - i;
					s2.insert(make_pair(cur[k], k));
				} else {
					s2.erase(make_pair(cur[k], k));
					cur[k] = idb[k] + i;
					s1.insert(make_pair(cur[k], k));
				}
				wh[k] = 1 - wh[k];
			}
		}

		//extract
		ans[i] = INF;
		if (!(s1.empty())) {
			c = *s1.begin();
			ans[i] = min(ans[i], c.fi - i);
		}
		if (!(s2.empty())) {
			c = *s2.begin();
			ans[i] = min(ans[i], c.fi + i);
		}
	}

	printf("%d\n", ans[0]);
	FORD(i, n, 1)
		printf("%d\n", ans[i]);

    return 0;
}


#pragma comment(linker, "/STACK:67108864")

#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <cassert>
#include <complex>
#include <bitset>
#include <map>
#include <set>

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define FORN(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define FORD(i, n, k) for(int i = (int)(n) - 1; i >= (int)(k); i--)

#define vi vector<int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x)*(x))
#define fi first
#define se second

using namespace std;

typedef long long int64;

const long double pi = 3.1415926535897932384626433832795;
const long double eps = 0.000000001;
const int INF = 1E9;
const int MAXN = 100500;

int n, id, k;
vi a, b, ida, idb, jmp, change, cur, wh, ans;
vector<pii> emptyv;
vector<vector<pii> > q;
pii c;
set<pii> s1, s2;

void init() {
	a.resize(n);
	b.resize(n);
	ida.resize(n);
	idb.resize(n);
	jmp.resize(n);
	change.resize(n);
	cur.resize(n);
	ans.resize(n);
	wh.resize(n);
	emptyv.clear();
	forn(i, n + 2)
		q.push_back(emptyv);

	s1.clear();
	s2.clear();
}

int main() {

    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

	scanf("%d", &n);
	init();
	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
	}
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	forn(i, n) {
		ida[a[i]] = i;
		idb[b[i]] = i;
	}

	//calc jumps and flips
	forn(i, n) {
		jmp[a[i]] = (n + idb[a[i]] - ida[a[i]]) % n;
		change[a[i]] = n - ida[a[i]];
		q[change[a[i]]].push_back(make_pair(0, a[i]));
		q[jmp[a[i]]].push_back(make_pair(-1, a[i]));
	}
	forn(i, n)
		sort(all(q[i]));

	//insert elements
	forn(i, n) {
		if (ida[i] <= idb[i]) {
			s1.insert(make_pair(idb[i] - ida[i], i));
			wh[i] = 0;
		} else {
			s2.insert(make_pair(ida[i] - idb[i], i));
			wh[i] = 1;
		}
		cur[i] = abs(idb[i] - ida[i]);
	}

	//go!
	forn(i, n) {
		forn(j, q[i].size()) {
			k = q[i][j].se;
			if (q[i][j].fi == -1) {
				if (wh[k] == 0) {
					s1.erase(make_pair(cur[k], k));
					cur[k] = -i;
					s2.insert(make_pair(cur[k], k));
				} else {
					s2.erase(make_pair(cur[k], k));
					cur[k] = i;
					s1.insert(make_pair(cur[k], k));
				}
				wh[k] = 1 - wh[k];
			} else {
				if (wh[k] == 0) {
					s1.erase(make_pair(cur[k], k));
					cur[k] = idb[k] - i;
					s2.insert(make_pair(cur[k], k));
				} else {
					s2.erase(make_pair(cur[k], k));
					cur[k] = idb[k] + i;
					s1.insert(make_pair(cur[k], k));
				}
				wh[k] = 1 - wh[k];
			}
		}

		//extract
		ans[i] = INF;
		if (!(s1.empty())) {
			c = *s1.begin();
			ans[i] = min(ans[i], c.fi - i);
		}
		if (!(s2.empty())) {
			c = *s2.begin();
			ans[i] = min(ans[i], c.fi + i);
		}
	}

	printf("%d\n", ans[0]);
	FORD(i, n, 1)
		printf("%d\n", ans[i]);

    return 0;
}


#pragma warning (disable:4786)
#include <vector>
#include <map>
#include <string>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <fstream>

using namespace std;
#define N 100010

int a[N], b[N], c[N];

int main() {
#ifndef ONLINE_JUDGE
    ifstream cin("in.txt");
#endif
	multiset<int> s;
	int n, i;
	cin>>n;
	for(i=0;i<n;i++)	cin>>a[i];
	for(i=0;i<n;i++)	cin>>b[i], c[a[i]] = i;
	for(i=0;i<n;i++)
		s.insert(i-c[b[i]]);
	for(i=0;i<n;i++){
		multiset<int>::iterator it = s.lower_bound(i);
		int m;
		if(it==s.end())
			m = i-*(--it);
		else if(it==s.begin())
			m = i-*it;
		else {
			int p = *it, q = *(--it);
			m = __min(p-i, i-q);
		}
		cout<<m<<endl;
		s.erase(s.find(i-c[b[i]]));
		s.insert(n-c[b[i]]+i);
	}
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <memory.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int inf = 1000*1000*1000;
#define CL(x,a) memset(x,a,sizeof(x));
#define ALL(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define PDI pair<double,int>
#define MP(a,b) make_pair(a,b)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vector<PII > > vvpii;

int n;
int ar[100009];
int br[100009];
int res[100009];
vector<int> v[100009];
int getIter(int a, int b)
{
	if (b > a)
		return (b-a)%n;
	else
		return (b + n - a)%n;
}
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d",&n);
	FOR(i,n)
	{
		int t;
		scanf("%d",&t);
		t--;
		ar[t] = i;
	}
	FOR(i,n)
	{
		int t;
		scanf("%d",&t);
		t--;
		br[t] = i;
	}
	FOR(i,n)
		res[i] = inf;
	FOR(i,n)
	{
		//res[getIter(ar[i],br[i])] = 0;
		v[getIter(ar[i],br[i])].push_back(i);
	}
	multiset<pair<int,int> > st;
	multiset<int,greater<int> > Min;
	for (int z=0,i=0;z < n*3;z++,i=(i+1)%n)
	{
		FOR(j,v[i].size())
		{
			st.insert(MP(z+ar[v[i][j]]+1,z));
			Min.insert(z);
		}
		while(st.size() && st.begin()->first <= z)
		{
			Min.erase(Min.find(st.begin()->second));
			st.erase(st.begin());
		}
		if (st.size())
			res[i] = min(res[i],abs(*(Min.begin()) - z) );
	}
	st.clear();
	Min.clear();
	for (int z=0,i=0;z < n*3;z++,i=(i-1+n)%n)
	{
		FOR(j,v[i].size())
		{
			st.insert(MP(z+ n - ar[v[i][j]],z));
			Min.insert(z);
		}
		while(st.size() && st.begin()->first <= z)
		{
			Min.erase(Min.find(st.begin()->second));
			st.erase(st.begin());
		}
		if (st.size())
			res[i] = min(res[i],abs(*(Min.begin()) - z) );
	}
	FOR(i,n)
	{
		printf("%d\n",res[i]);
	}
	return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:200000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; }
template<typename T> inline T sqr(T x) { return x * x; }

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 300100;

int n, a[MAXN], b[MAXN], posa[MAXN], posb[MAXN];
int wh[MAXN], stv[MAXN], tolb, torb;
multiset<int> tol, tor;
vector<int> e[MAXN];

void add(int x, int pa, int pb) {
	int p = pa - pb;
	if (0 <= p && p < n)
		e[p].pb(x);
}

void recalc(int x, int pos, int L, int R) {
	if (wh[x] == -1) tol.erase(tol.find(stv[x]));
	if (wh[x] == +1) tor.erase(tor.find(stv[x]));

	int val1 = abs(posa[x] - pos);
	int val2 = abs(posa[x] + n - pos);

	if (!(L <= posa[x] && posa[x] <= R))
		val1 = INF;

	if (!(L <= posa[x] + n && posa[x] + n <= R))
		val2 = INF;

	int pp = (val1 < val2) ? (posa[x]) : (posa[x] + n);
	if (pp > pos) {
		wh[x] = +1;
		stv[x] = abs(pp - pos) - torb;
		tor.insert(stv[x]);
	} else {
		wh[x] = -1;
		stv[x] = abs(pp - pos) - tolb;
		tol.insert(stv[x]);
	}
}

int get(const multiset<int> &st, int balance) {
	if (st.empty()) return INF;
	return *st.begin() + balance;
}

int main() {
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
#else
#endif

	cin >> n;
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
	}

	forn(i, n) {
		posa[a[i]] = i;
		posb[b[i]] = i;
	}

	forn(i, n) {
		add(i, posa[i], posb[i]);
		add(i, posa[i] + n, posb[i]);
		add(i, posa[i] + (n + 1) / 2, posb[i]);
		e[i].pb(posa[i] + 1);
	}

	forn(i, n)
		recalc(i, posb[i], 0, n - 1);

	forn(i, n) {
		forn(j, e[i].size())
			recalc(e[i][j], i + posb[e[i][j]], i, i + n - 1);

		int ans = min(get(tor, torb), get(tol, tolb));
		printf("%d\n", ans);
		tolb++; torb--;

		//int res = INF;
		//forn(j, n)
		//	if (i <= posa[j] && posa[j] < i + n)
		//		res = min(res, abs(posa[j] - (i + posb[j])));
		//	else
		//		res = min(res, abs(posa[j] + n - (i + posb[j])));

		//if (res != ans)
		//	throw;
	}

	return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:200000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; }
template<typename T> inline T sqr(T x) { return x * x; }

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 300100;

int n, a[MAXN], b[MAXN], posa[MAXN], posb[MAXN];
int wh[MAXN], stv[MAXN], tolb, torb;
multiset<int> tol, tor;
vector<int> e[MAXN];

void add(int x, int pa, int pb) {
	int p = pa - pb;
	if (0 <= p && p < n)
		e[p].pb(x);
}

void recalc(int x, int pos, int L, int R) {
	if (wh[x] == -1) tol.erase(tol.find(stv[x]));
	if (wh[x] == +1) tor.erase(tor.find(stv[x]));

	int val1 = abs(posa[x] - pos);
	int val2 = abs(posa[x] + n - pos);

	if (!(L <= posa[x] && posa[x] <= R))
		val1 = INF;

	if (!(L <= posa[x] + n && posa[x] + n <= R))
		val2 = INF;

	int pp = (val1 < val2) ? (posa[x]) : (posa[x] + n);
	if (pp > pos) {
		wh[x] = +1;
		stv[x] = abs(pp - pos) - torb;
		tor.insert(stv[x]);
	} else {
		wh[x] = -1;
		stv[x] = abs(pp - pos) - tolb;
		tol.insert(stv[x]);
	}
}

int get(const multiset<int> &st, int balance) {
	if (st.empty()) return INF;
	return *st.begin() + balance;
}

int main() {
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
#else
#endif

	cin >> n;
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
	}

	forn(i, n) {
		posa[a[i]] = i;
		posb[b[i]] = i;
	}

	forn(i, n) {
		add(i, posa[i], posb[i]);
		add(i, posa[i] + n, posb[i]);
		add(i, posa[i] + (n + 1) / 2, posb[i]);
		e[i].pb(posa[i]);
	}

	forn(i, n)
		recalc(i, posb[i], 0, n - 1);

	forn(i, n) {
		forn(j, e[i].size())
			recalc(e[i][j], i + posb[e[i][j]], i, i + n - 1);

		int ans = min(get(tor, torb), get(tol, tolb));
		printf("%d\n", ans);
		tolb++; torb--;
	}

	return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:200000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; }
template<typename T> inline T sqr(T x) { return x * x; }

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 300100;

int n, a[MAXN], b[MAXN], posa[MAXN], posb[MAXN];
int wh[MAXN], stv[MAXN], tolb, torb;
multiset<int> tol, tor;
vector<int> e[MAXN];

void add(int x, int pa, int pb) {
	int p = pa - pb;
	if (0 <= p && p < n)
		e[p].pb(x);
}

void recalc(int x, int pos) {
	if (wh[x] == -1) tol.erase(tol.find(stv[x]));
	if (wh[x] == +1) tor.erase(tor.find(stv[x]));

	int val1 = abs(posa[x] - pos);
	int val2 = abs(posa[x] + n - pos);

	int pp = (val1 < val2) ? (posa[x]) : (posa[x] + n);
	if (pp > pos) {
		wh[x] = +1;
		stv[x] = abs(pp - pos) - torb;
		tor.insert(stv[x]);
	} else {
		wh[x] = -1;
		stv[x] = abs(pp - pos) - tolb;
		tol.insert(stv[x]);
	}
}

int get(const multiset<int> &st, int balance) {
	if (st.empty()) return INF;
	return *st.begin() + balance;
}

int main() {
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
#else
#endif

	cin >> n;
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
		posa[a[i]] = i;
		a[n + i] = a[i];
	}

	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
		posb[b[i]] = i;
	}

	forn(i, n) {
		add(i, posa[i], posb[i]);
		add(i, posa[i] + n, posb[i]);
		add(i, posa[i] + (n + 1) / 2, posb[i]);
	}

	forn(i, n) {
		forn(j, e[i].size())
			recalc(e[i][j], i + posb[e[i][j]]);

		int ans = min(get(tor, torb), get(tol, tolb));
		printf("%d\n", ans);

		tolb++; torb--;
	}

	return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:200000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; }
template<typename T> inline T sqr(T x) { return x * x; }

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 300100;

int n, a[MAXN], b[MAXN], posa[MAXN], posb[MAXN];
int wh[MAXN], stv[MAXN], tolb, torb;
multiset<int> tol, tor;
vector<int> e[MAXN];

void add(int x, int pa, int pb) {
	int p = pa - pb;
	if (0 <= p && p < n)
		e[p].pb(x);
}

void recalc(int x, int pos, int L, int R) {
	if (wh[x] == -1) tol.erase(tol.find(stv[x]));
	if (wh[x] == +1) tor.erase(tor.find(stv[x]));

	int val1 = abs(posa[x] - pos);
	int val2 = abs(posa[x] + n - pos);

	if (!(L <= posa[x] && posa[x] <= R))
		val1 = INF;

	if (!(L <= posa[x] + n && posa[x] + n <= R))
		val2 = INF;

	int pp = (val1 < val2) ? (posa[x]) : (posa[x] + n);
	if (pp > pos) {
		wh[x] = +1;
		stv[x] = abs(pp - pos) - torb;
		tor.insert(stv[x]);
	} else {
		wh[x] = -1;
		stv[x] = abs(pp - pos) - tolb;
		tol.insert(stv[x]);
	}
}

int get(const multiset<int> &st, int balance) {
	if (st.empty()) return INF;
	return *st.begin() + balance;
}

int main() {
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
#else
#endif

	bool debug = false;

	cin >> n;
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
	}

	if (debug) {
		srand(time(0));
		n = 100;
		forn(i, n) a[i] = b[i] = i;
		random_shuffle(a, a + n);
		random_shuffle(b, b + n);
	}

	forn(i, n) {
		posa[a[i]] = i;
		posb[b[i]] = i;
	}

	forn(i, n) {
		add(i, posa[i], posb[i]);
		add(i, posa[i] + n, posb[i]);
		add(i, posa[i] + (n + 1) / 2, posb[i]);
		e[posa[i] + 1].pb(i);
	}

	forn(i, n)
		recalc(i, posb[i], 0, n - 1);

	forn(i, n) {
		forn(j, e[i].size())
			recalc(e[i][j], i + posb[e[i][j]], i, i + n - 1);

		int ans = min(get(tor, torb), get(tol, tolb));
		printf("%d\n", ans);
		tolb++; torb--;

		if (debug) {
			int res = INF;
			forn(j, n)
				if (i <= posa[j] && posa[j] < i + n)
					res = min(res, abs(posa[j] - (i + posb[j])));
				else
					res = min(res, abs(posa[j] + n - (i + posb[j])));

			if (res != ans)
				throw;
		}
	}

	return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:200000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; }
template<typename T> inline T sqr(T x) { return x * x; }

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 300100;

int n, a[MAXN], b[MAXN], posa[MAXN], posb[MAXN];
int wh[MAXN], stv[MAXN], tolb, torb;
multiset<int> tol, tor;
vector<int> e[MAXN];

void add(int x, int pa, int pb) {
	int p = pa - pb;
	if (0 <= p && p < n)
		e[p].pb(x);
}

void recalc(int x, int pos) {
	if (wh[x] == -1) tol.erase(tol.find(stv[x]));
	if (wh[x] == +1) tor.erase(tor.find(stv[x]));

	int val1 = abs(posa[x] - pos);
	int val2 = abs(posa[x] + n - pos);

	int pp = (val1 < val2) ? (posa[x]) : (posa[x] + n);
	if (pp > pos) {
		wh[x] = +1;
		stv[x] = abs(pp - pos) - torb;
		tor.insert(stv[x]);
	} else {
		wh[x] = -1;
		stv[x] = abs(pp - pos) - tolb;
		tol.insert(stv[x]);
	}
}

int get(const multiset<int> &st, int balance) {
	if (st.empty()) return INF;
	return *st.begin() + balance;
}

int main() {
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
#else
#endif

	cin >> n;
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
		posa[a[i]] = i;
	}

	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
		posb[b[i]] = i;
	}

	forn(i, n) {
		add(i, posa[i], posb[i]);
		add(i, posa[i] + n, posb[i]);
		add(i, posa[i] + (n + 1) / 2, posb[i]);
	}

	forn(i, n)
		recalc(i, posb[i]);

	forn(i, n) {
		forn(j, e[i].size())
			recalc(e[i][j], i + posb[e[i][j]]);

		int ans = min(get(tor, torb), get(tol, tolb));
		printf("%d\n", ans);

		tolb++; torb--;
	}

	return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:200000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; }
template<typename T> inline T sqr(T x) { return x * x; }

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 300100;

int n, a[MAXN], b[MAXN], posa[MAXN], posb[MAXN];
int wh[MAXN], stv[MAXN], tolb, torb;
multiset<int> tol, tor;
vector<int> e[MAXN];

void init() {
	memset(wh, 0, sizeof wh);
	tol.clear();
	tor.clear();
	forn(i, MAXN) e[i].clear();
	tolb = torb = 0;
}

void add(int x, int pa, int pb) {
	int p = pa - pb;
	if (0 <= p && p < n)
		e[p].pb(x);
}

void recalc(int x, int pos, int L, int R) {
	if (wh[x] == -1) tol.erase(tol.find(stv[x]));
	if (wh[x] == +1) tor.erase(tor.find(stv[x]));

	int val1 = abs(posa[x] - pos);
	int val2 = abs(posa[x] + n - pos);

	if (!(L <= posa[x] && posa[x] <= R))
		val1 = INF;

	if (!(L <= posa[x] + n && posa[x] + n <= R))
		val2 = INF;

	int pp = (val1 < val2) ? (posa[x]) : (posa[x] + n);
	if (pp > pos) {
		wh[x] = +1;
		stv[x] = abs(pp - pos) - torb;
		tor.insert(stv[x]);
	} else {
		wh[x] = -1;
		stv[x] = abs(pp - pos) - tolb;
		tol.insert(stv[x]);
	}
}

int get(const multiset<int> &st, int balance) {
	if (st.empty()) return INF;
	return *st.begin() + balance;
}

int main() {
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
#else
#endif

	cin >> n;
	forn(i, n) {
		scanf("%d", &b[i]);
		b[i]--;
	}

	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	forn(i, n) {
		posa[a[i]] = i;
		posb[b[i]] = i;
	}

	forn(i, n) {
		add(i, posa[i], posb[i]);
		add(i, posa[i] + n, posb[i]);
		add(i, posa[i] + (n + 1) / 2, posb[i]);
		e[posa[i] + 1].pb(i);
	}

	forn(i, n)
		recalc(i, posb[i], 0, n - 1);

	forn(i, n) {
		forn(j, e[i].size())
			recalc(e[i][j], i + posb[e[i][j]], i, i + n - 1);

		int ans = min(get(tor, torb), get(tol, tolb));
		printf("%d\n", ans);
		tolb++; torb--;
	}

	return 0;
}


#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
int w[100100], o[100100];
int main()
{
	int i, a, pv;
	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%d", &o[i]);
		w[o[i]] = i;
	}
	for (i = 1; i <= n; i++){
		scanf("%d", &a);
		w[a] = w[a] - i;
		if (w[a] < 0)w[a] += n;
	}
	sort(w + 1, w + n + 1);
	pv = 1;
	for (i = 0; i < n; i++){
		printf("%d\n", min(w[pv] - i, i + n - w[pv + n - 1]));
		while (w[pv] == i){
			w[pv + n] = i + n;
			pv++;
		}
	}
}


#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
int w[200100], o[100100];
int main()
{
	int i, a, pv;
	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%d", &o[i]);
		w[o[i]] = i;
	}
	for (i = 1; i <= n; i++){
		scanf("%d", &a);
		w[a] = i - w[a];
		if (w[a] < 0)w[a] += n;
	}
	sort(w + 1, w + n + 1);
	pv = 1;
	for (i = 0; i < n; i++){
		printf("%d\n", min(w[pv] - i, i + n - w[pv + n - 1]));
		while (w[pv] == i){
			w[pv + n] = i + n;
			pv++;
		}
	}
	return 0;
}


#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
int w[100100], o[100100];
int main()
{
	int i, a, pv;
	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%d", &o[i]);
		w[o[i]] = i;
	}
	for (i = 1; i <= n; i++){
		scanf("%d", &a);
		w[a] = i - w[a];
		if (w[a] < 0)w[a] += n;
	}
	sort(w + 1, w + n + 1);
	pv = 1;
	for (i = 0; i < n; i++){
		printf("%d\n", min(w[pv] - i, i + n - w[pv + n - 1]));
		while (w[pv] == i){
			w[pv + n] = i + n;
			pv++;
		}
	}
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;

const int MAX_N=1000*100+100;

int a[MAX_N], a_[MAX_N];
int b[MAX_N];
int n;

int dis[MAX_N];

struct S{
	int k;
	S(int k=0): k(k){}
	bool operator < (const S s) const {
		if(dis[k]!=dis[s.k])	return dis[k]>dis[s.k];
		return k<s.k;
	}
};
struct T{
	int k;
	T(int k=0): k(k){}
	bool operator < (const T t) const {
		if(dis[k]!=dis[t.k])	return dis[k]<dis[t.k];
		return k<t.k;
	}
};

set<S> S1;
set<T> S2;

vector<int> v;

int main(){

	cin >>n;
	for(int i=0; i<n; i++){
		cin >>a[i];	a[i]--;
		a_[a[i]]=i;
	}
	for(int i=0; i<n; i++){
		cin >>b[i];	b[i]--;
	}

	for(int i=0; i<n; i++){
		dis[i]=i-a_[b[i]];
		if(dis[i]<=0){
			S1.insert(S(i));
		}else{
			S2.insert(T(i));
		}
	}

	for(int k=0; k<n; k++){
		int cur=min((S1.size()==0?n:-dis[S1.begin()->k]-k), (S2.size()==0?n:dis[S2.begin()->k]+k));
		v.push_back(cur);
		while(S1.size()!=0 && dis[S1.begin()->k]==-k){
			int r=S1.begin()->k;
			S1.erase(S1.begin());
			S2.insert(T(r));
		}
		int r=n-1-k;
		S2.erase(T(r));
		dis[r]=-a_[b[r]]-(k+1);
		S1.insert(S(r));
	}

	cout <<v[0] <<endl;
	for(int i=n-1; i>=1; i--)
		cout <<v[i] <<endl;

	return 0;
}

/*
10
5 1 6 2 8 3 4 10 9 7
3 1 10 6 8 5 2 7 9 4
*/


#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

const int MAX_N=1000*100+100;

int a[MAX_N], a_[MAX_N];
int b[MAX_N];
int n;

int dis[MAX_N];

struct S{
	int k;
	S(int k=0): k(k){}
	bool operator < (const S s) const {
		if(dis[k]!=dis[s.k])	return dis[k]>dis[s.k];
		return k<s.k;
	}
};
struct T{
	int k;
	T(int k=0): k(k){}
	bool operator < (const T t) const {
		if(dis[k]!=dis[t.k])	return dis[k]<dis[t.k];
		return k<t.k;
	}
};

set<S> S1;
set<T> S2;

int main(){

	cin >>n;
	for(int i=0; i<n; i++){
		cin >>a[i];	a[i]--;
		a_[a[i]]=i;
	}
	for(int i=0; i<n; i++){
		cin >>b[i];	b[i]--;
	}

	for(int i=0; i<n; i++){
		dis[i]=i-a_[b[i]];
		if(dis[i]<=0){
			S1.insert(S(i));
		}else{
			S2.insert(T(i));
		}
	}

	for(int k=0; k<n; k++){
		int cur=min((S1.size()==0?n:-dis[S1.begin()->k]-k), (S2.size()==0?n:dis[S2.begin()->k]+k));
		cout <<cur <<endl;
		while(S1.size()!=0 && dis[S1.begin()->k]==-k){
			int r=S1.begin()->k;
			S1.erase(S1.begin());
			S2.insert(T(r));
		}
		int r=n-1-k;
		S2.erase(T(r));
		dis[r]=-a_[b[r]]-(k+1);
		S1.insert(S(r));
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int maxn = 100010;
int a[maxn], b[maxn];
int reva[maxn], revb[maxn];
pii what[maxn];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]),a[i]--,reva[a[i]]=i;
	for (int i = 0 ;i < n; ++i) scanf("%d", &b[i]),b[i]--,revb[b[i]]=i;
	set<pii> stpos, stneg;
	int corrpos = 0, corrneg = 0;
	for (int i = 0; i < n; ++i) {
		int diff = revb[i]-reva[i];
		what[i] = mp(abs(diff),i);
		if (diff>=0) stpos.insert(mp(diff,i));
		else stneg.insert(mp(-diff,i));
	}
	for (int i = 0; i < n; ++i) {
		int curans = INF;
		if (!stpos.empty()) curans = min(curans, corrpos+stpos.begin()->X);
		if (!stneg.empty()) curans = min(curans, corrneg+stneg.begin()->X);
		printf("%d\n", curans);
		if (i == n-1) break;
		int ccc = 0;
		if (stpos.count(what[b[i]])) stpos.erase(what[b[i]]), ccc=1;
		if (stneg.count(what[b[i]])) stneg.erase(what[b[i]]), ccc=1;
		assert(ccc==1);
		corrpos--;
		corrneg++;
		while (!stpos.empty() && stpos.begin()->X+corrpos<0) {
			pii cur = *stpos.begin();
			stpos.erase(stpos.begin());
			cur.X+=corrpos;
			cur.X=-cur.X;
			cur.X-=corrneg;
			what[cur.Y]=cur;
			//cur.X=1-corrneg;
			stneg.insert(cur);
		}
		stpos.insert(mp(n-1-reva[b[i]]-corrpos,b[i]));
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int maxn = 100010;
int a[maxn], b[maxn];
int reva[maxn], revb[maxn];
pii what[maxn];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]),a[i]--,reva[a[i]]=i;
	for (int i = 0 ;i < n; ++i) scanf("%d", &b[i]),b[i]--,revb[b[i]]=i;
	set<pii> stpos, stneg;
	int corrpos = 0, corrneg = 0;
	for (int i = 0; i < n; ++i) {
		int diff = revb[i]-reva[i];
		what[i] = mp(abs(diff),i);
		if (diff>=0) stpos.insert(mp(diff,i));
		else stneg.insert(mp(-diff,i));
	}
	for (int i = 0; i < n; ++i) {
		int curans = INF;
		if (!stpos.empty()) curans = min(curans, corrpos+stpos.begin()->X);
		if (!stneg.empty()) curans = min(curans, corrneg+stneg.begin()->X);
		printf("%d\n", curans);
		if (stpos.count(what[b[i]])) stpos.erase(what[b[i]]);
		if (stneg.count(what[b[i]])) stneg.erase(what[b[i]]);
		corrpos--;
		corrneg++;
		while (!stpos.empty() && stpos.begin()->X+corrpos<0) {
			pii cur = *stpos.begin();
			stpos.erase(stpos.begin());
			cur.X+=corrpos;
			cur.X=-cur.X;
			cur.X-=corrneg;
			//cur.X=1-corrneg;
			stneg.insert(cur);
		}
		stpos.insert(mp(n-1-reva[b[i]]-corrpos,b[i]));
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int maxn = 100010;
int a[maxn], b[maxn];
int reva[maxn], revb[maxn];
pii what[maxn];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]),a[i]--,reva[a[i]]=i;
	for (int i = 0 ;i < n; ++i) scanf("%d", &b[i]),b[i]--,revb[b[i]]=i;
	set<pii> stpos, stneg;
	int corrpos = 0, corrneg = 0;
	for (int i = 0; i < n; ++i) {
		int diff = revb[i]-reva[i];
		what[i] = mp(abs(diff),i);
		if (diff>=0) stpos.insert(mp(diff,i));
		else stneg.insert(mp(-diff,i));
	}
	for (int i = 0; i < n; ++i) {
		int curans = INF;
		if (!stpos.empty()) curans = min(curans, corrpos+stpos.begin()->X);
		if (!stneg.empty()) curans = min(curans, corrneg+stneg.begin()->X);
		printf("%d\n", curans);
		if (stpos.count(what[b[i]])) stpos.erase(what[b[i]]);
		if (stneg.count(what[b[i]])) stneg.erase(what[b[i]]);
		corrpos--;
		corrneg++;
		while (!stpos.empty() && stpos.begin()->X+corrpos<0) {
			pii cur = *stpos.begin();
			stpos.erase(stpos.begin());
			//cur.X+=corrpos-corrneg;
			cur.X=1-corrneg;
			stneg.insert(cur);
		}
		stpos.insert(mp(n-1-reva[b[i]]-corrpos,b[i]));
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int maxn = 100010;
int a[maxn], b[maxn];
int reva[maxn], revb[maxn];
pii what[maxn];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]),a[i]--,reva[a[i]]=i;
	for (int i = 0 ;i < n; ++i) scanf("%d", &b[i]),b[i]--,revb[b[i]]=i;
	set<pii> stpos, stneg;
	int corrpos = 0, corrneg = 0;
	for (int i = 0; i < n; ++i) {
		int diff = revb[i]-reva[i];
		what[i] = mp(abs(diff),i);
		if (diff>=0) stpos.insert(mp(diff,i));
		else stneg.insert(mp(-diff,i));
	}
	for (int i = 0; i < n; ++i) {
		int curans = INF;
		if (!stpos.empty()) curans = min(curans, corrpos+stpos.begin()->X);
		if (!stneg.empty()) curans = min(curans, corrneg+stneg.begin()->X);
		printf("%d\n", curans);
		if (i == n-1) break;
		int ccc = 0;
		if (stpos.count(what[b[i]])) ccc|=stpos.erase(what[b[i]]);
		if (stneg.count(what[b[i]])) ccc|=stneg.erase(what[b[i]]);
		assert(ccc==1);
		corrpos--;
		corrneg++;
		while (!stpos.empty() && stpos.begin()->X+corrpos<0) {
			pii cur = *stpos.begin();
			stpos.erase(stpos.begin());
			cur.X+=corrpos;
			cur.X=-cur.X;
			cur.X-=corrneg;
			//cur.X=1-corrneg;
			stneg.insert(cur);
		}
		stpos.insert(mp(n-1-reva[b[i]]-corrpos,b[i]));
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;
const int maxn = 100010;
int a[maxn], b[maxn];
int reva[maxn], revb[maxn];
pii what[maxn];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]),a[i]--,reva[a[i]]=i;
	for (int i = 0 ;i < n; ++i) scanf("%d", &b[i]),b[i]--,revb[b[i]]=i;
	set<pii> stpos, stneg;
	int corrpos = 0, corrneg = 0;
	for (int i = 0; i < n; ++i) {
		int diff = revb[i]-reva[i];
		what[i] = mp(abs(diff),i);
		if (diff>=0) stpos.insert(mp(diff,i));
		else stneg.insert(mp(-diff,i));
	}
	for (int i = 0; i < n; ++i) {
		int curans = INF;
		if (!stpos.empty()) curans = min(curans, corrpos+stpos.begin()->X);
		if (!stneg.empty()) curans = min(curans, corrneg+stneg.begin()->X);
		printf("%d\n", curans);
		int ccc = 0;
		if (stpos.count(what[b[i]])) ccc|=stpos.erase(what[b[i]]);
		if (stneg.count(what[b[i]])) ccc|=stneg.erase(what[b[i]]);
		assert(ccc==1);
		corrpos--;
		corrneg++;
		while (!stpos.empty() && stpos.begin()->X+corrpos<0) {
			pii cur = *stpos.begin();
			stpos.erase(stpos.begin());
			cur.X+=corrpos;
			cur.X=-cur.X;
			cur.X-=corrneg;
			//cur.X=1-corrneg;
			stneg.insert(cur);
		}
		stpos.insert(mp(n-1-reva[b[i]]-corrpos,b[i]));
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sst stringstream
#define sz(x) ((int)x.size())
#define vc vector
typedef vc<int> vi;
typedef vc<ll> vl;
typedef vc<string> vs;

map<int,int> M;
map<int,int>::ite it;

int n,a[100010],b[100010],apos[100010],dif[100010];

int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	rep(i,n)cin>>a[i],a[i]--,apos[a[i]]=i;
	rep(i,n){
		cin>>b[i],b[i]--;
		dif[i]=i-apos[b[i]];
		M[dif[i]]++;
	}
	rep(i,n){
		it = M.lower_bound(i);
		/*int res = INF;
		if(it!=M.end()){
			res = it->fir - i;
		}*/
		int res = it->fir - i;
		if(it!=M.begin()){
			it--;
			res = min(res,i - it->fir);
		}
		cout<<res<<endl;

		M[dif[i]]--;
		if(M[dif[i]] == 0){
			M.erase(dif[i]);
		}
		M[dif[i]+n]++;
	}
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sst stringstream
#define sz(x) ((int)x.size())
#define vc vector
typedef vc<int> vi;
typedef vc<ll> vl;
typedef vc<string> vs;

int n,a[100010],apos[100010],b[100010];
int mv[100010];
multiset<int> posi,nega;
multiset<int>::ite it;

int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>a[i];
		a[i]--;
		apos[a[i]]=i;
	}
	rep(i,n){
		cin>>b[i];
		b[i]--;
		int dif = i - apos[b[i]];
		if(dif>0)posi.insert(dif);
		else nega.insert(-dif);
		mv[i] = apos[b[i]];
	}
	rep(ii,n){
		int erased = posi.erase(ii);
		rep(i,erased)nega.insert(-ii);

		int minP = INF, minN = INF;
		if(!posi.empty())minP = *posi.begin() - ii;
		if(!nega.empty())minN = *nega.begin() + ii;
		cout<<min(minP,minN)<<endl;

		it = nega.find(mv[ii]-ii);
		nega.erase(it);
		posi.insert(n-mv[ii]+ii);
	}
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sst stringstream
#define sz(x) ((int)x.size())
#define vc vector
typedef vc<int> vi;
typedef vc<ll> vl;
typedef vc<string> vs;

map<int,int> M;
map<int,int>::ite it;

int n,a[100010],b[100010],apos[100010],dif[100010];

int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	rep(i,n)cin>>a[i],a[i]--,apos[a[i]]=i;
	rep(i,n){
		cin>>b[i],b[i]--;
		dif[i]=i-apos[b[i]];
		M[dif[i]]++;
	}
	rep(i,n){
		it = M.lower_bound(i);
		int res = INF;
		if(it!=M.end()){
			res = it->fir - i;
		}
		if(it!=M.begin()){
			it--;
			res = min(res,i - it->fir);
		}
		cout<<res<<endl;

		M[dif[i]]--;
		if(M[dif[i]] == 0){
			M.erase(dif[i]);
		}
		M[dif[i]+n]++;
	}
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sst stringstream
#define sz(x) ((int)x.size())
#define vc vector
typedef vc<int> vi;
typedef vc<ll> vl;
typedef vc<string> vs;

map<int,int> M;
map<int,int>::ite it;

int n,a[100010],b[100010],apos[100010],dif[100010];

int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	rep(i,n)cin>>a[i],a[i]--,apos[a[i]]=i;
	rep(i,n){
		cin>>b[i],b[i]--;
		dif[i]=i-apos[b[i]];
		M[dif[i]]++;
	}
	rep(i,n){
		it = M.lower_bound(i);
		/*int res = INF;
		if(it!=M.end()){
			res = it->fir - i;
		}*/
		int res = it->fir - i;
		if(it!=M.begin()){
			it--;
			res = min(res,i - it->fir);
		}
		cout<<res<<endl;

		//M[dif[i]]--;
		/*if(M[dif[i]] == 0)*/
		if(--M[dif[i]]==0){
			M.erase(dif[i]);
		}
		M[dif[i]+n]++;
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin >> n;
	vector<int> pos(n+2), b(n+2);
	for (int i = 0; i < n; i++)
	{
		int c;
		scanf("%d", &c);
		pos[c] = i;
	}
	multiset<int> dist;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &b[i]);
		dist.insert(i - pos[b[i]]);
	}
	for (int i = 0; i < n; i++)
	{
		multiset<int>::iterator it = dist.lower_bound(i);
		int ans = 100500;
		if (it != dist.end()) ans = min(ans, *it - i);
		if (it != dist.begin()) ans = min(ans, i - *(--it));
		printf("%d\n", ans);

		dist.erase(dist.find(i - pos[b[i]]));
		dist.insert(i - pos[b[i]] + n);
	}
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <numeric>
#include <ctime>
#include <climits>
using namespace std;

int nextInt() {
	int x;
	scanf("%d", &x);
	return x;
}

long long nextLong() {
	long long x;
	scanf("%I64d", &x);
	return x;
}

double nextDouble() {
	double x;
	scanf("%lf", &x);
	return x;
}

const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
	scanf("%s", buf);
	return buf;
}
string nextLine() {
	gets(buf);
	return buf;
}

int stringToInt(string s) {
	stringstream in(s);
	int x;
	in >> x;
	return x;
}

struct Point {
	typedef double T;
	T x, y;
	Point () : x(0), y(0) {}
	Point (T x, T y) : x(x), y(y) {}
	Point operator - (Point op) const { return Point(x - op.x, y - op.y); }
	Point operator + (Point op) const { return Point(x + op.x, y + op.y); }
	Point operator * (T op) const { return Point(x * op, y * op); }
	T operator * (Point op) const { return x * op.x + y * op.y; }
	T operator % (Point op) const { return x * op.y - y * op.x; }
	T length2() { return x * x + y * y; }
	double length() { return sqrt(length2()); }
};

Point nextPoint() {
	double x = nextDouble();
	double y = nextDouble();
	return Point(x, y);
}

typedef vector<vector<int> > Adj;

vector<int> getPos(vector<int>& a) {
	vector<int> res(a.size());
	for (int i = 0; i < a.size(); ++i) {
		res[a[i]] = i;
	}
	return res;
}

vector<int> solveBrute(vector<int> a, vector<int> b) {
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	vector<int> res(n);
	for (int shift = 0; shift < n; ++shift) {
		int best = n;
		for (int i = 0; i < n; ++i) {
			int x = posa[i];
			int y = (posb[i] - shift + n) % n;
			int cur = abs(x - y);
			best = min(best, cur);
		}
		res[shift] = best;
	}
	return res;
}

int _n, _shift;

struct Element {
	int x0;
	int x1;
	Element(int x0, int x1) : x0(x0), x1(x1) {
	}
	bool operator < (const Element& other) const {
		int d1 = getDev();
		int d2 = other.getDev();
		if (d1 != d2) {
			return d1 < d2;
		}
		return x0 < other.x0;
	}
	bool operator == (const Element& other) const {
		return x0 == other.x0 && x1 == other.x1;
	}
	int getDev() const {
		return (x1 + _shift) % _n - x0;
	}
};

void addElement(const Element& e, set<Element>& pos, set<Element>& neg) {
	int dev = e.getDev();
	if (dev >= 0) {
		pos.insert(e);
	} else {
		neg.insert(e);
	}
}

int getOptimalDev(set<Element>& pos, set<Element>& neg) {
	int res = _n;
	if (!pos.empty()) {
		res = min(res, pos.begin()->getDev());
	}
	if (!neg.empty()) {
		res = min(res, -(--neg.end())->getDev());
	}
	return res;
}

void removeElement(Element& e, set<Element>& pos, set<Element>& neg) {
	set<Element>::iterator it = pos.find(e);
	if (it != pos.end() && *it == e) {
		pos.erase(it);
	} else {
		it = neg.find(e);
		neg.erase(it);
	}
}

vector<int> solve(vector<int> a, vector<int> b) {
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	_n = n;
	_shift = 0;
	set<Element> neg;
	set<Element> pos;
	for (int i = 0; i < n; ++i) {
		Element e(posa[i], posb[i]);
		addElement(e, pos, neg);
	}
	vector<int> res(n);
	res[0] = getOptimalDev(pos, neg);
	vector<vector<int> > moveToPos(n);
	for (int i = 0; i < n; ++i) {
		if (posa[i] != 0) {
			moveToPos[(posa[i] - posb[i] + n) % n].push_back(i);
		}
	}
	for (int i = 1; i < n; ++i) {
		{
			int x = b[n - i];
			Element e(posa[x], posb[x]);
			removeElement(e, pos, neg);
		}
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			removeElement(e, pos, neg);
		}
		_shift = i;
		{
			int x = b[n - i];
			Element e(posa[x], posb[x]);
			addElement(e, pos, neg);
		}
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			addElement(e, pos, neg);
		}
		res[i] = getOptimalDev(pos, neg);
	}
	return res;
}

int main() {
	if (false) {
		for (int seed = 2; seed < 200; ++seed) {
			srand(seed);
			int n = 200;
			vector<int> a(n);
			vector<int> b(n);
			for (int i = 0; i < n; ++i) {
				a[i] = b[i] = i;
			}
			random_shuffle(a.begin(), a.end());
			random_shuffle(b.begin(), b.end());
			vector<int> r1 = solveBrute(a, b);
			vector<int> r2 = solve(a, b);
			if (r1 == r2) {
				cout << ".";
			} else {
				cout << seed << endl;
				break;
			}
		}
		return 0;
	}
	int n = nextInt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nextInt() - 1;
	}
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		b[i] = nextInt() - 1;
	}
	vector<int> res = solveBrute(a, b);
	for (int i = 0; i < res.size(); ++i) {
		cout << res[i] << endl;
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <numeric>
#include <ctime>
#include <climits>
using namespace std;

int nextInt() {
	int x;
	scanf("%d", &x);
	return x;
}

long long nextLong() {
	long long x;
	scanf("%I64d", &x);
	return x;
}

double nextDouble() {
	double x;
	scanf("%lf", &x);
	return x;
}

const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
	scanf("%s", buf);
	return buf;
}
string nextLine() {
	gets(buf);
	return buf;
}

int stringToInt(string s) {
	stringstream in(s);
	int x;
	in >> x;
	return x;
}

struct Point {
	typedef double T;
	T x, y;
	Point () : x(0), y(0) {}
	Point (T x, T y) : x(x), y(y) {}
	Point operator - (Point op) const { return Point(x - op.x, y - op.y); }
	Point operator + (Point op) const { return Point(x + op.x, y + op.y); }
	Point operator * (T op) const { return Point(x * op, y * op); }
	T operator * (Point op) const { return x * op.x + y * op.y; }
	T operator % (Point op) const { return x * op.y - y * op.x; }
	T length2() { return x * x + y * y; }
	double length() { return sqrt(length2()); }
};

Point nextPoint() {
	double x = nextDouble();
	double y = nextDouble();
	return Point(x, y);
}

typedef vector<vector<int> > Adj;

vector<int> getPos(vector<int>& a) {
	vector<int> res(a.size());
	for (int i = 0; i < a.size(); ++i) {
		res[a[i]] = i;
	}
	return res;
}

vector<int> solveBrute(vector<int> a, vector<int> b) {
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	vector<int> res(n);
	for (int shift = 0; shift < n; ++shift) {
		int best = n;
		for (int i = 0; i < n; ++i) {
			int x = posa[i];
			int y = (posb[i] + shift) % n;
			int cur = abs(x - y);
			best = min(best, cur);
		}
		res[shift] = best;
	}
	return res;
}

int _n, _shift;

struct Element {
	int x0;
	int x1;
	Element(int x0, int x1) : x0(x0), x1(x1) {
	}
	bool operator < (const Element& other) const {
		int d1 = getDev();
		int d2 = other.getDev();
		if (d1 != d2) {
			return d1 < d2;
		}
		return x0 < other.x0;
	}
	bool operator == (const Element& other) const {
		return x0 == other.x0 && x1 == other.x1;
	}
	int getDev() const {
		return (x1 + _shift) % _n - x0;
	}
};

void addElement(const Element& e, set<Element>& pos, set<Element>& neg) {
	int dev = e.getDev();
	if (dev >= 0) {
		pos.insert(e);
	} else {
		neg.insert(e);
	}
}

int getOptimalDev(set<Element>& pos, set<Element>& neg) {
	int res = _n;
	if (!pos.empty()) {
		res = min(res, pos.begin()->getDev());
	}
	if (!neg.empty()) {
		res = min(res, -(--neg.end())->getDev());
	}
	return res;
}

void removeElement(Element& e, set<Element>& pos, set<Element>& neg) {
	set<Element>::iterator it = pos.find(e);
	if (it != pos.end() && *it == e) {
		pos.erase(it);
	} else {
		it = neg.find(e);
		neg.erase(it);
	}
}

vector<int> solve(vector<int> a, vector<int> b) {
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	_n = n;
	_shift = 0;
	set<Element> neg;
	set<Element> pos;
	for (int i = 0; i < n; ++i) {
		Element e(posa[i], posb[i]);
		addElement(e, pos, neg);
	}
	vector<int> res(n);
	res[0] = getOptimalDev(pos, neg);
	vector<vector<int> > moveToPos(n);
	for (int i = 0; i < n; ++i) {
		if (posa[i] != 0) {
			moveToPos[(posa[i] - posb[i] + n) % n].push_back(i);
		}
	}
	for (int i = 1; i < n; ++i) {
		{
			int x = b[n - i];
			Element e(posa[x], posb[x]);
			removeElement(e, pos, neg);
		}
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			removeElement(e, pos, neg);
		}
		_shift = i;
		{
			int x = b[n - i];
			Element e(posa[x], posb[x]);
			addElement(e, pos, neg);
		}
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			addElement(e, pos, neg);
		}
		res[i] = getOptimalDev(pos, neg);
	}
	return res;
}

int main() {
	if (false) {
		for (int seed = 2; seed < 200; ++seed) {
			srand(seed);
			int n = 200;
			vector<int> a(n);
			vector<int> b(n);
			for (int i = 0; i < n; ++i) {
				a[i] = b[i] = i;
			}
			random_shuffle(a.begin(), a.end());
			random_shuffle(b.begin(), b.end());
			vector<int> r1 = solveBrute(a, b);
			vector<int> r2 = solve(a, b);
			if (r1 == r2) {
				cout << ".";
			} else {
				cout << seed << endl;
				break;
			}
		}
		return 0;
	}
	int n = nextInt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nextInt() - 1;
	}
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		b[i] = nextInt() - 1;
	}
	vector<int> res = solve(a, b);
	for (int i = 0; i < res.size(); ++i) {
		cout << res[i] << endl;
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <numeric>
#include <ctime>
#include <climits>
using namespace std;

int nextInt() {
	int x;
	scanf("%d", &x);
	return x;
}

long long nextLong() {
	long long x;
	scanf("%I64d", &x);
	return x;
}

double nextDouble() {
	double x;
	scanf("%lf", &x);
	return x;
}

const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
	scanf("%s", buf);
	return buf;
}
string nextLine() {
	gets(buf);
	return buf;
}

int stringToInt(string s) {
	stringstream in(s);
	int x;
	in >> x;
	return x;
}

struct Point {
	typedef double T;
	T x, y;
	Point () : x(0), y(0) {}
	Point (T x, T y) : x(x), y(y) {}
	Point operator - (Point op) const { return Point(x - op.x, y - op.y); }
	Point operator + (Point op) const { return Point(x + op.x, y + op.y); }
	Point operator * (T op) const { return Point(x * op, y * op); }
	T operator * (Point op) const { return x * op.x + y * op.y; }
	T operator % (Point op) const { return x * op.y - y * op.x; }
	T length2() { return x * x + y * y; }
	double length() { return sqrt(length2()); }
};

Point nextPoint() {
	double x = nextDouble();
	double y = nextDouble();
	return Point(x, y);
}

typedef vector<vector<int> > Adj;

vector<int> getPos(vector<int>& a) {
	vector<int> res(a.size());
	for (int i = 0; i < a.size(); ++i) {
		res[a[i]] = i;
	}
	return res;
}

vector<int> solveBrute(vector<int> a, vector<int> b) {
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	vector<int> res(n);
	for (int shift = 0; shift < n; ++shift) {
		int best = n;
		for (int i = 0; i < n; ++i) {
			int x = posa[i];
			int y = (posb[i] - shift + n) % n;
			int cur = abs(x - y);
			best = min(best, cur);
		}
		res[shift] = best;
	}
	return res;
}

int _n, _shift;

struct Element {
	int x0;
	int x1;
	Element(int x0, int x1) : x0(x0), x1(x1) {
	}
	bool operator < (const Element& other) const {
		int d1 = getDev();
		int d2 = other.getDev();
		if (d1 != d2) {
			return d1 < d2;
		}
		return x0 < other.x0;
	}
	bool operator == (const Element& other) const {
		return x0 == other.x0 && x1 == other.x1;
	}
	int getDev() const {
		return (x1 + _shift) % _n - x0;
	}
};

void addElement(const Element& e, set<Element>& pos, set<Element>& neg) {
	int dev = e.getDev();
	if (dev >= 0) {
		pos.insert(e);
	} else {
		neg.insert(e);
	}
}

int getOptimalDev(set<Element>& pos, set<Element>& neg) {
	int res = _n;
	if (!pos.empty()) {
		res = min(res, pos.begin()->getDev());
	}
	if (!neg.empty()) {
		res = min(res, -(--neg.end())->getDev());
	}
	return res;
}

void removeElement(Element& e, set<Element>& pos, set<Element>& neg) {
	set<Element>::iterator it = pos.find(e);
	if (it != pos.end() && *it == e) {
		pos.erase(it);
	} else {
		it = neg.find(e);
		neg.erase(it);
	}
}

vector<int> solve(vector<int> a, vector<int> b) {
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	_n = n;
	_shift = 0;
	set<Element> neg;
	set<Element> pos;
	for (int i = 0; i < n; ++i) {
		Element e(posa[i], posb[i]);
		addElement(e, pos, neg);
	}
	vector<int> res(n);
	res[0] = getOptimalDev(pos, neg);
	vector<vector<int> > moveToPos(n);
	for (int i = 0; i < n; ++i) {
		if (posa[i] != 0) {
			moveToPos[(posa[i] - posb[i] + n) % n].push_back(i);
		}
	}
	for (int i = 1; i < n; ++i) {
		{
			int x = b[n - i];
			Element e(posa[x], posb[x]);
			removeElement(e, pos, neg);
		}
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			removeElement(e, pos, neg);
		}
		_shift = i;
		{
			int x = b[n - i];
			Element e(posa[x], posb[x]);
			addElement(e, pos, neg);
		}
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			addElement(e, pos, neg);
		}
		res[i] = getOptimalDev(pos, neg);
	}
	return res;
}

int main() {
	if (false) {
		for (int seed = 2; seed < 200; ++seed) {
			srand(seed);
			int n = 200;
			vector<int> a(n);
			vector<int> b(n);
			for (int i = 0; i < n; ++i) {
				a[i] = b[i] = i;
			}
			random_shuffle(a.begin(), a.end());
			random_shuffle(b.begin(), b.end());
			vector<int> r1 = solveBrute(a, b);
			vector<int> r2 = solve(a, b);
			if (r1 == r2) {
				cout << ".";
			} else {
				cout << seed << endl;
				break;
			}
		}
		return 0;
	}
	int n = nextInt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nextInt() - 1;
	}
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		b[i] = nextInt() - 1;
	}
	vector<int> res = solve(a, b);
	for (int i = 0; i < res.size(); ++i) {
		cout << res[i] << endl;
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <numeric>
#include <ctime>
#include <climits>
using namespace std;

int nextInt() {
	int x;
	scanf("%d", &x);
	return x;
}

long long nextLong() {
	long long x;
	scanf("%I64d", &x);
	return x;
}

double nextDouble() {
	double x;
	scanf("%lf", &x);
	return x;
}

const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
	scanf("%s", buf);
	return buf;
}
string nextLine() {
	gets(buf);
	return buf;
}

int stringToInt(string s) {
	stringstream in(s);
	int x;
	in >> x;
	return x;
}

struct Point {
	typedef double T;
	T x, y;
	Point () : x(0), y(0) {}
	Point (T x, T y) : x(x), y(y) {}
	Point operator - (Point op) const { return Point(x - op.x, y - op.y); }
	Point operator + (Point op) const { return Point(x + op.x, y + op.y); }
	Point operator * (T op) const { return Point(x * op, y * op); }
	T operator * (Point op) const { return x * op.x + y * op.y; }
	T operator % (Point op) const { return x * op.y - y * op.x; }
	T length2() { return x * x + y * y; }
	double length() { return sqrt(length2()); }
};

Point nextPoint() {
	double x = nextDouble();
	double y = nextDouble();
	return Point(x, y);
}

typedef vector<vector<int> > Adj;

vector<int> getPos(vector<int>& a) {
	vector<int> res(a.size());
	for (int i = 0; i < a.size(); ++i) {
		res[a[i]] = i;
	}
	return res;
}

vector<int> solveBrute(vector<int> a, vector<int> b) {
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	vector<int> res(n);
	for (int shift = 0; shift < n; ++shift) {
		int best = n;
		for (int i = 0; i < n; ++i) {
			int x = posa[i];
			int y = (posb[i] + shift) % n;
			int cur = abs(x - y);
			best = min(best, cur);
		}
		res[shift] = best;
	}
	return res;
}

int _n, _shift;

struct Element {
	int x0;
	int x1;
	Element(int x0, int x1) : x0(x0), x1(x1) {
	}
	bool operator < (const Element& other) const {
		int d1 = getDev();
		int d2 = other.getDev();
		if (d1 != d2) {
			return d1 < d2;
		}
		return x0 < other.x0;
	}
	bool operator == (const Element& other) const {
		return x0 == other.x0 && x1 == other.x1;
	}
	int getDev() const {
		return (x1 + _shift) % _n - x0;
	}
};

void addElement(const Element& e, set<Element>& pos, set<Element>& neg) {
	int dev = e.getDev();
	if (dev >= 0) {
		pos.insert(e);
	} else {
		neg.insert(e);
	}
}

int getOptimalDev(set<Element>& pos, set<Element>& neg) {
	int res = _n;
	if (!pos.empty()) {
		res = min(res, pos.begin()->getDev());
	}
	if (!neg.empty()) {
		res = min(res, -(--neg.end())->getDev());
	}
	return res;
}

void removeElement(Element& e, set<Element>& pos, set<Element>& neg) {
	set<Element>::iterator it = pos.find(e);
	if (it != pos.end() && *it == e) {
		pos.erase(it);
	} else {
		it = neg.find(e);
		neg.erase(it);
	}
}

vector<int> solve(vector<int> a, vector<int> b) {
	int n = a.size();
	vector<int> posa = getPos(a);
	vector<int> posb = getPos(b);
	_n = n;
	_shift = 0;
	set<Element> neg;
	set<Element> pos;
	for (int i = 0; i < n; ++i) {
		Element e(posa[i], posb[i]);
		addElement(e, pos, neg);
	}
	vector<int> res(n);
	res[0] = getOptimalDev(pos, neg);
	vector<vector<int> > moveToPos(n);
	for (int i = 0; i < n; ++i) {
		if (posa[i] != 0) {
			moveToPos[(posa[i] - posb[i] + n) % n].push_back(i);
		}
	}
	for (int i = 1; i < n; ++i) {
		int x = b[n - i];
		Element e(posa[x], posb[x]);
		removeElement(e, pos, neg);
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			removeElement(e, pos, neg);
		}
		_shift = i;
		addElement(e, pos, neg);
		for (int j = 0; j < moveToPos[i].size(); ++j) {
			int x = moveToPos[i][j];
			Element e(posa[x], posb[x]);
			addElement(e, pos, neg);
		}
		res[i] = getOptimalDev(pos, neg);
	}
	return res;
}

int main() {
	if (false) {
		for (int seed = 2; seed < 10; ++seed) {
			srand(seed);
			int n = 3;
			vector<int> a(n);
			vector<int> b(n);
			for (int i = 0; i < n; ++i) {
				a[i] = b[i] = i;
			}
			random_shuffle(a.begin(), a.end());
			random_shuffle(b.begin(), b.end());
			vector<int> r1 = solveBrute(a, b);
			vector<int> r2 = solve(a, b);
			if (r1 == r2) {
				cout << ".";
			} else {
				cout << seed << endl;
				break;
			}
		}
		return 0;
	}
	int n = nextInt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nextInt() - 1;
	}
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		b[i] = nextInt() - 1;
	}
	vector<int> res = solve(a, b);
	for (int i = 0; i < res.size(); ++i) {
		cout << res[i] << endl;
	}
	return 0;
}