#P11997. Optimal Breakfast Energy

    ID: 14099 Type: Default 1000ms 256MiB

Optimal Breakfast Energy

Optimal Breakfast Energy

Little Blue is preparing for the Lanqiao Cup and decided to have a hearty breakfast before the contest. In the school cafeteria, there are n breads, m sausage packages, and k milk boxes. Each item gives Little Blue a non-zero "appetite" value. The breads are associated with an array \( a = [a_1, a_2, \dots, a_n] \), the sausages with \( b = [b_1, b_2, \dots, b_m] \), and the milks with \( c = [c_1, c_2, \dots, c_k] \).

When Little Blue buys the \( i\)th bread, \( j\)th sausage package, and \( t\)th milk box, after having his breakfast, he gains an energy of

[ E = (a_i \times b_j) \bmod c_t ]

Your task is to help him choose one item from each category such that the energy \( E \) is maximized. Determine this maximum energy.

inputFormat

The first line contains three integers \( n \), \( m \), and \( k \) separated by spaces.

The second line contains \( n \) positive integers representing the array \( a \) (the appetite values for breads).

The third line contains \( m \) positive integers representing the array \( b \) (the appetite values for sausages).

The fourth line contains \( k \) positive integers representing the array \( c \) (the appetite values for milks). Note that no element in \( a \), \( b \), or \( c \) is zero.

outputFormat

Output a single integer, the maximum energy that Little Blue can gain.

sample

3 3 3
1 2 3
1 2 3
2 3 4
3