import java.util.*; import java.util.function.*; class Ideone { private static int factorial(int n) { int acc = 1; for (int i = 1; i <= n; i++) acc *= i; return acc; } private static <T> List<T> reversed(List<T> list) { return list; } private static <T> int count(Predicate<T> pred, List<T> list) { int count = 0; for (var x : list) if (pred.test(x)) count++; return count; } private static List<Integer> f(int r, int m, int n) { List<Integer> list = new ArrayList<>(); for (int i = 1; i <= r; i++) for (int j = 0; j < m; j++) list.add(i); if (x < n) return reversed(list); List<Integer> acc = new ArrayList<>(); for (int i = 0, n_times = list.size(); i < n_times; i++) { double y = (double)x / list.size(); acc.add(list.remove((int)((n - 1) % x / y))); x = (int)((count(z -> z == acc.get(acc.size() - 1), list) + 1) * y); n -= (int)(count(z -> z < acc.get(acc.size() - 1), list) * y); } return acc; } } }
Standard input is empty
[1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 2, 3, 4, 5, 6, 7, 9, 8] [1, 2, 3, 4, 5, 6, 8, 7, 9] [4, 1, 6, 5, 8, 9, 7, 3, 2] [6, 8, 4, 7, 5, 3, 2, 1, 9] [9, 8, 7, 6, 5, 4, 3, 2, 1] [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4] [1, 1, 1, 2, 2, 2, 3, 3, 4, 3, 4, 4] [1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 3, 4] [2, 2, 2, 3, 3, 1, 4, 3, 4, 1, 1, 4] [3, 2, 4, 4, 2, 4, 3, 3, 1, 1, 1, 2] [4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1]