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]; lo...
### 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 con...
#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++; ...
### 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 op...
#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 in...
### 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 differe...
#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;...
### 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 differe...
#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) |...
### 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 opera...
#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++; els...
### 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 differe...
#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...
### 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 ...
#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,...
### 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 ...
#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...
### 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 d...
#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 <...
### 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 opera...
#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...
### 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 opera...
#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 += ...
### 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 d...
#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 = ...
### 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 differe...
#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) { ...
### 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 ...
#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)...
### 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 differe...
#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_od...
### 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 differe...
#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) { ...
### 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 op...
#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[...
### 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 differe...
#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...); } usin...
### 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 differe...
#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; f...
### 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 ...
#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;...
### 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 d...
#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++) { ...
### 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 ...
#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++) { ...
### 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 differe...
#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 ...
### 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 differe...
#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;...
### 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 ...
#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; }...
### 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 ...
#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" <...
### 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 ...
#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++; } } ...
### 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 differe...
#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 ...
### 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 ...
#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"; el...
### 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 opera...
#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 +...
### 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 ...
#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...
### 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 differe...
#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...
### 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 ...
#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 << "N...
### 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 ...
#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 (a...
### 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 ...
#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) { retur...
### 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 differe...
#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++; ...
### 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 ...
#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 i...
### 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 d...
#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...
### 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 ...
#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...
### 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 ...
#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; } ...
### 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 differe...
#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...
### 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 ...
#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++; ...
### 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 ope...
#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) { od...
### 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 ...
#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 >>...
### 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 ...
#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) fla...
### 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 ...
#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 != ...
### 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 ...
#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 { has...
### 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 ...
#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 ma...
### 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 d...
#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++; } ...
### 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 ...
#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 = r...
### 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 ...
#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++) { i...
### 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 ...
#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); s...
### 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 ope...
#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 ...
### 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 differe...
#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 ...
### 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 opera...
#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...
### 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 d...
#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 ==...
### 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 differe...
#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 ...
### 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 ...
#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 wr...
### 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 ...
#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 = ...
### 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 ope...
#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 *...
### 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 differe...
#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" ...
### 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 ...
#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; ...
### 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 differe...
#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;...
### 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 ...
#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"); } ...
### 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 d...
#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++; } ...
### 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 differe...
#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) { sumEv...
### 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 differe...
#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...
### 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 ...
#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]...
### 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 differe...
#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) { ...
### 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 ...
#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++; ...
### 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 ...
#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) { sumEv...
### 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 differe...
#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 { ...
### 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 ...
#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);...
### 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 d...
#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++; } ...
### 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 differe...
#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...
### 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 ...
#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, cl...
### 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 differe...
#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; boo...
### 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 ope...
#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) {...
### 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 op...
#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 ...
### 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 differe...
#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++; ...
### 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 ope...
#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; } ...
### 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 op...
#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...
### 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 ...
#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) ...
### 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 ...
#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 &...
### 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 ...
#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; ...
### 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 ...
#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]...
### 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 ...
#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...
### 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 ...
#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++; } ...
### 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 differe...
#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...
### 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 opera...
#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...
### 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 differe...
#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...
### 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 d...
#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 ...
### 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 op...
#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...
### 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 opera...
#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)) { prin...
### 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 ope...
#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...
### 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 differe...
#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 ...
### 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 ...
#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) ...
### 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 differe...
#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 ...
### 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 op...
#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" << ...
### 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 op...