QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796876#7319. Order-Preserving PartitionaintaWA 88ms12528kbC++235.9kb2024-12-02 08:22:562024-12-02 08:22:57

Judging History

你现在查看的是最新测评结果

  • [2024-12-02 08:22:57]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:12528kb
  • [2024-12-02 08:22:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
 
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define rep(i,b) rng(i,0,b-1)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
#define per(i,b) gnr(i,b-1,0)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long ll;
using pii=pair<int,int>;
using vi=vc<int>;
using uint=unsigned;
using ull=unsigned long long;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using t3=tuple<int,int,int>;
 
ll rand_int(ll l, ll r) { //[l, r]
	#ifdef LOCAL
	static mt19937_64 gen;
	#else
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    #endif
    return uniform_int_distribution<ll>(l, r)(gen);
}
 
 
template <uint MD> struct ModInt {
    using M = ModInt;
    ///const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<998244353>;
using t4 = tuple<int,int,int,int>;
using t5 = tuple<int,int,int,int,int>;
//template<> const Mint Mint::G = Mint(3);
 
#define N_ 1010000
const int SZ = (1<<20);
int n, w[N_], Loc[N_];
int Mn[N_], Mx[N_], UF[N_];
/*void Calc(int b, int e){
}*/
bool Block(int b, int e){
	if(b>e||b<1||e>n)return false;
	int Mn=n+1,Mx=0;
	rng(i,b,e)Mx=max(Mx,w[i]),Mn=min(Mn,w[i]);
	return Mx-Mn==e-b;
}
int Find(int a){
	if(a==UF[a])return a;
	return UF[a]=Find(UF[a]);
}
int GetA(int b, int e){
	Mx[b]=w[b]; rng(i,b+1,e)Mx[i]=max(Mx[i-1],w[i]);
	Mn[e]=w[e]; gnr(i,e-1,b)Mn[i]=min(Mn[i+1],w[i]);
	int s=0;
	if(Mx[e]-Mn[b]==e-b){
		rng(i,b,e-1)if(Mx[i]<Mn[i+1])s++;
	}
	return s;
}
int GetB(int b, int e){
	Mn[b]=w[b]; rng(i,b+1,e)Mn[i]=min(Mn[i-1],w[i]);
	Mx[e]=w[e]; gnr(i,e-1,b)Mx[i]=max(Mx[i+1],w[i]);
	int s=0;
	if(Mx[b]-Mn[e]==e-b){
		rng(i,b,e-1)if(Mn[i]>Mx[i+1])s++;
	}
	return s;
}
void Solve(){
	rng(i,0,n+1){
		w[i]=UF[i]=Loc[i]=Mn[i]=Mx[i]=0;
	}
	rng(i,1,n){
		scanf("%d",&w[i]);
	}
	int P[4];
	rep(i,4)scanf("%d",&P[i]);
	ll res=0;
	if(P[1]==1 || P[2]==1){
		rng(i,1,n)w[i]=n+1-w[i];
		rep(i,4)P[i]=5-P[i];
	}
	if(P[1]==4 || P[2]==4){
		if(P[2]==4){
			reverse(P,P+4);
			reverse(w+1,w+n+1);
		}
		rng(i,1,n) Loc[w[i]]=i;
		if(P[2]==1){
			if(P[0]==2){//2413
				int l = Loc[1], r = Loc[n];
				int p1 = 1; while(p1<=n && w[p1] <= w[n])p1++;
				int p2 = n; while(p2>=1 && w[p2] >= w[1])p2--;
				if(p1 <= r && r < l && r <= p2){ 
					int p3 = p1; while(p3<=n && w[p3]>=w[n])p3++;
					if(Block(1,p1-1) && Block(p1,p3-1) && Block(p3,p2) && Block(p2+1,n))res++;
				}
			}
			else{//3412
				int l = Loc[1], r = Loc[n];
				int p1 = r; while(p1<=n && w[p1] >= w[n])p1++;
				//~p1-1 , p1~
				if(r<p1 && p1<=l && Block(1,p1-1) && Block(p1,n)){
					ll c1 = GetA(1,p1-1), c2 = GetA(p1,n);
					res += c1*c2;
				}
			}
		}
		else if(P[3]==1){
			if(P[0]==2){//2431
				int p1 = n, r = Loc[n];
				while(p1>=1 && w[p1]<=w[1])p1--;
				if(r < p1){//[ ][ r ][ ,p1][p1+1,n]
					int p2 = 1; while(p2<=n && w[p2]<=w[p1])p2++; //[1,p2-1]
					if(p2<=r && Block(1,p2-1) && Block(p1+1,n) && Block(p2,p1)){
						res = GetB(p2,p1);
					}
				}
			}
			else{ //3421
				int p1 = n, r = Loc[n];
				while(p1>=1 && w[p1]<=w[1])p1--;
				if(r <= p1){//[  r ][p1+1,n]
					if(Block(1,p1) && Block(p1+1,n)) res = GetA(1,p1)*GetB(p1+1,n);
				}
			}
		}
		else{
			if(P[2]==2){//1423
				int p1 = 1; while(p1<=n && w[p1]<=w[n])p1++;
				int p2 = n; while(p2>=1 && w[p2]!=p1)p2--;
				while(p2>=1 && w[p2] < w[n])p2--;
				//[1,p1-1] [p1, p2], 
				if(Loc[1]< p1 && Block(1,p1-1) && Block(p1,p2) && p1 <= Loc[n] && Loc[n]<=p2) res = GetA(p2+1,n);
			}
			else{//1432
				int p1 = 1; while(p1<=n && w[p1]<=w[n])p1++;
				if(Block(1,p1-1) && Loc[1]<p1){
					int Mx = 0, cur=p1-1, cc=0;
					gnr(i,n,p1+1){
						cur++;
						Mx=max(Mx,w[i]);
						if(Mx == cur){
							res+=cc;
							cc++;
						}
					}
				}
			}
		}
	}
	else{
		if(P[0]==4){
			rng(i,1,n)w[i]=n+1-w[i];
			rep(i,4)P[i]=5-P[i];
		}
		rng(i,1,n) Loc[w[i]]=i;
		//rep(i,4)printf("%d ",P[i]);
		assert(P[0]==1 && P[3]==4);
		rng(i,1,n){
			UF[i]=i;
			Mx[i]=max(Mx[i-1],w[i]);
		}
		Mn[n]=w[n];
		gnr(i,n-1,1)Mn[i]=min(Mn[i+1],w[i]);
		if(P[1]==3){ // 1324
			int l =n,  r=1;
			rng(i,1,n){
				int x = Loc[i];
				UF[x]=x-1;
				l=min(l,x);r=max(r,x);
				int z = Find(r);
				int c2 = r-z;
				if(l==1 && z>1){
					int c1 = i-c2;
					if(Mx[c1] == c1 && Mn[r+1] == r+1)res++;
				}
			}
		}
		else{
			ll c=0;
			rng(i,1,n-1){
				if(Mx[i]==i){
					res += c*(c-1)/2;
					c++;
				}
			}
		}
	}
	printf("%lld\n",res);
}
int main(){
	while(scanf("%d",&n)==1){
		Solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12116kb

input:

10
2 1 4 3 10 9 8 7 5 6
2 4 1 3
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4

output:

0
84

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 67ms
memory: 12068kb

input:

10
4 1 8 2 3 10 9 7 5 6
1 2 3 4
10
1 2 7 10 6 4 3 9 8 5
1 2 3 4
10
7 8 4 6 1 3 2 9 10 5
1 2 3 4
10
6 5 1 10 7 8 9 3 4 2
1 2 3 4
10
8 7 10 6 3 5 9 4 2 1
1 2 3 4
10
9 4 5 8 7 3 10 6 1 2
1 2 3 4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0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #4:

score: 0
Accepted
time: 86ms
memory: 12044kb

input:

10
9 1 3 5 8 6 2 10 4 7
1 3 2 4
10
4 1 7 2 9 8 10 5 6 3
1 3 2 4
10
1 2 7 9 10 3 6 5 8 4
1 3 2 4
10
1 6 5 10 8 9 3 2 7 4
1 3 2 4
10
10 4 2 7 5 8 6 1 9 3
1 3 2 4
10
6 1 9 10 7 3 4 2 5 8
1 3 2 4
10
4 9 10 1 8 2 7 3 6 5
1 3 2 4
10
2 5 6 4 8 9 10 7 1 3
1 3 2 4
10
3 9 4 7 8 5 6 10 1 2
1 3 2 4
10
4 3 2 10 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #5:

score: 0
Accepted
time: 68ms
memory: 12012kb

input:

10
2 3 7 9 6 5 1 10 8 4
1 3 4 2
10
9 5 4 8 10 7 1 6 3 2
1 3 4 2
10
6 8 2 9 5 1 7 4 10 3
1 3 4 2
10
9 7 2 8 10 4 6 1 3 5
1 3 4 2
10
8 10 1 7 5 4 6 2 9 3
1 3 4 2
10
9 3 8 10 4 2 6 5 7 1
1 3 4 2
10
9 10 5 2 8 1 3 6 4 7
1 3 4 2
10
3 10 6 2 8 1 9 4 7 5
1 3 4 2
10
4 10 9 2 3 8 1 5 6 7
1 3 4 2
10
2 10 8 3 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #6:

score: 0
Accepted
time: 72ms
memory: 12048kb

input:

10
9 8 6 10 5 3 7 1 2 4
1 4 2 3
10
9 2 6 10 5 8 7 1 4 3
1 4 2 3
10
8 6 9 7 2 10 4 3 5 1
1 4 2 3
10
2 1 10 7 4 3 6 8 9 5
1 4 2 3
10
9 10 4 6 5 2 3 8 1 7
1 4 2 3
10
3 1 5 8 4 2 7 9 6 10
1 4 2 3
10
5 3 9 7 2 10 4 6 1 8
1 4 2 3
10
7 2 1 6 3 10 4 8 5 9
1 4 2 3
10
9 2 5 8 10 6 7 4 3 1
1 4 2 3
10
9 5 6 8 2...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #7:

score: 0
Accepted
time: 63ms
memory: 12128kb

input:

10
2 7 5 6 3 8 9 4 1 10
1 4 3 2
10
5 8 4 3 1 2 10 6 7 9
1 4 3 2
10
6 5 8 10 3 1 4 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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #9:

score: 0
Accepted
time: 60ms
memory: 11992kb

input:

10
2 6 3 9 8 5 10 7 1 4
2 1 4 3
10
4 7 2 9 1 6 5 8 3 10
2 1 4 3
10
2 6 1 3 5 10 7 9 8 4
2 1 4 3
10
9 6 1 7 3 10 4 5 2 8
2 1 4 3
10
9 2 6 4 3 8 5 7 10 1
2 1 4 3
10
3 10 7 1 8 5 4 2 9 6
2 1 4 3
10
8 5 9 10 7 4 3 6 1 2
2 1 4 3
10
1 2 5 6 3 10 8 4 7 9
2 1 4 3
10
6 7 10 5 3 8 9 4 2 1
2 1 4 3
10
10 7 4 8 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #10:

score: 0
Accepted
time: 70ms
memory: 12068kb

input:

10
1 5 10 7 8 9 6 4 2 3
2 3 1 4
10
3 10 9 4 6 1 8 2 7 5
2 3 1 4
10
9 5 6 3 1 7 2 4 10 8
2 3 1 4
10
8 9 4 10 2 6 7 5 1 3
2 3 1 4
10
7 8 9 5 4 3 10 6 2 1
2 3 1 4
10
6 7 1 4 10 2 9 3 8 5
2 3 1 4
10
5 2 7 4 3 6 9 10 8 1
2 3 1 4
10
2 6 9 8 10 7 1 5 3 4
2 3 1 4
10
1 5 7 3 10 6 9 8 2 4
2 3 1 4
10
3 9 1 8 1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #11:

score: 0
Accepted
time: 67ms
memory: 12128kb

input:

10
1 5 9 7 2 3 4 8 10 6
2 3 4 1
10
8 2 10 4 5 9 1 3 7 6
2 3 4 1
10
7 8 5 3 4 6 1 2 10 9
2 3 4 1
10
3 7 4 9 10 1 6 2 8 5
2 3 4 1
10
6 8 3 2 7 9 1 4 10 5
2 3 4 1
10
7 4 10 8 6 3 1 9 2 5
2 3 4 1
10
5 4 7 8 3 2 6 9 1 10
2 3 4 1
10
5 10 1 8 3 9 7 2 6 4
2 3 4 1
10
2 7 1 8 9 3 5 4 10 6
2 3 4 1
10
5 6 9 10 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #12:

score: 0
Accepted
time: 73ms
memory: 12052kb

input:

10
7 3 8 2 4 9 6 1 10 5
2 4 1 3
10
5 1 6 4 3 9 8 10 2 7
2 4 1 3
10
5 6 9 3 2 8 7 4 1 10
2 4 1 3
10
5 4 10 9 3 2 1 6 8 7
2 4 1 3
10
4 6 3 8 1 10 7 2 5 9
2 4 1 3
10
10 3 9 1 4 8 6 5 7 2
2 4 1 3
10
9 1 4 5 7 6 3 8 10 2
2 4 1 3
10
5 2 10 1 4 8 6 3 7 9
2 4 1 3
10
6 10 5 9 4 7 8 3 1 2
2 4 1 3
10
1 10 6 4 ...

output:

0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #13:

score: 0
Accepted
time: 63ms
memory: 12032kb

input:

10
10 8 1 7 2 9 4 5 6 3
2 4 3 1
10
7 6 9 2 1 10 4 3 5 8
2 4 3 1
10
3 2 10 8 7 6 5 4 1 9
2 4 3 1
10
6 5 8 10 1 9 2 7 4 3
2 4 3 1
10
6 1 5 2 4 3 10 9 7 8
2 4 3 1
10
9 1 5 8 4 2 6 3 7 10
2 4 3 1
10
7 9 6 3 5 2 1 10 4 8
2 4 3 1
10
5 1 4 6 7 9 3 10 8 2
2 4 3 1
10
1 4 2 7 5 6 9 10 8 3
2 4 3 1
10
10 8 6 2 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 68ms
memory: 12052kb

input:

10
8 3 9 7 6 2 1 10 4 5
3 1 2 4
10
10 3 9 1 8 4 7 2 5 6
3 1 2 4
10
4 9 8 10 6 2 5 1 3 7
3 1 2 4
10
5 4 6 10 9 1 8 3 2 7
3 1 2 4
10
7 2 4 9 10 3 5 1 8 6
3 1 2 4
10
6 5 1 10 7 2 4 8 9 3
3 1 2 4
10
6 5 4 10 2 3 9 1 8 7
3 1 2 4
10
1 9 7 3 4 8 5 6 2 10
3 1 2 4
10
4 10 1 8 2 9 7 6 3 5
3 1 2 4
10
1 9 5 10 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #15:

score: 0
Accepted
time: 72ms
memory: 12108kb

input:

10
3 4 5 2 9 6 7 10 1 8
3 1 4 2
10
7 1 4 8 5 6 2 3 10 9
3 1 4 2
10
8 9 6 3 5 10 2 7 1 4
3 1 4 2
10
2 6 1 7 10 9 4 5 8 3
3 1 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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #17:

score: 0
Accepted
time: 68ms
memory: 12036kb

input:

10
6 5 3 10 9 8 2 4 1 7
3 2 4 1
10
2 4 9 5 8 10 6 7 3 1
3 2 4 1
10
6 9 4 5 1 8 3 10 7 2
3 2 4 1
10
1 5 3 6 10 4 7 8 9 2
3 2 4 1
10
8 5 3 1 10 7 6 9 2 4
3 2 4 1
10
9 5 1 7 3 8 10 4 6 2
3 2 4 1
10
8 9 6 1 10 3 5 7 2 4
3 2 4 1
10
3 7 10 5 9 4 6 8 2 1
3 2 4 1
10
7 1 5 8 2 9 10 6 3 4
3 2 4 1
10
8 6 5 2 3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
...

result:

ok 100000 lines

Test #18:

score: 0
Accepted
time: 69ms
memory: 12176kb

input:

10
4 6 7 1 5 8 9 2 3 10
3 4 1 2
10
4 9 3 8 1 7 5 10 2 6
3 4 1 2
10
10 7 1 3 2 9 8 4 5 6
3 4 1 2
10
5 10 8 6 7 1 9 4 2 3
3 4 1 2
10
7 9 10 1 8 2 3 6 4 5
3 4 1 2
10
9 10 7 3 4 6 8 2 1 5
3 4 1 2
10
3 6 2 4 1 9 10 5 8 7
3 4 1 2
10
2 9 10 3 8 6 4 5 7 1
3 4 1 2
10
6 4 3 9 8 7 5 1 10 2
3 4 1 2
10
3 10 2 5 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
6
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #19:

score: 0
Accepted
time: 71ms
memory: 12112kb

input:

10
1 9 5 4 7 10 2 3 8 6
3 4 2 1
10
10 6 2 4 5 1 8 9 3 7
3 4 2 1
10
4 8 5 2 1 7 6 3 10 9
3 4 2 1
10
1 2 5 10 7 3 8 9 6 4
3 4 2 1
10
4 9 8 10 7 5 6 1 3 2
3 4 2 1
10
10 6 3 9 7 8 1 5 4 2
3 4 2 1
10
10 8 6 2 7 5 1 9 3 4
3 4 2 1
10
3 4 9 1 10 5 7 2 6 8
3 4 2 1
10
9 3 7 1 5 4 10 6 8 2
3 4 2 1
10
2 10 7 4 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #20:

score: 0
Accepted
time: 71ms
memory: 12064kb

input:

10
5 2 4 3 9 7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0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #22:

score: 0
Accepted
time: 69ms
memory: 12064kb

input:

10
5 2 4 3 7 6 8 9 1 10
4 2 1 3
10
7 5 1 10 9 6 8 2 3 4
4 2 1 3
10
1 4 6 3 5 8 2 10 7 9
4 2 1 3
10
9 3 10 4 7 8 6 2 5 1
4 2 1 3
10
6 9 3 7 2 1 5 4 8 10
4 2 1 3
10
6 8 7 5 3 2 9 4 1 10
4 2 1 3
10
3 8 6 5 4 9 1 7 2 10
4 2 1 3
10
6 2 3 4 10 7 8 9 5 1
4 2 1 3
10
6 7 3 2 4 8 5 10 1 9
4 2 1 3
10
7 8 6 2 3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #23:

score: 0
Accepted
time: 83ms
memory: 12176kb

input:

10
9 10 7 2 3 8 5 1 6 4
4 2 3 1
10
5 10 7 1 6 8 3 4 2 9
4 2 3 1
10
9 10 8 7 1 5 4 3 6 2
4 2 3 1
10
7 9 5 1 10 3 2 4 6 8
4 2 3 1
10
10 6 3 9 8 2 5 4 7 1
4 2 3 1
10
7 5 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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #25:

score: 0
Accepted
time: 67ms
memory: 12132kb

input:

10
5 10 7 9 6 4 1 8 3 2
4 3 2 1
10
3 5 8 10 7 4 6 9 1 2
4 3 2 1
10
6 2 5 9 8 4 10 3 1 7
4 3 2 1
10
5 7 6 10 4 2 1 3 8 9
4 3 2 1
10
3 10 2 1 9 7 4 6 5 8
4 3 2 1
10
7 5 4 6 10 9 1 8 2 3
4 3 2 1
10
6 9 1 7 2 10 8 4 5 3
4 3 2 1
10
5 8 2 1 6 3 10 4 9 7
4 3 2 1
10
9 7 2 3 10 4 6 1 8 5
4 3 2 1
10
6 4 8 2 1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 69ms
memory: 11992kb

input:

18
4 11 5 9 16 2 3 8 7 18 14 6 13 15 12 1 17 10
4 1 2 3
19
9 11 3 16 12 18 5 14 2 13 8 15 7 4 1 19 10 6 17
2 3 4 1
11
8 6 11 9 5 7 1 4 3 10 2
3 4 2 1
13
2 8 10 1 6 3 13 7 4 12 11 5 9
2 3 1 4
13
11 7 8 1 4 5 9 12 10 2 13 3 6
2 1 3 4
12
12 2 9 8 5 1 10 11 3 4 7 6
4 1 2 3
15
12 11 8 4 7 15 13 5 6 9 14 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
...

result:

ok 64448 lines

Test #27:

score: 0
Accepted
time: 57ms
memory: 12068kb

input:

27
6 16 12 1 11 23 13 18 14 17 26 4 27 19 5 9 10 24 21 22 2 3 7 15 8 20 25
2 1 3 4
26
1 21 13 18 15 20 11 8 3 6 9 2 4 24 23 17 25 5 12 7 22 10 14 19 26 16
1 2 3 4
20
1 19 18 5 13 14 2 8 4 3 7 6 12 15 20 9 10 11 16 17
2 1 4 3
25
25 18 9 3 21 14 10 8 5 12 13 15 7 6 11 2 24 23 16 4 19 17 1 20 22
3 4 2 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 40003 lines

Test #28:

score: 0
Accepted
time: 88ms
memory: 12052kb

input:

8
7 4 3 5 6 8 1 2
3 2 4 1
8
8 7 6 3 2 4 1 5
4 3 2 1
4
4 3 2 1
4 3 2 1
7
7 6 5 4 1 3 2
4 3 2 1
7
4 3 2 1 7 6 5
1 4 3 2
4
3 1 2 4
3 1 2 4
4
1 3 4 2
1 3 4 2
10
7 9 8 5 2 1 4 3 6 10
2 3 1 4
9
9 2 1 3 8 7 4 6 5
4 1 3 2
10
1 2 3 5 4 6 7 9 8 10
1 2 3 4
7
6 2 3 5 4 1 7
3 2 1 4
10
8 7 9 1 2 5 3 4 10 6
3 1 4 ...

output:

1
1
1
4
1
1
1
1
2
35
1
1
3
2
2
1
2
1
6
1
1
4
1
3
6
1
1
2
1
1
1
1
2
2
1
3
1
1
6
1
1
3
1
1
1
2
1
3
1
10
1
3
1
3
1
1
3
3
1
3
1
3
1
1
1
3
1
6
10
1
1
3
1
1
2
2
3
1
1
1
2
2
1
1
3
1
4
2
3
2
1
1
3
1
3
1
6
1
1
6
2
2
1
1
1
4
4
20
2
1
3
1
2
1
1
2
1
1
1
4
1
1
1
10
1
4
4
1
1
1
2
1
1
4
1
2
1
2
1
6
1
1
1
1
3
1
1
1...

result:

ok 142708 lines

Test #29:

score: 0
Accepted
time: 72ms
memory: 11996kb

input:

18
14 15 17 16 18 7 8 5 6 4 3 2 1 11 13 9 12 10
4 2 1 3
16
16 15 14 6 1 11 8 5 2 7 3 10 4 9 13 12
4 3 1 2
15
14 13 15 11 10 12 7 2 6 5 8 9 3 4 1
4 2 3 1
11
1 2 3 4 5 6 7 8 10 9 11
1 3 2 4
12
8 9 4 6 3 2 1 7 5 11 12 10
2 3 1 4
12
12 1 2 5 4 3 6 9 8 10 7 11
4 1 2 3
16
8 9 10 13 11 12 14 15 16 4 2 3 5 ...

output:

5
2
1
1
1
10
2
1
1
2
5
1
14
1
2
3
4
1
15
3
2
6
4
1
4
1
2
4
1
1
5
2
1
3
10
5
5
1
16
6
2
1
1
1
1
1
1
1
2
1
1
21
1
10
9
3
2
1
4
1
2
1
2
2
1
2
1
2
3
1
4
6
4
10
3
1
18
4
1
3
4
1
1
3
2
1
3
3
2
1
3
3
4
56
4
1
1
3
6
3
1
1
1
2
1
2
1
10
35
15
1
1
5
6
1
3
1
4
1
1
12
1
3
1
4
1
2
6
1
2
6
20
3
1
6
2
4
2
1
2
5
1
1...

result:

ok 64491 lines

Test #30:

score: 0
Accepted
time: 54ms
memory: 12128kb

input:

10
3 4 2 5 6 7 8 9 10 1
2 3 4 1
20
3 4 5 1 2 6 20 19 15 12 17 18 11 13 16 14 8 9 7 10
1 4 3 2
86
18 16 12 9 19 14 15 17 10 11 13 23 26 22 20 30 21 28 27 25 29 24 34 37 39 40 33 35 36 32 41 31 38 42 43 50 61 66 54 82 64 77 81 75 86 45 67 85 79 70 46 52 58 55 48 80 73 51 59 57 78 76 83 63 60 68 74 49 ...

output:

15
3
10
2
1
10
1
2
2
3
1
2
1
66
35
1
3
14
1
3
3
1
2
2
6
4
1
1
23
5
10
3
9
3
4
2
2
1
2
2
3
1
2
3
1
120
2
1
21
7
1
1
1
3
1
4
35
10
2
1
3
1
1
3
2
1140
1
4
1
10
4
3
1
21
1
153
1
3
3
1
12
2
1
1
1
1
12
10
1
3
1
2
2
15
2
1
4
2
1
6
1
3
1
1
2
2
1
1
3
1
4
1
2
6
1
55
16
1
2
2
1
1
1
1
1
220
2
1
2
28
2
2
4
2
1
6...

result:

ok 18219 lines

Test #31:

score: 0
Accepted
time: 49ms
memory: 11992kb

input:

108
76 73 78 79 75 77 74 80 81 82 83 63 69 64 72 68 54 67 62 61 55 56 60 57 71 65 59 66 58 53 70 105 107 100 85 96 97 95 87 102 99 84 98 104 94 88 90 101 91 106 103 89 86 93 92 108 52 11 5 33 26 51 17 12 10 27 19 2 32 36 43 29 38 42 21 1 24 4 31 50 16 14 45 6 39 20 44 13 18 47 48 8 3 49 28 35 23 15 ...

output:

1
1
28
1
1
2
3
1
145
1
1
21
3
11
250
1
1
1
37
1
10
1
1
2
3
92
1
4
1
1
1
1
23
1
3
903
1
20
2
1
1
16
1
4495
1
1
1
3
33
5
23
1
4
1
34
1
1
2
1
595
89
1
1
1
136
1
1
34
3
1
15
3
741
1
1
1
220
1
1
1
2
1
1
7
1
3
1
1
1
1
1
101
1
7
1
1
27
1
1
55
1
1
1
1
1
1
1140
341376
1
56
14
1
66
45
1
105
1
1
1
36
1
1
412
2...

result:

ok 1856 lines

Test #32:

score: 0
Accepted
time: 49ms
memory: 12128kb

input:

1611
1551 1499 1566 1583 1565 1428 1445 1567 1519 1533 1406 1435 1461 1452 1582 1497 1590 1471 1504 1608 1552 1489 1530 1511 1605 1448 1585 1541 1462 1423 1480 1449 1522 1488 1425 1493 1579 1515 1514 1544 1443 1467 1599 1568 1564 1520 1484 1513 1603 1432 1404 1548 1495 1481 1543 1546 1577 1536 1418 ...

output:

1
1
1
16
1
1
177
482
1
1
1
1
1
45760
1
437989
65703
1
1
1
6328
31
1
1
91
6
169
33153
1
1
1
199
1
1
314028
1
1
1
1
1
105
1
1
17
3737581
5
91
28
1
15
466
1
353
1
1
79
9
1
1
1
1
1
10908404
1
1
10890
903
1
1
287980
1
1
1
1
1431
1
14391741
1
1
1
1
4149466
3777484
1
1
1
1
1
1
1
10
1
1
704
1
253
57
1
1
1
1...

result:

ok 343 lines

Test #33:

score: -100
Wrong Answer
time: 51ms
memory: 12528kb

input:

47013
44529 44245 44311 44216 44212 44442 44224 44612 44626 44749 44744 44363 44623 44313 44697 44369 44266 44342 44343 44223 44438 44751 44294 44356 44739 44740 44241 44222 44349 44225 44459 44679 44727 44435 44752 44700 44698 44541 44475 44722 44613 44553 44481 44755 44430 44386 44580 44295 44641 ...

output:

1
1
1
1
7140
1
308633854
1
653600
1
1
35637903
1081
1
4475
821121
48
1
1
1
1
8007
11211694116
1
1
1
1
1
1
1

result:

wrong answer 23rd lines differ - expected: '211694039', found: '11211694116'