#include #define fo(i,a,b) for(int i=a;i<=b;++i) #define fod(i,a,b) for(int i=a;i>=b;--i) #define max(q,w) ((q)>(w)?(q):(w)) #define min(q,w) ((q)<(w)?(q):(w)) using namespace std; typedef long long LL; const int N=200500,INF=1e9; int read(int &n) { int q=1;n=0;char ch=' '; for(;ch!='-'&&(ch<'0'||ch>'9');ch=getchar()); if(ch=='-')q=-1,ch=getchar(); for(;ch<='9'&&ch>='0';ch=getchar())n=(n<<1)+(n<<3)+ch-48; return n; } int n,m; int a[N][3]; int p[N],z[N]; LL ans; bool PX(int q,int w){return a[q][0]