def sub(x,y,base):
    """
    Input: x,y  - two integers represented as lists, e.g. x = [3,0,1], y = [0,1,0]
           base - base of numeral system these integers are represented as, e.g. base = 4

    Output:
           new_number - the result of subtraction of two integers in the given base represented as list, e.g. [2,3,1]
    """
    def sub_one(x, base, index):
        if x[index-1] == 0:
            x[index-1] = base - 1
            return sub_one(x,base, index-1)
        else:
            x[index-1] = x[index-1] - 1
            return x
    length = len(x)
    new_number = [0] * length
    for i in range(0,length):
        if x[i] < y[i]:
            new_number = sub_one(new_number, base, i)
            new_number[i] = x[i] + base - y[i]
        else:
            new_number[i] = x[i] - y[i]
    return new_number