Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:256000000")
- #define _CRT_SECURE_NO_WARNINGS
- #define _CRT_SECURE_NO_DEPRECATE
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<string>
- #include<cstring>
- #include<algorithm>
- #include<cmath>
- #include <set>
- #include <queue>
- #include <map>
- #include <vector>
- #include <unordered_map>
- #include <assert.h>
- using namespace std;
- #define mp make_pair
- #define pub push_back
- #define con continue
- #define forn(i, n) for (int i = 0; i < int(n); ++i)
- #define fornr(i, n) for (int i = n - 1; i >= 0; --i)
- #define forab(i, a, b) for (int i = (a); i <= int(b); ++i)
- typedef long long ll;
- typedef pair <int, int> pii;
- typedef vector <int> vi;
- typedef vector < pii > vii;
- typedef vector < vector < int> > vvi;
- typedef vector < vector < pair < int, int > > > vvii;
- const int ZEROS = (int)(1E+6 * 5 + 100);
- const int INF = (int)1E+9;
- const long double EPS = 1E-13;
- pii A[30];
- void solve() {
- sort(A, A + 30);
- reverse(A, A + 30);
- int k = 0;
- int a1 = -1, a2 = -1, a3 = -1, a4 = -1;
- int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
- forn(i, 30) {
- if (A[i].first > 0) {
- x1 = A[i].first;
- A[i].first--;
- a1 = A[i].second;
- forn(j, 30) {
- if (A[j].first > 0 && i != j) {
- x2 = A[j].first;
- A[j].first--;
- a2 = A[j].second;
- break;
- }
- }
- if (a2 != -1) {
- k++;
- break;
- }
- }
- }
- sort(A, A + 30);
- forn(i, 30) { //4
- if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2) {
- x3 = A[i].first;
- A[i].first = 0;
- a3 = A[i].second;
- forn(j, 30) {
- if (A[j].first > 0 && i != j && A[j].second != a1 && A[j].second != a2) {
- x4 = A[j].first;
- A[j].first = 0;
- a4 = A[j].second;
- break;
- }
- }
- if (a4 != -1) {
- k++;
- break;
- }
- else
- {
- a3 = -1;
- A[i].first = x3;
- }
- }
- }
- bool u = false;
- forn(i, 30) {
- if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2
- && A[i].second != a3 && A[i].second != a4) {
- u = true;
- break;
- }
- }
- if (k == 0 || (a1 != -1 && a2 != -1 && a3 != -1 && a4 != -1 && u)) {
- cout << "No";
- return;
- }
- if (k < 2) {
- A[a3].first = x3; A[a4].first = x4;
- a3 = -1; a4 = -1;
- k = 1;
- forn(i, 30) { //3
- if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2) {
- x3 = A[i].first;
- A[i].first = 0;
- a3 = A[i].second;
- forn(j, 30) {
- if (A[j].first > 0 && i != j) {
- x4 = A[j].first;
- A[j].first = 0;
- a4 = A[j].second;
- break;
- }
- }
- if (a4 != -1) {
- k++;
- break;
- }
- else
- {
- a3 = -1;
- A[i].first = x3;
- }
- }
- }
- u = false;
- forn(i, 30) {
- if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2
- && A[i].second != a3 && A[i].second != a4) {
- u = true;
- break;
- }
- }
- if (u || k < 2) {
- A[a3].first = x3; A[a4].first = x4;
- a3 = -1; a4 = -1;
- k = 1;
- forn(i, 30) { //2
- if (A[i].first > 0) {
- x3 = A[i].first;
- A[i].first = 0;
- a3 = A[i].second;
- forn(j, 30) {
- if (A[j].first > 0 && i != j) {
- x4 = A[j].first;
- A[j].first = 0;
- a4 = A[j].second;
- break;
- }
- }
- if (a4 != -1) {
- k++;
- break;
- }
- else
- {
- a3 = -1;
- A[i].first = x3;
- }
- }
- }
- u = false;
- forn(i, 30) {
- if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2
- && A[i].second != a3 && A[i].second != a4) {
- u = true;
- break;
- }
- }
- if (u || k < 2) {
- cout << "No";
- return;
- }
- }
- }
- cout << "Yes";
- }
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- string s;
- cin >> s;
- set <char> S;
- forn(i, (int)s.size()) {
- A[s[i] - 'a'].first++;
- A[s[i] - 'a'].second = s[i] - 'a';
- }
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement