#include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #define debug(x) cerr << #x << " = " << x << endl; #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 100010 struct LazySeg_sum{ struct Data{ ll val; ll add; ll sum; bool valset; ll calc_sum(int l, int r){ if(valset){ return (val + add) * (r - l + 1); }else{ return sum + add * (r - l + 1); } } void set_data(int x,int y){ val = x; add = 0; valset = true; } Data():val(0),add(0),sum(0),valset(false){} }; vector data; int seg_size; LazySeg_sum(int n){ for(seg_size=1; seg_size < n; seg_size*=2); data.assign(seg_size*2, Data()); } ll set(int a, int b, ll x, int l=0, int r=-1,int k = 0){ if(r == -1) r = seg_size-1; if(a <= l && r <= b){ data[k].set_data(x,0); return data[k].calc_sum(l,r); } if(r < a || b < l) return data[k].calc_sum(l,r); if(data[k].valset){ data[k*2+1].set_data(data[k].val,data[k].add); data[k*2+2].set_data(data[k].val,data[k].add); } data[k].add = 0; data[k].valset = false; data[k].sum = set(a,b,x,l,(l+r)/2,k*2+1) + set(a,b,x,(l+r)/2+1,r,k*2+2); return data[k].calc_sum(l,r); } ll add(int a, int b, ll x, int l=0, int r=-1, int k = 0){ if(r == -1) r = seg_size-1; if(a <= l && r <= b){ data[k].add += x; return data[k].calc_sum(l,r); } if(r < a || b < l) return 0; if(data[k].valset){ data[k*2+1].set_data(data[k].val,0); data[k*2+2].set_data(data[k].val,0); data[k].valset = false; } data[k].sum = add(a,b,x,l,(l+r)/2,k*2+1) + add(a,b,x,(l+r)/2+1,r,k*2+2); return data[k].calc_sum(l,r); } ll query(int a, int b, int l=0, int r=-1, int k = 0){ if(r == -1) r = seg_size-1; if(r < a || b < l) return 0; if((a <= l && r <= b) || data[k].valset){ return data[k].calc_sum(max(a,l),min(b,r)); } return query(a,b,l,(l+r)/2,k*2+1) + query(a,b,(l+r)/2+1,r,k*2+2) + data[k].add * (min(b,r) - max(a,l) + 1); } }; int main(){ int n,q; int base = INF; ll A = 0, B = 0; scanf("%d%d",&n,&q); LazySeg_sum seg(n); for(int i=0;i b ) A += a; if( b > a ) B += b; } // debug(seg.query(0,INF)); } ll val = seg.query(0,INF); A += val%base; B += val/base; printf("%lld %lld\n",A,B); return 0; }