Problem Description
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.
The game can be played by two Z喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vciBtb3JlIHRoYW4gdHdvIHBsYXllcnMuIEl0IGNvbnNpc3RzIG9mIGEgY2hlc3Nib2FyZKOoxuXFzKOpYW5kIHNvbWUgY2hlc3NtZW6jqMbl19OjqSwgYW5kIGFsbCBjaGVzc21lbiBhcmUgbWFya2VkIGJ5IGEgcG9zaXRpdmUgaW50ZWdlciBvciChsHN0YXJ0obEgb3IgobBlbmShsS4gVGhlIHBsYXllciBzdGFydHMgZnJvbSBzdGFydC1wb2ludCBhbmQgbXVzdCBqdW1wcyBpbnRvIGVuZC1wb2ludCBmaW5hbGx5LiBJbgogdGhlIGNvdXJzZSBvZiBqdW1waW5nLCB0aGUgcGxheWVyIHdpbGwgdmlzaXQgdGhlIGNoZXNzbWVuIGluIHRoZSBwYXRoLCBidXQgZXZlcnlvbmUgbXVzdCBqdW1wcyBmcm9tIG9uZSBjaGVzc21hbiB0byBhbm90aGVyIGFic29sdXRlbHkgYmlnZ2VyICh5b3UgY2FuIGFzc3VtZSBzdGFydC1wb2ludCBpcyBhIG1pbmltdW0gYW5kIGVuZC1wb2ludCBpcyBhIG1heGltdW0uKS4gQW5kIGFsbCBwbGF5ZXJzIGNhbm5vdCBnbyBiYWNrd2FyZHMuIE9uZSBqdW1waW5nCiBjYW4gZ28gZnJvbSBhIGNoZXNzbWFuIHRvIG5leHQsIGFsc28gY2FuIGdvIGFjcm9zcyBtYW55IGNoZXNzbWVuLCBhbmQgZXZlbiB5b3UgY2FuIHN0cmFpZ2h0bHkgZ2V0IHRvIGVuZC1wb2ludCBmcm9tIHN0YXJ0LXBvaW50LiBPZiBjb3Vyc2UgeW91IGdldCB6ZXJvIHBvaW50IGluIHRoaXMgc2l0dWF0aW9uLiBBIHBsYXllciBpcyBhIHdpbm5lciBpZiBhbmQgb25seSBpZiBoZSBjYW4gZ2V0IGEgYmlnZ2VyIHNjb3JlIGFjY29yZGluZyB0byBoaXMKIGp1bXBpbmcgc29sdXRpb24uIE5vdGUgdGhhdCB5b3VyIHNjb3JlIGNvbWVzIGZyb20gdGhlIHN1bSBvZiB2YWx1ZSBvbiB0aGUgY2hlc3NtZW4gaW4geW91IGp1bXBpbmcgcGF0aC48YnI+CllvdXIgdGFzayBpcyB0byBvdXRwdXQgdGhlIG1heGltdW0gdmFsdWUgYWNjb3JkaW5nIHRvIHRoZSBnaXZlbiBjaGVzc21lbiBsaXN0Ljxicj4KCgogCjxicj4KCklucHV0CgpJbnB1dCBjb250YWlucyBtdWx0aXBsZSB0ZXN0IGNhc2VzLiBFYWNoIHRlc3QgY2FzZSBpcyBkZXNjcmliZWQgaW4gYSBsaW5lIGFzIGZvbGxvdzo8YnI+Ck4gdmFsdWVfMSB2YWx1ZV8yIKGtdmFsdWVfTiA8YnI+Ckl0IGlzIGd1YXJhbnRpZWQgdGhhdCBOIGlzIG5vdCBtb3JlIHRoYW4gMTAwMCBhbmQgYWxsIHZhbHVlX2kgYXJlIGluIHRoZSByYW5nZSBvZiAzMi1pbnQuPGJyPgpBIHRlc3QgY2FzZSBzdGFydGluZyB3aXRoIDAgdGVybWluYXRlcyB0aGUgaW5wdXQgYW5kIHRoaXMgdGVzdCBjYXNlIGlzIG5vdCB0byBiZSBwcm9jZXNzZWQuPGJyPgoKCiAKPGJyPgoKT3V0cHV0CgpGb3IgZWFjaCBjYXNlLCBwcmludCB0aGUgbWF4aW11bSBhY2NvcmRpbmcgdG8gcnVsZXMsIGFuZCBvbmUgbGluZSBvbmUgY2FzZS48YnI+CgoKIAo8YnI+CgpTYW1wbGUgSW5wdXQKCjxwcmUgY2xhc3M9"brush:java;">3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3
#include
using namespace std;
int *s;
int *p;
int main()
{
freopen("C:\\in.txt","r",stdin);
int n;
while(scanf("%d",&n)!=EOF&&n){
s=new int[n];
p=new int[n];
int max=0;
for(int i=0;is[j]){
if(p[i]