':type m: int
:type n: int
:rtype: int'

def numberOfPatterns(self, m, n):

    def merge(used, i):
        return (used | (1 << i))
    def contain(used, i):
        return bool((used & (1 << i)))
    def convert(i, j):
        return ((3 * i) + j)
    def numberOfPatternsHelper(m, n, level, used, i):
        number = 0
        if (level > n):
            return number
        if (m <= level <= n):
            number += 1
        (x1, y1) = ((i / 3), (i % 3))
        for j in xrange(9):
            if contain(used, j):
                continue
            (x2, y2) = ((j / 3), (j % 3))
            if ((((x1 == x2) and (abs((y1 - y2)) == 2)) or ((y1 == y2) and (abs((x1 - x2)) == 2)) or ((abs((x1 - x2)) == 2) and (abs((y1 - y2)) == 2))) and (not contain(used, convert(((x1 + x2) / 2), ((y1 + y2) / 2))))):
                continue
            number += numberOfPatternsHelper(m, n, (level + 1), merge(used, j), j)
        return number
    number = 0
    number += (4 * numberOfPatternsHelper(m, n, 1, merge(0, 0), 0))
    number += (4 * numberOfPatternsHelper(m, n, 1, merge(0, 1), 1))
    number += numberOfPatternsHelper(m, n, 1, merge(0, 4), 4)
    return number
