Under construction

Still being built. Things may change

Matryoshka Dolls

Time limit1sMemory limit128 MB

Summary
Given doll heights, nest each doll inside a strictly taller doll, each holding at most one, to minimize the number of outermost dolls.
Level

Easy3 of 10

Topics
Greedy, Sorting, Two pointers
Solved
No attempts yet

Problem

Adam received a box full of Matryoshka dolls (a traditional Russian nesting doll) from his friend Matryona. Every doll has a hollow bottom, so one doll can hold exactly one smaller doll directly inside it.

All the dolls have the same shape but different sizes. Doll ii is described by a single number hih_i, its height. Doll ii fits directly inside doll jj if and only if hi<hjh_i < h_j, and each doll may contain at most one doll immediately inside it (that inner doll may in turn hold another doll, forming a nested stack).

Adam wants to nest the dolls so that the number of outermost dolls (dolls that are inside no other doll) is as small as possible. Given the heights of all the dolls, compute this minimum possible number of outermost dolls.

Input

The input consists of multiple test cases. Each test case begins with a line containing an integer NN (1≤N≤1051 \le N \le 10^5), the number of dolls. Each of the next NN lines contains one integer hih_i (1≤hi≤1091 \le h_i \le 10^9), the height of the ii-th doll in centimeters. The input ends with a line containing N=0N = 0, which must not be processed.

Output

For each test case, print a single line containing the minimum possible number of outermost dolls after nesting the dolls optimally.

Examples3

  1. Example 1

    Input
    4
    5
    7
    7
    3
    3
    10
    10
    10
    3
    10
    999999999
    100000000
    0
    
    Expected output
    2
    3
    1
    
  2. Example 2

    Input
    1
    42
    0
    
    Expected output
    1
    
  3. Example 3

    Input
    5
    7
    7
    7
    7
    7
    0
    
    Expected output
    5