PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000053. Tách số và cộng K (Split Plus K)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tách số và cộng K (Split Plus K)

Split Plus K

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are n positive integers on the board and a positive constant k. In one operation, remove a value x and replace it with two positive integers y and z such that y+z=x+k. Determine the minimum number of operations needed until every number remaining on the board is equal. Print -1 if impossible. Zero operations are allowed.

Input

First line: n k. Second line: n positive integers a_i.

Output

The minimum number of operations, or -1 if impossible.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8, 1≤k,ai≤301\le k,a_i\le 30.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000, 1≤k,ai≤1061\le k,a_i\le 10^6.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5, 1≤k,ai≤10121\le k,a_i\le 10^{12}.

Examples

Input

2 1
3 4

Output

3

Explanation

Splitting 4 into 2 and 3, then splitting each 3 into two 2s, uses exactly three operations.