#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, ls, rs, val;
};
static struct node a[2 * 300005];
void ChangeNode(int point, int what, int how) {
  if (a[point].ls != -1) {
    if (a[a[point].ls].r >= what)
      ChangeNode(a[point].ls, what, how);
    else
      ChangeNode(a[point].rs, what, how);
  }
  a[point].val += how;
}
int FindSum(int point, int L, int R) {
  if ((a[point].l >= L) && (a[point].r <= R)) return a[point].val;
  int res = 0;
  if (a[a[point].ls].r >= L) res += FindSum(a[point].ls, L, R);
  if (a[a[point].rs].l <= R) res += FindSum(a[point].rs, L, R);
  return res;
}
int FindK(int point, int K) {
  if (a[point].ls == -1) return a[point].l;
  if (a[a[point].ls].val >= K)
    return FindK(a[point].ls, K);
  else
    return FindK(a[point].rs, K - a[a[point].ls].val);
}
int N;
int FindMin(int Z) {
  int cnt = FindSum(0, 0, Z);
  int res = N;
  int temp;
  if (cnt > 0) {
    temp = Z - FindK(0, cnt);
    if (temp < res) res = temp;
  }
  if (cnt < N) {
    temp = FindK(0, cnt + 1) - Z;
    if (temp < res) res = temp;
  }
  return res;
}
int main() {
  scanf("%d", &N);
  int r, w;
  r = 0;
  w = 1;
  a[r].l = 0;
  a[r].r = 3 * N;
  a[r].ls = -1;
  a[r].rs = -1;
  a[r].val = 0;
  while (w > r) {
    if (a[r].r > a[r].l) {
      a[w].l = a[r].l;
      a[w].r = (a[r].l + a[r].r) / 2;
      a[w].ls = -1;
      a[w].rs = -1;
      a[w].val = 0;
      a[r].ls = w;
      w++;
      a[w].l = a[w - 1].r + 1;
      a[w].r = a[r].r;
      a[w].ls = -1;
      a[w].rs = -1;
      a[w].val = 0;
      a[r].rs = w;
      w++;
    }
    r++;
  }
  int i;
  static int pa[300005];
  static int pb[300005];
  static int where[300005];
  for (i = 0; i < N; i++) {
    scanf("%d", &(pa[i]));
    where[pa[i]] = i;
  }
  int Z = N;
  for (i = 0; i < N; i++) {
    scanf("%d", &(pb[i]));
    ChangeNode(0, i - where[pb[i]] + Z, 1);
  }
  static int res[300005];
  res[0] = FindMin(Z);
  int gone, arr;
  for (i = 1; i < N; i++) {
    gone = -where[pb[i - 1]];
    arr = N - 1 - where[pb[i - 1]];
    ChangeNode(0, gone + Z, -1);
    Z++;
    ChangeNode(0, arr + Z, 1);
    res[i] = FindMin(Z);
  }
  for (i = 0; i < N; i++) printf("%d\n", res[i]);
  return 0;
}
