Problem H
Hiring and Firing

Unfortunately, due to labor laws, the firing of workers must follow a last-in-first-out order: the people who have been employed the shortest time must be fired first. Furthermore, a fired person cannot be re-hired within the foreseeable future so it is not possible to circumvent the law by firing some people and then immediately re-hiring some of them.
But this story is actually about HR, not workers! Every day, one employee from the HR department is assigned to be responsible for giving the fired workers the bad news that they are fired, and for then giving the newly hired workers the good news that they are hired. In order to minimize work environment problems in the form of social awkwardness for the HR staff, a policy has been established requiring that the HR person firing an employee must always be a different HR person than the one welcoming them when they were hired.
Now the time has come for the HR department to also optimize itself, by making itself as small as possible. Unlike workers, new HR staff cannot be hired with short notice, so the HR personnel must be permanent employees. What is the smallest number of HR people needed in order to manage all the planned hirings and firings?
Input
The first line of input contains an integer
The number of workers fired on a day is never larger than
the number of currently employed workers (in other words,
Output
Output a line with an integer
Sample Input 1 | Sample Output 1 |
---|---|
4 0 3 1 1 2 1 2 0 |
3 1 2 3 2 |
Sample Input 2 | Sample Output 2 |
---|---|
6 0 10 0 5 2 0 0 0 0 100 50 100 |
2 1 2 1 2 1 2 |