output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
const long long N = 205, inf = 1e18;
string second, t;
long long dp[N][N][N];
char par[N][N][N];
long long first(long long i, long long j, long long x) {
if (x < 0 or x > 204) return inf;
if (i == 0 and j == 0) return x;
if (dp[i][j][x] != -1) return dp[i][j][x];
long long a, b;
for (auto ch : {'(', ')'}) {
long long ni = i, nj = j, nx = x, k;
if (second[i] == ch) ni--;
if (t[j] == ch) nj--;
if (ch == '(') {
nx--;
a = first(ni, nj, nx) + 1;
} else {
nx++;
b = first(ni, nj, nx) + 1;
}
}
if (a < b)
dp[i][j][x] = a, par[i][j][x] = '(';
else
dp[i][j][x] = b, par[i][j][x] = ')';
return dp[i][j][x];
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> second >> t;
long long n = second.size(), m = t.size();
second = '#' + second, t = '#' + t;
memset(dp, -1, sizeof dp);
first(n, m, 0);
long long i = n, j = m, x = 0;
string ans = "";
while (i or j) {
char ch = par[i][j][x];
ans += ch;
if (second[i] == ch) i--;
if (t[j] == ch) j--;
if (ch == '(')
x--;
else
x++;
}
while (x) ans += '(', x--;
reverse(ans.begin(), ans.end());
cout << ans;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous).
Recall what is the regular bracket sequence:
* () is the regular bracket sequence;
* if S is the regular bracket sequence, then (S) is a regular bracket sequence;
* if S and T regular bracket sequences, then ST (concatenation of S and T) is a regular bracket sequence.
Recall that the subsequence of the string s is such string t that can be obtained from s by removing some (possibly, zero) amount of characters. For example, "coder", "force", "cf" and "cores" are subsequences of "codeforces", but "fed" and "z" are not.
Input
The first line of the input contains one bracket sequence s consisting of no more than 200 characters '(' and ')'.
The second line of the input contains one bracket sequence t consisting of no more than 200 characters '(' and ')'.
Output
Print one line β the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any.
Examples
Input
(())(()
()))()
Output
(())()()
Input
)
((
Output
(())
Input
)
)))
Output
((()))
Input
())
(()(()(()(
Output
(()()()(()()))
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 205, inf = 1e18;
string second, t;
long long dp[N][N][N];
char par[N][N][N];
long long first(long long i, long long j, long long x) {
if (x < 0 or x > 204) return inf;
if (i == 0 and j == 0) return x;
if (dp[i][j][x] != -1) return dp[i][j][x];
long long a, b;
for (auto ch : {'(', ')'}) {
long long ni = i, nj = j, nx = x, k;
if (second[i] == ch) ni--;
if (t[j] == ch) nj--;
if (ch == '(') {
nx--;
a = first(ni, nj, nx) + 1;
} else {
nx++;
b = first(ni, nj, nx) + 1;
}
}
if (a < b)
dp[i][j][x] = a, par[i][j][x] = '(';
else
dp[i][j][x] = b, par[i][j][x] = ')';
return dp[i][j][x];
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> second >> t;
long long n = second.size(), m = t.size();
second = '#' + second, t = '#' + t;
memset(dp, -1, sizeof dp);
first(n, m, 0);
long long i = n, j = m, x = 0;
string ans = "";
while (i or j) {
char ch = par[i][j][x];
ans += ch;
if (second[i] == ch) i--;
if (t[j] == ch) j--;
if (ch == '(')
x--;
else
x++;
}
while (x) ans += '(', x--;
reverse(ans.begin(), ans.end());
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(0);
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int n;
cin >> n;
int a = 0, b = 0;
for (int j = 1; j <= n; ++j) {
int x;
cin >> x;
if (x % 2) {
a++;
} else {
b++;
}
}
if (n % 2) {
if (a) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} else {
if (a > 0 & b > 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(0);
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int n;
cin >> n;
int a = 0, b = 0;
for (int j = 1; j <= n; ++j) {
int x;
cin >> x;
if (x % 2) {
a++;
} else {
b++;
}
}
if (n % 2) {
if (a) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} else {
if (a > 0 & b > 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) {
return a;
}
return (b % a, a);
}
void primesieve(long long int N, long long int s[]) {
vector<bool> prime(N + 1, false);
for (long long int i = 2; i <= N; i += 2) s[i] = 2;
for (long long int i = 3; i <= N; i += 2) {
if (prime[i] == false) {
s[i] = i;
for (long long int j = i; j * i <= N; j += 2) {
if (prime[i * j] == false) {
prime[i * j] = true;
s[i * j] = i;
}
}
}
}
}
long long int Primefactor(long long int N, long long int product) {
long long int s[N + 1];
primesieve(N, s);
long long int curr = s[N];
long long int cnt = 1;
while (N > 1) {
N /= s[N];
if (curr == s[N]) {
cnt++;
continue;
}
product *= (cnt + 1);
curr = s[N];
cnt = 1;
return product;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n];
long long int flag = 0;
long long int count = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
for (long long int i = 0; i < n; i++) {
if (a[i] % 2 != 0) count++;
}
if (count >= 1) {
if (count == n) {
if (n % 2 != 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
} else
cout << "YES"
<< "\n";
} else
cout << "NO"
<< "\n";
}
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) {
return a;
}
return (b % a, a);
}
void primesieve(long long int N, long long int s[]) {
vector<bool> prime(N + 1, false);
for (long long int i = 2; i <= N; i += 2) s[i] = 2;
for (long long int i = 3; i <= N; i += 2) {
if (prime[i] == false) {
s[i] = i;
for (long long int j = i; j * i <= N; j += 2) {
if (prime[i * j] == false) {
prime[i * j] = true;
s[i * j] = i;
}
}
}
}
}
long long int Primefactor(long long int N, long long int product) {
long long int s[N + 1];
primesieve(N, s);
long long int curr = s[N];
long long int cnt = 1;
while (N > 1) {
N /= s[N];
if (curr == s[N]) {
cnt++;
continue;
}
product *= (cnt + 1);
curr = s[N];
cnt = 1;
return product;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n];
long long int flag = 0;
long long int count = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
for (long long int i = 0; i < n; i++) {
if (a[i] % 2 != 0) count++;
}
if (count >= 1) {
if (count == n) {
if (n % 2 != 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
} else
cout << "YES"
<< "\n";
} else
cout << "NO"
<< "\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int t;
cin >> t;
bool even;
bool odd;
for (int i = 1; i <= t; i++) {
int size;
even = false;
odd = false;
cin >> size;
int arr[size];
for (int j = 0; j < size; j++) cin >> arr[j];
for (int j = 0; j < size; j++)
if (arr[j] % 2 == 0)
even = true;
else
odd = true;
if (even == true && odd == true)
cout << "YES" << endl;
else if (even == false && size % 2 != 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int t;
cin >> t;
bool even;
bool odd;
for (int i = 1; i <= t; i++) {
int size;
even = false;
odd = false;
cin >> size;
int arr[size];
for (int j = 0; j < size; j++) cin >> arr[j];
for (int j = 0; j < size; j++)
if (arr[j] % 2 == 0)
even = true;
else
odd = true;
if (even == true && odd == true)
cout << "YES" << endl;
else if (even == false && size % 2 != 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, num;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
scanf("%d", &n);
int E = 0, O = 0;
for (int j = 1; j <= n; j++) {
scanf("%d", &num);
if (num % 2 == 0)
E = 1;
else
O = 1;
}
if ((E && O) || (E == 0 && O && n % 2 != 0))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, num;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
scanf("%d", &n);
int E = 0, O = 0;
for (int j = 1; j <= n; j++) {
scanf("%d", &num);
if (num % 2 == 0)
E = 1;
else
O = 1;
}
if ((E && O) || (E == 0 && O && n % 2 != 0))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long t, n, odd, even, x;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
odd = 0;
even = 0;
for (long long i = 0; i < n; i++) {
cin >> x;
if (x % 2 == 1)
odd++;
else
even++;
}
if (odd == 0) {
cout << "NO\n";
continue;
}
if (n % 2 == 0 && even == 0) {
cout << "NO\n";
continue;
}
cout << "YES\n";
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long t, n, odd, even, x;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
odd = 0;
even = 0;
for (long long i = 0; i < n; i++) {
cin >> x;
if (x % 2 == 1)
odd++;
else
even++;
}
if (odd == 0) {
cout << "NO\n";
continue;
}
if (n % 2 == 0 && even == 0) {
cout << "NO\n";
continue;
}
cout << "YES\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, k, o;
cin >> t;
for (int j = 0; j < t; j++) {
cin >> n;
o = 0;
for (int i = 0; i < n; i++) {
cin >> k;
if (k % 2 == 1) o++;
}
if ((o != n && o != 0) || o % 2 == 1)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, k, o;
cin >> t;
for (int j = 0; j < t; j++) {
cin >> n;
o = 0;
for (int i = 0; i < n; i++) {
cin >> k;
if (k % 2 == 1) o++;
}
if ((o != n && o != 0) || o % 2 == 1)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, j;
cin >> t;
for (j = 0; j < t; j++) {
int n, i, s = 0, a[3000];
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
s = s + a[i];
}
if (s % 2 != 0) {
cout << "YES" << endl;
} else {
int k = 0, l = 0, v, m, p, h = 0;
for (i = 0; i < n; i++) {
if (a[i] % 2 != 0) {
k = a[i];
v = i;
break;
}
}
for (i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
l = a[i];
p = i;
break;
}
}
if (k > 0 && l > 0) {
if (n % 2 == 0) {
for (i = 0; i < n; i++) {
if (i == p) {
continue;
} else {
a[i] = k;
}
}
} else {
for (i = 0; i < n; i++) {
a[i] = k;
}
}
}
for (i = 0; i < n; i++) {
h = h + a[i];
}
if (h % 2 != 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, j;
cin >> t;
for (j = 0; j < t; j++) {
int n, i, s = 0, a[3000];
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
s = s + a[i];
}
if (s % 2 != 0) {
cout << "YES" << endl;
} else {
int k = 0, l = 0, v, m, p, h = 0;
for (i = 0; i < n; i++) {
if (a[i] % 2 != 0) {
k = a[i];
v = i;
break;
}
}
for (i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
l = a[i];
p = i;
break;
}
}
if (k > 0 && l > 0) {
if (n % 2 == 0) {
for (i = 0; i < n; i++) {
if (i == p) {
continue;
} else {
a[i] = k;
}
}
} else {
for (i = 0; i < n; i++) {
a[i] = k;
}
}
}
for (i = 0; i < n; i++) {
h = h + a[i];
}
if (h % 2 != 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, n, j, b, c, s;
cin >> t;
for (i = 0; i < t; i++) {
b = 0;
c = 0;
s = 0;
cin >> n;
int a[n];
for (j = 0; j < n; j++) {
cin >> a[j];
}
for (j = 0; j < n; j++) {
if (a[j] % 2 == 0)
b++;
else
c++;
}
if (c == 0)
cout << "NO" << endl;
else if (b == 0 && n % 2 == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, n, j, b, c, s;
cin >> t;
for (i = 0; i < t; i++) {
b = 0;
c = 0;
s = 0;
cin >> n;
int a[n];
for (j = 0; j < n; j++) {
cin >> a[j];
}
for (j = 0; j < n; j++) {
if (a[j] % 2 == 0)
b++;
else
c++;
}
if (c == 0)
cout << "NO" << endl;
else if (b == 0 && n % 2 == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t, n;
cin >> t;
while (t--) {
cin >> n;
vector<long long> v(n, 0);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
long long odd = 0;
for (int i = 0; i < n; i++) {
if (v[i] % 2 == 1) odd++;
}
if (odd == 0) {
cout << "NO\n";
} else if (odd == n && n % 2 == 0) {
cout << "NO\n";
} else
cout << "YES\n";
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t, n;
cin >> t;
while (t--) {
cin >> n;
vector<long long> v(n, 0);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
long long odd = 0;
for (int i = 0; i < n; i++) {
if (v[i] % 2 == 1) odd++;
}
if (odd == 0) {
cout << "NO\n";
} else if (odd == n && n % 2 == 0) {
cout << "NO\n";
} else
cout << "YES\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void fast();
long long int ar[200005];
long long int n, a, b, c, d, m, k, q, mod;
vector<long long int> v;
int32_t main() {
fast();
long long int t = 1;
cin >> t;
while (t--) {
cin >> n;
for (long long int i = 0; i < n; i++) cin >> ar[i];
;
long long int sum = 0;
for (long long int i = 0; i < n; i++) sum += ar[i];
long long int odd = 0;
long long int even = 0;
for (long long int i = 0; i < n; i++) {
if (ar[i] % 2 == 0)
even++;
else
odd++;
}
if (sum % 2 == 0) {
if (odd && even)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
} else {
cout << "YES"
<< "\n";
}
}
return 0;
}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
| ### Prompt
Generate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void fast();
long long int ar[200005];
long long int n, a, b, c, d, m, k, q, mod;
vector<long long int> v;
int32_t main() {
fast();
long long int t = 1;
cin >> t;
while (t--) {
cin >> n;
for (long long int i = 0; i < n; i++) cin >> ar[i];
;
long long int sum = 0;
for (long long int i = 0; i < n; i++) sum += ar[i];
long long int odd = 0;
long long int even = 0;
for (long long int i = 0; i < n; i++) {
if (ar[i] % 2 == 0)
even++;
else
odd++;
}
if (sum % 2 == 0) {
if (odd && even)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
} else {
cout << "YES"
<< "\n";
}
}
return 0;
}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[501102];
int ans, cnt, sum, d;
void solve() {
ans = 0;
cnt = 0;
sum = 0;
d = 0;
int n;
cin >> n;
for (int i = 1; n >= i; i++) {
cin >> a[i];
if (a[i] % 2 == 1) {
ans++;
if (a[i] * n % 2 == 1) d = 1;
} else
cnt++;
sum += a[i];
}
if (ans >= cnt && ans != n || sum % 2 == 1 || d != 0 ||
ans != 0 && cnt != 0) {
cout << "YES" << endl;
return;
}
cout << "NO" << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[501102];
int ans, cnt, sum, d;
void solve() {
ans = 0;
cnt = 0;
sum = 0;
d = 0;
int n;
cin >> n;
for (int i = 1; n >= i; i++) {
cin >> a[i];
if (a[i] % 2 == 1) {
ans++;
if (a[i] * n % 2 == 1) d = 1;
} else
cnt++;
sum += a[i];
}
if (ans >= cnt && ans != n || sum % 2 == 1 || d != 0 ||
ans != 0 && cnt != 0) {
cout << "YES" << endl;
return;
}
cout << "NO" << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int check() {
int n, sum = 0, c = 0, flag = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
sum = sum + a[i];
if (a[i] % 2 != 0) c++;
}
if (sum % 2 != 0)
flag = 1;
else if (n % 2 == 0) {
if (c == 0 || c == n)
flag = 0;
else
flag = 1;
} else if (n % 2 != 0 && c > 0) {
flag = 1;
} else
flag = 0;
return flag;
}
int main() {
int t;
cin >> t;
int a[t];
for (int i = 0; i < t; i++) a[i] = check();
for (int i = 0; i < t; i++) {
if (a[i] == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| ### Prompt
Please create a solution in cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int check() {
int n, sum = 0, c = 0, flag = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
sum = sum + a[i];
if (a[i] % 2 != 0) c++;
}
if (sum % 2 != 0)
flag = 1;
else if (n % 2 == 0) {
if (c == 0 || c == n)
flag = 0;
else
flag = 1;
} else if (n % 2 != 0 && c > 0) {
flag = 1;
} else
flag = 0;
return flag;
}
int main() {
int t;
cin >> t;
int a[t];
for (int i = 0; i < t; i++) a[i] = check();
for (int i = 0; i < t; i++) {
if (a[i] == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
vector<int> a;
vector<string> f;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
int s = 0;
for (int j = 0; j < n; j++) {
int temp;
cin >> temp;
a.push_back(temp);
s += temp;
}
if (s % 2 == 0) {
bool odd = false;
bool even = false;
for (int j = 0; j < n; j++) {
if (a[j] % 2 != 0) {
odd = true;
} else {
even = true;
}
}
if (odd && even) {
f.push_back("YES");
} else {
f.push_back("NO");
}
even = false;
odd = false;
} else {
f.push_back("YES");
}
a.clear();
}
for (int i = 0; i < f.size(); i++) {
cout << f[i] << "\n";
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
vector<int> a;
vector<string> f;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
int s = 0;
for (int j = 0; j < n; j++) {
int temp;
cin >> temp;
a.push_back(temp);
s += temp;
}
if (s % 2 == 0) {
bool odd = false;
bool even = false;
for (int j = 0; j < n; j++) {
if (a[j] % 2 != 0) {
odd = true;
} else {
even = true;
}
}
if (odd && even) {
f.push_back("YES");
} else {
f.push_back("NO");
}
even = false;
odd = false;
} else {
f.push_back("YES");
}
a.clear();
}
for (int i = 0; i < f.size(); i++) {
cout << f[i] << "\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int t;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
if (n % 2 == 0) {
int k = 0;
int p = 0;
for (int i = 0; i < n; i++) {
if (v[i] % 2 == 0)
k++;
else
p++;
}
if (k > 0 && p > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else {
int k = 0;
for (int i = 0; i < n; i++)
if (v[i] % 2 != 0) {
k++;
break;
}
if (k > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}
| ### Prompt
Please create a solution in cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int t;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
if (n % 2 == 0) {
int k = 0;
int p = 0;
for (int i = 0; i < n; i++) {
if (v[i] % 2 == 0)
k++;
else
p++;
}
if (k > 0 && p > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else {
int k = 0;
for (int i = 0; i < n; i++)
if (v[i] % 2 != 0) {
k++;
break;
}
if (k > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool is_even = false, is_odd = false;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x % 2)
is_odd = true;
else
is_even = true;
}
if (is_odd and is_even or is_odd and n % 2)
cout << "YES";
else
cout << "NO";
cout << endl;
}
}
| ### Prompt
Please formulate a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool is_even = false, is_odd = false;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x % 2)
is_odd = true;
else
is_even = true;
}
if (is_odd and is_even or is_odd and n % 2)
cout << "YES";
else
cout << "NO";
cout << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
odd += (x & 1 ? 1 : 0);
even += (!(x & 1) ? 1 : 0);
}
if (n & 1) {
if (odd > 0) {
cout << "YES";
} else {
cout << "NO";
}
} else {
if (odd > 0 && odd != n) {
cout << "YES";
} else if (odd > 0 && odd == n) {
cout << "NO";
} else if (odd == 0) {
cout << "NO";
}
}
cout << "\n";
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
odd += (x & 1 ? 1 : 0);
even += (!(x & 1) ? 1 : 0);
}
if (n & 1) {
if (odd > 0) {
cout << "YES";
} else {
cout << "NO";
}
} else {
if (odd > 0 && odd != n) {
cout << "YES";
} else if (odd > 0 && odd == n) {
cout << "NO";
} else if (odd == 0) {
cout << "NO";
}
}
cout << "\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
map<int, int> m;
for (int i = 0; i < n; i++) {
if (a[i] & 1) {
m[1]++;
} else {
m[0]++;
}
}
if (n & 1) {
if (m[1] > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
if (m[0] == 0) {
cout << "NO" << endl;
} else if (m[1] == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
}
| ### Prompt
Please create a solution in Cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
map<int, int> m;
for (int i = 0; i < n; i++) {
if (a[i] & 1) {
m[1]++;
} else {
m[0]++;
}
}
if (n & 1) {
if (m[1] > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
if (m[0] == 0) {
cout << "NO" << endl;
} else if (m[1] == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
}
``` |
#include <bits/stdc++.h>
void err() { std::cout << '\n'; }
template <typename T, typename... Args>
void err(T a, Args... args) {
std::cout << a << ' ';
err(args...);
}
void pt() { std::cout << '\n'; }
template <typename T, typename... Args>
void pt(T a, Args... args) {
std::cout << a << ' ';
pt(args...);
}
using namespace std;
const int N = 2000 + 5;
int n;
int a[N];
void run() {
int cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] & 1) ++cnt;
}
if (cnt == 0)
cout << "NO" << '\n';
else {
if (cnt % 2 == 0 && n == cnt)
cout << "NO" << '\n';
else
cout << "YES" << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(20);
int T;
cin >> T;
while (T--) run();
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
void err() { std::cout << '\n'; }
template <typename T, typename... Args>
void err(T a, Args... args) {
std::cout << a << ' ';
err(args...);
}
void pt() { std::cout << '\n'; }
template <typename T, typename... Args>
void pt(T a, Args... args) {
std::cout << a << ' ';
pt(args...);
}
using namespace std;
const int N = 2000 + 5;
int n;
int a[N];
void run() {
int cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] & 1) ++cnt;
}
if (cnt == 0)
cout << "NO" << '\n';
else {
if (cnt % 2 == 0 && n == cnt)
cout << "NO" << '\n';
else
cout << "YES" << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(20);
int T;
cin >> T;
while (T--) run();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
srand(time(0));
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(9);
solve();
return 0;
}
const long long INF = 1e18;
void query() {
long long n;
cin >> n;
long long cnt = 0;
for (long long i = 0; i < n; ++i) {
long long num;
cin >> num;
if (num % 2 == 0) {
cnt++;
}
}
if (cnt == n) {
cout << "NO" << '\n';
} else if (cnt == 0) {
if (n % 2 == 0) {
cout << "NO" << '\n';
} else {
cout << "YES" << '\n';
}
} else {
cout << "YES" << '\n';
}
}
void solve() {
long long t;
cin >> t;
for (long long i = 0; i < t; ++i) {
query();
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
srand(time(0));
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(9);
solve();
return 0;
}
const long long INF = 1e18;
void query() {
long long n;
cin >> n;
long long cnt = 0;
for (long long i = 0; i < n; ++i) {
long long num;
cin >> num;
if (num % 2 == 0) {
cnt++;
}
}
if (cnt == n) {
cout << "NO" << '\n';
} else if (cnt == 0) {
if (n % 2 == 0) {
cout << "NO" << '\n';
} else {
cout << "YES" << '\n';
}
} else {
cout << "YES" << '\n';
}
}
void solve() {
long long t;
cin >> t;
for (long long i = 0; i < t; ++i) {
query();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
int n;
while (t--) {
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
if (arr[i] & 1)
odd++;
else
even++;
if (odd > 0 && even > 0) {
cout << "YES\n";
goto ed;
}
}
if (odd == n && (n & 1)) {
cout << "YES\n";
} else
cout << "NO\n";
ed:
continue;
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
int n;
while (t--) {
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
if (arr[i] & 1)
odd++;
else
even++;
if (odd > 0 && even > 0) {
cout << "YES\n";
goto ed;
}
}
if (odd == n && (n & 1)) {
cout << "YES\n";
} else
cout << "NO\n";
ed:
continue;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 100;
long long n, m, t;
long long ans;
int main() {
while (cin >> t) {
while (t--) {
cin >> n;
long long odd = 0, even = 0;
long long sum = 0;
for (long long i = 0; i < n; i++) {
long long tmp;
cin >> tmp;
if (tmp % 2)
odd++;
else
even++;
sum += tmp;
}
if (sum % 2)
cout << "YES\n";
else {
if (odd == 0 || even == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
}
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 100;
long long n, m, t;
long long ans;
int main() {
while (cin >> t) {
while (t--) {
cin >> n;
long long odd = 0, even = 0;
long long sum = 0;
for (long long i = 0; i < n; i++) {
long long tmp;
cin >> tmp;
if (tmp % 2)
odd++;
else
even++;
sum += tmp;
}
if (sum % 2)
cout << "YES\n";
else {
if (odd == 0 || even == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
}
}
``` |
#include <bits/stdc++.h>
int main() {
int testCaseCount, caseInpCount;
scanf("%d", &testCaseCount);
for (int testCaseNum = 0; testCaseNum < testCaseCount; testCaseNum++) {
scanf("%d", &caseInpCount);
int oddCount = 0;
int evenCount = 0;
for (int caseNum = 0; caseNum < caseInpCount; caseNum++) {
int currentInp;
scanf("%d", ¤tInp);
if (currentInp % 2) {
oddCount++;
} else {
evenCount++;
}
}
if (oddCount % 2 || evenCount && oddCount) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int testCaseCount, caseInpCount;
scanf("%d", &testCaseCount);
for (int testCaseNum = 0; testCaseNum < testCaseCount; testCaseNum++) {
scanf("%d", &caseInpCount);
int oddCount = 0;
int evenCount = 0;
for (int caseNum = 0; caseNum < caseInpCount; caseNum++) {
int currentInp;
scanf("%d", ¤tInp);
if (currentInp % 2) {
oddCount++;
} else {
evenCount++;
}
}
if (oddCount % 2 || evenCount && oddCount) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool isSort(long long *a, long long n) {
for (int i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) return false;
}
return true;
}
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long o = 0, e = 0;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1)
o++;
else
e++;
}
if ((n == o && ((n & 1) == 0)) || n == e)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool isSort(long long *a, long long n) {
for (int i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) return false;
}
return true;
}
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long o = 0, e = 0;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1)
o++;
else
e++;
}
if ((n == o && ((n & 1) == 0)) || n == e)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b) {
if (b == 0) {
return 1;
}
long long result = binpow(a, b / 2);
if (b % 2) {
return a * result * result;
} else {
return result * result;
}
}
long long digit_sum(long long n) {
if (n <= 9) {
return n;
} else {
return n % 10 + digit_sum(n / 10);
}
}
long long is_prime(long long a) {
if (a % 2 == 0) {
return 2;
} else {
for (long long i = 3; i * i <= a; i++) {
if (a % i == 0) {
return i;
}
}
return -1;
}
}
long long count_digit(long long a) {
if (a <= 9) {
return 1;
} else {
return 1 + count_digit(a / 10);
}
}
void sol() {
long long n;
cin >> n;
vector<long long> arr(n);
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
long long odd_count = 0, even_count = 0;
for (long long i = 0; i < n; i++) {
if (arr[i] % 2) {
odd_count++;
} else {
even_count++;
}
}
if (even_count == n) {
cout << "NO" << endl;
return;
}
if (odd_count == n && n % 2 == 0) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long tttt;
cin >> tttt;
while (tttt--) sol();
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b) {
if (b == 0) {
return 1;
}
long long result = binpow(a, b / 2);
if (b % 2) {
return a * result * result;
} else {
return result * result;
}
}
long long digit_sum(long long n) {
if (n <= 9) {
return n;
} else {
return n % 10 + digit_sum(n / 10);
}
}
long long is_prime(long long a) {
if (a % 2 == 0) {
return 2;
} else {
for (long long i = 3; i * i <= a; i++) {
if (a % i == 0) {
return i;
}
}
return -1;
}
}
long long count_digit(long long a) {
if (a <= 9) {
return 1;
} else {
return 1 + count_digit(a / 10);
}
}
void sol() {
long long n;
cin >> n;
vector<long long> arr(n);
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
long long odd_count = 0, even_count = 0;
for (long long i = 0; i < n; i++) {
if (arr[i] % 2) {
odd_count++;
} else {
even_count++;
}
}
if (even_count == n) {
cout << "NO" << endl;
return;
}
if (odd_count == n && n % 2 == 0) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long tttt;
cin >> tttt;
while (tttt--) sol();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int fast_pow(long long int a, long long int p) {
long long int res = 1;
while (p) {
if (p % 2 == 0) {
a = a * 1ll * a % mod;
p /= 2;
} else {
res = res * 1ll * a % mod;
p--;
}
}
return res;
}
bool isPrime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
long long int fact(long long int n) {
long long int res = 1;
for (long long int i = 1; i <= n; i++) {
res = res * 1ll * i % mod;
}
return res;
}
long long int nCr(long long int n, long long int k) {
return fact(n) * 1ll * fast_pow(fact(k), mod - 2) % mod * 1ll *
fast_pow(fact(n - k), mod - 2) % mod;
}
void solve() {
long long int n;
cin >> n;
long long int cnt = 0;
long long int cnt1 = 0;
for (long long int i = 0; i < n; i++) {
long long int x;
cin >> x;
if ((x % 2 == 1)) {
cnt++;
} else
cnt1++;
}
if (n % 2 == 0) {
if (cnt > 0 and cnt1 > 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
} else {
if (cnt > 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) solve();
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int fast_pow(long long int a, long long int p) {
long long int res = 1;
while (p) {
if (p % 2 == 0) {
a = a * 1ll * a % mod;
p /= 2;
} else {
res = res * 1ll * a % mod;
p--;
}
}
return res;
}
bool isPrime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
long long int fact(long long int n) {
long long int res = 1;
for (long long int i = 1; i <= n; i++) {
res = res * 1ll * i % mod;
}
return res;
}
long long int nCr(long long int n, long long int k) {
return fact(n) * 1ll * fast_pow(fact(k), mod - 2) % mod * 1ll *
fast_pow(fact(n - k), mod - 2) % mod;
}
void solve() {
long long int n;
cin >> n;
long long int cnt = 0;
long long int cnt1 = 0;
for (long long int i = 0; i < n; i++) {
long long int x;
cin >> x;
if ((x % 2 == 1)) {
cnt++;
} else
cnt1++;
}
if (n % 2 == 0) {
if (cnt > 0 and cnt1 > 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
} else {
if (cnt > 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t, n;
cin >> t;
while (t--) {
cin >> n;
int cnt = 0, x;
for (int i = 0; i < n; i++) {
cin >> x;
if (x & 1) cnt++;
}
if (cnt == n) {
if (cnt & 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else {
if (cnt > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t, n;
cin >> t;
while (t--) {
cin >> n;
int cnt = 0, x;
for (int i = 0; i < n; i++) {
cin >> x;
if (x & 1) cnt++;
}
if (cnt == n) {
if (cnt & 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else {
if (cnt > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t-- > 0) {
int n;
cin >> n;
int arr[n];
int odd = 0;
int even = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2 == 0) {
even++;
} else {
odd++;
}
}
if (odd % 2 == 0 && even == 0) {
cout << "NO" << endl;
} else if (odd % 2 == 0 && even != 0 && odd != 0) {
cout << "YES" << endl;
} else if (odd == 0) {
cout << "NO" << endl;
} else if (odd % 2 != 0) {
cout << "YES" << endl;
}
}
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t-- > 0) {
int n;
cin >> n;
int arr[n];
int odd = 0;
int even = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2 == 0) {
even++;
} else {
odd++;
}
}
if (odd % 2 == 0 && even == 0) {
cout << "NO" << endl;
} else if (odd % 2 == 0 && even != 0 && odd != 0) {
cout << "YES" << endl;
} else if (odd == 0) {
cout << "NO" << endl;
} else if (odd % 2 != 0) {
cout << "YES" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t, n, a, nech = 0;
cin >> t;
for (long long q = 0; q < t; q++) {
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a;
if (a & 1) nech++;
}
if (nech == 0 || (nech == n && n % 2 == 0)) {
cout << "NO" << endl;
} else
cout << "YES" << endl;
nech = 0;
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t, n, a, nech = 0;
cin >> t;
for (long long q = 0; q < t; q++) {
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a;
if (a & 1) nech++;
}
if (nech == 0 || (nech == n && n % 2 == 0)) {
cout << "NO" << endl;
} else
cout << "YES" << endl;
nech = 0;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int num, oddcount = 0, evencount = 0;
for (int i = 0; i < n; i++) {
cin >> num;
num % 2 ? oddcount++ : evencount++;
}
if (n == evencount)
cout << "NO\n";
else if (n == oddcount && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
int main() {
int t = 0, tt;
cin >> tt;
while (t < tt) {
solve();
t++;
}
}
| ### Prompt
Generate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int num, oddcount = 0, evencount = 0;
for (int i = 0; i < n; i++) {
cin >> num;
num % 2 ? oddcount++ : evencount++;
}
if (n == evencount)
cout << "NO\n";
else if (n == oddcount && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
int main() {
int t = 0, tt;
cin >> tt;
while (t < tt) {
solve();
t++;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int a, demc = 0, deml = 0;
cin >> a;
int b[a + 2];
for (int i = 1; i <= a; ++i) {
cin >> b[i];
if (b[i] % 2 == 0)
++demc;
else
++deml;
}
if ((demc == a) || (a % 2 == 0 && deml == a))
cout << "NO";
else
cout << "YES";
cout << endl;
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int a, demc = 0, deml = 0;
cin >> a;
int b[a + 2];
for (int i = 1; i <= a; ++i) {
cin >> b[i];
if (b[i] % 2 == 0)
++demc;
else
++deml;
}
if ((demc == a) || (a % 2 == 0 && deml == a))
cout << "NO";
else
cout << "YES";
cout << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
int t;
cin >> t;
for (int titr = 0; titr < t; titr++) {
int n;
int a[2001];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
if (n % 2 == 0) {
bool o = 0;
bool e = 0;
for (int i = 0; i < n; i++) {
if (o && e) break;
if (a[i] % 2) {
o = 1;
} else {
e = 1;
}
}
if (o && e)
printf("YES\n");
else
printf("NO\n");
} else {
bool o = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2) {
o = 1;
break;
}
}
if (o)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
int t;
cin >> t;
for (int titr = 0; titr < t; titr++) {
int n;
int a[2001];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
if (n % 2 == 0) {
bool o = 0;
bool e = 0;
for (int i = 0; i < n; i++) {
if (o && e) break;
if (a[i] % 2) {
o = 1;
} else {
e = 1;
}
}
if (o && e)
printf("YES\n");
else
printf("NO\n");
} else {
bool o = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2) {
o = 1;
break;
}
}
if (o)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
template <class T>
void Swap(T &a, T &b) {
a ^= b;
b ^= a;
a ^= b;
}
template <class type>
void show(type name) {
for (auto &nm : name) cerr << nm << ' ';
cerr << '\n';
}
using lng = long long;
using ivec = vector<int>;
int main() {
int n, t;
cin >> t;
while (t--) {
int num, odd = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> num;
if (num & 1) odd++;
}
if (odd > 0) {
if (odd == n && odd % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
} else
cout << "NO\n";
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
template <class T>
void Swap(T &a, T &b) {
a ^= b;
b ^= a;
a ^= b;
}
template <class type>
void show(type name) {
for (auto &nm : name) cerr << nm << ' ';
cerr << '\n';
}
using lng = long long;
using ivec = vector<int>;
int main() {
int n, t;
cin >> t;
while (t--) {
int num, odd = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> num;
if (num & 1) odd++;
}
if (odd > 0) {
if (odd == n && odd % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
} else
cout << "NO\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
ifstream f("submatrix.in");
ofstream g("submatrix.out");
int t, i, j, n, nr, x;
int main() {
cin >> t;
for (i = 1; i <= t; i++) {
cin >> n;
nr = 0;
for (j = 1; j <= n; j++) {
cin >> x;
if (x % 2 == 0) nr++;
}
if (nr == n)
cout << "NO";
else if (nr == 0 && n % 2 == 0)
cout << "NO";
else
cout << "YES";
cout << '\n';
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
ifstream f("submatrix.in");
ofstream g("submatrix.out");
int t, i, j, n, nr, x;
int main() {
cin >> t;
for (i = 1; i <= t; i++) {
cin >> n;
nr = 0;
for (j = 1; j <= n; j++) {
cin >> x;
if (x % 2 == 0) nr++;
}
if (nr == n)
cout << "NO";
else if (nr == 0 && n % 2 == 0)
cout << "NO";
else
cout << "YES";
cout << '\n';
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
void sol() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
if (arr[i] % 2) {
odd++;
} else {
even++;
}
}
if (odd == 0) {
cout << "NO" << endl;
return;
}
if ((odd == n && n % 2) || (even > 0 && odd > 0)) {
cout << "YES" << endl;
return;
} else {
cout << "NO" << endl;
return;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long ttt;
cin >> ttt;
while (ttt--) {
sol();
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
void sol() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
if (arr[i] % 2) {
odd++;
} else {
even++;
}
}
if (odd == 0) {
cout << "NO" << endl;
return;
}
if ((odd == n && n % 2) || (even > 0 && odd > 0)) {
cout << "YES" << endl;
return;
} else {
cout << "NO" << endl;
return;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long ttt;
cin >> ttt;
while (ttt--) {
sol();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long fpow(long long x, long long y, long long p = 1000000007) {
x = x % p;
long long sum = 1;
while (y) {
if (y & 1) sum = sum * x;
sum %= p;
y = y >> 1;
x = x * x;
x %= p;
}
return sum;
}
long long modmul(long long x, long long y) { return (x * y) % 1000000007; }
long long modadd(long long x, long long y) { return (x + y) % 1000000007; }
long long modsub(long long x, long long y) {
return (x - y + 1000000007) % 1000000007;
}
void solve() {
int n;
cin >> n;
int arr[n];
int o = 0, e = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2)
o++;
else
e++;
}
if (o % 2 || o % n)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) solve();
}
| ### Prompt
Please create a solution in cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long fpow(long long x, long long y, long long p = 1000000007) {
x = x % p;
long long sum = 1;
while (y) {
if (y & 1) sum = sum * x;
sum %= p;
y = y >> 1;
x = x * x;
x %= p;
}
return sum;
}
long long modmul(long long x, long long y) { return (x * y) % 1000000007; }
long long modadd(long long x, long long y) { return (x + y) % 1000000007; }
long long modsub(long long x, long long y) {
return (x - y + 1000000007) % 1000000007;
}
void solve() {
int n;
cin >> n;
int arr[n];
int o = 0, e = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2)
o++;
else
e++;
}
if (o % 2 || o % n)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) solve();
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int sum = 0;
int even = 0;
int odd = 0;
int arr[2001];
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum += (arr[i]);
if (arr[i] % 2 == 0) {
even++;
} else {
odd++;
}
}
if (sum % 2 != 0) {
cout << "YES" << endl;
} else if (even > 0 && odd > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int sum = 0;
int even = 0;
int odd = 0;
int arr[2001];
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum += (arr[i]);
if (arr[i] % 2 == 0) {
even++;
} else {
odd++;
}
}
if (sum % 2 != 0) {
cout << "YES" << endl;
} else if (even > 0 && odd > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, r, j, n;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n;
int a[n];
r = 0;
for (j = 0; j < n; j++) {
cin >> a[j];
if (a[j] % 2 == 1) {
r = r + 1;
}
}
if (r == 0) {
cout << "NO\n";
} else if (r % 2 == 1) {
cout << "YES\n";
} else {
if (r == n) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, r, j, n;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n;
int a[n];
r = 0;
for (j = 0; j < n; j++) {
cin >> a[j];
if (a[j] % 2 == 1) {
r = r + 1;
}
}
if (r == 0) {
cout << "NO\n";
} else if (r % 2 == 1) {
cout << "YES\n";
} else {
if (r == n) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, i, j;
cin >> t;
for (i = 0; i < t; i++) {
long long int e = 0, o = 0;
cin >> n;
for (j = 0; j < n; j++) {
long long int p;
cin >> p;
if (p % 2 == 0)
e++;
else
o++;
}
if (o % 2 == 1)
cout << "YES" << endl;
else if (e > 0 && o > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, i, j;
cin >> t;
for (i = 0; i < t; i++) {
long long int e = 0, o = 0;
cin >> n;
for (j = 0; j < n; j++) {
long long int p;
cin >> p;
if (p % 2 == 0)
e++;
else
o++;
}
if (o % 2 == 1)
cout << "YES" << endl;
else if (e > 0 && o > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, c, d;
cin >> t;
for (int i = 0; i < t; i++) {
c = 0;
cin >> n;
int a[n];
for (int j = 0; j < n; j++) {
cin >> a[j];
c += a[j];
}
if (c % 2 != 0)
cout << "YES" << endl;
else {
c = 0;
d = 0;
for (int k = 0; k < n; k++) {
if (a[k] % 2 == 0) c++;
if (a[k] % 2 != 0) d++;
}
if (c > 0 && d > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, c, d;
cin >> t;
for (int i = 0; i < t; i++) {
c = 0;
cin >> n;
int a[n];
for (int j = 0; j < n; j++) {
cin >> a[j];
c += a[j];
}
if (c % 2 != 0)
cout << "YES" << endl;
else {
c = 0;
d = 0;
for (int k = 0; k < n; k++) {
if (a[k] % 2 == 0) c++;
if (a[k] % 2 != 0) d++;
}
if (c > 0 && d > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
int arr[n];
int odd = 0;
int even = 0;
int total = 0;
bool fl = false;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] & 1) {
odd += 1;
}
total += arr[i];
}
if (total & 1)
cout << "YES\n";
else if (odd == 0)
cout << "NO\n";
else {
if (odd < n)
cout << "YES\n";
else {
if (odd % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
}
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
int arr[n];
int odd = 0;
int even = 0;
int total = 0;
bool fl = false;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] & 1) {
odd += 1;
}
total += arr[i];
}
if (total & 1)
cout << "YES\n";
else if (odd == 0)
cout << "NO\n";
else {
if (odd < n)
cout << "YES\n";
else {
if (odd % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const double eps = 1e-9;
const int inf = 1e9;
int a[N];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int pos = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1) {
if (pos == -1) pos = i;
}
}
for (int i = 0; i < n; i++) {
if (i == pos) continue;
if (a[i] % 2 == 0) {
for (int j = 0; j < n; j++) {
if (j == i || j == pos) continue;
a[j] = a[i];
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) sum += a[i];
if (sum & 1)
cout << "YES\n";
else
cout << "NO\n";
}
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const double eps = 1e-9;
const int inf = 1e9;
int a[N];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int pos = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1) {
if (pos == -1) pos = i;
}
}
for (int i = 0; i < n; i++) {
if (i == pos) continue;
if (a[i] % 2 == 0) {
for (int j = 0; j < n; j++) {
if (j == i || j == pos) continue;
a[j] = a[i];
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) sum += a[i];
if (sum & 1)
cout << "YES\n";
else
cout << "NO\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long ar[n];
long long sum = 0;
long long e = 0;
long long o = 0;
for (long long i = 0; i < n; i++) {
cin >> ar[i];
if (ar[i] % 2 != 0)
o++;
else if (ar[i] % 2 == 0)
e++;
sum += ar[i];
}
if (sum % 2 != 0)
cout << "YES" << endl;
else {
if (e > 0 && o > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}
| ### Prompt
Create a solution in CPP for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long ar[n];
long long sum = 0;
long long e = 0;
long long o = 0;
for (long long i = 0; i < n; i++) {
cin >> ar[i];
if (ar[i] % 2 != 0)
o++;
else if (ar[i] % 2 == 0)
e++;
sum += ar[i];
}
if (sum % 2 != 0)
cout << "YES" << endl;
else {
if (e > 0 && o > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int t;
cin >> t;
int n;
int sum;
int odd;
int even;
while (t--) {
cin >> n;
sum = 0;
odd = 0;
even = 0;
int arr[n];
for (int j = 0; j < n; j++) {
cin >> arr[j];
if (arr[j] % 2 != 0 || arr[j] == 1) {
odd++;
} else {
even++;
}
sum += arr[j];
}
if (sum % 2 != 0 || sum == 1) {
cout << "YES" << endl;
} else {
if (odd != 0 && even != 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
solve();
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
int t;
cin >> t;
int n;
int sum;
int odd;
int even;
while (t--) {
cin >> n;
sum = 0;
odd = 0;
even = 0;
int arr[n];
for (int j = 0; j < n; j++) {
cin >> arr[j];
if (arr[j] % 2 != 0 || arr[j] == 1) {
odd++;
} else {
even++;
}
sum += arr[j];
}
if (sum % 2 != 0 || sum == 1) {
cout << "YES" << endl;
} else {
if (odd != 0 && even != 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int main() {
int calls;
cin >> calls;
int N;
int a;
bool even, odd;
for (int call = 0; call < calls; call++) {
cin >> N;
even = false;
odd = false;
for (int i = 0; i < N; i++) {
cin >> a;
if (a % 2 == 0) {
even = true;
} else {
odd = true;
}
}
if (even == true && odd == false) {
cout << "NO" << endl;
} else if (even == false && odd == true && (N % 2) == 0) {
cout << "NO" << endl;
} else if (even == false && odd == true && (N % 2) == 1) {
cout << "YES" << endl;
} else if (even == true && odd == true) {
cout << "YES" << endl;
}
}
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int main() {
int calls;
cin >> calls;
int N;
int a;
bool even, odd;
for (int call = 0; call < calls; call++) {
cin >> N;
even = false;
odd = false;
for (int i = 0; i < N; i++) {
cin >> a;
if (a % 2 == 0) {
even = true;
} else {
odd = true;
}
}
if (even == true && odd == false) {
cout << "NO" << endl;
} else if (even == false && odd == true && (N % 2) == 0) {
cout << "NO" << endl;
} else if (even == false && odd == true && (N % 2) == 1) {
cout << "YES" << endl;
} else if (even == true && odd == true) {
cout << "YES" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
const int maxx = 1e5 + 7;
const int maxn = 1e9 + 1;
using namespace std;
int t;
int n;
int a[maxx];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int flag1 = 0, flag2 = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] % 2 == 0)
flag1 = 1;
else
flag2 = 1;
}
if (flag1 && flag2)
cout << "YES" << endl;
else if (flag2) {
if (n % 2 == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
const int maxx = 1e5 + 7;
const int maxn = 1e9 + 1;
using namespace std;
int t;
int n;
int a[maxx];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int flag1 = 0, flag2 = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] % 2 == 0)
flag1 = 1;
else
flag2 = 1;
}
if (flag1 && flag2)
cout << "YES" << endl;
else if (flag2) {
if (n % 2 == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int ar[n];
int sum = 0;
int numOdd = 0;
int even = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
sum += ar[i];
if (ar[i] % 2 != 0)
numOdd++;
else
even++;
}
if (sum % 2 != 0 || (numOdd - 1 % 2 != 0 && numOdd > 0 && even >= 1))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main() {
int t;
cin >> t;
for (int tt = 0; tt < t; tt++) {
solve();
}
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int ar[n];
int sum = 0;
int numOdd = 0;
int even = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
sum += ar[i];
if (ar[i] % 2 != 0)
numOdd++;
else
even++;
}
if (sum % 2 != 0 || (numOdd - 1 % 2 != 0 && numOdd > 0 && even >= 1))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main() {
int t;
cin >> t;
for (int tt = 0; tt < t; tt++) {
solve();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int t, n, temp;
bool hasOdd, hasEven;
int main() {
cin >> t;
for (int i = 0; i < t; i++) {
hasEven = false;
hasOdd = false;
cin >> n;
for (int j = 0; j < n; j++) {
cin >> temp;
if (temp & 1) {
hasOdd = true;
} else {
hasEven = true;
}
}
if (n % 2 == 0) {
if (hasEven && hasOdd) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} else {
if (hasOdd) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int t, n, temp;
bool hasOdd, hasEven;
int main() {
cin >> t;
for (int i = 0; i < t; i++) {
hasEven = false;
hasOdd = false;
cin >> n;
for (int j = 0; j < n; j++) {
cin >> temp;
if (temp & 1) {
hasOdd = true;
} else {
hasEven = true;
}
}
if (n % 2 == 0) {
if (hasEven && hasOdd) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} else {
if (hasOdd) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int read() {
int sum = 0, f = 1;
char s = getchar();
while (s < '0' or s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' and s <= '9') {
sum = sum * 10 + s - '0';
s = getchar();
}
return sum * f;
}
int n, t, a, b, sum, c;
int main() {
t = read();
while (t--) {
sum = 0, a = 0, b = 0;
n = read();
for (int i = 1; i <= n; i++) {
c = read();
if (c % 2 == 1)
a++;
else
b++;
sum += c;
}
if (sum % 2 == 1) {
cout << "YES" << endl;
continue;
}
if (a >= 1 and b >= 1) {
cout << "YES" << endl;
continue;
}
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
int sum = 0, f = 1;
char s = getchar();
while (s < '0' or s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' and s <= '9') {
sum = sum * 10 + s - '0';
s = getchar();
}
return sum * f;
}
int n, t, a, b, sum, c;
int main() {
t = read();
while (t--) {
sum = 0, a = 0, b = 0;
n = read();
for (int i = 1; i <= n; i++) {
c = read();
if (c % 2 == 1)
a++;
else
b++;
sum += c;
}
if (sum % 2 == 1) {
cout << "YES" << endl;
continue;
}
if (a >= 1 and b >= 1) {
cout << "YES" << endl;
continue;
}
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, sum = 0, odd = 0, even = 0;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2 != 0 || arr[i] == 1) {
odd++;
} else {
even++;
}
sum += arr[i];
}
if (sum % 2 != 0 || sum == 1) {
cout << "YES"
<< "\n";
} else if (even != 0 && odd != 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, sum = 0, odd = 0, even = 0;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2 != 0 || arr[i] == 1) {
odd++;
} else {
even++;
}
sum += arr[i];
}
if (sum % 2 != 0 || sum == 1) {
cout << "YES"
<< "\n";
} else if (even != 0 && odd != 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int a[2010];
int main() {
int T = read();
while (T--) {
int ji = 0, ou = 0;
int n = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
if (a[i] & 1)
ji++;
else
ou++;
}
if (ou == n || (ji == n && ji % 2 == 0))
printf("NO\n");
else if (ji == n && (ji & 1))
printf("YES\n");
else
printf("YES\n");
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int a[2010];
int main() {
int T = read();
while (T--) {
int ji = 0, ou = 0;
int n = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
if (a[i] & 1)
ji++;
else
ou++;
}
if (ou == n || (ji == n && ji % 2 == 0))
printf("NO\n");
else if (ji == n && (ji & 1))
printf("YES\n");
else
printf("YES\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
int x[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> x[i];
sum += x[i];
}
bool b = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if ((sum - x[i] + x[j]) % 2) {
b = 1;
break;
}
}
if (b) break;
}
if (b || sum % 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
int x[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> x[i];
sum += x[i];
}
bool b = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if ((sum - x[i] + x[j]) % 2) {
b = 1;
break;
}
}
if (b) break;
}
if (b || sum % 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a;
int sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back(x);
sum += x;
}
long long odd = 0, even = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2) {
odd++;
} else {
even++;
}
}
if ((odd == n || even == n) && sum % 2 == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a;
int sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back(x);
sum += x;
}
long long odd = 0, even = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2) {
odd++;
} else {
even++;
}
}
if ((odd == n || even == n) && sum % 2 == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int times;
cin >> times;
while (times) {
int n;
cin >> n;
int count = 0;
bool o = false;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a % 2 == 0)
o = true;
else
count++;
}
if (n % 2 == 1 && count > 0 || n % 2 == 0 && count > 0 && o)
cout << "Yes" << endl;
else
cout << "No" << endl;
times--;
}
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int times;
cin >> times;
while (times) {
int n;
cin >> n;
int count = 0;
bool o = false;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a % 2 == 0)
o = true;
else
count++;
}
if (n % 2 == 1 && count > 0 || n % 2 == 0 && count > 0 && o)
cout << "Yes" << endl;
else
cout << "No" << endl;
times--;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 != 0) sum++;
}
if ((sum == n && sum % 2 == 0) || sum == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
| ### Prompt
Generate a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 != 0) sum++;
}
if ((sum == n && sum % 2 == 0) || sum == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
int test = tmp & 1;
if (tmp & 1)
odd++;
else
even++;
}
if ((odd >= 1 and even >= 1) or odd & 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
int test = tmp & 1;
if (tmp & 1)
odd++;
else
even++;
}
if ((odd >= 1 and even >= 1) or odd & 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
signed int main() {
long long int n, a, q;
cin >> q;
vector<int> v;
for (long long int i = 0; i < q; i++) {
cin >> n;
int sum = 0, odd = 0, even = 0;
for (long long int j = 0; j < n; j++) {
cin >> a;
if (a % 2 == 0) even++;
if (a % 2 == 1) odd++;
sum += a;
}
if ((odd % 2 == 0 && (even > 0 && odd > 0)) || (sum % 2 == 1))
v.push_back(1);
else
v.push_back(0);
}
for (long long int i = 0; i < q; i++) {
if (v[i] == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
signed int main() {
long long int n, a, q;
cin >> q;
vector<int> v;
for (long long int i = 0; i < q; i++) {
cin >> n;
int sum = 0, odd = 0, even = 0;
for (long long int j = 0; j < n; j++) {
cin >> a;
if (a % 2 == 0) even++;
if (a % 2 == 1) odd++;
sum += a;
}
if ((odd % 2 == 0 && (even > 0 && odd > 0)) || (sum % 2 == 1))
v.push_back(1);
else
v.push_back(0);
}
for (long long int i = 0; i < q; i++) {
if (v[i] == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 != 0) sum++;
}
if ((n % 2 != 0 && sum != 0) || (n % 2 == 0 && sum != 0 && sum != n))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 != 0) sum++;
}
if ((n % 2 != 0 && sum != 0) || (n % 2 == 0 && sum != 0 && sum != n))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long num = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) {
num = (num << 3) + (num << 1) + (ch ^ 48);
ch = getchar();
}
return w ? -num : num;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const long long mod = 1e9 + 7;
struct mat {
long long a[15][15];
mat() { memset(a, 0, sizeof(a)); }
};
mat mul(mat x, mat y) {
mat res;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
res.a[i][j] = (res.a[i][j] + x.a[i][k] * y.a[k][j]) % mod;
return res;
}
long long qpow(int p) {
mat bas;
mat res;
for (int i = 0; i < 2; i++) res.a[i][i] = 1;
bas.a[0][0] = bas.a[0][1] = bas.a[1][0] = 1;
bas.a[1][1] = 0;
while (p) {
if (1 & p) res = mul(res, bas);
bas = mul(bas, bas);
p >>= 1;
}
return res.a[0][1];
}
int main() {
int t;
t = read();
while (t--) {
int n;
n = read();
int sum = 0;
int num = 0;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
if (k % 2 == 1) sum++;
if (k % 2 == 0) num++;
}
if (n % 2 == 1) {
if (sum)
cout << "Yes" << endl;
else
cout << "NO" << endl;
} else {
if (sum != 0 && num != 0)
cout << "yes" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long num = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) {
num = (num << 3) + (num << 1) + (ch ^ 48);
ch = getchar();
}
return w ? -num : num;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const long long mod = 1e9 + 7;
struct mat {
long long a[15][15];
mat() { memset(a, 0, sizeof(a)); }
};
mat mul(mat x, mat y) {
mat res;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
res.a[i][j] = (res.a[i][j] + x.a[i][k] * y.a[k][j]) % mod;
return res;
}
long long qpow(int p) {
mat bas;
mat res;
for (int i = 0; i < 2; i++) res.a[i][i] = 1;
bas.a[0][0] = bas.a[0][1] = bas.a[1][0] = 1;
bas.a[1][1] = 0;
while (p) {
if (1 & p) res = mul(res, bas);
bas = mul(bas, bas);
p >>= 1;
}
return res.a[0][1];
}
int main() {
int t;
t = read();
while (t--) {
int n;
n = read();
int sum = 0;
int num = 0;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
if (k % 2 == 1) sum++;
if (k % 2 == 0) num++;
}
if (n % 2 == 1) {
if (sum)
cout << "Yes" << endl;
else
cout << "NO" << endl;
} else {
if (sum != 0 && num != 0)
cout << "yes" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int t, n, a;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
cin >> t;
while (t--) {
cin >> n;
bool e = 0, o = 0;
int sum = 0;
for (int i = 0; i < n; ++i) {
cin >> a;
sum += a;
if (a % 2 == 0)
e = 1;
else
o = 1;
}
if (sum % 2 != 0 || (e && o))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int t, n, a;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
cin >> t;
while (t--) {
cin >> n;
bool e = 0, o = 0;
int sum = 0;
for (int i = 0; i < n; ++i) {
cin >> a;
sum += a;
if (a % 2 == 0)
e = 1;
else
o = 1;
}
if (sum % 2 != 0 || (e && o))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long exp(long long a, long long n) {
if (n == 0) return 1;
long long residue = 1, result = a;
while (n > 1LL) {
if (n % 2LL == 1LL) residue = residue * residue % 1000000007LL;
result = result * result % 1000000007LL;
n = n >> 1;
}
return residue * result % 1000000007LL;
}
void sieve(long long n, vector<bool> &isPrime) {
for (int i = 0; i <= n; i++) isPrime[i] = true;
isPrime[0] = isPrime[1] = false;
for (long long i = 2; i * i <= n; i++) {
if (!isPrime[i]) continue;
for (long long j = i * i; j <= n; j += i) {
isPrime[j] = false;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t, n, sum, x, even, odd;
cin >> t;
while (t--) {
cin >> n;
sum = 0;
odd = even = 0;
for (int i = 0; i < n; i++) {
cin >> x;
sum += x;
if (x % 2 == 0)
even++;
else
odd++;
}
if (sum % 2 == 1)
cout << "YES" << endl;
else if (even > 0 && odd > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long exp(long long a, long long n) {
if (n == 0) return 1;
long long residue = 1, result = a;
while (n > 1LL) {
if (n % 2LL == 1LL) residue = residue * residue % 1000000007LL;
result = result * result % 1000000007LL;
n = n >> 1;
}
return residue * result % 1000000007LL;
}
void sieve(long long n, vector<bool> &isPrime) {
for (int i = 0; i <= n; i++) isPrime[i] = true;
isPrime[0] = isPrime[1] = false;
for (long long i = 2; i * i <= n; i++) {
if (!isPrime[i]) continue;
for (long long j = i * i; j <= n; j += i) {
isPrime[j] = false;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t, n, sum, x, even, odd;
cin >> t;
while (t--) {
cin >> n;
sum = 0;
odd = even = 0;
for (int i = 0; i < n; i++) {
cin >> x;
sum += x;
if (x % 2 == 0)
even++;
else
odd++;
}
if (sum % 2 == 1)
cout << "YES" << endl;
else if (even > 0 && odd > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long t, n, a[2010], kt, vt;
int main() {
cin >> t;
while (t--) {
cin >> n;
kt = 0;
vt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] % 2)
kt++;
else
vt++;
}
if (kt == 0)
cout << "NO"
<< "\n";
else {
if (vt == 0) {
if (n % 2)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
} else
cout << "YES"
<< "\n";
}
}
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long t, n, a[2010], kt, vt;
int main() {
cin >> t;
while (t--) {
cin >> n;
kt = 0;
vt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] % 2)
kt++;
else
vt++;
}
if (kt == 0)
cout << "NO"
<< "\n";
else {
if (vt == 0) {
if (n % 2)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
} else
cout << "YES"
<< "\n";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n + 4];
long long i, sum = 0;
long long o = 0, e = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] & 1) {
o = 1;
} else {
e = 1;
}
}
if (sum & 1) {
cout << "YES\n";
} else {
if (o == 1 && e == 1) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n + 4];
long long i, sum = 0;
long long o = 0, e = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] & 1) {
o = 1;
} else {
e = 1;
}
}
if (sum & 1) {
cout << "YES\n";
} else {
if (o == 1 && e == 1) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const double pie = 2 * acos(0.0);
const long long mxl = 1000000007;
template <class T>
inline void sarray(T* st, T* nd) {
while (st < nd) cin >> *st++;
}
template <class T>
inline void parray(T* st, T* nd) {
while (st < nd) cout << *st++ << endl;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int ar[n];
int odd = 0;
int even = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &ar[i]);
sum += ar[i];
if (ar[i] % 2) {
odd++;
} else {
even++;
}
}
if (sum % 2 || (odd > 0 && even > 0)) {
printf("YES");
printf("\n");
} else {
printf("NO");
printf("\n");
}
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double pie = 2 * acos(0.0);
const long long mxl = 1000000007;
template <class T>
inline void sarray(T* st, T* nd) {
while (st < nd) cin >> *st++;
}
template <class T>
inline void parray(T* st, T* nd) {
while (st < nd) cout << *st++ << endl;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int ar[n];
int odd = 0;
int even = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &ar[i]);
sum += ar[i];
if (ar[i] % 2) {
odd++;
} else {
even++;
}
}
if (sum % 2 || (odd > 0 && even > 0)) {
printf("YES");
printf("\n");
} else {
printf("NO");
printf("\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
int Case, n, a[2001];
int main(void) {
register int i, sum = 0;
scanf("%d", &Case);
while (Case--) {
scanf("%d", &n);
sum = 0;
for (i = 1; i <= n; ++i) scanf("%d", a + i), sum += a[i] & 1;
if (sum & 1 || (sum && sum ^ n))
puts("YES");
else
puts("NO");
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
int Case, n, a[2001];
int main(void) {
register int i, sum = 0;
scanf("%d", &Case);
while (Case--) {
scanf("%d", &n);
sum = 0;
for (i = 1; i <= n; ++i) scanf("%d", a + i), sum += a[i] & 1;
if (sum & 1 || (sum && sum ^ n))
puts("YES");
else
puts("NO");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[2005];
int main() {
int T;
scanf("%d", &T);
int n;
while (T--) {
int tag1 = 0, tag2 = 0;
scanf("%d", &n);
int sum = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum += a[i];
if (a[i] % 2 == 1) cnt++;
}
if (sum % 2 == 1 || cnt % 2 == 1) {
printf("YES\n");
continue;
}
for (int i = 1; i <= n; i++) {
if (a[i] % 2 == 0) {
if (tag2 == 1) {
printf("YES\n");
tag1 = 1;
break;
}
tag1 = 1;
}
if (a[i] % 2 == 1) {
if (tag1 == 1) {
printf("YES\n");
tag2 = 1;
break;
}
tag2 = 1;
}
}
if (tag1 != 1 || tag2 != 1) {
printf("NO\n");
}
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[2005];
int main() {
int T;
scanf("%d", &T);
int n;
while (T--) {
int tag1 = 0, tag2 = 0;
scanf("%d", &n);
int sum = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum += a[i];
if (a[i] % 2 == 1) cnt++;
}
if (sum % 2 == 1 || cnt % 2 == 1) {
printf("YES\n");
continue;
}
for (int i = 1; i <= n; i++) {
if (a[i] % 2 == 0) {
if (tag2 == 1) {
printf("YES\n");
tag1 = 1;
break;
}
tag1 = 1;
}
if (a[i] % 2 == 1) {
if (tag1 == 1) {
printf("YES\n");
tag2 = 1;
break;
}
tag2 = 1;
}
}
if (tag1 != 1 || tag2 != 1) {
printf("NO\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n;
int sum = 0, sumEven = 0, sumOdd = 0;
int array[n];
for (int i = 1; i <= n; i++) {
scanf("%d", &array[i]);
sum += array[i];
if (array[i] % 2 == 0) {
sumEven++;
} else {
sumOdd++;
}
}
if (sum % 2 == 1) {
cout << "YES"
<< "\n";
} else if (sumEven > 0 && sumOdd > 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
}
| ### Prompt
Develop a solution in cpp to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n;
int sum = 0, sumEven = 0, sumOdd = 0;
int array[n];
for (int i = 1; i <= n; i++) {
scanf("%d", &array[i]);
sum += array[i];
if (array[i] % 2 == 0) {
sumEven++;
} else {
sumOdd++;
}
}
if (sum % 2 == 1) {
cout << "YES"
<< "\n";
} else if (sumEven > 0 && sumOdd > 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
cin >> t;
while (t--) {
int n, nrp = 0, nri = 0;
cin >> n;
while (n--) {
int x;
cin >> x;
if (x % 2)
nri++;
else
nrp++;
}
if (nrp == 0)
if (nri % 2)
cout << "YES\n";
else
cout << "NO\n";
else if (nri)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
cin >> t;
while (t--) {
int n, nrp = 0, nri = 0;
cin >> n;
while (n--) {
int x;
cin >> x;
if (x % 2)
nri++;
else
nrp++;
}
if (nrp == 0)
if (nri % 2)
cout << "YES\n";
else
cout << "NO\n";
else if (nri)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int a[1000005];
bool isOdd(long long int arr[], long long int n) {
long long int l, r, flag = 0, flag1 = 0, sum = 0;
for (int i = 0; i < n; i++) {
sum += arr[i];
if (arr[i] % 2 == 0 && flag == 0) {
flag = 1;
l = arr[i];
}
if (arr[i] % 2 != 0 && flag1 == 0) {
r = arr[i];
flag1 = 1;
}
}
if (sum % 2 != 0) {
return true;
} else {
if (flag1 == 1 && flag == 1)
return true;
else
return false;
}
}
int main() {
long long int n;
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool res = isOdd(a, n);
if (res)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int a[1000005];
bool isOdd(long long int arr[], long long int n) {
long long int l, r, flag = 0, flag1 = 0, sum = 0;
for (int i = 0; i < n; i++) {
sum += arr[i];
if (arr[i] % 2 == 0 && flag == 0) {
flag = 1;
l = arr[i];
}
if (arr[i] % 2 != 0 && flag1 == 0) {
r = arr[i];
flag1 = 1;
}
}
if (sum % 2 != 0) {
return true;
} else {
if (flag1 == 1 && flag == 1)
return true;
else
return false;
}
}
int main() {
long long int n;
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool res = isOdd(a, n);
if (res)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
int cnt = 0;
int arr[x];
for (int j = 0; j < x; j++) {
cin >> arr[j];
if (arr[j] % 2 == 1) {
cnt++;
}
}
if (cnt == x && x % 2 == 0) {
cout << "NO" << endl;
} else if (cnt == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
int cnt = 0;
int arr[x];
for (int j = 0; j < x; j++) {
cin >> arr[j];
if (arr[j] % 2 == 1) {
cnt++;
}
}
if (cnt == x && x % 2 == 0) {
cout << "NO" << endl;
} else if (cnt == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int k = 0; k < t; k++) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int e = 0;
int o = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
e++;
} else {
o++;
}
}
if (o % 2 == 1) {
cout << "YES";
} else if (o == 0) {
cout << "NO";
} else if (o % 2 == 0 && e != 0) {
cout << "YES";
} else if (o % 2 == 0 && e == 0) {
cout << "NO";
}
cout << endl;
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int k = 0; k < t; k++) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int e = 0;
int o = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
e++;
} else {
o++;
}
}
if (o % 2 == 1) {
cout << "YES";
} else if (o == 0) {
cout << "NO";
} else if (o % 2 == 0 && e != 0) {
cout << "YES";
} else if (o % 2 == 0 && e == 0) {
cout << "NO";
}
cout << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n;
int sum = 0, sumEven = 0, sumOdd = 0;
int array[n];
for (int i = 1; i <= n; i++) {
scanf("%d", &array[i]);
sum += array[i];
if (array[i] % 2 == 0) {
sumEven++;
} else {
sumOdd++;
}
}
if (sum & 1) {
cout << "YES" << endl;
} else if (sumEven && sumOdd) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n;
int sum = 0, sumEven = 0, sumOdd = 0;
int array[n];
for (int i = 1; i <= n; i++) {
scanf("%d", &array[i]);
sum += array[i];
if (array[i] % 2 == 0) {
sumEven++;
} else {
sumOdd++;
}
}
if (sum & 1) {
cout << "YES" << endl;
} else if (sumEven && sumOdd) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
int i;
for (i = 0; i < t; i++) {
int n;
scanf("%d", &n);
int count = 0;
int counter = 0;
int j;
for (j = 0; j < n; j++) {
int temp;
scanf("%d", &temp);
if (temp % 2) {
count++;
} else {
counter++;
}
}
if (count && counter) {
printf("YES\n");
} else if (counter == 0 && count % 2 != 0) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return (0);
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
int i;
for (i = 0; i < t; i++) {
int n;
scanf("%d", &n);
int count = 0;
int counter = 0;
int j;
for (j = 0; j < n; j++) {
int temp;
scanf("%d", &temp);
if (temp % 2) {
count++;
} else {
counter++;
}
}
if (count && counter) {
printf("YES\n");
} else if (counter == 0 && count % 2 != 0) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return (0);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int T, N;
template <typename elemType>
inline void Read(elemType &T) {
elemType X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
T = (w ? -X : X);
}
int main() {
Read(T);
while (T--) {
Read(N);
bool Even = false, Odd = false;
for (register int i = 1; i <= N; ++i) {
int x;
Read(x);
if (x % 2)
Odd = true;
else
Even = true;
}
if (Odd && Even)
printf("YES\n");
else if (Even)
printf("NO\n");
else if (Odd) {
if (N % 2 == 0)
printf("NO\n");
else
printf("YES\n");
}
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int T, N;
template <typename elemType>
inline void Read(elemType &T) {
elemType X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
T = (w ? -X : X);
}
int main() {
Read(T);
while (T--) {
Read(N);
bool Even = false, Odd = false;
for (register int i = 1; i <= N; ++i) {
int x;
Read(x);
if (x % 2)
Odd = true;
else
Even = true;
}
if (Odd && Even)
printf("YES\n");
else if (Even)
printf("NO\n");
else if (Odd) {
if (N % 2 == 0)
printf("NO\n");
else
printf("YES\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, x = 0, y = 0, i, j, k;
cin >> n;
vector<long long> a(n);
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) {
if (a[i] % 2 == 0)
x++;
else
y++;
}
if (y % 2 != 0)
cout << "YES"
<< "\n";
else if (y % 2 == 0 && (y != 0 && x != 0))
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, x = 0, y = 0, i, j, k;
cin >> n;
vector<long long> a(n);
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) {
if (a[i] % 2 == 0)
x++;
else
y++;
}
if (y % 2 != 0)
cout << "YES"
<< "\n";
else if (y % 2 == 0 && (y != 0 && x != 0))
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[2000];
int i;
long long sum = 0;
int o = 0;
int e = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] % 2 == 0) e = 1;
if (a[i] % 2 != 0) o = 1;
}
if (sum % 2 != 0 || (o == 1 && e == 1))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[2000];
int i;
long long sum = 0;
int o = 0;
int e = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] % 2 == 0) e = 1;
if (a[i] % 2 != 0) o = 1;
}
if (sum % 2 != 0 || (o == 1 && e == 1))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double pi = 3.14159265358979323846;
const long long mxN = 2e5 + 1;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
void solve() {
bool odd = false, even = false;
long long n;
cin >> n;
vector<long long> a(n);
long long s = 0;
for (long long& x : a) {
cin >> x;
s += x;
if (x % 2)
odd = true;
else
even = true;
}
if (s % 2 == 1)
cout << "YES\n";
else if (odd && even)
cout << "YES\n";
else
cout << "NO\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double pi = 3.14159265358979323846;
const long long mxN = 2e5 + 1;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
void solve() {
bool odd = false, even = false;
long long n;
cin >> n;
vector<long long> a(n);
long long s = 0;
for (long long& x : a) {
cin >> x;
s += x;
if (x % 2)
odd = true;
else
even = true;
}
if (s % 2 == 1)
cout << "YES\n";
else if (odd && even)
cout << "YES\n";
else
cout << "NO\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mod = 1000000007;
const double dancila = 3.14159265359;
const double eps = 1e-9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (; t; --t) {
int n;
cin >> n;
bool imp = 0;
bool par = 0;
for (int i = 1; i <= n; ++i) {
int nr;
cin >> nr;
if (nr % 2 == 1)
imp = 1;
else
par = 1;
}
if (n % 2 == 1)
cout << (imp ? "YES" : "NO") << '\n';
else
cout << ((imp && par) ? "YES" : "NO") << '\n';
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mod = 1000000007;
const double dancila = 3.14159265359;
const double eps = 1e-9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (; t; --t) {
int n;
cin >> n;
bool imp = 0;
bool par = 0;
for (int i = 1; i <= n; ++i) {
int nr;
cin >> nr;
if (nr % 2 == 1)
imp = 1;
else
par = 1;
}
if (n % 2 == 1)
cout << (imp ? "YES" : "NO") << '\n';
else
cout << ((imp && par) ? "YES" : "NO") << '\n';
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int even = 0, odd = 0;
while (t > 0) {
t--;
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0) even = 1;
if (a[i] % 2 != 0) odd = 1;
}
if (n % 2 == 0) {
if (even == 0) {
cout << "NO" << endl;
} else if (even == 1 and odd == 1)
cout << "YES" << endl;
else if (odd == 0)
cout << "NO" << endl;
} else {
if (even == 1 and odd == 1)
cout << "YES" << endl;
else if (even == 0)
cout << "YES" << endl;
else if (even == 1 and odd == 0)
cout << "NO" << endl;
}
even = odd = 0;
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int even = 0, odd = 0;
while (t > 0) {
t--;
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0) even = 1;
if (a[i] % 2 != 0) odd = 1;
}
if (n % 2 == 0) {
if (even == 0) {
cout << "NO" << endl;
} else if (even == 1 and odd == 1)
cout << "YES" << endl;
else if (odd == 0)
cout << "NO" << endl;
} else {
if (even == 1 and odd == 1)
cout << "YES" << endl;
else if (even == 0)
cout << "YES" << endl;
else if (even == 1 and odd == 0)
cout << "NO" << endl;
}
even = odd = 0;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int A[2] = {0, 0};
int x;
for (int i = 0; i < n; i++) {
cin >> x;
A[x % 2] += 1;
}
if (A[1] == 0 || A[1] == n && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
| ### Prompt
Please formulate a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int A[2] = {0, 0};
int x;
for (int i = 0; i < n; i++) {
cin >> x;
A[x % 2] += 1;
}
if (A[1] == 0 || A[1] == n && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, ev = 0;
for (int i = 0, num; i < n; i++) {
cin >> num;
if (num % 2 == 0) {
ev++;
} else {
odd++;
}
}
if (odd == 0) {
cout << "NO";
} else {
if (ev == 0 && odd % 2 == 0) {
cout << "NO";
} else {
cout << "YES";
}
}
cout << '\n';
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, ev = 0;
for (int i = 0, num; i < n; i++) {
cin >> num;
if (num % 2 == 0) {
ev++;
} else {
odd++;
}
}
if (odd == 0) {
cout << "NO";
} else {
if (ev == 0 && odd % 2 == 0) {
cout << "NO";
} else {
cout << "YES";
}
}
cout << '\n';
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool odd, even;
int sum;
int in;
int n;
int T;
cin >> T;
while (T--) {
cin >> n;
odd = 0;
even = 0;
sum = 0;
for (int i = 0; i < n; i++) {
cin >> in;
sum += in % 2;
if (in % 2 == 1) {
odd = 1;
} else {
even = 1;
}
}
sum %= 2;
if (sum == 1) {
cout << "YES" << endl;
} else {
if (odd == 1 and even == 1) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
bool odd, even;
int sum;
int in;
int n;
int T;
cin >> T;
while (T--) {
cin >> n;
odd = 0;
even = 0;
sum = 0;
for (int i = 0; i < n; i++) {
cin >> in;
sum += in % 2;
if (in % 2 == 1) {
odd = 1;
} else {
even = 1;
}
}
sum %= 2;
if (sum == 1) {
cout << "YES" << endl;
} else {
if (odd == 1 and even == 1) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
start:
while (t--) {
int n;
cin >> n;
int sum = 0;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((sum - a[i] + a[j]) % 2 != 0) {
cout << "YES" << endl;
count++;
goto start;
}
}
}
if (count == 0) {
cout << "NO" << endl;
}
count = 0;
sum = 0;
}
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
start:
while (t--) {
int n;
cin >> n;
int sum = 0;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((sum - a[i] + a[j]) % 2 != 0) {
cout << "YES" << endl;
count++;
goto start;
}
}
}
if (count == 0) {
cout << "NO" << endl;
}
count = 0;
sum = 0;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int long long n;
cin >> n;
int a[n];
int even = 0, odd = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
even++;
else
odd++;
}
if (odd % 2 != 0)
cout << "YES" << endl;
else {
if (even > 0 && odd > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int long long n;
cin >> n;
int a[n];
int even = 0, odd = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
even++;
else
odd++;
}
if (odd % 2 != 0)
cout << "YES" << endl;
else {
if (even > 0 && odd > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int num;
cin >> num;
int arr[num + 1];
int count = 0;
int odd = 0;
for (int i = 0; i < num; i++) {
cin >> arr[i];
count += arr[i];
if (arr[i] % 2 != 0) odd++;
}
if (count % 2 != 0)
cout << "Yes" << endl;
else if (odd == num && num % 2 == 0)
cout << "NO" << endl;
else if (count % 2 == 0 && odd >= 2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main() {
int tt;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
int num;
cin >> num;
int arr[num + 1];
int count = 0;
int odd = 0;
for (int i = 0; i < num; i++) {
cin >> arr[i];
count += arr[i];
if (arr[i] % 2 != 0) odd++;
}
if (count % 2 != 0)
cout << "Yes" << endl;
else if (odd == num && num % 2 == 0)
cout << "NO" << endl;
else if (count % 2 == 0 && odd >= 2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main() {
int tt;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 1;
const int INF = 2e9 + 1;
const int MOD = (1e9 + 7);
void bye(string s = "") {
cout << s << '\n';
exit(0);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> arr(2);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
arr[a % 2]++;
}
if (arr[1] % 2 || (arr[1] && arr[0])) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
bye();
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 1;
const int INF = 2e9 + 1;
const int MOD = (1e9 + 7);
void bye(string s = "") {
cout << s << '\n';
exit(0);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> arr(2);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
arr[a % 2]++;
}
if (arr[1] % 2 || (arr[1] && arr[0])) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
bye();
}
``` |
#include <bits/stdc++.h>
int dx4[] = {0, 0, -1, 1};
int dy4[] = {-1, 1, 0, 0};
bool valid(int r, int c, int x, int y) {
if (x >= 1 && x <= r && y >= 1 && y <= c) return 1;
return 0;
}
using namespace std;
int main() {
int t;
cin >> t;
for (int cs = 1; cs <= t; cs++) {
int n;
cin >> n;
int a[n + 2];
int flag = 0;
int tot = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] % 2 == 1)
flag++;
else
tot++;
}
if (tot == n) {
cout << "NO" << endl;
} else {
if (flag == n && flag % 2 == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
int dx4[] = {0, 0, -1, 1};
int dy4[] = {-1, 1, 0, 0};
bool valid(int r, int c, int x, int y) {
if (x >= 1 && x <= r && y >= 1 && y <= c) return 1;
return 0;
}
using namespace std;
int main() {
int t;
cin >> t;
for (int cs = 1; cs <= t; cs++) {
int n;
cin >> n;
int a[n + 2];
int flag = 0;
int tot = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] % 2 == 1)
flag++;
else
tot++;
}
if (tot == n) {
cout << "NO" << endl;
} else {
if (flag == n && flag % 2 == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " = " << arg1;
ZZ(comma, args...);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long testcases;
cin >> testcases;
for (long long TC = (1); TC < (testcases + 1); TC++) {
long long n;
cin >> n;
bool odd = 0, even = 0;
long long sum = 0;
for (long long i = (0); i < (n); i++) {
long long x;
cin >> x;
if (x & 1)
odd = 1;
else
even = 1;
sum += x;
}
if ((sum & 1) || (odd && (n & 1)) || (n % 2 == 0 && odd && even))
cout << "YES";
else
cout << "NO";
cout << "\n";
}
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " = " << arg1;
ZZ(comma, args...);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long testcases;
cin >> testcases;
for (long long TC = (1); TC < (testcases + 1); TC++) {
long long n;
cin >> n;
bool odd = 0, even = 0;
long long sum = 0;
for (long long i = (0); i < (n); i++) {
long long x;
cin >> x;
if (x & 1)
odd = 1;
else
even = 1;
sum += x;
}
if ((sum & 1) || (odd && (n & 1)) || (n % 2 == 0 && odd && even))
cout << "YES";
else
cout << "NO";
cout << "\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int z = 0; z < t; z++) {
int n;
cin >> n;
int odd = 0, even = 0;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2 == 0) {
even++;
} else {
odd++;
}
}
if (odd == 0) {
cout << "NO" << endl;
} else if (odd == n && n % 2 == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int z = 0; z < t; z++) {
int n;
cin >> n;
int odd = 0, even = 0;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2 == 0) {
even++;
} else {
odd++;
}
}
if (odd == 0) {
cout << "NO" << endl;
} else if (odd == n && n % 2 == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int o = 0, e = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x % 2)
o++;
else
e++;
}
if (o) {
if (o == n) {
if (n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
} else
cout << "YES\n";
} else
cout << "NO\n";
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int o = 0, e = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x % 2)
o++;
else
e++;
}
if (o) {
if (o == n) {
if (n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
} else
cout << "YES\n";
} else
cout << "NO\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, sum = 0;
int count_even = 0, count_odd = 0;
for (int i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 0)
count_even++;
else
count_odd++;
sum += a;
}
if (sum % 2) {
cout << "YES\n";
} else {
if (count_even == 0 || count_odd == 0) {
if (count_even == 0) {
if (n % 2)
cout << "YES\n";
else
cout << "NO\n";
} else
cout << "NO\n";
} else
cout << "YES\n";
}
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, sum = 0;
int count_even = 0, count_odd = 0;
for (int i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 0)
count_even++;
else
count_odd++;
sum += a;
}
if (sum % 2) {
cout << "YES\n";
} else {
if (count_even == 0 || count_odd == 0) {
if (count_even == 0) {
if (n % 2)
cout << "YES\n";
else
cout << "NO\n";
} else
cout << "NO\n";
} else
cout << "YES\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int c = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 1) c++;
}
if (c == 0)
cout << "NO\n";
else if (c > 0) {
if (c == n && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int c = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 1) c++;
}
if (c == 0)
cout << "NO\n";
else if (c > 0) {
if (c == n && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
}
``` |
#include <bits/stdc++.h>
int main() {
int i, j, t, n, a[20000], counto, counte;
scanf("%d", &t);
for (i = 1; i <= t; i++) {
counto = 0, counte = 0;
scanf("%d", &n);
for (j = 0; j < n; j++) {
scanf("%d", &a[j]);
if (a[j] % 2 == 0)
counte++;
else
counto++;
}
if (counto == n && n % 2 == 0 || counte == n)
printf("NO");
else
printf("YES");
if (i != t) printf("\n");
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int i, j, t, n, a[20000], counto, counte;
scanf("%d", &t);
for (i = 1; i <= t; i++) {
counto = 0, counte = 0;
scanf("%d", &n);
for (j = 0; j < n; j++) {
scanf("%d", &a[j]);
if (a[j] % 2 == 0)
counte++;
else
counto++;
}
if (counto == n && n % 2 == 0 || counte == n)
printf("NO");
else
printf("YES");
if (i != t) printf("\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9) + 15;
long long time() {
return chrono::system_clock().now().time_since_epoch().count();
}
mt19937 rnd(time());
const double PI = acos(-1);
const double PPI = 2 * PI;
const int base = (1000 * 1000 * 1000);
void solve() {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int it;
cin >> it;
if (it % 2 == 0)
even++;
else
odd++;
}
if (n % 2 == 0 && odd == n) {
cout << "NO\n";
return;
} else if (odd == 0) {
cout << "NO\n";
return;
} else if (odd >= 1 && even >= 1) {
cout << "YES\n";
return;
} else if (n % 2 && odd == n) {
cout << "YES\n";
return;
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
| ### Prompt
Generate a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9) + 15;
long long time() {
return chrono::system_clock().now().time_since_epoch().count();
}
mt19937 rnd(time());
const double PI = acos(-1);
const double PPI = 2 * PI;
const int base = (1000 * 1000 * 1000);
void solve() {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int it;
cin >> it;
if (it % 2 == 0)
even++;
else
odd++;
}
if (n % 2 == 0 && odd == n) {
cout << "NO\n";
return;
} else if (odd == 0) {
cout << "NO\n";
return;
} else if (odd >= 1 && even >= 1) {
cout << "YES\n";
return;
} else if (n % 2 && odd == n) {
cout << "YES\n";
return;
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
int v, cnt;
scanf("%d", &t);
while (t--) {
cnt = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &v);
if (v % 2 == 1) {
cnt++;
}
}
if (cnt > 0 && (cnt < n || n % 2 == 1)) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
int v, cnt;
scanf("%d", &t);
while (t--) {
cnt = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &v);
if (v % 2 == 1) {
cnt++;
}
}
if (cnt > 0 && (cnt < n || n % 2 == 1)) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tests;
cin >> tests;
string ans[tests];
for (int i = 0; i < tests; i++) {
int n;
int sum = 0;
cin >> n;
int arr[n];
int odd = 0;
for (int j = 0; j < n; j++) {
cin >> arr[j];
if (arr[j] & 1) odd++;
sum += arr[j];
}
if (sum % 2 != 0)
ans[i] = "YES";
else if ((n - odd > 0 && odd > 0) || odd & 1)
ans[i] = "YES";
else
ans[i] = "NO";
}
for (int k = 0; k < tests; k++) {
cout << ans[k] << endl;
}
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int tests;
cin >> tests;
string ans[tests];
for (int i = 0; i < tests; i++) {
int n;
int sum = 0;
cin >> n;
int arr[n];
int odd = 0;
for (int j = 0; j < n; j++) {
cin >> arr[j];
if (arr[j] & 1) odd++;
sum += arr[j];
}
if (sum % 2 != 0)
ans[i] = "YES";
else if ((n - odd > 0 && odd > 0) || odd & 1)
ans[i] = "YES";
else
ans[i] = "NO";
}
for (int k = 0; k < tests; k++) {
cout << ans[k] << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, a, sum;
cin >> t;
while (t--) {
cin >> n;
sum = 0;
bool flag = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
sum += a % 2;
}
if (sum > 0 && sum < n || sum % 2 == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, a, sum;
cin >> t;
while (t--) {
cin >> n;
sum = 0;
bool flag = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
sum += a % 2;
}
if (sum > 0 && sum < n || sum % 2 == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool e = false, o = false;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (temp % 2 == 0)
e = true;
else
o = true;
}
if (e && !o)
cout << "NO" << endl;
else if (o && !e)
if (n % 2 == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool e = false, o = false;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (temp % 2 == 0)
e = true;
else
o = true;
}
if (e && !o)
cout << "NO" << endl;
else if (o && !e)
if (n % 2 == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
long long sum = 0;
for (auto &i : a) {
cin >> i;
sum += i;
}
if (sum % 2 == 1)
cout << "YES";
else {
long long ctr1 = 0, ctr2 = 0;
for (long long i = 0; i < n; i++) {
if (a[i] % 2 == 1)
ctr1++;
else
ctr2++;
}
if (ctr1 > 0 && ctr2 > 0)
cout << "YES";
else
cout << "NO";
}
cout << '\n';
}
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
long long sum = 0;
for (auto &i : a) {
cin >> i;
sum += i;
}
if (sum % 2 == 1)
cout << "YES";
else {
long long ctr1 = 0, ctr2 = 0;
for (long long i = 0; i < n; i++) {
if (a[i] % 2 == 1)
ctr1++;
else
ctr2++;
}
if (ctr1 > 0 && ctr2 > 0)
cout << "YES";
else
cout << "NO";
}
cout << '\n';
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 != 0) sum++;
}
if (sum != 0 && (n % 2 != 0 || (n % 2 == 0 && sum != n)))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 != 0) sum++;
}
if (sum != 0 && (n % 2 != 0 || (n % 2 == 0 && sum != n)))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.