Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Locale;
- import java.util.StringTokenizer;
- import java.util.TreeSet;
- public class C {
- String filename = "";//filename here, System.in/out if no file
- FastScanner in;
- PrintWriter out;
- void solve() {
- //your code here
- String s = in.next();
- int n = s.length();
- long max = 1;
- long w = 0;
- for (int i = 0; i < n; i++) {
- w += w * 10 + (long) (s.charAt(i) - '0');
- }
- long u = 0;
- TreeSet<Long> set = new TreeSet<>();
- set.add(w);
- long kek = 1;
- for (int i = 0; i < n - 1; i++) {
- u = u * 10 + (long)9;
- kek *= (long)9;
- }
- String cop = s;
- for (int i = 0; i < s.length(); i++) {
- char ch = s.charAt(i);
- max *= (long) (ch - '0');
- }
- long res = max;
- if (kek == res) {
- set.add(u);
- } else {
- if (kek > res) {
- set.clear();
- set.add(u);
- res = kek;
- }
- }
- for (int i = 0; i < n; i++) {
- int xex = 0;
- char[] e = s.toCharArray();
- long new_ans = 0;
- if (s.charAt(i) == '0') {
- for (int j = 0; j < i; j++) {
- e[j] = '0';
- }
- continue;
- }
- long new_pr = 1;
- String f = "";
- for (int j = 0; j < n; j++) {
- f += e[j];
- }
- s = f;
- char[] m = s.toCharArray();
- m[i] = (char) ((int) m[i] - 1);
- for (int j = i + 1; j < n; j++) {
- m[j] = '9';
- }
- new_pr += 1;
- while (xex < n && m[xex] == '0') {
- xex++;
- }
- new_pr--;
- for (int j = xex; j < n; j++) {
- new_pr *= (long) (m[j] - '0');
- }
- for (int c = 0; c < m.length; c++) {
- new_ans = new_ans * 10 + (long)(m[c] - '0');
- }
- if (new_pr == res) {
- set.add(new_ans);
- } else {
- if (new_pr > res) {
- res = new_pr;
- set.clear();
- set.add(new_ans);
- }
- }
- }
- set.remove((long)0);
- out.println(set.size());
- while (set.size() > 0) {
- long y = set.pollFirst();
- if (y == 0) {
- continue;
- }
- out.print(y + " ");
- }
- }
- void run() throws IOException {
- InputStream input = System.in;
- OutputStream output = System.out;
- try {
- File f = new File(filename + ".in");
- if (f.exists() && f.canRead()) {
- input = new FileInputStream(f);
- output = new FileOutputStream(filename + ".out");
- }
- } catch (IOException e) {
- }
- in = new FastScanner(input);
- out = new PrintWriter(new BufferedOutputStream(output));
- solve();
- in.close();
- out.close();
- }
- public static void main(String[] args) throws IOException {
- Locale.setDefault(Locale.US);
- new C().run();
- }
- class FastScanner implements Closeable {
- private BufferedReader br;
- private StringTokenizer tokenizer;
- public FastScanner(InputStream stream) throws FileNotFoundException {
- br = new BufferedReader(new InputStreamReader(stream));
- }
- public String next() {
- while (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- tokenizer = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return
- tokenizer.nextToken();
- }
- public String nextLine() {
- if (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- return br.readLine();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return tokenizer.nextToken("\n");
- }
- public int nextInt() {
- return Integer.parseInt(next());
- }
- public long nextLong() {
- return Long.parseLong(next());
- }
- public double nextDouble() {
- return
- Double.parseDouble(next());
- }
- @Override
- public void close() throws IOException {
- br.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement