#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 5, INF = 1000 * 1000 * 1000;
multiset<int> r, l;
multiset<int>::iterator it;
int a[N], b[N], adr, adl, f[N];
void print() {
  it = r.begin();
  while (it != r.end()) {
    cerr << *it + adr << " ";
    ++it;
  }
  cerr << endl;
  it = l.begin();
  while (it != l.end()) {
    cerr << *it + adl << " ";
    ++it;
  }
  cerr << endl << "fin" << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = n; i; --i) cin >> a[i], f[a[i]] = i;
  for (int i = n; i; --i) {
    cin >> b[i];
    if (f[b[i]] > i)
      r.insert(f[b[i]] - i);
    else
      l.insert(i - f[b[i]]);
  }
  r.insert(INF);
  l.insert(INF);
  for (int i = 0; i < n; ++i) {
    cout << min(*r.begin() + adr, *l.begin() + adl) << '\n';
    --adr;
    ++adl;
    while ((int)(r).size() && !(*r.begin() + adr)) {
      r.erase(r.begin());
      l.insert(-adl);
    }
    it = l.find(n - f[b[n - i]] - adl + 1);
    l.erase(it);
    if (f[b[n - i]] > 1)
      r.insert(f[b[n - i]] - 1 - adr);
    else
      l.insert(-adl);
  }
  return 0;
}
