#GL0000141. Mike và bài toán ƯCLN (Mike and gcd problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mike và bài toán ƯCLN (Mike and gcd problem)
Mike and gcd problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Mike has an array . An array is beautiful when the GCD of all its elements is greater than .
In one operation, choose adjacent positions . If their values were , replace them simultaneously, in that order, by and . Values may become zero or negative. Compute the GCD using absolute values; for example, the GCD of is .
Determine whether the array can become beautiful, and find the minimum number of operations if possible.
Input
The first line contains ; the second contains positive integers .
Output
Print YES if a beautiful array is achievable, otherwise NO. If you print YES, print the minimum number of operations on the second line. Preserve capitalization.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
2
1 3
Output
YES
1
Explanation
The original pair has GCD . One operation transforms into , whose GCD is . Since the initial array was not beautiful, one operation is optimal.