/* #include void self::main(){ LL(N); RD(lll,M); VL(N,a);--a; lll T=a.inversion(); if(T%2){ if(M%2){ ll k=ceil(ceil(T,M)-1,2); pp(M*(2*k+1)); } else{ pp(-1); } } else{ if(M%2){ ll k=ceil(ceil(T,M),2); pp(M*(2*k)); } else{ ll k=ceil(T,M); pp(M*k); } } } */ #include using namespace std; namespace self{void main();void sub();templatevoid pp(const auto&...a);void epp(const auto&...a);} int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);lin(__VA_ARGS__) #define VL(n,...) RDVL(ll,n,__VA_ARGS__) #define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a) #define ef(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):ranges::reverse_view(a)) namespace self{ using ll=long long; using lll=__int128_t; using ulll=__uint128_t; ostream&operator<<(ostream&o,const ulll&x){return(x<10?o:o<>(istream&i,lll&x){ll t;i>>t;x=t;return i;} ostream&operator<<(ostream&o,const lll&x){return o<<(x<0?"-":"")<0?x:-x);} constexpr auto refs(auto&...a){return array{ref(a)...};} void lin(auto&...a){(cin>>...>>a);} auto ceil(auto x,auto y){if(y<0)x=-x,y=-y;return x<=0?x/y:(x-1)/y+1;} templateusing pack_back_t=tuple_element_t>; } namespace self{ templateclass FenwickTree{ public: ll n_; vectordata_; FenwickTree(ll n):n_(n),data_(n){} void add(ll i,T x){ assert(0<=i&&i0)res+=data_[r-1],r-=r&-r; while(l>0)res-=data_[l-1],l-=l&-l; return res; } }; } namespace self{ templateistream&operator>>(istream&i,vector&v){fe(v,e)i>>e;return i;} templateconstexpr int depth=0; templatestruct core_t_helper{using type=T;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ static constexpr int D=depth+1; using C=core_t; using vector::vector; void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec(n,array{a...}[0]); else { } } vec&operator--(){fe(*this,e)--e;return*this;} ll size()const{return vector::size();} template>vec stable_sort(F f={})const{vec v=*this;ranges::stable_sort(v,f);return v;} template>auto sort_from(F f={})const{ veco(size()); std::iota(o.begin(),o.end(),0); return o.stable_sort([&](ll i,ll j){return f((*this)[i],(*this)[j]);}); } ll inversion()const{ ll res=0; FenwickTrees(size()); ef(sort_from(),i){ res+=s.sum(0,i); s.add(i,1); } return res; } }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; } templatevoid self::pp(const auto&...a){const char*c="";((o<