QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#559368#9185. Garden Decorationsucup-team004100 ✓6ms7148kbC++202.4kb2024-09-11 21:42:182024-09-11 21:42:19

Judging History

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

  • [2024-09-11 21:42:19]
  • 评测
  • 测评结果:100
  • 用时:6ms
  • 内存:7148kb
  • [2024-09-11 21:42:18]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

constexpr int MAXN = 500;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int w, N;
    std::cin >> w >> N;
    
    std::vector<int> a(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
        // a[i] = (i + 1) % N;
    }
    
    if (w == 0) {
        std::cout << 3 << "\n";
        return 0;
    }
    
    std::vector mat(3, std::vector(N, std::vector(N, 0)));
    for (int i = 0; i < N; i++) {
        mat[0][i][i] = 1;
        mat[1][i][a[i]] = 1;
        mat[2][i][i] = 1;
    }
    
    std::vector<std::array<int, 2>> op0, op2;
    for (int i = 0; i < N; i++) {
        if (mat[1][i][i] == 0) {
            for (int j = i + 1; j < N; j++) {
                if (mat[1][i][j] == 1) {
                    for (int k = 0; k < N; k++) {
                        mat[1][k][i] ^= mat[1][k][j];
                    }
                    op0.push_back({i, j});
                    break;
                }
            }
        }
        for (int j = i + 1; j < N; j++) {
            if (mat[1][j][i] == 1) {
                for (int k = i; k < N; k++) {
                    mat[1][j][k] ^= mat[1][i][k];
                }
                op2.push_back({i, j});
            }
        }
    }
    
    std::reverse(op0.begin(), op0.end());
    std::reverse(op2.begin(), op2.end());
    for (auto [i, j] : op0) {
        for (int k = j; k < N; k++) {
            mat[0][k][i] ^= mat[0][k][j];
        }
    }
    for (auto [i, j] : op2) {
        for (int k = 0; k <= i; k++) {
            mat[2][j][k] ^= mat[2][i][k];
        }
    }
    
    w--;
    if (w % 2 == 0) {
        std::vector<int> b(N);
        for (int i = 0; i < N; i++) {
            std::cin >> b[i];
            int x = 0;
            for (int j = 0; j <= i; j++) {
                if (mat[w][i][j]) {
                    x ^= b[j];
                }
            }
            std::cout << x << std::endl;
        }
    } else {
        std::vector<int> b(N);
        for (int i = N - 1; i >= 0; i--) {
            std::cin >> b[i];
            int x = 0;
            for (int j = i; j < N; j++) {
                if (mat[w][i][j]) {
                    x ^= b[j];
                }
            }
            std::cout << x << std::endl;
        }
    }
    
    return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3752kb

input:

0

output:

3

input:

1 2
1 0
0
1

output:

0
1

input:

2 2
1 0
1
0

output:

1
1

input:

3 2
1 0
1
1

output:

1
0

result:

points 1.0 W = 3

Test #2:

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

input:

0

output:

3

input:

1 2
0 1
1
0

output:

1
0

input:

2 2
0 1
0
1

output:

0
1

input:

3 2
0 1
1
0

output:

1
0

result:

points 1.0 W = 3

Test #3:

score: 10
Accepted
time: 1ms
memory: 3804kb

input:

0

output:

3

input:

1 2
1 0
1
0

output:

1
1

input:

2 2
1 0
1
1

output:

1
0

input:

3 2
1 0
0
1

output:

0
1

result:

points 1.0 W = 3

Test #4:

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

input:

0

output:

3

input:

1 2
1 0
0
0

output:

0
0

input:

2 2
1 0
0
0

output:

0
0

input:

3 2
1 0
0
0

output:

0
0

result:

points 1.0 W = 3

Test #5:

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

input:

0

output:

3

input:

1 2
1 0
1
1

output:

1
0

input:

2 2
1 0
0
1

output:

0
1

input:

3 2
1 0
1
0

output:

1
1

result:

points 1.0 W = 3

Test #6:

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

input:

0

output:

3

input:

1 2
0 1
0
1

output:

0
1

input:

2 2
0 1
1
0

output:

1
0

input:

3 2
0 1
0
1

output:

0
1

result:

points 1.0 W = 3

Test #7:

score: 10
Accepted
time: 1ms
memory: 3568kb

input:

0

output:

3

input:

1 2
1 0
1
1

output:

1
0

input:

2 2
1 0
0
1

output:

0
1

input:

3 2
1 0
1
0

output:

1
1

result:

points 1.0 W = 3

Test #8:

score: 10
Accepted
time: 1ms
memory: 3568kb

input:

0

output:

3

input:

1 2
1 0
1
1

output:

1
0

input:

2 2
1 0
0
1

output:

0
1

input:

3 2
1 0
1
0

output:

1
1

result:

points 1.0 W = 3

Test #9:

score: 10
Accepted
time: 1ms
memory: 3812kb

input:

0

output:

3

input:

1 2
1 0
0
1

output:

0
1

input:

2 2
1 0
1
0

output:

1
1

input:

3 2
1 0
1
1

output:

1
0

result:

points 1.0 W = 3

Test #10:

score: 10
Accepted
time: 1ms
memory: 3776kb

input:

0

output:

3

input:

1 2
1 0
1
0

output:

1
1

input:

2 2
1 0
1
1

output:

1
0

input:

3 2
1 0
0
1

output:

0
1

result:

points 1.0 W = 3

Test #11:

score: 10
Accepted
time: 1ms
memory: 3812kb

input:

0

output:

3

input:

1 2
1 0
1
0

output:

1
1

input:

2 2
1 0
1
1

output:

1
0

input:

3 2
1 0
0
1

output:

0
1

result:

points 1.0 W = 3

Test #12:

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

input:

0

output:

3

input:

1 2
1 0
1
0

output:

1
1

input:

2 2
1 0
1
1

output:

1
0

input:

3 2
1 0
0
1

output:

0
1

result:

points 1.0 W = 3

Test #13:

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

input:

0

output:

3

input:

1 2
1 0
0
1

output:

0
1

input:

2 2
1 0
1
0

output:

1
1

input:

3 2
1 0
1
1

output:

1
0

result:

points 1.0 W = 3

Subtask #2:

score: 24
Accepted

Test #14:

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

input:

0

output:

3

input:

1 3
2 1 0
1
1
1

output:

1
1
0

input:

2 3
2 1 0
0
1
1

