#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
    --b[i];
  }
  vector<int> posa(n), posb(n);
  for (int i = 0; i < n; ++i) {
    posa[a[i]] = i;
    posb[b[i]] = i;
  }
  multiset<int> left, right;
  for (int i = 0; i < n; ++i) {
    if (posb[i] < posa[i]) {
      left.insert(posa[i] - posb[i]);
    } else {
      right.insert(posb[i] - posa[i]);
    }
  }
  int x = 0;
  vector<int> r;
  while (x < n) {
    int ans = n + 10;
    if (!left.empty()) {
      ans = min(ans, *left.begin() - x);
    }
    if (!right.empty()) {
      ans = min(ans, *right.begin() + x);
    }
    r.push_back(ans);
    x++;
    if (x == n) {
      break;
    }
    while (!left.empty() && *left.begin() - x == 0) {
      left.erase(left.begin());
      right.insert(-x);
    }
    int e = b[n - x];
    if (posb[e] + x < posa[e]) {
      left.erase(left.find(posa[e] - posb[e]));
    } else {
      right.erase(right.find(posb[e] - posa[e]));
    }
    if ((posb[e] + x) % n < posa[e]) {
      left.insert(posa[e] - (posb[e] + x) % n + x);
    } else {
      right.insert((posb[e] + x) % n - posa[e] - x);
    }
  }
  reverse(r.begin() + 1, r.end());
  for (int x : r) {
    printf("%d\n", x);
  }
  return 0;
}
