#include <bits/stdc++.h>
using namespace std;
multiset<int> T;
int a[102012], b[102012], f[102012], s[102012];
int N, x;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &x), a[x] = i;
  for (int i = 1; i <= N; ++i) scanf("%d", s + i), b[s[i]] = i;
  for (int i = 1; i <= N; ++i) f[i] = b[i] - a[i], T.insert(f[i]);
  T.insert(1000002012);
  for (int i = 1; i <= N; ++i) {
    multiset<int>::iterator p = T.lower_bound(i - 1);
    int Ans = abs(*p - (i - 1));
    if (p != T.begin()) {
      --p;
      Ans = min(Ans, abs(*p - (i - 1)));
    }
    printf("%d\n", Ans);
    p = T.find(f[s[i]]);
    T.erase(p);
    f[s[i]] += N;
    T.insert(f[s[i]]);
  }
  return 0;
}
