def ala(x): out = [] while x != 0: out.append(x % 10) x /= 10 b = sorted(out) if out == b: return False b.reverse() if out == b: return False return True nis = 0 nnot = 100 n = 100 while nis != nnot * 99: n += 1 if ala(n): nis += 1 else: nnot += 1 print n