class Solution(object):
def maxDistance(self, arrays):
"""
:type arrays: List[List[int]]
:rtype: int
"""
m = []
for i, a in enumerate(arrays):
m.append((a[0], i))
m.append((a[-1], i))
m.sort(key=lambda x: x[0])
if m[0][1]!=m[-1][1]:
return m[-1][0]-m[0][0]
return max(m[-2][0]-m[0][0], m[-1][0]-m[1][0])


# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
"""
:type root: TreeNode
:type v: int
:type d: int
:rtype: TreeNode
"""
if d==1:
ans = TreeNode(v)
ans.left = root
return ans
def dfs(root, h):
if not root:
return
if h==d-1:
t = TreeNode(v)
t.left = root.left
root.left = t
t = TreeNode(v)
t.right = root.right
root.right = t
else:
dfs(root.left, h+1)
dfs(root.right, h+1)
dfs(root, 1)
return root


class Solution(object):
def smallestFactorization(self, a):
"""
:type a: int
:rtype: int
"""
ans = ''
for i in xrange(9, 1, -1):
t = 0
while a%i==0:
t += 1
a /= i
ans = str(i)*t + ans
ans = int(ans) if ans else 1
ans = ans if ans < 2**31 and a==1 else 0
return ans


(m-1)(n+1)+t

class Solution(object):
"""