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

public class Main {
	static long[] factor;
	static int mod = 1000000007;

	public static void main(String[] args) throws IOException {
		InputReader scan = new InputReader();
		int a = scan.nextInt(), b = scan.nextInt(), k = scan.nextInt();
		generateFactor(k);
		long sum = 0;
		for (int i = 0; i <= k; i++) {
			if (isGood(a * i + b * (k - i), a, b))
				sum += (factor[k] * (BigInteger.valueOf(factor[i] * factor[k - i] % mod)
						.modInverse(BigInteger.valueOf(mod)).longValue()) % mod);
			sum %= mod;
		}
		System.out.println(sum);
	}

	static boolean isGood(int n, int a, int b) {
		while (n % 10 == a || n % 10 == b) {
			n /= 10;
		}
		return n == 0;
	}

	static void generateFactor(int n) {
		factor = new long[n + 10];
		factor[0] = 1;
		for (int i = 1; i < n + 10; i++) {
			factor[i] = (factor[i - 1] * i) % mod;
		}
	}

	static class InputReader {

		InputStream is = System.in;
		byte[] inbuf = new byte[1 << 23];
		int lenbuf = 0, ptrbuf = 0;

		public InputReader() throws IOException {
			lenbuf = is.read(inbuf);
		}

		public int readByte() {

			if (ptrbuf >= lenbuf) {
				return -1;
			}

			return inbuf[ptrbuf++];
		}

		public boolean hasNext() {
			int t = skip();

			if (t == -1) {
				return false;
			}
			ptrbuf--;
			return true;
		}

		public StringBuilder printIntArr(int[] ar, int n) {
			StringBuilder res = new StringBuilder();
			for (int i = 0; i < n; i++) {
				res.append(ar[i] + " ");
			}
			res.append("\n");
			return res;
		}

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

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

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

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

		public String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (b != '\n' && b != '\r') {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

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

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

		public int[][] nmInt(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					map[i][j] = nextInt();
				}
			}
			return map;
		}

		public long[][] nmLong(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					map[i][j] = nextLong();
				}
			}
			return map;
		}

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

		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 * 10 + (b - '0');
				} 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 * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

	}
}


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

public class Template implements Runnable {

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

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

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

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

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

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

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

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

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

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    long[] fact;
    long[] revfact;
    int mod = (int) 1e9 + 7;

    long binpow(long x, int p, int mod) {
        if (p == 0) {
            return 1 % mod;
        }
        if (p % 2 == 0) {
            long half = binpow(x, p / 2, mod);
            return half * half % mod;
        } else {
            return x * binpow(x, p - 1, mod) % mod;
        }
    }

    long C(int n, int k) {
        if (k > n) return 0;
        long answer = fact[n];
        answer = answer * revfact[n - k] % mod;
        answer = answer * revfact[k] % mod;
        return answer;
    }

    long ways(int columns, int count, int minHeight) {
        if (columns == 0) {
            if (count == 0) return 1;
            return 0;
        }
        if (count / minHeight < columns) return 0;
        if (columns == 1) return 1;
        int ost = count - columns * minHeight;
        //return binpow(ost + 1, columns - 1, mod);
        int n = ost;
        int m = columns;
        return C(n + m - 1, m - 1);

       // return C(ost + 1, columns - 1);

//        return binpow(columns, ost, mod);
    }

    void solve() throws IOException {
        int MAX = 2 * 100000 + 100;
        fact = new long[MAX];
        revfact = new long[MAX];
        fact[0] = revfact[0] = 1;
        for (int i = 1; i < MAX; i++) {
            fact[i] = fact[i - 1] * i % mod;
            revfact[i] = binpow(fact[i], mod - 2, mod);
        }
        int f = readInt();
        int w = readInt();
        int h = readInt();
        if (w == 0) {
            out.println(1);
            return;
        }

        long correct = 0;
        long all = 0;

        for (int wineColumns = 1; wineColumns <= w; wineColumns++) {
            long foodCount = (ways(wineColumns - 1, f, 1) + ways(wineColumns + 1, f, 1) + ways(wineColumns, f, 1) * 2) % mod;
            all += ways(wineColumns, w, 1) * foodCount % mod;
            all %= mod;
            correct += ways(wineColumns, w, h + 1) * foodCount % mod;
            correct %= mod;
        }
        long answer = correct * binpow(all, mod - 2, mod) % mod;
        //long etalon = new NaiveSolver().solve(f, w, h);
        //if (answer != etalon) throw new RuntimeException("answer not equal etalon");
        out.println(answer);
    }

    class NaiveSolver {

        long solve(int f, int w, int h) {
            brut(f, w, h, true, true, "");
            brut(f, w, h, true, false, "");
            return correct * binpow(all, mod - 2, mod) % mod;
        }

        long correct;
        long all;

        void brut(int f, int w, int h, boolean nowAllOk, boolean nowWine, String represent) {
            if (f == 0 && w == 0) {
                all++;
                if (nowAllOk) correct++;
                System.err.println(represent);
                return;
            }
            if (nowWine) {
                if (w == 0) return;
            } else {
                if (h == 0) return;
            }
            if (nowWine) {
                for (int i = 1; i <= w; i++) {
                    brut(f, w - i, h, nowAllOk & (i > h), !nowWine, represent + str('w', i));
                }
            } else {
                for (int i = 1; i <= f; i++) {
                    brut(f - i, w, h, nowAllOk, !nowWine, represent + str('f', i));
                }
            }
        }
    }

