Teams Formation CodeForces - 878B 思维

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, seat i can be occupied only by a participant from the city ai.

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 sequence a1, 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 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值