Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- #include <cstdio>
- #include <cctype>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <iomanip>
- #include <queue>
- #include <utility>
- #include <ctime>
- #include <numeric>
- #define pb push_back
- #define mp make_pair
- #define x first
- #define y second
- #define forn(i, n) for (i = 0; i < n; i++)
- using namespace std;
- typedef pair <int, int> pii;
- typedef long double ld;
- typedef long long ll;
- typedef pair <ll, ll> pll;
- const ld EPS = 1e-9;
- const int INF = (int) 1e9;
- const int N = (int) 1e5 + 5;
- const ll M = (int) 1e9 + 7;
- int s(int x) {
- if (x < 10)
- return x;
- int sum = 0;
- while (x)
- sum += x % 10, x /= 10;
- return s(sum);
- }
- pll a[N];
- bool used[N];
- vector <ll> ans;
- int main() {
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> a[i].y;
- a[i].x = s(a[i].y);
- }
- sort(a, a + n);
- for (int i = 0; i < n; i++)
- if (a[i].x == 3 && !used[i])
- for (int j = i + 1; j < n; j++)
- if (!used[j] && a[j].x == 3) {
- ans.pb(a[i].y * a[j].y), used[i] = used[j] = 1;
- break;
- }
- for (int i = 0; i < n; i++)
- if (a[i].x == 2 && !used[i])
- for (int j = 0; j < n; j++)
- if (!used[j] && a[j].x == 4) {
- ans.pb(a[i].y * a[j].y), used[i] = used[j] = 1;
- break;
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- for (int k = 0; k < n; k++)
- if (!used[i] && !used[j] && !used[k] && a[i].x == 2 && a[j].x == 2 && a[k].x == 2 && i != j && i != k && j != k)
- ans.pb(a[i].y * a[j].y * a[k].y), used[i] = used[j] = used[k] = 1;
- for (int i = 0; i < n; i++)
- if (a[i].x == 3 && !used[i])
- for (int j = 0; j < n; j++)
- if (!used[j] && a[j].x == 2) {
- ans.pb(a[i].y * a[j].y), used[i] = used[j] = 1;
- break;
- }
- for (int i = 0; i < n; i++)
- if (!used[i])
- ans.pb(a[i].y);
- cout << ans.size() << endl;
- for (int i = 0; i < (int)ans.size(); i++)
- cout << ans[i] << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement