QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#5407#2019. 移球游戏Qingyu100 ✓30ms9284kbC++174.5kb2020-12-09 16:09:122021-12-19 06:16:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2021-12-19 06:16:44]
  • 评测
  • 测评结果:100
  • 用时:30ms
  • 内存:9284kb
  • [2020-12-09 16:09:12]
  • 提交

answer

#include <bits/stdc++.h>

inline int read() {
    int x = 0;
    register char ch = getchar();

    for (; !isdigit(ch); ch = getchar());

    for (; isdigit(ch); x = x * 10 + (ch & 15), ch = getchar());

    return x;
}
int st[20], TOP;
inline void write(int x) {
    if (!x)
        putchar(48);
    else {
        for (; x; st[++TOP] = x % 10, x /= 10);

        for (; TOP; putchar(st[TOP--] | 48));
    }
}
inline void writeln(int x) {
    write(x), putchar('\n');
}

const int MAXN = 55, MAXM = 410;

int n, m;
int S[MAXN], col0[MAXN], col1[MAXN], a[MAXN][MAXM];
std::vector <std::pair <int, int>> ans;
inline void move(int x, int y) {
    //printf("%d %d ",S[x],S[y]);
    assert(S[x] > 0);
    assert(S[y] < m);
    a[y][++S[y]] = a[x][S[x]], --S[x];
    ans.emplace_back(std::make_pair(x, y));
}
inline int size(int x) {
    return S[x];
}
inline int top(int x) {
    assert(S[x] > 0);
    return a[x][S[x]];
}
inline bool empty(int x) {
    return S[x] == 0;
}
inline bool full(int x) {
    return size(x) == m;
}
void solve(int L, int R, std::vector <int> vec) {
    if (L == R)
        return;

    int mid = (L + R) >> 1, len = R - L + 1;

    for (const auto &x : vec) {
        col0[x] = col1[x] = 0;

        for (int i = 1; i <= S[x]; ++i) {
            if (a[x][i] > mid)
                ++col1[x];
            else ++col0[x];

            assert(a[x][i] >= L && a[x][i] <= R);
        }
    }

#define col(x) (x > mid ? 1 : 0)

    for (int i = 0; i < len - 1; ++i) {
        int x = vec[i], y = vec[i + 1];
        int sx0 = col0[x], sx1 = col1[x], sy0 = col0[y], sy1 = col1[y];

        if (sx0 == 0 || sx1 == 0)
            continue;

        assert(sx0 + sx1 == m);
        assert(sy0 + sy1 == m);

        if (sx0 + sy0 > sx1 + sy1) {
            for (int i = 1; i <= sx0; ++i)
                move(y, n + 1);

            while (!empty(x))
                if (col(top(x)) == 0)
                    move(x, y);
                else
                    move(x, n + 1);

            assert(size(y) == m);
            assert(size(n + 1) == m);

            for (int i = 1; i <= m; ++i)
                move(y, x);

            for (int i = 1; i <= sx1; ++i)
                move(n + 1, y);

            for (int i = 1; i <= sx1; ++i)
                move(x, n + 1);

            assert(size(n + 1) == m);

            while (!empty(n + 1)) {
                if (full(x))
                    move(n + 1, y);
                else if (col(top(n + 1)) == 0)
                    move(n + 1, x);
                else
                    move(n + 1, y);
            }

            assert(size(x) == m);
            assert(size(y) == m);
            col0[x] = m, col1[x] = 0;
            col0[y] = sx0 + sy0 - m, col1[y] = sx1 + sy1;
        } else {
            for (int i = 1; i <= sx1; ++i)
                move(y, n + 1);

            while (!empty(x))
                if (col(top(x)) == 1)
                    move(x, y);
                else
                    move(x, n + 1);

            assert(size(y) == m);
            assert(size(n + 1) == m);

            for (int i = 1; i <= m; ++i)
                move(y, x);

            for (int i = 1; i <= sx0; ++i)
                move(n + 1, y);

            for (int i = 1; i <= sx0; ++i)
                move(x, n + 1);

            assert(size(n + 1) == m);

            while (!empty(n + 1)) {
                if (full(x))
                    move(n + 1, y);
                else if (col(top(n + 1)) == 1)
                    move(n + 1, x);
                else
                    move(n + 1, y);
            }

            assert(size(x) == m);
            assert(size(y) == m);
            col0[x] = 0, col1[x] = m;
            col0[y] = sx0 + sy0, col1[y] = sx1 + sy1 - m;
        }
    }

    std::vector <int> vec0, vec1;

    for (const auto &x : vec)
        if (col(top(x)) == 0)
            vec0.emplace_back(x);
        else
            vec1.emplace_back(x);

#undef col
    solve(L, mid, vec0), solve(mid + 1, R, vec1);
}

