QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526924#1955. Double Rainbowsroid_03#AC ✓3ms5656kbC++2011.0kb2024-08-22 01:47:232024-08-22 01:47:23

Judging History

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

  • [2024-08-22 01:47:23]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:5656kb
  • [2024-08-22 01:47:23]
  • 提交

answer


#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T>using ind_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T>using ind_mset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<vl> vll;
template<class T> using maxpq = priority_queue<T>;
template<class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<class T> using vec1 = vector<T>;
template<class T> using vec2 = vector<vector<T>>;
template<class T> using vec3 = vector<vector<vector<T>>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i,b,a)  for(ll i =((b)-1);i>=(a);i--)
#define mem(a,x)   memset(a,x,sizeof(a))
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define sz(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(),(v).rend()
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fbo(a) find_by_order(a) //will give a-th largest element
#define ook(a) order_of_key(a) //will give no. of elements strictly lesser than a
#define sz(x) ((int)(x).size())
#define nzl(x) __builtin_clzll(x)
#define nzr(x) __builtin_ctzll(x)
#define setbits(x) __builtin_popcountll(x)
#define setbitsParity(x) __builtin_parityll(x) // 1 -> odd else 0 if even
#define umap unordered_map
#define uset unordered_set
#define nl "\n"
#define PI atan(1)*4
#define E 2.71828
#define yes {cout << "Yes" << endl; return;}
#define no {cout << "No" << endl; return;}
#define YES {cout << "Yes" << endl;}
#define NO {cout << "No" << endl;}
#define nyet {cout<<"-1"<<endl;return;}
#define mxe(v)  (*max_element(v.begin(),v.end()))
#define mne(v)  (*min_element(v.begin(),v.end()))
#define unq(v)  v.resize(distance(v.begin(), unique(v.begin(), v.end())));
#define ub upper_bound
#define lb lower_bound
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
#define outt(a) \
	  FOR(i,1,sz(a))            \
	  cout << a[i] << " "; \
	  cout << endl;
#define inn(a) \
	  FOR(i,1,sz(a))            \
	  cin>>a[i];
#define FAST_AF_BOI                \
	ios_base ::sync_with_stdio(0); \
	cin.tie(0);               \
	cout.tie(0);

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
	  x += 0x9e3779b97f4a7c15;//abk
	  x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
	  x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
	  return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
	  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
	  return splitmix64(x + FIXED_RANDOM);
  }
};
typedef gp_hash_table<long long,long long,custom_hash> fast_map;
typedef unordered_map<long long,long long,custom_hash> safe_map;

