Problem :

https://www.hackerrank.com/challenges/separate-the-numbers/problem


My Solution :

#!/usr/bin/env python3


def is_valid(s, length):
    num_str = s[:length]
    num = int(num_str)
    i = 0
    while i < len(s):
        for c in num_str:
            if i == len(s) or c != s[i]:
                return False
            i += 1
        num += 1
        num_str = str(num)
    return True


def separate_numbers(s):
    for length in range(1, len(s)//2 + 1):
        if is_valid(s, length):
            return '{} {}'.format('YES', s[:length])
    return 'NO'


q = int(input())
for _ in range(q):
    s = input()
    result = separate_numbers(s)
    print(result)