    String str(char x, int cnt) {
        String res = "";
        while (cnt-- > 0) {
            res += x;
        }
        return res;
    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.List;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Egor Kulikov (egor@egork.net)
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int[] x = new int[n];
            int[] y = new int[n];
            int[] r = new int[n];
            in.readIntArrays(x, y, r);
            Circle[] circles = new Circle[n];
            for (int i = 0; i < n; i++) {
                circles[i] = new Circle(new Point(x[i], y[i]), r[i]);
            }
            List<Point> points = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    Point[] intersect = circles[i].intersect(circles[j]);
                    if (intersect != null) {
                        points.addAll(Arrays.asList(intersect));
                    }
                }
            }
            boolean[] bad = new boolean[points.size()];
            for (int i = 0; i < points.size(); i++) {
                for (int j = 0; j < i; j++) {
                    if (points.get(i).equals(points.get(j))) {
                        bad[i] = true;
                        break;
                    }
                }
            }
            int nVertices = ArrayUtils.count(bad, false);
            int nEdges = 0;
            IndependentSetSystem setSystem = new RecursiveIndependentSetSystem(points.size());
            for (int i = 0; i < n; i++) {
                int current = 0;
                IntList onThis = new IntArrayList();
                for (int j = 0; j < points.size(); j++) {
                    if (!bad[j] && Math.abs(circles[i].center.distance(points.get(j)) - r[i]) < GeometryUtils.epsilon) {
                        current++;
                        onThis.add(j);
                    }
                }
                for (int j = 1; j < onThis.size(); j++) {
                    setSystem.join(onThis.get(j), onThis.get(0));
                }
                nEdges += Math.max(current, 1);
            }
            int nComponents = setSystem.getSetCount() - ArrayUtils.count(bad, true);
            out.printLine(1 + nEdges - nVertices + nComponents);
        }

    }

    static class Line {
        public final double a;
        public final double b;
        public final double c;

        public Line(Point p, double angle) {
            a = Math.sin(angle);
            b = -Math.cos(angle);
            c = -p.x * a - p.y * b;
        }

        public Line(double a, double b, double c) {
            double h = GeometryUtils.fastHypot(a, b);
            this.a = a / h;
            this.b = b / h;
            this.c = c / h;
        }

        public Point intersect(Line other) {
            if (parallel(other)) {
                return null;
            }
            double determinant = b * other.a - a * other.b;
            double x = (c * other.b - b * other.c) / determinant;
            double y = (a * other.c - c * other.a) / determinant;
            return new Point(x, y);
        }

        public boolean parallel(Line other) {
            return Math.abs(a * other.b - b * other.a) < GeometryUtils.epsilon;
        }

        public Line perpendicular(Point point) {
            return new Line(-b, a, b * point.x - a * point.y);
        }

        public double value(Point point) {
            return a * point.x + b * point.y + c;
        }

        public Point[] intersect(Circle circle) {
            double distance = distance(circle.center);
            if (distance > circle.radius + GeometryUtils.epsilon) {
                return new Point[0];
            }
            Point intersection = intersect(perpendicular(circle.center));
            if (Math.abs(distance - circle.radius) < GeometryUtils.epsilon) {
                return new Point[]{intersection};
            }
            double shift = Math.sqrt(circle.radius * circle.radius - distance * distance);
            return new Point[]{new Point(intersection.x + shift * b, intersection.y - shift * a),
                    new Point(intersection.x - shift * b, intersection.y + shift * a)};
        }

        public double distance(Point center) {
            return Math.abs(value(center));
        }

        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            Line line = (Line) o;

            if (!parallel(line)) {
                return false;
            }
            if (Math.abs(a * line.c - c * line.a) > GeometryUtils.epsilon ||
                    Math.abs(b * line.c - c * line.b) > GeometryUtils.epsilon) {
                return false;
            }

            return true;
        }

    }

    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 printLine(int i) {
            writer.println(i);
        }

    }

    static class Circle {
        public final Point center;
        public final double radius;

        public Circle(Point center, double radius) {
            this.center = center;
            this.radius = radius;
        }

        public Point[] intersect(Circle other) {
            double distance = center.distance(other.center);
            if (distance < GeometryUtils.epsilon) {
                return null;
            }
            Line line = new Line(2 * (other.center.x - center.x), 2 * (other.center.y - center.y), other.radius * other
                    .radius - radius * radius + center.x * center.x - other.center.x * other.center.x +
                    center.y * center.y - other.center.y * other.center.y);
            return line.intersect(this);
        }

    }

    static class IntArrayList extends IntAbstractStream implements IntList {
        private int size;
        private int[] data;

        public IntArrayList() {
            this(3);
        }

        public IntArrayList(int capacity) {
            data = new int[capacity];
        }

        public IntArrayList(IntCollection c) {
            this(c.size());
            addAll(c);
        }

        public IntArrayList(IntStream c) {
            this();
            if (c instanceof IntCollection) {
                ensureCapacity(((IntCollection) c).size());
            }
            addAll(c);
        }

        public IntArrayList(IntArrayList c) {
            size = c.size();
            data = c.data.clone();
        }

        public IntArrayList(int[] arr) {
            size = arr.length;
            data = arr.clone();
        }

        public int size() {
            return size;
        }

        public int get(int at) {
            if (at >= size) {
                throw new IndexOutOfBoundsException("at = " + at + ", size = " + size);
            }
            return data[at];
        }

        private void ensureCapacity(int capacity) {
            if (data.length >= capacity) {
                return;
            }
            capacity = Math.max(2 * data.length, capacity);
            data = Arrays.copyOf(data, capacity);
        }

        public void addAt(int index, int value) {
            ensureCapacity(size + 1);
            if (index > size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size) {
                System.arraycopy(data, index, data, index + 1, size - index);
            }
            data[index] = value;
            size++;
        }

        public void removeAt(int index) {
            if (index >= size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size - 1) {
                System.arraycopy(data, index + 1, data, index, size - index - 1);
            }
            size--;
        }

    }

    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 void readIntArrays(int[]... arrays) {
            for (int i = 0; i < arrays[0].length; i++) {
                for (int j = 0; j < arrays.length; j++) {
                    arrays[j][i] = readInt();
                }
            }
        }

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

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

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

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

        }

    }

    static interface IntList extends IntReversableCollection {
        public abstract int get(int index);

        public abstract void addAt(int index, int value);

        public abstract void removeAt(int index);

        default public IntIterator intIterator() {
            return new IntIterator() {
                private int at;
                private boolean removed;

                public int value() {
                    if (removed) {
                        throw new IllegalStateException();
                    }
                    return get(at);
                }

                public boolean advance() {
                    at++;
                    removed = false;
                    return isValid();
                }

                public boolean isValid() {
                    return !removed && at < size();
                }

                public void remove() {
                    removeAt(at);
                    at--;
                    removed = true;
                }
            };
        }

        default public void add(int value) {
            addAt(size(), value);
        }

    }

    static class GeometryUtils {
        public static double epsilon = 1e-8;

        public static double fastHypot(double x, double y) {
            return Math.sqrt(x * x + y * y);
        }

    }

    static class ArrayUtils {
        public static int count(boolean[] array, boolean value) {
            int result = 0;
            for (boolean i : array) {
                if (i == value) {
                    result++;
                }
            }
            return result;
        }

    }

    static interface IntIterator {
        public int value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static class RecursiveIndependentSetSystem implements IndependentSetSystem {
        private final int[] color;
        private final int[] rank;
        private int setCount;
        private IndependentSetSystem.Listener listener;

        public RecursiveIndependentSetSystem(int size) {
            color = new int[size];
            rank = new int[size];
            for (int i = 0; i < size; i++) {
                color[i] = i;
            }
            setCount = size;
        }

        public RecursiveIndependentSetSystem(RecursiveIndependentSetSystem other) {
            color = other.color.clone();
            rank = other.rank.clone();
            setCount = other.setCount;
        }

        public boolean join(int first, int second) {
            first = get(first);
            second = get(second);
            if (first == second) {
                return false;
            }
            if (rank[first] < rank[second]) {
                int temp = first;
                first = second;
                second = temp;
            } else if (rank[first] == rank[second]) {
                rank[first]++;
            }
            setCount--;
            color[second] = first;
            if (listener != null) {
                listener.joined(second, first);
            }
            return true;
        }

        public int get(int index) {
            int start = index;
            while (color[index] != index) {
                index = color[index];
            }
            while (start != index) {
                int next = color[start];
                color[start] = index;
                start = next;
            }
            return index;
        }

        public int getSetCount() {
            return setCount;
        }

    }

    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {
        public IntIterator intIterator();

        default public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private IntIterator it = intIterator();

                public boolean hasNext() {
                    return it.isValid();
                }

                public Integer next() {
                    int result = it.value();
                    it.advance();
                    return result;
                }
            };
        }

        default public int compareTo(IntStream c) {
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                int i = it.value();
                int j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

    }

    static abstract class IntAbstractStream implements IntStream {

        public String toString() {
            StringBuilder builder = new StringBuilder();
            boolean first = true;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (first) {
                    first = false;
                } else {
                    builder.append(' ');
                }
                builder.append(it.value());
            }
            return builder.toString();
        }

        public boolean equals(Object o) {
            if (!(o instanceof IntStream)) {
                return false;
            }
            IntStream c = (IntStream) o;
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                if (it.value() != jt.value()) {
                    return false;
                }
                it.advance();
                jt.advance();
            }
            return !it.isValid() && !jt.isValid();
        }

        public int hashCode() {
            int result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result *= 31;
                result += it.value();
            }
            return result;
        }

    }

    static interface IndependentSetSystem {
        public boolean join(int first, int second);

        public int getSetCount();

        public static interface Listener {
            public void joined(int joinedRoot, int root);

        }

    }

    static interface IntCollection extends IntStream {
        public int size();

        default public void add(int value) {
            throw new UnsupportedOperationException();
        }

        default public IntCollection addAll(IntStream values) {
            for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {
                add(it.value());
            }
            return this;
        }

    }

    static interface IntReversableCollection extends IntCollection {
    }

    static class Point {
        public final double x;
        public final double y;

        public String toString() {
            return "(" + x + ", " + y + ")";
        }

        public Point(double x, double y) {
            this.x = x;
            this.y = y;
        }

        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            Point point = (Point) o;

            return Math.abs(x - point.x) <= GeometryUtils.epsilon && Math.abs(y - point.y) <= GeometryUtils.epsilon;
        }

        public int hashCode() {
            int result;
            long temp;
            temp = x != +0.0d ? Double.doubleToLongBits(x) : 0L;
            result = (int) (temp ^ (temp >>> 32));
            temp = y != +0.0d ? Double.doubleToLongBits(y) : 0L;
            result = 31 * result + (int) (temp ^ (temp >>> 32));
            return result;
        }

        public double distance(Point other) {
            return GeometryUtils.fastHypot(x - other.x, y - other.y);
        }

    }
}


import java.util.*;
public class C_Bear_And_Company_3 {

    static int cv, ck , cs;
    static int[][] freq;
    static ArrayList<Integer>[] pos;
    static int[][][][] dp;

    public static void main(String[] agrs) {
    	Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char[] c = in.next().toCharArray();
        cv = 0;
        ck = 0;
        cs = 0;
        freq = new int[n + 1][3];
        pos = new ArrayList[3];
        for (int i = 0; i < 3; i++) pos[i] = new ArrayList<>();
        int idx = 0;
        for (char x : c) {
            System.arraycopy(freq[idx], 0, freq[idx + 1], 0, 3);
            idx++;
            if (x == 'V') {
                freq[idx][0]++;
                cv++;
                pos[0].add(idx);
            } else if (x == 'K') {
                freq[idx][1]++;
                ck++;
                pos[1].add(idx);
            } else {
                freq[idx][2]++;
                cs++;
                pos[2].add(idx);
            }
        }
        dp = new int[cv + 1][ck + 1][cs + 1][3];
        for (int[][][] x : dp) for (int[][] y : x) for (int[] z : y) Arrays.fill(z, -1);
        System.out.println(dfs(0, 0, 0, 2));
    }

    static int dfs(int tv, int tk, int ts, int last) {
        if (tv == cv && tk == ck && ts == cs) {
            return 0;
        }
        if (dp[tv][tk][ts][last] != -1) return dp[tv][tk][ts][last];
        int ret = 1 << 29;
        if (tv < cv) {
            int p = pos[0].get(tv);
            int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1;
            ret = Math.min(ret, dfs(tv + 1, tk, ts, 0) + move);
        }
        if (tk < ck && last != 0) {
            int p = pos[1].get(tk);
            int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1;
            ret = Math.min(ret, dfs(tv, tk + 1, ts, 1) + move);
        }
        if (ts < cs) {
            int p = pos[2].get(ts);
            int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1;
            ret = Math.min(ret, dfs(tv, tk, ts + 1, 2) + move);
        }
        return dp[tv][tk][ts][last] = ret;
    }

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cv=new Scanner(System.in);
        long a=cv.nextInt();
        long b=cv.nextInt();
        long c=cv.nextInt();
        long k=0;
        if(a>b){
            k+=(b+c)*2;
            k++;
        }else if(b>a){
            k+=(a+c)*2;
            k++;
        }else {
            k+=(a+c)*2;
        }
        System.out.println(k);
    }
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author jtim
 */
public class taskC {

    public static void main(String[] args) {
        new taskC().main();
    }
    Scanner s = new Scanner(System.in);
    long min = Long.MAX_VALUE, max = Long.MIN_VALUE, n = 0;

    void check(long a, long b, long c) {
        long m = (a+1)*(b+2)*(c+2);
        long now = m - n;
        min = Math.min(min, now);
        max = Math.max(max, now);
    }

    void main() {
        n = s.nextInt();

        for (long x = 1; x * x <= n; x++) {
            if (n % x == 0) {

                long rem = n / x;

                for (long y = 1; y * y <= rem; y++) {
                    if (rem % y == 0) {

                        long z = rem / y;

                        check(x, y, z);
                        check(x, z, y);
                        check(y, x, z);
                        check(y, z, x);
                        check(z, x, y);
                        check(z, y, x);

                    }
                }

            }
        }

        System.out.println(min + " " + max);
    }
}


import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    boolean dp[]=new boolean[101];
	    dp[3]=dp[6]=dp[7]=true;
	    for(int i=8;i<101;i++){
	        dp[i]=dp[i-3]|dp[i-7];
	    }
	    while(n-->0){
	        int x=sc.nextInt();
	        if(dp[x])System.out.println("YES");
	        else System.out.println("NO");
	    }
	}
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

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

class TaskC {
    private static final long MAX_VALUE = 10000000000000L;
    private int n, m;
    private int[] a, b;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        a = new int[n];
        b = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < n; ++i) {

            b[i] = in.nextInt();
        }

        long[][] dp = new long[81][81];
        ArrayUtils.fill(dp, MAX_VALUE);
        for (int i = 0; i <= 80; ++i) {
            dp[i][i] = 0;
        }
        for (int i = 0; i < n; ++i) {
            long[][] next = new long[81][81];
            ArrayUtils.fill(next, MAX_VALUE);
            for (int j = 0; j <= 80; ++j) {
                for (int k = 0; k <= 80; ++k) {
                    if (k > 0) {
                        next[j][k - 1] = Math.min(next[j][k - 1], dp[j][k] + b[i]);
                    }
                    if (k + 1 <= 80) {
                        next[j][k + 1] = Math.min(next[j][k + 1], dp[j][k] + a[i]);
                    }
                }
            }
            dp = next;
        }

        long[][] result = new long[81][81];
        ArrayUtils.fill(result, MAX_VALUE);
        for (int i = 0; i <= 80; ++i) {
            result[i][i] = 0;
        }

        for (; m > 0; m >>= 1) {
            if (m % 2 == 1) result = mul(result, dp);
            dp = mul(dp, dp);
        }

        out.println(result[0][0]);
    }

    private long[][] mul(long[][] a, long[][] b) {
        long[][] c = new long[81][81];
        ArrayUtils.fill(c, MAX_VALUE);
        for (int k = 0; k <= 80; ++k) {
            for (int i = 0; i <= 80; ++i) {
                for (int j = 0; j <= 80; ++j) {
                    c[i][j] = Math.min(c[i][j], a[i][k] + b[k][j]);
                }
            }
        }
        return c;
    }
}

class InputReader {
    BufferedReader reader;
    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 (Exception e) {
                throw new UnknownError();
            }
        }
        return tokenizer.nextToken();
    }

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

    }

class ArrayUtils {

    public static void fill(long[][] array, long value) {
        for (int i = 0; i < array.length; ++i) {
            Arrays.fill(array[i], value);
        }
    }

    }


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

public class F946{

    long[] fibpow;
    char[] chs;
    long mod = 1000000007L;
    long modpow = mod-1L;
    long[][][] memo;

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

