text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 1; const long long N = 1e5 + 7; const long long mod = 1e8; const long double eps = 1E-7; string s, a; int n, cnt, lnt; void solve() { cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> a; if (a[0] == s[1]) cnt = 5; if (a[1] == s[0]) lnt = 5; if (a == s) { cout << "YES"; return; } } if (cnt + lnt == 10) cout << "YES"; else cout << "NO"; } bool mtest = false; int main() { ios_base::sync_with_stdio(0); ; int TE = 1; if (mtest) scanf("%d", TE); while (TE--) solve(); cerr << "\n" << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n, i, j, f1 = 0, f2 = 0; cin >> n; string ch[101]; for (i = 0; i < n; i++) { cin >> ch[i]; } for (i = 0; i < n; i++) { if (ch[i] == s) { cout << "YES" << endl; return 0; } } for (i = 0; i < n; i++) { for (j = 0; j < 2; j++) { if (ch[i][j] == s[0] && j == 1) { f1 = 1; } if (ch[i][j] == s[1] && j == 0) { f2 = 2; } } } if (f1 == 1 && f2 == 2) { cout << "YES" << endl; } else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; char str[10], sub[1234][1234]; int main() { int n; scanf("%s", str); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%s", sub[i]); int k = -1; int flag = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { if (str[0] == sub[i][j]) { if (j == 0 && str[1] == sub[i][1]) { flag = 1; break; } } } if (flag) break; } for (int ii = 0; ii < n; ii++) { if (str[0] == sub[ii][1]) { for (int i = 0; i < n; i++) { if (str[1] == sub[i][0]) { flag = 1; break; } } } if (flag) break; } if (flag) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> int sw, sw1, sw2; int main() { char a[1000]; scanf("%s", a); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char b[10]; scanf("%s", b); if (b[0] == a[0] && b[1] == a[1]) sw = 1; if (b[1] == a[0]) sw1 = 1; if (b[0] == a[1]) sw2 = 1; } if (sw == 1 || sw1 == 1 && sw2 == 1) printf("YES"); else printf("NO"); }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 100000 + 100; int main() { int n; char a[5], b[5]; scanf("%s", a); scanf("%d", &n); int flag1 = 0, flag2 = 0; for (int i = 0; i < n; i++) { scanf("%s", b); if (a[1] == b[1] && a[0] == b[0]) { flag1 = 1; flag2 = 1; } else { if (a[0] == b[1]) flag1 = 1; if (a[1] == b[0]) flag2 = 1; } } if (flag1 && flag2) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char s[5]; int i, n, j; char p[105][5]; cin >> s; cin >> n; for (i = 0; i < n; i++) { cin >> p[i]; } for (i = 0; i < n; i++) { if (s[0] == p[i][0] && s[1] == p[i][1]) { printf("YES\n"); return 0; } if (p[i][1] == s[0]) { for (j = 0; j < n; j++) { if (p[j][0] == s[1]) { printf("YES\n"); return 0; } } } } printf("NO\n"); }
#include <bits/stdc++.h> using namespace std; int hehe[10010]; string s[110]; string a; bool gg(int n) { int i, j; for (i = 1; i <= n; i++) { if (s[i][0] == a[0] && s[i][1] == a[1]) return 1; for (j = 1; j <= n; j++) { if (s[i][1] == a[0] && s[j][0] == a[1]) return 1; } } return 0; } int main() { cin >> a; int n, i, j; scanf("%d", &n); for (i = 1; i <= n; i++) cin >> s[i]; printf(gg(n) ? "YES\n" : "NO\n"); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const int MAX = 3e5 + 5; const long long MAX2 = 11; const int MOD = 1000000000 + 7; const long long INF = 20000; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; const double pi = acos(-1); const double eps = 1e-9; long long n, x[MAX], y, z, sz, cnt, tmp; bool v[MAX]; string s, t; char a, b, c[MAX], d[MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> a >> b; cin >> n; for (int i = 1; i <= n; i++) { cin >> c[i] >> d[i]; if (c[i] == a && d[i] == b) return cout << "YES", 0; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (d[i] == a && c[j] == b) return cout << "YES", 0; } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n; cin >> n; string arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; bool ok = false; for (int i = 0; i < n; i++) { if (s == arr[i]) { ok = true; } } bool f = false, b = false; for (int i = 0; i < n; i++) { if (arr[i][1] == s[0]) f = true; if (arr[i][0] == s[1]) b = true; } if (ok || (f & b)) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string s[1000], t; int n; void nhap() { int i; getline(cin, t); scanf("%d\n", &n); for (i = 1; i <= n; i++) { getline(cin, s[i]); } } bool kt(string a, string b) { string tmp; tmp.clear(); tmp.push_back(a[1]); tmp.push_back(b[0]); if (tmp == t) { return true; } return false; } void xuli() { int i, j; for (i = 1; i <= n; i++) { if (s[i] == t) { cout << "YES"; return; } } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (kt(s[i], s[j]) == true) { cout << "YES"; return; } } } cout << "NO"; } int main() { nhap(); xuli(); }
#include <bits/stdc++.h> using namespace std; char s[3], c[3]; bool ok[2]; int n; int main() { scanf("%s", s); scanf("%d", &n); while (n--) { scanf("%s", c); if (strcmp(s, c) == 0) return puts("YES"), 0; else { if (s[1] == c[0]) ok[0] = 1; if (s[0] == c[1]) ok[1] = 1; if (ok[0] && ok[1]) return puts("YES"), 0; } } return puts("NO"), 0; }
#include <bits/stdc++.h> using namespace std; const long long MX = 0; const long long MN = 0; long long mx = MX, mn = MN; long long x, c, k, n, m, cnt, y, ans; string s, str; bool bl; vector<string> v, vc; map<char, long long> mp; set<long long> st; set<long long>::iterator it; vector<long long> g[1001]; bool used[1001]; long long ar1[1001], ar2[1001]; pair<long long, long long> pr[1001]; char arc[101][101]; string r[5 + 1] = {"S", "M", "L", "XL", "XXL"}; void dfs(long long v) { used[v] = 1; for (long long i = 0; i < g[v].size(); i++) { long long to = g[v][i]; if (!used[to]) { cnt++; dfs(to); } } } int main() { cin >> s >> x; for (long long i = 0; i < x; i++) { cin >> str; v.push_back(str); } for (long long i = 0; i < v.size(); i++) { for (long long j = 0; j < v.size(); j++) { if (i == j) { str = v[i]; if ((s[0] == str[0] and s[1] == str[1]) or (s[0] == str[1] and s[1] == str[0])) { cout << "YES"; return 0; } } else { str = v[i] + v[j]; for (long long h = 0; h < str.size(); h++) { if (str[h] == s[0] and str[h + 1] == s[1]) { cout << "YES"; return 0; } } } } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; ; long long n; cin >> n; ; string a[n]; int z = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; if (s == a[i]) z = 1; } if (z == 1) { cout << "YES" << "\n"; return; } for (long long i = 0; i < n; i++) { for (long long j = i; j < n; j++) { if (a[i][1] == s[0] && a[j][0] == s[1]) { cout << "YES" << "\n"; return; } } } for (long long i = n - 1; i >= 0; i--) { for (long long j = i; j >= 0; j--) { if (a[i][1] == s[0] && a[j][0] == s[1]) { cout << "YES" << "\n"; return; } } } cout << "NO" << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int n; char ch[5], ans[105][3]; int main() { scanf("%s", ch); scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%s", ans[i]); for (int i = 1; i <= n; i++) if (ans[i][0] == ch[0] && ans[i][1] == ch[1]) { puts("YES"); return 0; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (ans[i][1] == ch[0] && ans[j][0] == ch[1]) { puts("YES"); return 0; } } puts("NO"); }
#include <bits/stdc++.h> using namespace std; int n; char str[1005], s[1005][1005], tmp[1005]; int main() { cin >> str >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { strcpy(tmp, s[i]), strcat(tmp, s[j]); if (strstr(tmp, str)) { cout << "YES"; return 0; } } } cout << "NO"; return 0; }
#include <bits/stdc++.h> int main() { int i, j, n, first = 0, second = 0; char flag = 1, Pass[10]; gets(Pass); scanf("%d", &n); char S[n][10]; for (i = 0; i < n; i++) { scanf("%s", S[i]); } for (i = 0; (flag) && (i < n); i++) { if (strstr(Pass, S[i])) { printf("YES\n"); flag = 0; } } for (i = 0; (flag) && (i < n); i++) { if (S[i][1] == Pass[0]) { first = 1; for (j = 0; (j < n); j++) { if (S[j][0] == Pass[1]) { second = 1; } } } } if (flag) { if ((first) && (second)) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; inline void prankami() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { prankami(); string pass, x; int n; cin >> pass >> n; bool first = false, second = false; for (int i = 0; i < n; i++) { cin >> x; if (x[0] == pass[1]) second = true; if (x[1] == pass[0]) first = true; if (x == pass) first = true, second = true; } if (first && second) cout << "YES\n"; else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; long long n; cin >> n; long long flag = 0, cnt = 0, cnt1 = 0; for (long long i = 0; i < n; ++i) { string s1; cin >> s1; if (s1 == s || (s1[0] == s[1] && s1[1] == s[0])) { flag = 1; } if (s1[1] == s[0]) { ++cnt; } if (s1[0] == s[1]) { ++cnt1; } if (cnt >= 1 && cnt1 >= 1) { flag = 1; } } cout << (flag ? "YES" : "NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int n; char s[105][5]; char t[5]; int main() { scanf("%s%d", t, &n); for (int i = 1; i <= n; i++) scanf("%s", s[i]); for (int i = 1; i <= n; i++) if (s[i][0] == t[0] && s[i][1] == t[1]) return puts("YES"), 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (s[i][1] == t[0] && s[j][0] == t[1]) return puts("YES"), 0; puts("NO"); }
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; } void check_time() {} const int res = 2e5 + 10; const long long int mod = 1e9 + 7; int main() { string s, x; int n, sum = 0, ans = 0; cin >> s; scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> x; if (x == s) { deb("YES"); return 0; } if (s[1] == x[0]) { sum = 1; } if (s[0] == x[1]) { ans = 1; } } cout << ((sum == 1 and ans == 1) ? "YES\n" : "NO\n") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string p; cin >> p; int n, k = 1; cin >> n; string str[n]; for (int i = 0; i < n; i++) { cin >> str[i]; if (str[i] == p) { cout << "YES" << "\n"; return 0; } } for (int i = 0; i < n; i++) { if (p[0] == str[i][1]) { k = 0; break; } } if (k == 1) { cout << "NO" << "\n"; return 0; } for (int i = 0; i < n; i++) { if (p[1] == str[i][0]) { cout << "YES" << "\n"; return 0; } } cout << "NO" << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { char s[2]; cin >> s; int n; cin >> n; char b[101][2]; for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i][0] == s[0] && b[i][1] == s[1]) { cout << "YES"; return 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (b[i][1] == s[0] && b[j][0] == s[1]) { cout << "YES"; return 0; } } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string p; cin >> p; long long n, count = 0, count1 = 0; cin >> n; if (n == 1) { string s; cin >> s; if ((s[0] == p[0] && s[1] == p[1]) || (s[0] == p[1] && s[1] == p[0])) { cout << "YES" << endl; } else { cout << "NO" << endl; } } else { while (n--) { string s; cin >> s; if ((s[0] == p[0] && s[1] == p[1]) || (s[0] == p[1] && s[1] == p[0])) { cout << "YES" << endl; return 0; } else if (s[0] == p[1]) { count++; } else if (s[1] == p[0]) { count1++; } } if (count > 0 && count1 > 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; char s[110][3]; int main() { int n; scanf("%s%d", s, &n); for (int i = 1; i <= n; i++) scanf("%s", s[i]); bool flag = 0; for (int i = 1; i <= n; i++) { if (strcmp(s[0], s[i]) == 0) { flag = 1; break; } for (int j = 1; j <= n; j++) { if (s[i][1] == s[0][0] && s[j][0] == s[0][1]) { flag = 1; break; } } } puts(flag ? "YES" : "NO"); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1e5 + 10; string s; string q[110]; int main() { int n; cin >> s; cin >> n; for (int i = 1; i <= n; i++) { cin >> q[i]; if (q[i] == s) { cout << "YES" << endl; return 0; } } for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { if ((q[i][1] == s[0] && q[j][0] == s[1]) || (q[j][1] == s[0] && q[i][0] == s[1])) { cout << "YES" << endl; return 0; } } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, k; string t, s[maxn]; bool ans, a, b; int main() { string t; cin >> t >> n; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == t) { ans = 1; } if (s[i][0] == t[1]) { a = 1; } if (s[i][1] == t[0]) { b = 1; } ans |= a && b; } if (ans) { cout << "YES\n"; } else { cout << "NO\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; long long n; cin >> n; bool found = 0; string arr[n + 1]; for (long long i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] == s) { found = 1; } } if (found == 1) { cout << "YES\n"; } else { long long counter1 = 0, counter2 = 0; long long found1 = 0, found2 = 0; for (long long i = 1; i <= n; i++) { if (arr[i][0] == s[1]) { found2 = i; counter2++; } if (arr[i][1] == s[0]) { counter1++; found1 = i; } } if (counter1 > 0 && counter2 > 0) { cout << "YES\n"; } else { cout << "NO\n"; } } }
#include <bits/stdc++.h> using namespace std; int main() { char a[3]; cin >> a; int n; cin >> n; bool flag1 = 0, flag2 = 0; for (int i = 1; i <= n; i++) { char str[3]; cin >> str; if (str[0] == a[1] && str[1] == a[0]) { cout << "YES" << endl; return 0; } if (str[0] == a[0] && str[1] == a[1]) { cout << "YES" << endl; return 0; } if (str[0] == a[1]) flag2 = 1; if (str[1] == a[0]) flag1 = 1; } if (flag1 && flag2) { cout << "YES" << endl; return 0; } else { cout << "NO" << endl; return 0; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; bool result = 0; cin >> s; long long n; cin >> n; string c[n]; for (long long i = 0; i < n; i++) { cin >> c[i]; if (c[i] == s) result = 1; } if (result == 1) cout << " YES"; else { for (long long i = 0; i < n; i++) { for (long long j = 0; j < n; j++) { if (c[i][1] == s[0] && c[j][0] == s[1]) { result = 1; break; } } } if (result == 1) cout << "YES"; else cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { string p; cin >> p; int n; cin >> n; vector<int> A(300), B(300); for (int i = 0; i < n; ++i) { string c; cin >> c; A[c[1]] = 1; B[c[0]] = 1; if (c == p) { cout << "YES" << endl; return 0; } } if (A[p[0]] && B[p[1]]) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string t; int n; cin >> t >> n; string s[105]; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) if ((s[i] + s[j]).find(t) != string::npos) { cout << "YES"; return 0; } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = (int)2e5 + 5; const double pi = 3.14159265359; int cnt[26], res[26]; void solve() { string s; cin >> s; int n; cin >> n; bool ok = 0; for (int i = 0; i < n; ++i) { string t; cin >> t; if (t == s) { ok = 1; } cnt[t[0] - 'a']++, res[t[1] - 'a']++; } if (ok) { cout << "YES"; return; } if ((cnt[s[1] - 'a'] && res[s[0] - 'a'])) cout << "YES"; else cout << "NO"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> long long poss[26][2]; signed main() { std::string s; std::cin >> s; long long n; std::cin >> n; for (long long i = 0; i < n; i++) { std::string t; std::cin >> t; if (t == s) { std::cout << "YES"; return 0; } for (long long j = 0; j < 2; j++) poss[t[j] - 'a'][j] = true; } if (poss[s[1] - 'a'][0] && poss[s[0] - 'a'][1]) std::cout << "YES"; else std::cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char n[2]; int i, k, j, Chek = 0; cin >> n; cin >> k; char M[2][k]; for (i = 0; i < k; i++) { cin >> M[0][i]; cin >> M[1][i]; if ((M[0][i] == n[0]) && (M[1][i] == n[1])) Chek = 1; if ((M[1][i] == n[0]) && (M[0][i] == n[1])) Chek = 1; } for (i = 0; i < k; i++) { for (j = 0; j < k; j++) { if ((M[1][i] == n[0]) && (M[0][j] == n[1])) Chek = 1; } } if (Chek == 1) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string f, g; cin >> f; int r, m = 0, n = 0, b = 0; cin >> r; for (int e = 0; e < r; e++) { cin >> g; if ((g == f) || (g.at(1) == f.at(0) && g.at(0) == f.at(1))) { m++; } else { if (g.at(0) == f.at(1)) { n++; } else { if (g.at(1) == f.at(0)) { b++; } } } } if ((!(m == 0)) || ((!(n == 0))) && ((!(b == 0)))) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; bool f = false, F = false; char ch[110][2]; int main() { scanf("%s", ch[0]); int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", ch[i]); if (ch[i][0] == ch[0][0] && ch[i][1] == ch[0][1]) return printf("YES\n") * 0; if (ch[i][0] == ch[0][1]) f = true; if (ch[i][1] == ch[0][0]) F = true; } if (f && F) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a; int k; bool a1 = false; bool a2 = false; cin >> a; cin >> k; for (int i = 0; i < k; i++) { string n; cin >> n; if (n == a) { a1 = true; a2 = true; } if (n[0] == a[1]) a1 = true; if (n[1] == a[0]) a2 = true; } if (a1 == true && a2 == true) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char mat[3]; scanf("%s", mat); int n; scanf("%d", &n); char a[n][3]; for (int i = 0; i < n; i++) scanf("%s", a[i]); bool flag = 0; for (int i = 0; i < n; i++) { if (a[i][0] == mat[0] && a[i][1] == mat[1] || a[i][0] == mat[1] && a[i][1] == mat[0]) flag = 1; for (int j = 0; j < n; j++) { if (a[i][1] == mat[0] && a[j][0] == mat[1]) flag = 1; } } if (flag) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int n; cin >> n; string x[200]; vector<char> v; for (int i = 0; i < n; i++) { cin >> x[i]; if (x[i][0] == s[0] && x[i][1] == s[1]) { cout << "YES"; return 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (x[i][1] == s[0] && x[j][0] == s[1]) { cout << "YES"; return 0; } } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; string DBG_DLM(int& i) { return (i++ == 0 ? "" : ", "); } template <class T> ostream& operator<<(ostream& os, vector<T> v); template <class T> ostream& operator<<(ostream& os, set<T> v); template <class T> ostream& operator<<(ostream& os, queue<T> q); template <class T> ostream& operator<<(ostream& os, priority_queue<T> q); template <class T, class K> ostream& operator<<(ostream& os, pair<T, K> p); template <class T, class K> ostream& operator<<(ostream& os, map<T, K> mp); template <class T, class K> ostream& operator<<(ostream& os, unordered_map<T, K> mp); template <int I, class TPL> void DBG(ostream& os, TPL t) {} template <int I, class TPL, class H, class... Ts> void DBG(ostream& os, TPL t) { os << (I == 0 ? "" : ", ") << get<I>(t); DBG<I + 1, TPL, Ts...>(os, t); } template <class T, class K> void DBG(ostream& os, pair<T, K> p, string delim) { os << "(" << p.first << delim << p.second << ")"; } template <class... Ts> ostream& operator<<(ostream& os, tuple<Ts...> t) { os << "("; DBG<0, tuple<Ts...>, Ts...>(os, t); os << ")"; return os; } template <class T, class K> ostream& operator<<(ostream& os, pair<T, K> p) { DBG(os, p, ", "); return os; } template <class T> ostream& operator<<(ostream& os, vector<T> v) { { int i = 0; os << "{"; { for (auto&& t : v) { os << DBG_DLM(i) << t; }; } os << "}"; return os; }; } template <class T> ostream& operator<<(ostream& os, set<T> s) { { int i = 0; os << "{"; { for (auto&& t : s) { os << DBG_DLM(i) << t; }; } os << "}"; return os; }; } template <class T> ostream& operator<<(ostream& os, queue<T> q) { { int i = 0; os << "{"; { for (; q.size(); q.pop()) { os << DBG_DLM(i) << q.front(); }; } os << "}"; return os; }; } template <class T> ostream& operator<<(ostream& os, priority_queue<T> q) { { int i = 0; os << "{"; { for (; q.size(); q.pop()) { os << DBG_DLM(i) << q.top(); }; } os << "}"; return os; }; } template <class T, class K> ostream& operator<<(ostream& os, map<T, K> m) { { int i = 0; os << "{"; { for (auto&& p : m) { os << DBG_DLM(i); DBG(os, p, "->"); }; } os << "}"; return os; }; } template <class T, class K> ostream& operator<<(ostream& os, unordered_map<T, K> m) { { int i = 0; os << "{"; { for (auto&& p : m) { os << DBG_DLM(i); DBG(os, p, "->"); }; } os << "}"; return os; }; } using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pil = pair<int, ll>; using pli = pair<ll, int>; using vs = vector<string>; using vvs = vector<vs>; using vvvs = vector<vvs>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>; using vpii = vector<pii>; using vvpii = vector<vpii>; using vvvpii = vector<vvpii>; template <class A, class B> bool amax(A& a, const B& b) { return b > a ? a = b, 1 : 0; } template <class A, class B> bool amin(A& a, const B& b) { return b < a ? a = b, 1 : 0; } ll ri() { ll l; cin >> l; return l; } string rs() { string s; cin >> s; return s; } void Main() { string s = rs(); int n = ri(); vs W(n); for (int i = int(0); i < int(n); ++i) { W[i] = rs(); if (W[i] == s) { cout << "YES" << endl; return; } } for (int i = int(0); i < int(n); ++i) for (int j = int(0); j < int(n); ++j) { if (W[i][1] == s[0] && W[j][0] == s[1]) { cout << "YES" << endl; return; } } cout << "NO" << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; inline void done() { cout << "YES" << '\n'; exit(0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string pwd; cin >> pwd; int n; cin >> n; bool a = false, b = false; for (int i = 0; i < n; i++) { string ss; cin >> ss; if (ss == pwd) done(); if (ss[0] == pwd[1]) a = true; if (ss[1] == pwd[0]) b = true; } if (a and b) done(); cout << "NO" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string mk; cin >> mk; int n; cin >> n; vector<string> a(n, string()); bool kt1 = false, kt2 = false; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] == mk) { cout << "YES"; return 0; } if (a[i][0] == mk[1]) kt1 = true; if (a[i][1] == mk[0]) kt2 = true; } if (kt1 && kt2) { cout << "YES"; } else { cout << "NO"; } }
#include <bits/stdc++.h> int main() { char password[5]; char tmp[5]; scanf("%s", password); int n; scanf("%d", &n); bool flag = 0; bool first = 0, second = 0; for (int i = 0; i < n; i++) { scanf("%s", tmp); if (tmp[0] == password[0] && tmp[1] == password[1]) flag = 1; if (tmp[0] == password[1]) first = 1; if (tmp[1] == password[0]) second = 1; } if (first && second) puts("YES"); else if (flag) puts("YES"); else puts("NO"); }
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a >= b) return a; else return b; } long long min(long long a, long long b) { if (a <= b) return a; else return b; } long long diff(long long a, long long b) { if (a >= b) return a - b; else return b - a; } 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 gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } void sort(long long arr[], long long n) { for (long long i = 0; i <= n; i++) { for (long long j = i; j <= n; j++) { if (arr[i] > arr[j]) { long long t = arr[i]; arr[i] = arr[j]; arr[j] = t; } } } } long long modd(long long n, long long m) { if (n - m > 0) { return n - m; } else { return m - n; } } long long mod(long long n) { if (n >= 0) { return n; } else { return -n; } } long long isperfectsquare(long long n) { long long k = sqrt(n); if (n % k == 0 && n / k == k) { return 1; } else { return 0; } } vector<long long> q; vector<long long> v[500005]; map<long long, long long> ct; long long vis[500005]; long long cnt = 1; void dfs(long long x) { vis[x] = cnt; for (long long i = 0; i < v[x].size(); i++) { if (vis[v[x][i]] == 0) { dfs(v[x][i]); } } } 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 ispalindrome(string s) { long long palindrome = 1; long long n = s.length(); for (long long i = 0; i < (n / 2); i++) { if (s[i] != s[n - 1 - i]) { palindrome = 0; break; } } return palindrome; } int32_t main() { string p; cin >> p; long long n; cin >> n; string s[n]; long long done = 0; for (long long i = 0; i < n; i++) { cin >> s[i]; if (s[i] == p) { done = 1; } } long long d1 = 0, d2 = 0; if (done == 0) { for (long long i = 0; i < n; i++) { if (s[i][0] == p[1]) { d1++; } if (s[i][1] == p[0]) { d2++; } } } if (d1 != 0 && d2 != 0) { done = 1; } if (done == 1) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 120; char s[maxn][3]; int main(int argc, char const *argv[]) { scanf("%s", s[0]); int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s[i]); } bool flag = false; for (int i = 1; i <= n; i++) { if (strcmp(s[0], s[i]) == 0) flag = true; for (int j = 1; j <= n; j++) { if (flag) break; if (s[0][0] == s[i][1] && s[0][1] == s[j][0]) flag = true; } if (flag) break; } printf("%s\n", flag ? "YES" : "NO"); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 103; string a[N], s; int n; int main() { cin >> s; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { string tmp = a[i] + a[j]; if (tmp.find(s) != string::npos) { cout << "YES"; return 0; } } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; bool p1 = false, p0 = false; char w[2]; cin >> w; cin >> n; char A[n][2]; for (i = 0; i < n; i++) cin >> A[i]; i = 0; while (i < n) { if (w[0] == A[i][0] && w[1] == A[i][1]) break; if (w[0] == A[i][1]) p0 = true; if (w[1] == A[i][0]) p1 = true; if (p0 && p1) break; i++; } if (i == n) cout << "NO" << endl; else cout << "YES" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using DO = double; using INT = long long; using pii = pair<int, int>; using pi3 = pair<pii, int>; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } int power(int a, int b, int mod, int ans = 1) { for (; b; b >>= 1, a = 1LL * a * a % mod) if (b & 1) ans = 1LL * ans * a % mod; return ans; } char str[11]; char s[111][11]; int n; int main() { cin >> str; cin >> n; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i <= n; i++) if (s[i][0] == str[0] and s[i][1] == str[1]) return puts("YES"); int flag0 = 0, flag1 = 0; for (int i = 1; i <= n; i++) { if (s[i][1] == str[0]) flag0 = 1; if (s[i][0] == str[1]) flag1 = 1; } if (flag0 & flag1) return puts("YES"); puts("NO"); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int main() { string s; cin >> s; int n; cin >> n; bool fl2, fl1; fl1 = fl2 = false; while (n--) { string tpl; cin >> tpl; if (tpl == s) { cout << "YES"; return 0; } if (tpl[0] == s[1]) { fl2 = true; } if (tpl[1] == s[0]) { fl1 = true; } if (fl1 && fl2) { cout << "YES"; return 0; } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n; cin >> n; bool lock = false, locker = false, lockerRoom = false; while (n--) { string sa; cin >> sa; if (sa.length() >= 2) { if (s[0] == sa[1]) lock = true; if (s[1] == sa[0]) locker = true; if (s[0] == sa[0] && s[1] == sa[1]) lockerRoom = true; } } if ((lock && locker) || (lockerRoom)) puts("YES"); else puts("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; string _s, s; int main() { int n; bool chest1 = 0, chest2 = 0; cin >> s >> n; for (int i = 0; i < n; ++i) { cin >> _s; if (_s[0] == s[1]) { chest1 = true; } if (_s[1] == s[0]) { chest2 = true; } if (_s == s) { cout << "YES"; return 0; } } if (chest1 == 1 && chest2 == 1) { cout << "YES"; return 0; } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n; bool t = false, t1 = false; cin >> n; for (int i = 1; i <= n; i++) { string k; cin >> k; if (k == s) { return cout << "YES", 0; } if (k[1] == s[0]) { t = true; } if (k[0] == s[1]) { t1 = true; } } if (t1 && t) return cout << "YES", 0; cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 7; const long long MOD = 1e9 + 7; string a[N]; int main() { ios::sync_with_stdio(0); string s, ss; cin >> s; int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { ss = a[i] + a[j]; if (ss.find(s) != -1) return cout << "YES", 0; } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string pass; cin >> pass; int q; cin >> q; bool ans = 0, isLeft = 0, isRight = 0; while (q--) { string tmp; cin >> tmp; if (tmp[1] == pass[0]) isLeft = true; if (tmp[0] == pass[1]) isRight = true; if (tmp == pass || (isLeft && isRight)) { ans = true; break; } } if (ans) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string pass; int n; cin >> pass >> n; bool a = 0, b = 0; for (int i = 0; i < n; i++) { string x; cin >> x; if (x == pass) a = b = 1; if (pass[1] == x[0]) b = 1; if (pass[0] == x[1]) a = 1; } a&& b ? cout << "YES\n" : cout << "NO\n"; }
#include <bits/stdc++.h> using namespace std; char s[33]; bool tag1[33]; bool tag2[33]; int main() { scanf("%s", s); int a = s[0] - 'a'; int b = s[1] - 'a'; int n; scanf("%d", &n); bool win = false; for (int i = 0; i < n; i++) { scanf("%s", s); tag1[s[0] - 'a'] = true; tag2[s[1] - 'a'] = true; if (s[0] - 'a' == a && s[1] - 'a' == b) { win = true; } } if (win || (tag2[a] && tag1[b])) { printf("YES\n"); } else { printf("NO\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-ffloat-store") #pragma GCC optimize("-fno-defer-pop") long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b == 1) return a % m; long long int t = power(a, b / 2, m) % m; t = (t * t) % m; if (b & 1) t = ((t % m) * (a % m)) % m; return t; } long long int modInverse(long long int a, long long int m) { return power(a, m - 2, m); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); char a, b; cin >> a >> b; long long int i, j = 0, k = 0, l = 0, n; cin >> n; char ar[n][3]; for (i = 0; i < n; i++) { cin >> ar[i]; if (ar[i][0] == a && ar[i][1] == b) { l = 1; } if (ar[i][0] == b) k = 1; if (ar[i][1] == a) j = 1; } if (l == 1 || (k == 1 && j == 1)) { cout << "YES\n"; } else { cout << "NO\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int min(int x, int y) { return (x > y ? y : x); } int max(int x, int y) { return (x > y ? x : y); } int main() { int n, a[2] = {0}, b[2] = {0}, i, j, flag = 0; string s; cin >> s; cin >> n; string str; for (i = 0; i < n; i++) { cin >> str; if (str == s) { flag = 1; } for (j = 0; j < 2; j++) { if (str[j] == s[1]) a[j]++; if (str[j] == s[0]) b[j]++; } } if (flag == 1) cout << "YES" << endl; else if ((a[0] > 0 && b[1] > 0)) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5; bool mrk[5]; int main() { string s; int n; cin >> s >> n; while (n--) { string t; cin >> t; if (s == t) mrk[0] = mrk[1] = true; if (t[0] == s[1]) mrk[0] = true; if (t[1] == s[0]) mrk[1] = true; } if (mrk[0] && mrk[1]) return cout << "YES", 0; cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; string p, s[101], r, r2; int main() { int n; cin >> p >> n; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i <= n - 1; i++) { r = s[i], r2 = p; sort(r.begin(), r.end()); sort(r2.begin(), r2.end()); if (r == r2) return cout << "YES", 0; for (int j = i + 1; j < n; j++) { r = s[j]; r2 = p; sort(r.begin(), r.end()); sort(r2.begin(), r2.end()); if (r == r2) return cout << "YES", 0; if (s[i][0] == p[1] && s[j][1] == p[0]) return cout << "YES", 0; if (s[i][1] == p[0] && s[j][0] == p[1]) return cout << "YES", 0; } } cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int n; cin >> n; bool aa = 0, bb = 0; for (int i = 0; i < n; i++) { string s; cin >> s; if (s == a) { cout << "YES" << endl; return 0; } if (s[0] == a[1]) aa = 1; if (s[1] == a[0]) bb = 1; } if (aa && bb) { cout << "YES" << endl; } else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string pass; cin >> pass; long long n; cin >> n; vector<string> a; for (int i = 0; i < n; i++) { string j; cin >> j; j = j + j; a.push_back(j); } long long flag = 0; for (int i = 0; i < n; i++) { if (a[i].find(pass) != string::npos) { flag = 1; break; } } if (flag == 1) { cout << "YES"; return 0; } long long one = 0, two = 0; for (int i = 0; i < n; i++) { if (a[i][0] == pass[1]) one = 1; if (a[i][1] == pass[0]) two = 1; } if (one == 1 && two == 1) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = 1000 * 1000 * 1000 + 21; const long long int LLINF = (1ll << 60) + 5; const int MOD = 1000 * 1000 * 1000 + 7; int n; string gg; string arr[228]; int main() { cin >> gg; cin >> n; for (int i = 0; i < n; ++i) { cin >> arr[i]; if (arr[i] == gg) return 0 * printf("YES\n"); } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if ((arr[i] + arr[j]).find(gg) != string::npos) return 0 * printf("YES\n"); } } printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s, t; vector<string> v; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; while (n--) { cin >> t; v.push_back(t); } for (int i = 0; i < v.size(); ++i) { if (v[i] == s) { cout << "YES" << endl; return 0; } if (v[i][1] == s[0]) { for (int j = 0; j < v.size(); ++j) { if (v[j][0] == s[1]) { cout << "YES" << endl; return 0; } } } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; bool check = false; bool check2 = false; char *str = new char[2]; cin >> str >> n; for (int i = 0; i < n; i++) { string str3; cin >> str3; if (str == str3) { check = true; check2 = true; break; } if (str3[0] == str[1] || str3[1] == str[0]) { if (str3[0] == str[1]) { check = true; } if (str3[1] == str[0]) { check2 = true; } } } if (check && check2) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char s[3], t[5]; bool fg[2] = {0, 0}; scanf("%s", s); int n; scanf("%d%*c", &n); for (int i = 0; i < n; i++) { scanf("%s", t); if (t[0] == s[0] && t[1] == s[1]) { fg[0] = fg[1] = 1; } if (t[0] == s[1]) fg[1] = 1; if (t[1] == s[0]) fg[0] = 1; } if (fg[0] == 1 && fg[1] == 1) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const int N = 1000000 + 7; const int multipleTest = 0; string x, s[N]; int n; void solve() { cin >> x; cin >> n; for (int i = (0), _b = (n); i < _b; ++i) cin >> s[i]; for (int i = (0), _b = (n); i < _b; ++i) { if (s[i] == x) { puts("YES"); return; } for (int j = (0), _b = (n); j < _b; ++j) { if (s[i].back() == x[0] && s[j][0] == x[1]) { puts("YES"); return; } } } puts("NO"); } int main() { int Test = 1; if (multipleTest) { cin >> Test; } for (int i = 0; i < Test; ++i) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { int n; char ca, cb, da, db; bool ba = false, bb = false; cin >> ca >> cb >> n; while (n--) { cin >> da >> db; if (da == cb) bb = true; if (db == ca) ba = true; if (da == ca && db == cb) ba = bb = true; } if (ba && bb) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(void) { cin.tie(0)->sync_with_stdio(false); string pw; cin >> pw; int n; cin >> n; string w[n]; for (int i = 0; i < n; i++) { cin >> w[i]; if (w[i] == pw) { cout << "YES" << '\n'; return 0; } } bool f = false, s = false; for (int i = 0; i < n; i++) { if (w[i][1] == pw[0]) { f = true; } if (w[i][0] == pw[1]) { s = true; } if (f == true && s == true) { cout << "YES" << '\n'; return 0; } } cout << "NO" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string str; string part[101]; bool A = false; bool B = false; int n; cin >> str; cin >> n; for (int i = 0; i < n; i++) { cin >> part[i]; if (part[i][0] == str[1]) A = true; if (part[i][1] == str[0]) B = true; } if (A && B) cout << "YES"; else { for (int i = 0; i < n; i++) { if (part[i] == str) { cout << "YES"; return 0; } } cout << "NO"; return 0; } }
#include <bits/stdc++.h> using namespace std; bool top = 0; bool bottom = 0; int main() { string pass; cin >> pass; int t; cin >> t; string a; for (int i = 1; i <= t; i++) { cin >> a; if (a[0] == pass[1]) bottom = 1; if (a[1] == pass[0]) top = 1; if ((a[0] == pass[0]) && (a[1] == pass[1])) { bottom = 1; top = 1; } } if (top && bottom) cout << "yes"; else cout << "no"; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; string s; cin >> s >> n; vector<string> a(n); for (string& i : a) cin >> i; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { string t = a[i] + a[j]; if (t.find(s) != -1) return !(cout << "YES"); } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n, l = 0, k = 0; cin >> n; string str[n]; for (int i = 0; i < n; i++) { cin >> str[i]; if (str[i] == s) { l = 1; k = 1; } else if (s[0] == str[i][1]) { k = 1; } if (s[1] == str[i][0]) { l = 1; } } cout << (l + k == 2 ? "YES" : "NO"); }
#include <bits/stdc++.h> using namespace std; char res[10]; char s[200][10]; int main() { int n; while (scanf(" %s", res) != EOF) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%s", s[i]); int flag = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == j) { if ((s[i][0] == res[0] && s[i][1] == res[1]) || (s[i][1] == res[0] && s[i][0] == res[1])) { flag = 1; break; } continue; } if (s[i][1] == res[0] && s[j][0] == res[1]) { flag = 1; break; } } if (flag) break; } if (flag) printf("YES\n"); else printf("NO\n"); } }
#include <bits/stdc++.h> using namespace std; char Ans[3]; char mp[120][3]; int main() { while (scanf("%s", Ans) != EOF) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%s", mp[i]); int flag = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (mp[i][1] == Ans[0] && mp[j][0] == Ans[1] || mp[i][0] == Ans[0] && mp[i][1] == Ans[1]) flag = 1; if (flag) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <bits/stdc++.h> int n; char str[5], t[5]; bool vis[5]; int main() { scanf("%s%d", str, &n); vis[0] = vis[1] = 0; while (n--) { scanf("%s", t); if (t[0] == str[0] && t[1] == str[1]) { printf("YES\n"); return 0; } if (t[0] == str[1]) vis[1] = 1; if (t[1] == str[0]) vis[0] = 1; } if (vis[0] && vis[1]) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; using INT = long long; string a[111]; int main() { int n; string s; cin >> s; cin >> n; int flag = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == s) flag |= 3; if (a[i][1] == s[0]) flag |= 1; if (a[i][0] == s[1]) flag |= 2; } if (flag == 3) return puts("YES"), 0; return puts("NO"), 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> s >> n; int res1 = 0, res2 = 0; for (int i = 1; i <= n; i++) { string s1; cin >> s1; if (s1 == s) { cout << "YES"; return 0; } if (s[1] == s1[0]) { res1++; } if (s[0] == s1[1]) { res2++; } } if (res1 != 0 && res2 != 0) { cout << "YES"; } else { cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; char* my_strrev(char* str) { char* left = str; char* rigth = str; while (*str++) ; str -= 2; while (left < str) { char c = *left; *left++ = *str; *str-- = c; } return rigth; } int main() { char** din = new char*[1]; for (int i = 0; i < 1; i++) { din[i] = new char[2]; } for (int i = 0; i < 1; i++) { cin >> din[i]; } int n; cin >> n; char** array = new char*[n]; for (int i = 0; i < n; i++) { array[i] = new char[2]; } for (int i = 0; i < n; i++) { cin >> array[i]; } int c = 0; for (int i = 0; i < n; i++) { if (strncmp(my_strrev(array[i]), din[0], 1) == 0) { c = 1; } array[i] = my_strrev(array[i]); } for (int i = 0; i < n; i++) { if (strcmp(array[i], din[0]) == 0) { cout << "YES"; return 0; } } din[0] = my_strrev(din[0]); int a = 0; for (int i = 0; i < n; i++) { if (strncmp(array[i], din[0], 1) == 0) { a = 1; } } if (a == 1 && c == 1) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; string s; int n; bool fst[256], snd[256]; int main() { cin >> s; cin >> n; for (int i = 0; i < n; i++) { string w; cin >> w; if (w[0] == s[0] && w[1] == s[1]) { cout << "YES" << endl; return 0; } fst[w[0]] = true; snd[w[1]] = true; } if (snd[s[0]] && fst[s[1]]) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; ifstream fin("input.txt"); ofstream fout("output.txt"); inline void boostIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { boostIO(); string Key; cin >> Key; int n; cin >> n; map<char, bool> A; map<char, bool> B; for (int i = 0; i < (n); ++i) { string ab; cin >> ab; if (Key == ab) { cout << "YES" << endl; return 0; } A[ab[0]] = 1; B[ab[1]] = 1; } if (A[Key[1]] == 1 && B[Key[0]] == 1) cout << "YES" << endl; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; string arr[105]; int n; string s; bool done = false; int main() { cin >> s; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int o = 0; o < n; o++) { if (done) { break; } string s2 = arr[o]; for (int j = 0; j < n; j++) { if (done) { break; } string s3 = s2; s3 += arr[j]; for (int k = 0; k < s3.length() - 1; k++) { string s4; s4 += s3[k]; s4 += s3[k + 1]; if (s4 == s) { cout << "YES" << endl; done = true; break; } } } } if (!done) { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; struct bark { char a; char b; } arr[102]; int main() { string str; int n, i, j, flag; cin >> str; cin >> n; flag = 0; for (i = 0; i < n; i++) { cin >> arr[i].a >> arr[i].b; if (arr[i].a == str[0] && arr[i].b == str[1] || (arr[i].a == str[1] && arr[i].b == str[0])) { flag = 1; } } if (flag == 1) { cout << "YES" << endl; return 0; } for (i = 0; i < n; i++) { if (arr[i].b == str[0]) { for (j = 0; j < n; j++) { if (arr[j].a == str[1]) { flag = 1; break; } } } } if (flag == 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string pw, kash[100]; int n; cin >> pw >> n; bool ans = false; for (int i = 0; i < n; i++) { cin >> kash[i]; if (kash[i][0] == pw[0] && kash[i][1] == pw[1]) ans = true; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (kash[i][1] == pw[0] && kash[j][0] == pw[1]) ans = true; } } if (ans) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 103; int main() { char a[3], b[N][3]; bool f1, f2; int n; while (~scanf("%s", a)) { f1 = f2 = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", b[i]); if (strcmp(b[i], a) == 0) f1 = 1, f2 = 1; if (b[i][0] == a[1]) f1 = 1; if (b[i][1] == a[0]) f2 = 1; } if (f1 == 1 && f2 == 1) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int n, i, c, j, f; char a; string x, s[105]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> x; cin >> n; for (i = 0; i < n; i++) { cin >> s[i]; } for (i = 0; i < n; i++) { if (s[i][0] == x[0] && s[i][1] == x[1]) { cout << "YES"; f = 1; return 0; } if (s[i][1] == x[0]) { for (j = 0; j < n; j++) { if (s[j][0] == x[1]) { cout << "YES"; f = 1; return 0; } } } cout << endl; } if (f == 0) cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); const double eps = 1e-7; const int IINF = INT_MAX; const long long LINF = LLONG_MAX; const int imod = 1e9 + 7; const long long lmod = 1e18 + 7; string s[110]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); map<string, int> x; string n; cin >> n; x[n] = 1; int m; cin >> m; int k = 0; for (int i = 1; i <= m; i++) { cin >> s[i]; x[s[i]]++; if (s[i][0] == n[1] and k == 0) k++; } if (x[n] > 1) { cout << "YES"; return 0; } if (k == 0) { cout << "NO"; return 0; } for (int i = 1; i <= m; i++) { if (s[i][1] == n[0]) { cout << "YES"; return 0; } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100 + 10; string p[MAX_N]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); string s; int n; cin >> s >> n; for (int i = 0; i < n; i++) { cin >> p[i]; if (p[i] == s) return cout << "YES", 0; } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (s[0] == p[i][1] && s[1] == p[j][0]) return cout << "YES", 0; cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string p, other[200]; cin >> p; int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; other[i] = s; other[i + n] = s; } string ans = "NO"; for (int i = 0; i < 2 * n; i++) { for (int j = 0; j < 2 * n; j++) { if (other[i] == p || (other[i][1] == p[0] && other[j][0] == p[1])) { ans = "YES"; } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; string s, x[102], z; long long n; bool check(string s1, string s2) { z.clear(); z = s1 + s2; if (s[0] == z[0] && s[1] == z[1]) return true; if (s[0] == z[1] && s[1] == z[2]) return true; if (s[0] == z[2] && s[1] == z[3]) return true; return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; cin >> n; for (long long i = 1; i <= n; i++) { cin >> x[i]; } for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { if (check(x[i], x[j]) || check(x[j], x[i])) { cout << "YES" << endl; return 0; } } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char a[2], t[2]; int n; int flag = 0, flag1 = 0, flag2 = 0; scanf("%c%c", &a[0], &a[1]); scanf("%d", &n); getchar(); for (int i = 0; i < n; i++) { scanf("%c%c", &t[0], &t[1]); getchar(); if (a[0] == t[1]) flag1 = 1; if (a[1] == t[0]) flag2 = 1; if ((a[0] == t[0] && a[1] == t[1]) || (flag1 && flag2)) flag = 1; } if (flag) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char s[1000][5]; char p[5]; int i, j, k, l, t, fl = 0; cin >> p; cin >> t; for (i = 0; i < t; i++) { cin >> s[i]; if (s[i][0] == p[0] && s[i][1] == p[1]) fl = 1; if (s[i][1] == p[0] && s[i][0] == p[1]) fl = 1; } if (fl == 0) for (i = 0; i < t; i++) { if (fl == 0) for (j = 0; j < t; j++) { if (s[i][1] == p[0] && s[j][0] == p[1]) fl = 1; if (s[i][0] == p[1] && s[j][1] == p[0]) fl = 1; if (fl == 1) break; } } if (fl == 1) cout << "YES\n"; else cout << "NO\n"; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 25; long long n; long long t[maxn]; char c1[maxn], c2[maxn]; char c[100]; int main() { cin >> c; cin >> n; int p = 0; for (int i = 0; i < n; i++) { char s[100]; cin >> s; if (s[0] == c[0] && s[1] == c[1]) p = 1; c1[s[0]] = 1; c2[s[1]] = 1; } if (c2[c[0]] == 1 && c1[c[1]] == 1) p = 1; puts(p ? "YES" : "NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string pass; cin >> pass; cin >> n; int i; int flag[2]; flag[0] = 0; flag[1] = 0; string kak; for (i = 0; i < n; i++) { cin >> kak; if (kak[0] == pass[0] && kak[1] == pass[1]) { cout << "YES" << endl; return 0; } if (kak[0] == pass[1] && kak[1] == pass[0]) { cout << "YES" << endl; return 0; } if (kak[1] == pass[0]) { flag[0] = 1; } if (kak[0] == pass[1]) { flag[1] = 1; } } if (flag[0] == 1 && flag[1] == 1) { cout << "YES" << endl; } else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; string s, s1; bool x1, x2; int n; int main() { cin >> s >> n; for (int i = 0; i < n; ++i) { cin >> s1; if (s1[1] == s[0]) x1 = true; if (s1[0] == s[1]) x2 = true; if ((s1[0] == s[0] && s1[1] == s[1]) || (x1 && x2)) return cout << "YES" << "\n", 0; } cout << "NO" << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string pw; int n; string word[101]; string str = "aa"; string tmp; cin >> pw; cin >> n; for (int i = 0; i < n; i++) { cin >> word[i]; if (word[i] == pw) { cout << "YES" << endl; return 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { str[0] = word[i][1]; str[1] = word[j][0]; if (str == pw) { cout << "YES" << endl; return 0; } } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, s1; int n, c1 = 0, c = 0, k = 0; cin >> s; cin >> n; for (int i = 0; i < n; i++) { cin >> s1; if (s1[0] == s[1]) c++; if (s1[1] == s[0]) c1++; if (s == s1) k++; } ((c > 0 && c1 > 0) || k > 0) ? cout << "YES" << "\n" : cout << "NO" << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxlongint = 2147483647; const int inf = 1000000000; char s[10], a[1000][1100]; ; int main() { scanf("%s", s); int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%s", a[i]); int ans = 0; for (int i = 1; i <= n; i++) { if (a[i][0] == s[0] && a[i][1] == s[1]) ans = 1; for (int j = 1; j <= n; j++) if (a[i][1] == s[0] && a[j][0] == s[1]) ans = 1; } if (ans) printf("YES"); else printf("NO"); }
#include <bits/stdc++.h> using namespace std; inline void scd(int &a) { scanf("%d", &a); } inline void scdd(int &a, int &b) { scanf("%d %d", &a, &b); } inline void sctd(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); } inline void sctlld(long long int &a, long long int &b, long long int &c) { scanf("%I64d %I64d %I64d", &a, &b, &c); } inline void scdlld(long long int &a, long long int &b) { scanf("%I64d %I64d", &a, &b); } inline void sclld(long long int &a) { scanf("%I64d", &a); } inline void scllu(unsigned long long int &a) { scanf("%I64u", &a); } inline void scdllu(unsigned long long int &a, unsigned long long int &b) { scanf("%I64u %I64u", &a, &b); } inline void sctllu(unsigned long long int &a, unsigned long long int &b, unsigned long long int &c) { scanf("%I64u %I64u %I64u", &a, &b, &c); } template <class Ver> inline void prd(Ver a) { cout << a << "\n"; }; template <class Ver> inline void prdd(Ver a, Ver b) { cout << a << " " << b << "\n"; }; template <class Ver> inline void prtd(Ver a, Ver b, Ver c) { cout << a << " " << b << " " << c << "\n"; }; inline void debug() { printf("asd\n"); } template <class Ver> inline void debugd(Ver a) { cout << "--- " << a << endl; }; template <class Ver> inline void debugdd(Ver a, Ver b) { cout << "--- " << a << " " << b << endl; }; template <class Ver> inline void debugtd(Ver a, Ver b, Ver c) { cout << "--- " << a << " " << b << " " << c << endl; }; void st() { ios_base::sync_with_stdio(0); cin.tie(0); } int main() { st(); int ver = 0, niy = 0, hbk = 0; string a; cin >> a; cin >> hbk; string b[200]; string c = ""; for (int i = 0; i < hbk; ++i) { cin >> b[i]; } for (int i = 0; i < hbk; ++i) { for (int j = hbk - 1; j >= i; --j) { c += b[i]; c += b[j]; } } for (int j = hbk - 1; j >= 0; --j) { for (int i = 0; i < j; ++i) { c += b[j]; c += b[i]; } } size_t d = c.find(a); if (d != string::npos) prd("YES"); else prd("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int main(int n) { char str[3], s[107][7], tmp[7]; scanf("%s%d", str, &n); for (int i = 1; i <= n; i++) scanf("%s", s[i]); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { strcpy(tmp, s[i]), strcat(tmp, s[j]); if (strstr(tmp, str)) return 0 * printf("YES\n"); } return 0 * printf("NO\n"); }