QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796874#7319. Order-Preserving PartitionaintaWA 642ms12148kbC++236.5kb2024-12-02 08:20:102024-12-02 08:20:10

Judging History

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

  • [2024-12-02 08:20:10]
  • 评测
  • 测评结果:WA
  • 用时:642ms
  • 内存:12148kb
  • [2024-12-02 08:20:10]
  • 提交

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,1,n){
		scanf("%d",&w[i]);
	}
	int P[4];
	rep(i,4)scanf("%d",&P[i]);
	ll res=0, r2=0;
	rng(i,1,n-3){
		rng(j,i+1,n-2){
			rng(k,j+1,n-1){
				if(Block(1,i) && Block(i+1,j) && Block(j+1,k) && Block(k+1,n)){
					vc<pii>T={{P[0],w[i]},{P[1],w[j]},{P[2],w[k]},{P[3],w[n]}};
					sort(all(T));
					int ck=0;
					rep(j,3)if(T[j].se>T[j+1].se)ck=1;
					if(!ck)r2++;
				}
			}
		}
	}
	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++;
				}
			}
		}
	}
	if(res!=r2){
		rng(i,1,n)printf("%d ",w[i]);
		rep(i,4)printf("%d ",P[i]);
		puts("");
	}
	else printf("%lld\n",res);
}
int main(){
/*	vi T(4);
	rep(i,4)T[i]=i;
	do{
		vi Z(5);
		rep(i,5)Z[i]=i;
		do{
			printf("%d\n",5);
			rep(i,5)printf("%d ",Z[i]+1);
			puts("");
			rep(i,4)printf("%d ",T[i]+1);
			puts("");
		}while(next_permutation(all(Z)));
	}while(next_permutation(all(T)));
	return 0;*/
	while(scanf("%d",&n)==1){
		Solve();
	}
}

详细

Test #1:

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

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: 124ms
memory: 10108kb

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

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 #3:

score: 0
Accepted
time: 122ms
memory: 12096kb

input:

10
5 10 1 9 4 8 3 7 6 2
1 2 4 3
10
1 7 4 8 9 5 10 2 6 3
1 2 4 3
10
3 4 6 5 9 7 10 1 8 2
1 2 4 3
10
8 3 4 7 5 10 9 2 6 1
1 2 4 3
10
3 5 10 6 2 8 9 7 4 1
1 2 4 3
10
2 1 8 4 9 10 7 6 3 5
1 2 4 3
10
6 5 4 8 2 1 7 3 10 9
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ok 100000 lines

Test #5:

score: 0
Accepted
time: 122ms
memory: 12148kb

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: 125ms
memory: 12104kb

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: 114ms
memory: 7888kb

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

result:

ok 100000 lines

Test #8:

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

input:

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

result:

ok 100000 lines

Test #10:

score: 0
Accepted
time: 127ms
memory: 12100kb

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: 124ms
memory: 7908kb

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: 121ms
memory: 8012kb

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: 120ms
memory: 12104kb

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: 124ms
memory: 12004kb

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: 120ms
memory: 8048kb

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

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 120ms
memory: 7928kb

input:

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

result:

ok 100000 lines

Test #18:

score: 0
Accepted
time: 125ms
memory: 12004kb

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: 123ms
memory: 12148kb

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: 118ms
memory: 7916kb

input:

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

output:

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
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
...

result:

ok 100000 lines

Test #21:

score: 0
Accepted
time: 121ms
memory: 12148kb

input:

10
9 4 1 6 2 10 5 8 3 7
4 1 3 2
10
7 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
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: 131ms
memory: 10048kb

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

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
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
2
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
...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 122ms
memory: 12144kb

input:

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

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 236ms
memory: 10000kb

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: 642ms
memory: 9920kb

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: -100
Wrong Answer
time: 180ms
memory: 12024kb

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:

wrong answer 260th lines differ - expected: '1', found: '1 2 3 4 5 7 6 9 8 1 3 2 4 '