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...
import java.io.*; import java.util.*; public class One { public static void main(String[] args) { FastReader in = new FastReader(); int tt = in.nextInt(); while(tt-- > 0){ int n = in.nextInt(); int[] a = in.readArray(n); int zeros = 0; int 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...
import math for test in range(int(input())): n = int(input()) a = [*map(int,input().split())] val_after = [] curr = 0 for i in range(n): curr += (-1)**i * a[i] if curr != 0: val = 0 prev_val = 0 for idx, i in reversed(list(enumerate(a))): val = 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.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class A1407 { public static void main(String args[]) { FastReader sc = new FastReader(); int t = sc.nextInt(); while (t-- != 0) { int n = sc.next...
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 a = 0, b = 0; int arr[n]; for (int i = 0; i < n; i++) { int c; cin >> c; if (c == 1) a++; else b++; } if (b >= n / 2) { cout << 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...
from sys import stdin, stdout from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque from heapq import merge, heapify, heappop, heappush, nsmallest from bisect import bisect_left as bl, bisect_right as br, bisect mod = pow(10, 9) + 7 mod2 = 998244353...
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 test in range(t): N = int(input()) arr = [int(i) for i in input().split(" ")] s = "" k = 0 j = 0 while j<=(N-1): if arr[j]+arr[j+1]==1: k = k+1 s = s+'0 ' if arr[j]+arr[j+1]==0: k = k+2 s = s+'0 0 ' if 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...
import sys sys.setrecursionlimit(2147483647) input=sys.stdin.readline def solve(t, A): zeros = A.count(0) ones = A.count(1) half = t //2 if zeros > half: return ['0']*(zeros // 2 * 2) elif ones > half: return ['1']*(ones // 2 * 2) elif half % 2 == 0: return ['1'] * half else: if A[0] == 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 sys range = xrange input = raw_input t = int(input()) for _ in range(t): n = int(input()) A = [int(x) for x in input().split()] B = [a for a in A if a] C = [a for a in A if not a] if len(B) > n//2: if len(B) & 1: B.pop() print len(B) print ' '.join(str(...
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...
otv = [] for i in range(int(input())): n = int(input()) l1 = 0 l0 = 0 for j in input().split(): if j == '1': l1 += 1 else: l0 += 1 line = '' if l1 > l0: if l1 & 1 == 1: for j in range(l1 - 1): line += '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...
t=int(input()) for _ in range(t): n=int(input()) li=list(map(int,input().split())) c_1=0 c_0=0 for i in range(n): if li[i]==1: c_1+=1 else: c_0+=1 if c_0>=n//2: print(n//2) for i in range(n//2): print(0,end=" ") print() else: par=0 if (n//2)%2==0 else 1 if par...
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 math from collections import defaultdict,deque from itertools import permutations ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" #t=1 t=ii() for _ in range(t): n=ii()...
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...
#_________________ Mukul Mohan Varshney _______________# #Template import sys import os import math import copy from math import gcd from bisect import bisect from io import BytesIO, IOBase from math import sqrt,floor,factorial,gcd,log,ceil from collections import deque,Counter,defaultdict from itertools import permu...
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 main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int testCases = 1; cin >> testCases; while (testCases--) solve(); return 0; } void solve() { int n, zeros = 0; cin >> n; vector<int> a(n); for (int& aa : 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; const int maxn = 1e5 + 10; const int N = 1e6 + 10; const int M = 3e5 + 10; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const int mod2 = 998244353; const int mod3 = 1e9 + 9; const int hash1 = 131; const int hash2 = 13331; co...
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 linput(): return [int(i) for i in input().split()] def nod(a, b): while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return a + b qwertyyyyyy = int(input()) for ______ in range(qwertyyyyyy): n = int(input()) q = linput() if q.count(0) >= (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...
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader ...
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 process(): n=int(input()) li=list(map(int,input().split())) removed=0 l=[] flag=0 lb=-1 for i in range(0,n): if(li[i]==1): flag=1 lb=i for j in range(i+1,n): if(li[j]==1): flag=0 # l.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 com.sun.org.apache.xpath.internal.operations.String; import java.io.*; import java.util.*; public class scratch_25 { // int count=0; //static long count=0; static class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** * call this meth...
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 sys import stdin,stdout import math import random import heapq from collections import Counter from functools import lru_cache #@lru_cache(maxsize=None) #for optimizing the execution time of callable objects/functions(placed above callable functions) try: for _ in range(int(input())): n=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...
t = int(input()) for _ in range(t): n = int(input()) A = list(map(int, input().split())) c0 = 0 c1 = 0 for a in A: if a == 0: c0 += 1 else: c1 += 1 if c0 >= c1: print(n-c1) ans = [0]*c0 print(*ans) else: if c1%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...
for _ in range(int(input())): n=int(input()) lst=input().split() one=lst.count("1") zero=lst.count("0") if one>zero: lst=list(filter(lambda x: x=="1",lst)) if len(lst)&1: lst.pop() else: lst=list(filter(lambda x: x=="0",lst)) print(len(lst)) 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...
t=int(input()) while t: n=int(input()) a=list(map(int, input().split())) p=n//2 l2=[] if p%2: if a[0]!=a[1]: l2.append(0) else: l2.append(a[0]) l2.append(a[1]) for i in range(2,n,4): sum=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...
import java.io.InputStream; import java.io.BufferedReader; import java.io.PrintWriter; import java.io.InputStreamReader; import java.io.IOException; import java.util.*; public class Aha { public static void main(String[] args) throws IOException { InputReader in = new InputReader(System.in); PrintWriter pw =...
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=[int(x) for x in input().split()] ic=0 oc=0 for i in arr: if i==1: ic+=1 else: oc+=1 if ic>oc: if ic%2==0: print(ic) print('1 '*ic) else: print(ic-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...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) if arr.count(0)>=n//2: print(n // 2) for i in range(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...
import java.util.*; import java.io.*; public class Ahahah { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new Stri...
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.File;import java.io.FileInputStream;import java.io.FileNotFoundException; import java.io.IOException;import java.io.InputStream;import java.io.PrintStream; import java.io.PrintWriter;import java.security.AccessControlException;import java.util.Arrays; import java.util.Collection;import java.util.Comparat...
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())) if a.count(0)>=n//2: 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) print(*[1]*(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...
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 self.write = self.buffer.write if self...
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()) l = list(map(int, input().split())) suml = sum(l) if suml<=n/2: print(n-suml) print(*[0 for _ in range(n-suml)]) else: count = suml-suml%2 print(count) print(*[1 for _ in range(count)])
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())) k=sum(a) s=[] if(k>(n-k)): for i in a: if(i==1): s.append(i) if(len(s)%2!=0): s.remove(1) else: for i in a: if(i==0): s.ap...
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.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { long mod1=(long)1e9+7; int mod2=998244353; public void solve() throws Exception { int t=sc.nextInt(); while(t-->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 main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, n; cin >> t; while (t--) { cin >> n; vector<int> vec(n); int cnt0 = 0, cnt1 = 0; for (int i = 0; i != n; ++i) { cin >> vec[i]; if (!vec[i]) ++cnt0; ...
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 testcase in range(testcases): n = int(input()) temparr = input() temparr = temparr.split() count0 = 0 count1 = 0 for i in temparr: if i == "0": count0 += 1 else: count1 += 1 half = n // 2 ans = [] if count1 <= 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...
import java.util.*; import java.io.*; public class vivek{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { ...
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...
# Author: S Mahesh Raju # Username: maheshraju2020 # Date: 08/09/2020 from sys import stdin, stdout, setrecursionlimit import heapq from math import gcd, ceil, sqrt from collections import Counter, deque from bisect import bisect_left, bisect_right ii1 = lambda: int(stdin.readline().strip()) is1 = lambda: stdin.readlin...
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; template <class A> void read(vector<A>& v) { for (auto& x : v) cin >> x; } template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cout << *x, 0); template <class c> 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...
tests = int(input()) for t in range(tests): n = int(input()) ls = list(map(int, input().split())) res = [] curr = 0 for item in ls: if item == 0: if curr % 2 == 1: res[-1] = 0 else: res.append(item) curr = 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...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int,input().split())) o = 0 z = 0 for i in range(n): if(l[i]): o+=1 else: z+=1 if(o>z): o-=o%2 print(o) for i in range(o): print(1, end =" ") else: print(z) f...
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 Ahaha { static BufferedReader br; static StringTokenizer tokenizer; public static void main(String[] args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = nextInt(); outer...
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]:r='0'.join('1'*(x-x%2)for x in map(len,s[::2].split('0')));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): n=int(input()) l=list(map(int,input().split())) x=sum(l) if x>n//2: if x%2: print(x-1) l=[1]*(x-1) print(*l) else: print(x) l=[1]*x print(*l) 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()) a=list(map(int,input().split())) cnt=a.count(1) if(cnt==n//2): print(n//2) for i in range(n//2): print(0,end=" ") print() continue if((n//2)%2==1 and cnt>n//2): print(n//2+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...
remaining_test_cases = int(input()) for _ in range(remaining_test_cases): N = int(input()) list_of_0_and_1 = list(map(int,input().split())) count_number_of_zeroes = 0 count_number_of_ones = 0 for i in range(len(list_of_0_and_1)): if list_of_0_and_1[i] == 0: count_numbe...
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...
# -*- coding: utf-8 -*- """ Created on Tue Sep 8 20:03:31 2020 @author: Yogesh Panjwani """ t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split()))[:n] ones=0 zeros=0 for j in a: if j==1: ones+=1 else: zeros+=1 if zeros...
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())) o=a.count(1) z=n-o if(z>=n//2): print(n//2) f=[0]*(n//2) print(*f) else: if(o&1): print(n-z-1) f=[1]*(n-z-1) print(*f) else: print(n-z) f=[1]*(n-z) print(*f)
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())) c1=l.count(1) c2=l.count(0) if(c1<=c2): print(c2) l=[0]*c2 print(*l) else: if(c1%2): print(c1-1) l=[1]*(c1-1) print(*l) else: 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...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) cnt0 = arr.count(0) cnt1 = arr.count(1) if cnt1 <= int(n/2): print(n-cnt1) print(' '.join(['0']*(n-cnt1))) elif cnt0 <= n/2: if cnt1%2 == 1: print(cnt1-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...
###################################################### ############Created by Devesh Kumar################### #############devesh1102@gmail.com#################### ##########For CodeForces(Devesh1102)################# #####################2020############################# ###############################################...
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())) o = arr.count(1) if o<=n//2: print(n-o) print(*([0]*(n-o))) else: print(o-(o%2)) print(*([1]*(o-(o%2)))) # def bfs(graph,src,n): # visited = [0]*n # queue = [src] # vi...
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()) // 2 arr = input() #Lista x = ('1 ' if arr.count('1') > arr.count('0') else '0 ') if (x == '1 ' and n % 2 == 1) : n += 1 print(n, x * n, 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...
import java.io.*; import java.math.*; import java.util.*; public class Codeforce2 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWrite...
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 from collections import defaultdict,Counter # input=sys.stdin.readline # def print(x): # sys.stdout.write(str(x)+"\n") # sys.stdout=open("CP1/output.txt",'w') # sys.stdin=open("CP1/input.txt",'r') # mod=pow(10,9)+7 t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().s...
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 queue import PriorityQueue for _ in range(int(input())): n = int(input()) ar = list(map(int,input().split())) o,z= 0,0 for i in ar: if i == 0: z +=1 else: o +=1 p = n//2 if p%2 == 0 : if z>o: 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...
for t in range(int(input())): num=int(input()) arr=list(map(int,input().split())) ones=arr.count(1) zeros=arr.count(0) if zeros>=num//2: print(zeros) for i in range(num): if arr[i]==0: print(0,end=' ') else: if ones%2!=0: ones-=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...
t = int(input()) for i in range(t): ind = [] dni = [] n = int(input()) s = list(map(int, input().split())) count = 0 for j in range(n): if(s[j] == 0 or j == n-1): if(s[j] == 1): count += 1 dni.append(j) if(count > 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...
def getInts(): return [int(s) for s in input().split()] def getInt(): return int(input()) def getStrs(): return [s for s in input().split()] def getStr(): return input() def listStr(): return list(input()) def solve(): N = getInt() A = getInts() if sum(A) > N//2: ans = [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...
#include <bits/stdc++.h> using namespace std; bool prime[1000001]; void sieve() { memset(prime, true, sizeof(prime)); for (long long int i = 2; i * i <= 1000000; i++) if (prime[i]) for (long long int j = i * i; j <= 1000000; j += i) prime[j] = false; prime[0] = prime[1] = false; } long long int fast_pow...
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 Main { public static Scanner in = new Scanner(System.in); public static void Solve() { int n = in.nextInt(); int[] vec = new int[n]; for(int i = 0; i < n; i++) vec[i] = in.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...
x=int(input()) for i in range(x): dlzkaPola=int(input()) pole=list(map(int, input().split())) pole.append(0) pouzit=[True]*dlzkaPola kolkozostalo=dlzkaPola j=0 while j < dlzkaPola+1: # print(j) if pole[j]==1: if pole[j+1]==0: pouzit[j]=False ...
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 Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++) a[i]=in.nextInt(); ...
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 math import * from collections import * from itertools import * from functools import * from bisect import * from heapq import * from operator import * from sys import * setrecursionlimit(100000000) for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) c1,c0=l.count(1),l.count...
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 [0] * int(input()): n = int(input()) a = list(map(int, input().split())) if a.count(0) < len(a) // 2: print((len(a)) // 2 + (len(a) // 2) % 2) print('1 ' * (len(a) // 2 + (len(a) // 2) % 2)) else: print(a.count(0)) print('0 ' * a.count(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 main() { long long int times; cin >> times; while (times--) { long long int n; cin >> n; long long int arr[n]; long long int zero = 0; long long int one = 0; for (long long int i = 0; i < n; i++) { cin >> arr[i]; if (arr[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...
for _ in range(int(input())): n=int(input()) a = input().split() o = a.count('1') z = n-o half = n>>1 if o>z: if half&1: half+=1 print(half) print('1 '*half) else: print(half) print('1 '*half) else: print(half) print('0 '*half)
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()) even0, even1 = [], [] odd0, odd1 = [], [] a = list(map(int, input().split())) while True: last_eq = -1 total = 0 for i in range(len(a)): if i % 2: s = -1 else: s = 1 if a[i] == 1: total += s if not total: last_eq = i if total...
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.lang.*; import java.io.*; public class First { public static void main(String[] args) throws Exception { // BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // int t = Integer.parseInt(br.readLine()); // while (t-- > 0) { // int n = Integer.parseInt(br....
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())) a = arr.count(0) b = arr.count(1) if b > n // 2: print(b - b % 2) print(*[1 for _ in range(b - b % 2)]) elif b == n // 2: print(a) print(*[0 for _ in range(a)]) 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.*; public class adda { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int zero=0,one=0; for(int i=0;i<n;i++) { 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...
def altSum(): n = int(input()) c = 0 list1 = list(map(int, input().split())) list2 = [] for i in range(0, len(list1)): if list1[i]==0: if c==1: c=0 list2.append(0) elif list1[i]==1: if c==1: list2.append(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...
#include <bits/stdc++.h> using namespace std; using ll = long long; class AAhahahahahahahaha { public: void solve(std::istream& cin, std::ostream& cout) { int t; cin >> t; while (t--) { int n; cin >> n; int a[n], c0 = 0, c1 = 0; for (int i = 0; i < n; i++) { cin >> a[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()) li = list(map(int,input().split())) ek = li.count(1) sunno = n-ek if sunno>=n//2: print(sunno) print(*[0]*sunno) else: ek -= ek%2 print(ek) print(*[1]*ek)
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 ahaha(arr,n): l = [] c_1 = 0 c_0 = 0 for i in arr: if i==0: c_0+=1 else: c_1+=1 if c_1>=(n//2) and c_1%2==0: l = [1]*c_1 elif c_1>(n//2) and c_1%2: l = [1]*(c_1-1) elif c_1==(n//2) and c_1%2: l = [0]*(c_1) elif c_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...
import sys ii = lambda: sys.stdin.readline().strip() idata = lambda: [int(x) for x in ii().split()] def solve(): n = int(ii()) data = idata() ans = [data[0]] count = data[0] for i in range(1, n): if ans[-1] == 1 and data[i] == 0 and count == 1: ans[-1] = 0 count = 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 mod = 1e9 + 7; void solve() { int n; cin >> n; vector<int> a(n); int one = 0, zero = 0; for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) { cin >> a[i]; } int sum = 0; int p1 = -1, p0 = -1, pe1 = 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 java.util.*;import java.io.*;import java.math.*; public class Main { public static void process()throws IOException { int n=ni(); int[]A=nai(n); int c=0; for(int i=0;i<n;i++) if(A[i]==1) c++; if(n-c>=n/2) { pn(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...
import java.io.*; import java.util.*; public class a { public static void main(String[] args) throws IOException { FastScanner stdin = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = stdin.nextInt(); for (int z = 1; z <= t; z++) { int n = stdin.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; int t, n, a; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n; int zeros = 0; int ones = 0; for (int i = 0; i < n; i++) { cin >> a; if (a == 0) zeros++; else ones++; } 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...
#include <bits/stdc++.h> using namespace std; long long power(long long base, long long pow, long long mo) { long long res = 1; while (pow) { if (pow & 1) res = (res * base) % mo; base = (base * base) % mo; pow /= 2; } return res; } long long Mul(long long a, long long b, long long mo) { long long...
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=[int(x) for x in input().split()] c=a.count(0) c1=a.count(1) if c>=n/2: print(c) for i in range(c): print(0,end=" ") print() else:# c1 > n/2 if (c1&1): c1-=1 print(c1) for i in ran...
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.IOException; import java.io.InputStreamReader; public class _669A { static BufferedReader br; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); int t = readInt(); while(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...
from collections import deque from collections import OrderedDict import math import sys import os import threading import bisect import operator import heapq from atexit import register from io import BytesIO #sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)) #sys.stdout = BytesIO() #register(lambda: os...
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())) s1=arr.count(1) s2=arr.count(0) if s2>=n//2: print(s2) print("0 "*(s2)) else: if s1%2==1: print(s1-1) print("1 "*(s1-1)) else: print(s1) ...
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, a[1000 + 10], c; int main() { std::ios::sync_with_stdio(false); int T; cin >> T; while (T--) { cin >> n; c = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (!a[i]) c++; } if (c >= n / 2) { cout << n / 2 << 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...
## necessary imports import sys input = sys.stdin.readline from bisect import bisect_left; from bisect import bisect_right; from math import ceil, factorial; def ceil(x): if x != int(x): x = int(x) + 1; return x; # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b];...
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 n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } if (n == 2) { if (a[0] == 1 && a[1] == 1) { cout << "2\n1 1\n"; } else { cout << "1\n0\n"; } return; } vector<int> b; for (int i = 0; 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.util.*; import java.util.Scanner; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import javax.lang.model.util.ElementScanner6; public class A1407M2 { public static void ma...
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; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (int &x : v) { cin >> x; } int c = 0, u = 0; for (int i = 0; i < n; i++) { if (v[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...
case=int(input()) for i in range(case): input() lst=list(map(int, input().split(" "))) one=lst.count(1) zero=lst.count(0) f=0 if one<=zero: f=1 else: f=0 for x in range(min(one, zero)): lst.remove(f) if 0 not in lst and len(lst)%2==1: lst.remove(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 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 self.write = self.buffer.write if self.wri...
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 works(l): x = 0 for i in range(len(l)): if i%2: x += int(l[i]) else: x -= int(l[i]) return x == 0 for _ in range(int(input())): n = int(input()) l = input().split() if works(l): print(n) print(' '.join(l)) else: for i in ran...
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, a, i, b; cin >> t; while (t--) { cin >> a; int s = 0, z = 0; for (i = 0; i < a; i++) { cin >> b; if (b == 0) { z++; } else { s++; } } if (z < s) { cout << s - s % 2 << endl; fo...
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 alterSum(arr,n): s = 0 for i in range(n): if i%2 == 0: s += arr[i] else: s -= arr[i] return s # for _ in range(1): # n = 10 # arr = [0,1,0,1,1,1,0,1,0,0] for _ in range(int(input())): # print('q') n = int(input()) arr = 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...
t=int(input()) for _ in range(t): n=int(input()) *a,=map(int, input().split()) for i in range(n-1,-1,-2): if a[i]!=a[i-1]: if a[i]: a[i]=2 else:a[i-1]=2 a=[ai for ai in a if ai<2] print(len(a)) print(*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; int main() { long long int t; cin >> t; while (t--) { long long int n, i; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } if (n == 2) { if (a[0] != a[1]) { cout << 1 << "\n"; cout << 0 << "\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 import os.path # ========================================================================= if(os.path.exists('in.txt')): sys.stdin = open("in.txt", "r") sys.stdout = open("out.txt", "w") # ============================================================================================= for _ in range(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()) a=[int(x) for x in input().split()] cnt0=a.count(0) cnt1=n-cnt0 if cnt0>=n//2: print(cnt0) for i in range(cnt0): print(0,end=" ") else: print(cnt1-(cnt1%2)) for i in range(cnt1-(cnt1%2)): 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...
#include <bits/stdc++.h> using namespace std; int solve() { long long int n; cin >> n; vector<long long int> a; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; a.push_back(x); } long long int c = a[0]; long long int n1odd = 0, n1even = 0; vector<long long int> v; for (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()) arr=list(map(int,input().split())) zero= arr.count(0) one = n-zero if one*2 <=n: print(zero) print(*[0]*zero) else: if one%2==1: one-=1 print(one) print(*[1]*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()) l = list(map(int,input().split())) o = l.count(1) z = l.count(0) e = n//2 if o == 0: print(n) print(*l) continue if o <= e: print(n-o) m = [0]*(n-o) print(*m) continue if o%2 == 0 and...