    private void solve() throws Exception {
        int n = nextInt();
        int x = nextInt();
        chs = nextToken().toCharArray();
        memo = new long[n][n][x+1];
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) Arrays.fill(memo[i][j], -1);
        fibpow = new long[x+1];
        if(x > 0) fibpow[1] = 1L;
        for(int i = 2; i <= x; i++) fibpow[i] = (fibpow[i-1]+ fibpow[i-2])%modpow;
        for(int i = 0; i <= x; i++) fibpow[i] = pow(2, fibpow[i]);
        out.println(doit(0,n-1,x));
    }

    long doit(int i, int j, int x) {
        if (x < 2 && i == j && chs[i]-'0' == x) return 1L;
        else if (x < 2 && i == j && chs[i]-'0' != x) return 0L;
        else if(x < 2 && i < j) return 0L;
        else if(memo[i][j][x] < 0){
            long res = 0L;
            res = (res + ((i==0?fibpow[x]:(1L)) * doit(i,j, x-2))%mod)%mod;
            for(int t = i; t < j; t++) res = (res + (doit(i,t,x-1) * doit(t+1,j, x-2))%mod)%mod;
            res = (res + (doit(i,j,x-1) * (j==chs.length-1? fibpow[x-1]:(1L)))%mod)%mod;
            memo[i][j][x] = res;
        }
        return memo[i][j][x];
    }

    public static void main(String[] args) {
        (new F946()).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();
    }

}


import java.util.*;
import java.io.*;
public class Main {
    static BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder out = new StringBuilder();

    public static void main(String[] args){
        int[] inp = nextIntArray();
        double r, h;
        r = inp[0]; h = inp[1];
        double a = (h + r/2) / r;
        double b =  ( ( (2 - Math.sqrt(3)) * r / 2 ) + h) / r;
        a = 2 * Math.floor(0.0000001 + a);
        b = 1 + 2 * Math.floor(0.0000001 + b);
        out.append((int) Math.max(a, b));

        System.out.println(out);
    }

    // the followings are methods to take care of inputs.
    static int nextInt(){
        return Integer.parseInt(nextLine());
    }
    static long nextLong(){
        return Long.parseLong(nextLine());
    }
    static int[] nextIntArray(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){
            ary[i] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static int[] nextIntArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArray(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length];
        for (int i = 0; i < inp.length; i++){
            ary[i] = Long.parseLong(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Long.parseLong(inp[i]);
        }
        return ary;
    }
	static String nextLine(){
		try {
			return reader.readLine().trim();
		} catch (Exception e){}
		return null;
	}
}


  import java.awt.Checkbox;
import java.awt.Point;
import java.io.*;
                    import java.math.*;
                    import java.util.*;
import java.util.Map.Entry;

import javax.print.attribute.SetOfIntegerSyntax;
import javax.swing.plaf.FontUIResource;

                    public class CODE2{
                      private static InputStream stream;
                        private static byte[] buf = new byte[1024];
                        private static int curChar;
                        private static int numChars;
                        private static SpaceCharFilter filter;
                        private static PrintWriter pw;
                        private static long count = 0,mod=1000000007;
                    //    private static TreeSet<Integer> ts=new TreeSet[200000];
public final static int INF = (int) 1E9;

public static void main(String args[]) {
    InputReader(System.in);
    pw = new PrintWriter(System.out);
    new Thread(null ,new Runnable(){
       public void run(){
           try{
               solve();

               pw.close();
           } catch(Exception e){
               e.printStackTrace();
           }
       }
   },"1",1<<26).start();
   }
    static StringBuilder sb;
    public static void test(){
         sb=new StringBuilder();
        int t=nextInt();
        while(t-->0){

            solve();

        }
        pw.println(sb);
    }
    public static long pow(long n, long p,long mod) {
        if(p==0)
            return 1;
        if(p==1)
            return n%mod;
        if(p%2==0){
            long temp=pow(n, p/2,mod);
        return (temp*temp)%mod;
        }else{
                 long temp=pow(n,p/2,mod);
                 temp=(temp*temp)%mod;
                 return(temp*n)%mod;

        }
    }
    public static long pow(long n, long p) {
        if(p==0)
            return 1;
        if(p==1)
            return n;
        if(p%2==0){
            long temp=pow(n, p/2);
        return (temp*temp);
        }else{
                 long temp=pow(n,p/2);
                 temp=(temp*temp);
                 return(temp*n);

        }
    }
    public static void Merge(long a[],int p,int r){
        if(p<r){
            int q = (p+r)/2;
            Merge(a,p,q);
            Merge(a,q+1,r);
            Merge_Array(a,p,q,r);
        }
    }
    public static void Merge_Array(long a[],int p,int q,int r){
       long b[] = new long[q-p+1];
        long c[] = new long[r-q];
        for(int i=0;i<b.length;i++)
            b[i] = a[p+i];
        for(int i=0;i<c.length;i++)
            c[i] = a[q+i+1];
        int i = 0,j = 0;
        for(int k=p;k<=r;k++){
            if(i==b.length){
                a[k] = c[j];
                j++;
            }
            else if(j==c.length){
                a[k] = b[i];
                i++;
            }
            else if(b[i]<c[j]){
                a[k] = b[i];
                i++;
            }
            else{
                a[k] = c[j];
                j++;
            }
        }
    }

    public static long gcd(long x, long y) {
        if (x == 0)
            return y;
        else
            return gcd( y % x,x);
    }

    public static boolean isPrime(int n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

        static LinkedList<Integer> adj[];
        static boolean Visited[];
        static HashSet<Integer> exc;
        static long oddsum[]=new long[1000001];
        static long co=0,ans=0;

        private static void buildgraph(int n){
            adj=new LinkedList[n+1];
            Visited=new boolean[n+1];
            levl=new int[n+1];

            for(int i=0;i<=n;i++){
                adj[i]=new LinkedList<Integer>();

            }

        }

        static int[] levl;
        static int[] eat;
        static int n,m;
        static int price[];
        //ind frog crab

        public static void solve(){

        	int n=nextInt();
        	int x=nextInt();
        	int a[]=nextIntArray(n);
        	int freq[]=new int[x];
        	int cnt=0;
        	for(int i=0;i<n;i++){
        		if(a[i]<x){
        			freq[a[i]]++;
        		}
        		if(a[i]==x)
        			cnt++;
        	}
        	for(int i=0;i<x;i++){
        		if(freq[i]==0){
        			cnt++;
        		}
        	}
        	pw.println(cnt);
    }

        static int col[];
    public static boolean isVowel(char c){
        if(c=='a' || c=='e'||c=='i' || c=='o' || c=='u')
            return true;
        return false;
    }
static int no_vert=0;

  private static void dfs(int start){
      Visited[start]=true;
     no_vert++;

      for(int i:adj[start]){
          if(!Visited[i])
              {
              col[i]=col[start]^1;
              dfs(i);

              }
      }

  }

    public static String reverseString(String s) {
        StringBuilder sb = new StringBuilder(s);
        sb.reverse();
        return (sb.toString());
    }

  /*
   private static void BFS(int sou){
        Queue<Integer> q=new LinkedList<Integer>();
        q.add(sou);
        Visited[sou]=true;
        levl[sou]=0;
        while(!q.isEmpty()){
            int top=q.poll();

            for(int i:adj[top]){
                //pw.println(i+" "+top);
            if(!Visited[i])
            {

                q.add(i);
                levl[i]=levl[top]+1;
            }

            Visited[i]=true;

            }
        }
    }*/

                  static int indeg[];
               /* private static void kahn(int n){

                    PriorityQueue<Integer> q=new PriorityQueue<Integer>();
                    for(int i=1;i<=n;i++){
                        if(indeg[i]==0){
                            q.add(i);
                        }
                    }
                    while(!q.isEmpty()){
                        int top=q.poll();
                        st.push(top);
                        for(Node i:adj[top]){
                            indeg[i.to]--;
                            if(indeg[i.to]==0){
                                q.add(i.to);
                            }
                        }
                    }
                }

                    static int state=1;
                    static long no_exc=0,no_vert=0;
                  static Stack<Integer> st;
                  static HashSet<Integer> inset;
                 /*   private static void topo(int curr){

                        Visited[curr]=true;
                        inset.add(curr);
                        for(int x:adj[curr]){
                            if(adj[x].contains(curr) || inset.contains(x)){
                                state=0;
                                return;
                            }
                            if(state==0)
                                return;

                        }
                        st.push(curr);

                        inset.remove(curr);
                    }*/
                    static HashSet<Integer> hs;

                     static boolean prime[];
                    static int spf[];
                    public static void sieve(int n){
                        prime=new boolean[n+1];
                        spf=new int[n+1];

                        Arrays.fill(spf, 1);
                        Arrays.fill(prime, true);
                    prime[1]=false;
                        spf[2]=2;

                    for(int i=4;i<=n;i+=2){
                        spf[i]=2;
                    }
                    for(int i=3;i<=n;i+=2){
                        if(prime[i]){
                            spf[i]=i;
                            for(int j=2*i;j<=n;j+=i){

                                prime[j]=false;
                            if(spf[j]==1){
                                spf[j]=i;
                            }
                            }
                        }
                    }

                    }

                    // To Get Input
// Some Buffer Methods

                     public static void sort(long a[]){
                         Merge(a, 0, a.length-1);
                     }
                    public static void InputReader(InputStream stream1) {
                        stream = stream1;
                    }

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

                    private static boolean isEndOfLine(int c) {
                        return c == '\n' || c == '\r' || c == -1;
                    }

                    private static 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++];
                    }

                    private static 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;
                    }

                    private static 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;
                    }

                    private static String nextToken() {
                        int c = read();
                        while (isSpaceChar(c))
                            c = read();
                        StringBuilder res = new StringBuilder();
                        do {
                            res.appendCodePoint(c);
                            c = read();
                        } while (!isSpaceChar(c));
                        return res.toString();
                    }

                    private static String nextLine() {
                        int c = read();
                        while (isSpaceChar(c))
                            c = read();
                        StringBuilder res = new StringBuilder();
                        do {
                            res.appendCodePoint(c);
                            c = read();
                        } while (!isEndOfLine(c));
                        return res.toString();
                    }

                    private static int[] nextIntArray(int n) {
                        int[] arr = new int[n];
                        for (int i = 0; i < n; i++) {
                            arr[i] = nextInt();
                        }
                        return arr;
                    }

                    private static long[][] next2dArray(int n, int m) {
                        long[][] arr = new long[n][m];
                        for (int i = 0; i < n; i++) {
                            for (int j = 0; j < m; j++) {
                                arr[i][j] = nextLong();
                            }
                        }
                        return arr;
                    }
                    private static char[][] nextCharArray(int n,int m){
                        char [][]c=new char[n][m];
                        for(int i=0;i<n;i++){
                            String s=nextLine();
                            for(int j=0;j<s.length();j++){
                                c[i][j]=s.charAt(j);
                            }
                        }
                        return c;
                    }

                    private static long[] nextLongArray(int n) {
                        long[] arr = new long[n];
                        for (int i = 0; i < n; i++) {
                            arr[i] = nextLong();
                        }
                        return arr;
                    }

                    private static void pArray(int[] arr) {
                        for (int i = 0; i < arr.length; i++) {
                            pw.print(arr[i] + " ");
                        }
                        pw.println();
                        return;
                    }

                    private static void pArray(long[] arr) {
                        for (int i = 0; i < arr.length; i++) {
                            pw.print(arr[i] + " ");
                        }
                        pw.println();
                        return;
                    }

                    private static void pArray(boolean[] arr) {
                        for (int i = 0; i < arr.length; i++) {
                            pw.print(arr[i] + " ");
                        }
                        pw.println();
                        return;
                    }

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

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

}


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

public class Main {

    static int N, M;
    static int[] J;
    static int[] K;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        J = sc.nextIntArray(N, -1);
        K = sc.nextIntArray(M);

        System.out.println(solve() ? "YES" : "NO");
    }

    static boolean solve() {
        int len = 0;
        for (int i = 0; i < M; i++) {
            len += K[i];
        }

        int[] cnt = new int[M];
        for (int i = 0; i < len; i++) {
            cnt[J[i]]++;
        }

        if( Arrays.equals(cnt, K) ) return true;

        for (int i = len; i < N; i++) {
            cnt[J[i-len]]--;
            cnt[J[i]]++;

            if( Arrays.equals(cnt, K) ) return true;
        }
        return false;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

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

        int[] nextIntArray(int n, int delta) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt() + delta;
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }

    static void writeLines(int[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (int a : as) pw.println(a);
        pw.flush();
    }

    static void writeLines(long[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (long a : as) pw.println(a);
        pw.flush();
    }

    static void writeSingleLine(int[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < as.length; i++) {
            if (i != 0) pw.print(" ");
            pw.print(as[i]);
        }
        pw.println();
        pw.flush();
    }

    static int max(int... as) {
        int max = Integer.MIN_VALUE;
        for (int a : as) max = Math.max(a, max);
        return max;
    }

    static int min(int... as) {
        int min = Integer.MAX_VALUE;
        for (int a : as) min = Math.min(a, min);
        return min;
    }

    static void debug(Object... args) {
        StringJoiner j = new StringJoiner(" ");
        for (Object arg : args) {
            if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));
            else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));
            else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));
            else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));
            else j.add(arg == null ? "null" : arg.toString());
        }
        System.err.println(j.toString());
    }

    static int lowerBound(int[] array, int value) {
        int low = 0, high = array.length, mid;
        while (low < high) {
            mid = ((high - low) >>> 1) + low;
            if (array[mid] < value) low = mid + 1;
            else high = mid;
        }
        return low;
    }

    static int upperBound(int[] array, int value) {
        int low = 0, high = array.length, mid;
        while (low < high) {
            mid = ((high - low) >>> 1) + low;
            if (array[mid] <= value) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}


import java.io.*;
import static java.lang.Math.*;
import java.util.*;
import java.util.function.*;
import java.lang.*;

public class Main {
    final static boolean debug = false;
    final static String fileName = "";
    final static boolean useFiles = false;

    public static void main(String[] args) throws FileNotFoundException {
        long start;
        if (debug)
            start = System.nanoTime();
        InputStream inputStream;
        OutputStream outputStream;
        if (useFiles) {
            inputStream = new FileInputStream(fileName + ".in");
            outputStream = new FileOutputStream(fileName + ".out");
        } else {
            inputStream = System.in;
            outputStream = System.out;
        }
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task(in, out);
        solver.solve();
        if(debug)
            out.println((System.nanoTime() - start) / 1e+9);
        out.close();
    }
}
class Task {
    public void solve() {
        int[][] a = new int[3][3];
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                a[i][j] = in.nextInt();
        int n = in.nextInt();
        long[][][] dp = new long[3][3][n + 1];
        for (int i = 1; i <= n; i++) {
            for (int from = 0; from < 3; from++) {
                for (int to = 0; to < 3; to++) {
                    if (from == to)
                        continue;
                    int other = 3 - (from + to);
                    dp[from][to][i] = min(dp[from][other][i - 1] + a[from][to] + dp[other][to][i - 1],
                            dp[from][to][i - 1] + a[from][other] + dp[to][from][i - 1] + a[other][to] + dp[from][to][i - 1]);
                }
            }
        }
        out.println(dp[0][2][n]);
    }

    private InputReader in;
    private PrintWriter out;

    Task(InputReader in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        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 double nextDouble(){
        return Double.parseDouble(next());
    }

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

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

    public byte nextByte(){
        return Byte.parseByte(next());
    }
}


import java.util.*;
import java.io.*;
public class c
{
	public static void main(String[] arg) throws IOException
	{
		new c();
	}
	public c() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		out.println(Math.max(1, 4*(int)(Math.sqrt(2)*n)));
		in.close(); out.close();
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}
}


public class H {
	public static void main(String[] args) {
		int n = new java.util.Scanner(System.in).nextInt();
		for (int i = 1; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				System.out.print(Integer.toString(i * j, n) + " ");
			}
			System.out.println();
		}
	}
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class MonthsYears {

	public static void main(String[] args){
		List<Integer> year = new ArrayList<>();
		year.add(31);
		year.add(28);
		year.add(31);
		year.add(30);
		year.add(31);
		year.add(30);
		year.add(31);
		year.add(31);
		year.add(30);
		year.add(31);
		year.add(30);
		year.add(31);

		List<Integer> values = new ArrayList<>();
		boolean containsLeap = false;
		boolean done = false;
		boolean match = true;
		Scanner sc = new Scanner(System.in);
		int sum =0;
		int n  = sc.nextInt();
		for(int counter =0;counter<n;counter++){
			int x = sc.nextInt();
			if(x==29 && containsLeap){
				System.out.println("NO");
				done = true;
				break;
			}else if(x==29 && !containsLeap){
				sum = sum+28;
				containsLeap = true;
				values.add(28);
			}else{
				sum = sum+x;
				values.add(x);
			}
		}

		int size = year.size();
		if(!done){
			for(int i=0;i<size;i++){
				int secondSum = year.get(i);

				for(int counter =1;counter<n;counter++){
					int indexMe = (i+counter)%size;
					secondSum = secondSum + year.get(indexMe);

				}

				if(sum==secondSum){
					match =true;
					for(int count =0;count<values.size();count++){
						int indexSum = (i+count)%12;

						if(year.get(indexSum)!=values.get(count)){
							match =false;
							break;
						}
					}

					if(match){
						done = true;
						break;
					}

					//done =true;
					//break;
				}

			}
			if(done){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}

	}

}


import java.io.*;
import java.util.*;
public class TwentyFive {
	public static void main(String[] args) throws Exception {
		FastIO in = new FastIO();
		String s = in.next();
		int ans = 0;
		for (int i=0; i<100000000; i+=25) {
			String test = i+"";
			if (test.length()!=s.length()) continue;
			int xValue = -1;
			boolean works = true;
			for (int j=0; j<s.length(); j++) {
				if (s.charAt(j)=='X') {
					if (xValue==-1) {
						xValue = test.charAt(j);
					}
					if (test.charAt(j)!=xValue) {
						works = false;
						break;
					}
				}
				else if (s.charAt(j)!='_') {
					if (test.charAt(j)!=s.charAt(j)) {
						works = false;
						break;
					}
				}
			}
			if (works) ans++;
		}
		System.out.println(ans);
	}
	static class FastIO {
		BufferedReader br;
	    StringTokenizer st;
	    public FastIO() throws IOException
	    {
	        br = new BufferedReader(
	            new InputStreamReader(System.in));

	    }

	    public String next() throws IOException
	    {
	        while (st == null || !st.hasMoreElements()) {

	            st = new StringTokenizer(br.readLine());
	        }
	        return st.nextToken();
	    }

	    public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); }

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

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

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


import java.util.Scanner;

public class Main {
	public static int N;
	public static int[] array;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		N = s.nextInt();
		array = new int[N];
		int min = 1 << 29;
		int count = 0;
		for (int i = 0; i < N; i++) {
			array[i] = s.nextInt();
			min = Math.min(min, array[i]);
		}
		for (int i : array) {
			if (i == min) {
				count++;
			}
		}
		if (count <= N / 2) {
			System.out.println("Alice");
		} else {
			System.out.println("Bob");
		}
	}
}


//1184A1
import java.util.*;
public class heidiA1{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    long r=sc.nextLong();
    if(r%2==0||r<=3)
    System.out.println("NO");
    else{
      System.out.println("1"+" "+((r-3)/2));
    }
  }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.Vector;

public class Main {

	static Vector<Vector<State> > v = new Vector<Vector<State> >();
	public static void main(String[] args) throws IOException {
		v.setSize(12);

		BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(cin.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int m = Integer.parseInt(tok.nextToken());
		int k = Integer.parseInt(tok.nextToken());
		for (int i = 0; i < n; i++) {
			v.set(i, new Vector<State>());
			cin.readLine();
			for (int j = 0; j < m; j++) {
				State s = new State();
				tok = new StringTokenizer(cin.readLine());
				s.a = Integer.parseInt(tok.nextToken());
				s.b = Integer.parseInt(tok.nextToken());
				s.c = Integer.parseInt(tok.nextToken());
				v.get(i).add(s);
			}
		}

		int mx=0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if(i == j) continue;
				int val = 0;
				Vector<Point> pro = new Vector<Point>();
				for (int kk = 0; kk < v.get(i).size(); kk++) {
					if(v.get(j).get(kk).b <= v.get(i).get(kk).a) continue;
					pro.add(new Point(v.get(j).get(kk).b - v.get(i).get(kk).a, v.get(i).get(kk).c));
				}
				int lim = k;
				Collections.sort(pro, new cmp());
				for (int kk = 0; kk < pro.size(); kk++) {
					if(pro.get(kk).y <= lim){
						lim -= pro.get(kk).y;
						val += pro.get(kk).x*pro.get(kk).y;
					}
					else{
						val += pro.get(kk).x*lim;
						break;
					}
				}
				mx = Math.max(mx,val);
			}
		}
		System.out.println(mx);
	}

}
class State{
	public int a,b,c;

}

class cmp implements Comparator<Point>{

	@Override
	public int compare(Point o1, Point o2) {
		if(o1.x > o2.x) return -1;
		if(o1.x < o2.x) return 1;
		if(o1.y > o2.y) return -1;
		if(o1.y < o2.y) return 1;
		return 0;
	}

}


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

public class G {

	static final int P = 1_000_000_007;

	void submit() {
		int n = nextInt();
		int m = nextInt();
		long exp = nextLong();
		int[] a = new int[n];
		int[] b = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		int maxCoef = 0;
		for (int i = 0; i < m; i++) {
			b[i] = nextInt();
			maxCoef = Math.max(maxCoef, b[i]);
		}

		int[] bPoly = new int[maxCoef + 1];
		bPoly[maxCoef] = 1;
		for (int pow : b) {
			bPoly[maxCoef - pow]--;
			if (bPoly[maxCoef - pow] < 0) {
				bPoly[maxCoef - pow] += P;
			}
		}

		int[] aPoly = {};
		for (int pow : a) {
			aPoly = sum(aPoly, quotPow(new int[] { 0, 1 }, bPoly, pow));
		}
		int[] ans = quotPow(aPoly, bPoly, exp);

		ans = prod(ans, quotPow(new int[] { 0, 1 }, bPoly, maxCoef));
		ans = quot(ans, bPoly);

		out.println((long)ans[0] * inv(P - bPoly[0]) % P);
	}

	int inv(int x) {
		return x == 1 ? 1 : P - (int)((long)(P / x) * inv(P % x) % P);
	}

	int[] quotPow(int[] a, int[] b, long n) {
		a = quot(a, b);
		int[] ret = { 1 };
		for (; n > 0; n >>= 1) {
			if ((n & 1) == 1) {
				ret = quot(prod(ret, a), b);
			}
			a = quot(prod(a, a), b);
		}
		return ret;
	}

	int[] sum(int[] a, int[] b) {
		int[] c = Arrays.copyOf(a, Math.max(a.length, b.length));
		for (int i = 0; i < b.length; i++) {
			c[i] += b[i];
			if (c[i] >= P) {
				c[i] -= P;
			}
		}
		return c;
	}

