#P9242. [蓝桥杯 2023 省 B] 接龙数列
[蓝桥杯 2023 省 B] 接龙数列
Problem Description
For an integer sequence of length : , we call it a chain sequence if and only if the first digit of is exactly equal to the last digit of ().
For example, is a chain sequence; is not a chain sequence, because the first digit of is not equal to the last digit of . All integer sequences of length are chain sequences.
Now you are given a sequence of length : . Please compute the minimum number of elements to delete so that the remaining sequence becomes a chain sequence.
Input Format
The first line contains an integer .
The second line contains integers .
Output Format
Output one integer representing the answer.
5
11 121 22 12 2023
1
Hint
Sample Explanation
Delete , and the remaining is a chain sequence.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, , . All are guaranteed to have no leading zeros.
Lanqiao Cup 2023 Provincial Contest Group B, Problem E.
Translated by ChatGPT 5