int main() { 
    n = read(), m = read();

    for (int i = 1; i <= n; ++i)
        S[i] = m;

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            a[i][j] = read();

    std::vector <int> vec;

    for (int i = 1; i <= n; ++i)
        vec.emplace_back(i);

    solve(1, n, vec);
    writeln((int)ans.size());

    for (const auto &x : ans)
        write(x.first), putchar(' '), writeln(x.second);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 1ms
memory: 3492kb

input:

2 20
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1

output:

81
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
1 3
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
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
3 2
1 3
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 1
3 2
3 2
3 2
3 2

result:

ok OK

Test #2:

score: 5
Accepted
time: 2ms
memory: 3500kb

input:

2 20
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1

output:

83
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
1 2
1 3
1 3
1 3
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
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
3 2
3 2
3 2
1 3
1 3
1 3
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 2
3 1
3 2
3 1
3 1
3 2

result:

ok OK

Test #3:

score: 5
Accepted
time: 0ms
memory: 3596kb

input:

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

output:

1919
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
1 2
1 11
1 2
1 11
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
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
11 2
11 2
1 11
1 11
11 1
11 1
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
3 11
3 11
3 11
3 11
3 11
3 11
2 3
2 3
2 3
2 3
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 3
2 3...

result:

ok OK

Test #4:

score: 5
Accepted
time: 2ms
memory: 3604kb

input:

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

output:

2092
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
1 11
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
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
11 2
1 11
11 1
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
3 11
3 11
3 11
3 11
2 11
2 3
2 3
2 3
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 3
3 2
3 2
3 2
3...

result:

ok OK

Test #5:

score: 5
Accepted
time: 2ms
memory: 3552kb

input:

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

output:

2231
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
2 11
1 11
1 11
1 2
1 11
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
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
11 2
11 2
11 2
1 11
1 11
1 11
11 1
11 1
11 1
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
11 2
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
3 11
2 3
2 11
2 3
2 3
2 11
2 3
2 3
2 3
2 3
2 3
...

result:

ok OK

Test #6:

score: 5
Accepted
time: 8ms
memory: 4268kb

input:

50 85
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 32 21 34 48 29 15 10 26 23 10 30 39 29 11 37 10 20 4 26 8 30 33 19 45 43 3 28 30 2 49 43 30 26 10 12 28 27 1 18 38 27 21 48 32 38 11 14 31 29 31 41 28 44 1 11 26 25 34 21 1 50 26 23 43 44 26 1 50 38 31
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 5 48 37...

output:

86213
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
1 2
1 2
1 2
1 51
1 2
1 2
1 2
1 51
1 2
1 2
1 51
1 51
1 2
1 51
1 2
1 51
1 51
1 2
1 2
1 2
1 2
1 2
1 2
1 51
1 51
1 2
1 2
1 2
1 51
1 2
1 2
1 51
1 51
1 2
1 2
1 51
1 51
1 2
1 2
1 2
1 2
1 51
1 2
1 2
1 51
1 2
1 2
...

result:

ok OK

Test #7:

score: 5
Accepted
time: 4ms
memory: 4256kb

input:

50 85
13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 44 35 37 50 30
19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 1 12 24 31 45 30 4 36 9 43 10 43 32 34 24 30 19 7 2 19 20 42 38 10 9 7 6 24 36 43 21 31 30 37 23 6 42 3 30 38 44 32 9 12 21 1 44 45 27 19 29 28 15 2 36 21 1 12 45 25 19 11 45 11 26 10 3 41 42 12...

output:

85888
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
1 51
1 51
1 51
1 51
1 51
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...

result:

ok OK

Test #8:

score: 5
Accepted
time: 4ms
memory: 4180kb

input:

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

output:

85800
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
1 51
1 51
1 2
1 2
1 2
1 2
1 2
1 2
1 51
1 51
1 51
1 2
1 51
1 51
1 51
1 2
1 51
1 51
1 51
1 2
1 51
1 51
1 2
1 2
1 2
1 2
1 51
1 51
1 51
1 2
1 2
1 2
1 51
1 2
1 2
1 51
1 2
1 2
1 51
1 2
1 2
1 51
1 2
1 51
1 2
1 51
1 2
1 2
1 51
1 2
1 2
1 2
1 2
1 51
1 51
1 2
1 51
1 51
1 2
1 51
1 2
1 2
1 2
1 51
1 2
1 51
1 51
1 51
1 51
1 51
...

result:

ok OK

Test #9:

score: 5
Accepted
time: 12ms
memory: 7676kb

input:

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

output:

303331
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #10:

score: 5
Accepted
time: 11ms
memory: 8664kb

input:

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

output:

305235
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #11:

score: 5
Accepted
time: 19ms
memory: 8660kb

input:

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

output:

302920
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #12:

score: 5
Accepted
time: 26ms
memory: 8396kb

input:

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

output:

301032
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #13:

score: 5
Accepted
time: 13ms
memory: 7612kb

input:

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

output:

305924
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #14:

score: 5
Accepted
time: 6ms
memory: 8404kb

input:

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

output:

306191
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #15:

score: 5
Accepted
time: 10ms
memory: 9184kb

input:

50 400
37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 3...

output:

404483
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #16:

score: 5
Accepted
time: 13ms
memory: 9000kb

input:

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

output:

406831
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #17:

score: 5
Accepted
time: 19ms
memory: 8396kb

input:

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

output:

405131
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #18:

score: 5
Accepted
time: 30ms
memory: 7464kb

input:

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

output:

408689
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Test #19:

score: 5
Accepted
time: 16ms
memory: 8404kb

input:

50 400
50 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 5...

output:

409227
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 51
3 5...

result:

ok OK

Test #20:

score: 5
Accepted
time: 19ms
memory: 9284kb

input:

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

415334
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 51
2 5...

result:

ok OK

Extra Test:

score: 0
Extra Test Passed