欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1119A.Ilya and a Colorful Walk
Ilya and a Colorful Walk
Ilya lives in a beautiful city of Chordalsk.
There are houses on the street Ilya lives, they are numerated from to from left to right; the distance between every two neighboring houses is equal to unit. The neighboring houses are and , and , ..., and . The houses and are not neighboring.
The houses are colored in colors so that the -th house is colored in the color . Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors.
Ilya wants to select two houses and so that , and they have different colors: . He will then walk from the house to the house the distance of units.
Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible.
Help Ilya, find this maximum possible distance.
Input
The first line contains a single integer () — the number of cities on the street.
The second line contains integers () — the colors of the houses.
It is guaranteed that there is at least one pair of indices and so that and .
Output
Print a single integer — the maximum possible distance Ilya can walk.
Note
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 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 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 units.
Samples
5
1 2 3 2 3
4
3
1 2 1
1
7
1 1 3 1 1 1 1
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |