#include <bits/stdc++.h>
using namespace std;
int n, a[1000007], b[1000007], pos1[1000007], pos2[1000007];
multiset<int>::iterator it;
multiset<int> S;
int main() {
  int i, res;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    pos1[a[i]] = i;
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    pos2[b[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    S.insert(pos2[i] - pos1[i]);
  }
  for (i = 0; i < n; i++) {
    it = S.lower_bound(i);
    res = n;
    if (it != S.end()) {
      res = *it - i;
    }
    if (it != S.begin()) {
      --it;
      res = min(res, i - *it);
    }
    cout << res << endl;
    it = S.find(pos2[b[i]] - pos1[b[i]]);
    S.erase(it);
    S.insert(n + pos2[b[i]] - pos1[b[i]]);
  }
  return 0;
}