output:

0
1
1

input:

3 3
2 1 0
1
1
0

output:

1
1
1

result:

points 1.0 W = 3

Test #15:

score: 24
Accepted
time: 1ms
memory: 3756kb

input:

0

output:

3

input:

1 4
2 0 3 1
1
0
0
1

output:

1
0
1
0

input:

2 4
2 0 3 1
0
1
0
1

output:

0
1
1
0

input:

3 4
2 0 3 1
0
1
1
0

output:

0
1
1
0

result:

points 1.0 W = 3

Test #16:

score: 24
Accepted
time: 1ms
memory: 3576kb

input:

0

output:

3

input:

1 5
4 0 1 2 3
1
1
1
1
0

output:

1
1
1
1
0

input:

2 5
4 0 1 2 3
0
1
1
1
1

output:

0
1
0
1
0

input:

3 5
4 0 1 2 3
0
1
0
1
0

output:

0
1
1
1
1

result:

points 1.0 W = 3

Test #17:

score: 24
Accepted
time: 1ms
memory: 3568kb

input:

0

output:

3

input:

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

output:

1
0
0
0
0
1
1
0
1
0
1
0
1
0
1

input:

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

output:

1
1
0
1
0
0
1
0
0
0
0
0
0
0
1

input:

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

output:

1
0
0
0
0
1
0
0
1
0
0
1
0
1
0

result:

points 1.0 W = 3

Test #18:

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

input:

0

output:

3

input:

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

output:

1
0
0
1
1
0
1
1
0
0
1
1
1
0

input:

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

output:

0
1
1
0
1
1
1
1
1
0
0
0
1
1

input:

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

output:

1
1
0
0
1
1
1
1
0
0
0
0
1
0

result:

points 1.0 W = 3

Test #19:

score: 24
Accepted
time: 1ms
memory: 3812kb

input:

0

output:

3

input:

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

output:

1
1
0
0
0
1
1
0
1
1
0
1
0
1
1

input:

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

output:

1
0
1
0
0
1
0
0
0
1
1
0
0
0
1

input:

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

output:

1
0
0
0
1
1
0
1
0
1
1
0
1
0
0

result:

points 1.0 W = 3

Test #20:

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

input:

0

output:

3

input:

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

output:

0
0
0
1
1
0
0
1
1
1
1
1
0
0

input:

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

output:

0
0
1
0
0
0
1
0
0
1
0
0
1
0

input:

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

output:

0
1
0
0
1
0
1
0
0
0
0
1
1
1

result:

points 1.0 W = 3

Test #21:

score: 24
Accepted
time: 1ms
memory: 3816kb

input:

0

output:

3

input:

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

output:

0
0
1
0
0
0
1
0
0
1
1
0
0
0

input:

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

output:

0
0
0
1
1
1
0
1
0
1
1
1
1
1

input:

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

output:

1
1
1
1
1
0
1
1
0
0
0
0
1
0

result:

points 1.0 W = 3

Test #22:

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

input:

0

output:

3

input:

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

output:

1
1
0
1
0
1
0
0
1
0
1
1
0
1
0

input:

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

output:

0
1
0
1
1
0
1
0
0
1
0
1
0
1
1

input:

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

output:

1
1
0
1
0
1
0
0
1
0
1
1
0
1
0

result:

points 1.0 W = 3

Test #23:

score: 24
Accepted
time: 1ms
memory: 3812kb

input:

0

output:

3

input:

1 3
1 2 0
1
1
1

output:

1
0
1

input:

2 3
1 2 0
1
0
1

output:

1
1
1

input:

3 3
1 2 0
1
1
1

output:

1
1
1

result:

points 1.0 W = 3

Test #24:

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

input:

0

output:

3

input:

1 3
2 0 1
0
0
0

output:

0
0
0

input:

2 3
2 0 1
0
0
0

output:

0
0
0

input:

3 3
2 0 1
0
0
0

output:

0
0
0

result:

points 1.0 W = 3

Subtask #3:

score: 9
Accepted

Test #25:

score: 9
Accepted
time: 6ms
memory: 7148kb

input:

0

output:

3

input:

1 500
499 498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 42...

output:

0
1
0
0
1
0
0
1
0
1
1
1
0
0
0
0
0
0
1
0
1
1
0
1
0
0
0
0
0
0
0
1
0
1
0
0
0
1
1
1
0
0
1
1
0
0
1
0
0
1
0
0
0
0
1
0
0
0
1
1
1
0
0
0
0
0
1
1
0
0
1
1
1
1
0
1
1
0
1
0
0
1
0
1
1
0
1
0
1
1
0
1
1
0
1
1
0
0
1
1
1
1
1
1
1
0
0
0
1
1
1
0
0
1
0
0
1
0
1
0
0
1
0
0
1
0
0
0
1
0
0
1
0
0
1
0
1
1
0
1
1
1
0
1
1
0
1
1
1
1
...

input:

2 500
499 498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 42...

output:

0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
1
0
0
1
1
0
0
1
1
1
0
1
0
0
1
1
0
0
0
1
0
0
1
0
0
0
0
1
1
1
0
0
0
0
1
0
0
1
0
1
1
0
1
1
1
0
0
0
1
0
0
0
0
1
1
1
0
0
0
1
1
0
0
0
1
1
0
0
0
1
1
1
0
1
1
1
0
1
0
1
1
0
0
1
1
1
0
0
0
1
1
0
0
0
1
1
0
0
0
1
1
1
1
1
1
0
0
1
0
0
1
0
0
1
0
1
0
1
1
1
1
0
0
1
0
0
...

input:

3 500
499 498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 42...

output:

0
1
0
1
1
1
0
1
0
1
1
1
0
0
0
0
0
0
0
0
1
1
0
0
1
0
0
1
1
0
0
0
1
0
0
1
0
1
0
0
0
0
1
0
0
0
0
0
0
1
0
1
1
1
1
0
0
0
0
1
1
1
0
1
1
0
0
0
1
0
1
1
0
1
0
1
1
1
0
1
0
1
0
0
0
0
1
0
0
0
0
1
1
1
0
0
0
1
0
0
1
0
1
0
0
0
0
1
0
0
1
0
0
0
1
0
1
0
0
1
0
1
0
1
0
1
1
1
0
0
0
0
0
0
0
0
1
0
0
0
1
0
1
0
0
0
1
0
1
1
...

result:

points 1.0 W = 3

Test #26:

