QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801515#2955. Stable TableLaVuna47AC ✓3ms4812kbC++173.1kb2024-12-07 00:57:182024-12-07 00:57:19

Judging History

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

  • [2024-12-07 00:57:19]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:4812kb
  • [2024-12-07 00:57:18]
  • 提交

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif


int solve()
{
	int n,m;
	if(!(cin>>n>>m))
		return 1;
	vector<vector<ll>> a(n,vector<ll>(m));
	FOR(i,0,n)FOR(j,0,m)cin>>a[i][j];
	
	int ctr=0;
	{
		set<ll> S;
		FOR(i,0,n)FOR(j,0,m)S.insert(a[i][j]);
		unordered_map<ll,ll> I;
		for(auto item:S)I[item]=ctr++;
		FOR(i,0,n)FOR(j,0,m)a[i][j]=I[a[i][j]];
	}
	set<int> initial;
	FOR(i,0,m)initial.insert(a[0][i]);
	assert(sz(initial)<=2);

	vector<vector<pii>> I(ctr);
	FOR(i,0,n)FOR(j,0,m)I[a[i][j]].pb({i,j});

	vector<int> Dbot(ctr,1e8);
	{
		queue<int> Q;
		FOR(i,0,m) if(Dbot[a[n-1][i]]==1e8) Dbot[a[n-1][i]]=1, Q.push(a[n-1][i]);
		
		while(!Q.empty())
		{
			auto v = Q.front();
			Q.pop();
			for(auto [x,y]: I[v])
			{
				if(x-1>=0&& Dbot[a[x-1][y]]==1e8)
				{
					Dbot[a[x-1][y]]=Dbot[v]+1;
					Q.push(a[x-1][y]);
				}
			}
		}
	}
	
	int u = *initial.begin();
	int v = *initial.rbegin();
	if(u==v)
	{
		cout << Dbot[u]<<'\n';
		return 0;
	}
	
	auto Du = vector<int>(ctr,1e8);
	auto Dv = vector<int>(ctr,1e8);

	Du[u]=0, Dv[v]=0;

	{
		queue<int> Q;
		Q.push(u);
		while(!Q.empty())
		{
			auto vert=Q.front();
			Q.pop();
			
			for(auto [x,y]: I[vert])
			{
				if(x+1<n)
				{
					int to=a[x+1][y];
					if(Du[to]==1e8)
					{
						Du[to]=Du[vert]+1;
						Q.push(to);
					}
				}
			}
		}
	}
	{
		queue<int> Q;
		Q.push(v);
		while(!Q.empty())
		{
			auto vert=Q.front();
			Q.pop();
			
			for(auto [x,y]: I[vert])
			{
				if(x+1<n)
				{
					int to=a[x+1][y];
					if(Dv[to]==1e8)
					{
						Dv[to]=Dv[vert]+1;
						Q.push(to);
					}
				}
			}
		}
	}
	int res=Dbot[u]+Dbot[v];
	FOR(i,0,ctr)
	{
		if(Du[i]!=1e8&&Dv[i]!=1e8)
		{
			res=min(res,Du[i]+Dv[i]+Dbot[i]);
		}
	}
	cout<<res<<'\n';
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1e9;
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3624kb

input:

7 8
3 3 3 3 10 10 10 10
2 14 3 7 7 10 4 11
2 14 3 1 1 10 4 11
2 14 8 8 8 8 4 11
9 14 5 5 5 5 4 13
9 14 12 12 12 12 4 13
9 6 6 6 6 6 6 13

output:

5

result:

ok single line: '5'

Test #2:

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

input:

8 8
1 1 1 1 1 1 1 1
2 3 3 4 5 6 6 7
2 2 3 4 5 6 7 7
2 3 3 3 6 6 6 7
2 2 3 8 8 8 6 7
9 2 9 10 10 11 11 12
9 9 9 9 10 11 12 12
13 9 14 14 10 10 15 15

output:

3

result:

ok single line: '3'

Test #3:

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

input:

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

output:

4

result:

ok single line: '4'

Test #4:

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

input:

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

output:

7

result:

ok single line: '7'

Test #5:

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

input:

10 5
4 4 4 2 2
4 4 4 8 8
15 4 1 1 8
3 4 9 9 9
3 6 6 6 6
3 13 13 12 12
3 10 10 12 12
3 14 14 7 7
11 11 11 7 7
5 5 5 7 7

output:

7

result:

ok single line: '7'

Test #6:

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

input:

10 5
4 4 4 2 2
4 4 4 8 8
15 4 1 1 8
3 4 9 9 9
3 4 6 6 6
3 13 13 12 12
3 10 10 12 12
3 14 14 7 7
11 11 11 7 7
5 5 5 7 7

output:

8

result:

ok single line: '8'

Test #7:

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

input:

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

output:

6

result:

ok single line: '6'

Test #8:

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

input:

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

output:

100

result:

ok single line: '100'

Test #9:

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

input:

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

output:

200

result:

ok single line: '200'

Test #10:

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

input:

8 12
13 13 13 13 13 13 13 13 3 3 3 3
13 13 13 13 13 13 13 13 3 2 2 3
13 13 13 1 1 13 13 13 3 3 3 3
13 13 13 1 1 13 13 13 8 11 11 11
13 13 13 13 13 7 8 8 8 11 11 11
13 13 13 13 13 7 9 9 9 11 11 11
4 4 4 4 6 6 10 10 10 11 12 12
5 5 5 5 6 6 10 12 12 12 12 12

output:

5

result:

ok single line: '5'

Test #11:

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

input:

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

output:

75

result:

ok single line: '75'

Test #12:

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

input:

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

output:

6

result:

ok single line: '6'

Test #13:

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

input:

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

output:

4

result:

ok single line: '4'

Test #14:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
1 1 1 1 3 1 1 1 1 4 4 5 6 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 9 10 1 1 1 11 12 12 13 1 1...

output:

17

result:

ok single line: '17'

Test #15:

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

input:

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

output:

12

result:

ok single line: '12'

Test #16:

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

input:

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

output:

14

result:

ok single line: '14'

Test #17:

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

input:

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

output:

5

result:

ok single line: '5'

Test #18:

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

input:

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

output:

5

result:

ok single line: '5'

Test #19:

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

input:

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

output:

5

result:

ok single line: '5'

Test #20:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

101

result:

ok single line: '101'

Test #21:

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

input:

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

output:

2

result:

ok single line: '2'

Test #22:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 3...

output:

100

result:

ok single line: '100'

Test #23:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 3...

output:

99

result:

ok single line: '99'

Test #24:

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

input:

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

output:

4

result:

ok single line: '4'

Test #25:

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

input:

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

output:

4

result:

ok single line: '4'

Test #26:

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

input:

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

output:

5

result:

ok single line: '5'

Test #27:

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

input:

18 4
6 6 12 12
13 3 3 5
13 21 21 5
13 4 4 5
13 32 32 5
7 7 14 14
8 15 15 16
8 2 2 16
8 27 27 16
1 1 9 9
17 11 11 10
17 35 35 10
18 19 26 22
20 19 26 25
28 19 26 31
30 19 26 34
33 19 26 24
29 19 26 23

output:

12

result:

ok single line: '12'

Test #28:

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

input:

50 50
1 1 1 1 1 1 1 1 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
3 4 1 1 1 1 1 1 1 2 2 2 2 5 2 6 6 2 2 2 2 2 2 2 7 7 8 2 2 2 9 2 2 2 10 2 2 2 2 2 2 2 2 2 2 11 12 2 2 2
13 13 1 1 1 1 1 1 1 1 2 2 14 2 2 2 15 2 2 16 2 17 17 2 7 7 8 18 18 19 20 20 21 22 10 10 2 2...

output:

7

result:

ok single line: '7'

Test #29:

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

input:

75 75
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
1 3 4 5 1 1 1 1 1 1 1 1 1 1 1 1 6 6 6 7 8 8 9 9 9 10 10 10 2 11 12 13 14 2 2 2 2 2 15 2 2 2 2 2 2 2 16 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 17 ...

output:

13

result:

ok single line: '13'

Test #30:

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

input:

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

output:

9

result:

ok single line: '9'

Test #31:

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

input:

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

output:

28

result:

ok single line: '28'

Test #32:

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

input:

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

output:

5

result:

ok single line: '5'

Test #33:

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

input:

30 75
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 3 3 1 1 4 1 5 1 1 1 6 7 1 1 1 1 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 1 1 10 10 11 1 1 1 1 1 1 1 1 1 12 12 12 13 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

5

result:

ok single line: '5'