火车头模板

· · 个人记录

namespace FastIO{
    constexpr int IOSIZE=1<<20;
    char ibuf[IOSIZE],obuf[IOSIZE];
    char*p1=ibuf,*p2=ibuf,*p3=obuf;
    inline char _gc(){if(p1==p2){p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);if(p1==p2)return EOF;}return*p1++;}
    inline void _pc(char c){if(p3==obuf+IOSIZE){fwrite(obuf,1,p3-obuf,stdout);p3=obuf;}*p3++=c;}
    inline bool _isdigit(char c){return c>='0'&&c<='9';}
    inline bool _isspace(char c){return c<=' ';}
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntReader{static void read(T&x){char c;while(!_isdigit(c=_gc()));x=c-'0';while(_isdigit(c=_gc()))x=x*10+(c-'0');}};
    template<typename T>struct IntReader<T,true>{static void read(T&x){char c;while(!_isdigit(c=_gc())&&c!='-');bool neg=(c=='-');if(neg)c=_gc();x=c-'0';while(_isdigit(c=_gc()))x=x*10+(c-'0');if(neg)x=-x;}};
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntWriter{static void write(T x){if(x==0){_pc('0');return;}char buf[20];int n=0;do{buf[n++]=x%10+'0';x/=10;}while(x);while(n--)_pc(buf[n]);}};
    template<typename T>struct IntWriter<T,true>{static void write(T x){if(x==0){_pc('0');return;}if(x<0){_pc('-');x=-x;}char buf[20];int n=0;do{buf[n++]=x%10+'0';x/=10;}while(x);while(n--)_pc(buf[n]);}};
    inline void read(int&x){IntReader<int>::read(x);}
    inline void read(long long&x){IntReader<long long>::read(x);}
    inline void read(unsigned int&x){IntReader<unsigned int>::read(x);}
    inline void read(unsigned long long&x){IntReader<unsigned long long>::read(x);}
    inline void read(short&x){IntReader<short>::read(x);}
    inline void read(long&x){IntReader<long>::read(x);}
    inline void read(char&x){while(_isspace(x=_gc()));}
    inline void read(bool&b){char c;while(_isspace(c=_gc()));b=(c!='0'&&c!='f');}
    inline void read(std::string&s){char c;while(_isspace(c=_gc()));s.clear();do{s+=c;}while(!_isspace(c=_gc()));}
    inline void read(char *x){char c;int k=0;while(_isspace(c=_gc()));do{x[k]=c;k++;}while(!_isspace(c=_gc()));x[k]='\0';}
    template<typename T>typename std::enable_if<std::is_floating_point<T>::value,void>::type read(T&x){char c;while(!_isdigit(c=_gc())&&c!='-'&&c!='.');bool neg=(c=='-');if(c=='-'||c=='.')c=_gc();x=0;T base=1;while(_isdigit(c)){x=x*10+(c-'0');c=_gc();}if(c=='.'){c=_gc();while(_isdigit(c)){base*=0.1;x+=(c-'0')*base;c=_gc();}}if(neg)x=-x;}
    inline void write(int x){IntWriter<int>::write(x);}
    inline void write(long long x){IntWriter<long long>::write(x);}
    inline void write(unsigned int x){IntWriter<unsigned int>::write(x);}
    inline void write(unsigned long long x){IntWriter<unsigned long long>::write(x);}
    inline void write(short x){IntWriter<short>::write(x);}
    inline void write(long x){IntWriter<long>::write(x);}
    inline void write(char x){_pc(x);}
    inline void write(const char*x){while(*x)_pc(*x++);}
    inline void write(const std::string&s){for(char c:s)_pc(c);}
    inline void write(bool b){_pc(b?'1':'0');}
    template<typename T,typename...Args>inline void read(T&x,Args&...args){read(x);read(args...);}
    template<typename T,typename...Args>inline void write(const T&x,const Args&...args){write(x);write(args...);}
    struct FastIO_{~FastIO_(){if(p3>obuf)fwrite(obuf,1,p3-obuf,stdout);}template<typename T>FastIO_& operator>>(T& x){read(x);return *this;}FastIO_& operator>>(char *x){read(x);return *this;}template<typename T>FastIO_& operator<<(const T& x){write(x);return *this;}}fio;
}using namespace FastIO;
#define cin FastIO::fio
#define cout FastIO::fio
#define endl '\n'

