#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 17;
struct elem {
  int idx, value;
  elem(){};
  elem(int _idx, int _value) {
    idx = _idx;
    value = _value;
  }
  bool operator<(const elem &t1) const { return value > t1.value; }
};
int N;
priority_queue<elem> q1, q2;
int b[MAXN], position[MAXN];
int out[MAXN];
void scan() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    int x;
    scanf("%d", &x);
    position[x] = i;
  }
  for (int i = 1; i <= N; ++i) scanf("%d", b + i);
}
void solve() {
  int delta = 0;
  q1.push(elem(1e9, 1e9));
  q2.push(elem(1e9, 1e9));
  for (int i = 1; i <= N; ++i)
    if (i > position[b[i]])
      q1.push(elem(i, i - position[b[i]]));
    else
      q2.push(elem(i, position[b[i]] - i));
  printf("%d\n", min(q1.top().value, q2.top().value));
  for (int i = 1; i < N; ++i) {
    ++delta;
    out[i] = 1;
    q1.push(elem(i, N - position[b[i]] + delta));
    while (q1.top().value - delta == 0) {
      q2.push(elem(q1.top().idx, -delta));
      out[q1.top().idx] = 0;
      q1.pop();
    }
    while (out[q2.top().idx]) q2.pop();
    printf("%d\n", min(q1.top().value - delta, q2.top().value + delta));
  }
}
int main() {
  scan();
  solve();
}
