Super Chorus

Time Limit : 3 Second

Memory Limit : 128 MB

Submission: 534

Solved: 68

Description
Song is the leader of HUST chorus team. 3 second before a chorus competition he found his team which was already been arranged in a line was out of order, so he decided to eliminate some people to make sure that those m remaining students are bilateral symmetric in height and gender.(The ith person and the (m-i+1)th person have the same height and gender.) The person in the middle was the tallest and the height strictly decreased from the middle to both sides.(If m is a even number ,then the person in the middle refers to the m/2th and (m/2+1)th student.) However, it was too difficult for him so he asked for your help.
Input
Multiple cases, end with EOF. Each case's first line is a positive integer n(0 < n <= 3000) which means the length of the chorus team. n lines followed and each line has two numbers, Hi and Gi. Hi is the height of the ist person.(measured by mm,100<=Hi<=1900) Gi is the gender of the the ist person. Gi=1 means male and Gi=0 means female.
Output
In each case you should output one integer indicating the max number of m.
sample input
2
1730 1
1730 1
3
1650 0
1700 1
1650 0
3
1750 0
1670 1
1750 1

sample output
2
3
1
hint
source
Hust Monthly 10.04.05/xhSong
© 2015 HUST ACMICPC TEAM. All Right Reserved.