#include #include #include #include typedef long long ll; #define MAX_N 112233 #define REP(i, x, n) for(i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define INF 0x7FFFFFF #define ALLOCA(type, n) ((type*)alloca(sizeof(type) * (n))) #define MALLOC(type, n) ((type*)malloc(sizeof(type) * (n))) #define CALLOC(type, n) ((type*)calloc((n), sizeof(type))) #define REALLOC(type, n, p) ((type*)realloc((p), sizeof(type) * (n))) #define MAX(a,b) a>b?a:b #define MIN(a,b) asize;q->size++;while(i > 0){long p = (i - 1) / 2;if (q->data[p]<=data){break;}q->data[i] = q->data[p];i=p;}q->data[i] = data;} long heappop(hq *q){long ret = q->data[0];q->size--;long data = q->data[q->size];long i = 0;while(i * 2 + 1 < q->size) {long a = i * 2 + 1, b = i * 2 + 2;if (b < q->size && q->data[b] < q->data[a]) {a=b;}if (q->data[a] >= data) {break;}q->data[i] = q->data[a];i=a;}q->data[i]=data;return ret;} #define SORT(h, n) qsort(h, n, sizeof(h[0]), ASC) #define RSORT(h, n) qsort(h, n, sizeof(h[0]), DESC) int ASC(const void *c1,const void *c2){int tmp1=*(int *)c1;int tmp2=*(int *)c2;if(tmp1tmp2){return 1;}} int DESC(const void *c1,const void *c2){int tmp1 = *(int *)c1;int tmp2=*(int *)c2;if(tmp1>tmp2){return -1;}if(tmp1==tmp2){return 0;}if(tmp1