#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N], b[N], who[N];
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    x--;
    a[x] = i;
  }
  multiset<int> le, ri;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
    b[i]--;
    if (i <= a[b[i]])
      le.insert(a[b[i]] - i);
    else
      ri.insert(i - a[b[i]]);
  }
  for (int step = 0; step < n; step++) {
    who[step] = b[step % n];
  }
  multiset<int>::iterator it2;
  int c1 = 0, c2 = 0, ans;
  for (int step = 0; step < n; step++, c1++, c2--) {
    ans = 1 << 30;
    if (le.size() > 0) ans = *le.begin() + c1;
    if (ri.size() > 0) ans = min(ans, *ri.begin() + c2);
    printf("%d\n", ans);
    int value = a[who[step]] - c1;
    it2 = le.find(value);
    le.erase(it2);
    int v = -1;
    if (a[who[step]] == n - 1) {
      le.insert(-c1 - 1);
    } else {
      v = n - 1 - a[who[step]] - c2 + 1;
    }
    for (auto it : ri) {
      if (it + c2 == 1) {
        le.insert(-c1 - 1);
      } else
        break;
    }
    while (ri.size() > 0 && *ri.begin() + c2 == 1) ri.erase(ri.begin());
    if (v != -1) ri.insert(v);
  }
  return 0;
}
