Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define F first
- #define S second
- #define ld long double
- #define ll long long
- #define TIME 1.0*clock()/CLOCKS_PER_SEC
- mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
- const int N = 1e5 + 10;
- const ll MOD = 1e9 + 7;
- const int rx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
- const int ry[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
- const ld eps = 1e-7;
- const double pi = acos(-1.0);
- const int INF = 2e9;
- int main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string s;
- cin >> s;
- vector <int> kol(10, 0);
- for (auto it : s) kol[int(it - '0')] ++;
- int n = s.size();
- vector <int> kol2(10, 0);
- if (kol[1] && kol[0] >= 18) {
- kol[1] --;
- kol[0] -= 18;
- kol2[1] ++;
- kol2[0] += 18;
- int sum = 0;
- for (int i = 0; i < 10; i++) {
- sum += kol[i];
- }
- if (sum == 0) {
- for (int i = 0; i < 10; i++) {
- if (kol2[i]) {
- kol2[i] --;
- kol[i] ++;
- sum ++;
- break;
- }
- }
- }
- } else {
- int len = 18;
- for (int i = 9; i >= 0; i--) {
- if (len < kol[i]) {
- kol[i] -= len;
- kol2[i] += len;
- len = 0;
- } else {
- kol2[i] += kol[i];
- len -= kol[i];
- kol[i] = 0;
- }
- }
- int sum = 0;
- for (int i = 0; i < 10; i++) {
- sum += kol[i];
- }
- if (sum == 0) {
- for (int i = 0; i < 10; i++) {
- if (kol2[i]) {
- kol2[i] --;
- kol[i] ++;
- sum ++;
- break;
- }
- }
- }
- if (sum == kol[0] && sum > 1) {
- kol2[0] ++;
- kol[0] --;
- sum --;
- bool f = false;
- for (int i = 1; i < 10; i++) {
- if (kol2[i]) {
- kol2[i] --;
- kol[i] ++;
- sum ++;
- f = true;
- break;
- }
- }
- if (!f) {
- cout << "-1 -1" << endl;
- return 0;
- }
- }
- }
- int len1 = 0, len2 = 0;
- for (int i = 0; i < 10; i++) len1 += kol[i];
- for (int i = 0; i < 10; i++) len2 += kol2[i];
- if ((len2 > 1 && len2 == kol2[0]) || !len1) {
- cout << "-1 -1" << endl;
- return 0;
- }
- if ((len1 > 1 && len1 == kol[0]) || !len2) {
- cout << "-1 -1" << endl;
- return 0;
- }
- if ((len1 <= 18 || (len1 == 19 && kol[1] == 1 && kol[0] == 18)) && (len2 <= 18 || (len2 == 19 && kol2[1] == 1 && kol2[0] == 18))) {
- for (int i = 1; i < 10; i++) {
- if (kol[i]) {
- cout << i;
- kol[i] --;
- break;
- }
- }
- for (int i = 0; i < kol[0]; i++) cout << "0";
- for (int i = 1; i < 10; i++) {
- for (int j = 0; j < kol[i]; j ++) cout << i;
- }
- cout << " ";
- for (int i = 1; i < 10; i++) {
- if (kol2[i]) {
- cout << i;
- kol2[i] --;
- break;
- }
- }
- for (int i = 0; i < kol2[0]; i++) cout << "0";
- for (int i = 1; i < 10; i++) {
- for (int j = 0; j < kol2[i]; j ++) cout << i;
- }
- cout << endl;
- } else cout << "-1 -1" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement