Little penguin Polo has an n × m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of row i and column j as aij.

In one move the penguin can add or subtract number d from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.

Input

The first line contains three integers n, m and d (1 ≤ n, m ≤ 100, 1 ≤ d ≤ 104) — the matrix sizes and the d parameter. Next n lines contain the matrix: the j-th integer in the i-th row is the matrix element aij (1 ≤ aij ≤ 104).

Output

In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).

Examples

Input

2 2 2
2 4
6 8


Output

4


Input

1 2 7
6 7


Output

-1
from os import path
import sys,time, collections as c , math as m , pprint as p
maxx , localsys , mod = float('inf'), 0 , int(1e9 + 7) 
if (path.exists('input.txt')):  sys.stdin=open('input.txt','r') ;   sys.stdout=open('output.txt','w')
input = sys.stdin.readline
n , m , k = map(int , input().split()) ; arr =[]
for _ in range(n):
    arr.extend(map(int , input().split()))
arr.sort()
med , x = arr[(n*m)//2] , 0
for i in range(n*m):
    x += abs(med - arr[i])
print(-1 if x % k else int(x//k))



        

#[1 , 2 ,5 ,5 , 7 , 100]

























# def ok(p , s):
#     cnt , need =0 , 0
#     for i in s:
#         if p[need] == i:
#             cnt+=1 ; need ^= 1
#     if cnt % 2 and p[0] != p[1]:
#         cnt-=1
#     return cnt

# for _ in range(int(input())):
#     s = input().rstrip('\n') ; n , ans = len(s) , maxx
#     for i in range(10):
#         for j in range(10):
#             ans = min(ans , n - ok((str(i) , str(j)), s))
#     print(ans)
#This problem was so easy oh gawd , so you can only make left cyclic shift = right cyclic shift , when there are at most
#2 characters
#(incase of 1 ch) at the same time if total string has only character it is valid no matter how you see it 
#(incase of 2 ch) all the characters at odd positions must be equal , and all the characters at even position must be equal





# n , k = map(int , input().split()) ; s = input().rstrip('\n')
# ans = a = b = j = 0
# for i in range(n):
#     a , b = (a+1 , b) if s[i] == 'a' else (a , b+1 )
#     if min(a, b) > k :
#         a , b = (a -1 , b) if s[j] == 'a' else (a , b -1) ; j+=1
#     else:
#         ans+=1
# print(ans)
# #two - pointer method , if at any point min(a , b )> k then keep on decreasing from the beginning untill and unless you get min(a , b) 
# #less than k