Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())) : n = int(input()) arr = list(map(int,input().split())) res = [] i = 0 while i < n - 1 : if arr[i] == arr[i+1] : res.append(arr[i]) res.append(arr[i+1]) else: res.append(0) i += 2 print(len(res)) for i i...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s1, s2 = sum(a[::2]), sum(a[1::2]) x, y = a.count(0), a.count(1) if all(i == 0 for i in a) or all(i == 1 for i in a) or s1 == s2: print(n) print(*a) elif n == 2: print(1) prin...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n=int(input()) a=list(map(int, input().split())) ans=[] for i in range(0, n, 2): if a[i]==a[i+1]: ans.extend([a[i], a[i]]) else: ans.append(0) print(len(ans)) print(*ans)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) z=a.count(0) o=a.count(1) if z>=o: print(z) print(*([0]*z)) else: if o%2==0: print(o) print(*([1]*o)) else: print(o-1) print(*([1]*(o-1)))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') t = 1 t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) # b = list(map(int, input().split())) # s = input() ones, zero = a.count(1), a.count(0) # print(ones, ',', ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int,input().split())) if a.count(1)<=a.count(0): print(n//2) arr = [0] * (n//2) print(*arr) if a.count(1) > a.count(0): if n%4!=0: print(n//...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from collections import deque import copy for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) z=l.count(0) o=l.count(1) if z>=n//2: print(z) print('0 '*z) elif o>=n//2: print(o//2 *2) print('1 '*(o//2 *2))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for _ in range(t): n = int(input()) l = map(int, input().split()) out = [] for _ in range(n//2): if next(l) + next(l) == 2: out.append(1) out.append(1) else: out.append(0) print(len(out)) print(' '.join(map(str,out)))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); } const long long MAX_PRIME = 1e9 + 7; const long long INF = 1e18; long long fast_pow(long long x, long long y, long long z) { if (y == 0) return 1 % z; else if (y == 1) return x % z; if...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> void input(vector<T> &arr, long long int n) { T temp; for (long long int i = 0; i < n; i++) cin >> temp, arr.push_back(temp); } template <typename T> void output(vector<T> arr) { for (auto x : arr) cout << x << " "; cout << endl; } template <ty...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys input = lambda: sys.stdin.readline().rstrip('\r\n') def alt_sum(a, n): s = 0 for i in range(n): if i & 1: s -= a[i] else: s += a[i] return s def check(a, k): c = 0 z = 0 for i in range(len(a)): if a[i] == 1: c += 1 ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) zero=0 one=0 l=list(map(int,input().split())) for i in range(n): if l[i]: one+=1 else: zero+=1 if one<=(n//2): print(zero) for _ in range(zero): print(0,end=" ") print() e...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for _ in range(t): n=int(input()) s=list(map(int,input().split())) x=s.count(0) y=s.count(1) if y%2!=0: s.remove(1) y-=1 x+=1 y+=1 if x<y: print(n-x) for i in s: if i==1: print(i,end=" ") else: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import math def MI(): return map(int,input().split()) def ML(): return list(MI()) def I(): return int(input()) def LOOP(SizE,solve): for XIX in range(SizE): solve() def solve(): n=I() a=ML() nd={0:0,1:0} for x in a: nd[x]+=1 if nd[1]*2<=n: res=[0 for x in range(nd[0])] else: if nd[1]&1: nd[1]-=1 ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# cook your dish here # code # ___________________________________ # | | # | | # | _, _ _ ,_ | # | .-'` / \'-'/ \ `'-. | # | / | | | | \ | # | ; \_ _/ \_ _/ ; ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) p=a.count(1) q=a.count(0) if p>q: t=n//2 if t%2==0: print(t) r=['1']*(n//2) print(' '.join(r)) else: print(t+1) r=['1']*(t+1) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.*; import java.lang.reflect.Array; import java.util.*; public class A { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys import bisect as bi import math from collections import defaultdict as dd import heapq import itertools ##import operator input=sys.stdin.readline import random ##sys.setrecursionlimit(10**7) ##fo=open("output.txt","w") ##fi=open("input2.txt","w") mo=10**9+7 def cin(): return map(int,sin().split()) def a...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
test = int(input()) for _ in range(test): n = int(input()) arr = list(map(int, input().split())) on, ze = 0, 0 for i in range(n): if arr[i]==1: on+=1 else: ze+=1 if on<=n//2: print(n-on) for i in range(n-on): print(0, end = ' '...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; const long long MXN = 5e3 + 10; long long q, n; void solve() { cin >> n; long long cnt0 = 0, cnt1 = 0; for (int i = 1; i <= n; i++) { long long x; cin >> x; cnt0 += (x == 0), cnt1 += (x == 1); } if (cnt0 >= n / 2) { cout << n / 2 << '\n'; for (...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for i in range(t): n=int(input()) q=0 a=[int(i) for i in input().split()] for i in range(len(a)): if a[i]==0: q+=1 q1=n-q if q>=n/2: print(q) for i in range(q): print(0) else: print(q1-q1%2) for i in range(q1-q1%2): print(1)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for it in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] c1 = a.count(1) if c1 <= n - c1: print(n // 2) print(*([0] * (n // 2))) else: k = n // 2 if k % 2 == 1: k += 1 print(k) print(*([1] * k))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from __future__ import division, print_function def main(): # Template 1.0 import sys, re, math from collections import deque, defaultdict, Counter, OrderedDict from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor from heapq import heappush, heappop, heapify, nlargest, nsmal...
PYTHON
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.util.*; import java.io.*; public class CFA { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; private static final long MOD = 1000L * 1000L * 1000L + 7; private static final int[] dx = {0, -1, 0, 1}; private static final int[] dy = {1, 0, -1, 0}; private ...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.util.*; import java.io.*; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] a = new int[n]; for(int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int countZero = 0; for(...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) data=[int(x) for x in input().split()] one_count=0 for q in data: if(q==1): one_count+=1 zero_count=n-one_count if(one_count<=(n//2)): print(n//2) for q in range(n//2): print(0,end=' ') print() ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import itertools import math import sys input = sys.stdin.readline # Input Functions def inp(): return int(input()) def inlst(): return (list(map(int, input().split()))) def instr(): s = input() return list(s[:len(s) - 1]) def invar(): return map(int, input().split()) def pba(n, a): r...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for t in range(int(input())): n=int(input()) a=list(map(int,input().split())) k=0 i=0 j=1 l=[] while(i<n and j<n): if(a[i]!=a[j]): s=0 if(j+1<n): s=a[j+1] if(a[i]==s): l.append(a[i]) else: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from collections import * import sys # "". join(strings) # print(guess, flush= True) def ri(): return int(input()) def rl(): return list(map(int, input().split())) t =ri() for _ in range(t): n = ri() aa = rl() bb = [] i = 0 while i + 1 <=n-1: if aa[i] == aa[i+1]: bb.append(aa[i]) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int b[n]; int a = 0, z = 0; for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i] == 1) { a++; } if (b[i] == 0) { z++; } } if (a == z) ...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) c=0 cnt=0 for i in range(len(l)): if(l[i]==0): c+=1 else: cnt+=1 if(c>=n//2): print(n//2) for i in range(n//2): print("0",end=" ") elif(cnt>(n...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
T = int(input()) for t in range(T): n = int(input()) A = [int(i) for i in input().split()] # if at most half is 1, remove all the 1 # if odd number of 1 one_count = 0 for i in A: if i == 1: one_count += 1 if one_count <= n//2: # remove all 1 ans = [0] * (n...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) o = 0 for i in a: if i == 1: o+=1 if o > n-o: if o%2 == 0: print(o) print(*([1]*o)) else: print(o-1) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> ones; vector<int> zeros; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) { ones.p...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def solution(n, a): n_0 = a.count(0) if n // 2 <= n_0: return [n // 2, [0] * (n // 2)] elif (n // 2) % 2 == 0: return [n // 2, [1] * (n // 2)] else: return [n // 2 + 1, [1] * (n // 2 + 1)] if __name__ == "__main__": t = int(input()) for _ in range(t): n...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
ntest = int(input()) for test in range(ntest): n = int(input()) a = list(map(int, input().split())) res = [] for i in range(0, n-3, 4): if sum(a[i:i+4]) >= 3: res.extend([1, 1]) else: res.extend([0, 0]) if n % 4 == 2: if sum(a[-2:]) == 2: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys # input = sys.stdin.readline ll = lambda: list(map(int, input().split())) lls = lambda: list(map(str, input().split())) fin = lambda: list(map(float, input().split())) st = lambda: input() v = lambda: map(int, input().split()) ii = lambda: int(input()) mod = (10 ** 9) + 7 from math import * # from fractions ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for i in range(t): n=int(input()) a=[int(i) for i in input().split()] b=sum([a[i] for i in range(0,n,2)]) c=sum([a[i] for i in range(1,n,2)]) if b==c: if b==0: print(n//2) print(*[0 for i in range(n//2)]) else: print(n) print(*a) elif a.count(0)<n//2: b=[in...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict import threading BUFSIZE = 8192 clas...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; public class TaskA { public static void main(String[]...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t, i, j, k; cin >> t; while (t--) { long long n; cin >> n; long long A[n + 1]; for (i = 0;...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from fractions import Fraction import bisect import os import io from collections import Counter import bisect from collections import defaultdict import math import random import heapq from math import sqrt import sys from functools import reduce, cmp_to_key from collections import deque import threading from itertool...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int32_t main() { int64_t t; cin >> t; while (t--) { int64_t n; cin >> n; int64_t a[n]; int64_t sum = 0; int64_t cz = 0, co = 0; for (int64_t i = 0; i < n; i++) { cin >> a[i]; if (i % 2 == 0) sum += a[i]; else s...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import io import os from collections import Counter, defaultdict, deque def solve(N, A): zeroes = A.count(0) ones = A.count(1) assert zeroes + ones == N if zeroes >= N // 2: A = [0] * zeroes else: A = [1] * (2 * (ones // 2)) return str(len(A)) + "\n" + " ".join(map(str, A)) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int(input()) arr = [int(num) for num in input().split(' ')] if n==2: x = arr.count(0) y = arr.count(1) if x == y: print(1) print(0) else: print(2) for item in arr: print(item,en...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) c=0 for i in a: if i==1: c+=1 if n==2: if c==2: print(2) print(1,1) elif c==1: print(1) print(0) else: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) a=list(map(int, input().split())) x=a.count(0) y=a.count(1) if x>=y: print(x) a=[0]*x else: if y%2==0: print(y) a=[1]*y else: print(y-1) a=[1]*(y-1) print(*a)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input())): l = int(input()) s = list(map(int, input().split())) r = [] for i in range(l//2): if s[i*2] == 0 and s[i*2+1] == 0: r.append(0); r.append(0); elif s[i*2] == 1 and s[i*2+1] == 1...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class A { private static FastReader fr = new FastReader(); private static PrintWriter out=new PrintWriter(System.out); public static void main(...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int(input()) A = list(map(int,input().split())) if(A.count(0)>=n//2): print(n//2) print("0 "*(n//2)) elif(A.count(1)>n//2): if(n//2)%2!=0: print(n//2+1) print("1 "*(n//2+1)) else: print(n//2) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from collections import Counter cases = int(input()) for t in range(cases): n = int(input()) a = list(map(int,input().split())) a = Counter(a) if a[0]>=a[1]: print(a[0]) print(*[0]*a[0]) else: if a[1]%2==0: print(a[1]) print(*[1]*a[1]) else: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) z=a.count(0) o=a.count(1) if z>=o: print(n//2) print('0 '*(n//2)) else : if (n//2)%2==0: print(n//2) print('1 '*(n//2)) else: print(n//2+1) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; int T, n, a[maxn], cnt[10]; int main() { cin >> T; while (T--) { cnt[0] = cnt[1] = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; cnt[a[i]]++; } if (cnt[0] >= cnt[1]) { cout << n / 2 << endl; ...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 100 + 10, M = 1e5 + 10; const int mod = 1e9 + 7; int a[M]; int res[M]; void solve() { int n; cin >> n; int cnt0 = 0, cnt1 = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == 1) cnt1++; else c...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys # def check(n,a): # on=0 # for p in range(n): # if(a[p]==0): # if(on%2==0): # return True # else: # on+=1 # return False def solve(n,a): # if(n==2): # if(a[0]==0 and a[1]==0): # return [0,0] # elif(a[0]==0 and a[1]==1): # return [0] # elif(a[0]==1 and a[1]==0): # return...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) c = [0, 0] for i in a: if i == 0: c[0] += 1 else: c[1] += 1 if c[1] <= (n // 2): a = [i for i in a if i == 0] print(len(a)) print(*a) else: a...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; long long binPow(long long a, long long b) { if (b == 0) return 1; long long ans = binPow(a, b / 2); ans = ans * ans % MOD; if (b % 2) ans = ans * a % MOD; return ans; } void solve() { int n; cin >> n; vector<int> a(n); int nu...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.util.Scanner; public class Aahahaha { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int noTest=sc.nextInt(); for(int i=0;i<noTest;i++) { int N=sc.nextInt(); int[] arr=new int[N]; int onceCount=0,zeroCount=0; for(int j=0;j<N;j++) { arr...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) ze=a.count(0) on=a.count(1) ch='1' if on>ze else '0' amo=max(on,ze) if ze==amo: print(amo) print(" ".join([ch]*max(on,ze))) else: print(amo-(amo%2)) amo=amo-(amo%2) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def main_function(): t = int(input()) data = [] for i in range(t): n = int(input()) data.append([int(i) for i in input().split(" ")]) for j in data: a = j zero_counter = [0, 0] one_counter = [0, 1] for i in a: if i == 0: zero_...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) if a.count(0)>=n/2: print(n//2) print(" ".join("0"*(n//2))) else: #この時、1はn//2+1個以上 if (n//2)%2==0: print(n//2) print(" ".join("1"*(n//2))) else: print...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.*; import java.util.*; public class CFA { static final PrintWriter out = new PrintWriter(System.out); // static final Reader in = new Reader(); static final Scanner in = new Scanner(System.in); static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br ...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for tt in range(t): n = int(input()) a = list(map(int, input().split())) if a.count(1) <= n // 2: print(a.count(0)) print(a.count(0) * '0 ') else: q = a.count(1) q = q // 2 * 2 print(q) print(q * '1 ')
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from collections import Counter t=int(input()) while(t>0): n=int(input()) arr=list(map(int,input().split())) c=Counter(arr) n0=c[0] n1=c[1] if(n0>=n/2): print(n0) for i in range(0,n0): print('0',end=' ') print(end='\n') else: print(n1-n1%2) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# by the authority of GOD import os,sys from io import BytesIO, IOBase from collections import defaultdict def main(): from math import gcd for _ in range(int(input())): n = int(input()) mn = 0 a = [int(X) for X in input().split()] x= a.count(1) y=n-x if x>y:...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, count = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) count++; } if (count > n / 2) { if (n / 2 % 2 == 0) { cout...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacem...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
a=int(input()) i=1 while(i<a+1): b=int(input()) c=input() if(c.count("0")>=b/2): print(b//2) print("0 "*int(b/2)) else: if((b/2) % 2 ==0 ): print(b//2) print("1 "*int(b/2)) else: print(b // 2 + 1) print("1 " * int(b / 2 + 1)) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), ans; int cnt0 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (!a[i]) cnt0++; } int cnt1 = n - cnt0; if (cnt0 >= n / 2) { cout << cnt0 <...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
''' Problem: A. Ahahahahahahahaha URL: https://codeforces.com/contest/1407/problem/A Author: Ad Fernvndez ''' t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) half = int(n/2) if a.count(0) >= half: print(a.count(0)) for i in a: if(i == 0): ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int (input()) ar = list(map(int , input().split())) # print(ar , n ) ans = [] flag = 0 cou = 0 for i in range(n): if ar[i] == 1 and flag: if cou&1: ans = ans + [1] + [0] * (cou -1) + [1] else : ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) ones = 0 zeros = 0 for i in range(n): if a[i] == 0: zeros += 1 else: ones += 1 if ones > n//2: if ones%2 == 1: ones -= 1 print(ones) for i...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) z=o=0 for i in a: if i==1: o+=1 else: z+=1 if z>=o: print(z) ans=[0]*z print(*ans) else: if o%2!=0: o-=1 ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import math class Read: @staticmethod def string(): return input() @staticmethod def int(): return int(input()) @staticmethod def list(sep=' '): return input().split(sep) @staticmethod def list_int(sep=' '): return list(map(int, input().split(sep...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) count0 = 0 for i in arr: if i==0: count0+=1 count1 = n-count0 if count0>=n/2: print(count0) for i in range(count0): print(0, end=" ") else: if co...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from collections import Counter import math t=int(input()) for some_num in range(t): n=int(input()) k=[int(i) for i in input().split(" ")] kc=Counter(k) if(kc[0]>=n/2): print(kc[0]) print('0 '*kc[0]) else: a=(kc[1]//2)*2 print(a) print('1 '*a)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.*; import java.util.*; import static java.lang.Integer.*; public class A { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st; ...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys import math as mt import collections as cc import sys import itertools as it I=lambda:list(map(int,input().split())) for tc in range(int(input())): n,=I() l=I() a=0 b=0 a0=[] a1=[] b0=[] b1=[] for i in range(0,n,2): a+=l[i] if l[i]==0: a0.append(i) else: a1.append(i) for j in range(1,n,...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) while(t): n = int(input()) arr = [int(i) for i in input().split()] b = sorted(arr) if b[n//2 - 1] == 0: print(n//2) print('0 '*(n//2)) else: if n%4==0: print(n//2) print('1 '*(n//2)) else: print(n//2+1) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for _ in range(t): n = int(input()) array = list(map(int, input().split())) one = sum(array) zero = n-one x=11 if n == x: print(int(x/2)) print('10'*int(x/2)) if zero < one: if one % 2 == 0: print(one) ans = '1 '*(one) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int (input()) for i in range (t): n=int(input()) a=list(map(int,input().split())) c=0 for j in a: if j==1: c+=1 if c<=n/2: print(n-c) print("0 "*(n-c-1)+"0") else: if c%2==0: print(c) print("1 "*(c-1)+"1") else: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long T; cin >> T; while (T--) { long long n; cin >> n; long long arr[n]; vector<long long> ans; long long odd = 0, eve = 0; for (long long i = 0; i < n; i++) cin...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys if __name__ == "__main__": n = int(sys.stdin.readline()) for i in range(n): s = int(sys.stdin.readline()) data = [int(i) for i in sys.stdin.readline().split()] stack = [] it = 0 for j, value in enumerate(data): if stack and stack[-1][0] == value: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) ans = [] for i in range(t): n = int(input()) seq = list(map(int, input().split())) countOne = seq.count(1) countZero = seq.count(0) sumEven = sumOdd = 0 for i in range(n): if i % 2 == 0: sumEven += seq[i] else: sumOdd += seq[i] if...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# Name: Rhythem Jain # Date: 01.09.2020 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): r...
PYTHON
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
tc = int(input()) for _ in range(tc): n = int(input()) lis = list(map(int, input().split())) nlis = [] start = 0 while(start < len(lis)): if (lis[start] == lis[start + 1]): nlis.append(lis[start]) nlis.append(lis[start + 1]) start += 2 else: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for q in range(int(input())): n = int(input()) a = input().split() one = a.count('1') z = n - one if one <= n//2: print(z) print('0 '*z) else: if one % 2 == 0: print(one) print('1 '*one) else: print(one - 1) print('1 '*(one-1))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for tests in range(t): n = int(input()) a = [int(x) for x in input().split()] zeros_count = a.count(0) ones_count = n - zeros_count if ones_count % 2 != 0 and n > 2: a.remove(1) ones_count -= 1 if zeros_count >= ones_count: k = zeros_count output ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
"""T=int(input()) for _ in range(0,T): n=int(input()) a,b=map(int,input().split()) s=input() s=[int(x) for x in input().split()] for i in range(0,len(s)): a,b=map(int,input().split())""" T=int(input()) for _ in range(0,T): n=int(input()) s=[int(x) for x in input().split()] c0=0...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) c0, c1 = a.count(0), a.count(1) ans = [] if c1 <= n//2: for i in a: if i == 0: ans.append(i) else: flag = 1 if c1&1 else 0 for i in a: if flag ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from sys import stdin from collections import defaultdict input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().rstrip().split())) if a.count(0) >= a.count(1): print(n // 2) out = [0] * (n // 2) print(*out) else: if (n // ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from __future__ import division, print_function # import threading # threading.stack_size(2**27) import sys sys.setrecursionlimit(10**4) # sys.stdin = open('inpy.txt', 'r') # sys.stdout = open('outpy.txt', 'w') from sys import stdin, stdout import bisect #c++ upperbound import math import heapq i_m=922337203...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int a[n], c0 = 0, c1...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long on...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys from functools import reduce from collections import Counter import time import datetime from math import sqrt,gcd # def time_t(): # print("Current date and time: " , datetime.datetime.now()) # print("Current year: ", datetime.date.today().strftime("%Y")) # print("Month of year: ", datetime.date...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
''' Problem Link : https://codeforces.com/contest/1407/problem/A - Let 𝑐𝑛𝑡0 be the count of zeroes in the array, 𝑐𝑛𝑡1 — count of ones. - Then if 𝑐𝑛𝑡1 ≤ 𝑛/2, we remove all ones and alternating sum, obliously, equals 0. - Otherwise, 𝑐𝑛𝑡0 < 𝑛/2, we remove all zeroes and if 𝑐𝑛𝑡1 is odd — plus anothe...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int(input()) li = list(map(int,input().split())) a=0 for i in range(n): if li[i]==0: a+=1 if a>=n//2: print(a) print(' '.join(['0']*a)) else: if (n//2)%2==0: print(n//2) print(' '.join(['1']*(n//2))) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int arr[n]; for (long long int i = 0; i < n; i++) { cin >> arr[i]; } map<int, int> mp; for (long long int i = 0; i < n; i++) { mp[arr[i]]...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys # import math from collections import deque # import heapq # from math import inf # from math import gcd # print(help(deque)) # 26 pprint = lambda s: print(' '.join(map(lambda x: str(x), s))) input = lambda: sys.stdin.readline().strip() ipnut = input for i in range(int(ipnut())): n = int(ipnut()) ...
PYTHON3