Codeforces Round 505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
D
Recovering BST
Codeforces
2100
原题
← CE →
翻译中…

Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!

翻译中…

Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset.

翻译中…

To not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed $1$.

翻译中…

Help Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found here.

翻译中…

Input

翻译中…

The first line contains the number of vertices $n$ ($2 \le n \le 700$).

翻译中…

The second line features $n$ distinct integers $a_i$ ($2 \le a_i \le 10^9$) — the values of vertices in ascending order.

翻译中…

Output

翻译中…

If it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than $1$, print "Yes" (quotes for clarity).

翻译中…

Otherwise, print "No" (quotes for clarity).

翻译中…

Note

翻译中…

The picture below illustrates one of the possible trees for the first example.

翻译中…

image

翻译中…

The picture below illustrates one of the possible trees for the third example.

翻译中…

image

翻译中…

样例

Input #1
6
3 6 9 18 36 108
Output #1
Yes
InputCopy OutputCopy
Input #2
2
7 17
Output #2
No
InputCopy OutputCopy
Input #3
9
4 8 10 12 15 18 33 44 81
Output #3
Yes
InputCopy OutputCopy
题目信息
题号
1025D
时间限制
1 s
内存限制
256 MB
标签
暴力
动态规划
数学
数论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。