score: 9
Accepted
time: 6ms
memory: 7004kb

input:

0

output:

3

input:

1 499
498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 42...

output:

0
0
1
1
0
0
0
1
0
0
0
0
0
0
1
0
0
0
1
1
1
1
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
0
1
1
0
1
0
1
1
1
1
0
1
0
1
0
0
1
0
1
1
1
0
0
0
1
1
1
0
0
0
0
1
0
0
0
1
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
1
0
1
0
0
0
0
1
0
0
0
0
0
1
1
0
0
1
0
0
0
0
0
0
0
0
0
1
1
1
0
0
0
1
1
1
1
1
0
0
0
0
1
1
1
0
1
1
0
1
0
1
1
0
0
0
1
1
0
1
0
0
...

input:

2 499
498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 42...

output:

1
0
1
0
1
0
0
0
1
0
1
0
0
1
0
0
0
0
0
0
1
0
0
1
1
0
0
1
0
0
1
1
1
0
0
0
0
1
1
0
1
0
0
1
1
1
0
1
1
1
0
1
1
1
1
0
1
1
0
0
0
0
1
1
0
0
1
1
1
0
0
1
1
1
0
0
1
0
1
1
0
0
1
0
0
1
1
0
0
1
0
0
0
0
1
0
1
0
1
0
0
0
1
1
0
0
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
0
1
1
0
1
0
1
1
1
1
0
1
1
0
1
1
0
1
1
1
0
1
1
1
0
1
0
...

input:

3 499
498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 42...

output:

1
0
0
1
1
0
0
1
1
0
1
0
0
1
1
0
0
0
1
1
0
1
0
1
1
0
0
1
0
0
1
0
1
1
0
1
0
1
0
1
1
1
0
0
0
0
1
1
0
1
1
1
1
0
1
1
0
0
0
0
0
1
0
0
0
0
1
1
0
0
0
1
0
0
0
1
0
1
0
0
1
1
0
0
1
1
0
1
1
1
1
0
0
0
1
1
1
0
1
0
0
1
0
1
0
1
0
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
1
0
0
0
1
0
1
0
0
0
0
0
0
0
0
1
1
0
1
1
0
0
0
1
1
1
0
...

result:

points 1.0 W = 3

Subtask #4:

score: 13
Accepted

Test #27:

score: 13
Accepted
time: 4ms
memory: 7128kb

input:

0

output:

3

input:

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

output:

1
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
1
1
1
0
1
1
1
1
0
1
0
0
1
0
0
1
0
1
0
0
0
0
0
0
1
1
0
1
0
1
1
0
1
1
1
0
1
0
0
1
0
1
0
1
1
0
1
0
1
0
1
0
0
1
0
1
0
0
1
0
1
1
0
0
1
0
1
1
0
1
0
0
1
0
1
0
0
1
1
0
1
0
1
1
1
1
1
0
0
0
1
1
1
1
0
0
1
0
1
1
0
0
1
0
1
1
1
0
0
0
1
1
0
1
1
0
0
0
0
1
1
0
1
0
0
0
0
...

input:

2 500
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 100 10...

output:

1
0
0
1
1
0
0
0
1
0
1
0
0
0
1
1
0
0
0
1
1
0
1
1
0
0
1
1
1
0
0
0
0
1
0
0
0
1
1
1
0
1
1
1
1
1
0
1
0
0
1
0
0
0
1
1
1
0
1
1
1
0
0
1
0
0
1
0
1
1
0
0
0
1
0
1
0
0
0
0
1
0
1
1
1
0
1
0
0
0
1
0
1
0
1
0
0
1
1
1
0
0
1
1
0
0
1
0
1
1
1
1
1
1
0
1
1
0
0
1
0
1
1
0
1
0
1
1
1
1
0
1
0
0
1
1
0
0
0
0
0
0
0
0
0
1
0
1
1
0
...

input:

3 500
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 100 10...

output:

1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
0
1
1
0
0
0
1
1
1
0
1
1
0
1
1
1
1
0
0
0
0
0
1
0
1
1
1
1
0
1
1
0
0
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
0
1
0
1
1
1
0
1
1
1
0
1
1
1
1
0
1
0
1
1
1
1
0
0
0
0
1
0
0
1
0
0
0
1
0
1
1
1
0
1
0
1
1
1
0
0
1
0
0
1
0
1
1
0
1
0
0
0
1
0
1
1
1
0
0
0
0
...

result:

points 1.0 W = 3

Test #28:

score: 13
Accepted
time: 6ms
memory: 7108kb

input:

0

output:

3

input:

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

output:

0
0
1
0
0
0
1
0
0
0
1
0
1
0
1
0
1
1
1
0
1
0
1
1
0
0
0
0
0
1
1
1
0
0
1
0
1
0
0
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
0
1
0
0
1
1
0
1
0
1
1
1
1
1
1
0
0
1
1
1
0
0
1
1
1
1
0
1
0
0
0
0
1
0
1
0
1
0
1
0
0
1
0
0
0
1
1
0
0
1
1
1
1
0
1
0
1
1
1
1
0
0
0
0
0
0
0
0
1
0
1
0
1
1
0
0
1
0
1
0
0
0
1
1
1
0
0
1
0
0
1
1
1
0
0
0
...

input:

2 499
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 100 10...

output:

1
0
0
1
1
1
0
1
0
1
1
0
0
1
1
1
0
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
1
0
1
1
0
0
1
0
0
1
1
0
1
1
1
1
1
0
1
1
0
1
0
1
0
0
1
0
0
0
1
1
1
0
0
1
1
0
0
0
0
1
1
0
0
1
0
1
1
0
1
1
0
0
1
0
1
0
0
0
0
0
0
0
1
1
0
0
1
0
0
1
0
1
1
1
0
0
0
1
0
1
0
1
1
1
1
1
1
1
1
0
1
1
0
1
0
0
0
0
1
1
1
1
0
0
1
0
0
...

input:

3 499
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 100 10...

output:

0
1
1
0
0
1
1
0
0
1
1
1
1
1
1
1
0
0
1
1
1
1
0
1
0
0
0
0
1
0
0
1
0
1
1
1
1
0
1
0
1
1
0
0
0
0
0
0
0
0
0
1
1
1
1
1
0
1
0
1
1
1
1
0
0
0
0
0
1
0
1
0
0
1
0
1
0
0
0
1
1
1
0
0
0
1
1
1
1
1
1
1
1
0
1
1
0
0
1
0
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
0
0
0
0
0
0
1
1
1
1
1
0
1
0
1
1
1
1
0
0
1
0
0
1
0
1
1
0
1
0
0
1
0
0
1
...

result:

points 1.0 W = 3

Subtask #5:

score: 13
Accepted

Test #29:

score: 13
Accepted
time: 3ms
memory: 7072kb

input:

0

output:

3

input:

1 500
499 0 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:

1
0
1
1
0
1
1
0
1
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
0
0
1
1
1
1
0
0
1
1
1
1
0
1
1
1
1
1
0
1
0
0
1
0
1
1
0
0
1
0
1
0
0
0
0
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
0
0
0
0
0
1
1
1
1
0
0
0
0
0
1
1
0
1
1
0
1
1
1
1
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
1
1
0
0
0
1
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
0
1
1
...

input:

2 500
499 0 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
0
1
1
1
1
0
0
0
0
1
1
1
1
1
0
1
1
0
0
1
1
0
1
0
1
0
1
1
1
0
1
1
0
1
1
1
1
1
1
0
1
1
1
0
0
0
1
1
0
0
0
1
0
1
0
0
1
1
1
1
1
1
1
0
0
1
1
0
1
0
0
1
0
1
1
1
1
1
0
1
0
0
1
0
0
1
1
0
1
0
1
0
0
0
1
0
1
0
1
0
0
0
1
1
1
1
1
1
1
1
0
1
0
0
1
0
1
1
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
1
1
0
0
1
0
0
0
1
1
1
0
0
1
0
0
...

input:

3 500
499 0 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:

1
1
0
1
1
0
1
1
0
1
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
0
0
1
1
1
1
0
0
1
1
1
1
0
1
1
1
1
1
0
1
0
0
1
0
1
1
0
0
1
0
1
0
0
0
0
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
0
0
0
0
0
1
1
1
1
0
0
0
0
0
1
1
0
1
1
0
1
1
1
1
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
1
1
0
0
0
1
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
0
1
...

result:

points 1.0 W = 3

Test #30:

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

input:

0

output:

3

input:

1 499
498 0 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
0
1
0
0
1
0
0
0
1
1
1
0
1
1
1
0
1
1
1
0
0
1
0
0
1
0
1
0
0
1
0
1
0
0
0
1
0
0
1
1
1
0
1
0
1
0
1
0
0
0
1
0
0
1
0
0
0
0
1
0
0
1
1
0
1
1
1
0
0
1
1
0
0
1
1
0
0
0
1
0
0
0
1
0
1
0
1
1
1
1
1
0
1
0
1
0
1
1
0
1
1
0
1
1
0
0
1
1
1
0
1
0
0
1
0
1
0
1
0
0
1
1
0
0
1
0
0
1
1
0
0
1
0
1
0
0
0
1
0
0
0
0
1
1
1
0
0
0
0
...

input:

2 499
498 0 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
1
0
0
1
0
0
0
1
1
0
1
0
0
0
0
1
0
1
1
1
0
0
1
0
0
0
0
0
0
0
0
1
0
1
1
0
0
1
0
1
1
1
1
0
1
0
0
0
1
1
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
1
1
1
1
1
0
1
1
0
0
0
0
1
1
1
1
0
0
0
1
1
0
0
0
1
0
0
1
1
1
1
1
0
0
0
0
0
1
0
0
1
1
1
0
0
0
1
0
1
1
0
0
0
0
0
1
0
0
0
0
0
0
1
1
1
0
0
1
1
1
1
0
0
1
1
0
0
1
1
1
0
1
1
...

input:

3 499
498 0 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
0
0
1
0
0
1
0
0
0
1
1
1
0
1
1
1
0
1
1
1
0
0
1
0
0
1
0
1
0
0
1
0
1
0
0
0
1
0
0
1
1
1
0
1
0
1
0
1
0
0
0
1
0
0
1
0
0
0
0
1
0
0
1
1
0
1
1
1
0
0
1
1
0
0
1
1
0
0
0
1
0
0
0
1
0
1
0
1
1
1
1
1
0
1
0
1
0
1
1
0
1
1
0
1
1
0
0
1
1
1
0
1
0
0
1
0
1
0
1
0
0
1
1
0
0
1
0
0
1
1
0
0
1
0
1
0
0
0
1
0
0
0
0
1
1
1
0
0
0
...

result:

points 1.0 W = 3

Subtask #6:

score: 31
Accepted

Test #31:

score: 31
Accepted
time: 6ms
memory: 7112kb

input:

0

output:

3

input:

1 500
285 191 63 156 100 260 361 355 8 0 91 328 136 126 224 358 13 449 148 467 153 378 129 360 295 496 213 430 337 258 140 456 367 33 364 340 184 366 248 412 159 176 421 160 150 185 379 489 19 97 171 85 413 220 437 396 107 300 5 446 203 25 401 35 279 442 169 451 475 167 486 103 71 494 334 79 327 146...

output:

0
1
1
0
0
1
1
0
0
1
0
1
1
0
0
0
0
0
1
0
0
0
1
1
0
0
0
1
1
1
0
1
1
1
0
1
0
0
0
0
0
1
1
0
1
1
0
0
1
1
0
1
0
1
1
0
1
1
1
1
0
1
0
0
1
1
1
0
0
0
1
0
0
1
0
1
0
0
1
0
1
0
0
1
1
1
1
0
1
1
0
0
1
1
1
1
1
1
0
1
1
0
0
0
0
0
0
0
1
0
1
1
1
0
0
1
1
0
0
1
0
1
1
1
0
1
1
1
0
1
0
0
1
0
1
0
1
0
0
0
1
1
0
0
0
0
0
0
1
0
...

input:

2 500
285 191 63 156 100 260 361 355 8 0 91 328 136 126 224 358 13 449 148 467 153 378 129 360 295 496 213 430 337 258 140 456 367 33 364 340 184 366 248 412 159 176 421 160 150 185 379 489 19 97 171 85 413 220 437 396 107 300 5 446 203 25 401 35 279 442 169 451 475 167 486 103 71 494 334 79 327 146...

output:

1
1
0
1
1
0
0
0
0
0
0
1
1
1
1
0
0
0
1
0
0
1
1
0
1
0
1
1
0
1
1
0
1
0
1
0
1
0
0
0
1
0
1
0
1
1
1
0
0
1
1
1
1
1
1
0
1
1
0
1
1
0
0
1
0
1
0
1
1
1
1
0
0
1
0
1
0
0
0
1
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
0
1
1
0
0
1
1
0
1
0
0
1
1
0
0
0
0
0
1
1
1
1
0
0
0
0
0
0
0
0
1
1
1
0
0
0
1
0
0
0
1
1
1
0
1
0
0
1
1
1
1
1
1
1
0
...

input:

3 500
285 191 63 156 100 260 361 355 8 0 91 328 136 126 224 358 13 449 148 467 153 378 129 360 295 496 213 430 337 258 140 456 367 33 364 340 184 366 248 412 159 176 421 160 150 185 379 489 19 97 171 85 413 220 437 396 107 300 5 446 203 25 401 35 279 442 169 451 475 167 486 103 71 494 334 79 327 146...

output:

1
1
1
1
1
0
0
1
0
0
0
0
0
1
0
1
0
1
0
0
1
1
0
1
1
0
0
1
0
0
1
1
1
1
0
1
1
1
1
0
1
0
1
0
0
1
0
1
0
0
1
0
0
1
0
0
1
0
1
0
1
0
0
1
1
0
1
0
0
0
0
0
0
0
0
1
0
0
1
1
1
1
1
1
0
1
1
0
1
0
0
1
0
0
1
0
0
0
1
0
0
1
1
0
0
1
0
0
0
1
0
0
1
1
1
1
1
1
0
1
1
0
1
0
0
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
1
0
1
0
0
1
0
1
1
...

result:

points 1.0 W = 3

Test #32:

score: 31
Accepted
time: 5ms
memory: 7072kb

input:

0

output:

3

input:

1 499
268 194 277 346 145 186 138 205 120 126 254 102 229 381 49 270 197 458 123 410 68 23 371 490 432 208 377 325 272 175 99 481 209 35 487 267 155 292 215 335 67 398 392 46 28 59 105 498 185 183 89 70 303 250 391 141 379 136 51 423 71 54 113 293 386 55 442 331 475 214 470 316 12 5 301 211 317 39 3...

output:

0
0
0
1
1
1
1
1
1
0
0
1
0
1
0
0
0
1
1
0
1
0
1
0
1
0
1
1
1
0
1
1
0
1
0
1
1
0
1
0
0
0
1
0
1
0
0
0
0
1
1
0
1
1
1
0
1
1
0
0
1
1
1
1
1
0
1
0
0
0
1
1
1
0
1
1
1
1
1
0
1
0
1
0
1
0
0
1
1
0
1
1
1
1
0
0
0
0
1
1
0
0
0
1
0
0
1
1
1
1
1
1
1
1
1
1
0
1
0
1
1
0
0
1
1
0
0
0
0
1
0
0
0
0
0
1
0
1
0
0
0
1
1
1
1
0
1
1
0
0
...

input:

2 499
268 194 277 346 145 186 138 205 120 126 254 102 229 381 49 270 197 458 123 410 68 23 371 490 432 208 377 325 272 175 99 481 209 35 487 267 155 292 215 335 67 398 392 46 28 59 105 498 185 183 89 70 303 250 391 141 379 136 51 423 71 54 113 293 386 55 442 331 475 214 470 316 12 5 301 211 317 39 3...

output:

1
1
1
1
0
0
1
0
1
0
1
0
1
1
0
0
1
0
1
1
0
0
1
0
0
1
0
0
1
1
0
0
1
1
1
1
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
0
0
1
0
0
1
1
0
0
0
0
0
0
0
0
1
0
1
0
0
0
0
1
1
1
0
0
0
1
1
0
0
0
0
1
1
0
1
1
0
0
0
1
1
1
0
1
0
0
1
0
1
0
0
1
0
0
0
0
0
1
1
1
0
1
1
0
1
1
0
0
0
1
1
1
0
1
0
0
0
0
0
0
0
0
1
1
1
0
1
0
1
1
0
0
0
1
0
0
...

input:

3 499
268 194 277 346 145 186 138 205 120 126 254 102 229 381 49 270 197 458 123 410 68 23 371 490 432 208 377 325 272 175 99 481 209 35 487 267 155 292 215 335 67 398 392 46 28 59 105 498 185 183 89 70 303 250 391 141 379 136 51 423 71 54 113 293 386 55 442 331 475 214 470 316 12 5 301 211 317 39 3...

output:

0
0
0
1
1
1
1
0
0
1
0
1
0
1
1
1
0
0
0
1
1
0
1
0
1
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
1
0
1
1
0
0
0
1
1
0
0
1
0
1
0
0
0
0
1
0
0
0
0
1
0
1
1
1
1
0
1
0
0
0
0
1
1
1
0
0
0
0
1
1
0
0
0
0
1
1
1
1
1
1
0
1
1
1
0
0
1
1
0
0
0
1
1
1
1
0
0
1
0
0
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
0
1
1
0
1
1
1
0
0
0
0
1
0
...

result:

points 1.0 W = 3

Test #33:

score: 31
Accepted
time: 5ms
memory: 7144kb

input:

0

output:

3

input:

1 500
30 5 174 168 64 74 256 422 29 325 149 67 414 442 429 110 179 331 287 484 329 494 118 431 180 82 104 90 283 230 242 418 129 352 106 493 222 365 272 167 148 401 72 402 140 134 172 374 259 56 28 6 458 9 19 382 282 160 77 301 66 432 296 328 318 451 32 169 111 131 314 238 88 233 122 154 276 341 225...

output:

1
0
0
0
0
0
1
1
1
0
0
1
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
1
0
0
1
0
0
0
0
0
0
1
0
0
0
1
0
0
1
1
0
0
1
1
1
0
1
0
1
0
0
1
1
0
1
1
0
0
0
0
1
0
0
1
1
1
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
1
1
1
0
1
1
0
0
0
0
0
1
0
0
0
0
0
0
1
0
1
0
1
0
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
1
0
0
0
0
0
1
0
1
1
1
0
0
1
0
...

input:

2 500
30 5 174 168 64 74 256 422 29 325 149 67 414 442 429 110 179 331 287 484 329 494 118 431 180 82 104 90 283 230 242 418 129 352 106 493 222 365 272 167 148 401 72 402 140 134 172 374 259 56 28 6 458 9 19 382 282 160 77 301 66 432 296 328 318 451 32 169 111 131 314 238 88 233 122 154 276 341 225...

output:

0
0
1
1
1
1
0
0
0
1
0
0
1
0
1
1
1
1
0
1
0
0
1
1
0
1
0
0
0
0
0
1
1
0
0
0
1
1
0
0
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
1
1
1
0
0
0
0
0
0
1
1
0
0
1
0
0
1
1
0
1
1
1
1
0
0
0
0
1
1
0
0
1
1
1
0
0
1
0
1
1
1
1
1
1
0
0
0
1
0
0
1
1
0
1
0
1
1
0
1
1
0
0
0
0
1
0
0
1
1
1
1
0
0
1
0
1
0
0
1
0
1
0
0
1
0
0
1
1
1
1
0
0
1
0
1
...

input:

3 500
30 5 174 168 64 74 256 422 29 325 149 67 414 442 429 110 179 331 287 484 329 494 118 431 180 82 104 90 283 230 242 418 129 352 106 493 222 365 272 167 148 401 72 402 140 134 172 374 259 56 28 6 458 9 19 382 282 160 77 301 66 432 296 328 318 451 32 169 111 131 314 238 88 233 122 154 276 341 225...

output:

0
0
1
0
0
0
0
1
1
1
0
1
0
0
1
0
0
0
0
0
0
0
0
0
1
0
1
1
0
1
1
0
1
1
0
0
1
1
1
0
1
1
0
0
1
0
1
1
0
1
0
1
1
0
1
0
0
1
0
0
0
1
1
0
0
0
0
1
0
1
1
0
1
0
0
1
1
1
1
0
0
1
0
1
0
0
1
1
0
0
0
1
0
0
0
0
1
0
1
0
0
1
0
0
1
1
0
1
1
0
0
1
1
0
0
0
1
1
1
0
0
0
0
1
0
1
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
1
0
1
1
1
0
0
1
0
...

result:

points 1.0 W = 3

Test #34:

score: 31
Accepted
time: 5ms
memory: 7132kb

input:

0

output:

3

input:

1 499
407 20 406 394 446 169 359 188 328 372 198 216 134 235 209 57 403 417 145 437 310 360 17 147 262 427 384 368 456 154 428 122 258 350 6 494 379 120 495 33 156 278 206 203 388 279 171 425 176 366 67 163 4 248 31 488 202 94 289 448 249 88 468 11 45 325 442 299 98 338 348 238 108 24 356 187 101 42...

output:

0
1
0
1
0
0
1
0
1
1
1
0
0
1
0
0
0
0
1
1
0
1
0
0
0
1
1
0
1
1
1
1
1
0
1
0
1
1
0
1
1
0
1
0
0
1
1
1
0
1
1
1
0
1
1
1
0
1
0
1
1
0
0
1
1
0
0
0
0
0
1
1
1
0
0
1
1
0
1
1
1
0
0
0
1
1
0
0
0
0
1
1
1
1
0
0
1
0
0
0
1
1
0
1
1
1
0
0
0
0
1
0
1
0
0
0
1
0
0
0
0
0
1
0
1
0
1
1
0
0
0
0
0
1
1
0
1
1
0
1
0
0
1
1
1
0
0
0
0
1
...

input:

2 499
407 20 406 394 446 169 359 188 328 372 198 216 134 235 209 57 403 417 145 437 310 360 17 147 262 427 384 368 456 154 428 122 258 350 6 494 379 120 495 33 156 278 206 203 388 279 171 425 176 366 67 163 4 248 31 488 202 94 289 448 249 88 468 11 45 325 442 299 98 338 348 238 108 24 356 187 101 42...

output:

0
1
0
1
0
1
1
0
0
0
1
1
0
1
0
0
1
1
1
0
1
0
1
0
1
0
1
1
0
0
0
0
1
1
1
1
0
1
1
1
1
0
0
0
1
0
1
1
1
0
1
1
0
1
1
1
0
0
1
0
1
1
1
1
0
0
0
0
1
1
1
0
1
0
0
0
0
1
1
1
1
0
1
1
1
1
1
0
1
0
0
1
0
0
0
1
1
0
1
1
0
0
1
0
1
0
1
1
0
1
1
0
1
0
1
1
0
0
0
0
0
0
1
1
0
1
0
0
1
1
0
1
1
1
1
1
1
1
0
1
1
0
1
1
0
0
1
0
0
1
...

input:

3 499
407 20 406 394 446 169 359 188 328 372 198 216 134 235 209 57 403 417 145 437 310 360 17 147 262 427 384 368 456 154 428 122 258 350 6 494 379 120 495 33 156 278 206 203 388 279 171 425 176 366 67 163 4 248 31 488 202 94 289 448 249 88 468 11 45 325 442 299 98 338 348 238 108 24 356 187 101 42...

output:

1
1
0
1
1
1
0
0
0
0
0
1
1
0
0
1
1
1
1
0
0
0
0
1
0
0
0
1
1
1
0
1
0
0
1
1
0
1
1
0
1
0
0
0
0
0
0
0
0
1
1
1
0
1
1
0
1
1
1
1
1
0
1
0
1
0
1
1
0
0
1
1
1
0
0
1
0
0
0
1
1
0
1
1
0
0
0
1
0
1
1
1
1
1
1
1
0
1
1
1
0
1
0
1
1
0
0
1
0
1
0
1
1
1
1
0
0
0
0
1
0
1
0
0
0
1
0
0
0
1
1
1
0
1
1
0
1
0
0
0
1
0
1
0
1
0
0
0
1
1
...

result:

points 1.0 W = 3

Test #35:

score: 31
Accepted
time: 1ms
memory: 7144kb

input:

0

output:

3

input:

1 500
452 378 487 437 399 489 316 252 499 392 295 449 396 385 469 338 455 473 479 448 470 413 320 476 351 261 267 340 389 302 301 421 330 347 341 488 443 264 406 430 461 288 404 486 298 352 292 344 369 494 415 322 433 272 271 269 299 423 324 371 290 257 308 463 312 412 456 355 366 281 276 453 420 29...

output:

0
1
0
1
0
0
1
1
1
1
0
0
0
1
1
0
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
0
0
1
0
1
0
0
0
0
1
1
0
1
0
1
1
0
1
1
0
1
1
1
0
0
0
1
0
0
1
0
1
1
1
1
1
0
0
1
1
0
1
0
1
0
0
1
1
0
1
0
0
0
1
1
0
1
1
0
0
0
1
1
1
1
1
1
1
1
1
0
0
1
1
1
1
0
0
0
0
1
1
0
0
1
1
0
0
1
0
0
1
1
0
1
0
1
1
1
1
1
0
0
1
0
0
0
1
0
0
0
1
1
0
0
0
...

