Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(v) \
- for (auto &i : v) \
- cin >> i;
- #define cout(v) \
- for (auto &i : v) \
- cout << i << " ";
- #define br cout << '\n';
- #define ll long long
- #define ull unsigned long long
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define MOD 1000000007
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" \
- << "\n";
- void Warding()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- bool is_prime(int n)
- {
- if (n <= 1)
- return false;
- for (int i = 2; i <= sqrt(n); i++)
- if (n % i == 0)
- return false;
- return true;
- }
- void solve()
- {
- int a = 0, b = 0;
- string s;
- cin >> s;
- for (int i = 0; i < s.length(); i++)
- {
- if (s[i] == 'a')
- {
- a++;
- if (b % 2 % 3 and b % 3 % 2 )
- {
- cout << "NO" << '\n';
- return;
- }
- b = 0;
- }
- else
- {
- b++;
- if (a % 2 % 3 and a % 3 % 2 )
- {
- cout << "NO" << '\n';
- return;
- }
- a = 0;
- }
- }
- cout << ((a % 2 % 3 and a % 3 % 2 ) or (b % 2 % 3 and b % 3 % 2) ? "NO" : "YES") << '\n';
- }
- int main()
- {
- Warding();
- int t = 1;
- cin >> t;
- while (t--)
- {
- solve();
- }
- Time
- }
Add Comment
Please, Sign In to add comment