加固后模板:

#include<bits/stdc++.h>
using namespace std;
namespace FastIO{
    constexpr int IOSIZE=1<<30;
    char ibuf[IOSIZE],obuf[IOSIZE];
    char*p1=ibuf,*p2=ibuf,*p3=obuf;
    inline char _gc(){if(p1==p2){p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);if(p1==p2)return EOF;}return*p1++;}
    inline void _pc(char c){if(p3==obuf+IOSIZE){fwrite(obuf,1,p3-obuf,stdout);p3=obuf;}*p3++=c;}
    inline bool _isdigit(char c){return c>='0'&&c<='9';}
    inline bool _isspace(char c){return c<=' ';}
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntReader{static void read(T&x){char c;while(!_isdigit(c=_gc()));x=c-'0';while(_isdigit(c=_gc()))x=x*10+(c-'0');}};
    template<typename T>struct IntReader<T,true>{static void read(T&x){char c;while(!_isdigit(c=_gc())&&c!='-');bool neg=(c=='-');if(neg)c=_gc();x=c-'0';while(_isdigit(c=_gc()))x=x*10+(c-'0');if(neg)x=-x;}};
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntWriter{static void write(T x){if(x==0){_pc('0');return;}char buf[20];int n=0;do{buf[n++]=x%10+'0';x/=10;}while(x);while(n--)_pc(buf[n]);}};
    template<typename T>struct IntWriter<T,true>{static void write(T x){using UT=typename std::make_unsigned<T>::type;if(x==0){_pc('0');return;}UT val;if(x<0){_pc('-');val=~static_cast<UT>(x)+1u;}else val=static_cast<UT>(x);char buf[20];int n=0;do{buf[n++]=val%10+'0';val/=10;}while(val);while(n--)_pc(buf[n]);}};
    inline void read(int&x){IntReader<int>::read(x);}
    inline void read(long long&x){IntReader<long long>::read(x);}
    inline void read(unsigned int&x){IntReader<unsigned int>::read(x);}
    inline void read(unsigned long long&x){IntReader<unsigned long long>::read(x);}
    inline void read(short&x){IntReader<short>::read(x);}
    inline void read(long&x){IntReader<long>::read(x);}
    inline void read(char&x){while(_isspace(x=_gc()));}
    inline void read(bool&b){char c;while(_isspace(c=_gc()));b=(c!='0'&&c!='f');}
    inline void read(std::string&s){char c;while(_isspace(c=_gc()));s.clear();do{s+=c;}while(!_isspace(c=_gc()));}
    inline void read(char *x){char c;int k=0;while(_isspace(c=_gc()));do{x[k]=c;k++;}while(!_isspace(c=_gc()));x[k]='\0';}
    template<typename T>typename std::enable_if<std::is_floating_point<T>::value,void>::type read(T&x){char c;while(!_isdigit(c=_gc())&&c!='-'&&c!='.');bool neg=(c=='-');if(c=='-'||c=='.')c=_gc();x=0;T base=1;while(_isdigit(c)){x=x*10+(c-'0');c=_gc();}if(c=='.'){c=_gc();while(_isdigit(c)){base*=0.1;x+=(c-'0')*base;c=_gc();}}if(neg)x=-x;}
    inline void write(int x){IntWriter<int>::write(x);}
    inline void write(long long x){IntWriter<long long>::write(x);}
    inline void write(unsigned int x){IntWriter<unsigned int>::write(x);}
    inline void write(unsigned long long x){IntWriter<unsigned long long>::write(x);}
    inline void write(short x){IntWriter<short>::write(x);}
    inline void write(long x){IntWriter<long>::write(x);}
    inline void write(char x){_pc(x);}
    inline void write(const char*x){while(*x)_pc(*x++);}
    inline void write(const std::string&s){for(char c:s)_pc(c);}
    inline void write(bool b){_pc(b?'1':'0');}
    template<typename T,typename...Args>inline void read(T&x,Args&...args){read(x);read(args...);}
    template<typename T,typename...Args>inline void write(const T&x,const Args&...args){write(x);write(args...);}
    struct FastIO_{~FastIO_(){if(p3>obuf)fwrite(obuf,1,p3-obuf,stdout);}template<typename T>FastIO_& operator>>(T& x){read(x);return *this;}FastIO_& operator>>(char *x){read(x);return *this;}template<typename T>FastIO_& operator<<(const T& x){write(x);return *this;}}fio;
}using namespace FastIO;
#define cin FastIO::fio
#define cout FastIO::fio

