#include #include using namespace std; const int maxs = 100; int c=1,g[1000][maxs+1],s[1000],p[1000],r[100010]; void del(int i, int v) { s[i]--; for (int j=v;jv;j--) g[i][j] = g[i][j-1]; s[i]++; } void just() { int n = 0; for (int i=0;i g[i][v] + p[i]) v++; mak(i,v); g[i][v] = x - p[i]; if (s[i] == maxs){ just(); } break; } } } int main() { int N; scanf ("%d",&N); while (N--){ int x,y; scanf ("%d %d",&x,&y); rem(y); add(x,y); ins(x); } int ans = 0; for (int i=0;i