#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  long long a[n], b[n];
  multiset<long long> m;
  map<long long, long long> ind1, ind2;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    ind1[a[i]] = i;
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    ind2[b[i]] = i;
  }
  for (long long i = 1; i <= n; i++) {
    m.insert(ind2[i] - ind1[i]);
  }
  for (long long i = 0; i < n; i++) {
    multiset<long long>::iterator it = m.lower_bound(i);
    long long u = LONG_LONG_MAX;
    if (it != m.end()) {
      u = min(u, (*it) - i);
    }
    if (it != m.begin()) {
      u = min(u, i - *(--it));
    }
    cout << u << "\n";
    m.erase(m.find(i - ind1[b[i]]));
    long long t = i - ind1[b[i]];
    m.insert(n + t);
  }
}
