#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long mo = 998244353;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
long long power(long long a, long long n) {
  long long sum = 1;
  while (n) {
    if (n & 1) sum = sum * a % mo;
    n >>= 1;
    a = a * a % mo;
  }
  return sum;
}
int n, m, k;
long long a[maxn], c[maxn], num[maxn], tmp[maxn], fg[maxn];
long long id[maxn], pos[maxn];
long long sz, cnt, sum, up, down, ans;
long long lx1[maxn], lx2[maxn], rx1[maxn], rx2[maxn];
int lb(int x) { return x & (-x); }
struct node {
  long long dis;
  int id;
  bool operator<(node aa) const { return dis < aa.dis; }
};
multiset<node> p, q;
multiset<node>::iterator it, itt;
int main() {
  int T, cas = 1;
  scanf("%d", &n);
  int ld = 1, lu = 0, rd = 1, ru = 0;
  int cnt = 1;
  down = 0;
  ans = n + 1;
  for (register int i = (1); i <= (n); i++) {
    scanf("%lld", &a[i]);
    pos[a[i]] = i;
  }
  for (register int i = (1); i <= (n); i++) {
    scanf("%lld", &c[i]);
    if (i <= pos[c[i]]) {
      fg[i] = pos[c[i]] - i;
      q.insert(node{pos[c[i]] - i, i});
      ans = min(ans, pos[c[i]] - i);
      tmp[i] = 1;
    } else {
      fg[i] = i - pos[c[i]];
      p.insert(node{i - pos[c[i]], i});
      ans = min(ans, i - pos[c[i]]);
      tmp[i] = 2;
    }
  }
  printf("%lld\n", ans);
  long long tim = 0;
  for (register int i = (2); i <= (n); i++) {
    tim++;
    cnt = tim;
    if (n == pos[c[cnt]]) {
      fg[cnt] = -tim;
      q.insert(node{-tim, cnt});
    } else {
      fg[cnt] = tim + (long long)n - pos[c[cnt]];
      p.insert(node{tim + (long long)n - pos[c[cnt]], cnt});
    }
    it = p.begin();
    long long ans = n + 1;
    if (it != p.end()) ans = min(ans, (*it).dis - tim);
    while (!p.empty()) {
      it = p.begin();
      if ((*it).dis == tim) {
        q.insert(node{-tim, (*it).id});
        fg[(*it).id] = -tim;
        p.erase(it);
      } else
        break;
    }
    while (!q.empty() && ((*q.begin()).dis != fg[(*q.begin()).id])) {
      it = q.begin();
      q.erase(it);
    }
    if (!q.empty()) ans = min(ans, (*q.begin()).dis + tim);
    printf("%lld\n", ans);
  }
  return 0;
}