input:

2 500
452 378 487 437 399 489 316 252 499 392 295 449 396 385 469 338 455 473 479 448 470 413 320 476 351 261 267 340 389 302 301 421 330 347 341 488 443 264 406 430 461 288 404 486 298 352 292 344 369 494 415 322 433 272 271 269 299 423 324 371 290 257 308 463 312 412 456 355 366 281 276 453 420 29...

output:

0
1
0
1
1
1
1
0
1
0
1
1
1
1
1
0
0
1
1
0
1
0
1
1
1
1
0
0
0
1
1
1
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
0
0
1
0
1
0
1
0
0
0
1
1
0
0
0
1
0
0
1
0
0
1
0
1
1
0
0
0
1
1
1
0
1
0
1
0
0
1
1
0
1
1
0
0
0
0
1
0
1
0
0
1
1
1
1
1
0
1
0
1
0
1
0
0
1
1
1
0
1
1
1
0
1
0
0
1
1
1
1
1
1
0
1
1
1
0
1
1
0
0
1
0
0
1
1
1
0
0
0
1
1
1
0
...

input:

3 500
452 378 487 437 399 489 316 252 499 392 295 449 396 385 469 338 455 473 479 448 470 413 320 476 351 261 267 340 389 302 301 421 330 347 341 488 443 264 406 430 461 288 404 486 298 352 292 344 369 494 415 322 433 272 271 269 299 423 324 371 290 257 308 463 312 412 456 355 366 281 276 453 420 29...

output:

1
0
1
0
0
1
1
1
0
1
0
1
1
0
1
1
1
1
0
0
1
0
1
1
0
1
0
1
0
0
0
1
1
1
0
0
0
0
0
1
0
0
1
0
1
0
1
1
1
0
1
1
1
1
1
0
1
1
1
1
0
1
1
1
0
1
1
0
1
1
0
1
1
1
0
0
0
0
0
1
1
0
0
0
1
0
0
1
0
0
0
0
1
1
0
1
0
1
0
1
0
1
0
0
1
1
1
0
0
1
1
1
1
0
0
0
0
1
0
0
0
1
0
0
0
0
0
1
0
1
1
0
0
1
0
0
1
0
1
1
1
0
0
1
1
0
0
1
1
1
...

result:

points 1.0 W = 3

Test #36:

score: 31
Accepted
time: 6ms
memory: 7076kb

input:

0

output:

3

input:

1 500
121 129 11 59 186 238 151 89 164 236 182 96 25 152 105 156 120 95 146 131 0 173 198 60 239 204 82 71 207 249 9 193 213 73 67 34 91 15 20 99 12 201 130 206 80 234 143 54 208 2 248 179 40 116 217 243 203 44 209 118 22 154 199 240 72 133 147 210 142 192 124 63 97 181 50 128 166 183 157 18 167 159...

output:

0
0
1
0
0
1
1
0
1
0
0
1
1
0
0
0
0
0
0
1
1
0
1
1
1
0
0
0
1
1
0
1
1
1
1
0
1
0
1
1
1
0
0
0
1
1
0
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
0
1
0
1
1
0
0
1
1
0
1
0
0
0
1
1
0
1
0
1
1
0
1
0
1
0
1
0
1
1
0
0
1
0
1
1
1
1
0
0
0
1
0
0
1
1
0
1
1
1
1
0
1
1
1
0
0
1
0
0
1
1
1
0
1
...

input:

2 500
121 129 11 59 186 238 151 89 164 236 182 96 25 152 105 156 120 95 146 131 0 173 198 60 239 204 82 71 207 249 9 193 213 73 67 34 91 15 20 99 12 201 130 206 80 234 143 54 208 2 248 179 40 116 217 243 203 44 209 118 22 154 199 240 72 133 147 210 142 192 124 63 97 181 50 128 166 183 157 18 167 159...

output:

1
0
0
0
1
1
0
0
0
1
0
0
1
0
1
1
1
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
1
0
0
0
1
1
1
0
1
0
0
1
0
1
1
1
0
1
0
0
0
1
1
1
0
0
0
1
0
1
1
1
0
1
0
1
1
1
1
1
1
0
0
1
1
0
1
1
0
1
1
1
0
0
1
1
1
1
0
0
0
1
0
0
1
1
1
0
0
1
1
1
1
0
0
1
0
0
1
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
1
1
0
0
1
0
1
0
0
0
1
0
0
1
1
0
1
1
0
0
...

input:

3 500
121 129 11 59 186 238 151 89 164 236 182 96 25 152 105 156 120 95 146 131 0 173 198 60 239 204 82 71 207 249 9 193 213 73 67 34 91 15 20 99 12 201 130 206 80 234 143 54 208 2 248 179 40 116 217 243 203 44 209 118 22 154 199 240 72 133 147 210 142 192 124 63 97 181 50 128 166 183 157 18 167 159...

output:

1
1
0
0
0
1
0
1
1
1
0
0
1
1
1
0
1
1
0
1
0
1
1
1
1
0
0
0
0
0
0
0
0
1
1
1
1
0
1
0
1
0
1
1
1
0
0
1
1
1
0
1
1
1
1
0
0
1
1
0
1
0
1
1
0
1
1
0
0
0
0
0
0
1
1
0
1
1
0
0
0
0
0
0
1
1
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
1
0
0
1
1
1
1
1
0
0
1
1
1
0
1
1
0
1
0
0
0
0
1
0
1
0
0
0
1
0
1
0
0
1
0
1
0
0
0
1
0
0
0
0
0
0
1
1
0
...

result:

points 1.0 W = 3

Test #37:

score: 31
Accepted
time: 6ms
memory: 7044kb

input:

0

output:

3

input:

1 500
7 498 232 121 372 462 92 267 185 8 477 324 61 361 424 152 175 275 20 436 244 33 223 472 130 366 312 64 466 207 104 330 411 52 346 215 90 395 253 49 289 479 74 179 351 154 394 279 46 209 470 114 243 364 113 407 216 69 323 413 48 304 173 58 408 352 159 255 410 6 230 311 12 457 353 145 186 432 1 ...

output:

