CF1119A Ilya and a Colorful Walk

题目描述

ilya 有很多房子,每个房子都有一个颜色。因为 ilya 喜欢散步,所以想要选最远的两个不同颜色的房子作为散步的起点和终点。输出这个最远距离。

输入格式

第一行一个整数 $n$,表示有多少房子。 第二行 $n$ 个整数,表示颜色,相同的数字表示相同的颜色,不同的数字表示不同的颜色。

输出格式

输出最大距离。

说明/提示

In the first example the optimal way is to walk from the first house to the last one, where Ilya can walk the distance of $ 5-1 = 4 $ units. In the second example the optimal way is to either walk from the first house to the second or from the second to the third. Both these ways have the distance of $ 1 $ unit. In the third example the optimal way is to walk from the third house to the last one, where Ilya can walk the distance of $ 7-3 = 4 $ units.