import java.util.*;

public class Quiz{
	static int MOD = (int)1e9 + 9;
	public static void main(String[] args){
		Scanner reader = new Scanner(System.in);
		long n = reader.nextInt();
		long m = reader.nextInt();
		long k = reader.nextInt();

		long r = (n + k - 1)/k;

		long longDrops = n%k;

		if(longDrops == 0){
			long d = m - (r * (k-1));

			if(d <= 0){
				System.out.println(m);
				return;
			}

			long sum = (fastExpo(2,d+1)-2) * k + (m - d*k);
			System.out.println((sum+MOD)%MOD);
		}else{
			long d = (m-longDrops*r) - (r-1)*(k-longDrops-1);

			if(d <= 0){
				System.out.println(m);
				return;
			}

			long sum = (fastExpo(2,d+1)-2) * k + (m - d*k);
			System.out.println((sum+MOD)%MOD);
		}
	}

	public static long fastExpo(long b, long p){
		if(p == 0)
			return 1;
		if(p % 2 == 1)
			return (b * fastExpo(b, p-1))%MOD;
		long x = fastExpo(b, p/2);
		return (x * x)%MOD;
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class cf337c {
  static long mod,n,m,k;
  public static void main(String[] args) {
    FastIO in = new FastIO(), out = in;
    n = in.nextLong();
    m = in.nextLong();
    k = in.nextLong();
    mod = (long)1e9 + 9;
    long x = m - (n-n%k)/k * (k-1) - n%k;
    if(x < 0) x = 0;
    long ans = (pow(2,x+1)-2)*k + m-x*k;
    ans = ((ans%mod)+mod)%mod;
    out.println(ans);
    out.close();
  }
  static long pow(long x, long p) {
    if(p == 0) return 1%mod;
    long ans = pow(x,p/2);
    ans = (ans*ans)%mod;
    if(p%2 == 1) ans = (ans*x)%mod;
    return ans;
  }
  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in,System.out);
    }
    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }
    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch(Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }
    public int numTokens() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }
    public String next() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }
    public double nextDouble() {
      return Double.parseDouble(next());
    }
    public long nextLong() {
      return Long.parseLong(next());
    }
    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


import java.math.BigInteger;
import java.util.*;

public class A {
	private static Scanner in;

	final int M = 1000000009;

	public void run() {
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int z = n - m;
		if (z >= n / k) {
			System.out.println(m);
			return;
		}
		int f = n - k * z;
		int ans = BigInteger.ONE.shiftLeft(f / k + 1).remainder(BigInteger.valueOf(M)).intValue();
		System.out.println(((ans + M - 2L) * k + (f % k + (k - 1) * z)) % M);
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		in = new Scanner(System.in);
		new A().run();
		in.close();
	}
}


import java.io.*;
import java.util.*;

public class CF {

	long mod = (long) 1e9 + 9;

	class Pair {
		long a, b;

		public Pair(long a, long b) {
			super();
			this.a = a % mod;
			this.b = b % mod;
		}

	}

	int k;

	long pow(long n, long k) {
		if (k == 0)
			return 1;
		long m1 = pow(n, k / 2);
		m1 = (m1 * m1) % mod;
		if (k % 2 != 0)
			m1 = (m1 * n) % mod;
		return m1;
	}

	long st(int n, int m, int k) {
		int parts = n / k;
		int used = n - m;
		if (parts > n - m) {
			long cur = 0;
			int counter = 0;
			int need = parts - (n - m);
			for (int i = 1; i <= n; i++) {
				if (counter + 1 == k && need <= 0) {
					counter = 0;
					used--;
				} else {
					counter++;
					cur++;
					if (counter == k) {
						counter = 0;
						cur = (cur * 2) % mod;
						need--;
					}
				}
			}
			if (used < 0)
				throw new AssertionError();
			return cur;
		} else {
			return m;
		}
	}

	long mysol(int n, int m, int k) {
		this.k = k;
		int parts = n / k;
		if (parts > n - m) {
			long ost = n - (n - m) * k;
			long power = ost / k;
			long res = pow(2, power + 1);
			long cur = ((res - 2 + mod) % mod) * k;
			cur %= mod;
			cur += Math.max(0, m - power * k);
			cur %= mod;
			return cur;
		} else {
			return m;
		}
	}

	void realSolve() throws IOException {
		 int n = in.nextInt();
		 int m = in.nextInt();
		 k = in.nextInt();
		 out.println(mysol(n, m, k));
		/*Random rnd = new Random(123);
		for (int t = 0; t < 10000; t++) {
			System.err.println(t);
			int n = rnd.nextInt(100) + 2;
			int m = rnd.nextInt(n + 1);
			int k = rnd.nextInt(n - 1) + 2;

			if (t == 16) {
				System.err.println("!");
			}
			long r1 = mysol(n, m, k);
			long r2 = st(n, m, k);
			if (r1 != r2)
				throw new AssertionError(r1 + " " + r2);

		}*/
	}

	private class InputReader {
		StringTokenizer st;
		BufferedReader br;

		public InputReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public InputReader(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				String s;
				try {
					s = br.readLine();
				} catch (IOException e) {
					return null;
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		boolean hasMoreElements() {
			while (st == null || !st.hasMoreElements()) {
				String s;
				try {
					s = br.readLine();
				} catch (IOException e) {
					return false;
				}
				st = new StringTokenizer(s);
			}
			return st.hasMoreElements();
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

	InputReader in;
	PrintWriter out;

	void solveIO() throws IOException {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);

		realSolve();

		out.close();

	}

	void solve() throws IOException {
		in = new InputReader(new File("input.txt"));
		out = new PrintWriter(new File("output.txt"));

		realSolve();

		out.close();

	}

	public static void main(String[] args) throws IOException {
		new CF().solveIO();
	}
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class A{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int mod=(int)1e9+9;

	long n, m, k;

	void run(){
		n=sc.nextLong();
		m=sc.nextLong();
		k=sc.nextLong();
		solve();
	}

	void solve(){
		long ans=0;
		long s=n-m;
		long remain=max(n-s*k, 0);
//		debug("remain", remain);
		ans=m-remain;
//		debug("ans", ans);
		long r=remain%k;
		ans=(ans+r)%mod;
		remain-=r;
//		debug("remain2", remain);
		long a=remain/k;
		long add=(powMod(2, a, mod)-1)*k%mod*2%mod;
//		debug("add", add);
		ans=(ans+add)%mod;
//		debug(ans);
		println(ans+"");
	}

	long powMod(long x, long k, long mod){
		if(k==0){
			return 1%mod;
		}else if(k%2==0){
			return powMod(x*x%mod, k/2, mod);
		}else{
			return x*powMod(x, k-1, mod)%mod;
		}
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args){
		Locale.setDefault(Locale.US);
		new A().run();
	}
}


//package round196;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class A {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	public static long pow(long a, long n, long mod)
	{
//		a %= mod;
		long ret = 1;
		int x = 63-Long.numberOfLeadingZeros(n);
		for(;x >= 0;x--){
			ret = ret * ret % mod;
			if(n<<63-x<0)ret = ret * a % mod;
		}
		return ret;
	}

	void solve()
	{
		int n = ni(), m = ni(), K = ni();
		if(m <= n/K*(K-1)+n%K){
			out.println(m);
		}else{
			int mod = 1000000009;
			int f = m - (n/K*(K-1)+n%K);
			out.println(((pow(2, f+1, mod) + mod - 2) * K + (m - f*K)) % mod);
		}
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new A().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class C {
    private static BufferedReader in;
    private static StringTokenizer st;
    private static PrintWriter out;

    public static void main(String[] args) throws NumberFormatException, IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        int mod = (int) (1e9+9);
        int correct = n - n / k;
        int carry = n % k;
        long ans;
        if(correct >= m){
            ans = m;
        }else{
            m -= correct;
            int block = n / k;
            BigInteger pow = BigInteger.valueOf(2).modPow(BigInteger.valueOf(m + 1), BigInteger.valueOf(mod));
            ans = (pow.longValue() - 2 + mod) % mod;
            ans = (ans * (long) k) % mod;
            ans = (ans + (long)(block - m)* (long)(k-1) + carry) % mod;
        }
        System.out.println(ans);

    }

    static String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
    static int nextInt() throws NumberFormatException, IOException{
        return Integer.parseInt(next());
    }
    static long nextLong() throws NumberFormatException, IOException{
        return Long.parseLong(next());
    }

    static double nextDouble() throws NumberFormatException, IOException{
        return Double.parseDouble(next());
    }

}


import java.io.*;
import java.util.*;

public class History {
	static final int INF = (int)1E9;
	static final double EPS = 1E-9;
	static final long MOD = INF + 9;

	static long powmod(long p) {
		long res = 1;
		long d = 2;
		while (p > 0) {
			if (p % 2 == 1) {
				res = (res * d) % MOD;
				p--;
			}
			else {
				d = (d * d) % MOD;
				p /= 2;
			}
		}
		return res % MOD;
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		long n = in.nextLong();
		long m = in.nextLong();
		long k = in.nextLong();

		long ans = 0;

		long t = (k - 1) * (n - m);

		if (t <= m) {
			n -= k * (n - m);

			long g = n / k;

			ans = 2 * k * (powmod(g) - 1) + n % k;

			ans = (ans + t) % MOD;
		}
		else {
			ans = m;
		}

		System.out.println(ans % MOD);
	}
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
    	return Long.parseLong(next());
    };
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 * Created by hama_du on 15/09/10.
 */
public class A {
    private static final long MOD = 1000000009;

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        long n = in.nextInt();
        long correct = in.nextInt();
        long k = in.nextInt();
        long wrong = n - correct;
        long set = wrong * k + k - 1;
        if (set >= n) {
            out.println(correct);
        } else {
            long needExtraCorrect = n - (wrong * k + k - 1);
            long firstSet = needExtraCorrect + k - 1;
            long otherSet = correct - firstSet;

            long firstDouble = firstSet / k;
            otherSet += firstSet % k;
            long[][] mat = new long[][]{ {2, 2*k}, {0, 1}};
            long[][] A = pow(mat, firstDouble, MOD);
            long score = (A[0][1] + otherSet) % MOD;
            out.println(score);
        }
        out.flush();
    }

    public static long[][] pow(long[][] a, long n, long mod) {
        long i = 1;
        long[][] res = E(a.length);
        long[][] ap = mul(E(a.length), a, mod);
        while (i <= n) {
            if ((n & i) >= 1) {
                res = mul(res, ap, mod);
            }
            i *= 2;
            ap = mul(ap, ap, mod);
        }
        return res;
    }

    public static long[][] E(int n) {
        long[][] a = new long[n][n];
        for (int i = 0 ; i < n ; i++) {
            a[i][i] = 1;
        }
        return a;
    }

    public static long[][] mul(long[][] a, long[][] b, long mod) {
        long[][] c = new long[a.length][b[0].length];
        if (a[0].length != b.length) {
            System.err.print("err");
        }
        for (int i = 0 ; i < a.length ; i++) {
            for (int j = 0 ; j < b[0].length ; j++) {
                long sum = 0;
                for (int k = 0 ; k < a[0].length ; k++) {
                    sum = (sum + a[i][k] * b[k][j]) % mod;
                }
                c[i][j] = sum;
            }
        }
        return c;
    }

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

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

        private int next() {
            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 char nextChar() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            if ('a' <= c && c <= 'z') {
                return (char) c;
            }
            if ('A' <= c && c <= 'Z') {
                return (char) c;
            }
            throw new InputMismatchException();
        }

        public String nextToken() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

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

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

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

    static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}


import java.io.*;
import java.util.StringTokenizer;

public class A {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void solve() throws IOException {
		final int mod = 1000*1000*1000+9;
		long n = readInt();
		long m = readInt();
		long k = readInt();
		long fail = n-m;
		long posl = n / k ;
		if(n % k != 0) {
			posl++;
		}
		if(posl <= fail) {
			out.println(m);
		} else {
			long d = fail - posl;
			long res = (k-1) * fail;
			m -= (k-1) * fail;
			long z = m / k;
			res += m % k;
			res %= mod;
			long x = binpow(2, z+1, mod);
			x -= 2;
			x += mod;
			x %= mod;
			x *= k;
			res += x;
			res %= mod;
			out.println(res);
		}
    }

	long binpow (long a, long n, long mod) {
		long res = 1;
		while (n != 0)
			if ((n & 1) != 0) {
				res *= a;
				res = res % mod;
				--n;
			}
			else {
				a *= a;
				a = a % mod;
				n >>= 1;
			}
		return res;
	}

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

    public static void main(String[] args) {
        new A().run();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class A {

	static StringTokenizer st;
	static BufferedReader in;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//		long a = 2;
//		int q = nextInt();
//		long sum = a;
//		int s = q;
//		for (int i = 2; i <= s; i++) {
//			a = a*2+2;
//			sum += a;
//		}
//		System.out.println(sum);
//		System.out.println((4*((long)Math.pow(2, s)-1)-2*s));
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		long t = (long)(n-m) * k;
		int mod = (int) (1e9+9);
		long ans = 0;
		int x = m / (k-1);
		if (m % (k-1) != 0)
			x++;
		if (n-m < x-1) {
			int s = (int) (n - t);
			int cnt = s / k;
			ans = BigInteger.valueOf(2).modPow(BigInteger.valueOf(cnt+1), BigInteger.valueOf(mod)).longValue();
			ans = (ans-2+mod) % mod;
//			ans = ans * 4 % mod;
//			ans = (ans-2*cnt+2*mod) % mod;
			ans = ans * k % mod;
			ans = (ans+(long)(k-1) * (n-m) % mod) % mod;
			ans = (ans+s % k) % mod;
		}
		else
			ans = m;
		System.out.println(ans);
		pw.close();
	}
	private static int nextInt() throws IOException{
		return Integer.parseInt(next());
	}

	private static long nextLong() throws IOException{
		return Long.parseLong(next());
	}

	private static double nextDouble() throws IOException{
		return Double.parseDouble(next());
	}

	private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}


import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigDecimal;
import java.math.BigInteger;

import static java.lang.Math.*;

// Solution is at the bottom of code

public class _____A implements Runnable{

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	OutputWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args){
		new Thread(null, new _____A(), "", 128 * (1L << 20)).start();
	}

	/////////////////////////////////////////////////////////////////////

	void init() throws FileNotFoundException{
		Locale.setDefault(Locale.US);

		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new OutputWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new OutputWriter("output.txt");
		}
	}

	////////////////////////////////////////////////////////////////

	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	void debug(Object... objects){
		if (ONLINE_JUDGE){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}

	/////////////////////////////////////////////////////////////////////

	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			Locale.setDefault(Locale.US);

			init();
			solve();

			out.close();
			time();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	/////////////////////////////////////////////////////////////////////

	String delim = " ";

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}

		return tok.nextToken(delim);
	}

