#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = -1u / 2;
int n;
int a[N], b[N], c[N];
struct xxx {
  int t, x;
  xxx() {}
  xxx(int _t, int _x) {
    t = _t;
    x = _x;
  }
  inline bool operator<(const xxx &a) const {
    return t != a.t ? t > a.t : x < a.x;
  }
};
set<xxx> l, r;
int v[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (i <= a[b[i]]) {
      v[b[i]] = i - a[b[i]];
      l.insert(xxx(v[b[i]], b[i]));
    } else {
      v[b[i]] = a[b[i]] - i;
      r.insert(xxx(v[b[i]], b[i]));
    }
  }
  for (int i = 0; i < n; i++) {
    int ans = inf;
    if (l.size() > 0) {
      ans = min(ans, i - (l.begin()->t));
    }
    if (r.size() > 0) {
      ans = min(ans, -(r.begin()->t) - i);
    }
    printf("%d\n", ans);
    int z = b[i + 1];
    l.erase(l.find(xxx(v[z], z)));
    v[z] = -i - n + a[z] - 1;
    r.insert(xxx(v[z], z));
    while (r.size() > 0 and -(r.begin()->t) - i == 1) {
      int k = r.begin()->x;
      r.erase(r.begin());
      v[k] = i + 1;
      l.insert(xxx(v[k], k));
    }
  }
}
