No.3286 Make a Happy Connection
Problem Statement
yuki feels happy when equal values appear next to each other in a sequence.
You are given a sequence $A$ consisting of $N$ elements. Determine whether, by swapping adjacent elements of $A$ exactly $1$ time, you can make at least $1$ place where adjacent elements have the same value.
More formally, you perform the following operation exactly $1$ time.
- Choose any $i$ $(1 \le i \le N-1)$ and swap $A_i,A_{i+1}$.
Considering $j$ such that $1 \le j \le N-1$, determine whether you can make it so that, after the operation, there exists $j$ such that $A_j = A_{j+1}$.
Constraints
- $2 \le N \le 500$
- $1 \le A_i \le 100$
- All inputs are integers.
Input
The input is given from standard input in the following format.
$N$ $A_1\ A_2\ \cdots\ A_N$
Output
Print Yes if the condition is satisfied, and No otherwise. Print a newline at the end.
Sample
Sample 1
Input
4 1 3 2 3
Output
Yes
Performing the operation with $i=3$ swaps $A_3 $ and $A_4$, resulting in $A=(1,3,3,2)$. Here $A_2=3$, $A_3=3$, so equal elements are next to each other and the condition is satisfied.
Sample 2
Input
5 1 1 1 1 1
Output
Yes
The condition is satisfied no matter how you perform the operation.
Sample 3
Input
5 1 2 3 4 1
Output
No
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
kona0001
drken1215