import sys from operator import add inp sys stdin num int inp readline

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
from operator import add
inp = sys.stdin
num = int(inp.readline())
def scalar_pr(x, y):
return reduce(add, map(lambda (x,y): x*y, zip(x,y)))
def perms(x):
l = len(x)
for i in range(l):
for j in range(l):
for k in range(l):
for n in range(l):
r = x[:]
r[i], r[j] = r[j], r[i]
r[k], r[n] = r[n], r[k]
yield r
for i in range(num):
n = int(inp.readline())
x = map(int, inp.readline().split())
y = map(int, inp.readline().split())
assert len(x) == len(y) == n
m = None
for q in perms(x):
r = scalar_pr(q, y)
if m is None or m > r:
m = r
print "Case #%d: %d" % (i+1, m)