超级加固后模板(???)

#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2")
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wsequence-point"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#include<cctype>
#include<cstdint>
#include<cstdio>
#include<string>
#include<type_traits>
#include<cmath>
#include<utility>
#include<iomanip>
#include<iostream>
#if defined(__linux__)
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif
namespace FastIO{
    constexpr int IOSIZE=1<<20;
    char obuf[IOSIZE];
    char*p3=obuf;
    constexpr char lut[100][2]={
        {'0','0'},{'0','1'},{'0','2'},{'0','3'},{'0','4'},{'0','5'},{'0','6'},{'0','7'},{'0','8'},{'0','9'},
        {'1','0'},{'1','1'},{'1','2'},{'1','3'},{'1','4'},{'1','5'},{'1','6'},{'1','7'},{'1','8'},{'1','9'},
        {'2','0'},{'2','1'},{'2','2'},{'2','3'},{'2','4'},{'2','5'},{'2','6'},{'2','7'},{'2','8'},{'2','9'},
        {'3','0'},{'3','1'},{'3','2'},{'3','3'},{'3','4'},{'3','5'},{'3','6'},{'3','7'},{'3','8'},{'3','9'},
        {'4','0'},{'4','1'},{'4','2'},{'4','3'},{'4','4'},{'4','5'},{'4','6'},{'4','7'},{'4','8'},{'4','9'},
        {'5','0'},{'5','1'},{'5','2'},{'5','3'},{'5','4'},{'5','5'},{'5','6'},{'5','7'},{'5','8'},{'5','9'},
        {'6','0'},{'6','1'},{'6','2'},{'6','3'},{'6','4'},{'6','5'},{'6','6'},{'6','7'},{'6','8'},{'6','9'},
        {'7','0'},{'7','1'},{'7','2'},{'7','3'},{'7','4'},{'7','5'},{'7','6'},{'7','7'},{'7','8'},{'7','9'},
        {'8','0'},{'8','1'},{'8','2'},{'8','3'},{'8','4'},{'8','5'},{'8','6'},{'8','7'},{'8','8'},{'8','9'},
        {'9','0'},{'9','1'},{'9','2'},{'9','3'},{'9','4'},{'9','5'},{'9','6'},{'9','7'},{'9','8'},{'9','9'},
    };
#if defined(__linux__)
    char*mmap_ptr=nullptr,*mmap_end=nullptr;
    char ibuf[IOSIZE];
    char*p1=ibuf,*p2=ibuf;
    bool use_mmap=false;
    inline void init_mmap(){
        int fd=fileno(stdin);
        struct stat st;
        if((fstat(fd,&st)==0)&(st.st_size>0)){
            void*p=mmap(nullptr,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
            if(p!=(void*)MAP_FAILED){
                mmap_ptr=(char*)p;
                mmap_end=mmap_ptr+st.st_size;
                use_mmap=true;
                return;
            }
        }
        use_mmap=false;
        p1=ibuf,p2=ibuf;
    }
    inline char _gc_mmap(){return (mmap_ptr>=mmap_end)?EOF:*mmap_ptr++;}
    inline char _gc_fread(){
        if(p1==p2){
            p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
            if(p1==p2)return EOF;
        }
        return*p1++;
    }
    inline char _gc(){return use_mmap?_gc_mmap():_gc_fread();}
#else
    char ibuf[IOSIZE];
    char*p1=ibuf,*p2=ibuf;
    inline char _gc(){
        if(p1==p2){
            p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
            if(p1==p2)return EOF;
        }
        return*p1++;
    }
    inline void init_mmap(){}
#endif
    inline void flush(){fwrite(obuf,1,p3-obuf,stdout);p3=obuf;}
    inline void _pc(char c){if(p3==obuf+IOSIZE){flush();}*p3++=c;}
    inline bool _isdigit(char c){return (c>='0')&(c<='9');}
    inline bool blank(const char x){return (x==' ')|(x=='\n')|(x=='\r')|(x=='\t');}
    constexpr uint64_t MUL10 = 0xCCCCCCCCCCCDULL;
    inline uint64_t div10_u64(uint64_t x){
        return (x * MUL10) >> 64;
    }
    inline uint64_t mod10_u64(uint64_t x){
        return x - div10_u64(x)*10;
    }
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntReader{
        static void read(T&x){
            char c;
            while(true){
                c=_gc();
                if(!blank(c))break;
            }
            uint64_t tmp=c^48;
            while(true){
                char nc=_gc();
                if(!_isdigit(nc)) break;
                c=nc;
                tmp=(tmp<<1)+(tmp<<3)+(c^48);
            }
            x=(T)tmp;
        }
    };
    template<typename T>struct IntReader<T,true>{
        static void read(T&x){
            char c;
            while(true){
                c=_gc();
                if(!blank(c))break;
            }
            bool neg=(c=='-');
            if(neg) c=_gc();
            uint64_t tmp=c^48;
            while(true){
                char nc=_gc();
                if(!_isdigit(nc)) break;
                c=nc;
                tmp=(tmp<<1)+(tmp<<3)+(c^48);
            }
            x=(T)(neg ? -tmp : tmp);
        }
    };
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntWriter{
        static void write(T x){
            if(x==0){_pc(48);return;}
            uint64_t v=(uint64_t)x;
            char tmp[64];int len=0;
            for(;v>=100;v=div10_u64(v)){
                uint64_t r=mod10_u64(v);
                tmp[++len]=lut[r][1];
                tmp[++len]=lut[r][0];
            }
            if(v>=10){
                tmp[++len]=lut[v][1];
                tmp[++len]=lut[v][0];
            }else{
                tmp[++len]=v+48;
            }
            while(len)_pc(tmp[len--]);
        }
    };
    template<typename T>struct IntWriter<T,true>{
        static void write(T x){
            if(x==0){_pc(48);return;}
            uint64_t v;
            if(x<0){_pc('-');v=~(uint64_t)x+1;}
            else{v=(uint64_t)x;}
            char tmp[64];int len=0;
            for(;v>=100;v=div10_u64(v)){
                uint64_t r=mod10_u64(v);
                tmp[++len]=lut[r][1];
                tmp[++len]=lut[r][0];
            }
            if(v>=10){
                tmp[++len]=lut[v][1];
                tmp[++len]=lut[v][0];
            }else{
                tmp[++len]=v+48;
            }
            while(len)_pc(tmp[len--]);
        }
    };
    inline void read(int&x){IntReader<int>::read(x);}
    inline void read(long long&x){IntReader<long long>::read(x);}
    inline void read(unsigned int&x){IntReader<unsigned int>::read(x);}
    inline void read(unsigned long long&x){IntReader<unsigned long long>::read(x);}
    inline void read(short&x){IntReader<short>::read(x);}
    inline void read(long&x){IntReader<long>::read(x);}
    inline void read(char&x){for(x=_gc();blank(x)&(x^EOF);x=_gc());}
    inline void read(bool&b){char c;for(c=_gc();blank(c)&(c^EOF);c=_gc());b=(c^'0')&(c^'f');}
    inline void read(char *x){char a=_gc();for(;blank(a)&(a^EOF);a=_gc());for(;(!blank(a))&(a^EOF);a=_gc())*x++=a;*x=0;}
    inline void read(std::string&s){s.clear();char a=_gc();for(;blank(a)&(a^EOF);a=_gc());for(;(!blank(a))&(a^EOF);a=_gc())s+=a;}

    template<typename T>static T pow10(int e){T r=1;if(e>0)for(int i=0;i<e;i++)r*=10;else for(int i=0;i<-e;i++)r*=0.1;return r;}
    template<typename T>typename std::enable_if<std::is_floating_point<T>::value,void>::type read(T&x){
        char c;while((!_isdigit(c=_gc()))&(c^'-')&(c^'.'));
        bool neg=(c=='-');
        if(c=='-')c=_gc();
        uint64_t intpart=0;
        while(_isdigit(c)){intpart=intpart*10+(c^48);c=_gc();}
        uint64_t fracpart=0;int frac_len=0;
        if(c=='.'){
            c=_gc();
            while(_isdigit(c)){fracpart=fracpart*10+(c^48);frac_len++;c=_gc();}
        }
        T res=(T)intpart;
        if(frac_len>0)res+=(T)fracpart*pow10<T>(-frac_len);
        if((c=='e')|(c=='E')){
            c=_gc();bool eneg=(c=='-');
            if((c=='+')|(c=='-'))c=_gc();
            int exp=0;
            while(_isdigit(c)){exp=exp*10+(c^48);c=_gc();}
            if(eneg)exp=-exp;
            res*=pow10<T>(exp);
        }
        if(neg)res=-res;
        x=res;
    }

    template<typename T>typename std::enable_if<std::is_floating_point<T>::value,void>::type write(T x,int prec=6,bool sci=false){
        if(x<0){_pc('-');x=-x;}
        if(sci){
            int exp=0;
            if(x>0){
                while(x>=10){x/=10;exp++;}
                while(x<1){x*=10;exp--;}
            }
            T rnd=0.5*pow10<T>(-prec);
            x+=rnd;
            long long ip=(long long)x;T fp=x-ip;
            IntWriter<long long>::write(ip);
            if(prec>0){
                _pc('.');
                for(int i=0;i<prec;i++){fp*=10;int d=(int)fp;_pc(d+48);fp-=d;}
            }
            _pc('e');
            if(exp<0){_pc('-');exp=-exp;}else{_pc('+');}
            if(exp<10)_pc('0');
            IntWriter<int>::write(exp);
        }else{
            long long ip=(long long)x;T fp=x-ip;
            T rnd=0.5*pow10<T>(-prec);
            fp+=rnd;
            long long carry=(long long)fp;ip+=carry;fp-=carry;
            IntWriter<long long>::write(ip);
            if(prec>0){
                _pc('.');
                for(int i=0;i<prec;i++){fp*=10;int d=(int)fp;_pc(d+48);fp-=d;}
            }
        }
    }
    inline void write(const std::pair<int,double> x){
        int a=x.first;
        if(a<7){
            double b=x.second,c=b;
            if(b<0){_pc('-');b=-b;c=-c;}
            double y=5*powl(10.0,-a-1);
            b+=y;c+=y;
            int len=0;char tmp[64];
            if(b<1)_pc(48);
            else for(;b>=1;b/=10)tmp[++len]=std::floor(b)-std::floor(b/10)*10+48;
            while(len)_pc(tmp[len--]);
            if(a)_pc('.');
            for(c*=10;a;a--,c*=10)_pc(std::floor(c)-std::floor(c/10)*10+48);
        }else{
            flush();
            std::cout<<std::fixed<<std::setprecision(a)<<x.second;
        }
    }
    inline void write(){}
    template<typename T,typename...Args>inline void write(const T&x,const Args&...args){
        write(x);
        write(args...);
    }
    template<typename T>inline void write(const T&x){IntWriter<T>::write(x);}
    struct FastIO{
        FastIO(){init_mmap();}
        ~FastIO(){flush();}
        template<typename T>FastIO&operator>>(T&x){read(x);return*this;}
        template<typename T>FastIO&operator<<(const T&x){write(x);return*this;}
        FastIO&operator<<(double x){write(x,6,false);return*this;}
        FastIO&operator<<(float x){write(x,6,false);return*this;}
        template<typename T>FastIO&putf(T x,int prec,bool sci=false){write(x,prec,sci);return*this;}
    }fio;
}
using namespace FastIO;
#define cin FastIO::fio
#define cout FastIO::fio

这模板神了

#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2")
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wsequence-point"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#include<cctype>
#include<cstdint>
#include<cstdio>
#include<string>
#include<type_traits>
#include<cmath>
#include<utility>
#include<iomanip>
#include<iostream>
#if defined(__linux__)
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif
namespace FastIO{
    constexpr int IOSIZE=1<<20;
    char obuf[IOSIZE];
    char*p3=obuf;
    constexpr char lut[100][2]={
        {'0','0'},{'0','1'},{'0','2'},{'0','3'},{'0','4'},{'0','5'},{'0','6'},{'0','7'},{'0','8'},{'0','9'},
        {'1','0'},{'1','1'},{'1','2'},{'1','3'},{'1','4'},{'1','5'},{'1','6'},{'1','7'},{'1','8'},{'1','9'},
        {'2','0'},{'2','1'},{'2','2'},{'2','3'},{'2','4'},{'2','5'},{'2','6'},{'2','7'},{'2','8'},{'2','9'},
        {'3','0'},{'3','1'},{'3','2'},{'3','3'},{'3','4'},{'3','5'},{'3','6'},{'3','7'},{'3','8'},{'3','9'},
        {'4','0'},{'4','1'},{'4','2'},{'4','3'},{'4','4'},{'4','5'},{'4','6'},{'4','7'},{'4','8'},{'4','9'},
        {'5','0'},{'5','1'},{'5','2'},{'5','3'},{'5','4'},{'5','5'},{'5','6'},{'5','7'},{'5','8'},{'5','9'},
        {'6','0'},{'6','1'},{'6','2'},{'6','3'},{'6','4'},{'6','5'},{'6','6'},{'6','7'},{'6','8'},{'6','9'},
        {'7','0'},{'7','1'},{'7','2'},{'7','3'},{'7','4'},{'7','5'},{'7','6'},{'7','7'},{'7','8'},{'7','9'},
        {'8','0'},{'8','1'},{'8','2'},{'8','3'},{'8','4'},{'8','5'},{'8','6'},{'8','7'},{'8','8'},{'8','9'},
        {'9','0'},{'9','1'},{'9','2'},{'9','3'},{'9','4'},{'9','5'},{'9','6'},{'9','7'},{'9','8'},{'9','9'},
    };
#if defined(__linux__)
    char*mmap_ptr=nullptr,*mmap_end=nullptr;
    char ibuf[IOSIZE];
    char*p1=ibuf,*p2=ibuf;
    bool use_mmap=false;
    inline void init_mmap(){
        int fd=fileno(stdin);
        struct stat st;
        if((fstat(fd,&st)==0)&(st.st_size>0)){
            void*p=mmap(nullptr,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
            if(p!=(void*)MAP_FAILED){
                mmap_ptr=(char*)p;
                mmap_end=mmap_ptr+st.st_size;
                use_mmap=true;
                return;
            }
        }
        use_mmap=false;
        p1=ibuf,p2=ibuf;
    }
#else
    char ibuf[IOSIZE];
    char*p1=ibuf,*p2=ibuf;
    inline void init_mmap(){}
#endif
    inline void flush(){fwrite(obuf,1,p3-obuf,stdout);p3=obuf;}
    inline void _pc(char c){if(p3==obuf+IOSIZE){flush();}*p3++=c;}
    inline bool _isdigit(char c){return (c>='0')&(c<='9');}
    inline bool blank(const char x){return (x==' ')|(x=='\n')|(x=='\r')|(x=='\t');}
    constexpr uint64_t MUL10 = 0xCCCCCCCCCCCDULL;
    inline uint64_t div10_u64(uint64_t x){
        return (x * MUL10) >> 64;
    }
    inline uint64_t mod10_u64(uint64_t x){
        return x - div10_u64(x)*10;
    }
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntReader{
        static void read(T&x){
            char c;
#if defined(__linux__)
            if(use_mmap){
                while(true){
                    if(mmap_ptr>=mmap_end) return;
                    c=*mmap_ptr++;
                    if(!blank(c))break;
                }
                uint64_t tmp=c^48;
                while(true){
                    if(mmap_ptr>=mmap_end)break;
                    c=*mmap_ptr++;
                    if(!_isdigit(c))break;
                    tmp=(tmp<<1)+(tmp<<3)+(c^48);
                }
            }else{
                while(true){
                    if(p1>=p2){
                        p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                        if(p1>=p2) return;
                    }
                    c=*p1++;
                    if(!blank(c))break;
                }
                uint64_t tmp=c^48;
                while(true){
                    if(p1>=p2){
                        p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                        if(p1>=p2) break;
                    }
                    c=*p1++;
                    if(!_isdigit(c))break;
                    tmp=(tmp<<1)+(tmp<<3)+(c^48);
                }
            }
#else
            while(true){
                if(p1>=p2){
                    p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                    if(p1>=p2) return;
                }
                c=*p1++;
                if(!blank(c))break;
            }
            uint64_t tmp=c^48;
            while(true){
                if(p1>=p2){
                    p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                    if(p1>=p2) break;
                }
                c=*p1++;
                if(!_isdigit(c))break;
                tmp=(tmp<<1)+(tmp<<3)+(c^48);
            }
#endif
            x=(T)tmp;
        }
    };
    template<typename T>struct IntReader<T,true>{
        static void read(T&x){
            char c;
            bool neg=false;
#if defined(__linux__)
            if(use_mmap){
                while(true){
                    if(mmap_ptr>=mmap_end) return;
                    c=*mmap_ptr++;
                    if(!blank(c))break;
                }
                if(c=='-'){neg=true;if(mmap_ptr>=mmap_end){x=0;return;}c=*mmap_ptr++;}
                uint64_t tmp=c^48;
                while(true){
                    if(mmap_ptr>=mmap_end)break;
                    c=*mmap_ptr++;
                    if(!_isdigit(c))break;
                    tmp=(tmp<<1)+(tmp<<3)+(c^48);
                }
            }else{
                while(true){
                    if(p1>=p2){
                        p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                        if(p1>=p2) return;
                    }
                    c=*p1++;
                    if(!blank(c))break;
                }
                if(c=='-'){neg=true;if(p1>=p2){p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);if(p1>=p2){x=0;return;}}c=*p1++;}
                uint64_t tmp=c^48;
                while(true){
                    if(p1>=p2){
                        p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                        if(p1>=p2) break;
                    }
                    c=*p1++;
                    if(!_isdigit(c))break;
                    tmp=(tmp<<1)+(tmp<<3)+(c^48);
                }
            }
#else
            while(true){
                if(p1>=p2){
                    p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                    if(p1>=p2) return;
                }
                c=*p1++;
                if(!blank(c))break;
            }
            if(c=='-'){neg=true;if(p1>=p2){p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);if(p1>=p2){x=0;return;}}c=*p1++;}
            uint64_t tmp=c^48;
            while(true){
                if(p1>=p2){
                    p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                    if(p1>=p2) break;
                }
                c=*p1++;
                if(!_isdigit(c))break;
                tmp=(tmp<<1)+(tmp<<3)+(c^48);
            }
#endif
            x=(T)(neg?-tmp:tmp);
        }
    };
    template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntWriter{
        static void write(T x){
            if(x==0){_pc(48);return;}
            uint64_t v=(uint64_t)x;
            char tmp[64];int len=0;
            for(;v>=100;v=div10_u64(v)){
                uint64_t r=mod10_u64(v);
                tmp[++len]=lut[r][1];
                tmp[++len]=lut[r][0];
            }
            if(v>=10){
                tmp[++len]=lut[v][1];
                tmp[++len]=lut[v][0];
            }else{
                tmp[++len]=v+48;
            }
            while(len)_pc(tmp[len--]);
        }
    };
    template<typename T>struct IntWriter<T,true>{
        static void write(T x){
            if(x==0){_pc(48);return;}
            uint64_t v;
            if(x<0){_pc('-');v=~(uint64_t)x+1;}
            else{v=(uint64_t)x;}
            char tmp[64];int len=0;
            for(;v>=100;v=div10_u64(v)){
                uint64_t r=mod10_u64(v);
                tmp[++len]=lut[r][1];
                tmp[++len]=lut[r][0];
            }
            if(v>=10){
                tmp[++len]=lut[v][1];
                tmp[++len]=lut[v][0];
            }else{
                tmp[++len]=v+48;
            }
            while(len)_pc(tmp[len--]);
        }
    };

