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...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) x = [1] * (n // 2) y = [0] * (n // 2) if a.count(0) >= n // 2: print(n // 2) print(*y) elif (n // 2) % 2 == 0: print(n // 2) print(*x) 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...
t=int(input()) for _ in range(t): n=int(input()) list1=list(map(int,input().strip().split())) index=-1 count=0 list2=[] for i in range(n): val=list1[i] if val==1: if index==-1: index=i if i%2==0: curr=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()) arr=list(map(int,input().split())) s0=arr.count(0) s1=arr.count(1) if s1<=n//2: arr=[i for i in arr if i!=1] else: arr=[i for i in arr if i!=0] if s1%2!=0: arr.remove(1) print(len(arr)) for i in 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...
#include <bits/stdc++.h> int main() { int t, n; scanf("%d", &t); while (t--) { scanf("%d", &n); int i, j, a; int count1 = 0, count0 = 0; for (i = 1; i <= n; i++) { scanf("%d", &a); if (a == 1) { count1++; } else { count0++; } } if (count1 <= 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...
""" Satwik_Tiwari ;) . 8th Sept , 2020 - Tuesday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, 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...
# This is a sample Python script. # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. def print_hi(name): # Use a breakpoint in the code line below to debug your script. print(f'Hi, {name}') # Press ...
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 __future__ import division, print_function MOD = 998244353 mod = 10**9 + 7 # import resource # resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY]) def prepare_factorial(): fact = [1] for i in range(1, 100005): fact.append((fact[-1] * i) % mod) ifact = [0] * 10000...
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 op(): n=int(input()) arr = list(map(int, input().split())) one=arr.count(1) zero=n-one if zero>=n//2: print(zero) for i in range(zero): print('0 ',end='') else: print(one-one%2) for i in range(one-one%2): print('1 ',end='') '''if 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...
import sys from collections import Counter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] 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()) A=[int(_) for _ in input().split()] zrs,one=0,0 for _ in range(n): if A[_]==1: one+=1 else: zrs+=1 if zrs>=one or one==1: print(zrs) for _ in range(zrs): print(0,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...
import java.io.*; import java.util.*; public class A{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));} public FastReader(String fileName) throws FileNotFoundException{br = new BufferedRead...
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 ques1 { public static void main(String[] args)throws Exception{ new ques1().run();} long mod=1000000000+7; void solve() throws Exception { for(int ii=ni();ii>0;ii--) { int N=ni(); int a[]=new int[N]; for (int i = 0; i < a.length; i++) { a[i]=ni...
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 as _sys def main(): t = int(input()) for i in range(t): n, = _read_ints() a = tuple(_read_ints()) fixed_a = fix_array(a) print(len(fixed_a)) print(*fixed_a) def _read_line(): result = _sys.stdin.readline() assert result[-1] == "\n" return result...
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()) Ans = [] for i in range(N): A = int(input()) B = list(map(int, input().split())) T = [] P = [] m = 0 for j in range(A): if B[j] == 1: T.append(1) m = j else: P.append(0) k = sum(T) h = 0 ok = 0 if k % 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())) cnt0=0 cnt1=0 for val in a: if val==0: cnt0+=1 else: cnt1+=1 if cnt0>=cnt1: print(cnt0) print("0 "*cnt0) else: if cnt1%2==0: print(cnt...
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 A { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0){ int n=sc.nextInt(); int[] arr=new int[n]; int zero=0; int one=0; 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...
for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) ones=a.count(1) zeroes=a.count(0) if ones<=n/2: print(zeroes) for i in range(zeroes): print(0,end=" ") else: print(ones-ones%2) for i in range(ones-ones%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 import heapq, functools, collections import math, random from collections import Counter, defaultdict # available on Google, not available on Codeforces # import numpy as np # import scipy def solve(lst): # fix inputs here console("----- solving ------") console(lst) if lst.count('0') >= 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...
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict #threading.stack_size(10**8) mo...
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()) s=list(map(int,input().split())) zero=0 one=0 for i in range(n): if s[i]==1: one+=1 else: zero+=1 if zero>=one: print(zero) for i in range(zero): print(0,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...
t = int(input()) for _ in range(t): n = int(input()) s = list(map(int,input().split())) one=0 zero=0 for i in range(len(s)): if s[i]==1: one+=1 else: zero+=1 if i>0 and s[i]==1 and s[i-1]==1: f = True ans = zero 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...
for _ in range(int(input())): n = int(input()) one = list(map(int, input().split())) one = len([x for x in one if x == 1]) zero = n - one if zero >= n // 2: print(zero) print(*(["0"] * zero)) else: if one % 2 == 1: one -= 1 print(one) 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; void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { cout << x; } void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __print(float x) { cou...
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_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; long long int o = 0, z = 0; for (long long int i = 0; i < n; i++) { cin >> a[i]; if (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...
from sys import stdin,stdout input=stdin.readline for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) e=a.count(1) o=n-e if e-(e%2)>=n//2: b=[1]*(e-(e%2)) else: b=[0]*o stdout.write(str(len(b))+'\n') stdout.write(' '.join(str(i) 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...
import sys import math t= int(input()) for i in range(t): n= int(input()) a= list(map(int,input().split())) one=0 zer=0 for j in a: if j==1: one+=1 else: zer+=1 if one<=(n//2): print(zer) for j in range(zer): print(0,end=' ') ...
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 def solve(): n=int(input()) L=list(map(int,input().split())) zero = L.count(0) if zero>=n/2: print(zero) print(*[0]*zero) return one = n-zero print(one//2*2) print(*[1]*(one//2*2)) if __name__=="__main__": 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...
# https://codeforces.com/contest/1407/problem/0 import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ # do magic here t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) ones = arr.count(1) zeros = arr.count(0) ch = '0' if zeros == 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...
def solve(): n = int(input()) lst = list(map(int,input().split())) if sum(lst) <= n // 2: print(n//2) print("0 " * (n // 2)) else: print(n//2 + (n // 2) % 2) print("1 " * (n//2 + (n // 2) % 2)) for i in range(int(input())): 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()) l=list(map(int,input().split())) if n==2: if 0 in l: print(1) print(0) else: print(2) print(' '.join(list(map(str,l)))) elif l.count(1)>l.count(0): print(n-l.count(0)-l.count(0)%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()) l=list(map(int,input().split())) c=l.count(0) f=l.count(1) if c>=f: print(n//2) for _ in range(n//2): print(0,end=" ") else: if (n//2)%2!=0: n=n+2 print(n//2) for _ in range(n//2): print(1,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...
#include <bits/stdc++.h> using namespace std; long long calc(long long n) { return (((n - 1) * n) / 2); } int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; map<long long, long long> mp; for (long long i = 0; i < n; i++) { cin >> a[i]; mp[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 java.util.*; import java.io.*; import java.math.BigInteger; public class A { private static final int mod =(int)1e9+7; public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(...
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 functools import reduce import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import * from io import BytesIO, IOBase input = lambda: sys.stdin.readline().rstrip("\r\n") def value(): return tuple(map(int, input().split())) # multiple values def 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...
def mi(): return map(int, input().split()) for _ in range(int(input())): n = int(input()) a = list(mi()) o,z=0,0 for i in range(n): if a[i]: o+=1 else: z+=1 if o<=n//2: print (z) print ('0 '*z) else: o-=o%2 print (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...
/* /$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ |__ $$ /$$__ $$| $$ | $$ /$$__ $$ | $$| $$ \ $$| $$ | $$| $$ \ $$ ...
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,n): count_zero = 0 count_one = 0 for x in arr: if(x==0): count_zero +=1 else: count_one +=1 if(count_one>count_zero): if(count_one&1 ==0): return(ones(count_one)) else: return(ones(count_one-1)) else: if(count_zero&1==0): return(zeros(count_zero)) else: return(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(0,int(input())): n = int(input()) l1 = list(map(int,input().split())) z = 0 o = 0 for i in l1: if i == 0: z+=1 else: o+=1 if o > z: if o % 2 ==1: o -=1 print(o) for _ in range(0,o): 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...
#include <bits/stdc++.h> using namespace std; int tr[3001]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int _0 = 0, _1 = 0; for (int i = 1; i <= n; i++) { cin >> tr[i]; if (tr[i]) _1++; else _0++; } if (_1 > _0) { cout << n / 2 + (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 vishal in range(int(input())): n=int(input()) a=list(map(int,input().split())) if a.count(1)>a.count(0): kk=n-a.count(0)-((n-a.count(0))%2) print(kk) print(" ".join(["1"]*(kk))) else: print(n-a.count(1)) print(" ".join(["0"]*(n-a.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...
#include <bits/stdc++.h> using namespace std; int main() { int t, zero, one, n; cin >> t; while (t--) { cin >> n; string b; zero = 0; one = 0; for (int i = 0; i < n; i++) { char c; cin >> c; if (c != ' ') { b += c; } } 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...
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) c0=0 for i in l: if (i == 0): c0 += 1 c1 = n - c0 if (c0 >= n // 2): print(c0) print('0 ' * c0) else: if (c1 % 2): c1 -= 1 print(c1) 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...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) if a.count(1) <= n//2: final = [0]*(n//2) print(len(final)) print(*final) else: final = [1]*((a.count(1)//2)*2) print(len(final)) print(*final)
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.math.*; public class ahaha { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int runs = sc.nextInt(); while(runs-->0) { int size = sc.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); int zero = 0; int one = 0; for(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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { // Scanner sc= new Scanner(System.in); FastScanner sc = new FastScanner(); int t = sc.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 _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) even, odd = 0, 0 for i in range(n): if (i+1)%2 == 0: even += arr[i] else: odd += arr[i] if even == odd: print(n) for num in arr: print(num,end=" ")...
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 long long int mod = 1000000000 + 7; const long long int N = 1000000 + 6; int recur_depth = 0; template <typename Ostream, typename Cont> typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<( Ostream& os, const Cont& v) { os << "["; 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 t in range(int(input())): n=int(input()) num=list(map(int,input().split())) i=0 out=[] while i<len(num): if i==len(num)-1: if num[i]==0: out.append(0) break if num[i]==num[i+1]: out.append(num[i]) out.append(num[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...
import sys read = lambda: sys.stdin.readline().strip() readi = lambda: map(int, read().split()) for _ in range(int(read())): n = int(read()) nums = list(readi()) for i in range(n): total = 0 step = 1 j = 0 while j < n: if j != i: total += step * ...
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 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> char dud(...); struct debug { template <class c> debug& operator<<(const 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 as dd from collections import deque from functools import * from fractions import Fraction as f from copy import * from bisect import * from heapq import * #from math import * from itertools import permutations ,product def eprint(*args): print(*args, file=sys.stder...
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())) d = [0,0] for i in arr: d[i]+=1 if(d[0]>=d[1]): print(d[0]) print('0 '*d[0]) else: k = d[1] - d[1]%2 print(k) print('1 '*k)
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 pos(arr,n): evenP=[] oddP=[] for i in range(len(arr)): if i%2==0 and arr[i]==1: evenP.append(i) if i%2!=0 and arr[i]==1: oddP.append(i) if n==1: return oddP else: return evenP def haha(arr): even=arr[0::2] odd=arr[1::2] n=len(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...
import java.util.Scanner; public class Main { 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 cnt1=0; int cnt2=0; for (...
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()) i=0 a=list(map(int,input().split())) while i<len(a)-1: if a[i]-a[i+1]!=0: if i+2>=len(a): a=a[:len(a)-2]+[0] elif a[i]==a[i+2]: a=a[:i+1]+a[i+2:] else: a=a[:i]+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...
import java.util.*; import java.lang.*; import java.io.*; public class A { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int arr[]=new int[n]; int one=0,zero=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...
#OM GANESHAY NAMH #GANPATI BAPPA MORYA import math,queue,heapq import sys sys.setrecursionlimit(10**6) fastinput=sys.stdin.readline fastout=sys.stdout.write t=int(fastinput()) while t: t-=1 n=int(fastinput()) a=list(map(int,fastinput().split())) c=a.count(1) if c==0 or c==n: 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...
for _ in range(int(input())): n, lst = int(input()), input() count0, count1 = lst.count('0'), lst.count('1') if count0 >= n / 2: print(n // 2) for i in range(n // 2): print(0, end=" ") else: print(count1 - (count1 & 1)) for i in range(count1 - (count1 & 1)): print(1, end=...
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 tt 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: print(a.count(1) - (a.count(1) % 2)) print(*[1] * (a.count(1)-(a.count(1)%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 Main { public static void main(String[] args) throws IOException { FastScanner f = new FastScanner(); int ttt=1; ttt=f.nextInt(); PrintWriter out=new PrintWriter(System.out); for(int tt=0;tt<ttt;tt++) { int n=f.nextInt(); int[] count=new int[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; int an[1100]; int main() { int T, n; scanf("%d", &T); while (T--) { scanf("%d", &n); int sum = 0, x; for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &an[i]), sum += an[i]; if (sum >= (n / 2 + ((n / 2) % 2))) x = 1, sum = (n / 2 + ((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...
N = int(input()) for i in range(N): n = int(input()) a = list(map(int, input().split())) b = [] for j in range(len(a) // 2): x = a[2*j] y = a[2*j + 1] if x == y: b.append(x) b.append(y) else: b.append(0) print(len(b)) print(*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...
import java.io.*; import java.util.*; public class A { public static void main(String[] agrs) { FastScanner sc = new FastScanner(); int yo = sc.nextInt(); while(yo-->0) { int n = sc.nextInt(); int[] arr = sc.readArray(n); int one = 0, zero = 0; int k = n/2; 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 i in range(t): n = int(input()) arr = list(map(int, input().split())) zero = arr.count(0) one = n - zero if zero >= n / 2: print(zero) print(*[0 for i in range(zero)]) else: print(one - one % 2) print(*[1 for i in range(one - one % 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().strip().split())) one, zero = 0, 0 for i in a: if i == 0: zero += 1 else: one += 1 if one <= n / 2: print(zero) for i in range(zero): print(0,end=' ') 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...
#include <bits/stdc++.h> using namespace std; const int N = 200; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, x, z = 0, o = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x == 1) { o++; } else { 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.util.Scanner; public class Ahahahahahahahaha { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int test=in.nextInt(); for(int t=0;t<test;t++) { int num=in.nextInt(); int zero=0; int one=0; for(int i=0;i<num;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 i in range(t): n= int(input()) a= list(map(int,input().split())) while(False): break ek=0 less=0 for xx in a: if xx==1: ek+=1 else: less+=1 while(False): break if ek<=(n//2): print(le...
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...
ct = input() for line in range(int(ct)): n = input() arr = [int(i) for i in input().split()] if arr.count(0) >= arr.count(1): test = ['0'] * arr.count(0) final = ' '.join(test) print(arr.count(0)) else: if arr.count(1) % 2 == 1: tt = arr.count(1) - 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...
mod = 1000000007 eps = 10**-9 def main(): import sys from collections import Counter input = sys.stdin.buffer.readline for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) if N == 2: if A[0] == A[1] == 1: print(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...
#Codeforces Round #669 #Problem A import sys # #BEGIN TEMPLATE # def input(): return sys.stdin.readline()[:-1] def getInt(): return int(input()) def getIntIter(): return map(int, input().split()) def getIntList(): return list(getIntIter()) def flush(): sys.stdout.flush() # #END TEMPLATE # for _ in range(getInt()): ...
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 final class Codechef { static Scanner sc=new Scanner(System.in); static FastReader re=new FastReader(); static PrintWriter writer=new PrintWriter(System.out); public static void main(String[] args){ int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); 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...
# -*- coding: utf-8 -*- """ Created on Mon Aug 3 21:10:40 2020 @author: dennis """ import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(...
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...
test_case = int(input()) for i in range(test_case): n = int(input()) s = input().split(" ") count_1 = 0 count_0 = 0 for j in range(n): if s[j] == '1': count_1 += 1 else: count_0 += 1 if count_0 >= n/2: print(count_0) s = '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...
for _ in range(int(input())): n=int(input()) lst=[int(i) for i in input().split()] n1=lst.count(1) n0=lst.count(0) if n0>=(n//2): print(n//2) for i in range(n//2): print(0,end=' ') print() else: if n1%2==0: print(n1) for i in ra...
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 { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(in.readLine()); for(int i = 0; i < t; 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...
def answer(n,A): x=sum(A) if x>n//2: if x%2==0: return x,[1]*(x) else: return x-1,[1]*(x-1) else: return (n-x),[0]*(n-x) t=int(input()) for i in range(t): n=int(input()) arr=list(map(int,input().split())) a,b=answer(n,arr) 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())) cnt = [0,0] for i in arr: if i==1: cnt[1]+=1 else: cnt[0]+=1 rem = n//2 if rem%2!=0: if cnt[0]>=rem: print(rem) for i in range(rem): ...
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 _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n; cin >> n; int cnt[2] = {0, 0}; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; cnt[tmp]++; } if (cnt[0] >= cnt[1]) { cout << cnt[0] << 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...
t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) ze=a.count(0) on=a.count(1) if(ze>=on): print(ze) print("0 "*ze) elif(on%2==0): print(on) print("1 "*on) elif(on%2!=0): print(on-1) print("1 "*(on-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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class bigvova { public static void main(String[] args) { FastReader sc = new FastReader(); 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...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
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 mod = 1e9 + 7; using namespace std; vector<long long int> fact(1000005); long long int modInverse(long long int a, long long int m) { long long int mom = m, y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long long int q = a / m; long long int top = m; m = a % m;...
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 Counter import string import math def binomialCoeff(n , k): if n<k: return 1 C = [0 for i in range(k+1)] C[0] = 1 for i in range(1,n+1): j = min(i ,k) while (j>0): C[j] = C[j] + C[j-1] j -= 1 return C[k] def array_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()) while(t>0): t-=1 n=int(input()) arr=[int(x) for x in input().split()] se=so=0 for i in range(n): if i%2==0: se+=arr[i] else: so+=arr[i] if se==so: print(n) for a in arr: print(a,end=" ") print() else: n1=n0=0 n1=se+so n0=n-n1 if n1<=n0: print(n0) 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...
#!/usr/bin/env python # https://github.com/cheran-senthil/PyRival/blob/master/templates/template_py3.py import os import sys,math from io import BytesIO, IOBase def main(): t=int(input()) for case in range(t): n=int(input()) l=list(map(int,input().split())) ct0 = l.count(0); ct1 = l....
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; import java.util.Arrays; public class Ahahahahahahahaha { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for (int i = 0; i < t; i++) { int cnt0 = 0, cnt1 = 0; int n = s.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...
for i in range(int(input())): print("\n") n=int(input()) a=list(map(int,input().split())) c=[] for i in range(1,n,2): if a[i]-a[i-1]!=0: c.append(0) else: c.append(a[i-1]);c.append(a[i]) print(len(c)) for i in range(len(c)): print(c[i],end=' ')...
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 sdfhyujkl in range(t): n = int(input()) l = list(map(int, input().split())) for i in range(0, n, 2): if l[i] != l[i+1]: l[i] = - l[i] l[i+1] = - l[i+1] answer = [] for i in range(n): if l[i]!=-1: answer.append(l[i]) print(l...
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 java.math.*; public class Main { InputStream is; PrintWriter out; String INPUT = ""; //class Declaration static class pair implements Comparable < pair > { long x; long y; pair(long i, long j) { x = i; y = j; } public int compareTo(pair p) { 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.util.*; import java.io.*; public class Solution{ static PrintWriter out=new PrintWriter(System.out); public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().trim().split(" "); int numTest...
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()) ali = list(map(int, input().split())) q = ali.count(0) w = ali.count(1) if(q< n//2): if(w%2 != 0): w -= 1 print(w) a = [1]*w print(*a) else: print(w) a = [1]*w...
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()) s=input().split() l=[0,0] for i in range(n): if int(s[i]): l[0]=l[0]+int(s[i]) else: l[1]=l[1]+int(s[i]) if l[0]>n//2: if l[0]%2!=0: l[0]=l[0]-1 print(l[0]) print(*(l[0]*'1')) els...
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 import math,sys,heapq from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import random import bisect as bi def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime-----...
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 functools import reduce from collections import Counter import time import datetime from math import sqrt,gcd # def time_t(): # print("Current date and time: " , datetime.datetime.now()) # print("Current year: ", datetime.date.today().strftime("%Y")) # print("Month of year: ", datetime.date...
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 q=int(input()) for k in range(q): n=int(input()) a=list(map(int,stdin.readline().split())) sum0=0 sum1=0 for i in a: if i==0: sum0+=1 else: sum1+=1 if sum0>=n//2: print(n//2) for i in range(n//2): print(0,end=" ") print() else: if (n//2)%2!=0: 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.*; import java.io.*; public class main { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int test_case = in.nextInt(); for(int t=0;t<test_case;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...
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { FastScanner sc = new FastScanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); for(int ti = 0; ti < t; ti++){ int n = 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()) l = list(map(int,input().split())) one = l.count(1) zero = n-one if zero>=n//2: print(zero) print(*[0]*zero) else: one -= one%2 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...
import os import sys from io import BytesIO, IOBase # region fastio 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.writable else None ...