1
0
1
1
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
0
1
1
1
0
0
1
1
1
0
0
1
0
0
0
0
1
0
1
1
1
0
1
0
1
1
1
0
0
1
1
1
1
0
0
1
0
1
1
0
0
0
1
1
0
0
1
0
1
0
0
0
0
1
1
1
1
1
0
0
0
0
1
1
1
1
1
1
1
0
1
1
1
0
1
0
0
0
0
0
1
1
1
0
1
0
1
0
1
0
1
1
0
1
0
0
1
1
1
1
0
0
0
0
0
1
0
0
1
0
0
0
0
1
0
1
1
1
0
0
0
0
0
0
1
1
1
1
1
0
...

input:

2 500
7 498 232 121 372 462 92 267 185 8 477 324 61 361 424 152 175 275 20 436 244 33 223 472 130 366 312 64 466 207 104 330 411 52 346 215 90 395 253 49 289 479 74 179 351 154 394 279 46 209 470 114 243 364 113 407 216 69 323 413 48 304 173 58 408 352 159 255 410 6 230 311 12 457 353 145 186 432 1 ...

output:

0
0
0
0
1
0
0
0
0
1
1
1
1
1
1
0
1
1
1
1
1
0
0
0
1
0
1
0
1
1
0
1
0
0
0
0
0
1
0
0
0
0
1
1
1
0
0
0
0
0
1
1
0
0
0
1
0
0
0
1
0
1
0
0
0
1
1
1
1
0
0
0
0
1
1
0
1
0
1
0
1
1
1
1
1
0
0
0
0
0
0
0
0
1
1
0
0
1
0
1
1
1
1
0
1
1
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
0
0
0
0
1
1
0
1
0
1
1
0
1
0
1
0
0
1
1
1
1
1
1
0
1
0
0
0
0
...

input:

3 500
7 498 232 121 372 462 92 267 185 8 477 324 61 361 424 152 175 275 20 436 244 33 223 472 130 366 312 64 466 207 104 330 411 52 346 215 90 395 253 49 289 479 74 179 351 154 394 279 46 209 470 114 243 364 113 407 216 69 323 413 48 304 173 58 408 352 159 255 410 6 230 311 12 457 353 145 186 432 1 ...

output:

1
0
1
0
0
0
0
0
1
1
0
0
1
0
0
1
1
1
1
0
1
1
0
1
1
1
1
1
1
0
1
1
1
1
0
1
0
0
1
0
0
1
0
0
0
1
1
0
1
1
0
1
1
1
1
0
0
1
0
0
0
0
1
1
1
0
1
1
0
1
1
1
1
1
1
0
0
0
0
1
0
1
1
1
0
1
1
0
1
1
0
1
1
0
0
1
1
1
0
0
0
1
1
1
0
0
1
0
1
1
1
0
1
1
1
0
1
0
0
1
0
0
1
1
1
1
1
0
1
1
0
1
0
1
1
1
0
0
0
0
1
1
1
1
1
0
0
1
0
0
...

result:

points 1.0 W = 3

Test #38:

score: 31
Accepted
time: 4ms
memory: 7112kb

input:

0

output:

3

input:

1 500
349 341 416 411 232 170 222 315 443 211 269 276 474 168 336 429 479 356 406 453 446 294 186 305 495 415 448 372 435 193 313 400 187 403 309 225 350 244 296 378 263 351 425 458 288 188 242 206 216 250 201 401 368 330 285 223 454 424 195 376 212 360 292 410 346 291 274 386 237 421 258 256 438 44...

output:

0
0
1
1
0
0
1
1
0
1
0
0
0
0
1
1
0
0
1
1
1
0
1
1
1
1
0
0
1
1
1
0
1
0
0
0
0
1
1
0
0
1
0
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
1
1
0
1
0
0
1
1
1
1
1
0
0
1
1
0
0
1
0
1
1
0
0
0
0
1
1
0
1
0
1
0
0
0
0
0
0
0
0
1
1
0
0
0
1
1
0
1
1
1
0
0
1
1
0
1
1
0
1
1
0
1
0
1
0
1
1
1
0
1
1
1
1
0
0
0
1
0
0
1
1
1
1
0
1
0
0
0
0
0
0
1
...

input:

2 500
349 341 416 411 232 170 222 315 443 211 269 276 474 168 336 429 479 356 406 453 446 294 186 305 495 415 448 372 435 193 313 400 187 403 309 225 350 244 296 378 263 351 425 458 288 188 242 206 216 250 201 401 368 330 285 223 454 424 195 376 212 360 292 410 346 291 274 386 237 421 258 256 438 44...

output:

0
0
1
0
0
0
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
0
1
1
1
0
0
1
1
1
0
1
0
1
0
1
1
0
0
0
0
0
1
0
1
0
1
1
0
0
0
0
0
0
1
1
0
0
0
1
0
1
0
0
0
1
0
0
1
0
1
0
1
0
1
0
0
0
0
0
1
1
1
1
1
1
1
0
0
0
0
1
0
1
0
1
1
1
0
0
0
0
0
1
1
1
1
0
0
0
1
1
1
0
0
0
1
1
0
0
0
1
0
1
1
1
0
0
1
1
1
0
0
0
0
0
1
0
0
1
1
0
0
0
1
0
0
1
1
...

input:

3 500
349 341 416 411 232 170 222 315 443 211 269 276 474 168 336 429 479 356 406 453 446 294 186 305 495 415 448 372 435 193 313 400 187 403 309 225 350 244 296 378 263 351 425 458 288 188 242 206 216 250 201 401 368 330 285 223 454 424 195 376 212 360 292 410 346 291 274 386 237 421 258 256 438 44...

output:

0
0
1
0
0
1
0
0
0
0
1
1
0
0
0
1
1
0
1
0
1
0
0
0
1
1
0
0
1
0
1
1
0
1
0
0
0
0
1
1
1
0
0
1
1
0
1
0
0
0
1
0
1
0
1
1
1
1
0
1
1
1
0
1
0
0
0
1
0
0
1
0
0
1
0
1
1
1
1
0
0
1
1
1
1
0
0
1
0
1
0
1
1
1
0
1
1
0
1
0
0
0
1
0
1
0
1
0
0
1
0
1
0
0
0
1
0
0
1
0
1
0
1
1
1
0
0
1
0
1
1
1
0
0
1
1
1
1
0
0
1
1
1
1
0
1
0
1
1
1
...

result:

points 1.0 W = 3