text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
long long poww(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
using namespace std;
const int maxn = 1000 * 100 + 5;
const long long inf = 9223372036854775807;
const long long mod = 1e9 + 7;
const long long Log = 22;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
int mark[1001];
memset(mark, 0, sizeof mark);
int n, m, ans = -1;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
mark[x] = 1;
}
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
if (mark[x]) {
ans = x;
}
}
if (ans != -1) {
cout << "YES" << endl << 1 << ' ' << ans << endl;
} else
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long me(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
long long a[n];
unordered_map<long long, long long> hash;
unordered_map<long long, long long> hash1;
for (long long i = 0; i < n; i++) {
cin >> a[i];
hash[a[i]]++;
}
long long b[m];
for (long long i = 0; i < m; i++) {
cin >> b[i];
hash1[b[i]]++;
}
for (auto it = hash.begin(); it != hash.end(); it++) {
if (it->second >= 1 && hash1[it->first] >= 1) {
cout << "YES\n" << 1 << " " << it->first << endl;
return;
}
}
cout << "NO\n";
}
int main() {
c_p_c();
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
long long a[n], b[m];
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < m; i++) cin >> b[i];
long long flag = 0, ans{0};
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < m; j++) {
if (a[i] == b[j]) {
flag = 1;
ans = a[i];
break;
}
}
}
if (flag != 1)
cout << "NO" << endl;
else
cout << "YES" << endl
<< "1"
<< " " << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
long long _, n, m, a[N], b[N], tag;
void solve() {
cin >> n >> m;
tag = 0;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) {
cin >> b[i];
for (int j = 0; j < n; ++j) {
if (a[j] == b[i]) tag = a[j];
}
}
if (!tag)
cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << 1 << " " << tag << endl;
}
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _;
while (_--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, x = 0, y;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j]) {
x = a[i];
break;
}
}
}
if (x) {
cout << "YES"
<< "\n";
cout << 1 << " " << x << endl;
} else {
cout << "NO" << endl;
}
}
}
|
#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
int t;
int a[1005], b[1005];
bool c[1005];
int main() {
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d%d", &n, &m);
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), c[a[i]] = 1;
int ans = -1;
for (int j = 1; j <= m; j++) {
scanf("%d", &b[j]);
if (c[b[j]]) {
ans = b[j];
}
}
if (ans != -1) {
puts("YES");
printf("1 %d\n", ans);
} else {
puts("NO");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[1006], B[1006];
void solve() {
unordered_map<int, int> mp;
for (int i = 1; i <= n; i++) mp[A[i]]++;
for (int i = 1; i <= m; i++) {
if (mp[B[i]] != 0) {
cout << "YES\n";
cout << 1 << " " << B[i] << "\n";
return;
}
}
cout << "NO\n";
}
int main() {
int t;
cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> A[i];
for (int i = 1; i <= m; i++) cin >> B[i];
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, m, n, ans;
cin >> t;
while (t--) {
ans = 0;
cin >> m >> n;
set<long long int> s;
long long int a[m];
long long int b[n];
for (long long int i = 0; i < m; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (long long int i = 0; i < n; i++) {
cin >> b[i];
}
for (long long int i = 0; i < n; i++) {
if (s.find(b[i]) != s.end()) {
ans = b[i];
break;
}
}
if (ans == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl << 1 << " " << ans << endl;
}
}
return 0;
}
|
#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, m;
cin >> n >> m;
int a[n];
vector<int> v;
int b[m];
int g[1005] = {0};
int h[1005] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
g[a[i]]++;
}
for (int i = 0; i < m; i++) {
cin >> b[i];
h[b[i]]++;
}
int ct = 0;
for (int i = 0; i < 1005; i++) {
if (g[i] > 0 && h[i] > 0) {
ct++;
v.push_back(i);
}
}
if (ct == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
if (ct == 1) {
cout << ct << " ";
cout << v[0] << endl;
} else {
cout << "1"
<< " ";
cout << v[0] << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int local;
void solve() {
int n, m;
cin >> n >> m;
vector<int> ar1(n), ar2(m);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
ar1[i] = x;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
ar2[i] = x;
}
int ct = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (ar1[i] == ar2[j]) {
cout << "YES" << endl;
cout << 1 << " " << ar1[i] << endl;
return;
}
}
}
cout << "NO" << endl;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
local = 1;
if (local) {
int tc;
cin >> tc;
while (tc--) solve();
} else
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int ans = -1;
int n, m, x;
cin >> n >> m;
set<int> S;
for (int i = 0; i < n; i++) {
cin >> x;
S.insert(x);
}
for (int i = 0; i < m; i++) {
cin >> x;
if (S.count(x)) ans = x;
}
if (ans != -1)
cout << "YES\n1 " << ans << endl;
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void dekhao(T val) {
cout << "template val is == " << val << endl;
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) os << ", ";
os << *it;
}
return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
typename set<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
typename map<F, S>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
void Ekfile() {
freopen("A1.in", "r", stdin);
freopen("A1.out", "w", stdout);
}
int Tcase;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> Tcase;
while (Tcase--) {
long long int n, m, a[1100], b[1100];
map<int, int> amap, bmap;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
amap[a[i]]++;
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
bmap[b[i]]++;
}
int flag = 0, elem = -1;
for (int i = 1; i <= m; i++) {
if (amap[b[i]] >= 1) {
flag = 1;
elem = b[i];
break;
}
}
if (flag) {
cout << "YES" << endl;
cout << 1 << ' ' << elem << endl;
} else
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long PI = acosl(-1.0);
const long long xx = 1e6;
pair<pair<int, int>, pair<int, int>> arr[xx] = {};
int n;
long long a[xx] = {};
set<long long> s;
long long ps[xx] = {};
void buildbst(int begin, int end, long long small, long long big, int pos) {
if (begin > end) return;
if (begin == end) {
s.insert(a[begin]);
return;
}
if (small == big) {
s.insert(ps[end] - ps[begin - 1]);
return;
}
long long mid = (small + big) / 2;
long long po = upper_bound(a, a + n + 1, mid) - a;
s.insert(ps[end] - ps[begin - 1]);
buildbst(begin, po - 1, small, a[po - 1], 2 * pos);
buildbst(po, end, a[po], big, 2 * pos + 1);
}
void solve() {
int n, m;
cin >> n >> m;
int a[1001] = {};
int b[1001] = {};
int t;
for (long long i = 0; i < n; i++) {
cin >> t;
a[t]++;
}
for (long long i = 0; i < m; i++) {
cin >> t;
b[t]++;
}
for (long long i = 0; i < 1001; i++) {
if (a[i] > 0 && b[i] > 0) {
cout << "YES"
<< "\n";
cout << 1 << " " << i << "\n";
return;
}
}
cout << "NO"
<< "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
for (long long i = 0; i < t; i++) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 2 * 1e5 + 4;
long long add(long long a, long long b, long long m) {
if (a < 0) a += m;
if (b < 0) b += m;
long long res = ((a % m) + (b % m)) % m;
res %= m;
return res;
}
long long mul(long long a, long long b, long long m) {
if (a < 0) a += m;
if (b < 0) b += m;
long long res = ((a % m) * (b % m)) % m;
res %= m;
return res;
}
long long sub(long long a, long long b, long long m) {
long long res = (a - b + m) % m;
res %= m;
return res;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
vector<long long> a(1001, 0), b(m);
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
a[x] = 1;
}
for (long long i = 0; i < m; i++) {
cin >> b[i];
}
for (auto x : b) {
if (a[x] == 1) {
cout << "YES\n";
cout << "1 " << x << '\n';
goto yaha;
}
}
cout << "NO\n";
yaha:;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int i, n, m, d = -1;
cin >> m >> n;
vector<int> a(m), b(n), c(10000, 0);
for (i = 0; i < m; i++) {
cin >> a[i];
c[a[i]]++;
}
for (i = 0; i < n; i++) {
cin >> b[i];
if (c[b[i]] > 0) {
d = b[i];
}
}
if (d != -1)
cout << "YES\n1 " << d << '\n';
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
vector<bool> was(1005, false);
int ans = 0;
for (int i = 0; i < n; ++i) cin >> a[i], was[a[i]] = true;
for (int i = 0; i < m; ++i) {
cin >> b[i];
if (was[b[i]]) {
ans = b[i];
}
}
if (!ans) {
cout << "NO\n";
continue;
}
cout << "YES\n";
cout << 1 << " " << ans << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, i, s, n, p, j, x, m;
cin >> t;
while (t--) {
cin >> n >> m;
map<long long, long long> a;
for (i = 1; i <= n; i++) {
cin >> x;
a[x]++;
}
p = 0;
for (j = 1; j <= m; j++) {
cin >> x;
if (a[x] > 0) p = x;
}
if (p == 0)
cout << "NO" << endl;
else
cout << "YES" << endl << 1 << " " << p << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
void printarray(long long arr[], long long n) {
for (long long i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return;
}
void printvector(vector<long long> v) {
for (long long i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
return;
}
void help() {
long long n, m;
cin >> n >> m;
long long a[n], b[m];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
for (long long j = 0; j < m; j++) {
cin >> b[j];
}
set<long long> s;
for (long long i = 0; i < n; i++) {
s.insert(a[i]);
}
for (long long i = 0; i < m; i++) {
if (s.find(b[i]) != s.end()) {
cout << "YES" << endl;
cout << "1 " << b[i] << endl;
return;
}
}
cout << "NO" << endl;
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
long long t;
cin >> t;
while (t--) {
help();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
int t, n, m;
int a[N + 2], b[N + 2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n >> m;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x]++;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
b[x]++;
}
int cnt = 0;
int ans = -1;
for (int i = 0; i <= N; i++) {
if (a[i] > 0 && b[i] > 0) {
ans = i;
break;
}
}
if (ans == -1)
cout << "NO\n";
else
cout << "YES\n1 " << ans << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt;
cin >> tt;
while (tt--) {
int m, n, k, flag = 0;
cin >> m >> n;
int ar[m + 1], arr[n + 1];
for (int i = 0; i < m; i++) cin >> ar[i];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (ar[i] == arr[j]) {
k = ar[i];
flag = 1;
break;
}
}
if (flag == 1) break;
}
if (flag == 0)
cout << "NO" << endl;
else
cout << "YES" << endl << 1 << " " << k << endl;
}
}
|
#include <bits/stdc++.h>
using i64 = long long;
const int maxn = 200000;
inline int Min(const int &x, const int &y) { return x < y ? x : y; }
inline int Max(const int &x, const int &y) { return x > y ? x : y; }
namespace IOManager {
constexpr int FILESZ = 131072;
char buf[FILESZ];
const char *ibuf = buf, *tbuf = buf;
struct IOManager {
inline char gc() {
return (ibuf == tbuf) and
(tbuf = (ibuf = buf) + fread(buf, 1, FILESZ, stdin),
ibuf == tbuf)
? EOF
: *ibuf++;
}
template <typename _Tp>
inline operator _Tp() {
_Tp s = 0u;
char c = gc();
for (; c < 48; c = gc())
;
for (; c > 47; c = gc()) s = (_Tp)(s * 10u + c - 48u);
return s;
}
};
} // namespace IOManager
IOManager::IOManager io;
int a[maxn + 1];
bool e[maxn + 1];
int main() {
for (int T = io; T; --T) {
const int n = io, m = io;
for (int i = 1; i <= n; ++i) e[a[i] = io] = true;
int ans = 0;
for (int i = 1; i <= m; ++i) {
const int b = io;
if (e[b]) ans = b;
}
if (ans == 0)
puts("NO");
else
printf("YES\n1 %d\n", ans);
for (int i = 1; i <= n; ++i) e[a[i]] = false;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
long long a[n], b[m];
for (long long i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < (int)(m); ++i) cin >> b[i];
map<long long, long long> mp;
for (int i = 0; i < (int)(n); ++i) mp[a[i]] = 1;
long long f = 0, in;
for (int i = 0; i < (int)(m); ++i) {
if (mp[b[i]]) {
f = 1;
in = i;
break;
}
}
if (f) {
cout << "YES\n";
cout << 1 << " " << b[in];
} else
cout << "NO";
cout << "\n";
}
return 0;
}
|
#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 n, m;
cin >> n >> m;
vector<int> a(n), b(m);
map<int, int> mp;
vector<int> sol;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]] = 1;
}
for (int j = 0; j < m; j++) {
cin >> b[j];
if (mp[b[j]] > 0) {
sol.push_back(b[j]);
}
}
if (sol.size() == 0)
cout << "NO\n";
else {
cout << "YES\n" << 1 << " " << sol[0] << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, m;
int a[1001], b[1001];
cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
vector<int> v;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j]) {
v.push_back(a[i]);
break;
}
}
if (v.size() == 1) {
break;
}
}
if (v.size() == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
cout << v.size() << " ";
for (int i = 0; i < v.size(); i++) {
cout << v[i] << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
int sum[N];
int main() {
int T;
scanf("%d", &T);
while (T--) {
memset(sum, 0, sizeof sum);
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= m; i++) scanf("%d", b + i);
for (int i = 1; i <= n; i++) sum[a[i]]++;
bool flag = true;
for (int i = 1; i <= m; i++) {
if (sum[b[i]]) {
puts("YES");
flag = false;
printf("1 %d\n", b[i]);
break;
}
}
if (flag) puts("NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
for (long long p = 1; p <= t; p++) {
long long n, m;
cin >> n >> m;
bool arr[1001];
memset(arr, false, sizeof(arr));
for (long long i = 1; i <= n; i++) {
long long angka;
cin >> angka;
arr[angka] = true;
}
bool jawaban = false;
long long containa = 0;
for (long long i = 1; i <= m; i++) {
long long angka;
cin >> angka;
if (arr[angka]) {
jawaban = true;
containa = angka;
}
}
if (jawaban) {
cout << "YES\n";
cout << "1 " << containa << "\n";
} else {
cout << "NO\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
cin >> T;
while (T--) {
int n, m, te, f = 0, ans;
cin >> n >> m;
map<int, int> ma;
for (int i = 0; i < n; i++) {
cin >> te;
if (ma[te] == 0) ma[te]++;
}
for (int i = 0; i < m; i++) {
cin >> te;
if (ma[te]) ma[te]++;
if (ma[te] >= 2 && !f) {
f = 1;
ans = te;
}
}
if (f) {
cout << "YES\n1 " << ans << "\n";
} else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int a[n], b[m], i, j, track = 0, flag = 0;
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 0; i < m; ++i) cin >> b[i];
sort(a, a + n);
sort(b, b + m);
for (i = 0; i < n; ++i) {
for (j = 0; j < m; ++j) {
if (a[i] == b[j]) {
track = b[j];
flag = 1;
break;
}
}
if (flag) break;
}
if (!flag)
cout << "NO\n";
else {
cout << "YES\n";
cout << "1 " << track << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int m, n;
cin >> m >> n;
int a[m];
for (int i = 0; i < m; i++) cin >> a[i];
int b[n];
for (int i = 0; i < n; i++) cin >> b[i];
unordered_set<int> s;
for (int i = 0; i < m; i++) s.insert(a[i]);
int flag = 1;
for (int i = 0; i < n; i++) {
if (s.find(b[i]) != s.end()) {
cout << "YES" << endl;
cout << 1 << " " << b[i] << endl;
flag = 0;
break;
}
}
if (flag == 1) cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
scanf("%lld", &t);
while (t--) {
long long n, m, x, ans = -1;
scanf("%lld%lld", &n, &m);
map<long long, long long> mp;
for (long long i = 0; i < n; i++) {
scanf("%lld", &x);
mp[x]++;
}
for (long long i = 0; i < m; i++) {
scanf("%lld", &x);
if (mp[x] > 0 && ans == -1) {
ans = x;
}
}
if (ans == -1) {
printf("NO\n");
} else {
printf("YES\n");
printf("1 %lld\n", ans);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m, i;
vector<long long int> v;
cin >> n >> m;
long long int a[n], b[m], c = 0, j, p;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + m);
if (m > n) {
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if (b[i] == a[j]) {
p = a[j];
c++;
break;
}
if (c != 0 && p != 1) break;
}
}
} else {
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (b[j] == a[i]) {
p = a[i];
c++;
break;
}
if (c != 0 && p != 1) break;
}
}
}
if (c != 0) {
cout << "YES" << endl;
cout << 1 << " " << p << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long N = 1e6 + 5;
void pairsort(long long a[], long long b[], long long n) {
pair<long long, long long> pairt[n];
for (long long i = 0; i < n; i++) {
pairt[i].first = a[i];
pairt[i].second = b[i];
}
sort(pairt, pairt + n);
for (long long i = 0; i < n; i++) {
a[i] = pairt[i].first;
b[i] = pairt[i].second;
}
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long isPrime(long long n) {
if (n < 2) return 0;
if (n < 4) return 1;
if (n % 2 == 0 or n % 3 == 0) return 0;
for (long long i = 5; i * i <= n; i += 6)
if (n % i == 0 or n % (i + 2) == 0) return 0;
return 1;
}
long long C(long long n, long long r) {
if (r > n - r) r = n - r;
long long ans = 1;
for (long long i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
long long mod = 1e9 + 7;
long long modexpo(long long x, long long p) {
long long res = 1;
x = x % mod;
while (p) {
if (p % 2) res = res * x;
p >>= 1;
x = x * x % mod;
res %= mod;
}
return res;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
long long a[n], b[m];
for (long long i = 0; i < n; ++i) {
cin >> a[i];
}
for (long long i = 0; i < m; ++i) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + m);
long long ans = -1;
long long i = 0, j = 0;
while (i < n and j < m) {
if (a[i] < b[j]) {
i++;
} else if (a[i] > b[j]) {
j++;
} else {
ans = i;
break;
}
}
if (ans == -1)
cout << "NO"
<< "\n";
else {
cout << "YES"
<< "\n";
cout << 1 << " " << a[i] << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int c[1005];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d%d", &n, &m);
int cnt = 0;
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (c[x] == 0) c[x] = 1;
}
for (int i = 1; i <= m; i++) {
int x;
scanf("%d", &x);
if (c[x] == 1) c[x] = 2, cnt++;
}
if (cnt == 0)
printf("NO\n");
else {
printf("YES\n");
for (int i = 1; i <= 1000; i++) {
if (c[i] == 2) {
printf("1 %d\n", i);
break;
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int t, n, m, k, x;
int main() {
cin >> t;
while (t--) {
k = -1;
map<int, int> a;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x;
a[x] = 1;
}
for (int i = 1; i <= m; i++) {
cin >> x;
if (a[x] == 1) k = x;
}
puts(k == -1 ? "NO" : "YES");
if (k != -1) cout << 1 << ' ' << k << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, number;
void solve() {
cin >> n >> m;
set<int> a;
int answer = -1;
for (int i = 0; i < n; i++) {
cin >> number;
a.emplace(number);
}
for (int i = 0; i < m; i++) {
cin >> number;
if (a.count(number) > 0) {
answer = number;
}
}
if (answer == -1) {
cout << "NO"
<< "\n";
} else {
cout << "YES"
<< "\n";
cout << 1 << " " << answer << "\n";
}
}
int main() {
int testCases;
cin >> testCases;
while (testCases--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535;
long long n, m;
const int mx = 69;
char grid[mx][mx];
long long blocked[mx][mx];
long long vis[mx][mx];
void FAST() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long power(long long a, long long b) {
long long res = 1;
for (int i = 1; i <= b; ++i) res *= a;
return res;
}
vector<long long> digit(long long n) {
long long arr[10000];
long long i = 0;
long long j, r;
vector<long long> v;
while (n != 0) {
r = n % 10;
arr[i] = r;
i++;
n = n / 10;
}
for (j = i - 1; j > -1; j--) {
v.push_back(arr[j]);
}
return v;
}
long long sum(long long x) {
long long ans = 0;
while (x > 0) {
ans += (x % 10);
x /= 10;
}
return ans;
}
bool opp(int x, int y) { return ((x ^ y) < 0); }
int main() {
FAST();
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
long long a[n], b[m];
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < m; i++) cin >> b[i];
long long ans, f = 0;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < m; j++) {
if (a[i] == b[j]) {
f = 1;
ans = a[i];
}
}
}
if (f == 1) {
cout << "YES" << '\n';
cout << 1 << ' ';
cout << ans << '\n';
} else
cout << "NO" << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int tc;
cin >> tc;
while (tc--) {
long long int n, m;
cin >> n >> m;
long long int i, j, flg = 1;
vector<long long int> a, b;
for (i = 0; i < n; i++) {
long long int k;
cin >> k;
a.push_back(k);
}
for (i = 0; i < m; i++) {
long long int k;
cin >> k;
b.push_back(k);
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a[i] == b[j]) {
flg = 0;
break;
}
}
if (flg == 0) break;
}
if (flg == 1)
cout << "NO"
<< "\n";
else
cout << "YES"
<< "\n"
<< 1 << " " << a[i] << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int n, m, T;
int a[MAXN], b[MAXN];
inline void Read(int &Ret) {
char ch;
bool flag = 0;
for (; ch = getchar(), !isdigit(ch);)
if (ch == '-') flag = 1;
for (Ret = ch - '0'; ch = getchar(), isdigit(ch); Ret = Ret * 10 + ch - '0')
;
flag && (Ret = -Ret);
}
int main() {
Read(T);
while (T--) {
Read(n);
Read(m);
for (int i = 1; i <= n; i++) Read(a[i]);
for (int i = 1; i <= m; i++) Read(b[i]);
bool flag = false;
int ans;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i] == b[j]) {
ans = a[i];
flag = true;
break;
}
}
if (flag) break;
}
if (flag) {
printf("YES\n1 %d\n", ans);
} else
printf("NO\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
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 x, y;
cin >> x >> y;
long long int b[y];
set<long long int> s;
for (long long int i = 0; i < x; i++) {
long long int g;
cin >> g;
s.insert(g);
}
long long int ans = -1;
for (long long int i = 0; i < y; i++) {
cin >> b[i];
auto it = s.find(b[i]);
if (it != s.end()) {
ans = b[i];
}
}
if (ans != -1) {
cout << "YES" << endl;
cout << 1 << " " << ans << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
long long int t;
cin >> t;
while (t--) {
map<long long int, long long int> m1;
long long int n, m;
cin >> n >> m;
long long int a[n], b[m], i;
for (i = 0; i < n; i++) {
cin >> a[i];
m1[a[i]] = 1;
}
for (i = 0; i < m; i++) {
cin >> b[i];
}
long long int flag = 0;
for (i = 0; i < m; i++) {
if (m1[b[i]] == 1) {
flag = 1;
cout << "YES\n";
cout << 1 << " " << b[i] << "\n";
break;
}
}
if (flag == 0) {
cout << "NO\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const char nl = '\n';
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m), c;
for (int i{}; i < n; i++) cin >> a[i];
for (int i{}; i < m; i++) cin >> b[i];
if (n <= m) {
for (int i{}; i < n; i++) {
if (b.end() != find(b.begin(), b.end(), a[i])) {
c.push_back(a[i]);
break;
}
}
} else {
for (int i{}; i < m; i++) {
if (a.end() != find(a.begin(), a.end(), b[i])) {
c.push_back(b[i]);
break;
}
}
}
if (c.size() != 0) {
cout << "YES"
<< "\n";
cout << c.size() << " " << c[0] << "\n";
} else {
cout << "NO"
<< "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
long long int a[n], b[m];
map<int, int> make_pair;
set<int> mp1, mp2;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
mp1.insert(a[i]);
make_pair[a[i]]++;
}
for (long long int i = 0; i < m; i++) {
cin >> b[i];
make_pair[b[i]]++;
mp2.insert(b[i]);
}
long long int flag = 0;
for (auto i : make_pair) {
if (i.second > 1 && mp1.find(i.first) != mp1.end() &&
mp2.find(i.first) != mp2.end()) {
flag = 1;
cout << "YES\n";
cout << "1"
<< " " << i.first << "\n";
break;
}
}
if (!flag) cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
vector<int> v1;
vector<int> v2;
while (t--) {
int n, m;
cin >> n >> m;
for (int i = 0; i <= n - 1; i++) {
int ch;
cin >> ch;
v1.push_back(ch);
}
for (int j = 0; j <= m - 1; j++) {
int ch2;
cin >> ch2;
v2.push_back(ch2);
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
vector<int> v(v1.size() + v2.size());
vector<int>::iterator it, st;
it =
set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), v.begin());
int k = v.size();
if ((k == (v1.size() + v2.size())) && (v[0] == 0) && (v[k - 1] == 0)) {
cout << "NO"
<< "\n";
} else {
cout << "YES"
<< "\n"
<< 1 << " " << v[0] << "\n";
}
v1.clear();
v2.clear();
v.clear();
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int binexp(long long int a, long long int b) {
long long int ans = 1;
while (b > 0) {
if (b & 1) ans = ans * a;
a = a * a;
}
return ans;
}
long long int modexp(long long int a, long long int b, long long int m) {
long long int ans = 1;
while (b > 0) {
if (b & 1) {
ans = ans * a % m;
}
a = a * a % m;
}
return ans % m;
}
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
unordered_map<int, int> make_pair;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
make_pair[x]++;
}
int ans = -1;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
if (make_pair[x] != 0) ans = x;
}
if (ans == -1)
cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << 1 << " " << ans << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n1, n2;
cin >> t;
while (t--) {
cin >> n1 >> n2;
int ar1[n1], ar2[n2], c = 0;
for (int i = 0; i < n1; i++) {
cin >> ar1[i];
}
for (int i = 0; i < n2; i++) {
cin >> ar2[i];
}
for (int i = 0; i < n2; i++) {
for (int j = 0; j < n1; j++) {
if (ar2[i] == ar1[j]) {
c = ar1[j];
break;
}
}
if (c != 0) break;
}
if (c != 0) {
cout << "YES" << endl;
cout << 1 << " " << c << endl;
} else {
cout << "NO" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30000 + 20, MAXM = 2 * 100000 + 10,
MOD = 1000 * 1000 * 1000 + 7, INF = 1000 * 1000 * 1000;
int a[MAXN], b[MAXN];
void solve() {
int n, m;
cin >> n >> m;
for (int i = 0; i <= 1000; i++) a[i] = 0;
for (int i = 0, x; i < n; i++) {
cin >> x;
a[x]++;
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < m; i++)
if (a[b[i]]) {
cout << "YES" << endl;
cout << 1 << " " << b[i] << endl;
return;
}
cout << "NO" << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, i, n, m, j, a;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
vector<long long> a, b, c;
long long g, h;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> g;
a.push_back(g);
}
for (i = 0; i < m; i++) {
cin >> h;
b.push_back(h);
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a[i] == b[j]) {
c.push_back(a[i]);
break;
}
}
}
if (c.size() >= 1) {
cout << "YES" << '\n';
cout << 1 << " " << c[0] << '\n';
;
cout << '\n';
} else {
cout << "NO" << '\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, l1, l2, result, element;
cin >> t;
for (int i = 0; i < t; i++) {
int a[1000], b[1000];
result = 0;
cin >> l1 >> l2;
for (int j = 0; j < l1; j++) {
cin >> a[j];
}
for (int k = 0; k < l2; k++) {
cin >> b[k];
}
for (int x = 0; x < l2; x++) {
for (int m = 0; m < l1; m++) {
if (a[m] == b[x]) {
result = 1;
element = a[m];
break;
}
}
if (result == 1) {
break;
}
}
if (result == 1) {
cout << "YES" << endl;
cout << "1"
<< " " << element << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void test() {
int n, j;
cin >> n >> j;
map<int, int> m;
map<int, int> m2;
vector<int> a(n), b(j);
int in;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
}
for (int i = 0; i < j; i++) {
cin >> b[i];
}
int flag = 0;
for (int i = 0; i < j; i++) {
if (m[b[i]] > 0) {
cout << "YES\n1 " << b[i] << "\n";
flag = 1;
break;
}
}
if (flag == 0) {
cout << "NO"
<< "\n";
}
}
int main() {
int t;
cin >> t;
while (t--) {
test();
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j]) {
cout << "YES\n1 " << a[i] << '\n';
return;
}
}
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
long long int arr1[n];
long long int arr2[m];
for (long long int i = 0; i < n; i++) {
cin >> arr1[i];
}
for (long long int i = 0; i < m; i++) {
cin >> arr2[i];
}
set<long long int> st;
for (long long int i = 0; i < n; i++) {
st.insert(arr1[i]);
}
long long int flag = 0, v;
for (long long int i = 0; i < m; i++) {
if (st.find(arr2[i]) != st.end()) {
flag = 1;
v = arr2[i];
break;
}
}
if (flag == 1) {
cout << "YES" << endl;
cout << 1 << " " << v << endl;
} else {
cout << "NO" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int n, long long int p) {
long long int result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result % p * x % p) % p;
x = (x % p * x % p) % p;
n = n / 2;
}
return result % p;
}
void solve() {
long long int n, m;
cin >> n >> m;
vector<long long int> cnt(1005);
for (long long int i = 0; i <= n - 1; i++) {
long long int a1;
cin >> a1;
cnt[a1] = 1;
}
for (long long int i = 0; i <= m - 1; i++) {
long long int a2;
cin >> a2;
if (cnt[a2] == 1) cnt[a2]++;
}
for (long long int i = 1; i <= 1000; i++) {
if (cnt[i] >= 2) {
cout << "YES" << endl;
cout << "1 " << i << endl;
return;
}
}
cout << "NO" << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t = 1;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<int> b(m);
map<int, int> m1;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
m1[x]++;
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (auto i : b) {
if (m1[i]) {
cout << "YES\n";
cout << 1 << " " << i << "\n";
return;
}
}
cout << "NO\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int _;
cin >> _;
while (_--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int b[m];
for (int i = 0; i < m; i++) cin >> b[i];
int check = 0;
for (int i = 0; i < n; i++) {
if (check == 1) break;
for (int j = 0; j < m; j++)
if (a[i] == b[j]) {
cout << "YES" << endl;
cout << 1 << " " << b[j] << endl;
check = 1;
break;
}
}
if (check == 0) cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long exp) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base);
base = (base * base);
exp /= 2;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
long long *a = new long long[n];
long long *b = new long long[m];
set<long long> s;
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (s.find(a[i]) == s.end()) {
s.insert(a[i]);
}
}
long long ans = -1;
for (long long i = 0; i < m; i++) {
cin >> b[i];
if (s.find(b[i]) != s.end()) {
ans = b[i];
}
}
if (ans == -1) {
cout << "NO"
<< "\n";
} else {
cout << "YES"
<< "\n";
cout << 1 << " " << ans << "\n";
}
delete[] a;
delete[] b;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (auto &e : a) cin >> e;
for (auto &e : b) cin >> e;
map<int, int> cnt;
for (auto &e : b) cnt[e]++;
bool ok = false;
for (auto &e : a) {
if (cnt.count(e)) {
cout << "YES"
<< "\n";
cout << 1 << " " << e << "\n";
ok = true;
}
if (ok) break;
}
if (!ok) {
cout << "NO"
<< "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
read:
while (t--) {
int a, b;
cin >> a >> b;
long long int ar[a];
long long int arr[b];
for (int i = 0; i < a; i++) {
cin >> ar[i];
}
for (int i = 0; i < b; i++) {
cin >> arr[i];
}
sort(ar, ar + a);
for (int i = 0; i < b; i++) {
bool ans = binary_search(ar, ar + a, arr[i]);
if (ans == 1) {
cout << "YES" << endl << 1 << " " << arr[i] << endl;
goto read;
}
}
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
long long int A[n], B[m];
for (long long int i = 0; i < n; i++) {
cin >> A[i];
}
for (long long int i = 0; i < m; i++) {
cin >> B[i];
}
long long int flag = 0, num = 0, temp = 0;
unordered_map<long long int, long long int> mp;
for (int i = 0; i < n; i++) mp[A[i]]++;
for (auto x : mp) {
for (long long int i = 0; i < m; i++) {
if (B[i] == x.first) {
num = x.first;
flag = 1;
break;
}
}
if (flag == 1) break;
}
if (flag == 1) {
cout << "YES\n1 " << num << "\n";
} else {
cout << "NO\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1000], b[1000];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
int n, m, flag = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
sort(b + 1, b + 1 + m);
for (int i = 1; i <= n; i++)
if (b[lower_bound(b + 1, b + 1 + m, a[i]) - b] == a[i]) {
flag = i;
break;
}
if (flag)
cout << "YES\n1 " << a[flag] << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, flag = 0, i, x;
cin >> n >> m;
map<int, int> a;
vector<int> b;
for (i = 0; i < n; i++) {
cin >> x;
a.insert({x, 1});
}
for (i = 0; i < m; i++) {
int y;
cin >> y;
b.push_back(y);
}
for (i = 0; i < m; i++) {
if (a.find(b[i]) != a.end()) {
flag = 1;
break;
}
}
if (flag == 1) {
cout << "YES" << endl;
cout << 1 << " " << b[i] << endl;
} else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
long long a[n], b[m];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
for (long long i = 0; i < m; i++) {
cin >> b[i];
}
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < m; j++) {
if (a[i] == b[j]) {
cout << "YES" << endl << 1 << " " << a[i] << endl;
return;
}
}
}
cout << "NO" << endl;
return;
}
int main() {
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}
int getCommon(int arr1[], int arr2[], int m, int n) {
int i = 0, j = 0;
while (i < m && j < n) {
if (arr1[i] < arr2[j])
i++;
else if (arr2[j] < arr1[i])
j++;
else {
return arr2[j];
}
}
return -1;
}
void solve() {
int n, m;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + m);
int ans = getCommon(a, b, n, m);
if (ans == -1) {
cout << "NO" << '\n';
} else {
cout << "YES" << '\n';
cout << "1 " << ans << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m;
int main() {
int task;
for (scanf("%d", &task); task--;) {
scanf("%d%d", &n, &m);
unordered_set<int> S;
for (int i = 1, x; i <= n; i++) scanf("%d", &x), S.insert(x);
bool flag = true;
for (int i = 1, x; i <= m; i++) {
scanf("%d", &x);
if (flag && S.count(x)) {
puts("YES");
printf("1 %d\n", x);
flag = false;
}
}
if (flag) puts("NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int a[n];
int b[m];
vector<int> v;
unordered_map<int, int> ans;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans[a[i]]++;
}
for (int i = 0; i < m; i++) {
cin >> b[i];
if (ans[b[i]] >= 1) {
v.push_back(b[i]);
}
}
if (v.size() == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
cout << 1 << " " << v[0] << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m, x, a[1001] = {};
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
int ans = 0;
for (int i = 0; i < m; i++) {
cin >> x;
if (a[x]) ans = x;
}
if (ans) {
cout << "YES" << endl << 1 << " " << ans << endl;
} else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int a[n], b[m];
unordered_set<int> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
bool flag = false;
for (int i = 0; i < m; i++) {
if (s.find(b[i]) != s.end()) {
cout << "YES" << endl;
cout << "1"
<< " " << b[i] << endl;
flag = true;
break;
}
}
if (flag == false) cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, a, b, c, m, l, r, p, q, s;
void dihan() {
cin >> n >> m;
vector<long long> x(n);
for (auto &i : x) cin >> i;
vector<long long> y(m);
for (auto &i : y) cin >> i;
vector<long long> z(1001);
for (i = 0; i < n; i++) z[x[i]] = 1;
for (i = 0; i < m; i++)
if (z[y[i]] == 1) break;
(i < m) ? cout << "YES" << endl
<< 1 << " " << y[i] << endl
: cout << "NO" << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin >> t;
while (t--) dihan();
}
|
#include <bits/stdc++.h>
using namespace std;
void g_o_a_l() {
long long n, m, q;
string s;
map<long long, long long> p, r;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> q;
++p[q];
}
long long j = 0;
for (int i = 0; i < m; i++) {
cin >> q;
++r[q];
if (p[q] > 0 && r[q] > 0) j = q;
}
if (j)
cout << "YES"
<< "\n"
<< 1 << " " << j << "\n";
else
cout << "NO"
<< "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int t = 1;
cin >> t;
while (t--) {
g_o_a_l();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, i, j;
cin >> n >> m;
int A[n], B[m];
for (i = 0; i < n; i++) {
cin >> A[i];
}
for (i = 0; i < m; i++) {
cin >> B[i];
}
int flag = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (A[i] == B[j]) {
cout << "YES"
<< "\n"
<< 1 << ' ' << A[i] << "\n";
flag = 1;
break;
}
}
if (flag == 1) break;
}
if (flag == 0)
cout << "NO"
<< "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const long double pi = acos(-1);
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
vector<long long> a(n), b(m);
set<long long> s;
for (long long i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
long long r;
bool y = false;
for (long long i = 0; i < m; i++) {
cin >> b[i];
if (s.find(b[i]) != s.end()) {
r = b[i];
y = true;
}
}
if (y) {
cout << "YES" << endl;
cout << "1 " << r << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int m;
cin >> m;
vector<int> arr1, arr2, result;
arr1.reserve(n);
arr2.reserve(m);
int c;
for (int i = 0; i < n; i++) {
cin >> c;
arr1.push_back(c);
}
for (int i = 0; i < m; i++) {
cin >> c;
arr2.push_back(c);
}
int res = -1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (arr1[i] == arr2[j]) res = arr1[i];
if (res == -1)
cout << "NO\n";
else {
cout << "YES\n";
cout << 1 << " " << res << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, k, x;
cin >> t;
vector<int> vec1;
vector<int> vec2;
vector<int>::iterator it, it2;
for (int i = 0; i < t; i++) {
int a, b;
cin >> a >> b;
for (int j = 0; j < a; j++) {
cin >> k;
vec1.push_back(k);
}
for (int l = 0; l < b; l++) {
cin >> k;
vec2.push_back(k);
}
stack<int> s;
x = 0;
for (it = vec1.begin(); it != vec1.end(); it++) {
for (it2 = vec2.begin(); it2 != vec2.end(); it2++) {
if (*it == *it2) {
s.push(*it2);
x++;
}
}
}
if (x == 0)
cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << "1"
<< "\t" << s.top() << endl;
}
while (x--) {
s.pop();
}
vec1.clear();
vec2.clear();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int mod1 = 998244353;
const long long int inf = 9e18 + 5;
const double pi = acosl(-1.0l);
const long double eps = 1e-9;
bool equalTo(double a, double b) {
if (fabs(a - b) <= eps)
return true;
else
return false;
}
bool notEqual(double a, double b) {
if (fabs(a - b) > eps)
return true;
else
return false;
}
bool lessThan(double a, double b) {
if (a + eps < b)
return true;
else
return false;
}
bool lessThanEqual(double a, double b) {
if (a < b + eps)
return true;
else
return false;
}
bool greaterThan(double a, double b) {
if (a > b + eps)
return true;
else
return false;
}
bool greaterThanEqual(double a, double b) {
if (a + eps > b)
return true;
else
return false;
}
void swap(long long int &a, long long int &b) {
long long int t = a;
a = b;
b = t;
}
long long int min(long long int a, long long int b) {
if (a < b) return a;
return b;
}
long long int max(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long int pow(long long int a, long long int b) {
a %= mod;
long long int ans = 1;
while (b > 0) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b /= 2;
}
return ans;
}
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
long long int tc;
cin >> tc;
while (tc--) {
long long int n, m;
cin >> n >> m;
long long int a[n];
long long int b[m];
map<long long int, long long int> mp;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
long long int pos = -1;
for (long long int i = 0; i < m; i++) {
cin >> b[i];
if (mp[b[i]]) {
pos = i;
}
}
if (pos == -1) {
cout << "NO\n";
} else {
cout << "YES\n";
cout << "1 " << b[pos] << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1050], b[1050];
set<int> brojevi;
int main() {
int t, n, m;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n >> m;
brojevi.clear();
for (int j = 0; j < n; j++) {
cin >> a[j];
auto pos = brojevi.find(a[j]);
if (pos == brojevi.end()) {
brojevi.insert(a[j]);
}
}
int c = -1;
for (int j = 0; j < m; j++) {
cin >> b[j];
}
for (int j = 0; j < m; j++) {
auto pos = brojevi.find(b[j]);
if (pos != brojevi.end()) {
c = b[j];
break;
}
}
if (c == -1) {
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
cout << 1 << " " << c << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int bs(int a[], int val, int m) {
int start = 0, end = m - 1, mid = (start + end) / 2;
while (end >= start) {
mid = (start + end) / 2;
if (a[mid] == val)
return 1;
else if (a[mid] > val)
end = mid - 1;
else
start = mid + 1;
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m, f = 0;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + m);
for (int i = 0; i < n; i++) {
if (bs(b, a[i], m) == 1) {
cout << "YES\n";
cout << 1 << " " << a[i] << "\n";
f = 1;
break;
}
}
if (f == 0) cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
map<int, int> mp;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mp[x] = i + 1;
}
int ans = -1;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
if (mp[x] != 0) ans = x;
}
if (ans != -1) {
cout << "YES\n";
cout << 1 << " " << ans << "\n";
} else {
cout << "NO\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc, i, n1, n2, a, b;
vector<int> v1, v2;
cin >> tc;
while (tc--) {
cin >> n1 >> n2;
for (i = 0; i < n1; i++) {
cin >> a;
v1.push_back(a);
}
for (i = 0; i < n2; i++) {
cin >> a;
v2.push_back(a);
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
vector<int> v(v1.size() + v2.size());
vector<int>::iterator it, st;
it =
set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), v.begin());
if (!(v.front()))
cout << "NO\n";
else {
cout << "YES\n1 ";
cout << v.front() << endl;
}
v.clear();
v1.clear();
v2.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long modPower(long long num, long long r) {
if (r == 0) return 1;
if (r == 1) return num % 1000000007;
long long ans = modPower(num, r / 2) % 1000000007;
if (r % 2 == 0) {
return (ans * ans) % 1000000007;
}
return (((ans * ans) % 1000000007) * num) % 1000000007;
}
long long nCr(long long n, long long r) {
long long res = 1;
if (r > n - r) {
r = n - r;
}
for (long long i = 0; i < r; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
void solve() {
long long n, m, num;
unordered_map<long long, long long> one;
cin >> n >> m;
int a[m];
for (long long i = 0; i < n; i++) {
cin >> num;
one[num]++;
}
for (long long i = 0; i < m; i++) {
cin >> a[i];
}
for (long long i = 0; i < m; i++) {
if (one[a[i]] >= 1) {
cout << "YES"
<< "\n";
cout << 1 << " " << a[i] << "\n";
return;
}
}
cout << "NO"
<< "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int b[m];
for (int i = 0; i < m; i++) cin >> b[i];
int f = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j]) {
f = a[i];
break;
}
}
if (f != -1) break;
}
if (f == -1)
cout << "NO\n";
else
cout << "YES\n" << 1 << " " << f << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int mod1 = 1000000007;
long long int mod2 = 67280421310721;
long long int mod3 = 998244353;
long long int INF = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
int n, l;
cin >> n >> l;
map<int, int> m;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
m[x]++;
}
bool f = 0;
int ans = 0;
for (int i = 0; i < l; i++) {
int x;
cin >> x;
if (m[x] > 0) {
f = 1;
ans = x;
}
}
if (f)
cout << "YES\n"
<< "1 " << ans << "\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
void solve(int tc) {
int n, m;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
int ans = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j]) {
ans = a[i];
break;
}
}
if (ans != -1) {
break;
}
}
if (ans == -1) {
cout << "NO\n";
return;
}
cout << "YES\n";
cout << 1 << " " << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int tc = 1;
cin >> tc;
for (int i = 1; i <= tc; i++) {
solve(i);
}
return 0;
}
|
#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, m;
cin >> n >> m;
int a[n];
unordered_map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
int b[m];
int ans = -1;
for (int i = 0; i < m; i++) {
cin >> b[i];
if (mp[b[i]] > 0) {
ans = b[i];
}
}
if (ans == -1)
cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << "1"
<< " " << ans << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p) {
out << "(" << p.first << ", " << p.second << ")";
return out;
}
template <template <typename, typename...> class ContainerType,
typename ValueType, typename... Args>
void print(const ContainerType<ValueType, Args...> &c) {
for (const auto &v : c) cout << v << ' ';
cout << '\n';
}
void print() { cout << '\n'; }
template <typename T, typename... Args>
void print(T a, Args... args) {
cout << a << " ";
print(args...);
}
long long llipower(long long x, long long y, long long p = LLONG_MAX) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
set<int> a;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
a.insert(x);
}
vector<int> b(m);
for (int i = 0; i < m; i++) cin >> b[i];
bool con = false;
for (int i = 0; i < m; i++) {
if (a.count(b[i])) {
con = true;
cout << "YES"
<< "\n";
cout << 1 << " " << b[i] << "\n";
break;
}
}
if (!con)
cout << "NO"
<< "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = -1;
for (int i = 0; i < n; i++) {
if (find(b.begin(), b.end(), a[i]) != b.end()) {
ans = a[i];
break;
}
}
if (ans == -1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
cout << "1 " << ans << endl;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
while (a--) {
int b, c;
cin >> b >> c;
int arr1[b], arr2[c];
set<int> check;
for (int j = 0; j < b; j++) {
cin >> arr1[j];
check.insert(arr1[j]);
}
int x = -1;
for (int j = 0; j < c; j++) {
cin >> arr2[j];
if (check.count(arr2[j])) x = arr2[j];
}
if (x == -1)
cout << "NO\n";
else {
cout << "YES\n";
cout << "1"
<< " " << x << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
out << a.first << " " << a.second;
return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
if (b > a) a = b;
return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
if (b < a) a = b;
return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const int N = 55;
void solve() {
long long int m, n, count = 0;
cin >> m >> n;
long long int mini = min(m, n);
long long int arr[m], arr2[n], arr3[mini];
for (int i = 0; i < m; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
cin >> arr2[i];
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (arr[i] == arr2[j]) {
arr3[count] = arr[i];
count++;
break;
}
}
if (count > 0) break;
}
if (count > 0) {
cout << "YES" << endl;
cout << count << " ";
for (int i = 0; i < count; i++) cout << arr3[i] << " ";
cout << endl;
} else
cout << "NO" << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
long long int a[n], b[m];
for (long long int i = 0; i < n; i++) cin >> a[i];
for (long long int i = 0; i < m; i++) cin >> b[i];
long long int flag = 0, ans = 0;
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < m; j++)
if (a[i] == b[j]) {
flag = 1;
ans = a[i];
break;
}
if (flag == 1) break;
}
if (flag == 0)
cout << "NO" << endl;
else
cout << "YES" << endl << 1 << " " << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int t, n, i, j, x, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while (t--) {
cin >> n >> m;
vector<long long int> a;
vector<long long int> b;
long long int flag = 0;
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
for (i = 0; i < m; i++) {
cin >> x;
b.push_back(x);
}
std::vector<long long int>::iterator u;
std::vector<long long int>::iterator it;
for (it = a.begin(); it != a.end(); it++) {
u = std::find(b.begin(), b.end(), *it);
if (u != b.end()) {
cout << "YES" << endl;
cout << 1 << " " << *it << endl;
flag = 1;
break;
}
}
if (flag == 0) {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
int main() {
int m, n, t, tt;
cin >> t;
while (t--) {
set<int> as;
vector<int> b;
int res = -1;
cin >> m >> n;
b.resize(n);
for (int i = 0; i < m; i++) {
cin >> tt;
as.insert(tt);
}
for (int i = 0; i < n; i++) {
cin >> tt;
if (as.find(tt) != as.end()) res = tt;
}
if (res != -1) {
cout << "YES" << endl;
cout << 1 << " " << res << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> ar(n);
vector<int> ar2(m);
int ans = -1;
for (int i = 0; i < n; ++i) {
cin >> ar[i];
}
for (int i = 0; i < m; ++i) {
cin >> ar2[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (ar[i] == ar2[j]) ans = ar[i];
}
}
if (ans == -1)
cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << 1 << " " << ans << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
cin >> t;
op:
while (t--) {
long long n, m;
cin >> n >> m;
long long x;
vector<long long> a;
vector<long long> b;
set<long long> s;
for (long long i = 0; i < n; i++) {
cin >> x;
s.insert(x);
a.push_back(x);
}
for (long long i = 0; i < m; i++) {
cin >> x;
b.push_back(x);
}
long long ok = 0;
long long ind;
for (long long i = 0; i < m; i++) {
if (s.find(b[i]) != s.end()) {
ind = b[i];
ok = 1;
break;
}
}
if (ok == 0) {
cout << "NO" << endl;
goto op;
}
cout << "YES" << endl;
cout << 1 << " " << ind << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t, a, b;
int m[1001], n[1001], flag;
int main() {
cin >> t;
for (int i = 0; i < t; i++) {
flag = 0;
cin >> a >> b;
for (int x = 0; x < a; x++) cin >> m[x];
for (int y = 0; y < b; y++) cin >> n[y];
for (int z = 0; z < a; z++) {
if (flag == 1) break;
for (int r = 0; r < b; r++) {
if (flag == 1) break;
if (m[z] == n[r]) {
cout << "YES" << endl << 1 << " " << m[z] << endl;
flag = 1;
}
}
}
if (flag == 0) cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long l, r, a, x, y, z, b, i, j, k, n, m, num, ans, t;
long long arr[200005], arr2[200005];
string s;
char str[10][10];
bool cmp(long long a, long long b) { return a > b; }
int main() {
cin >> t;
for (k = 0; k < t; k++) {
memset(arr, 0, sizeof(arr));
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a;
arr[a] = 1;
}
b = -1;
for (i = 0; i < m; i++) {
cin >> a;
if (arr[a] == 1) {
b = a;
}
}
if (b == -1)
cout << "NO\n";
else {
cout << "YES" << '\n' << "1 " << b << '\n';
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int k = -1;
int i = 0, j = 0;
do {
if (a[i] == b[j]) {
k = a[i];
break;
}
if (a[i] > b[j]) {
j++;
} else {
i++;
}
} while (i < n && j < m);
if (k == -1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl << 1 << " " << k << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long _siz6xTU51_skxxXnGl2_sgUZxRBhyMOD = 1000000007;
const long long _siz6xTU51_skxxXnGl2_sgUZxRBhyN = 100000;
template <typename _siz6xTU51_skxxXnGl2_sgUZxRBhythird>
ostream& operator<<(ostream& _siz6xTU51_skxxXnGl2_sgUZxRBhyos,
const vector<_siz6xTU51_skxxXnGl2_sgUZxRBhythird>&
_siz6xTU51_skxxXnGl2_sgUZxRBhyv) {
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x7b";
for (auto _siz6xTU51_skxxXnGl2_sgUZxRBhyit =
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin();
_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.end();
++_siz6xTU51_skxxXnGl2_sgUZxRBhyit) {
if (_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin())
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x2c\x20";
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << *_siz6xTU51_skxxXnGl2_sgUZxRBhyit;
}
return _siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x7d";
}
template <typename first, typename second>
ostream& operator<<(
ostream& _siz6xTU51_skxxXnGl2_sgUZxRBhyos,
const pair<first, second>& _siz6xTU51_skxxXnGl2_sgUZxRBhyp) {
return _siz6xTU51_skxxXnGl2_sgUZxRBhyos
<< "\x28" << _siz6xTU51_skxxXnGl2_sgUZxRBhyp.first << "\x2c\x20"
<< _siz6xTU51_skxxXnGl2_sgUZxRBhyp.second << "\x29";
}
template <typename _siz6xTU51_skxxXnGl2_sgUZxRBhythird>
ostream& operator<<(ostream& _siz6xTU51_skxxXnGl2_sgUZxRBhyos,
const set<_siz6xTU51_skxxXnGl2_sgUZxRBhythird>&
_siz6xTU51_skxxXnGl2_sgUZxRBhyv) {
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x5b";
for (auto _siz6xTU51_skxxXnGl2_sgUZxRBhyit =
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin();
_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.end();
++_siz6xTU51_skxxXnGl2_sgUZxRBhyit) {
if (_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin())
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x2c\x20";
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << *_siz6xTU51_skxxXnGl2_sgUZxRBhyit;
}
return _siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x5d";
}
template <typename _siz6xTU51_skxxXnGl2_sgUZxRBhythird>
ostream& operator<<(ostream& _siz6xTU51_skxxXnGl2_sgUZxRBhyos,
const multiset<_siz6xTU51_skxxXnGl2_sgUZxRBhythird>&
_siz6xTU51_skxxXnGl2_sgUZxRBhyv) {
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x5b";
for (auto _siz6xTU51_skxxXnGl2_sgUZxRBhyit =
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin();
_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.end();
++_siz6xTU51_skxxXnGl2_sgUZxRBhyit) {
if (_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin())
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x2c\x20";
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << *_siz6xTU51_skxxXnGl2_sgUZxRBhyit;
}
return _siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x5d";
}
template <typename first, typename second>
ostream& operator<<(ostream& _siz6xTU51_skxxXnGl2_sgUZxRBhyos,
const map<first, second>& _siz6xTU51_skxxXnGl2_sgUZxRBhyv) {
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x5b";
for (auto _siz6xTU51_skxxXnGl2_sgUZxRBhyit =
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin();
_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.end();
++_siz6xTU51_skxxXnGl2_sgUZxRBhyit) {
if (_siz6xTU51_skxxXnGl2_sgUZxRBhyit !=
_siz6xTU51_skxxXnGl2_sgUZxRBhyv.begin())
_siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x2c\x20";
_siz6xTU51_skxxXnGl2_sgUZxRBhyos
<< _siz6xTU51_skxxXnGl2_sgUZxRBhyit->first << "\x20\x3d\x20"
<< _siz6xTU51_skxxXnGl2_sgUZxRBhyit->second;
}
return _siz6xTU51_skxxXnGl2_sgUZxRBhyos << "\x5d";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
if (1) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhykk = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk <= 1000;
_siz6xTU51_skxxXnGl2_sgUZxRBhykk++) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhypp = 34;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyup = 20;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhycp = 13 * 23;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
_siz6xTU51_skxxXnGl2_sgUZxRBhypp =
_siz6xTU51_skxxXnGl2_sgUZxRBhyup + _siz6xTU51_skxxXnGl2_sgUZxRBhycp;
}
}
long long _siz6xTU51_skxxXnGl2_sgUZxRBhytest;
cin >> _siz6xTU51_skxxXnGl2_sgUZxRBhytest;
while (_siz6xTU51_skxxXnGl2_sgUZxRBhytest--) {
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyn;
cin >> _siz6xTU51_skxxXnGl2_sgUZxRBhyn;
long long _siz6xTU51_skxxXnGl2_sgUZxRBhym;
cin >> _siz6xTU51_skxxXnGl2_sgUZxRBhym;
vector<long long> _siz6xTU51_skxxXnGl2_sgUZxRBhya(
_siz6xTU51_skxxXnGl2_sgUZxRBhyn);
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhyi = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhyi < _siz6xTU51_skxxXnGl2_sgUZxRBhyn;
_siz6xTU51_skxxXnGl2_sgUZxRBhyi++) {
cin >> _siz6xTU51_skxxXnGl2_sgUZxRBhya[_siz6xTU51_skxxXnGl2_sgUZxRBhyi];
}
vector<long long> _siz6xTU51_skxxXnGl2_sgUZxRBhyb(
_siz6xTU51_skxxXnGl2_sgUZxRBhym);
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhyi = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhyi < _siz6xTU51_skxxXnGl2_sgUZxRBhym;
_siz6xTU51_skxxXnGl2_sgUZxRBhyi++) {
cin >> _siz6xTU51_skxxXnGl2_sgUZxRBhyb[_siz6xTU51_skxxXnGl2_sgUZxRBhyi];
}
long long _siz6xTU51_skxxXnGl2_sgUZxRBhyres = -1e9;
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhyi = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhyi <
_siz6xTU51_skxxXnGl2_sgUZxRBhya.size();
_siz6xTU51_skxxXnGl2_sgUZxRBhyi++) {
for (long long _siz6xTU51_skxxXnGl2_sgUZxRBhyj = 0;
_siz6xTU51_skxxXnGl2_sgUZxRBhyj <
_siz6xTU51_skxxXnGl2_sgUZxRBhyb.size();
_siz6xTU51_skxxXnGl2_sgUZxRBhyj++) {
if (_siz6xTU51_skxxXnGl2_sgUZxRBhya[_siz6xTU51_skxxXnGl2_sgUZxRBhyi] ==
_siz6xTU51_skxxXnGl2_sgUZxRBhyb[_siz6xTU51_skxxXnGl2_sgUZxRBhyj]) {
_siz6xTU51_skxxXnGl2_sgUZxRBhyres =
_siz6xTU51_skxxXnGl2_sgUZxRBhyb[_siz6xTU51_skxxXnGl2_sgUZxRBhyj];
break;
}
}
if (_siz6xTU51_skxxXnGl2_sgUZxRBhyres != -1e9) {
break;
}
}
if (_siz6xTU51_skxxXnGl2_sgUZxRBhyres != -1e9) {
cout << "\x59\x45\x53" << '\n';
cout << 1 << "\x20" << _siz6xTU51_skxxXnGl2_sgUZxRBhyres << '\n';
} else {
cout << "\x4e\x4f" << '\n';
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, i, j, ans = 0, k = 1;
cin >> n >> m;
int a[n], b[m];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a[i] == b[j]) {
ans = a[i];
break;
}
}
if (ans > 0) {
break;
}
}
if (ans == 0) {
cout << "NO" << endl;
} else {
cout << "YES"
<< "\n"
<< k << " " << ans << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int T, n, m, a[1005], b[1005], book[1005];
int main() {
cin >> T;
while (T--) {
memset(book, 0, sizeof(book));
cin >> n >> m;
for (register int i = 1; i <= n; i++) cin >> a[i], book[a[i]] = 1;
;
for (register int i = 1; i <= m; i++) cin >> b[i];
int flag = 0;
for (register int i = 1; i <= m; i++) {
if (book[b[i]]) {
flag = 1;
puts("YES");
printf("1 %d\n", b[i]);
break;
}
}
if (!flag) puts("NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
long long int testcases;
cin >> testcases;
while (testcases--) {
solve();
}
return 0;
}
void solve() {
int n, m;
cin >> n >> m;
int match;
int flag = 0;
int a[n];
int b[m];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i] == b[j]) {
flag = 1;
match = a[i];
}
}
}
if (flag == 0)
cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << "1 " << match << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, j, n, m;
cin >> t;
while (t--) {
int flag = 0;
cin >> n >> m;
int a[n];
int b[m];
int p[1001] = {0};
int q[1001] = {0};
for (i = 0; i < n; i++) {
cin >> a[i];
p[a[i]]++;
}
for (i = 0; i < m; i++) {
cin >> b[i];
q[b[i]]++;
}
for (i = 0; i <= 1000; i++) {
if (q[i] >= 1 && p[i] >= 1) {
cout << "YES" << endl;
cout << "1"
<< " " << i << endl;
flag = 1;
break;
}
}
if (!flag) {
cout << "NO" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool was[10000], ansb;
int t, n, m, a, ans;
int main() {
cin >> t;
for (int j = 0; j < t; j++) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a;
was[a] = true;
}
for (int i = 0; i < m; i++) {
cin >> a;
if (was[a] == true) {
ansb = true;
ans = a;
}
}
if (ansb) {
cout << "YES" << endl << 1 << " " << ans << endl;
} else {
cout << "NO" << endl;
}
for (int i = 0; i <= 1000; i++) {
was[i] = false;
}
ansb = false;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.