Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
ans = []
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
z = arr.count(0)
k = len(arr) // 2
if z >= k:
ns = (z, " ".join(["0"] * z))
else:
if k % 2 == 0:
ns = (k, " ".join(["1"] * k))
else:
ns = (k + ... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | from sys import stdin, stdout
def find(arr,N):
a=arr.count(1)
b=arr.count(0)
K=N-N//2
if b>=K: return [0]*K
if a>K: return [1]*(K+1 if K%2 else K)
if a==K and K%2==0: return [1]*K
x=arr.count(0)
A=[1]*x+[0]+[1]*(K-x)
if x%2==0: del A[-1]
else: del A[0]
return A
def main():
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.util.*;
import java.io.*;
public class A_1407 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int[] array = sc.nextIntArray(n);
int ... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
from collections import defaultdict
input = sys.stdin.readline
from collections import deque
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr()... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | n = int(input())
for _ in range(n):
s = int(input())
mas = list(map(int, input().split()))
summas = sum(mas)
if summas <= s / 2:
print(s - summas)
print(*[0 for _ in range(s - summas)])
else:
count = summas - summas % 2
print(count)
print(*[1 for _ in range(co... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n = int(input())
data = list(map(int, input().split()))
zero = 0
one = 0
for x in data:
if x == 0:
zero += 1
else:
one += 1
if zero >= one:
print(zero)
for i in range(zero):
print(0, end=' ')
el... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
v, w, x, y, z, ans, num, sum, dif, mn, mx;
string str, s1, s2;
scanf("%lld", &t);
while (t--) {
scanf("%lld", &n);
long long int arr[n];
for (i = 0; i < n; i+... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | a=int(input())
for i in range(a):
b=int(input())
c=[int(x) for x in input().split()]
count=c[0]
count1=0
for j in range(b):
if(c[j]==count):
count1=count1+1
if(c[j]!=count):
if(count==1):
if(count1%2!=0):
c[j-1]=10**4
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math
# sys.stdin = open('input')
def inp(force_list=False):
re = map(int, raw_input().split())
if len(re) == 1 and not force_list:
return re[0]
return re
def inst():... | PYTHON |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys, os.path
import math
from collections import Counter
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
def solve(l,n):
x = Counter(l)
if x[0] >= x[1]:
print(x[0])
print(" ".join("0"*x[0]))
else:
if x[1]%2 == 0:
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
n = int(input())
a = list(map(int,input().split()))
z = 0
for e in a:
if e == 0:
z += 1
m = n//2
if z >= m:
print(m)
print(*list([0]*m))
else:
if m%2 == ... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
S = sum(a)
if 2 * S >= n:
if n % 4 == 0:
print(n//2)
for i in range(n//2):
print(1, end = ' '*(i+1!=n//2))
else:
if 2 * S == n:
pri... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
n = int(input())
A = list(map(int, input().split()))
B = [0,0]
for j in range(n):
B[A[j]] += 1
# print(B)
if B[1] <= n//2:
print(n//2)
print(*([0]*(n//2)))
else:
m = n//2 if (n//2)%2 ==... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | # KUSHAGRA WADHWA
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
s0 = 0
s1 = 0
for i in range(n):
if a[i] == 0:
s0 += 1
else:
s1 += 1
if s0 >= s1:
print(s0)
for j in range(s0):
print("0 ", en... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #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) {... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
for (cin >> t; t--;) {
int n, zero = 0, one = 0, i;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 0) {
zero++;
}
if (a[i] == 1) {
one++;
}
}
if (zero >= (n... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
while t>0:
n=int(input())
a=[int(x) for x in input().split()]
one=0
zero=0
for i in range(n):
if a[i]==0:
zero+=1
else:
one+=1
if zero>=n//2:
print(n//2)
for j in range(n//2):
print("0",end=' ')
elif (n//2)%2!... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for i in range(int(input())):
a=int(input())
l=list(map(int,input().split()))
m=l.count(1)
if m>int(a/2):
i=0
while i<len(l):
if not l[i]:
l.pop(i)
i-=1
i+=1
if m%2==1:
l.remove(1)
else:
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
for i in range(t):
n=int(input())
a=list(map(int,input().split()))
count0=0
count1=0
for i in range(n):
if a[i]==1:
count1+=1
else:
count0+=1
if count1<=n//2:
res=[0]*(n-count1)
print(len(res))
print(*res)
else:
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int CN = 2e3 + 3;
int read() {
int s = 0, ne = 1;
char c = getchar();
while (c < '0' || c > '9') ne = c == '-' ? -1 : 1, c = getchar();
while (c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - '0', c = getchar();
return s * ne;
}
int t, n, a[CN];
int main(... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | def solve():
n = int(raw_input())
a = map(int, raw_input().split())
c = sum(a)
m = n / 2
if n - c >= m:
b = [0] * m
else:
b = [1] * ((m + 1) / 2) * 2
print len(b)
for x in b:
print x,
print
T = int(raw_input())
for t in xrange(T):
solve()
| PYTHON |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 |
def zeroSum(a):
if a.count(1) <= len(a)/2:
x = [0 for i in range(a.count(1),len(a))]
else:
x = [1 for i in range(a.count(1))]
if 1 in x and len(x) % 2 == 1:
x.pop()
return x
if __name__ == '__main__':
trials = int(input())
for i in range(trials):
n = int(input()... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
long long dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long t = 1;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
long long c1 = 0, c0 = 0;
fo... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
//solution start :-)
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int a... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
while t:
t-=1
n=int(input())
a=[int(i) for i in input().split()]
one=0
zero=0
for i in range(n):
if a[i]==1:
one+=1
else:
zero+=1
if one<=zero:
print(zero)
ans=[0 for i in range(zero)]
print(*ans,sep=" ")
els... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
input = sys.stdin.readline
t = int(input()) # test cases
for i in range(t):
n = int(input()) # length of the array
s = list(map(int, input().split()))
a = []
tmp = 0
sum = 0
for j in range(0, len(s) - 1, 2):
tmp += (s[j] - s[j + 1])
if tmp == 0:
a = s
else:... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n = int(input())
a = input().split()
ans = ''
oneCt = 0
length = n
for i in range(n):
if a[i] == '1':
oneCt += 1
zeroCt = n-oneCt
if oneCt > zeroCt:
if oneCt % 2 == 0:
print(length-zeroCt)
print('1 '*oneC... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | a=int(input())
for i in range(a):
n=int(input())
b=[int(s) for s in input().split()]
s=0
ss=0
if sum(b)%2==0:
x=b.count(1)
y=b.count(0)
if x<y:
for j in range(x):
b.remove(1)
else:
for j in range(y):
b.remove(0)
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos((long double)-1);
const long double e = exp(1);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int one = 0, zero = 0;
for (... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for t in range(int(input())):
n = int(input())
*a, = map(int, input().split())
ans = []
if a.count(0) >= a.count(1):
ans = [0]*(n//2)
else:
m = n//2+(n//2) % 2
ans = [1]*m
print(len(ans))
print(*ans)
| PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
cnt1 = sum(a)
cnt0 = n-cnt1
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):
p... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int T, n, i, a[1001], j;
cin >> T;
for (i = 1; i <= T; i++) {
cin >> n;
int sum = 0, p = 0, q = 0, flag = 0, kt = 0, k;
for (j = 1; j <= n; j++) {
cin >> a[j];
if (j % 2 != 0) {
sum = sum + a[j];
} else {
sum ... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
cone=sum(a)
czero=n-cone
if(cone<=n//2):
print(czero)
print(*[0]*czero)
else:
if(cone%2==0):
print(cone)
print(*[1]*cone)
else:
print(cone-1)
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split(" ")))
no_zeros = 0
for i in range(n):
if a[i] == 0:
no_zeros += 1
if no_zeros >= n/2:
print(no_zeros)
for i in range(no_zeros):
print(0,end=" ")
else:
x = n - no_zeros
z = x if x % 2==0 else x-1
print(z... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n), ans;
int cnt0 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (!a[i]) cnt0++;
}
int cnt1 = n - cnt0;
if (cnt0 >= n / 2) {
cout << cnt0 <... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | from __future__ import print_function, division
from sys import stdin, stdout
from fractions import gcd
# from math import *
from collections import *
from operator import mul
from functools import reduce
from copy import copy
rstr = lambda: stdin.readline().strip()
rstrs = lambda: [str(x) for x in stdin.readline().sp... | PYTHON |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
N = int(input())
A = [int(_) for _ in input().split()]
nb0 = len([el for el in A if el == 0])
if nb0 >= N//2:
print(N//2)
print(' '.join(map(str, [0]*(N//2))))
continue
if (N//2) % 2 == 0:
p... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys, collections, math
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
n = int(input())
arr = get_array()
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | ii = lambda : int(input())
il = lambda : list(map(int, input().split()))
for _ in range(ii()):
c=0
c=1
n=ii()
a=il()
c=c+1
if(a.count(0)>=a.count(1)):
l=[0]*(a.count(0))
print(len(l))
print(*l)
else:
c=0
if(a.count(1)%2!=0):
l=[1]*(a.coun... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long gcd(long long x, long long y) {
if (!y) return x;
return gcd(y, x % y);
}
long long power(long long x, long long y) {
long long res = 1ll;
x %= MOD;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) ... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | # for _ in range(int(input())):
# n = int(input())
# a = map(int, input().split())
# count0 = 0
# count1 = 0
# result = []
# for i in a:
# if i == 0:
# count0 += 1
# else:
# count1 += 1
#
# if count0 >= count1:
# result = [0] * count0
#
# ... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 |
import sys
import math
from math import *
from collections import Counter,defaultdict,deque
sys.setrecursionlimit(10**9)
lip = lambda : list(map(int, input().split()))
ip = lambda : int(input())
sip = lambda : input().split()
def main():
n = ip()
arr = lip()
ans = []
i = 0
while(i<n):
o = 2
z = 2
w... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.util.Scanner;
public class ahaha {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int test = in.nextInt();
for (int i = 0; i < test; i++) {
int n = in.nextInt();
int arr[] = new int[n + 1];
int sum = 0;
... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
count1=a.count(1)
count0=a.count(0)
if count0>=count1:
print(count0)
for i in range(count0):
print(0,end=" ")
print()
else:
p=n//2+((n//2)%2)
print(p)
for i i... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
import math
from collections import defaultdict,deque
input = sys.stdin.readline
def inar():
return [int(el) for el in input().split()]
def main():
t=int(input())
for _ in range(t):
n=int(input())
arr=inar()
one=0
zero=0
for i in range(n):
if a... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
while t:
n=int(input())
a=list(map(int,input().split()))
i=1
b=[]
while i<n:
if a[i]-a[i-1]!=0:
if a[i-1]==1:
b.append(a[i])
else:
b.append(a[i-1])
else:
b.append(a[i-1])
b.append(a[i])
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.util.*;
public class Main{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int z=0;z<t;z++)
{
int n=sc.nextInt();
int a[]=new int[n];
int zero=0;
int one=0;
for(int i=0;i<n;i++)
{
a[i]=sc.nex... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
import math,bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,OrderedDict
def I(): return int(sys.stdin.readline())
def neo(): return map(int, sys.stdin.readline()... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int T, i, j, x, n, oddsum, evensum, count1, k;
cin >> T;
for (x = 0; x < T; x++) {
oddsum = evensum = count1 = 0;
cin >> n;
n++;
long long int a[n];
for (i = 1; i < n; i++) cin >> a[i];
for (i = 1, j = 2; i < n; j += 2, i... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | from sys import stdin,stdout
for _ in range(int(stdin.readline())):
n=int(stdin.readline())
# a=list(map(int,stdin.readline().split()))
# s=''.join(input().split())
# con1=s.split('0');ans=0
# s1=''
a = list(map(int, stdin.readline().split()))
c1=ans=0;s1=''
a+=[100]
for i in range(n... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.util.*;
import java.io.*;
public class heloo{
public static void main(String[] args ) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));;
int t= Integer.parseInt(br.readLine().trim());
StringBuilder ans=new StringBuilder();
while(t... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 |
import java.util.ArrayList;
import java.util.Scanner;
public class minProd1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int m = 0; m < t; m++) {
ArrayList<Integer> zero = new ArrayList<>();
ArrayList<Inte... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | a=int(input())
for i in range(0,a):
b=int(input())
arr=list(map(int,input().split()))
one=[]
zero=[]
for i in range(0,len(arr)):
if(arr[i]==0):
zero.append(i+1)
else:
one.append(i+1)
if(len(one)%2==0):
if(len(one)<len(zero)):
print(len(... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n = int(input())
#n, k = map(int, input().split())
a = list(map(int, input().split()))
o=a.count(1)
z=a.count(0)
if(o>z):
if(o%2==0):
print(o)
for i in range(o):
print(1,end=' ')
else:
print(o-1)
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
zero = a.count(0)
if (zero >= (n//2)):
print(zero)
print(*[0 for i in range(zero)])
else:
one = a.count(1)
if (one % 2):
print(one-1)
print(*[1 for i in ra... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for t in range(int(input())):
n = int(input())
arr = [int(x) for x in input().split()]
temp = sum(arr)
if temp>n//2:
if temp%2==0:
a = [1]*temp
print(temp)
print(*a)
else:
a = [1]*(temp-1)
print(temp-1)
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil,pi,sin,cos,acos,atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | n = int(input())
for i in range(n):
l = int(input())
a = list(map(int,input().split()))
kol_0 = 0
kol_1 = 0
for i in range(len(a)):
if a[i] == 0:
kol_0 += 1
else:
kol_1 += 1
otv = []
if kol_0 >= kol_1:
otv = [0]*kol_0
else:
if kol_1... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
for i in range(t):
n = int(input())
l = [int(i) for i in input().split()]
ones = l.count(1)
zeros = l.count(0)
if ones>zeros:
if ones%2 == 1:
ones-=1
print(ones)
print(*[1]*ones)
else:
print(zeros)
print(*[0]*zeros)
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | from math import *
t = int(input())
for q in range(t):
n = int(input())
li= list(map(int,input().split()))
odd = 0
even = 0
for i in range(0,n,2):
odd = odd+li[i]
for j in range(1,n,2):
even = even+li[j]
if odd==even:
print(n)
print(*li)
else:
new_... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
c0=0
c1=0
for i in range(n):
if(arr[i]==1):
c1+=1
else:
c0+=1
if c0>=c1:
print(c0)
print(*([0]*c0))
else:
if c1%2!=0:
c1-=1
prin... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
t = int(input())
for _ in range(t):... | PYTHON |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n=int(input())
A=[int(_) for _ in input().split()]
x,y=0,0
for _ in range(n):
if A[_]==0:
x+=1
else:
y+=1
if x>=y:
print(x)
print(*[0 for _ in range(x)])
else:
if y%2==1:
print(y-1)
print(*[1 for _ in range(y-1)])
else:
print(y)
print(*[1 for _ in range(... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
void solve() {
int n;
cin >> n;
int cnt1 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1) cnt1++;
}
int cnt0 = n - cnt1;
if (cnt0 >= n / 2) {
cout << cnt0 << endl;
for (int i = 0; i < cnt0; i... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import math
from collections import deque
from collections import defaultdict
t = int(input())
while t>0:
t-=1
n = int(input())
arr = list(map(int,input().strip().split(" ")))
sm = 0
k = 0
st = 0
ed = 0
fd = False
ans = []
for i in range(n):
if arr[i] == 1... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | x = int(input())
ans = []
for k in range(x):
n = int(input())
a = list(map(int, input().split()))
kln = 0
for i in range(n):
if a[i] == 0:
kln += 1
if kln >= n // 2:
ans.append(([0] * kln))
else:
kle = 0
for i in range(n):
if a[i] == 1:
kle += 1
if kle % 2 == 1:
ans.append(([1] * (kle - 1))... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | from collections import Counter
for t in range(int(input())):
n = int(input())
a = input().split()
c = Counter(a)
if c['0'] >= (n // 2):
print(n // 2)
print('0 ' * (n // 2))
else:
if (n // 2 % 2 == 1):
print(n // 2 + 1)
print('1 ' * (n // 2 + 1))
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
/*
6
1 1 1 1 0 0
*/
public class A {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
int T=fs.nextInt();
f... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | a = int(input())
for i in range(a):
b = int(input())
l = list(map(int,input().split()))
c=0
co=0
for j in range(b):
if(l[j]==1):
c+=1
co = b-c
if(co>=b//2):
print(co)
print(*([0]*(co)))
else:
c = c-c%2
print(c)
print(*([1]*c))
| PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
while t>0:
t-=1
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(0,n,2):
if (a[i]-a[i+1])==0:
b.append(a[i])
b.append(a[i+1])
elif a[i]==0:
b.append(a[i])
elif a[i+1]==0:
b.append(a[i+1])
pr... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | def ans():
N=int(input())
for i in range(N):
A=int(input())
arr=input().split()
a=0
b=0
for j in range(A):
if arr[j]=='1':
a+=1
elif arr[j]=='0':
b+=1
if a>b:
if (len(arr)//2)%2==0:
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int N = 1050;
int a[N];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 1) cnt++;
}
if (n == 2 && (a[1] == 0 || a[2] == 0)) {
cout << 1 <<... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n = int(input())
lst = list(map(int, input().split()))
czero = lst.count(0)
cone = lst.count(1)
if cone<=n//2:
ans = [0 for i in range(n-cone)]
else:
ans = [1 for i in range(n-czero)]
if czero%2!=0:
ans.remove(1)
print(len(ans... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 |
from __future__ import division
import sys
input = sys.stdin.readline
import math
from math import sqrt, floor, ceil
from collections import Counter
from copy import deepcopy as dc
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().spli... | PYTHON |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 |
t = int(input())
for i in range(t):
n = int(input())
A = sum(map(int, input().split()))
if A <= n // 2:
print(n // 2)
print(" ".join(['0' for i in range(n // 2)]))
else:
if n % 4 == 0:
print(n // 2)
print(" ".join(['1' for i in range(n // 2)]))
else:
print(n // 2 + 1)
print(" ".join(['1' for i ... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
b = c = 0
for i in a:
if i==1:
b+=1
else:
c+=1
if b>c:
flag = 1
else:
flag = 0
d = [0 for i in range(n)]
f = False
curr = False
lol = 0
for i in range(0,n,2):
if a[i]==a[i+1]:
d[i] = a[i]
d[i+1] = a[i+1]
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
def answer(n, a):
if a.count(1) <= n//2:
#remove all the ones. Keep all the zeros.
print(n-a.count(1)) #only zeros remain
print('0 ' * a.count(0))
return
#less than half zeros. Delete them all. Keep all of the ones if even. Delete a one if not.
if a.count(1) ... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 |
for _ in range(int(input())):
n=int(input())
arr=[int(j) for j in input().split()]
c1=arr.count(1)
c2=arr.count(0)
if c2>c1:
x=[0]*(c2)
print(c2)
print(*x)
else:
if c1%2==0:
x=[1]*(c1)
print(c1)
print(*x)
else:
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.util.*;
import java.io.*;
public class cf {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int c1 = 0;
for (int i = 0; i < n; i++) {
c1 += sc.nextInt();... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
for i in range(t):
n=int(input())
a=list(map(int,input().split()))
d=a.count(1)
c=n-d
if c>=d:
for j in range(n-1,-1,-1):
if a[j]==1:
del a[j]
else:
for j in range(n-1,-1,-1):
if a[j]==0:
del a[j]
if d... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(in.readLine());
i... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
one = a.count(1)
zero = a.count(0)
if one%2==0:
if one>=n//2:
res = [a[i] for i in range(n) if a[i]==1]
print(len(res))
print(*res)
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
import itertools
import math
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
m,=I()
while(m):
m-=1
n,=I()
arr=I()
c=0
z=o=0
for i in range(n):
if arr[i]==0:
z+=1
else:
o+=1
if o<=n//2:
print(z)
print(... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #100010
for t in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
count_ones=arr.count(1)
if count_ones<=n//2:
ans=[0]*(n-count_ones)
print(len(ans))
print(*ans)
else:
if count_ones%2==1:
count_ones-=1
ans=[1]*count_ones
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
while t:
t += -1
n = int(input())
l = list(map(int, input().split()))
if n == 2:
if l == [1, 1]:
print(2)
print(1, 1)
else:
print(1)
print(0)
else:
i = 0
ans = []
while 1:
if (len(ans... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
zero = a.count(0)
one = n-zero
if (zero>=n//2):
print(zero)
print("0 "*zero)
else:
one -= one%2
print(one)
print("1 "*one... | PYTHON |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
using namespace std;
const long long md = 1e9 + 7;
const long long N = 362880;
const long long inf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
;
long long q;
cin >> q;
while... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | l=[]
for _ in range(int(input())):
n=int(input())
s=list(map(int,input().split()))
count1=0
count0=0
for i in range(n):
if s[i]==0:
count0=count0+1
else:
count1=count1+1
if count0>=count1:
l.append(n//2)
a=["0" for i in range(n//2)]
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t=int(input())
while t:
k=f=0
t=t-1
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
if a[i]==1:
k+=1
else:
f=f+1
if k<=f:
print(int(n/2))
for i in range(int(n/2)):
print(0)
else:
if (n/2)%2==0:
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n = int(input())
x = list(map(int, input().split()))
z = x.count(0)
o = n - z
if z >= n // 2:
print(z)
print("0 " * z)
else:
print(o - o % 2)
print("1 " * (o - o % 2)) | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | '''Author- Akshit Monga'''
t=int(input())
for _ in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
a=sum(arr)
ans=[]
if a<=(n/2):
print(n-a)
assert n-a>=(n/2)
for i in range(n-a):
print(0,end=' ')
else:
if a%2!=0:
a-=1
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
first = []
second = []
zeroes = a.count(0)
ones = a.count(1)
if zeroes%2:
if (ones-1) >= n//2:
print(ones-1)
print(*[1 for i in range(ones-1)])
els... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
ones = 0
for i in range(n):
if a[i] == 1:
ones += 1
if ones > n // 2:
if ones % 2 == 0:
lst = [1 for x in range(ones)]
print(len(lst))
print(*lst)
... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | tst=int(input())
t=1
while t<=tst:
n=int(input())
ls=list(map(int,input().split()))
odd=even=i=0
while i<n:
x=ls[i]
if x==1:
odd+=1
else:
even+=1
i+=1
if odd==even:
print(even)
i=1
while i<=even:
pri... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
z = arr.count(0)
o = arr.count(1... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | import java .io.*;
import java .util.*;
public class Aha{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0)
{
int n=in.nextInt();
int[] arr=new int[n];
ArrayList<Integer> arrli = new ArrayList<Integer>(n);
for(int i=0;i<n;i++)
arr[i]=in... | JAVA |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, '... | CPP |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | from sys import stdin,stdout
from math import gcd,log2,log10,floor;
import math;
from collections import defaultdict
# import numpy as np
input=stdin.readline
# print=stdout.write
def count(a,i):
return a.count(i)
for i in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
zeros=count(... | PYTHON3 |
1407_A. Ahahahahahahahaha | Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s... | 2 | 7 | T=int(input())
for z in range(T):
n=int(input())
a=[int(x) for x in input().split()]
prev=0
l=list()
for e in a:
if e==0:
l.append(0)
prev=0
else:
if prev==0:
prev=1
else:
l.append(1)
... | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.