using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray(); int amebaCount = (int)inpt[0]; Ameba.Diff = inpt[1]; long jikan = inpt[2]; inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray(); List list = new List(); for(int i=0; i{ if(a.First < b.First) { return -1; } else if(a.First> b.First) { return 1; } return 0; }); while (list.Count > 1) { bool marged = false; int last = list.Count; for(int i=0; ilist[i].CanMarge(a)).ToArray(); if(target.Length > 1) { Ameba mg = new Ameba(list[i].First, list[i].Last); Ameba src = list[i]; target.ToList().ForEach(a=>mg = mg.Marget(a)); list.RemoveAll(a=>src.CanMarge(a)); list.Insert(i, mg); marged = true; break; } } if(!marged) { break; } } long ans = 0; list.ForEach(a=>ans+=a.Count()); Console.WriteLine(ans); } public class Ameba { public long First; public long Last; public static long Diff; public Ameba(long pos) { this.First = pos; this.Last = pos; } public Ameba(long first, long last) { this.First = first; this.Last = last; } public Ameba Marget(Ameba target) { Ameba mg = new Ameba(Math.Min(this.First,target.First), Math.Max(this.Last, target.Last)); return mg; } public long Count() { return (this.Last - this.First) / Diff + 1; } public void JikanKeika(long num) { this.First = this.First - (num * Diff); this.Last = this.Last + (num * Diff); } public bool CanMarge(Ameba target) { Ameba saki; Ameba ato; if(this.First < target.First) { saki = this; ato = target; } else if(this.First > target.First) { saki = target; ato = this; } else { return true; } if((ato.First - saki.First) % Diff > 0) { return false; } if(ato.First <= saki.Last) { return true; } if(ato.First - saki.Last == Diff) { return true; } return false; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 4 2 3 0 10 12 24 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }