''' 可惜了,最后两题sql不会写。。。 提供下第二题的一种方法: ''' cnt = [int(i) for i in input().split()] ret = [] for i in range(10): #将备选数字从小到大排好 if cnt[i]: ret.extend([i] * cnt[i]) a, b = int(input()), int(input()) if a > b: #保证a的位数比b小 a, b = b, a left, right = 0, 0 #最终两个数字 while a: # 对left,right逐步填入各位的数字 tmp = ret.pop(0) if (left*10+tmp) <= (right*10+tmp): #判断当前数字填入哪一边 left = left*10+tmp a -= 1 else: right = right*10+tmp b -= 1 while b: # 若right还未填满,将剩下数字按需填入 right = right*10+ret.pop(0) b -= 1 print(left * right)