#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& a : A) {
    cin >> a;
    a--;
  }
  vector<int> ans;
  ans.reserve(N);
  vector<int> curString;
  curString.reserve(N);
  vector<int> maxPalEnding;
  maxPalEnding.reserve(N + 1);
  vector<int> numSuffFolds;
  numSuffFolds.reserve(N + 1);
  vector<int> minPalStarting;
  minPalStarting.reserve(N);
  vector<int> maxPalCenter;
  maxPalCenter.reserve(N + 1);
  maxPalEnding.push_back(0);
  numSuffFolds.push_back(0);
  maxPalCenter.push_back(0);
  vector<pair<int, int>> minPalStartingUpdates;
  minPalStartingUpdates.reserve(N);
  auto addChar = [&](int v) {
    int r = int(curString.size());
    int m = maxPalEnding.back();
    vector<int> minPalStartingCnds;
    {
      int nm = m;
      int nr = r + 1;
      while (nm < nr) {
        if (maxPalCenter[nm] == r - nm && 2 * nm - nr >= 0 &&
            curString[2 * nm - nr] == v) {
          maxPalCenter[nm]++;
          if (minPalStarting[2 * nm - nr] == -1) {
            minPalStartingUpdates.emplace_back(nr, 2 * nm - nr);
            minPalStarting[2 * nm - nr] = nr - nm;
          }
          break;
        }
        assert(int(minPalStarting.size()) == nm);
        minPalStarting.push_back(-1);
        minPalStartingCnds.push_back(nm);
        nm++;
        maxPalCenter.push_back(
            nm == nr ? 0 : min(r - nm, maxPalCenter[2 * m - nm]));
        assert(int(maxPalCenter.size()) == nm + 1);
        while (!minPalStartingCnds.empty() &&
               minPalStartingCnds.back() >= nm - maxPalCenter.back()) {
          int p = minPalStartingCnds.back();
          minPalStartingCnds.pop_back();
          minPalStartingUpdates.emplace_back(nr, p);
          minPalStarting[p] = nm - p;
        }
      }
      m = nm, r = nr;
    }
    curString.push_back(v);
    maxPalEnding.push_back(m);
    numSuffFolds.push_back(
        m < r ? numSuffFolds[r - minPalStarting[2 * m - r]] + 1 : 0);
  };
  int curFolds = 0;
  for (int v : A) {
    addChar(v);
    int r = int(curString.size());
    int m = maxPalEnding.back();
    if (m < r && maxPalCenter[2 * m - r] >= r - m) {
      curFolds += 2;
      int nl = 2 * m - r;
      curString.resize(nl);
      maxPalEnding.resize(nl + 1);
      numSuffFolds.resize(nl + 1);
      m = maxPalEnding[nl];
      maxPalCenter.resize(m + 1);
      maxPalCenter.back() = nl - m;
      while (!minPalStartingUpdates.empty() &&
             minPalStartingUpdates.back().first > nl) {
        minPalStarting[minPalStartingUpdates.back().second] = -1;
        minPalStartingUpdates.pop_back();
      }
      minPalStarting.resize(m);
    } else if (2 * m - r == 0) {
      curFolds++;
      vector<int> nString(curString.begin() + m, curString.end());
      curString.clear();
      maxPalEnding.clear();
      maxPalEnding.push_back(0);
      numSuffFolds.clear();
      numSuffFolds.push_back(0);
      maxPalCenter.clear();
      maxPalCenter.push_back(0);
      minPalStarting.clear();
      minPalStartingUpdates.clear();
      for (int x : nString) addChar(x);
    }
    ans.push_back(curFolds + numSuffFolds.back());
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << " \n"[i + 1 == N];
  }
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

No matter what trouble you're in, don't be afraid, but face it with a smile.

I've made another billion dollars!

— Boboniu

Boboniu has issued his currencies, named Bobo Yuan. Bobo Yuan (BBY) is a series of currencies. Boboniu gives each of them a positive integer identifier, such as BBY-1, BBY-2, etc.

Boboniu has a BBY collection. His collection looks like a sequence. For example:

<image>

We can use sequence a=[1,2,3,3,2,1,4,4,1] of length n=9 to denote it.

Now Boboniu wants to fold his collection. You can imagine that Boboniu stick his collection to a long piece of paper and fold it between currencies:

<image>

Boboniu will only fold the same identifier of currencies together. In other words, if a_i is folded over a_j (1≤ i,j≤ n), then a_i=a_j must hold. Boboniu doesn't care if you follow this rule in the process of folding. But once it is finished, the rule should be obeyed.

A formal definition of fold is described in notes.

According to the picture above, you can fold a two times. In fact, you can fold a=[1,2,3,3,2,1,4,4,1] at most two times. So the maximum number of folds of it is 2.

As an international fan of Boboniu, you're asked to calculate the maximum number of folds. 

You're given a sequence a of length n, for each i (1≤ i≤ n), you need to calculate the maximum number of folds of [a_1,a_2,…,a_i].

Input

The first line contains an integer n (1≤ n≤ 10^5).

The second line contains n integers a_1,a_2,…,a_n (1≤ a_i≤ n).

Output

Print n integers. The i-th of them should be equal to the maximum number of folds of [a_1,a_2,…,a_i].

Examples

Input


9
1 2 3 3 2 1 4 4 1


Output


0 0 0 1 1 1 1 2 2


Input


9
1 2 2 2 2 1 1 2 2


Output


0 0 1 2 3 3 4 4 5


Input


15
1 2 3 4 5 5 4 3 2 2 3 4 4 3 6


Output


0 0 0 0 0 1 1 1 1 2 2 2 3 3 0


Input


50
1 2 4 6 6 4 2 1 3 5 5 3 1 2 4 4 2 1 3 3 1 2 2 1 1 1 2 4 6 6 4 2 1 3 5 5 3 1 2 4 4 2 1 3 3 1 2 2 1 1


Output


0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 4 4 4 5 5 6 7 3 3 3 4 4 4 4 3 3 4 4 4 4 4 5 5 5 5 6 6 6 7 7 8

Note

Formally, for a sequence a of length n, let's define the folding sequence as a sequence b of length n such that:

  * b_i (1≤ i≤ n) is either 1 or -1. 
  * Let p(i)=[b_i=1]+∑_{j=1}^{i-1}b_j. For all 1≤ i<j≤ n, if p(i)=p(j), then a_i should be equal to a_j. 



([A] is the value of boolean expression A. i. e. [A]=1 if A is true, else [A]=0).

Now we define the number of folds of b as f(b)=∑_{i=1}^{n-1}[b_i≠ b_{i+1}].

The maximum number of folds of a is F(a)=max\{ f(b)∣ b  is a folding sequence of a \}.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& a : A) {
    cin >> a;
    a--;
  }
  vector<int> ans;
  ans.reserve(N);
  vector<int> curString;
  curString.reserve(N);
  vector<int> maxPalEnding;
  maxPalEnding.reserve(N + 1);
  vector<int> numSuffFolds;
  numSuffFolds.reserve(N + 1);
  vector<int> minPalStarting;
  minPalStarting.reserve(N);
  vector<int> maxPalCenter;
  maxPalCenter.reserve(N + 1);
  maxPalEnding.push_back(0);
  numSuffFolds.push_back(0);
  maxPalCenter.push_back(0);
  vector<pair<int, int>> minPalStartingUpdates;
  minPalStartingUpdates.reserve(N);
  auto addChar = [&](int v) {
    int r = int(curString.size());
    int m = maxPalEnding.back();
    vector<int> minPalStartingCnds;
    {
      int nm = m;
      int nr = r + 1;
      while (nm < nr) {
        if (maxPalCenter[nm] == r - nm && 2 * nm - nr >= 0 &&
            curString[2 * nm - nr] == v) {
          maxPalCenter[nm]++;
          if (minPalStarting[2 * nm - nr] == -1) {
            minPalStartingUpdates.emplace_back(nr, 2 * nm - nr);
            minPalStarting[2 * nm - nr] = nr - nm;
          }
          break;
        }
        assert(int(minPalStarting.size()) == nm);
        minPalStarting.push_back(-1);
        minPalStartingCnds.push_back(nm);
        nm++;
        maxPalCenter.push_back(
            nm == nr ? 0 : min(r - nm, maxPalCenter[2 * m - nm]));
        assert(int(maxPalCenter.size()) == nm + 1);
        while (!minPalStartingCnds.empty() &&
               minPalStartingCnds.back() >= nm - maxPalCenter.back()) {
          int p = minPalStartingCnds.back();
          minPalStartingCnds.pop_back();
          minPalStartingUpdates.emplace_back(nr, p);
          minPalStarting[p] = nm - p;
        }
      }
      m = nm, r = nr;
    }
    curString.push_back(v);
    maxPalEnding.push_back(m);
    numSuffFolds.push_back(
        m < r ? numSuffFolds[r - minPalStarting[2 * m - r]] + 1 : 0);
  };
  int curFolds = 0;
  for (int v : A) {
    addChar(v);
    int r = int(curString.size());
    int m = maxPalEnding.back();
    if (m < r && maxPalCenter[2 * m - r] >= r - m) {
      curFolds += 2;
      int nl = 2 * m - r;
      curString.resize(nl);
      maxPalEnding.resize(nl + 1);
      numSuffFolds.resize(nl + 1);
      m = maxPalEnding[nl];
      maxPalCenter.resize(m + 1);
      maxPalCenter.back() = nl - m;
      while (!minPalStartingUpdates.empty() &&
             minPalStartingUpdates.back().first > nl) {
        minPalStarting[minPalStartingUpdates.back().second] = -1;
        minPalStartingUpdates.pop_back();
      }
      minPalStarting.resize(m);
    } else if (2 * m - r == 0) {
      curFolds++;
      vector<int> nString(curString.begin() + m, curString.end());
      curString.clear();
      maxPalEnding.clear();
      maxPalEnding.push_back(0);
      numSuffFolds.clear();
      numSuffFolds.push_back(0);
      maxPalCenter.clear();
      maxPalCenter.push_back(0);
      minPalStarting.clear();
      minPalStartingUpdates.clear();
      for (int x : nString) addChar(x);
    }
    ans.push_back(curFolds + numSuffFolds.back());
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << " \n"[i + 1 == N];
  }
  return 0;
}

```