#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = ~0u >> 2;
int numa[N], numb[N], pos[N];
struct node {
  int val, id;
  node(int _val, int _id) { val = _val, id = _id; }
  bool operator<(const node& A) const { return val > A.val; }
};
int now[N], unuse[N];
priority_queue<node> A, B;
int __ans[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &numa[i]);
    pos[numa[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &numb[i]);
    int val = i - pos[numb[i]];
    if (val < 0)
      B.push(node(abs(val), i));
    else
      A.push(node(abs(val), i));
    now[i] = val;
  }
  int tmp = 0, len = 0;
  for (int k = n - 1; k >= 0; k--) {
    int pa = A.empty() ? inf : A.top().val + tmp;
    int pb = B.empty() ? inf : B.top().val - tmp;
    __ans[len++] = min(pa, pb);
    while (pb == 0) {
      int id = B.top().id;
      A.push(node(-tmp, id));
      B.pop();
      if (B.empty()) break;
      pb = B.top().val - tmp;
    }
    unuse[k] = 1;
    int np = pos[numb[k]];
    now[k] = -np - tmp - 1;
    while (!A.empty() && (A.top().val + tmp != abs(now[A.top().id] + tmp) &&
                          unuse[A.top().id])) {
      unuse[A.top().id] = 0;
      A.pop();
    }
    tmp++;
    if (np == 0)
      A.push(node(-tmp, k));
    else
      B.push(node(np + tmp, k));
  }
  cout << __ans[0] << endl;
  for (int i = len - 1; i; i--) printf("%d\n", __ans[i]);
}
