import
java.util.*;
class
GFG {
static
class
Line
implements
Comparable<Line> {
public
int
m, c;
public
Line(
int
m1,
int
c1)
{
m = m1;
c = c1;
}
public
int
compareTo(Line l)
{
if
(m != l.m)
return
-m + l.m;
else
return
-c + l.c;
}
public
boolean
check(Line L1, Line L2, Line L3)
{
return
(L3.c - L1.c) * (L1.m - L2.m)
< (L2.c - L1.c) * (L1.m - L3.m);
}
};
static
class
Convex_HULL_Trick {
ArrayList<Line> l;
public
Convex_HULL_Trick() { l =
new
ArrayList<Line>(); }
public
void
add(Line newLine)
{
int
n = l.size();
while
(
n >=
2
&& newLine.check(l.get(n -
2
), l.get(n -
1
), newLine)) {
n--;
}
l.add(newLine);
}
public
int
value(
int
ind,
int
x)
{
return
(l.get(ind)).m * x + (l.get(ind)).c;
}
public
int
maxQuery(
int
x)
{
if
(l.size() ==
0
)
return
Integer.MAX_VALUE;
int
low =
0
, high = (
int
)l.size() -
2
;
while
(low <= high) {
int
mid = (low + high) /
2
;
if
(value(mid, x) < value(mid +
1
, x))
low = mid +
1
;
else
high = mid -
1
;
}
return
value(low, x);
}
};
public
static
void
main(String[] args)
{
Line[] lines = {
new
Line(
1
,
1
),
new
Line(
0
,
0
),
new
Line(-
3
,
3
) };
int
[] Q = { -
2
,
2
,
1
};
int
n =
3
, q =
3
;
Convex_HULL_Trick cht =
new
Convex_HULL_Trick();
Arrays.sort(lines);
for
(
int
i =
0
; i < n; i++)
cht.add(lines[i]);
for
(
int
i =
0
; i < q; i++) {
int
x = Q[i];
System.out.println(cht.maxQuery(x));
}
}
}