// ================================== i/o module ==================================
template <class T> void _print(T x){cerr<<x;};
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template<class T>void read(T &x){x=0;int f=0;char ch=getchar();while(ch<'0' || ch>'9')f|=(ch=='-'),ch=getchar();while(ch>='0' && ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();x=f? -x:x;return ;}
template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
template <class T> inline vector<T>& operator--(vector<T>& v) { for(auto &x:v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { for(auto &x:v) ++x; return v; }
template <class T> inline vector<T>& operator^=(vector<T>& v,int y) { for(auto &x:v) x^=y; return v; }
inline string& operator^=(string& s,int y) { for(auto &x:s)x=((x-'0')^y)+'0' ; return s; }

void dgb_out () { cerr << endl; }
template < typename Head, typename... Tail >
void dgb_out ( Head H, Tail... T) { cerr <<' ' << H; dgb_out (T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dgb_out(__VA_ARGS__) 
#else
#define dbg(...)
#endif

// ================================================================================

//`````````````````````````````````````````````IMP FUNCTIONS``````````````````````````````````````````````````````
ll ceil(ll a,ll b){return (a+b-1)/b;}
int log_2(ull i){return i?nzl(1)-nzl(i):-1;}
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll bin_expo(ll a, ll b, ll mod) {ll res = 1;a%=mod;if(a==0)return 0;while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll bin_mul(ll a, ll b, ll mod) {ll res = 0; while (b > 0) {if (b & 1)res = (res + a) % mod; a = (a + a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return bin_expo(a, b - 2, b);}
ll ncr(ll n, ll r, ll m, ll *fact, ll *ifact) {if(n<r)return 0;ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r];if(n < r) return 0;if(n == r || r == 0) return 1;if(r<0) return 0; return (((val1 * val2) % m) * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vl sieve(int n) {int*arr = new int[n + 1](); vl vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i*i <= n; i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
ll large_expo(ll a,ll b,ll c,ll m) {return bin_expo(a,bin_expo(b,c,phin(m)),m);} //(a^b^c)%M 
ll large_expo_prime(ll a,ll b,ll c,ll m) {return bin_expo(a,bin_expo(b,c,m-1),m);} //(a^b^c)%M when m is prime
template<class T>vector<T> prefixSum(vector<T> v, bool flag){vector<T> ans;T sum = 0;if (flag){for (auto &e : v){sum += e;ans.eb(sum);}}else{ans.pb(0);REP(i, v.size(), 0){sum += v[i];ans.eb(sum);}reverse(all(ans));}return ans;}
ll ffs(ll n){if(n==0)return -1;return log2(n & -n);}
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll uid(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
//````````````````````````````````````````````````````````````````````````````````````````````````````````````

const ll INF = 1e18 + 10;
const ll inf = 1e9 + 10;
const ll N = 30000 + 10;
const ll mod1 = (1e9 + 7);
const ll mod2 = (998244353);

/*
Self notes cause I need it :
1. dumbfk read the question properly ... I m fed up with this lack of presence of mind
2. dont assume that something is given in question ,like the input is sorted or stuff
   if some step needs the input to be sorted , either check question or sort , dont assume
3. in case you have less time to debug : 
	Common errors :
	  -> Wrote wrong variable names at places cause ur stupid	
	 -> For debugging u hard coded small values and submitted that solution right away
*/

#define int long long

void transcendent(int tc)
{
	int n, k; cin >> n >> k;
	vec1<int> a(n); cin >> a;
	fast_map cnt;
	int cur = 0, ncur = k;
	fast_map ncnt;
	for(auto &x : a) ncnt[x] ++;
	auto add = [&] (int x) {
		if(!cnt[x]) cur ++;
		cnt[x] ++;
	};
	auto rem = [&] (int x) {
		cnt[x] --;
		if(!cnt[x]) cur --;
	};
	auto add2 = [&] (int x) {
		if(!ncnt[x]) ncur ++;
		ncnt[x] ++;
	};
	auto rem2 = [&] (int x) {
		ncnt[x] --;
		if(!ncnt[x]) ncur --;
	};
	int ans = INF;
	for(int i = 0, j = 0; i < n; i ++) {
		add(a[i]);
		rem2(a[i]);
		while(cur == k and j < i and cnt[a[j]] > 1) rem(a[j]), add2(a[j]), j ++;
		if(cur == k and ncur == k) ckmin(ans, i - j + 1);
	}
	cout << (ans == INF? 0 : ans) << nl;
}

static void read(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}

int32_t main()
{
	//read();
	FAST_AF_BOI
	 auto begin = std::chrono::high_resolution_clock::now();
	cout << fixed << setprecision(12);
	cerr << fixed << setprecision(0);
	//clock_t timer;
	//timer = clock();
	//PreComp();
	int test = 1;
	// cin >> test;
	FOR(tc, 1, test + 1)
	{
			//cerr << endl << "----Test:" << tc << "----" <<endl;
			transcendent(tc);
	}
	auto end = std::chrono::high_resolution_clock::now();
	 auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
	 //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

2 1
1
1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3920kb

input:

10000 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 4388kb

input:

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

output:

5000

result:

ok single line: '5000'

Test #5:

score: 0
Accepted
time: 2ms
memory: 4644kb

input:

10000 5000
5000
4999
4998
4997
4996
4995
4994
4993
4992
4991
4990
4989
4988
4987
4986
4985
4984
4983
4982
4981
4980
4979
4978
4977
4976
4975
4974
4973
4972
4971
4970
4969
4968
4967
4966
4965
4964
4963
4962
4961
4960
4959
4958
4957
4956
4955
4954
4953
4952
4951
4950
4949
4948
4947
4946
4945
4944
4943...

output:

5000

result:

ok single line: '5000'

Test #6:

score: 0
Accepted
time: 2ms
memory: 4552kb

input:

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

output:

4999

result:

ok single line: '4999'

Test #7:

score: 0
Accepted
time: 2ms
memory: 4648kb

input:

10000 4999
4999
4999
4999
4997
4996
4995
4994
4993
4992
4991
4990
4989
4988
4987
4986
4985
4984
4983
4982
4981
4980
4979
4978
4977
4976
4975
4974
4973
4972
4971
4970
4969
4968
4967
4966
4965
4964
4963
4962
4961
4960
4959
4958
4957
4956
4955
4954
4953
4952
4951
4950
4949
4948
4947
4946
4945
4944
4943...

output:

4999

result:

ok single line: '4999'

Test #8:

score: 0
Accepted
time: 0ms
memory: 4428kb

input:

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

output:

5000

result:

ok single line: '5000'

Test #9:

score: 0
Accepted
time: 0ms
memory: 4544kb

input:

10000 5000
388
1361
2394
2422
486
1068
888
1674
932
1916
758
2261
1405
1266
1515
1007
1572
1023
2283
422
997
1274
1450
2118
1163
231
2420
1516
1697
1276
1094
1193
2307
2287
293
1740
1057
2467
1476
2314
2428
1743
1416
1229
2301
1604
266
1282
878
111
831
2411
1346
1710
386
1844
79
2078
1226
1546
513
1...

output:

5000

result:

ok single line: '5000'

Test #10:

score: 0
Accepted
time: 2ms
memory: 4476kb

input:

10000 5000
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
50
51
51
5...

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 2ms
memory: 4388kb

input:

10000 5000
5000
5000
4999
4999
4998
4998
4997
4997
4996
4996
4995
4995
4994
4994
4993
4993
4992
4992
4991
4991
4990
4990
4989
4989
4988
4988
4987
4987
4986
4986
4985
4985
4984
4984
4983
4983
4982
4982
4981
4981
4980
4980
4979
4979
4978
4978
4977
4977
4976
4976
4975
4975
4974
4974
4973
4973
4972
4972...

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 1ms
memory: 3720kb

input:

10000 2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
...

output:

2

result:

ok single line: '2'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3916kb

input:

10000 2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

output:

2

result:

ok single line: '2'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

10000 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 1ms
memory: 3780kb

input:

10000 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

2

result:

ok single line: '2'

Test #16:

score: 0
Accepted
time: 1ms
memory: 3772kb

input:

10000 2
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

output:

2

result:

ok single line: '2'

Test #17:

score: 0
Accepted
time: 1ms
memory: 3864kb

input:

10000 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

0

result:

ok single line: '0'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

10000 2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

output:

0

result:

ok single line: '0'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3728kb

input:

10000 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

2

result:

ok single line: '2'

Test #20:

score: 0
Accepted
time: 3ms
memory: 5656kb

input:

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

output:

0

result:

ok single line: '0'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3732kb

input:

10000 100
78
35
20
42
88
77
7
97
13
82
26
85
11
2
48
85
22
13
24
100
42
11
24
61
33
18
1
95
10
39
27
54
51
86
64
61
43
42
96
12
92
25
19
85
6
23
52
74
66
91
94
88
3
88
22
15
71
22
70
61
62
51
42
1
20
26
64
62
86
95
4
26
70
86
77
90
42
49
5
87
25
21
36
18
60
60
20
19
87
74
92
39
19
84
33
93
71
76
95
...

output:

230

result:

ok single line: '230'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

10000 200
77
133
141
49
164
136
31
18
95
184
52
74
92
57
100
185
151
64
169
131
168
181
103
145
41
93
99
73
153
196
174
193
103
148
11
176
32
126
105
145
82
122
158
3
153
13
139
181
156
153
97
182
149
125
64
148
81
186
187
104
163
198
8
15
124
22
42
11
116
200
15
148
156
25
91
44
60
166
155
79
140
1...

output:

779

result:

ok single line: '779'

Test #23:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

10000 300
129
75
71
112
153
224
220
41
194
285
141
39
153
296
53
64
196
27
147
130
100
91
1
102
111
158
105
53
11
212
151
27
243
108
65
58
197
212
282
244
286
169
129
52
114
64
111
127
88
139
199
191
137
25
162
219
160
52
160
250
59
124
280
287
222
261
104
240
118
205
171
31
54
115
210
60
77
91
105
...

output:

1382

result:

ok single line: '1382'

Test #24:

score: 0
Accepted
time: 1ms
memory: 3732kb

input:

10000 400
196
349
37
306
118
67
400
278
7
108
129
54
301
209
240
311
390
60
208
82
84
93
317
90
252
25
66
258
383
235
162
238
151
150
170
266
321
243
296
338
338
197
173
32
66
59
307
243
187
305
100
229
179
78
319
298
324
154
244
294
188
259
364
313
382
326
171
288
219
319
386
372
131
251
206
128
34...

output:

1713

result:

ok single line: '1713'

Test #25:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

10000 500
106
229
482
121
460
36
153
358
427
230
28
480
71
96
6
421
320
484
255
322
436
155
315
148
87
80
159
72
64
196
474
198
490
327
91
351
154
79
350
213
170
460
112
155
118
82
343
20
446
55
301
193
349
223
352
167
150
446
254
218
138
223
134
397
74
100
157
373
266
238
432
99
195
223
77
194
254
...

output:

2534

result:

ok single line: '2534'

Test #26:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

10000 600
306
202
391
284
110
578
252
577
194
402
577
282
598
212
280
420
578
513
183
167
214
501
594
337
125
283
147
407
84
329
495
166
178
289
496
299
469
187
447
324
401
488
140
521
304
266
102
165
569
211
573
162
274
432
25
271
515
265
556
192
496
600
1
497
383
434
83
293
133
45
181
233
32
162
3...

output:

3128

result:

ok single line: '3128'

Test #27:

score: 0
Accepted
time: 1ms
memory: 3984kb

input:

10000 700
377
291
123
562
45
16
138
478
211
148
627
606
645
117
55
166
337
477
416
472
547
240
33
171
480
639
254
44
520
203
434
588
595
141
244
524
255
575
637
22
563
108
50
670
694
249
161
432
476
561
460
269
108
31
184
435
684
555
30
53
297
144
252
28
142
154
691
132
381
159
181
670
178
531
70
33...

output:

4237

result:

ok single line: '4237'

Test #28:

score: 0
Accepted
time: 1ms
memory: 3996kb

input:

10000 800
602
508
604
246
697
722
279
100
787
215
119
637
106
61
298
451
250
713
66
268
344
477
30
365
354
231
696
498
613
579
157
130
633
46
779
288
780
117
310
80
201
753
690
181
148
58
162
454
503
308
180
487
371
686
358
48
746
220
499
630
194
112
741
241
236
173
106
174
268
194
485
313
768
493
2...

output:

3983

result:

ok single line: '3983'

Test #29:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

10000 900
69
425
161
895
267
298
447
122
759
279
632
646
779
239
819
700
491
271
859
31
237
206
2
379
776
334
309
586
398
6
401
37
715
283
751
899
860
324
601
368
824
328
197
679
646
780
543
134
630
411
104
734
762
339
854
683
78
210
30
633
621
239
479
19
556
497
227
851
535
67
132
402
385
598
292
4...

output:

0

result:

ok single line: '0'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

10000 1000
539
442
643
459
644
709
190
951
488
756
29
805
810
809
260
441
330
841
581
255
357
25
475
971
735
265
996
721
377
978
915
494
342
796
998
754
424
27
210
893
123
240
348
685
178
590
403
499
251
41
588
736
800
666
690
283
614
50
25
321
752
973
879
290
617
803
273
348
824
331
699
94
991
962
...

output:

0

result:

ok single line: '0'