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 |
|---|---|---|---|---|---|
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
while t > 0:
n = int(input())
if (n // 2) % 2 == 0:
half = n // 2
a = []
e, o = 2, 1
for i in range(half):
a.append(e)
e += 2
for i in range(half, n):
a.append(o)
o += 2
evenHalf = a[:half]
o... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for t in range(int(input())):
n = int(input())
if n % 4 != 0:
print("NO")
else:
print("YES")
ch = []
for q in range(2, n+1, 2):
ch.append(q)
nech = []
for q in range(1, n-2, 2):
nech.append(q)
nech.append(n//2+q+2)
strok... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for _ in range(t):
n = int(input())
if(n%4!=0):
print("NO")
else:
print("YES")
s = 0
s2=0
for i in range(int(n/2)):
print((i+1)*2, end = " ")
s+=(i+1)*2
for i in range(int(n/2)-1):
print((i+1)*2-1, end=' ')
s2+=(i+1)*2-1
print(s-s2) | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for i in range(int(input())):
n=int(input())
if(n%4==0):
l=[0]*n
a=2
print("YES")
for i in range(n//2):
l[i]=a
l[n//2+i]=a-1
a+=2
sum1=sum(l[0:n//2])
l[n-1]=sum1-sum(l[n//2:n-1])
for i in range(len(l)):
l[i]=... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
while(t != 0):
n = int(input())
if (n//2) % 2 == 1:
print("NO")
else :
print("YES")
s = (n // 4) * (4 + (n//2 - 1) * 2)
for i in range(2,n+1,2):
print(i, end = ' ')
for i in range(1,n-1,2):
print(i, end = ' ')
print(s -... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for i in range(t):
n = int(input())
if n % 4 == 0:
print("YES")
for i in range(n // 4):
print(2 + 6*i,4 + 6*i,end=" ")
for i in range(n // 4):
print(1 + 6*i,5+ 6*i,end=" ")
print()
else:
print("NO")
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n,k = map(int,input().split())
l = list(map(int,input().split()))
ones = [0]*(2*k+4)
zeros = [0]*(2*k+4)
for i in range(n//2):
x = l[i]
y = l[n-i-1]
if x>y:
x,y = y,x
zeros[x+y] += 1
ones[x+1] += 1
ones[y+k+1] -= 1
for i in range(1,2*k+4):
ones[i] += ones[i-1]
ans... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int sumeven(int n);
int findsumodd(int x, int n);
int main() {
int n;
cin >> n;
int a;
for (int i = 0; i < n; i++) {
cin >> a;
if ((a / 2) % 2 != 0) {
cout << "NO" << endl;
continue;
} else {
cout << "YES" << endl;
int x = sumeven... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
while(t):
n=int(input())
if (n//2)%2!=0:
print("NO")
else:
e=[]
o=[]
ee=2
oo=1
for i in range(n//2):
e.append(ee)
ee+=2
for i in range(n//2-1):
o.append(oo)
oo+=2
z=sum(e)-sum(o)
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import sys
input = sys.stdin.readline
ans = []
t = int(input())
from itertools import accumulate
for _ in range(t):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = [0] * (2 * k + 2)
for i in range(n // 2):
sum_ = a[i] + a[-i - 1]
max_ = max(a[i], a[-i... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (String ln; (ln = in.readLine()) != null; ) {
int N = Integer.par... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for t in range(int(input())):
n=int(input())
a=0
b=0
v=[]
for i in range(1,(n//2)+1):
v.append(2*i)
a=a+2*i
for i in range(1,(n//2)+1):
v.append(2*i-1)
b=b+(2*i)-1
if abs(a-b)%2==0:
i... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.util.Scanner;
public class B {
public static void main(String[] args) {
new B();
}
public B() {
Scanner sc = new Scanner(System.in);
int amountT = sc.nextInt();
for (int task = 0; task < amountT; task++) {
int n = sc.nextInt();
if (n%4 == 2) System.out.println("NO");
else {
Syst... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for tt in range(t):
n = int(input())
if n % 4 == 0:
print('YES')
a = list(range(2, n + 1, 2)) + list(range(1, n - 1, 2)) + [sum(range(2, n + 1, 2)) - sum(range(1, n - 1, 2))]
print(' '.join(map(str, a)))
else:
print('NO')
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input().strip())
for _ in range(t):
n = int(input().strip())
if (n / 2) % 2 != 0:
print('NO')
continue
print('YES')
l = []
p = 0
for i in range(n // 2):
p += 2
l.append(p)
s = sum(l)
p = -1
for i in range(n // 2 - 1):
p += 2
l.... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.util.HashMap;
import java.util.Scanner;
public class codefcf {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t=s.nextInt();
while(t-->0) {
int n=s.nextInt(),k=s.nextInt(),max=0;
HashMap<Long,Integer> map=new HashMap();
... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n = int(input())
if (n // 2) % 2 == 1:
print('NO')
else:
print('YES')
l = []
s1 = 0
for i in range(0, n, 2):
l.append(i + 2)
s1 += i + 2
l2 = []
s2 = 0
for i in range(len(l) - 1):
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | lst = [int(input()) for i in range(int(input()))]
for n in lst:
if n % 4 != 0:
print("NO")
continue
print("YES")
a = []
b = []
for i in range(2, n+1, 2):
a.append(str(i))
b.append(str(i-1))
b[-1] = str(int(b[-1]) + n//2)
print(" ".join(a + b))
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | def solve(n):
size_half = n // 2
if size_half % 2 != 0:
return None
even_half = [2*i for i in range(1, size_half+1)]
odd_half = [2*i+1 for i in range(size_half)]
diff = sum(even_half) - sum(odd_half)
odd_half[size_half-1] += diff
result = even_half + odd_half
return result
i... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | n = int(input())
for _ in range(n):
a = int(input())
if a % 4 != 0: print('NO')
else:
print('YES')
c = [2*int(i) for i in range(1, a//2+1)]
cs = sum(c)
k = 1
s = 1
while k < a//2:
cs -= s
k += 1
c.append(s)
s += 2
print(*c, cs)
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for _ in range(t):
n = int(input())
# n guaranteed to be divisible by 2
half = n//2
if half % 2 == 1:
print("NO")
else:
res = []
j = 2
for i in range(half):
res.append(j)
j+=2
j = 1
for i in range(half-1):
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #!/usr/bin/env python3
t = int(input())
for test in range(t):
n = int(input())
array = []
for i in range(1, n // 2 + 1):
array.append(2*i)
for i in range(1, n // 2):
array.append(2*i-1)
num = sum(array[:n // 2]) - sum(array[n // 2:])
if not num in array and num % 2 == 1:
array.append(num)
print("YES")
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
a = []
b = []
c = []
d = 0
for i in range(t):
n = int(input())
if n%4 != 0 :
a.append("NO")
else:
a.append("YES")
for i in range(1,int(n/2+1)):
b.append(2*i)
for i in range(int(n/2-1)):
b.append(2*i+1)
b.append(int(n+n/2-1))
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for i in range(t):
n=int(input())
if int(n%4)!=0:
print("NO")
else:
l=[]
e=2
o=1
for j in range(int(n/2)):
l.append(e*(j+1))
for j in range(int(n/2)-1):
if j==0:
l.append(o)
else:
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in[0]*int(input()):
n=int(input())
a=[*range(2,n+1,2)]
b=[*range(1,n,2)]
b[-1]+=n//2
print(['YES\n'+' '.join(map(str,a+b)),'NO'][n%4>0])
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n = int(input())
if n%4==0:
print("YES")
for i in range(2,n+1,2):
print(i,end=" ")
ans = 0
for i in range(1,n+1,2):
if i < n-1:
ans+=i
print(i,end=" ")
else:
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | case = int(input())
for n in range(case):
n = int(input())
if (n % 4 != 0):
print("NO")
else:
print("YES")
a = []
half = int(n/2)
for i in range(half):
a.append(2*(i+1))
for i in range(half):
a.append(2*(i+1) - 1)
a[-1] = a[-1] + half
for i in range(len(a)):
a[i] = str(a[i])
print(' '.join... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | 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.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelp... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for i in range(int(input())):
l,s=[],[]
n=int(input())
chk=int(n/2)
if chk%2!=0:
print("NO")
else:
print("YES")
e=chk*(chk+1)
od=(chk-1)*(chk-1)
f=e-od
for i in range(1,n+1):
if i%2==0:
l.append(i)
else:
s.append(i)
s.pop()
s.append(f)
print(*(l+... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for _ in range(t):
n=int(input())
if((n%4!=0)):
print("NO")
else:
print("YES")
l=[]
s=2
k=1
for i in range(int((n//2))):
l.append(s)
s+=2
for i in range(int((n//2)-1)):
l.append(k)
k+=2
l.append(sum(l[:((n//2))])-sum(l[n//2:]))
print(" ".join(str(x) for x in l))
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for i in range(t):
n = int(input())
if (n % 4 !=0):
print("NO")
else:
print("YES")
sum_even = 0
sum_odd = 0
for j in range(0,n//2):
sum_even = (2*j + 2) + sum_even
print(str(2*j + 2),end=' ')
for j in range(0, n//2):
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for _ in range(t):
n = int(input())
if (n // 2) % 2 == 0:
evens = [2 * (i + 1) for i in range(n // 2)]
num = sum(evens)
odds = [2 * (i + 1) - 1 for i in range(n // 2 - 1)]
odds.append(num - sum(odds))
print('YES')
print(*(evens + odds))
else:
print('NO')
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for t in range(int(input())):
n=int(input())
if((n//2)%2==1):
print("NO")
else:
l=[]
i=2
j=0
while(i<=n):
l.append(i)
i+=2
j+=2
i=1
while(i<j-1):
l.append(i)
i+=2
l.append(n+(j//2)-1)
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for _ in range(t):
n=int(input())
if(n%4==2):
print("NO")
else:
print("YES")
for i in range(n//2):
print(2*(i+1),end=' ')
for i in range(n//2-1):
print(2*i+1,end=' ')
print(2*i+3+n//2) | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import sys,math
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
n,k = map(int,input().split())
a = list(map(int,input().split()))
x = [0]*(2*k+5)
for i in range(n//2):
p,q = a[i],a[n-1-i]
if p > q:
p,q = q,p
x[0] += 2
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.next());
StringBuilder sb = new StringBuilder();
for(int t = 0; t < T; t++){
int n = Integer.parseIn... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | """import sys
def input():
return sys.stdin.readline()[:-1]"""
for _ in range(int(input().strip())):
n, k = map(int,input().split())
nums = list(map(int,input().split()))
common_values = [0 for _ in range(2*k+2)]
for i in range(n//2):
a, b = nums[i], nums[n-1-i]
common_values[a+b - m... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for t in range(int(input())):
n=int(input())
e,o=[],[]
if (n//2)%2:
print("NO")
else:
for i in range(1,(n//2)+1):
e.append(i*2)
o.append((i*2)-1)
o[-1]+=sum(e)-sum(o)
e.extend(o)
print("YES")
print(*e) | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for i in range(t):
n=int(input())
if (n//2)%2==1 :
print("NO")
else:
print("YES")
k=2
for j in range(n//2):
print(k,end=" ")
k+=2
k=1
for j in range(n//2-1):
print(k,end=" ")
k+=2
print(k+(... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n=int(input())
count=0
if((n>>1)&1):
print('NO')
else:
print("YES")
for i in range(2,n+1,2):
print(i,end=" ")
for i in range(1,n+1,2):
count+=1
print(i,end=" ")
if(count==(n//2)-1):
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in=new ... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for i in range(t):
n=int(input())
if((n/2)%2==0):
print( 'YES')
for j in range(n):
if((n/2)%2!=0):
print('NO',end='')
break
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import sys
import collections
import itertools
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = N // 2
c = collections.Counter()
x = 0
y = 0
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
while(t):
n = int(input())
if( (n//2) % 2==0):
print("YES")
for e in range(1,n//2+1):
print(e*2,end=" ")
for o in range(1,n-1,2):
print(o,end=" ")
val = n + n//2 - 1
print(val)
else:
print("NO")
t-=... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Solution {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
StringBuilder ans = new StringBuilder();
for (... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | # cook your dish here
for _ in range(int(input())):
n,k=map(int,input().split())
a=list(map(int,input().split()))
cntx=[0]*(2*k+1)
prefx=[0]*(2*k+2)
for i in range(n//2):
cntx[a[i]+a[n-i-1]]+=1
prefx[min(a[i],a[n-i-1])+1]+=1
prefx[max(a[i],a[n-i-1])+k+1]+=-1
ans=n
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for i in range(t):
n=int(input())
if n%4!=0:
print("NO")
else:
print("YES")
even_arr=[2]
odd_arr=[1]
LEN=(n//2)-1
for j in range(LEN):
even_arr.append(even_arr[-1]+2)
odd_arr.append(odd_arr[-1]+2)
odd_arr[-1]+=LE... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for i in range(t):
n = int(input())
num = int(n / 2)
if n % 4 == 0:
print("YES")
for j in range(num):
print(2 * (j+1), end = ' ')
for j in range(num-1):
print(2*(j+1) - 1, end = ' ')
print(3*(num) - 1)
else:
print("NO")
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for _ in range(t):
n = int(input())
if (n//2) % 2 == 1:
print("NO")
else :
print("YES")
lst = []
for i in range(1, n//2 + 1):
lst.append(2*i)
for j in range(1, n//2):
lst.append(2*j - 1)
total = (n**2 + 2*n)//4
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | tests = int(input())
values = [0] * tests
for i in range(tests):
values[i] = int(input())
for i in range(tests):
if (values[i]//2)%2 == 1:
print('NO')
continue
list_1 = [0] * (values[i]//2)
list_2 = [0] * (values[i]//2)
zap1 = 4
zap2 = 1
sum1 = 0
sum2 = 0
for k in ... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | def nod(a,b):
while a != b:
a, b = max(a,b), min(a,b)
if a % b == 0:
a -= (a // b - 1) * b
else:
a -= (a // b) * b
return a
for i in range(int(input())):
n = int(input())
if n % 4 == 0:
print('YES')
p... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n % 4 != 0) {
cout << "NO\n";
continue;
}
cout << "YES\n";
long long sum = 0, cur = 0;
for (long long i = 0, x = ... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* Codeforc... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for nt in range(int(input())):
n=int(input())
if n%4!=0:
print ("NO")
else:
print ("YES")
a,b=0,0
for i in range(n//2):
print (2*(i+1),end=" ")
a+=2*(i+1)
for i in range(n//2-1):
print (2*(i)+1,end=" ")
b+=2*i+1
print (a-b) | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
INF = float('inf')
def solution(arr, n, k):
pairs = []
for i in range(n // 2):
the_pair = (arr[i], arr[n - i - 1])
pairs.append((min(the_pair), max(the_pair)))
pref = [0] * (2 * k + 5)
the_map = ... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n = int(input())
if(n%4 == 0):
s=0
print("YES")
x = (n//2)
for i in range(1,(n//2)+1):
print(2*i, end= " ")
for i in range(1,(n//2)):
print(2*i-1, end= " ")
s+=2*i-1
print(x*(x+1) - s)
else:
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | n = int(input())
for _ in range(n):
a = int(input())
s = (a//2)
if s % 2 == 0:
print('YES')
ss = 0
for i in range(1,s+1):
print(i*2, end=" ")
ss += i*2
for i in range(1,s):
print(i*2-1, end=" ")
ss -= i*2-1
print(ss)
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for i in range(int(input())):
x=int(input())
if x%4!=0:
print('NO')
continue
else:
print('YES')
z=[a for a in range(2,x+1) if a%2==0]
answer=[]
for i in range(x//2-1):
answer.append(z[i]-1)
answer.append(sum(z)-sum(answer))
answer... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | n=int(input())
while(n>0):
a=int(input())
if(a%4==0):
s=''
print('YES')
o=0
o1=0
for i in range(int(a/2)):
#s+=str(2+i*2)+' '
print(2+i*2,end=' ')
o+=2+i*2
for i in range(int(a/2)-1):
#s+=st... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
N = int(input())
if not (N//2) % 2:
print("Yes")
for i in range(1, N//2+1, 1):
print(2*i, end=" ")
for i in range(1, N//2, 1):
print(2*i-1, end=" ")
print(N + (N//2) - 1)
else:
print("No") | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, x, i, j, p = 1, q = 0, sum = 0, sum1 = 0;
cin >> n;
long long int a[n];
x = n / 2;
if (x % 2 != 0)
cout << "NO" << endl;
else {
for (i = 0; i < x; i++) {
... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | # python3 q1.py < test.txt
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = [int(j) for j in input().split()]
count = [0 for i in range(2 * k + 2)]
pre = [0 for i in range(2 * k + 2)]
for j in range(int(n / 2)):
count[a[j] + a[n - 1 - j]] += 1
pre... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, i, j, k, l;
int tst, t;
cin >> tst;
while (tst--) {
cin >> n;
m = n / 2ll;
if (m % 2) {
cout << "NO" << endl;
continue;
} else {
k = 0ll;
cout << "YES" << endl;
for (i = 1; i <= m; i++) {... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for i in range(t):
n=int(input())
h=int(n/2)
if int(h%2)==0:
print("YES")
l=[]
m=[]
for i in range(1,h+1):
e=int(2*i)
l.append(e)
if i==h:
f=sum(l)-sum(m)
m.append(f)
else:
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
if ((n / 2) & 1) {
cout << "No" << endl;
continue;
}
long long tmp1 = 0;
... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for i in range(t):
n = int(input())
if (n//2)%2 != 0:
print("NO")
continue
print("YES")
s = 0
sum_ = 0
for j in range(n//2):
s+=2
sum_ += s
print(s, end = " ")
st = 1
for j in range(n//2 -1):
print(st, end = " ")
sum_ -= st
st += 2
print(sum_) | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for i in range(t) :
n = int(input())
if(n % 4 == 0) :
print("YES")
se = 0
so = 0
e = 2
o = 1
for i in range(n//2) :
print(e, end = " ")
se += e
e += 2
for i in range(n//2-1) :
pr... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.util.Scanner;
public class BalancedArray {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
if (n / 2 % 2 != 0) {
System.out.println("NO");
} else {
int a[] = new int[n... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for i in range(int(input())):
n=int(input())
if ((n//2) % 2)!=0:
print("NO")
else:
a=[]
b=[]
for i in range(2, n+1 , 2):
a.append(i)
for i in range(1 , n+1 , 2):
b.append(i)
if sum(a) != sum(b):
c=sum(a)-sum(b)
b[-1]=b[-1]+c
print("YES")
print(*a, *b)
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for _ in range(t):
n=int(input())
kp=int(n/2)
sp=[]
tp=[]
if(kp%2!=0):
print('NO')
else:
print('YES')
for k in range(int(n//2)):
sp.append(2*(k+1))
tp.append((2*(k+1))-1)
tp[kp-1]+=kp
print(*sp, sep =... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import sys, bisect
input = sys.stdin.readline
# import test; input = test.readline(0)
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
l, r, m = [], [], [0]*(2*k + 1)
for i in range(n>>1):
x, y = a[i], a[n - i - 1]
if x > y: x, y = ... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | test = int(input())
for t in range(test):
n,k = list(map(int, input().split()))
L = list(map(int, input().split()))
sums=[]
d={}
ran = [0]*(2*k+2)
for x in range(n//2):
a=L[x]
b=L[n-x-1]
s = L[x]+L[n-x-1]
d[s]=d.get(s,0)+1
ran[min(a,b)+1]+=1
ran[ma... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n = int(input())
x = n//2
if x&1==1:
print("NO")
continue
print("YES")
even = [2]
odd = [1]
for i in range(1,x):
even.append(even[-1]+2)
odd.append(odd[-1]+2)
esum = sum(even)
osum = sum(odd)
odd[-1... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.util.Scanner;
import java.io.*;
import java.lang.*;
public class Solution
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
if(n%4!=0)
{
... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | I = input
t = int(I())
for _ in range(t):
n = int(I())
if (n // 2) % 2 == 0:
print('YES')
for i in range(1, n // 2 + 1):
print(2*i, end=' ')
for i in range(1, n // 2):
print(2*i-1, end=' ')
print(2*(n // 2)-1+n//2)
else:
print('NO') | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for i in range(t):
n = int(input())
if n % 4 != 0:
print('NO')
else:
print('YES')
count = 2
for j in range(n // 2):
print(count, end=' ')
count += 2
count = 1
for j in range((n // 2) - 1):
print(count, end=... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n = int(input())
if (n//2)&1:
print("NO")
continue
a = [0]*n
for i in range(n//2):
a[i] = (i+1)*2
j = n//2
a[j]=1
for i in range(j+1,n):
a[i] = a[i-1]+2
a[n-1] +=n//2
print("YES")
print(*a)
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n % 4) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
vector<int> arr(n);
int a = 2;
bool flag ... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(int(input())):
n = int(input())
lsum = 0
rsum = 0
n = n//2
if n%2!=0:
print("NO")
else:
print("YES")
for i in range(1, n+1):
print(2*i, end=" ")
lsum += 2*i
i = 1
for _ in range(n-1):
print(i, end=" ")
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io impor... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
int n;
cin >> n;
if ((n / 2) % 2 == 1) {
cout << "NO\n";
} else {
cout << "YES\n";
int sum = 0;
for (int j = 2; j <= 2 * (n / 2); j += 2) {
sum += j;
co... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for i in range(t):
n=int(input())
p=n//2
s=0
m=1
if(p%2==0):
print("YES")
for i in range(p):
s=s+2
print(s,end=" ")
print(m,end=" ")
for i in range(1,p-1):
m=m+2
print(m,end=" ")
print(p*3-1)
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
int main(void) {
long long int a, b, c, i, j = 0, p = 0, q = 0;
scanf("%lld", &a);
for (i = 0; i < a; i++) {
scanf("%lld", &b);
c = b / 2;
if (c % 2 != 0) {
printf("NO\n");
} else {
printf("YES\n");
for (j = 2; j <= b; j += 2) {
printf("%lld ", j)... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for _ in range(input()):
n,k=map(int,raw_input().split())
l=map(int,raw_input().split())
f=[0]*(2*k+3)
ans=1e10
d={}
for i in range(n/2):
try:
d[l[i]+l[n-i-1]]+=1
except KeyError:
d[l[i]+l[n-i-1]]=1
a,b=min(l[i],l[n-i-1])+1,max(l[i],l[n-i-1])+k
f[a]+=1
f[b+1]-=1
p=0
fo... | PYTHON |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | # The place between your comfort zone and your dream is where life takes place. Helen Keller
# by : Blue Edge - Create some chaos
# import sys
# sys.stdin = open('input.txt', 'r')
for _ in range(int(input())):
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*(2*k+2)
for i in range(n... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | n = int(input())
for i in range(n):
my_input = int(input())
checker = True if my_input%4 == 0 else False
if not checker:
print("NO")
else:
print("YES")
e_sum = 0
e = 0
for j in range(my_input//2):
e += 2
print(e, end=" ")
e_sum ... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
void code_init() {}
void solve() {
int n;
cin >> n;
if (n % 4 != 0) {
cout << "NO" << endl;
return;
} else {
cout << "YES" << endl;
for (int i = 1, _i = (n / 2 + 1); i < _i; ++i) cout << i * 2 << " ";
for (int i = 0, _i = (n / 2 - 1); i < _i; ++i... | CPP |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for i in range(int(input())):
n = int(input())
if n % 4 == 0:
print("YES")
print(*[2*i for i in range(1, n // 2 + 1)], *[2*i - 1 for i in range(1, n // 2)], 2 * (n // 2) - 1 + n // 2)
else:
print("NO")
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | def add(arr, N, lo, hi, val):
arr[lo] += val
if (hi != N - 1):
arr[hi + 1] -= val
# Utility method to get actual
# array from operation array
def updateArray(arr, N):
# convert array into prefix sum array
for i in range(1, N):
arr[i] += arr[i - 1]
# method to print fin... | PYTHON |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for i in range(t):
n=int(input())
if(n%4!=0 or n==0):
print("NO")
else:
sume=0
num=2
numo=1
liste=[]
for j in range(0,n//2):
liste.append(num)
sume+=num
num+=2
rem=0
for j in range(n//2,n-1):
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | // Don't place your source in a package
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;
// Please name your class Main
public class Main {
static FastScanner fs=new FastScanner();
stat... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t = int(input())
for x in range(t):
n = int(input())
if (n//2)%2 != 0:
print("NO")
else:
z = 1
y = 1
l = []
for num1 in range(int(n/2)):
l.append(2*z)
z+=1
for num2 in range(int(n/2)):
l.append(y)
y = y+2
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | def hello():
n = int(input())
if n % 4 != 0:
print('NO', end = '\n')
return 0
else:
print('YES', end = '\n')
s1 = 0
for i in range(n // 2 - 1):
print(2 * i + 2, end = ' ')
s1 += 2 * i + 2
print(10 ** 9, end =' ')
s1 += 10 ** 9
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | t=int(input())
for _ in range(t):
n=int(input())
if (n//2)%2:
print("NO")
continue
print("YES")
ans1=[2*i for i in range(1,n//2+1)]
ans2=[2*i-1 for i in range(1,n//2)]
last = sum(ans1)-sum(ans2)
ans1+=ans2
ans1.append(last)
print(*ans1)
| PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | T = int(input())
for times in range(T):
n = int(input())
halfNumber = n // 2
if(n % 4 == 0):
print("YES")
dis = n // 4
for i in range(1, halfNumber + 1):
print(i*2, end=" ")
for i in range(1, halfNumber):
print(i*2 - 1,end=" ")
print((halfNumbe... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | def main():
t=int(input())
for _ in range(t):
n=int(input())
if (n//2)&1==1:
print("NO")
continue
else:
print("YES")
k=n//2
for i in range(1,k+1):
print(i*2,end=" ")
s=k*(k+1)
m=k*k
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
int n, k;
int a[] = new int[200010];
int min[] = new int[400010];
int max[] = new int[400010];
int ... | JAVA |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | for t in range(int(input())):
n=int(input())
if n%4:
print('NO')
else:
print('YES')
for i in range(1,n//2+1):
print(2*i,end =" ")
for i in range(1,n//2):
print(2*i-1,end =" ")
... | PYTHON3 |
1343_B. Balanced Array | You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while (T--) {
long long int n, x;
cin >> n;
if ((n / 2) % 2 == 1)
cout << "NO\n";
else {
cout << "YES\n";
long long int sum = 0;
... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.