using
System;
class
GFG
{
static
int
__gcd(
int
a,
int
b)
{
if
(a == 0)
return
b;
if
(b == 0)
return
a;
if
(a == b)
return
a;
if
(a > b)
return
__gcd(a - b, b);
return
__gcd(a, b-a);
}
static
int
N = 705;
static
int
[,,]dp =
new
int
[N, N, 2];
static
int
possibleWithState(
int
l,
int
r,
int
state,
int
[]a)
{
if
(l > r)
return
1;
if
(dp[l, r, state] != -1)
return
dp[l, r, state];
int
root;
if
(state == 1)
root = a[r + 1];
else
root = a[l - 1];
for
(
int
i = l; i <= r; i++)
{
if
(__gcd(a[i], root) > 1)
{
int
x = possibleWithState(l, i - 1, 1, a);
if
(x != 1)
continue
;
int
y = possibleWithState(i + 1, r, 0, a);
if
(x == 1 && y == 1)
return
dp[l,r,state] = 1;
}
}
return
dp[l,r,state] = 0;
}
static
bool
isPossible(
int
[]a,
int
n)
{
for
(
int
i = 0; i < dp.GetLength(0); i++)
for
(
int
j = 0; j < dp.GetLength(1); j++)
for
(
int
k = 0; k < dp.GetLength(2); k++)
dp[i, j, k]=-1;
Array.Sort(a);
for
(
int
i = 0; i < n; i++)
if
(possibleWithState(0, i - 1, 1, a) != 0 &&
possibleWithState(i + 1, n - 1, 0, a) != 0)
{
return
true
;
}
return
false
;
}
public
static
void
Main(String []args)
{
int
[]a = { 3, 6, 9, 18, 36, 108 };
int
n = a.Length;
if
(isPossible(a, n))
Console.WriteLine(
"Yes"
);
else
Console.WriteLine(
"No"
);
}
}