PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000158. Dãy có tổng xen kẽ bằng không (Ahahahahahahahaha)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy có tổng xen kẽ bằng không (Ahahahahahahahaha)
Ahahahahahahahaha
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a binary sequence of even length . Remove at most elements without reordering the remaining elements. Output a subsequence of length whose alternating sum equals zero.
Input
The first line contains the even integer . The second contains values .
Output
Print the length , then the retained elements in original relative order. Any valid subsequence is accepted.
Subtasks
- Subtask 1 (20 points): ; chẵn; .
- Subtask 2 (30 points): ; chẵn; .
- Subtask 3 (50 points): ; chẵn; .
Examples
Input
6
1 0 1 0 0 0
Output
3
0 0 0
Explanation
The original array has four zeros. Keeping the zeros at positions yields after three deletions. Its alternating sum is , and its length is .