using
System;
using
System.Collections.Generic;
class
GFG {
static
void
robotSim(List<
int
> commands,
List<Tuple<
int
,
int
>> obstacles)
{
List<
int
> dx =
new
List<
int
>(
new
int
[]{ 0, 1, 0, -1 });
List<
int
> dy =
new
List<
int
>(
new
int
[]{ 1, 0, -1, 0 });
int
x = 0, y = 0;
int
di = 0;
Dictionary<Tuple<
int
,
int
>,
int
> obstacleSet =
new
Dictionary<Tuple<
int
,
int
>,
int
>();
foreach
(Tuple<
int
,
int
> i
in
obstacles)
obstacleSet[i] = 1;
int
ans = 0;
foreach
(
int
cmd
in
commands)
{
if
(cmd == -2)
di = (di - 1) % 4;
else
if
(cmd == -1)
di = (di + 1) % 4;
else
{
for
(
int
i = 0; i < cmd; i++)
{
if
(!obstacleSet.ContainsKey(
new
Tuple<
int
,
int
>(x + dx[di],
y + dy[di])))
{
x += dx[di];
y += dy[di];
ans = Math.Max(ans, x * x + y * y);
}
}
}
}
Console.WriteLine(ans);
}
static
void
Main()
{
List<
int
> commands =
new
List<
int
>(
new
int
[]{ 4, -1, 4, -2, 4 });
List<Tuple<
int
,
int
>> obstacles =
new
List<Tuple<
int
,
int
>>();
obstacles.Add(
new
Tuple<
int
,
int
>(2,4));
robotSim(commands, obstacles);
}
}