#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef long double LD; typedef vector VI; typedef pair PII; const LD eps=1e-9; const LD PI=atan2((LD)0,(LD)-1); const LL MOD=1000000007; const int INF=1<<30; const int ARR_INF=1<<6; const int MAXN=50005; struct GT { int team; int b; }gt[MAXN]; int n,m; map mp; int add[MAXN]; int Solve(int team) { int now; int killed=0; for(now=n;now>0;now--) { if(gt[now].team==team) break; } for(int i=now;i>0;i--) { if(gt[i].team==gt[now].team) { if(gt[i].b+add[i]>gt[now].b+add[now]) now=i; } else { if(gt[i].b+add[i]0;i--) add[i]=add[i+1]+mp[i]; int ans=n-Solve(0); ans-=Solve(1); printf("%d\n",ans); } return 0; }