import java.io.*; import java.util.*; /** * Try all permutations. Count the number of times each pair of digits * appears in the sequence. * * @author Finn Lidbetter */ public class ant_finn { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char[] seq = br.readLine().toCharArray(); int n = seq.length; // counts[i][j] is the number of times that digit j comes immediately after digit i. int[][] counts = new int[9][9]; for (int i=1; i= c[toSwap]) --toSwap; swap(c, first++, toSwap); toSwap = c.length - 1; while (first < toSwap) swap(c, first++, toSwap--); return c; } static int getFirst(int[] c) { for (int i = c.length - 2; i >= 0; --i) if (c[i] < c[i + 1]) return i; return -1; } static void swap(int[] c, int i, int j) { int tmp = c[i]; c[i] = c[j]; c[j] = tmp; } }