object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n,m = s.nextInt
		val c = Array.fill(100001)(0)
		for(_ <- 1 to n)
			c(s.nextInt) += 1
		val a,b = Array.fill(m)(0)
		for(i <- 1 to 100000) {
			a(i % m) += c(i) % 2
			b(i % m) += c(i) / 2
		}
		println(a.mkString(" "))
		println(b.mkString(" "))
		var r = 0
		for(i <- 0 until m) {
			if(i * 2 % m == 0) {
				r += a(i) / 2
				a(i) %= 2
			} else {
				{
					val t = math.min(a(i),a(m - i))
					r += t
					a(i) -= t
					a(m - i) -= t
				}
				{
					val t = math.min(a(i) / 2,b(m - i))
					r += t * 2
					a(i) -= t * 2
					b(m - i) -= t
				}
			}
		}
		for(i <- 0 until m) {
			r += b(i)
			b(i) = 0
		}
		//println(a.mkString(" "))
		//println(b.mkString(" "))
		println(r)
	}
}
