Simon has a prime number x and an array of non-negative integers a1, a2, ..., an.

Simon loves fractions very much. Today he wrote out number <image> on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: <image>, where number t equals xa1 + a2 + ... + an. Now Simon wants to reduce the resulting fraction. 

Help him, find the greatest common divisor of numbers s and t. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109 + 7).

Input

The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number.

The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109). 

Output

Print a single number — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

2 2
2 2


Output

8


Input

3 3
1 2 3


Output

27


Input

2 2
29 29


Output

73741817


Input

4 5
0 0 0 0


Output

1

Note

In the first sample <image>. Thus, the answer to the problem is 8.

In the second sample, <image>. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.

In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.

In the fourth sample <image>. Thus, the answer to the problem is 1.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CPrimeNumber solver = new CPrimeNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class CPrimeNumber {
        int mod = 1000000007;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

            long x = in.nextInt();

            int[] a = in.nextIntArray(n);


            int max = a[n - 1];

            Map<Integer, Integer> map = new HashMap<>();

            long tot = 0;
            for (int val : a) {
                tot += val;
                map.merge(val, 1, (x1, y) -> x1 + y);
            }

            PriorityQueue<ele> eles = new PriorityQueue<>((p1, p2) -> (int) Math.signum(p1.times - p2.times));


            for (int key : map.keySet()) {
                int val = map.get(key);

                int t = 0;
                while (val % x == 0) {
                    val /= x;
                    t++;
                }
                eles.add(new ele(tot - key + t, val));
            }

            long ans = eles.peek().times;

            long sum = 0;
            while (!eles.isEmpty()) {
                ele pe = eles.poll();

                if (pe.times == ans) {
                    sum += pe.mul;
                } else {
                    int t = 0;
                    while (sum % x == 0) {
                        sum /= x;
                        t++;
                    }

                    if (t == 0) {
                        //out.println(Math.min(ans, tot));
                        //return;
                        break;
                    }

                    eles.add(pe);
                    eles.add(new ele(ans + t, sum));
                    ans = eles.peek().times;
                    sum = 0;
                }
            }

            if (sum > 0) {
                int t = 0;
                while (sum % x == 0) {
                    sum /= x;
                    t++;
                }

                ans += t;
            }
            out.println(pow(x, Math.min(ans, tot), mod));

//        long sum = 0;
//
//        long max = -1;
//
//        int maxt = 0;
//
//        Map<Integer, Integer> map = new HashMap<>();
//
//        for (int val : a) {
//            sum += val;
//
//
//            map.merge(val, 1, (x1, y) -> x1 + y);
//            if (val > max) {
//                max = val;
//                maxt = 1;
//            } else if (val == max) {
//                maxt++;
//            }
//        }
//
//        sum -= max;
//
//        long ans = pow(x, sum, mod);
//
//        long gcd = map.get((int) max);
//
//        for (int key : map.keySet()) {
//            gcd = gcd(gcd, map.get(key));
//        }
//
//        long t = 0;
//
//        long tgcd = gcd;
//        while (gcd % x == 0) {
//            gcd /= x;
//            t++;
//        }
//
//        t = Math.min(t, max);
//
//        ans *= pow(x, t, mod);
//
//        ans %= mod;
//
//        //long mint = map.get(a[0]);
//
//        long cmax = maxt / tgcd;
//
//        long xt = 0;
//
//        long tcmax = cmax;
//        while (tcmax % x == 0) {
//            tcmax /= x;
//            xt++;
//        }
//
//        for (int key : map.keySet()) {
//            int val = map.get(key);
//
//            long min = val / tgcd;
//
//            long time = max - key;
//
////            for (int i = 0; i < Math.min(xt, time); i++) {
////                if (min < cmax) {
////                    min *= x;
////                } else break;
////            }
//
//            long cxt = 0;
//
//            while (min % x == 0) {
//                min /= x;
//                cxt++;
//            }
//
//            cxt += time;
//
//            xt = Math.min(xt, cxt);
//
//            //ngcd = gcd(ngcd, min);
//
//        }
//
////        long nt = 0;
////
////        while (ngcd % x == 0) {
////            ngcd /= x;
////            nt++;
////        }
////
//        xt = Math.max(0, Math.min(xt, max - t));
//
//        ans *= pow(x, xt, mod);
//
//        ans %= mod;
//
//        out.println(ans);
        }

        long pow(long a, long p, int mod) {
            if (p == 0) {
                return 1;
            }

            long t = pow(a, p / 2, mod);

            if (p % 2 != 0) {
                return (((t * t) % mod) * a) % mod;
            } else {
                return (t * t) % mod;
            }
        }

        class ele {
            long times;
            long mul;

            public ele(long times, long mul) {
                this.times = times;
                this.mul = mul;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}