	int[] prod(int[] a, int[] b) {
		int[] c = new int[a.length + b.length - 1];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b.length; j++) {
				c[i + j] += (int) ((long) a[i] * b[j] % P);
				if (c[i + j] >= P) {
					c[i + j] -= P;
				}
			}
		}
		return c;
	}

	int[] quot(int[] a, int[] b) {
		a = a.clone();
		// leading coef of b is 1
		if (a.length < b.length) {
			return a;
		}
		int degB = b.length - 1;
		for (int ptr = a.length - 1; ptr >= degB; ptr--) {
			long coef = a[ptr];
			for (int i = 0, j = ptr - degB; i < degB; i++, j++) {
				a[j] -= (int) (coef * b[i] % P);
				if (a[j] < 0) {
					a[j] += P;
				}
			}
		}
		return Arrays.copyOf(a, degB);
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	G() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

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

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

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

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

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


import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Codeforces911C {

    public static void main(String[] args) {
        Integer[] array = new Integer[3];
        boolean possible = false;
        Scanner scanner = new Scanner(System.in);
        array[0] = scanner.nextInt();
        array[1] = scanner.nextInt();
        array[2] = scanner.nextInt();
        List<Integer> list = Arrays.asList(array);
        Collections.sort(list);
        array = (Integer[]) list.toArray();
        int sum = array[0] + array[1] + array[2];
        if (sum > 7) {

            if (array[0] == 1) {
                possible = true;
            } else if (array[1] <= 2) {
                possible = true;
            } else if (array[1] == 3) {
                if (array[0] == 3 && array[2] == 3) {
                    possible = true;
                } else {
                    possible = false;
                }
            } else if (array[1] == 4) {
                if (array[2] == 4 && array[0] == 2) {
                    possible = true;
                } else {
                    possible = false;
                }
            }

        } else {
            possible = true;
        }
        if(possible){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
//        int gcd = BigInteger.valueOf(array[0]).gcd(BigInteger.valueOf(array[1])).gcd(BigInteger.valueOf(array[2])).intValue();
//        gcd = array[0]*array[1]*array[2]/gcd;

    }
}


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

import static java.lang.Math.*;

public class Main implements Runnable {

    static String filename = "";

    int[] factorize(int n) {
        ArrayList<Integer> ans = new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            while (n % i == 0) {
                ans.add(i);
                n /= i;
            }
        }
        int[] ansa = new int[ans.size()];
        for (int i = 0; i < ans.size(); i++) {
            ansa[i] = ans.get(i);
        }
        return ansa;
    }

    int gcd(int a, int b) {
        while (b != 0) {
            a %= b;
            int temp = a;
            a = b;
            b = temp;
        }
        return a;
    }

    int digitsum(int n, int b) {
        int ans = 0;
        while (n > 0) {
            ans += n % b;
            n /= b;
        }
        return ans;
    }

    int get3(int b) {
        Random rnd = new Random();
        int ans = 0;
        for (int i = 0; i < 10000; i++) {
            int num = rnd.nextInt(1000000000);
            ans = gcd(ans, num - digitsum(num, b));
        }
        return ans;
    }

    int is2type(int b, int d) {
        int[] bfactors = factorize(b);
        int[] dfactors = factorize(d);

        boolean type2 = true;
        TreeMap<Integer, Integer> bf = new TreeMap<Integer, Integer>();
        for (int i : bfactors) {
            if (!bf.containsKey(i)) {
                bf.put(i, 0);
            }
            bf.put(i, bf.get(i) + 1);
        }
        TreeMap<Integer, Integer> df = new TreeMap<Integer, Integer>();
        for (int i : dfactors) {
            if (!df.containsKey(i)) {
                df.put(i, 0);
            }
            df.put(i, df.get(i) + 1);
        }
        for (int i : dfactors) {
            if (!bf.containsKey(i)) {
                type2 = false;
            }
        }

        if (type2) {
            int ans = 0;
            long pow = 1;
            while (pow % d != 0) {
                pow *= b;
                ans++;
                /*
                for (Map.Entry<Integer, Integer> e : df.entrySet()) {
                    System.out.println(e.getKey() + " " + e.getValue());
                }
                System.out.println();
                */
            }
            return ans;
        } else {
            return -1;
        }
    }

    boolean is3type(int b, int d) {
        return (b - 1) % d == 0;
    }

    boolean is11type(int b, int d) {
        return (b + 1) % d == 0;
    }

    HashMap<Integer, Boolean> type6 = new HashMap<Integer, Boolean>();

    boolean is6type(int b, int d) {
        if (type6.containsKey(d)) {
            return type6.get(d);
        }
        for (int i = 2; i < d; i++) {
            if (d % i == 0) {
                int di = d / i;
                if (i % di == 0 || di % i == 0) {
                    continue;
                }
                boolean[] m1 = getMask(b, i);
                boolean[] m2 = getMask(b, di);
                for (int ii = 0; ii < 4; ii++) {
                    for (int jj = 0; jj < 4; jj++) {
                        if (ii == jj) {
                            continue;
                        }
                        if (m1[ii] && m2[jj]) {
                            type6.put(d, true);
                            return true;
                        }
                    }
                }
                /*
                if (is2type(b, i) != -1 || is3type(b, i) || is11type(b, i) || is6type(b, i)) {
                    if (is2type(b, di) != -1 || is3type(b, di) || is11type(b, di) || is6type(b, di)) {
                        if (is3type(b, i) && is3type(b, di))
                            continue;
                        type6.put(d, true);
                        return true;
                    }
                }
                */
            }
        }
        type6.put(d, false);
        return false;
    }

    boolean[] getMask(int b, int d) {
        boolean[] ans = new boolean[4];
        ans[0] = is2type(b, d) != -1;
        ans[1] = is3type(b, d);
        ans[2] = is11type(b, d);
        ans[3] = is6type(b, d);
        return ans;
    }

    public void solve() throws Exception {
        int b = sc.nextInt(), d = sc.nextInt();
        int ans;
        if ((ans = is2type(b, d)) != -1) {
            out.println("2-type");
            out.println(ans);
        } else if (is3type(b, d)) {
            out.println("3-type");
        } else if (is11type(b, d)) {
            out.println("11-type");
        } else if (is6type(b, d)) {
            out.println("6-type");
        } else {
            out.println("7-type");
        }
    }

    BufferedReader in;
    PrintWriter out;
    FastScanner sc;

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 1 << 25).start();
    }

    @Override
    public void run() {
        try {
            init();
            solve();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            out.close();
        }
    }

    void init() throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        sc = new FastScanner(in);
    }
}

class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

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

        return strTok.nextToken();
    }

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

    public BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

}


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

/**
 * @author Don Li
 */
public class ArtemArray {
    void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();

        long ans = 0;
        int[] b = new int[n];
        int m = 0;
        for (int i = 0; i < n; i++) {
            while (m > 1 && b[m - 1] <= Math.min(b[m - 2], a[i])) {
                ans += Math.min(b[m - 2], a[i]);
                m--;
            }
            b[m++] = a[i];
        }

        for (int i = 1; i < m - 1; i++) ans += Math.min(b[i - 1], b[i + 1]);

