QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796877#7319. Order-Preserving PartitionaintaAC ✓93ms29656kbC++235.9kb2024-12-02 08:24:072024-12-02 08:24:07

Judging History

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

  • [2024-12-02 08:24:07]
  • 评测
  • 测评结果:AC
  • 用时:93ms
  • 内存:29656kb
  • [2024-12-02 08:24:07]
  • 提交

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%1000000007);
}
int main(){
	while(scanf("%d",&n)==1){
		Solve();
	}
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 12092kb

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: 71ms
memory: 12164kb

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: 78ms
memory: 11980kb

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: 73ms
memory: 12160kb

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: 71ms
memory: 12032kb

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: 68ms
memory: 12092kb

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: 74ms
memory: 11976kb

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: 69ms
memory: 12080kb

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: 71ms
memory: 12012kb

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: 74ms
memory: 11980kb

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: 67ms
memory: 12096kb

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: 73ms
memory: 12092kb

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: 68ms
memory: 11984kb

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: 72ms
memory: 12080kb

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: 11980kb

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: 72ms
memory: 12044kb

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: 12168kb

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: 68ms
memory: 12136kb

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: 76ms
memory: 12096kb

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: 76ms
memory: 11984kb

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: 12104kb

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: 58ms
memory: 12092kb

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: 93ms
memory: 12092kb

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: 70ms
memory: 12092kb

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: 50ms
memory: 12092kb

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: 50ms
memory: 11984kb

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: 48ms
memory: 12072kb

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: 0
Accepted
time: 55ms
memory: 12440kb

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
211694039
1
1
1
1
1
1
1

result:

ok 30 lines

Test #34:

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

input:

100000
2407 2623 330 2721 9310 11263 942 11740 11844 6796 9213 10866 7598 10051 10468 8318 10999 427 3173 11533 11903 435 11744 12064 11082 9570 10714 4559 4008 12306 6388 10587 12757 4398 616 3972 2838 2321 2094 5267 6882 184 9512 10275 10413 2166 11932 9067 282 9851 11373 12131 7538 12791 7260 553...

output:

1
1
6834
12914
1
1
11215
1
1
1

result:

ok 10 lines

Test #35:

score: 0
Accepted
time: 61ms
memory: 18568kb

input:

200000
51203 54598 51106 51124 54159 45816 49417 51679 55693 48518 50634 52079 44541 52019 50017 49349 48390 48303 44680 50108 51951 46206 53776 48553 46463 51310 43615 43748 48011 44580 52883 52735 52046 47186 52446 46180 43959 51526 44390 43589 45677 49730 44162 46249 44320 43649 49959 46167 49835...

output:

3751
39265
1
33930
66177440

result:

ok 5 lines

Test #36:

score: 0
Accepted
time: 55ms
memory: 23588kb

input:

1000000
1945 5741 27629 481 32390 31269 29984 12400 31453 10166 28170 26235 4699 21893 20951 5203 20761 11138 15137 5307 9835 664 15843 6925 22327 4960 32614 4154 18307 12562 8197 84 11601 18793 4821 19767 3098 22223 19975 29273 5155 1814 8665 21465 12492 21806 14792 18985 9761 27305 28272 32247 844...

output:

716379553

result:

ok single line: '716379553'

Test #37:

score: 0
Accepted
time: 59ms
memory: 23508kb

input:

1000000
36197 35627 92907 70400 4596 97834 21175 80349 92210 65840 44354 119490 70444 50611 67891 97304 44984 28487 24757 114303 10255 100570 7781 27002 44442 9620 86257 3702 45829 27821 72971 90267 97763 77370 36719 10022 12504 113226 87283 39915 55548 110163 28092 72837 32646 7677 61520 27149 2559...

output:

90402

result:

ok single line: '90402'

Test #38:

score: 0
Accepted
time: 58ms
memory: 23580kb

input:

1000000
31307 53776 76945 226523 127287 188771 182273 129303 234461 43116 231496 191643 107175 13206 216923 198336 166968 197507 220276 193257 119855 44770 200203 93267 23616 113258 47512 165784 5719 229647 34855 164210 197648 208888 42872 86652 232908 174967 128714 188116 202015 202706 159963 34318...

output:

1

result:

ok single line: '1'

Test #39:

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

input:

1000000
7809 32918 10621 33428 9881 6664 34393 28362 125 13502 8268 8686 5918 8014 37788 18305 25256 35336 25913 36708 7885 30237 8205 34310 19005 28415 8253 26102 21963 7779 13396 18201 28320 20197 38314 21805 7254 35151 31187 15493 14434 11460 36777 17845 7902 32269 13286 13963 6923 16027 11293 10...

output:

1

result:

ok single line: '1'

Test #40:

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

input:

1000000
140815 167066 15405 89690 28726 119382 93322 14257 133771 155216 175053 97895 171583 143533 99351 86824 65412 71816 125550 146535 170188 107962 54481 169908 169000 112260 117387 184520 169410 109565 131682 47232 59915 123229 226578 209573 87895 14360 25042 49982 113369 172602 185651 99450 73...

output:

1

result:

ok single line: '1'

Test #41:

score: 0
Accepted
time: 61ms
memory: 23592kb

input:

1000000
6451 31242 90377 4159 26335 60670 94960 6580 100880 32366 5169 8753 25569 41304 18204 87417 5601 56061 108843 25406 69363 37952 58714 10284 50040 29393 102341 71485 102355 103371 98312 96641 106594 4325 12648 33404 78706 69737 39538 85295 60328 60270 80631 45912 30632 87826 53539 44845 68629...

output:

1

result:

ok single line: '1'

Test #42:

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

input:

1000000
979318 979347 979403 979351 979323 979353 979389 979371 979362 979337 979355 979390 979331 979400 979370 979388 979360 979341 979345 979348 979330 979372 979375 979361 979374 979343 979325 979315 979316 979336 979339 979327 979382 979334 979364 979350 979333 979356 979397 979381 979367 97939...

output:

1

result:

ok single line: '1'

Test #43:

score: 0
Accepted
time: 58ms
memory: 23660kb

input:

1000000
595116 596195 596337 595302 596339 596139 595924 595192 595171 595459 595784 595511 595381 595846 596583 595076 596749 596758 595187 595170 596721 595671 596173 595802 596026 596242 596051 595746 596643 596042 596495 595565 596262 596747 594980 595346 596585 596276 595241 595474 595054 59557...

output:

1

result:

ok single line: '1'

Test #44:

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

input:

1000000
496943 499456 497627 499221 497403 498248 498182 497662 498826 497780 498572 499087 497097 498322 497586 498316 499158 498432 498229 499216 498243 499329 498100 498336 497230 499003 497589 497048 498419 499097 498660 497062 498721 499417 498683 498146 499489 497986 497288 496999 497122 49911...

output:

57014

result:

ok single line: '57014'

Test #45:

score: 0
Accepted
time: 55ms
memory: 23448kb

input:

1000000
541038 534906 543537 533896 540452 532553 535512 534771 536447 537547 543512 535496 540716 539965 539615 531129 534688 542593 535328 541545 541833 542866 530470 538063 536511 532061 536591 542348 538165 537964 541788 530273 533281 537508 536818 533666 533536 536075 536421 531640 539162 53726...

output:

74365110

result:

ok single line: '74365110'

Test #46:

score: 0
Accepted
time: 59ms
memory: 23588kb

input:

1000000
974544 974459 974474 974529 974455 974518 974471 974377 974552 974388 974504 974426 974473 974451 974493 974402 974457 974440 974546 974490 974416 974427 974444 974523 974508 974373 974565 974463 974517 974483 974452 974545 974532 974557 974383 974482 974449 974535 974374 974507 974524 97438...

output:

1

result:

ok single line: '1'

Test #47:

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

input:

1000000
382355 365350 345864 323389 359811 337855 375677 307466 382835 335186 390809 293979 344927 393010 314020 307174 366505 310577 388549 289988 315795 335319 349563 359862 368503 380877 312498 324640 292264 315885 355698 390688 321644 364738 330748 364021 349683 319868 306984 364082 291755 36951...

output:

1

result:

ok single line: '1'

Test #48:

score: 0
Accepted
time: 59ms
memory: 23596kb

input:

1000000
875025 875657 874895 875978 874980 875222 875216 875178 875500 875147 875087 875799 875597 875790 875274 875746 875509 875310 874925 875588 875369 875798 875958 875232 875724 875535 876041 874878 875383 875209 875206 875445 875632 875940 875876 875344 876028 875333 876023 875795 875547 87567...

output:

191042

result:

ok single line: '191042'

Test #49:

score: 0
Accepted
time: 59ms
memory: 23508kb

input:

1000000
772144 775718 775306 774592 772841 774068 772938 773682 775334 775513 775291 772764 774251 773941 771752 773923 771658 772024 773935 772420 771393 774274 772273 775579 773213 774203 774408 775451 773048 773506 773865 773497 772055 773588 771533 773029 774969 773607 773335 773707 773294 77298...

output:

1

result:

ok single line: '1'

Test #50:

score: 0
Accepted
time: 50ms
memory: 23588kb

input:

1000000
920582 918969 920220 920713 919792 921100 923157 922711 921693 921363 921517 919110 921829 917592 917132 920775 919510 921419 918820 920277 919965 920119 918934 919874 922396 917706 921249 917267 917313 921106 920839 920317 917756 923303 921318 920143 922078 922606 923262 921305 921021 92090...

output:

1

result:

ok single line: '1'

Test #51:

score: 0
Accepted
time: 59ms
memory: 23588kb

input:

1000000
973311 973068 973093 973169 973191 973053 973151 973161 973402 973320 973401 973119 973381 973384 973105 973047 973180 973118 973082 973243 973266 973385 973141 973215 973299 973164 973300 973321 973109 973027 973260 973408 973218 973281 973273 973224 973427 973190 973186 973050 973406 97324...

output:

1

result:

ok single line: '1'

Test #52:

score: 0
Accepted
time: 59ms
memory: 23660kb

input:

1000000
810832 810439 810990 813805 816343 802207 805573 807472 809052 811098 808554 806369 805088 808133 807268 811773 801205 804366 804131 805207 814051 801734 804658 805935 816801 809853 816227 812128 801121 806041 807696 801335 806874 806759 807749 805428 812593 803275 808944 811128 813454 81398...

output:

66801

result:

ok single line: '66801'

Test #53:

score: 0
Accepted
time: 59ms
memory: 23580kb

input:

1000000
747883 749861 753531 753849 749968 749107 751315 751867 749251 750378 753756 749195 753118 753754 751961 750187 752992 748385 751687 750449 749742 748008 753286 748635 753715 747770 748907 752025 749326 747670 748146 749512 750269 750795 752454 750061 749141 751600 748647 753629 750649 74852...

output:

48156

result:

ok single line: '48156'

Test #54:

score: 0
Accepted
time: 55ms
memory: 23588kb

input:

1000000
999683 999582 999446 999756 999366 999412 999872 999844 999472 999623 999536 999856 999828 999746 999866 999734 999709 999537 999871 999848 999638 999540 999437 999878 999662 999631 999892 999695 999677 999786 999799 999538 999791 999505 999427 999397 999650 999414 999376 999377 999862 99968...

output:

762843746

result:

ok single line: '762843746'

Test #55:

score: 0
Accepted
time: 59ms
memory: 23660kb

input:

1000000
999449 999253 999418 999202 999400 999190 999194 999310 999354 999185 999275 999232 999416 999211 999230 999372 999397 999184 999217 999179 999243 999338 999300 999247 999289 999412 999356 999440 999225 999291 999454 999304 999299 999277 999361 999443 999365 999171 999382 999351 999320 99942...

output:

1

result:

ok single line: '1'

Test #56:

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

input:

1000000
994012 994548 998613 996121 998544 998228 995436 996181 995728 995304 996993 993045 995634 995766 995603 996058 998385 994023 993008 996458 992095 992488 996975 998710 993600 998169 997862 991964 998240 994369 998623 995614 997115 992281 998526 994905 996823 994297 992221 991896 993258 99257...

output:

1

result:

ok single line: '1'

Test #57:

score: 0
Accepted
time: 61ms
memory: 27528kb

input:

1000000
732853 766985 839840 816839 828536 820691 717280 790411 700870 720999 728483 768616 747843 839829 836307 787071 795631 703654 752789 717590 804855 786544 829215 703505 727758 698789 741264 778907 814243 837749 703743 703880 744416 689846 748141 723078 820004 842448 739233 683382 710119 82382...

output:

1

result:

ok single line: '1'

Test #58:

score: 0
Accepted
time: 59ms
memory: 23656kb

input:

1000000
990241 990176 990573 990608 989279 988846 988470 991555 990484 988578 991939 990835 990876 989658 989951 988827 990988 988872 990931 991391 989686 991048 992360 990810 989396 990550 989268 990296 990479 989755 990513 988712 988723 990588 992292 991159 988715 990474 990340 991613 991618 99170...

output:

1

result:

ok single line: '1'

Test #59:

score: 0
Accepted
time: 59ms
memory: 23584kb

input:

1000000
972103 969491 971231 969233 969452 973483 974950 969083 972056 971779 975132 973605 968621 971788 971524 973552 974213 971926 969209 973611 968422 973149 970577 970634 971781 972368 971568 975061 973525 972352 969599 972806 970722 969185 968874 973500 971570 974944 969192 972443 971636 96946...

output:

1

result:

ok single line: '1'

Extra Test:

score: 0
Extra Test Passed