fun main(args: Array) { val (n,d,t) = readLine()!!.split(" ").map { it.toInt() } Ameba.d = d.toLong() Ameba.t = t.toLong() val ameba = readLine()!!.split(" ").map { n -> n.toLong().let { Ameba(it) } }.sorted() val amebaDic = mutableMapOf>() for(a in ameba) { if(!amebaDic.containsKey(a.group)) { amebaDic[a.group] = mutableListOf() } if(amebaDic[a.group]!!.isEmpty()) { amebaDic[a.group]!!.add(a) } else { if(amebaDic[a.group]!!.last().canUnion(a)) { amebaDic[a.group]!!.last().union(a) } else { amebaDic[a.group]!!.add(a) } } } val ans = amebaDic.values.map { list -> list.map { (it.to - it.from) / d + 1 }.sum() }.sum() println(ans) } class Ameba(init:Long):Comparable { companion object { var d = 0L var t = 0L } val group = (init%d + d)%d var from = init - d*t var to = init + d*t fun union(other:Ameba) { from = Math.min(from, other.from) to = Math.max(to, other.to) } fun canUnion(other: Ameba):Boolean { return (other.from in from..to) || (other.to in from..to) } override fun compareTo(other: Ameba): Int { return from.compareTo(other.from) } }