        out.println(ans);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new ArtemArray().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

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

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

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

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


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

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);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskE {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n=in.readInt(), sx=in.readInt()%n, sy=in.readInt()%n, dx=in.readInt()%n, dy=in.readInt()%n;
        long t=in.readLong(), Sx=(2L*sx+dx+sy)%n, Sy=(2L*sy+dy+sx)%n, Dx=(dx+sx+sy)%n, Dy=(dy+sy+sx)%n, t0=(t%2==0?t/2:t)%n, t1=(t%2==1?(t-1)/2:t-1)%n;
        Matrix.mod=n;
        Matrix base=new Matrix(new long[][] {
            {2, 1, 1, 1, 0, 0},
            {1, 2, 1, 1, 0, 0},
            {1, 0, 1, 0, 0, 0},
            {0, 1, 0, 1, 0, 0},
            {1, 1, 1, 1, 1, 0},
            {0, 0, 0, 0, 1, 1}
        }), matrix=new Matrix(new long[][]{
            {Sx, Sy, Dx, Dy, 1, 1},
            {sx, sy, dx, dy, 0, 1}
        });
        long[][] data=Matrix.multiply(matrix, base.power(t)).data;
        Sx=(data[1][0]+n)%n;
        Sy=(data[1][1]+n)%n;
        //out.printLine(data[1][0], data[1][1]);
        out.printLine(Sx==0?n:Sx, Sy==0?n:Sy);
    }
}

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 int readInt() {
        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 readLong() {
        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 static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

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

class OutputWriter {
    private final PrintWriter writer;

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

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

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

}

class Matrix {
    public static long mod = Long.MAX_VALUE;
    public final long[][] data;
    public final int rowCount;
    public final int columnCount;

    public Matrix(int rowCount, int columnCount) {
        this.rowCount = rowCount;
        this.columnCount = columnCount;
        this.data = new long[rowCount][columnCount];
    }

    public Matrix(long[][] data) {
        this.rowCount = data.length;
        this.columnCount = data[0].length;
        this.data = data;
    }

    public static Matrix multiply(Matrix first, Matrix second) {
        Matrix result = new Matrix(first.rowCount, second.columnCount);
        for (int i = 0; i < first.rowCount; i++) {
            for (int j = 0; j < second.rowCount; j++) {
                for (int k = 0; k < second.columnCount; k++)
                    result.data[i][k] = (result.data[i][k] + first.data[i][j] * second.data[j][k]) % mod;
            }
        }
        return result;
    }

    public static Matrix identityMatrix(int size) {
        Matrix result = new Matrix(size, size);
        for (int i = 0; i < size; i++)
            result.data[i][i] = 1;
        return result;
    }

    public Matrix power(long exponent) {
        if (exponent == 0)
            return identityMatrix(rowCount);
        if (exponent == 1)
            return this;
        Matrix result = power(exponent >> 1);
        result = multiply(result, result);
        if ((exponent & 1) == 1)
            result = multiply(result, this);
        return result;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Dot {

    static int N, D;
    static int[] vx, vy;
    static Boolean[][][][] dp;

    static long sq(long x) {
	return x * x;
    }

    static boolean solve(int p1, int p2, int x, int y) {
	if (sq(x) + sq(y) > sq(D))
	    return true;
	if (dp[p1][p2][x + 200][y + 200] != null)
	    return dp[p1][p2][x + 200][y + 200];
	boolean ans = false;
	if (p1 == 0)
	    ans |= !solve(p2, 1, y, x);
	for (int i = 0; i < N; i++)
	    ans |= !solve(p2, p1, x + vx[i], y + vy[i]);
	return dp[p1][p2][x + 200][y + 200] = ans;
    }

    public static void main(String[] args) throws IOException {
	MyScanner sc = new MyScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	int x = sc.nextInt(), y = sc.nextInt();
	N = sc.nextInt();
	D = sc.nextInt();
	vx = new int[N];
	vy = new int[N];
	for (int i = 0; i < N; i++) {
	    vx[i] = sc.nextInt();
	    vy[i] = sc.nextInt();
	}
	dp = new Boolean[2][2][402][402];
	out.println(solve(0, 0, x, y) ? "Anton" : "Dasha");
	out.flush();
	out.close();
    }

    static class MyScanner {

	BufferedReader br;
	StringTokenizer st;

	MyScanner(InputStream is) {
	    br = new BufferedReader(new InputStreamReader(is));
	}

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

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

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

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


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

public class C_submit {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static long[][] c = new long[61][];
	static {
		for (int i = 0; i < c.length; i++) {
			c[i] = new long[i + 1];
			c[i][0] = c[i][i] = 1;
			for (int j = 1; j < i; j++)
				c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}

	long c(int n, int k) {
		return n < 0 || k < 0 || k > n ? 0 : c[n][k];
	}

	void solve() throws IOException {
		long n = nextLong();
		long t = nextLong();
		if (Long.bitCount(t) != 1) {
			out.println(0);
			return;
		}

		int need = Long.numberOfTrailingZeros(t) + 1;

		// return numbers of x : 2 <= x <= n + 1, bitcount(x) = need

		n += 2;

		String s = Long.toBinaryString(n);

		int prefBitCnt = 0;

		long ans = 0;

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == '1') {
				int sufLen = s.length() - i - 1;
				ans += c(sufLen, need - prefBitCnt);
				prefBitCnt++;
			}
		}

		if (need == 1)
			ans--;

		out.println(ans);
	}

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

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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


import java.util.Scanner;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

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

class TaskC {
     public final long MOD = 1000000007;
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        String a = in.next();
        String b = in.next();
        long[][] dp = new long[2][5001];
        ArrayUtils.fill(dp, 0);
        int flag = 0;
        long res = 0;
        for (int i = 0; i < a.length(); ++i){
            Arrays.fill(dp[i&1], 0);
            for (int j = 0; j < b.length(); ++j){
                if (j >= 1){
                    dp[i&1][j] = dp[i&1][j - 1];
                }
                if (a.charAt(i) == b.charAt(j)){
                    ++dp[i&1][j];
                    if (i >= 1 && j >= 1){
                        dp[i&1][j] += dp[(i-1)&1][j-1];
                    }
                    dp[i&1][j] %= MOD;
                }
            }
            res += dp[i&1][b.length() -  1];       res %= MOD;
        }
        out.println(res);
        return;
    }

}

class ArrayUtils {

    public static void fill(long[][] array, long value) {
        for (long[] row : array)
            Arrays.fill(row, value);
    }

    }


//package com.company;

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

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader input = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(input);

        String s = in.readLine();
        String ss[] = s.split(" ");

        int n = Integer.parseInt(ss[0]);
        int k = Integer.parseInt(ss[1]);

        String number = in.readLine();
        if (k == 0)
        {
            System.out.println(number);
        }
        else if(n == 1)
        {
            System.out.println("0");
        }
        else
        {
            StringBuffer tmp = new StringBuffer();
            tmp.append("1");

            if(number.charAt(0) != '1')
                k--;

            int counter = 1;
            while(k > 0 && counter < n)
            {
                if(number.charAt(counter) != '0')
                {
                     k--;
                }
                counter++;
                tmp.append("0");
            }

            if(counter < n)
                tmp.append(number.substring(counter));

            System.out.println(tmp.toString());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.StringTokenizer;

public class DimaAndHorses2 {
    public static void main(String[] args) {
        InputReader r = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = r.nextInt(), m = r.nextInt();
        ArrayList<Integer>[] adj = new ArrayList[n];
        for (int i = 0; i < adj.length; i++) {
            adj[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int from = r.nextInt() - 1;
            int to = r.nextInt() - 1;
            adj[from].add(to);
            adj[to].add(from);
        }
        int[] res = new int[n];
        Queue<Integer> q = new LinkedList<Integer>();
        for (int i = 0; i < n; i++)
            q.add(i);
        while (!q.isEmpty()) {
            int f = q.remove();
            int enemies = 0;
            for (int x : adj[f])
                if (res[x] == res[f])
                    enemies++;
            if (enemies < 2)
                continue;
            res[f] = 1 - res[f];
            for (int x : adj[f])
                q.add(x);
            q.add(f);
        }
        for (int x : res)
            out.print(x);
        out.close();
        return;
    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return 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());
        }
    }
}