Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <cstdlib>
- #include <iomanip>
- #include <sstream>
- #include <cstdio>
- #include <bitset>
- #include <vector>
- #include <queue>
- #include <cmath>
- #include <stack>
- #include <set>
- #include <map>
- #define ft first
- #define sd second
- #define pb push_back
- #define pf push_front
- #define mk make_pair
- #define all(c) (c).begin(), (c).end()
- #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define rfile freopen("input.txt", "r", stdin)
- #define wfile freopen("output.txt", "w", stdout)
- #define files rfile; wfile
- #define DEBUG 1
- typedef long long ll;
- typedef unsigned long long ull;
- using namespace std;
- const int Z = 3 * (int)1e5 + 111;
- const int INF = (int)1e9 + 111;
- const int MODF = (int)1e9 + 7;
- string ss;
- void check(string s, string t) {
- s.erase(s.begin(), s.begin() + t.size());
- s += t;
- if (s != ss) {
- cout << 1 << '\n';
- exit(0);
- }
- }
- void rec(string s, string t) {
- if (t.size() % 2 != 0 || t.size() == 0)
- return;
- string a = t.substr(0, t.size() / 2);
- string b = t.substr(t.size() / 2 + t.size() % 2, t.size() / 2);
- reverse(b.begin(), b.end());
- // cout << a << '\n' << b << '\n';
- // cout << t.substr(0, t.size() / 2) << '\n';
- // cout << t.substr(t.size() / 2 + t.size() % 2, t.size() / 2) << '\n';
- if (a == b) {
- check(s, a);
- rec(s, a);
- }
- }
- int main() {
- SWS;
- string s;
- int flag = 0;
- cin >> s;
- ss = s;
- for (int i = 1; i < s.size(); i++)
- if (s[i] != s[i - 1])
- flag = 1;
- if (!flag) {
- cout << "Impossible";
- return 0;
- }
- if (s.size() % 2 == 0) {
- rec(s, s);
- for (int i = 1; i <= s.size() / 2 - s.size() % 2; i++)
- if (s[i] != s[i - 1])
- flag = 1;
- if (!flag) {
- cout << "Impossible";
- return 0;
- }
- cout << 2 << '\n';
- return 0;
- }
- else {
- flag = 0;
- for (int i = 1; i <= s.size() / 2 - s.size() % 2; i++)
- if (s[i] != s[i - 1])
- flag = 1;
- if (!flag) {
- cout << "Impossible";
- return 0;
- }
- cout << 2;
- return 0;
- }
- cout << 3;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement