PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000212. Đồ thị sắp xếp nổi bọt (Bubble Sort Graph)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đồ thị sắp xếp nổi bọt (Bubble Sort Graph)

Bubble Sort Graph

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Iahub starts with a permutation a1,a2,…,ana_1,a_2,\ldots,a_n of the integers from 11 to nn. The undirected graph GG initially has vertices labeled 11 through nn and no edges.

During each bubble-sort pass, visit positions i=1,2,…,n−1i=1,2,\ldots,n-1 in order. Whenever ai>ai+1a_i>a_{i+1}, add an undirected edge between vertices labeled aia_i and ai+1a_{i+1}, then swap these two elements. Repeat until a pass makes no swaps.

An independent set contains no pair of vertices connected by an edge. Determine the maximum size of an independent set in the resulting graph.

Input

The first line contains an integer nn. The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, a permutation of 1,2,…,n1,2,\ldots,n.

Output

Print one integer: the maximum size of an independent set.

Subtasks

  • Subtask 1 (20 points): 2≤n≤302\le n\le 30; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; all values are distinct.
  • Subtask 2 (30 points): 2≤n≤10002\le n\le 1000; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; all values are distinct.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; all values are distinct.

Examples

Input

3
3 1 2

Output

2

Explanation

Swapping 33 with 11 adds edge (3,1)(3,1); swapping 33 with 22 adds (3,2)(3,2). The permutation becomes [1,2,3][1,2,3]. Vertices 1,21,2 are nonadjacent, but adding 33 would violate independence.

Input

4
4 3 2 1

Output

1

Explanation

Every pair begins in decreasing order and reverses its relative order during sorting, producing an edge. An independent set can contain only one vertex.