Teams Formation CodeForces

来源:互联网 发布:国内域名不备案 编辑:程序博客网 时间:2024/05/01 20:02

This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus hasn passenger seats, seati can be occupied only by a participant from the cityai.

Today the bus has completed m trips, each time bringingn participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequencea1, a2, ..., an repeatedm times).

After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were nok neighboring participants from the same city.

Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.

Input

The first line contains three integers n, k andm (1 ≤ n ≤ 105,2 ≤ k ≤ 109,1 ≤ m ≤ 109).

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number of city, person from which must take seati in the bus.

Output

Output the number of remaining participants in the line.

Example
Input
4 2 51 2 3 1
Output
12
Input
1 9 101
Output
1
Input
3 2 101 2 1
Output
0
Note

In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.

很思维的一道题,我们的一般处理方法就是把每一个序列都分解为A+M+B形式
然后m次叠加,A和B可以消除,这样就可以分情况讨论一下
如果M内部的所有元素都是相同的,那么就有可能出现全部消除的情况,设M的长度为len,那么len*m%k==0的话,那么这个序列就是可以全部消除的序列
如果len*m%k!=0,那么中间会剩余len*m%k个序列,然后再加上A,B就是剩余长度
如果M内部的元素存在不同,那么M与M之间不可能继续消去,所以剩余长度就是len*m+A+B
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 换驾驶证c1一只眼不合格怎么办 考驾照紧张腿抖怎么办 驾照该换了色弱怎么办 怀孕5个月感冒咳嗽怎么办 怀孕4个月喉咙痛怎么办 怀孕5个多月总是咳嗽尿失禁怎么办 怀孕7个月感冒了怎么办 怀孕7个月感冒喉咙痛怎么办 孕38周感冒咳嗽喉咙痛怎么办 嗓子痛咳嗽有痰怎么办 怀孕6个月了咳嗽怎么办 怀孕了咳嗽黄痰怎么办 科二5次没考过怎么办 交警开的罚单丢了怎么办 驾驶员从业资格证被水洗了怎么办 驾照考五次没过怎么办 学车每次考不过怎么办 年检超期3个月怎么办 年检超过3个月怎么办 工商执照年检时候忘记密码怎么办 个体工商营业执照年检过期怎么办 忘了审车时间怎么办 汽车年检超过时间了怎么办 星巴克金星会员到期怎么办 驾考学员证丢了怎么办 违章扣满12分怎么办 违章扣满12分后怎么办 东方时尚驾校科二考不过怎么办 东方时尚科二科三考五次没过怎么办 不想考科目三了怎么办 科目三两次没过怎么办 练科目三很紧张怎么办 驾照学员卡丢了怎么办 驾考时考试的车系统出错怎么办 驾驶证超期6个月怎么办 北京汽车年检只有电子保单怎么办 交电费户号9位数怎么办 扬州驾照12分扣完了怎么办 有大专毕业证在深圳怎么办居住证 微信解释包错误怎么办 富士康离职不批怎么办