prompt
string
response
string
Problem: 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, Alexandr...
def ans(n, arr): one = 0 zero = 0 for i in range(n): if arr[i] == 1: one += 1 else: zero += 1 if zero >= n // 2: return [0] * (n // 2) else: if (n // 2) % 2 == 0: return [1] * (n // 2) else: return [1] * (n // 2 ...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; const int MOD = 1e9 + 7; int A[maxn]; int main() { ios::sync_with_stdio(false); int T, n; cin >> T; while (T--) { cin >> n; int cnt0 = 0, cnt1 = 0; for (int i = 1, a; i <= n; i++) { cin >> a; if (a) cnt1++; ...
Problem: 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, Alexandr...
def solve(arr,s): temp=[] t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) s=sum(arr) if s>n//2: temp=[1]*(2*(s//2)) elif s==0: temp=[0]*n elif s==n//2: temp=[0]*(s) else: temp=[0]*(2*((n-s)//2)) if len(temp)...
Problem: 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, Alexandr...
t=int(input()) while t>0: n=int(input()) arr=list(map(int,input().split())) count0=arr.count(0) count1=arr.count(1) if count0>=n//2: print(count0) for i in range(count0): print(0,end=" ") else: print(count1-(count1%2)) for i in range((count1-(count1%2)...
Problem: 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, Alexandr...
from sys import stdin def readline(): return stdin.readline() def solve(n, a): arr = [] k = 0 i = 1 while i < n: if a[i - 1] == a[i]: k += 2 arr.append(a[i - 1]) arr.append(a[i]) i += 2 elif i < n - 1 and a[i - 1] == a[i + 1]: ...
Problem: 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, Alexandr...
#python for _ in " "*int(input()): a=int(input()) z=list(map(int,input().split())) s=z.count(0);k=a//2 s1=z.count(1) if s>=s1:print(k);print('0 '*k) else:print(k+k%2);print('1 '*(k+k%2))
Problem: 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, Alexandr...
t=int(input()) for i in range(t): n=int(input()) b=list(map(int,input().split())) p=b.count(0) if p>=(n//2): print(n//2) arr=[0]*(n//2) print(*arr) else: if n%4==0: print(n // 2) arr = [1] * (n // 2) print(*arr) else: ...
Problem: 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, Alexandr...
q = int(input()) for _ in range(q): n = int(input()) s = list(map(int, input().split())) res = [] l = 0 r = 1 while r < n: if s[l] == s[r]: res.append(s[l]) res.append(s[r]) l = r + 1 r = l + 1 elif r + 1 < n: res.append...
Problem: 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, Alexandr...
import sys input=sys.stdin.readline t=int(input()) for i in range(t): n=int(input()) a=[int(i) for i in input().split() if i!='\n'] if sum(a)>n/2: ans=[1]*(sum(a)) if len(ans)&1: ans.pop() else: ans=[0]*int(n/2) print(len(ans)) print(*ans)
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) cnt = [0, 0] for i in range(n): cnt[a[i]] += 1 take = 0 if cnt[0] >= cnt[1] else 1 ans = [] for i in range(n): if len(ans) % 2 == 0 and len(ans) >= n // 2: break if a[i] == take: ans.append(str(a[i])) print(len(a...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; void arraychk(int a[], int n) { for (int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n"; ; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int tt = 1; cin >> tt; for (int cse = 1; cse <= tt; cse++) { int ...
Problem: 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, Alexandr...
#!/usr/bin/env python3 import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = [int(item) for item in input().split()] if sum(a) <= n // 2: print(n // 2) print(" ".join(["0" for _ in range(n // 2)])) else: if n % 4 == 0: print(...
Problem: 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, Alexandr...
from sys import stdin,stdout from math import gcd,sqrt from collections import deque input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\n') L=lambda:list(R()) P=lambda x:stdout.write(x) hg=lambda x,y:((y+x-1)//x)*x pw=lambda x:1 if x==1 else 1+pw(x//2) chk=lambda x:ch...
Problem: 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, Alexandr...
t=int(input()) for you in range(t): n=int(input()) l=input().split() li=[int(i) for i in l] num0=0 num1=0 for i in li: if(i==0): num0+=1 else: num1+=1 if(num0>=n//2): print(num0) for i in range(num0): print(0,end=" ") el...
Problem: 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, Alexandr...
""" Code of Ayush Tiwari Codeforces: servermonk Codechef: ayush572000 """ import sys input = sys.stdin.buffer.readline def solution(): # This is the main code n=int(input()) l=list(map(int,input().split())) z=0 o=0 for i in range(n): if l[i]==0: z+=1 else: ...
Problem: 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, Alexandr...
import java.util.Scanner; public class AAAAA { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int z = 0, o = 0; for (int i = 0; i < n; i++) { if (...
Problem: 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, Alexandr...
t = int(input()) for _ in range(t): n = int(input()) arr = [int(j) for j in input().split()] o = arr.count(1) z = arr.count(0) if o > z: if (n-z)%2 == 1: print(n-z-1) print(*([1]*(n-z-1))) else: print(n-z) print(*([1]*(n-z))) else: print(n-o) print(*([0]*(n-o)))
Problem: 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, Alexandr...
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
Problem: 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, Alexandr...
for _ in range(int(input())): input();a=list(map(int,input().split())) if a.count(1)%2:a.pop(a.index(1)) s='\n';c=l=0 for i in a: if i:s+='0 '*(c-c%2)+'1 ';l+=c-c%2+1;c=0 else:c+=1 print(l+c,s+'0 '*c)
Problem: 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, Alexandr...
import sys from math import sqrt from collections import defaultdict inpt = sys.stdin.readline def inp(): return(int(inpt())) def inlist(): return(list(map(int,inpt().split()))) def instr(): s = inpt() return(list(s[:len(s)-1])) def inbitstr(): s = inpt() return([int(i) for i in list(s[:len(...
Problem: 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, Alexandr...
t=int(input()) for i in range(t): n=int(input()) k=list(map(int,input().split(' '))) if sum(k)<=n//2: print(n-sum(k)) print('0 '*(n-sum(k))) elif sum(k)>n//2: if (n//2)%2==0: print(n//2) print('1 '*(n//2)) else: print(n//2+1) ...
Problem: 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, Alexandr...
testcases = int(input()) for _ in range(testcases): n = int(input()) l = list(map(int, input().split())) cnt0 = l.count(0) cnt1 = n - cnt0 if(cnt0 >= n//2): print(cnt0) for i in range(cnt0 - 1): print(0,end = ' ') else: print(0) else: ...
Problem: 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, Alexandr...
import java.io.*; import java.math.*; import java.util.*; public class Main { static Scanner sc=new Scanner(System.in); public static void main(String[] args) { int t=sc.nextInt(); for(int i=0;i<t;i++) { show(); } } private static void show() { int n=sc.nextInt(); int zero=0,one=0; for(int i=0;i<n;i+...
Problem: 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, Alexandr...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Round_669D2P1 { static final FS sc = new FS(); static final PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int t = sc....
Problem: 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, Alexandr...
# for _ in range(int(input())): n = int(input()) arr = list(map(str, input().split())) word = "".join(arr) z = arr.count("0") zz = arr.count("1") if z >= zz: word = word.replace("1", "") print(len(word)) for j in list(word): print(j, end=" ") print() ...
Problem: 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, Alexandr...
#!/usr/bin/env python # coding: utf-8 # In[ ]: try: t = int(input()) while(t!=0): n = int(input()) arr = list(map(int,input().split())) popi = [] count = 1 for i in range(n-1): if arr[i] == arr[i+1]: count += 1 else: ...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) n1 = n // 2 a = [int(i) for i in input().split()] s = sum(a) if s <= n1: print(n1, '0 ' * n1, sep='\n') else: print(n1 + n1 % 2, '1 ' * (n1 + n1 % 2), sep='\n')
Problem: 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, Alexandr...
#include <bits/stdc++.h> const int maxN = 3e5 + 10; using namespace std; int n, t, a[maxN], d, d1; void Process() { if (d >= n / 2) { cout << n / 2 << '\n'; for (int i = 1; i <= n / 2; ++i) cout << 0 << ' '; cout << '\n'; } else { if (d1 % 2 == 0) { cout << d1 << '\n'; for (int i = 1; i ...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) a = [*map(int, input().split())] zc = sum(x == 0 for x in a) oc = n - zc if zc == oc: print(zc) print(*(0 for i in range(zc))) elif zc < oc: if zc % 2 == 1: print(oc - 1) print(*(1 for i in range(oc - 1))) else: print(oc) print(*(1 for i in range...
Problem: 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, Alexandr...
t=int(input()) while t>0: n=int(input()) x=[int(x) for x in input().split()] x0=x[0::2] x1=x[1::2] if len(x)%2!=0: x.remove(x[int((n+1)/2-1)]) count=1 else:count=0 arr=[] for i in range(len(x1)): if x0[i]==x1[i]: arr.append(x0[i]) arr.appen...
Problem: 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, Alexandr...
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException //use buffered reader? { BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tk; int tc = Integer.parseInt(inp.readLine()); ...
Problem: 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, Alexandr...
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Forces { private static List<Integer> sport(int[] a) { List<Integer> ans = new ArrayList<>(); int n = a.length; for (int i = 0; i < n; i += 4) { if (i + 4 <= n) { int s = a[i] + a[i + 1] + a[i + 2] + a[i + 3]; ...
Problem: 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, Alexandr...
for t in range(int(input())): n=int(input()) a=list(map(int,input().split())) i=0 b=[] add,store=0,0 while True: if(i<n-3): if(a[i]==a[i+1]): b.append(a[i]) b.append(a[i+1]) i+=2 elif(a[i]!=a[i+1] and a[i]==a[i+2]): ...
Problem: 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, Alexandr...
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: ans=[] for i in range(n): if a[i]==1:ans.append(1) if len(ans)%2!=0: print(len(ans[1:])) print(*ans[1:]) else:print(len(ans)...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] z = a.count(0) o = a.count(1) if(z >= n//2): print(z) for i in range(z): print(0,end = ' ') elif(o > n//2): print(n//2 + ((n//2)%2)) if((n//2)%2 != 0): pri...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) zero = 0 one = 0 for i in range(n): if a[i] == 1: one += 1 else: zero += 1 k = n // 2 if one > n // 2: if k % 2 == 0: print(k) print(*[1]...
Problem: 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, Alexandr...
from sys import stdin ############################################################### def iinput(): return int(stdin.readline()) def minput(): return map(int, stdin.readline().split()) def linput(): return list(map(int, stdin.readline().split())) ############################################################### t = iinp...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, k; cin >> t; while (t--) { cin >> n; int arr[n]; int c1 = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 1) c1++; } if (n - c1 >= c1) { cout << n - c1 << endl; for (int i = 0; ...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const double eps = 1e-9; const int inf = 1e9; int a[N]; bool vis[N]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int c0 = 0, c1 = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; ...
Problem: 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, Alexandr...
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from collections import Counter #sys.setrecursionlimit(100000000) inp = lambda: int(input()) strng = lambda: inpu...
Problem: 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, Alexandr...
def solve(arr): ones = sum(arr) if ones <= len(arr) // 2: print(len(arr) // 2) for i in range((len(arr) // 2) - 1): print('0', end=' ') print('0') else: if ones % 2 == 1: ones -= 1 print(ones) for i in range(ones-1): print('...
Problem: 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, Alexandr...
# for _ in range(int(input())): # = map(int, input().split()) # = int(input()) # = input() def count(a, i): c = 1 while i < len(a)-1: if not a[i+1]: c+=1 i+=1 else: return c return 0 for _ in range(int(input())): input() a = list(map(int, input()...
Problem: 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, Alexandr...
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); while (n-->0){ int ind=in.nextInt(),z=0; for (int i = 0; i < ind; i++) { int bh=in.nextInt(); if...
Problem: 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, Alexandr...
t=int(input()) for i in range(t): n=int(input()) k = 0 c = [] ls=list(map(int, input().split())) for i in range(0,len(ls),2): a=ls[i] b=ls[i+1] if a == b: k+=2 c.append(a) c.append(b) elif a==1: k+=1 c.append...
Problem: 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, Alexandr...
import java.util.*; import java.io.*; import java.math.BigInteger; public class _practise { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.has...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; int n, m, k, h; int s[100002], q[100002], r[100002]; int main() { while (cin >> n) { int t = 1; while (n--) { cin >> m; k = 0; h = 0; for (int i = 1; i <= m; ++i) { cin >> s[i]; if (s[i]) k++; if (s[i] == 0) h++; ...
Problem: 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, Alexandr...
t = int(input()) i = 0 while i < t: n = int(input()) a = list(map(int, input().split())) b = [] zero = a.count(0) IND = [] index = 0 if zero >= n//2: while index < n: if a[index] == 1: IND.append(index) index += 1 index = 0 ...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) u = list(map(int, input().split())) a = [0] * n ans = [] k = 0 sm = sum(u) cnt = 0 for i in range(n): if u[i] == 0: k += 1 ans.append(0) elif k % 2 == 1 and cnt > 0: if cnt == sm - 1 and sm...
Problem: 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, Alexandr...
from sys import stdin, stdout t = int(stdin.readline()) for case in range(t): n = int(stdin.readline()) arr = list(map(int, stdin.readline().split())) one, zero = 0, 0 for item in arr: if item == 0: zero += 1 else: one += 1 if one > zero: one = one - ...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) lis = list(map(int,input().split())) zer = lis.count(0) one = n-zer if one>zer: o = [1 for i in range(n//2)] n=n//2 if n%2: o+=[1] print(n + 1) print(*o) else: print(n) ...
Problem: 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, Alexandr...
import sys input = sys.stdin.readline t=int(input()) for tests in range(t): n=int(input()) A=list(map(int,input().split())) ZERO=A.count(0) if ZERO>=n//2: print(ZERO) print(*[0]*ZERO) else: ONE=n-ZERO print(ONE//2*2) print(*[1]*(ONE//2*2))
Problem: 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, Alexandr...
t = int(input()) for i in range(t): n = int(input()) arr = [int(j) for j in input().split()] j = 0 tot = 0 s = 0 if sum(arr)%2 != 0: while j < len(arr): if arr[j] == 1: del arr[j] break j+=1 while j < len(arr): if arr[j] == 1: if tot == 0: tot = 1 else: if s%2 != 0: del arr[j...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) z = l.count(0) o = n-z if z>=o: print(n//2) print('0 '*(n//2)) else: if n%4: print(n//2+1) print('1 '*(n//2+1)) else: print(n//2) prin...
Problem: 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, Alexandr...
import java.util.*; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testCases = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int t = 0; t < testCases; t++) { int n = sc.nextInt(); int arr[] = ...
Problem: 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, Alexandr...
t = int(input()) while t != 0: n = int(input()) a = list(map(int, input().split()))[:n] n_1 = a.count(1) if n_1 <= n//2: o = a.count(0) ans = [0] * o print(o) print(*ans) elif n_1 > n // 2 and n_1 % 2 == 0: ans = [1] * n_1 print(n_1) print(*ans...
Problem: 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, Alexandr...
//package com.company; import java.util.*; import java.util.Arrays; import java.lang.Math.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner (System.in); int t = scan.nextInt(); while (t>0) { int n = scan.nextInt(); int...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; long long int M = 1e9 + 7; long long int cdiv(long long int a, long long int b) { return (a % b == 0) ? a / b : a / b + 1; } long long int myMod(long long int a, long long int b) { long long int r = a % b; return r < 0 ? r + b : r; } long long int ModPow(long long int...
Problem: 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, Alexandr...
from collections import defaultdict t = int(input()) for _ in range(t): n = int(input()) l = list(map(int,input().split())) hash = defaultdict(int) for i in l: hash[i]+=1 if hash[0] == hash[1]: print(n//2) print(*[0]*(n//2)) elif hash[0]>hash[1]: print(hash[0]...
Problem: 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, Alexandr...
import java.util.*; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class Test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int tc=0 ;tc<t;tc++){ in...
Problem: 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, Alexandr...
for _ in range(int(input())): n,m=int(input()),list(map(int,input().strip().split())) p=[] for x in range(0,n,2): if m[x]!=m[x+1]: p.append(0) else: p.append(m[x]) p.append(m[x+1]) print(len(p)) print(*p)
Problem: 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, Alexandr...
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
Problem: 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, Alexandr...
for s in[*open(0)][2::2]:a=*map(len,s[::2].split('0')),;r='0'.join('1'*(x-x%2)for x in a);print(len(r),*r)
Problem: 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, Alexandr...
t = int(input()) for _ in range(t): z = 0 ek = 0 n = int(input()) half = int(n/2) l = list(map(int,input().split())) for i in range(n): if l[i] == 0: z += 1 else: ek += 1 if z > ek: print(half) for i in range(0,half): print(...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) evenSum=0 oddSum=0 OI=[] ZI=[] for i in range(1,n+1): if(arr[i-1]==0): ZI.append(i-1) if(arr[i-1]==1): OI.append(i-1) if(i%2==1): oddSum+=arr[i-1] ...
Problem: 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, Alexandr...
N = int(input()) for i in range(N): n = int(input()) a = list(map(int,input().split())) one_cnt = sum(a) zero_cnt = n - one_cnt if zero_cnt >= one_cnt: print(zero_cnt) for _ in range(zero_cnt): print(0,end = " ") else: if one_cnt % 2 == 1: ...
Problem: 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, Alexandr...
import sys import math # import numpy as np fast_reader=sys.stdin.readline fast_writer=sys.stdout.write def input(): return fast_reader().strip() # def print(*argv): # fast_writer(' '.join((str(i)) for i in argv)) # fast_writer('\n') #####################################################################...
Problem: 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, Alexandr...
#!/usr/bin/env python from __future__ import division, print_function import os import 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 main(): for _ in range(int(input())): n ...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; int a = 0, b = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i]) ++b; else ++a; } if (a >= b) { cout << a << endl; ...
Problem: 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, Alexandr...
import java.io.*; import java.util.*; /* polyakoff */ public class Main { static FastReader in; static PrintWriter out; static Random rand = new Random(); static final int oo = (int) 2e9; static final long OO = (long) 4e18; static final int MOD = (int) 1e9 + 7; static void solve() { ...
Problem: 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, Alexandr...
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) x=a.count(1) if x<=n/2: print(n-x) print('0 '*(n-x)) else: print(n//2+((n//2)%2!=0)) print('1 '*(n//2+((n//2)%2!=0)))
Problem: 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, Alexandr...
t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) zero=0 one=0 for i in a: if i==1: one+=1 else: zero+=1 if zero>=one: print(zero) ans=[0]*(zero) print(*ans) else: if one%2==0: ...
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; int t, n; int ans; int a[1005]; int a1, a0; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); ans = 0; a0 = 0; a1 = 0; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { if (a[i]) a1++; ...
Problem: 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, Alexandr...
T = int (input ()) for I in range (0, T): N = int (input ()) X = input () O0 = X.count ('0') O1 = X.count ('1') if N == 2 and O1 != 2: print ('1') print ('0') elif N == 2 and O1 == 2: print ('2') print ('1 1') elif O0 < O1: print (int ((N // 2)...
Problem: 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, Alexandr...
//I AM THE CREED /* //I AM THE CREED /* package codechef; // don't place package name! */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.awt.Point; public class Main{ //#include <bits/stdc++. h> ...
Problem: 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, Alexandr...
n=int(input()) for _ in range(n): a=int(input()) b=list(map(int,input().split())) if a%4!=0: c=a+(4-a%4) else: c=a c//=2 if b.count(1)>=c: print(c) print("1 "*c) else: print(a//2) print("0 "*(a//2))
Problem: 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, Alexandr...
#!/usr/bin/env python from __future__ import division, print_function import math import os import sys from fractions import * from sys import * from decimal import * from io import BytesIO, IOBase from itertools import * from collections import * # sys.setrecursionlimit(10**5) M = 10 ** 9 + 7 # print(math.factorial(...
Problem: 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, Alexandr...
for _ in range(int(input())): input();a=list(map(int,input().split()));s='\n';c=l=0 if a.count(1)%2:a.pop(a.index(1)) for i in a: if i:s+='0 '*(c-c%2)+'1 ';l+=c-c%2+1;c=0 else:c+=1 print(l+c,s+'0 '*c)
Problem: 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, Alexandr...
import sys from collections import defaultdict input=sys.stdin.readline for _ in range(int(input())): n=int(input()) lis=list(map(int,input().split())) z=lis.count(0) o=lis.count(1) if z>=o: print(z) print(*[0]*z) else: print(o-o%2) print(*[1]*(o-o%2))
Problem: 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, Alexandr...
for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) c_1=arr.count(1) c_0=arr.count(0) if c_0>=n//2: print(c_0) print(" ".join("0" for i in range(c_0))) else: if c_1%2!=0: c_1-=1 print(c_1) print(" ".join("1" for i i...
Problem: 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, Alexandr...
import java.io.*; import java.util.Random; import java.util.StringTokenizer; public class A { //Solution by Sathvik Kuthuru public static void main(String[] args) { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(System.out); Task solver = new Task(); int t...
Problem: 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, Alexandr...
t=int(input()) while t: n=int(input()) arr=list(map(int,input().split())) if len(arr)==1 and arr[0]==1: print(0) print([]) t=t-1 continue s=sum(arr) if s%2!=0: for i in range(len(arr)): if arr[i]==1: arr.pop(i) break...
Problem: 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, Alexandr...
import sys input = sys.stdin.readline testCases = int(input()) answers = [] for _ in range(testCases): # take input n = int(input()) arr = list(map(int,input().split())) s = sum(arr) if s <= n // 2: ans = [0] * (n // 2) else: # num of ones is greater than equal to n//2 ...
Problem: 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, Alexandr...
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) s0=0 s1=0 for i in range(0,len(a)): if a[i]==0: s0+=1 else: s1+=1 if s0> len(a)//2: print(len(a)//2 +1) print("0 "*(len(a)//2 +1)) elif s1> len(a)//2: i...
Problem: 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, Alexandr...
for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) o = l.count(1) #print(f'count {o}', l, n) if o>n//2: print(o- (1 if o%2==1 else 0)) print(' '.join(['1' for _ in range(o- (1 if o%2==1 else 0))])) else: print(n - o) print(' '.join(...
Problem: 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, Alexandr...
t = int(input()) def passes(a): return sum(a[::2]) - sum(a[1::2]) == 0 for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] num1s = a.count(1) if num1s * 2 <= n: print(n - num1s) print(*([0] * (n - num1s))) continue if num1s % 2 == 0: p...
Problem: 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, Alexandr...
t = int(input()) while(t>0): n = int(input()) arr = list(map(int,input().strip().split()))[:n] cnt_0 = arr.count(0) if cnt_0 >= n/2: print(cnt_0) for i in range(cnt_0): print(0,end=" ") elif cnt_0 < n/2: print(arr.count(1)-arr.count(1)%2) for i in range(ar...
Problem: 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, Alexandr...
t = int(input()) for i in range(t): n = int(input()) a = [int(i) for i in input().split()[:n]] k=0 if(n==1): if(a[0] == 1 and a[1] == 1): print(2) print('1 1') else: print(1) print(0) else: while (k < len(a) - 1): i...
Problem: 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, Alexandr...
t = int(input()) for _ in range(t): n = int(input()) *a, = map(int, input().split()) ans = [] z, one = a.count(0), a.count(1) if z >= one: print(n // 2) print(*[0] * (n // 2)) else: print((one // 2) * 2) print(*[1] * ((one // 2) * 2))
Problem: 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, Alexandr...
T=int(input()) for _ in range(T): n=int(input()) a = list(map(int,input().split())) ones = sum(a) z = n -ones if(ones==n or ones==0): print(n) for i in range(n): print(a[i],end=' ') elif(ones <= n//2): print (z) for i in range(z): print(0,e...
Problem: 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, Alexandr...
import java.util.*; public class Ahahahahahahahaha { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int arr[]=new int[n]; int z=0,o=0; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); if(arr[i]==0) { z++; ...
Problem: 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, Alexandr...
import java.io.*; import java.util.*; public class Solution{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- != 0){ int n = sc.nextInt(); int arr[] = new int[n]; int zero = 0, one = 0; ...
Problem: 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, Alexandr...
for _ in range(int(input())): n=int(input()) a=list(map(int, input().split())) c_1=0 c_0=0 for i in a: if i==1: c_1+=1 else: c_0+=1 if c_0>=c_1: print(n//2,end=" ") count=0 for i in a: if count==n//2: bre...
Problem: 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, Alexandr...
def count_balance(case): count = 0 for j in range(0,len(case)): if (j+1) % 2 == 0 and case[j] == 1: count = count + 1 elif (j+1) % 2 != 0 and case[j] == 1: count = count - 1 return count def change_balance(case, direction): down = 0 up = 0 for i in ...
Problem: 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, Alexandr...
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) k=n//2 a,b=l.count(0),l.count(1) if a>=b: print(a) print('0 '*a) else: print((b//2)*2) print("1 "*(b//2)*2)
Problem: 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, Alexandr...
#include <bits/stdc++.h> using namespace std; void solve(int a[], int n) { int i; int c = 0; for (i = 0; i < n - 1; i = i + 2) { if (a[i] - a[i + 1] == 0) c++; } if (c == n / 2) { cout << n << '\n'; for (int i = 0; i < n; i++) cout << a[i] << " "; cout << '\n'; return; } else { int c...
Problem: 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, Alexandr...
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().rstrip().split()) inl = lambda: list(map(int, input().split())) out = lambda x, s='\n': print(s.join(map(str, x))) t = ini() for _ in range(t): n = ini() a = inl() if n ==...
Problem: 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, Alexandr...
for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) l=a.count(0) if l>=n//2: print(l) print('0 '*l) else: y=n-l if y%2==0: print(y) print('1 '*y) else: print(y-1) print('1 '*(y-1))
Problem: 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, Alexandr...
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(buf.readLine().trim()); while(t-->0) { int n = Integer.parseInt(buf.readLine...
Problem: 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, Alexandr...
n1=int(input()) for test in range (n1): n = int(input()) set1=[int(y) for y in input().split()] zerocount=0 onecount=0 for i in range(n): if(set1[i]==0): zerocount=zerocount+1 else: onecount=onecount+1 k=int(n/2) if(onecount>zerocount): if(...
Problem: 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, Alexandr...
import java.io.*; import java.util.*; import static java.lang.Math.min; public class Main { void solve() throws Throwable { int t = readInt(); for (int test = 0; test < t; test++) { int n = readInt(); int[] a = readIntArray(n); int zeroCnt = 0; for ...