#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[2][maxn + 1], numpos[2][maxn + 1], wz[maxn + 1], heap[2][maxn + 1],
    dy[maxn + 1], heapkind[maxn + 1], heapdelta[2], heapsize[maxn + 1],
    jl[maxn + 1], n;
vector<pair<int, int> > sj;
void init() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[0][i]);
    numpos[0][a[0][i]] = i;
  }
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[1][i]);
    numpos[1][a[1][i]] = i;
  }
}
void up(int heap[], int p) {
  int x;
  x = heap[p];
  while (p / 2 >= 1) {
    if (jl[x] < jl[heap[p / 2]]) {
      heap[p] = heap[p / 2];
      dy[heap[p]] = p;
      p /= 2;
    } else
      break;
  }
  heap[p] = x;
  dy[x] = p;
}
void down(int heap[], int heapsize, int p) {
  int x, j;
  x = heap[p];
  while (p * 2 <= heapsize) {
    j = p * 2;
    if ((j + 1 <= heapsize) && (jl[heap[j + 1]] < jl[heap[j]])) ++j;
    if (jl[x] > jl[heap[j]]) {
      heap[p] = heap[j];
      dy[heap[p]] = p;
      p = j;
    } else
      break;
  }
  heap[p] = x;
  dy[x] = p;
}
void ins(int t, int x) {
  heap[t][++heapsize[t]] = x;
  dy[x] = heapsize[t];
  wz[x] = t;
  up(heap[t], heapsize[t]);
}
void remove(int t, int x) {
  if (dy[x] == heapsize[t]) {
    --heapsize[t];
  } else {
    heap[t][dy[x]] = heap[t][heapsize[t]];
    dy[heap[t][dy[x]]] = dy[x];
    --heapsize[t];
    up(heap[t], dy[x]);
    down(heap[t], heapsize[t], dy[x]);
  }
  dy[x] = 0;
  wz[x] = -1;
}
void work() {
  int i, j, k, result, p, x;
  heapsize[0] = heapsize[1] = 0;
  heapdelta[0] = heapdelta[1] = 0;
  for (i = 1; i <= n; ++i)
    if (numpos[1][i] >= numpos[0][i]) {
      sj.push_back(pair<int, int>(numpos[1][i] - numpos[0][i] + 1, i));
      jl[i] = numpos[1][i] - numpos[0][i];
      ins(0, i);
    } else {
      sj.push_back(pair<int, int>(n - (numpos[0][i] - numpos[1][i]) + 1, i));
      jl[i] = numpos[0][i] - numpos[1][i];
      ins(1, i);
    }
  sort(sj.begin(), sj.end());
  p = 0;
  for (i = 1; i <= n; ++i) {
    result = 1000000000;
    if (heapsize[0]) result = jl[heap[0][1]] + heapdelta[0];
    if (heapsize[1])
      if (jl[heap[1][1]] + heapdelta[1] < result)
        result = jl[heap[1][1]] + heapdelta[1];
    printf("%d\n", result);
    while ((p < sj.size()) && (sj[p].first == i)) {
      x = sj[p].second;
      if (wz[x] == 0) {
        remove(0, x);
        jl[x] = jl[x] + heapdelta[0] - heapdelta[1];
        ins(1, x);
      }
      ++p;
    }
    --heapdelta[0];
    ++heapdelta[1];
    x = a[1][i];
    remove(wz[x], x);
    jl[x] = n - numpos[0][x] - heapdelta[0];
    ins(0, x);
  }
}
int main() {
  init();
  work();
  return 0;
}