    inline void read(int&x){IntReader<int>::read(x);}
    inline void read(long long&x){IntReader<long long>::read(x);}
    inline void read(unsigned int&x){IntReader<unsigned int>::read(x);}
    inline void read(unsigned long long&x){IntReader<unsigned long long>::read(x);}
    inline void read(short&x){IntReader<short>::read(x);}
    inline void read(long&x){IntReader<long>::read(x);}
    inline char gc(){
#if defined(__linux__)
        if(use_mmap){
            if(mmap_ptr>=mmap_end) return EOF;
            return *mmap_ptr++;
        }else{
            if(p1>=p2){
                p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
                if(p1>=p2) return EOF;
            }
            return *p1++;
        }
#else
        if(p1>=p2){
            p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);
            if(p1>=p2) return EOF;
        }
        return *p1++;
#endif
    }
    inline void read(char&x){for(x=gc();blank(x)&(x^EOF);x=gc());}
    inline void read(bool&b){char c;for(c=gc();blank(c)&(c^EOF);c=gc());b=(c^'0')&(c^'f');}
    inline void read(char *x){char a=gc();for(;blank(a)&(a^EOF);a=gc());for(;(!blank(a))&(a^EOF);a=gc())*x++=a;*x=0;}
    inline void read(std::string&s){s.clear();char a=gc();for(;blank(a)&(a^EOF);a=gc());for(;(!blank(a))&(a^EOF);a=gc())s+=a;}
    template<typename T>static T pow10(int e){T r=1;if(e>0)for(int i=0;i<e;i++)r*=10;else for(int i=0;i<-e;i++)r*=0.1;return r;}
    template<typename T>typename std::enable_if<std::is_floating_point<T>::value,void>::type read(T&x){
        char c;while((!_isdigit(c=gc()))&(c^'-')&(c^'.'));
        bool neg=(c=='-');
        if(c=='-')c=gc();
        uint64_t intpart=0;
        while(_isdigit(c)){intpart=intpart*10+(c^48);c=gc();}
        uint64_t fracpart=0;int frac_len=0;
        if(c=='.'){
            c=gc();
            while(_isdigit(c)){fracpart=fracpart*10+(c^48);frac_len++;c=gc();}
        }
        T res=(T)intpart;
        if(frac_len>0)res+=(T)fracpart*pow10<T>(-frac_len);
        if((c=='e')|(c=='E')){
            c=gc();bool eneg=(c=='-');
            if((c=='+')|(c=='-'))c=gc();
            int exp=0;
            while(_isdigit(c)){exp=exp*10+(c^48);c=gc();}
            if(eneg)exp=-exp;
            res*=pow10<T>(exp);
        }
        if(neg)res=-res;
        x=res;
    }
    template<typename T>typename std::enable_if<std::is_floating_point<T>::value,void>::type write(T x,int prec=6,bool sci=false){
        if(x<0){_pc('-');x=-x;}
        if(sci){
            int exp=0;
            if(x>0){
                while(x>=10){x/=10;exp++;}
                while(x<1){x*=10;exp--;}
            }
            T rnd=0.5*pow10<T>(-prec);
            x+=rnd;
            long long ip=(long long)x;T fp=x-ip;
            IntWriter<long long>::write(ip);
            if(prec>0){
                _pc('.');
                for(int i=0;i<prec;i++){fp*=10;int d=(int)fp;_pc(d+48);fp-=d;}
            }
            _pc('e');
            if(exp<0){_pc('-');exp=-exp;}else{_pc('+');}
            if(exp<10)_pc('0');
            IntWriter<int>::write(exp);
        }else{
            long long ip=(long long)x;T fp=x-ip;
            T rnd=0.5*pow10<T>(-prec);
            fp+=rnd;
            long long carry=(long long)fp;ip+=carry;fp-=carry;
            IntWriter<long long>::write(ip);
            if(prec>0){
                _pc('.');
                for(int i=0;i<prec;i++){fp*=10;int d=(int)fp;_pc(d+48);fp-=d;}
            }
        }
    }
    inline void write(const std::pair<int,double> x){
        int a=x.first;
        if(a<7){
            double b=x.second,c=b;
            if(b<0){_pc('-');b=-b;c=-c;}
            double y=5*powl(10.0,-a-1);
            b+=y;c+=y;
            int len=0;char tmp[64];
            if(b<1)_pc(48);
            else for(;b>=1;b/=10)tmp[++len]=std::floor(b)-std::floor(b/10)*10+48;
            while(len)_pc(tmp[len--]);
            if(a)_pc('.');
            for(c*=10;a;a--,c*=10)_pc(std::floor(c)-std::floor(c/10)*10+48);
        }else{
            flush();
            std::cout<<std::fixed<<std::setprecision(a)<<x.second;
        }
    }

    inline void write(){}
    template<typename T,typename...Args>inline void write(const T&x,const Args&...args){
        write(x);
        write(args...);
    }
    template<typename T>inline void write(const T&x){IntWriter<T>::write(x);}
    struct FastIO{
        FastIO(){init_mmap();}
        ~FastIO(){flush();}
        template<typename T>FastIO&operator>>(T&x){read(x);return*this;}
        template<typename T>FastIO&operator<<(const T&x){write(x);return*this;}
        FastIO&operator<<(double x){write(x,6,false);return*this;}
        FastIO&operator<<(float x){write(x,6,false);return*this;}
        template<typename T>FastIO&putf(T x,int prec,bool sci=false){write(x,prec,sci);return*this;}
    }fio;
}
using namespace FastIO;
#define cin FastIO::fio
#define cout FastIO::fio