	String readLine() throws IOException{
		return in.readLine();
	}

	/////////////////////////////////////////////////////////////////

	final char NOT_A_SYMBOL = '\0';

	char readChar() throws IOException{
		int intValue = in.read();

		if (intValue == -1){
			return NOT_A_SYMBOL;
		}

		return (char) intValue;
	}

	char[] readCharArray() throws IOException{
		return readLine().toCharArray();
	}

	/////////////////////////////////////////////////////////////////

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException{
		int[] array = new int[size];

		for (int index = 0; index < size; ++index){
			array[index] = readInt();
		}

		return array;
	}

	///////////////////////////////////////////////////////////////////

	long readLong() throws IOException{
		return Long.parseLong(readString());
	}

	long[] readLongArray(int size) throws IOException{
		long[] array = new long[size];

		for (int index = 0; index < size; ++index){
			array[index] = readLong();
		}

		return array;
	}

	////////////////////////////////////////////////////////////////////

	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}

	double[] readDoubleArray(int size) throws IOException{
		double[] array = new double[size];

		for (int index = 0; index < size; ++index){
			array[index] = readDouble();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	Point readPoint() throws IOException{
		int x = readInt();
		int y = readInt();
		return new Point(x, y);
	}

	Point[] readPointArray(int size) throws IOException{
		Point[] array = new Point[size];

		for (int index = 0; index < size; ++index){
			array[index] = readPoint();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
	throws IOException{
		List<Integer>[] graph = new List[vertexNumber];

		for (int index = 0; index < vertexNumber; ++index){
			graph[index] = new ArrayList<Integer>();
		}

		while (edgeNumber-- > 0){
			int from = readInt() - 1;
			int to = readInt() - 1;

			graph[from].add(to);
			graph[to].add(from);
		}

		return graph;
	}

	/////////////////////////////////////////////////////////////////////

	class OutputWriter extends PrintWriter{

		final int DEFAULT_PRECISION = 12;

		int precision;
		String format, formatWithSpace;

		{
			precision = DEFAULT_PRECISION;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		public OutputWriter(OutputStream out) {
			super(out);
		}

		public OutputWriter(String fileName) throws FileNotFoundException {
			super(fileName);
		}

		public int getPrecision() {
			return precision;
		}

		public void setPrecision(int precision) {
			this.precision = precision;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		private String createFormat(int precision){
			return "%." + precision + "f";
		}

		@Override
		public void print(double d){
			printf(format, d);
		}

		public void printWithSpace(double d){
			printf(formatWithSpace, d);
		}

		public void printAll(double...d){
			for (int i = 0; i < d.length - 1; ++i){
				printWithSpace(d[i]);
			}

			print(d[d.length - 1]);
		}

		@Override
		public void println(double d){
			printlnAll(d);
		}

		public void printlnAll(double... d){
			printAll(d);
			println();
		}
	}

	/////////////////////////////////////////////////////////////////////

	int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	int[][] steps8 = {
			{-1, 0}, {1, 0}, {0, -1}, {0, 1},
			{-1, -1}, {1, 1}, {1, -1}, {-1, 1}
	};

	boolean check(int index, int lim){
		return (0 <= index && index < lim);
	}

	/////////////////////////////////////////////////////////////////////

	boolean checkBit(int mask, int bitNumber){
		return (mask & (1 << bitNumber)) != 0;
	}

	/////////////////////////////////////////////////////////////////////

	long md = (1000 * 1000 * 1000 + 9);

	void solve() throws IOException{
		int n = readInt();
		int m = readInt();
		int k = readInt();

		long count = n / k;
		long mod = n % k;

		long maxM = count * (k - 1) + mod;
		if (maxM >= m) {
			out.println(m % md);
			return;
		}

		long d = m - maxM;
		long mul = (binpow(2, d) - 1 + md) % md * 2 % md;

		long ans = (mul * k) % md;
		ans = (ans + ((count - d) * (k - 1) % md + md) % md + mod) % md;

		out.println(ans);
	}

	long binpow(long a, long n) {
		if (n == 0) return 1;
		if ((n & 1) == 0) {
			long b = binpow(a, n >> 1);
			return (b * b) % md;
		} else {
			return binpow(a, n - 1) * a % md;
		}
	}
}


import java.math.BigInteger;
import java.util.*;

public class A {
	private static Scanner in;

	final int M = 1000000009;

	public void run() {
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int z = n - m;
		if (z >= n / k) {
			System.out.println(m);
			return;
		}
		int f = n - k * z;
		int last = f % k + (k - 1) * z;
		f /= k;
		int ans = BigInteger.ONE.shiftLeft(f + 1).remainder(BigInteger.valueOf(M)).intValue();
		System.out.println(((ans + M - 2L) * k + last) % M);
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		in = new Scanner(System.in);
		new A().run();
		in.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class CFC {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "Yes";
    private static final String no = "No";

    void solve() throws IOException {
        long x = nextLong();
        long k = nextLong();
        if (x == 0) {
            outln(0);
            return;
        }
        x %= MOD;
        long two = powMod(2, k, MOD);
        long res = two;
        res *= 2;
        res %= MOD;
        res *= x;
        res %= MOD;
        res -= two - 1;
        while (res < 0) {
            res += MOD;
        }
        while (res >= MOD) {
            res -= MOD;
        }

        outln(res);
    }

    public long powMod(long N, long M, long MOD){//N^M % MOD
        if(M == 0L)
            return 1L;
        long[] hp = new long[64];
        boolean[] bp = new boolean[64];
        hp[0] = N;
        for(int i = 1; i < hp.length; i++) {
            hp[i] = (hp[i - 1] * hp[i - 1]) % MOD;
        }
        for(int j = 0; j < hp.length; j++) {
            if((M & (1L << j)) != 0)
                bp[j] = true;
        }
        long res = 1;
        for(int i = 0;i < bp.length; i++){
            if(bp[i]) {
                res = (res * hp[i]) % MOD;
            }
        }
        return res;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFC() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFC();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


import java.util.Scanner;

public class R489C {
	static long MOD=(long)1e9+7;
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		long n=scan.nextLong(), k=scan.nextLong();
		if(n==0) {
			System.out.println(0);
			return;
		}
		long x=2*n-1;
		long e=exp(2,k);
		System.out.println((x%MOD*e%MOD+1)%MOD);
	}
	public static long exp(long x, long e) {
		long res=1;

		while (e>0)	{
			if(e%2==1) res=(res*x)%MOD;

			e/=2;
			x=(x*x)%MOD;
		}
		return res;
	}
}


import java.io.*;
import java.util.*;

public class Main {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		long n = scn.nextLong(), k = scn.nextLong(), mod = (int)1e9 + 7;
		if(n == 0) {
			out.println(0);
			return;
		}
		n %= mod;
		long x = (pow(2, k + 1, mod) * n) % mod;
		long y = (pow(2, k, mod) + mod - 1) % mod;

		long ans = ((x - y) % mod + mod) % mod;
		out.println(ans);
	}

	long pow(long a, long x, long m) {
		if(x == 0) {
			return 1;
		}
		long p = pow(a, x / 2, m);
		p *= p;
		p %= m;
		if(x % 2 == 1) {
			p *= a;
			p %= m;
		}
		return p;
	}

	long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	void run() throws Exception {
		boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(onlineJudge);
		long time = System.currentTimeMillis();
		solve();
		out.flush();
		if (!onlineJudge) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextArray(int n, boolean isOneInd) {
			int k = isOneInd ? 1 : 0;
			int[] a = new int[n + k];
			for (int i = k; i < n + k; i++)
				a[i] = nextInt();
			return a;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * Created by aditya on 5/3/17.
 */
public class Main3 {

    static long x, k;
    static long MOD = (long)1e9 + 7;

    public static void main(String args[]) throws Exception{
        FastInput fi = new FastInput(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        x = fi.nextLong();
        k = fi.nextLong();

        if(x == 0) {
            System.out.println(0);
            return;
        }

//        System.out.println(pow(2, k+1));
        long q1 = (pow(2, k+1) * (x%MOD)) % MOD;
        long q2 = pow(2, k);
        long q3 = 1;
//        System.out.println(q1);
//        System.out.println(q2);
//        System.out.println(q3);

        long exp = (q1-q2 + MOD + MOD)%MOD;
        exp = (exp + q3)%MOD;

//        exp = (exp*2)%MOD;

        pw.println(exp);

        pw.close();
    }

    static long pow(long n, long k) {
        if(k == 0)
            return 1;
        if(k == 1)
            return n;
        long ret = pow(n, k/2)%MOD;
        ret = (ret*ret)%MOD;
        if(k%2 == 1)
            ret = (ret*n)%MOD;

        return ret;
    }

    static class FastInput {

        private Reader in;
        private BufferedReader br;
        private StringTokenizer st;

        public FastInput(Reader in) {
            this.in=in;
            br = new BufferedReader(in);
        }

        public String nextString() {

            while(st==null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    System.out.println(e.getStackTrace());
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public double nextDouble() {

            return Double.parseDouble(nextString());
        }

    }

}


import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class C {

    public static void main(String[] args) throws IOException {
        init(System.in);
        BigInteger x = new BigInteger(next());
        if (x.compareTo(BigInteger.ZERO) == 0) {
            System.out.println(0);
            return;
        }
        BigInteger k = new BigInteger(next());
        BigInteger mod = new BigInteger("1000000007");
        BigInteger two = BigInteger.ONE.add(BigInteger.ONE);
        BigInteger ans = two.modPow(k, mod);
        ans = ans.multiply(two.multiply(x).subtract(BigInteger.ONE)).add(BigInteger.ONE).mod(mod);
        System.out.println(ans);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

//    private static int nextInt() throws IOException {
//        return Integer.parseInt(next());
//    }

//    private static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    private static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    private static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.Locale;
import java.util.StringTokenizer;

public class C {
    String fileName = "<name>";

    public static final int MOD = (int) (1e9 + 7);

    public void solve() throws IOException {
        long x = nextLong();
        if (x == 0) {
            out.print(0);
            return;
        }
        long k = nextLong();
        BigInteger power = BigInteger.valueOf(2)
                .modPow(BigInteger.valueOf(k), BigInteger.valueOf(MOD));
        BigInteger r = BigInteger.valueOf(x).multiply(power);
        BigInteger l = r.subtract(power).add(BigInteger.ONE);
        out.print(l.add(r).mod(BigInteger.valueOf(MOD)));
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new C().run();
    }
}


import java.io.*;
import java.util.*;

public class test {
    static boolean DEBUG_FLAG = false;
    int INF = (int)1e9;
    long MOD = 1000000007;

    static void debug(String s) {
        if(DEBUG_FLAG) {
            System.out.print(s);
        }
    }

    long pow(long a, long n, long mod) {
        if (n == 0) {
            return 1;
        }
        long rs = 1;
        while (n != 0) {
            if (n % 2 == 1) {
                rs *= a;
            }
            rs %= mod;
            n >>= 1;
            a *= a;
            a %= mod;
        }
        return rs;
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        long x = in.nextLong();
        long k = in.nextLong();
        if(x==0) {
            out.println(0);
            return;
        }
        long a = (2 * x - 1) % MOD;
        long b = pow(2, k, MOD);
        a = (a * b) % MOD;
        a += 1;
        a %= MOD;
        out.println(a);
    }

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }

    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Dummy {
  private static long mod = 1000000007;
  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] strs = reader.readLine().split(" ");
    long x = Long.parseLong(strs[0]);
    long k = Long.parseLong(strs[1]);
    long twoPK = modPow(2, k);
    long twoPK_1 = (twoPK * 2) % mod;
    long res = ((twoPK_1 * (x % mod)) % mod - (twoPK - 1) + mod) % mod;
    System.out.println(x == 0? x: res);
  }

  private static long modPow(long base, long pow) {
    long res = 1;
    while(pow != 0) {
      if((pow & 1) != 0) {
        res = (res % mod * base % mod)%mod;
      }
      base = (base % mod * base % mod) % mod;
      pow >>= 1;
    }
    return res;
  }
}


import java.io.*;
import java.util.*;

public class A992{

	long mod = 1000000007L;

	private void solve() throws Exception {
		long x = nextLong();
		long k = nextLong();
		if(x == 0) {
			out.println(0);
			return;
		}
		x = x%mod;
		long res = (((x*pow(2,k+1))%mod + (mod-pow(2,k))%mod)%mod+1)%mod;
		out.println(res);
	}

	long pow(long m, long n){
	    long res = 1;
	    while(n > 0){
	        if(n % 2 == 1)res = (res*m)%mod;
	        m = (m*m)%mod;
	        n = n/2;
	    }
	    return res;
	}

	public static void main(String[] args) {
		(new A992()).run();
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private float nextFloat() throws IOException {
		return Float.parseFloat(nextToken());
	}

	private String nextLine() throws IOException {
		return new String(in.readLine());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}

}


//package CF489; //comment this line

import java.io.*;
import java.util.*;
import java.math.*;
public class B
{
    private static long MOD=1000000007;
    private static BigInteger m=new BigInteger(1000000007+"");

    private static long pow(long x, long a)
    {
        if(a==0)
        return 1;

        long ans=pow(x,a/2);

        ans=(ans*ans)%MOD;

        if(a%2==1)
        ans=(ans*x)%MOD;

        return ans%MOD;
    }
    public static void main(String args[]) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        long N,K,ans;

        //System.out.println(); //comment this line
        String s[]=br.readLine().trim().split(" ");

        N=Long.parseLong(s[0]);
        K=Long.parseLong(s[1]);

        BigInteger bi=new BigInteger(N+"");
        BigInteger a=new BigInteger(N+"");
        BigInteger two=new BigInteger(2+"");

        if(N==0)
        {
            System.out.println(0);
            System.exit(0);
        }
        if(K==0)
        {
            a=a.multiply(two);
            a=a.mod(m);

            System.out.println(a);
            System.exit(0);
        }

        long p=pow(2,K);

        BigInteger p2=new BigInteger(p+"");
        BigInteger tmp=p2.subtract(BigInteger.ONE);
        tmp=tmp.mod(m);

        p2=p2.multiply(two);
        p2=p2.mod(m);

        a=a.multiply(p2);
        a=a.mod(m);

        a=a.subtract(tmp);
        a=a.mod(m);

        if(!(a.signum()==1)&&!(a.signum()==0))
        a.add(m);

        System.out.println(a);
    }
}


import java.util.*;
import java.io.*;

public class C {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	public static void quickSort(int[] a, int from, int to) {
		if (to - from <= 1) {
			return;
		}
		int i = from;
		int j = to - 1;
		int x = a[from + (new Random()).nextInt(to - from)];
		while (i <= j) {
			while (a[i] < x) {
				i++;
			}
			while (a[j] > x) {
				j--;
			}
			if (i <= j) {
				int t = a[i];
				a[i] = a[j];
				a[j] = t;
				i++;
				j--;
			}
		}
		quickSort(a, from, j + 1);
		quickSort(a, j + 1, to);
	}

	long mod = 1000000007;

	public long pow(long k) {
		if (k == 0) {
			return 1L;
		}
		if (k == 1) {
			return 2L;
		}
		if (k % 2 == 1) {
			return (2L * pow(k - 1)) % mod;
		}
		long x = pow(k / 2);
		return (x * x) % mod;
	}

	public void solve() {
		long x = in.nextLong();
		if (x == 0) {
			out.println(0);
			return;
		}
		x %= mod;
		long k = in.nextLong();
		long pow = pow(k);
		long ans = 1;
		ans = (ans - pow + mod) % mod;
		ans = (ans + (((2 * pow) % mod) * x) % mod) % mod;
		out.println(ans);
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	public static void main(String[] args) {
		new C().run();
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

/*
 * Author    : joney_000[jaswantsinghyada007@gmail.com]
 * Algorithm : N/A
 * Platform  : Codeforces
 * Ref       :
 */

public class A{

  private InputStream inputStream ;
  private OutputStream outputStream ;
  private FastReader in ;
  private PrintWriter out ;

  private final int BUFFER = 100005;
  private final long mod = 1000000000+7;
  private final int  INF  = Integer.MAX_VALUE;
  private final long INF_L  = Long.MAX_VALUE / 10;

  public A(){}
  public A(boolean stdIO)throws FileNotFoundException{
    // stdIO = false;
    if(stdIO){
      inputStream = System.in;
      outputStream = System.out;
    }else{
      inputStream = new FileInputStream("input.txt");
      outputStream = new FileOutputStream("output.txt");
    }
    in = new FastReader(inputStream);
    out = new PrintWriter(outputStream);
  }

  void run()throws Exception{
    long x = l(); long k = l();
    if(x == 0){
      out.write("0");
      return;
    }
    x %= mod;
    long a = (x * pow(2L, k, mod) + mod)%mod;
    long b = (a - pow(2L, k, mod) + 1 + mod)%mod;
    long res = (a + b + mod )%mod;
    out.write(""+res+"\n");
  }

  long gcd(long a, long b){
    if(b == 0)return a;
    return gcd(b, a % b);
  }

  long lcm(long a, long b){
    if(a == 0 || b == 0)return 0;
    return (a * b)/gcd(a, b);
  }

  long mulMod(long a, long b, long mod){
    if(a == 0 || b == 0)return 0;
    if(b == 1)return a;
    long ans = mulMod(a, b/2, mod);
    ans = (ans * 2) % mod;
    if(b % 2 == 1)ans = (a + ans)% mod;
    return ans;
  }

  long pow(long a, long b, long mod){
    if(b == 0)return 1;
    if(b == 1)return a;
    long ans = pow(a, b/2, mod);
    ans = (ans * ans);
    if(ans >= mod)ans %= mod;

    if(b % 2 == 1)ans = (a * ans);
    if(ans >= mod)ans %= mod;

    return ans;
  }

  // 20*20   nCr Pascal Table
  long[][] ncrTable(){
    long ncr[][] = new long[21][21];

    for(int i = 0; i <= 20; i++){
      ncr[i][0] = ncr[i][i] = 1L;
    }

    for(int j = 0; j <= 20; j++){
      for(int i = j + 1; i <= 20; i++){
        ncr[i][j] = ncr[i-1][j] + ncr[i-1][j-1];
      }
    }

    return ncr;
  }

  int i()throws Exception{
    return in.nextInt();
  }

  long l()throws Exception{
    return in.nextLong();
  }

  double d()throws Exception{
    return in.nextDouble();
  }

  char c()throws Exception{
    return in.nextCharacter();
  }

  String s()throws Exception{
    return in.nextLine();
  }

  BigInteger bi()throws Exception{
    return in.nextBigInteger();
  }

  private void closeResources(){
    out.flush();
    out.close();
    return;
  }

//  IMP: roundoff upto 2 digits
//  double roundOff = Math.round(a * 100.0) / 100.0;
//                    or
//  System.out.printf("%.2f", val);

//  print upto 2 digits after decimal
//  val = ((long)(val * 100.0))/100.0;

  public static void main(String[] args) throws java.lang.Exception{

    A driver = new A(true);
    driver.run();
    driver.closeResources();
  }
}

class FastReader{

  private boolean finished = false;

  private InputStream stream;
  private byte[] buf = new byte[4 * 1024];
  private int curChar;
  private int numChars;
  private SpaceCharFilter filter;

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

  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 peek(){
    if (numChars == -1){
      return -1;
    }
    if (curChar >= numChars){
      curChar = 0;
      try{
        numChars = stream.read (buf);
      } catch (IOException e){
        return -1;
      }
      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==','){
        c = read();
      }
      if (c < '0' || c > '9'){
        throw new InputMismatchException ();
      }
      res *= 10;
      res += c - '0';
      c = read ();
    } while (!isSpaceChar (c));
    return res * sgn;
  }

  public long nextLong(){
    int c = read ();
    while (isSpaceChar (c))
      c = read ();
    int sgn = 1;
    if (c == '-'){
      sgn = -1;
      c = read ();
    }
    long 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 String nextString(){
    int c = read ();
    while (isSpaceChar (c))
      c = read ();
    StringBuilder res = new StringBuilder ();
    do{
      res.appendCodePoint (c);
      c = read ();
    } while (!isSpaceChar (c));
    return res.toString ();
  }

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

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

  private String readLine0(){
    StringBuilder buf = new StringBuilder ();
    int c = read ();
    while (c != '\n' && c != -1){
      if (c != '\r'){
        buf.appendCodePoint (c);
      }
      c = read ();
    }
    return buf.toString ();
  }

  public String nextLine(){
    String s = readLine0 ();
    while (s.trim ().length () == 0)
      s = readLine0 ();
    return s;
  }

  public String nextLine(boolean ignoreEmptyLines){
    if (ignoreEmptyLines){
      return nextLine ();
    }else{
      return readLine0 ();
    }
  }

  public BigInteger nextBigInteger(){
    try{
      return new BigInteger (nextString ());
    } catch (NumberFormatException e){
      throw new InputMismatchException ();
    }
  }

  public char nextCharacter(){
    int c = read ();
    while (isSpaceChar (c))
      c = read ();
    return (char) c;
  }

  public double nextDouble(){
    int c = read ();
    while (isSpaceChar (c))
      c = read ();
    int sgn = 1;
    if (c == '-'){
      sgn = -1;
      c = read ();
    }
    double res = 0;
    while (!isSpaceChar (c) && c != '.'){
      if (c == 'e' || c == 'E'){
        return res * Math.pow (10, nextInt ());
      }
      if (c < '0' || c > '9'){
        throw new InputMismatchException ();
      }
      res *= 10;
      res += c - '0';
      c = read ();
    }
    if (c == '.'){
      c = read ();
      double m = 1;
      while (!isSpaceChar (c)){
        if (c == 'e' || c == 'E'){
          return res * Math.pow (10, nextInt ());
        }
        if (c < '0' || c > '9'){
          throw new InputMismatchException ();
        }
        m /= 10;
        res += (c - '0') * m;
        c = read ();
      }
    }
    return res * sgn;
  }

  public boolean isExhausted(){
    int value;
    while (isSpaceChar (value = peek ()) && value != -1)
      read ();
    return value == -1;
  }

  public String next(){
    return nextString ();
  }

  public SpaceCharFilter getFilter(){
    return filter;
  }

  public void setFilter(SpaceCharFilter filter){
    this.filter = filter;
  }

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

class Pair implements Comparable<Pair>{
  public int a;
  public int b;
  public int c;

  public Pair(){
    this.a = 0;
    this.b = 0;
    this.c = 0;
  }

  public Pair(int a,int b, int c){
    this.a = a;
    this.b = b;
    this.c = c;
  }

  public int compareTo(Pair p){
   return this.c - p.c;
  }

  @Override
  public String toString(){
    return "a = " + this.a + " b = " + this.b + " c = "+this.c;
  }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class C
{

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        BigInteger x = sc.nextBigInteger();
        BigInteger k = sc.nextBigInteger();
        BigInteger zero = new BigInteger("0");
        BigInteger one = new BigInteger("1");
        BigInteger two = new BigInteger("2");
        BigInteger modulo = new BigInteger("1000000007");
        BigInteger ans = two.modPow(k.add(one),modulo);
        ans = ans.multiply(x);
        ans = ans.subtract(two.modPow(k,modulo));
        ans = ans.add(one);
        ans = ans.mod(modulo);
        if (x.equals(zero))
        {
         System.out.println(0);
         }
         else
         {
        System.out.println(ans);
        }
    }
}


//package que_a;

import java.io.*;
import java.util.*;
import java.math.*;

public class utkarsh {

    InputStream is;
    PrintWriter out;

    long mod = (long) (1e9 + 7);
    boolean SHOW_TIME;

    void solve() {
        //Enter code here utkarsh
        //SHOW_TIME = true;
        long X = nl();
        BigInteger x = BigInteger.valueOf(X);
        long K = nl();
        BigInteger k = BigInteger.valueOf(K);
        BigInteger MOD = BigInteger.valueOf(mod);

        if(X == 0) {
            out.println(0); return;
        }
        if(k.compareTo(BigInteger.ZERO) == 0) {
            out.println((x.add(x)).mod(MOD));   return;
        }

        BigInteger p = BigInteger.valueOf(modpow(2, K, mod));
        BigInteger ans = x.multiply(p);
        ans = ans.add(ans);
        ans = ans.subtract(p).add(BigInteger.ONE);
        ans = ans.add(MOD);
        out.println(ans.mod(MOD));
    }

    long modpow(long b, long e, long mod) {
        b %= mod;
        long r = 1;
        while(e > 0) {
            if((e & 1) == 1) {
                r *= b; r %= mod;
            }
            b *= b; b %= mod;
            e >>= 1;
        }
        return r;
    }

    //---------- I/O Template ----------

    public static void main(String[] args) { new utkarsh().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        long start = System.currentTimeMillis();
        solve();
        long end = System.currentTimeMillis();
        if(SHOW_TIME) out.println("\n" + (end - start) + " ms");
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}


import java.io.*;
import java.util.*;

public class C implements Runnable{
	public static void main (String[] args) {new Thread(null, new C(), "_cf", 1 << 28).start();}

	long MOD = (long)1e9+7;

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		long x = fs.nextLong();
		long k = fs.nextLong();
		if(x == 0) {
			System.out.println(0);
			return;
		}
		if(k == 0) {
			System.out.println(mult(x, 2));
			return;
		}

		long max = mult(x, power(2, k, MOD));
		long min = sub(max, power(2, k, MOD));
		long total = 0;
		if(min <= max) {
			total = sub(summ(max), summ(min));
		}
		else {
			total = summ(max);
			total = add(total, sub(summ(MOD-1), summ(min)));
		}
		total = mult(total, 2);
		total = div(total, power(2, k, MOD));
		out.println(total);
		out.close();
	}

	long summ(long x) {
		x *= x+1;
		x /= 2;
		x %= MOD;
		return x;
	}

	long add(long a, long b) {
		a %= MOD;
		b %= MOD;
		a += b;
		a %= MOD;
		return a;
	}

	long sub(long a, long b) {
		a %= MOD;
		b %= MOD;
		a -= b;
		while(a < 0) a += MOD;
		a %= MOD;
		return a;
	}

	long mult(long a, long b) {
		a %= MOD;
		b %= MOD;
		a *= b;
		a %= MOD;
		return a;
	}

	long div(long a, long b) {
		a %= MOD;
		b %= MOD;
		a *= inv(b);
		a %= MOD;
		return a;
	}

	long inv(long x) {
		long res = power(x, MOD-2, MOD);
		while(res < 0) res += MOD;
		res %= MOD;
		return res;
	}

	long power (long x, long y, long m) {
    	long res = 1;
    	x %= m;
    	while(y > 0) {
    		if(y % 2 == 1) {
    			res = (res * x) % m;
    		}
    		y >>= 1L;
    		x = (x * x) % m;
    	}
    	return res;
    }

	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 50; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

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

	}

}


import java.io.*;
import java.math.BigInteger;

public class C {

    private static Solver solver = new Solver();

    private static long m = 1000000000L + 7L;

    public static void main(String[] args) throws IOException {
        solver.withProcedure(() -> {
            String[] input = solver.readString().split(" ");
            BigInteger x = new BigInteger(input[0]);
            BigInteger k = new BigInteger(input[1]);

            if (x.compareTo(BigInteger.ZERO) == 0) {
                solver.println("" + 0);
                return;
            }

            BigInteger two = BigInteger.valueOf(2);

            BigInteger mm = BigInteger.valueOf(m);
            BigInteger binpowedK = two.modPow(k, mm);
            BigInteger binpowedKPlusOne = two.modPow(k.add(BigInteger.ONE), mm);

            BigInteger res = binpowedKPlusOne.multiply(x).subtract(binpowedK.subtract(BigInteger.ONE)).mod(mm);

            if (res.compareTo(BigInteger.ZERO) < 0) {
                res = BigInteger.ZERO;
            }

            solver.println("" + res);
        }).solve();
    }

    private static long binpow(long a, long n) {
        a = a % m;

        long res = 1L;
        while (n > 0) {
            if ((n & 1L) != 0)
                res = (res * a) % m;

            a = (a * a) % m;
            n >>= 1L;
        }

        return res;
    }

    @FunctionalInterface
    private interface Procedure {
        void run() throws IOException;
    }

    private static class Solver {
        private Procedure procedure;

        private StreamTokenizer in;
        private PrintWriter out;
        private BufferedReader bufferedReader;

        Solver() {
            try {
                boolean oj = System.getProperty("ONLINE_JUDGE") != null;

                Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
                Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");

                bufferedReader = new BufferedReader(reader);
                in = new StreamTokenizer(bufferedReader);
                out = new PrintWriter(writer);
            } catch (Exception e) {
                throw new RuntimeException("Initialization has failed");
            }
        }

        void solve() throws IOException {
            procedure.run();
        }

        int readInt() throws IOException {
            in.nextToken();
            return (int) in.nval;
        }

        long readLong() throws IOException {
            in.nextToken();
            return (long) in.nval;
        }

        String readString() throws IOException {
            return bufferedReader.readLine();
        }

        char readChar() throws IOException {
            in.nextToken();
            return in.sval.charAt(0);
        }

        void println(String str) {
            out.println(str);
            out.flush();
        }

        void print(String str) {
            out.print(str);
            out.flush();
        }

        Solver withProcedure(Procedure procedure) {
            this.procedure = procedure;

            return this;
        }
    }

}


import java.util.*;
import java.io.*;

public class R489C {

	static long m = (long)(1e9+7);
	/*
	1000000000000000000
	 */

	public static void main(String[] args) {
		JS scan = new JS();
		long n = scan.nextLong();
		long k = scan.nextLong();
		if(n == 0) {
			System.out.println(0);
			return;
		}
		if(k == 0) {
			long ans = (n%m)*(2%m)%m;
			System.out.println(ans%m);
			return;
		}
		//System.out.println(2+" "+(k+1)+" "+m);
		long coeff = power(2L, k+1, m);
		//System.out.println(coeff);
		long r = (coeff%m)*(n%m)%m;
		//System.out.println(r);
		long x = power(2L, k, m)%m-1;
		if(x < 0) x += m;
		long ans = r-x;
		if(ans < 0) ans += m;
		System.out.println(ans%m);
	}

	static long power(long x, long y, long p){
        // Initialize result
		long res = 1;

        // Update x if it is more
        // than or equal to p
        x = x % p;

        while (y > 0){
            // If y is odd, multiply x
            // with result
            if((y & 1)==1)
                res = (res%p * x%p) % p;

            // y must be even now
            // y = y / 2
            y = y >> 1;
            x = (x%p * x%p) % p;
        }
        return res;
    }

	/*
	1000000000000000000 1000000000000000000
	 */

	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}


import java.util.*;
import java.io.*;

public class Solution1 {

    private void solve() throws IOException {
        long MOD = 1_000_000_007;
        long x = in.nextLong();
        long k = in.nextLong();
        if (x == 0) {
            System.out.println(0);
            return;
        }
        long val = binpow(2, k + 1, MOD) % MOD;
        long kek = (binpow(2, k, MOD) - 1 + MOD) % MOD;
        x = (val % MOD) * (x % MOD) % MOD;
        long ans = (x % MOD - kek % MOD + MOD) % MOD;
        System.out.println(ans % MOD);
    }

    private long binpow(long a, long n, long mod) {
        long res = 1;
        while (n > 0) {
            if (n % 2 == 1)
                res = (res % mod) * (a % mod) % mod;
            a = (a % mod) * (a % mod) % mod;
            n >>= 1;
        }
        return res % mod;
    }

    private PrintWriter out;
    private MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution1().run();
    }
}


/**
 * Created by Baelish on 6/18/2018.
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C_3 {
    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        long mod = (long) 1e9 + 7;

        long xx = in.nextLong(), kk = in.nextLong();

        if(xx == 0){
            pw.println(0); pw.close();
            return;
        }

        BigInteger x = BigInteger.valueOf(xx), k = BigInteger.valueOf(kk);

       // long a = bigMod(2, k+1, mod );long b = bigMod(2, k, mod);

        BigInteger MOD = BigInteger.valueOf(mod);
        BigInteger a = BigInteger.valueOf(2).modPow(BigInteger.valueOf(kk+1), MOD);
        BigInteger b = BigInteger.valueOf(2).modPow(BigInteger.valueOf(kk), MOD);

        BigInteger s = (a.multiply(x)).mod(MOD);
        s = s.subtract(b.mod(MOD));
        s = s.add(BigInteger.ONE);
        s = s.mod(MOD);
        s = s.add(MOD);
        s = s.mod(MOD);

       // debug(a, b, x);

       // long s = ((a * x) % mod - b % mod + 1 + mod) % mod;

        pw.println(s);

        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        static final int ints[] = new int[128];
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            for (int i = '0'; i <= '9'; i++) ints[i] = i - '0';
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + ints[b];
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + ints[b];
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
       /* public char nextChar() {
            return (char)skip();
        }*/

        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        /*private char buff[] = new char[1005];
        public char[] nextCharArray(){
            int b = skip(), p = 0;
            while(!(isSpaceChar(b))){
                buff[p++] = (char)b;
                b = readByte();
            }
            return Arrays.copyOf(buff, p);
        }*/
    }
}


import java.util.*;
import java.io.*;
public class A{
	static long mod = 1000000000+7;
	static int arr[];
	static HashMap<Long,Long> map = new HashMap<>();
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long x = scan.nextLong();
		long k = scan.nextLong();
		if(x == 0)
		{
			System.out.println(0);
			return;
		}
		x = x%mod;
		long power = pow(2,k + 1)%mod;
		power = (power*x)%mod;
		long num = (pow(2,k) - 1 + mod)%mod;
		long ans = (power - num + mod)%mod;
		System.out.println((ans));
	}
	public static long pow(long a,long b)
	{
		if(b == 0)
			return 1;
		if(b == 1)
			return a;
		long x1,x2;
		if(map.containsKey(b - b/2))
			x1 = map.get(b - b/2);
		else
		{
			x1 = pow(a,b - b/2)%mod;
			map.put(b - b/2,x1);
		}
		if(map.containsKey(b/2))
			x2 = map.get(b/2);
		else
		{
			x2 = pow(a,b/2)%mod;
			map.put(b/2,x2);
		}
		return (x1*x2)%mod;
	}
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

/* spar5h */

public class cf3 implements Runnable{

	final static long mod = (long)1e9 + 7;

	static long modExp(long x, long pow) {

		x = x % mod;

	    long res = 1;

	    while (pow > 0) {

	        if (pow % 2 == 1)
	            res = res * x % mod;

	        pow = pow / 2;
	        x = x * x % mod;
	    }

	    return res;
	}

	public void run() {

		InputReader s = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		int t = 1;

		while(t-- > 0) {

			long x = s.nextLong(), k = s.nextLong();

			if(x == 0) {
				w.println(0); continue;
			}

			x = x % mod;

			long res = (modExp(2, k + 1) * x % mod + 1) % mod;
			res = (res + mod - modExp(2, k)) % mod;

			w.println(res);
		}

		w.close();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		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 String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		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 long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long 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 double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

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

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new cf3(),"cf3",1<<26).start();
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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);
        _992C solver = new _992C();
        solver.solve(1, in, out);
        out.close();
    }

    static class _992C {
        static int mod = (int) 1e9 + 7;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long x = in.nextLong();
            long k = in.nextLong();

            if (x == 0) {
                out.println(0);
                return;
            }

            long[][] base = new long[][]{{2, 0}, {1, 1}};

            _992C.Matrix.N = 2;

            base = _992C.Matrix.matrixPower(base, base, k);

            x %= mod;
            long ans = 2 * base[0][0] * x - base[1][0];

            ans %= mod;

            if (ans < 0)
                ans += mod;

            out.println(ans);
        }

        static public class Matrix {
            static int N;
            static long[][] id = new long[][]{{1, 0}, {0, 1}};

            static long[][] matrixPower(long[][] mat, long[][] base, long pow) {
                if (pow == 0) {
                    return id;
                }
                if (pow == 1) {
                    return base;
                }

                long[][] t = matrixPower(mat, base, pow / 2);

                t = multiplyMatrix(t, t);
                if (pow % 2 == 1) {
                    t = multiplyMatrix(t, base);
                }

                return t;
            }

            static long[][] multiplyMatrix(long[][] m, long[][] m2) {
                long[][] ans = new long[N][N];

                for (int i = 0; i < N; i++)
                    for (int j = 0; j < N; j++) {
                        ans[i][j] = 0;
                        for (int k = 0; k < N; k++) {
                            ans[i][j] += m[i][k] * m2[k][j];
                            ans[i][j] %= mod;
                        }
                    }

                return ans;
            }

        }

    }

    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);
        }

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

    }

    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 long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long 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 interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.*;
import java.util.*;

public class C
{
	static long mod=(long)(1e9+7);
	public static long powMod(long e,long b)
	{
		/*e=e%mod;*/
		long res=1;

		while(e>0)
		{
			if(e%2==1)
				res=res*b%mod;
			e/=2;
			b=b*b%mod;
		}
		return res;
	}

		public static void main(String[] args) throws IOException
		{
			Scanner sc=new Scanner(System.in);
			PrintWriter pw=new PrintWriter(System.out);
			long x=sc.nextLong(),k=sc.nextLong();
			if(x==0)
			{
				System.out.println(0);
				return;
			}

			if(k==0)
			{
				pw.println((2*x)%mod);

				pw.close();return;
			}

			long ans=2*x-1;
			ans=ans%mod;

			long b=powMod(k,2);
			ans=((ans*b)+1)%mod;

			pw.println(ans);

			pw.close();

		}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class C{
	public static void main (String[] args) throws java.lang.Exception{
		Scanner scan=new Scanner(System.in);
		long x=scan.nextLong(), k=scan.nextLong();
		long MOD = 1000000007;
		if(x==0){
			System.out.println("0");
			return;
		}
		x %= MOD;
		long ans= (((new myC()).fastPow(2L, k+1)*x)%MOD - (new myC()).fastPow(2L, k) + MOD + 1)% MOD;
		ans %= MOD;
		System.out.println(ans);
	}
}

class myC{
	long MOD = 1000000007;
	long fastPow(long x, long k){
		long bb=x%MOD, ans=1;
		while(k > 0){
			if((k&1)==1){
				ans=(ans*bb)%MOD;
			}
			bb=(bb*bb)%MOD;
			k>>=1;
		}
		return ans;
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Div2_489C {

	static final long MOD = 1_000_000_007;

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		long st = Long.parseLong(inputData.nextToken());
		if(st == 0) {
			printer.println(0);
			printer.close();
			return;
		}
		st %= MOD;
		long years = Long.parseLong(inputData.nextToken());
		long[][] res = exp(years);
		long ans = (res[0][0] * st % MOD * 2 % MOD + res[0][1] * (-1 + MOD) % MOD) % MOD;
		printer.println(ans);
		printer.close();
	}

	static long[][] exp(long pow) {
		long[][] cBase = base;
		long[][] res = { { 1, 0 }, { 0, 1 } };

		while (pow != 0) {
			if ((pow & 1) != 0) {
				res = mult(res, cBase);
			}
			cBase = mult(cBase, cBase);
			pow >>= 1;
		}
		return res;
	}

	static long[][] base = { { 2, 1 }, { 0, 1 } };

	static long[][] mult(long[][] a, long[][] b) {
		long[][] res = new long[2][2];
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				res[i][j] = (a[i][0] * b[0][j] % MOD + a[i][1] * b[1][j] % MOD) % MOD;
			}
		}
		return res;
	}

}