package codeforces.c197;

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

public class ETry implements Runnable {

    private PrintWriter out = new PrintWriter(System.out, true);
    private Scanner scanner;

    int n;
    int[] size;
    int[] parent;
    PointWI[] points;
    int[] ans;

    Graph graph;

    @Override
    public void run() {
        n = scanner.nextInt();
        // читаем граф
        graph = new Graph(n);

        for (int i = 0; i < n - 1; i++) {
            int x = scanner.nextInt() - 1;
            int y = scanner.nextInt() - 1;
            graph.addEdge(x, y);
        }

        // читаем точки
        points = new PointWI[n];
        for (int i = 0; i < n; i++) {
            points[i] = new PointWI(scanner.nextLong(), scanner.nextLong(), i);
        }

        // подвешиваем дерево и
        size = new int[n];
        parent = new int[n];
        dfs(0, -1);

        // считаем ответ
        ans = new int[n];
        Arrays.fill(ans, -1);

        // ищем самый левый
        List<PointWI> pointsList = Arrays.asList(points);

        PointWI min = Collections.min(pointsList, new MostLeftPointComparator());
        Collections.swap(pointsList, 0, min.i);

        // считаем
        rec(0, 0, n - 1);

        // ответ
        for (int i = 0; i < n; i++) {
            out.print(ans[i] + 1);
            if (i == n - 1) {
                out.println();
            } else {
                out.print(" ");
            }
        }
    }

    private void rec(int x, int left, int right) {
        ans[points[left].i] = x;
        Arrays.sort(points, left + 1, right + 1, new PointComparator(points[left]));
        int i = left + 1;
        for (int y : graph.adjacent(x)) {
            if (y != parent[x]) {
                rec(y, i, i + size[y] - 1);
                i += size[y];
            }
        }
    }

    private void dfs(int x, int p) {
        parent[x] = p;
        size[x] = 1;
        for (int y : graph.adjacent(x)) {
            if (y != p) {
                dfs(y, x);
                size[x] += size[y];
            }
        }
    }

    public ETry setInput(InputStream inputStream) {
        this.scanner = new Scanner(inputStream);
        return this;
    }

    public static void main(String[] args) {
        new ETry().setInput(System.in).run();
    }
}

class Graph {
    private final int n;
    private final List<List<Integer>> adj;

    public Graph(int n) {
        this.n = n;
        this.adj = new ArrayList<List<Integer>>(n);
        createAdjList(n);
    }

    private void createAdjList(int n) {
        while (n > 0) {
            this.adj.add(new ArrayList<Integer>());
            n--;
        }
    }

    public void addEdge(int v, int u) {
        adj.get(v).add(u);
        adj.get(u).add(v);
    }

    public Iterable<Integer> adjacent(int v) {
        return adj.get(v);
    }

    public int getN() {
        return n;
    }
}

//solution

class PointWI {
    long x, y;
    int i;

    public PointWI(long x, long y, int i) {
        this.x = x;
        this.y = y;
        this.i = i;
    }

    @Override
    public String toString() {
        return String.format("[(%d %d) %d]", x, y, i);
    }

}

class MostLeftPointComparator implements Comparator<PointWI> {
    @Override
    public int compare(PointWI p1, PointWI p2) {
        int byx = compare(p1.x, p2.x);
        if (byx == 0) {
            return compare(p1.y, p2.y);
        }
        return byx;
    }

    public static int compare(long a, long b) {
        return a < b ? -1 : (a == b ? 0 : 1);
    }
}

class PointComparator implements Comparator<PointWI> {
    PointWI root;

    public PointComparator(PointWI root) {
        this.root = root;
    }

    @Override
    public int compare(PointWI a, PointWI b) {
        long wp = (a.x - root.x) * (b.y - root.y) - (a.y - root.y) * (b.x - root.x);
        if (wp < 0)
            return -1;
        if (wp > 0)
            return 1;
        return 0;
    }
}


import java.util.*;

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

    private void solve(int n) {
        int sum = 0;
        for (int i=2; i<n; ++i) {
            int w = n;
            while (w >= i) {
                sum += w % i;
                w = w / i;
            }
            sum += w;
        }

        int x = gcd(sum, n-2);
        System.out.println((sum/x) + "/" + ((n-2)/x));
    }

    private int gcd(int c, int d) {
        int r = c % d;
        while (r != 0) {
            c = d;
            d = r;
        }
        return d;
    }

    public void run() {
        try {
            Scanner s = new Scanner(System.in);
            solve(s.nextInt());
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


import java.util.Scanner;
public class Numbers {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = n;
        int x = 0;
        int y = n - 2;
        for(int i=2; i<n; i++) {
            while(k >= i) {
                x += k % i;
                x /= i;
            }
            x += k;
            k = n;
        }
        System.out.println(x + "/" + y);
    }
}


import java.util.Scanner;

public class Table {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int [][]table = new int[n+1][n+1];

        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                table[i][j] = table[i][j-1]+i;
            }
        }
        int count=0;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                if(m==table[i][j])
                    count++;
            }

        }
        System.out.println(count);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.Collection;
import java.util.Random;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

  static class TaskD {
    static final IntModular MOD = new IntModular();
    int n;
    int m;
    int[] end1;
    int[] end2;
    IntArrayList points;
    IntArrayList counts;
    IntArrayList covered;
    IntArrayList newCovered;

    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      n = in.nextInt();
      m = in.nextInt();
      end1 = new int[m];
      end2 = new int[m];
      in.nextInts(m, end1, end2);
      initKeyPoints();
      int res = MOD.mul(n, n);
      IntArrayList edgeIdxs = new IntArrayList(m);
      for (int mask = (1 << m) - 1; mask > 0; --mask) {
        edgeIdxs.clear();
        for (int i = 0; i < m; ++i)
          if ((mask & (1 << i)) > 0) {
            edgeIdxs.add(i);
          }
        res = MOD.add(res, calcUnordered(edgeIdxs));
      }
      out.println(res);
    }

    void initKeyPoints() {
      points = new IntArrayList();
      for (int i = 0; i < m; ++i) {
        addKeyPoints(end1[i]);
        addKeyPoints(end2[i]);
      }
      points.sortAndUnique();
      counts = new IntArrayList(points.size);
      for (int point : points) {
        int cnt = 1;
        if (!points.binarySearch(point << 1)) {
          cnt += calcSubtree(point << 1);
        }
        if (!points.binarySearch((point << 1) | 1)) {
          cnt += calcSubtree((point << 1) | 1);
        }
        counts.add(cnt);
      }
    }

    int calcSubtree(int x) {
      int lower = x, upper = x;
      int res = 0;
      for (; lower <= n; lower <<= 1, upper = (upper << 1) | 1) {
        res += Math.min(n, upper) - lower + 1;
        if (n <= upper) break;
      }
      return res;
    }

    void addKeyPoints(int x) {
      for (; x > 0; x >>= 1) points.add(x);
    }

    int calcUnordered(IntArrayList edgeIdxs) {
      int res = 0;
      do {
        for (int mask = (1 << edgeIdxs.size) - 1; mask >= 0; --mask) {
          res = MOD.add(res, calcOrdered(edgeIdxs, mask));
        }
      } while (edgeIdxs.nextPermutation());
      return res;
    }

    int calcOrdered(IntArrayList edgeIdxs, int orderMask) {
      if (covered == null) {
        covered = new IntArrayList();
      }
      covered.clear();
      int source = -1, sink = -1;
      for (int i = 0; i < edgeIdxs.size; ++i) {
        int from, to;
        if ((orderMask & (1 << i)) > 0) {
          from = end1[edgeIdxs.get(i)];
          to = end2[edgeIdxs.get(i)];
        } else {
          from = end2[edgeIdxs.get(i)];
          to = end1[edgeIdxs.get(i)];
        }
//System.out.printf("(%d->%d) ", from, to);
        if (source < 0) {
          source = from;
          covered.add(source);
        }
        if (i > 0) addPath(sink, from);
        sink = to;
      }
//System.out.println();
      covered.add(sink);
      int coveredSize = covered.size;
//System.out.printf("\tcovered:%s\n", covered.toDisplay());
      covered.sortAndUnique();
//System.out.printf("\tcovered:%s\n", covered.toDisplay());
//if (coveredSize != covered.size) System.out.printf("\tno %d %d\n", coveredSize, covered.size);
      if (coveredSize != covered.size) return 0;
      int res = 0;
      for (int i = 0; i < points.size; ++i) {
        int u = points.get(i);
        for (int j = 0; j < points.size; ++j) {
          int v = points.get(j);
//if (u != v) System.out.printf("\t(%d,%d)->(%d,%d):%b\n", u, source, v, sink, isValid(u, source, v, sink));
          if (u == v || !isValid(u, source, v, sink)) continue;
          res = MOD.add(res, MOD.mul(counts.get(i), counts.get(j)));
        }
      }
      return res;
    }

    void addPath(int x, int y) {
      while (x != y) {
        if (x < y) {
          covered.add(y);
          y >>= 1;
        } else {
          covered.add(x);
          x >>= 1;
        }
      }
      covered.add(x);
    }

    boolean isValid(int source0, int sink0, int source1, int sink1) {
      if (newCovered == null) {
        newCovered = new IntArrayList();
      }
      newCovered.clear();
//System.out.printf("\t\t(%d,%d)->(%d,%d)\n", source0, sink0, source1, sink1);
//System.out.println("\t\tstep1");
      if (!addPathWithCheck(source0, sink0)) return false;
//System.out.println("\t\tstep2");
      if (!addPathWithCheck(source1, sink1)) return false;
//System.out.printf("\t\tstep3 %s\n", newCovered.toDisplay());
      int size = newCovered.size;
      newCovered.sortAndUnique();
      return size == newCovered.size;
    }

    boolean addPathWithCheck(int x, int y) {
      int sink = y;
      while (x != y) {
        if (x < y) {
          if (sink != y) {
            if (covered.binarySearch(y)) return false;
            newCovered.add(y);
          }
          y >>= 1;
        } else {
          if (covered.binarySearch(x)) return false;
          newCovered.add(x);
          x >>= 1;
        }
      }
      if (sink != x) {
        if (covered.binarySearch(x)) return false;
        newCovered.add(x);
      }
      return true;
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

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

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

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

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

  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPosition;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPosition = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) throw new RuntimeException();
        res = res * 10 + (c - '0');
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public void nextInts(int n, int[]... res) {
      int m = res.length;
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
          res[j][i] = nextInt();
        }
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPosition >= numberOfChars) {
        currentPosition = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPosition++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' ' || c == '\t' || isEndOfLineChar(c);
    }

    public boolean isEndOfLineChar(int c) {
      return c == '\n' || c == '\r' || c < 0;
    }

  }

  static interface IntCollection {
  }

  static class IntArrayList implements Displayable, IntCollection, Iterable<Integer> {
    private static final int[] EMPTY = {};
    public int[] values;
    public int size;

    public IntArrayList() {
      values = EMPTY;
      clear();
    }

    public IntArrayList(int capacity) {
      values = new int[IntUtils.nextPow2(capacity)];
      clear();
    }

    public IntArrayList(Collection<Integer> collection) {
      this(collection.size());
      addAll(collection);
    }

    public void clear() {
      size = 0;
    }

    public void add(int value) {
      ensureCapacity(size + 1);
      addInternal(value);
    }

    public void addAll(Collection<Integer> values) {
      ensureCapacity(size + values.size());
      for (int value : values) {
        addInternal(value);
      }
    }

    public int get(int idx) {
      if (idx >= size) throw new ArrayIndexOutOfBoundsException();
      return values[idx];
    }

    public void sort() {
      IntArrayUtils.sort(values, 0, size);
    }

    public void unique() {
      size = IntArrayUtils.unique(values, 0, size);
    }

    public void sortAndUnique() {
      sort();
      unique();
    }

    public int lowerBound(int value) {
      return IntArrayUtils.lowerBound(values, 0, size, value);
    }

    public boolean binarySearch(int value) {
      int idx = lowerBound(value);
      return idx < size && get(idx) == value;
    }

    public boolean nextPermutation() {
      return IntArrayUtils.nextPermutation(values, 0, size);
    }

    public void ensureCapacity(int capacity) {
      if (capacity <= values.length) return;
      int[] newValues = new int[IntUtils.nextPow2(capacity)];
      for (int i = 0; i < size; ++i) {
        newValues[i] = values[i];
      }
      values = newValues;
    }

    public Iterator<Integer> iterator() {
      return new Iterator<Integer>() {
        private int i = 0;

        public boolean hasNext() {
          return i < size;
        }

        public Integer next() {
          return values[i++];
        }
      };
    }

    private void addInternal(int value) {
      values[size++] = value;
    }

  }

  static class IntArrayUtils {
    private static final Random RANDOM = new Random(1000000007);

    public static void reverse(int[] values, int fromIdx, int toIdx) {
      for (int i = fromIdx, j = toIdx - 1; i < j; ++i, --j) {
        swap(values, i, j);
      }
    }

    public static int unique(int[] values, int fromIdx, int toIdx) {
      if (fromIdx == toIdx) return 0;
      int res = 1;
      for (int i = fromIdx + 1; i < toIdx; ++i) {
        if (values[i - 1] != values[i]) {
          values[fromIdx + res++] = values[i];
        }
      }
      return res;
    }

    public static void sort(int[] values, int fromIdx, int toIdx) {
      shuffle(values, fromIdx, toIdx);
      Arrays.sort(values, fromIdx, toIdx);
    }

    public static int lowerBound(int[] values, int fromIdx, int toIdx, int value) {
      int res = toIdx;
      for (int lower = fromIdx, upper = toIdx - 1; lower <= upper; ) {
        int medium = (lower + upper) >> 1;
        if (value <= values[medium]) {
          res = medium;
          upper = medium - 1;
        } else {
          lower = medium + 1;
        }
      }
      return res;
    }

    public static void swap(int[] values, int uIdx, int vIdx) {
      if (uIdx == vIdx) return;
      values[uIdx] ^= values[vIdx];
      values[vIdx] ^= values[uIdx];
      values[uIdx] ^= values[vIdx];
    }

    public static void shuffle(int[] values, int fromIdx, int toIdx) {
      for (int i = toIdx - fromIdx - 1; i > 0; --i) {
        swap(values, i + fromIdx, RANDOM.nextInt(i + 1) + fromIdx);
      }
    }

    public static boolean nextPermutation(int[] values, int fromIdx, int toIdx) {
      int pos = -1;
      for (int i = toIdx - 2; i >= fromIdx; --i)
        if (values[i] < values[i + 1]) {
          pos = i;
          break;
        }
      if (pos < 0) return false;
      int newPos = -1;
      for (int i = toIdx - 1; i > pos; --i)
        if (values[pos] < values[i]) {
          newPos = i;
          break;
        }
      swap(values, pos, newPos);
      reverse(values, pos + 1, toIdx);
      return true;
    }

  }

  static class IntUtils {
    public static boolean isPow2(int n) {
      return n > 0 && (n & (n - 1)) == 0;
    }

    public static int nextPow2(int n) {
      if (n < 1) return 1;
      return isPow2(n) ? n : Integer.highestOneBit(n) << 1;
    }

  }

  static interface Displayable {
  }

  static class IntModular {
    private static final int MOD = 1000000007;
    public final int mod;
    private final int[] x;

    public IntModular() {
      this(MOD);
    }

    public IntModular(int mod) {
      this.mod = mod;
      this.x = new int[2];
    }

    public int add(int a, int b) {
      return fix(a + b);
    }

    public int fix(int a) {
      a = slightFix(a);
      return 0 <= a && a < mod ? a : slightFix(a % mod);
    }

    public int mul(int a, int b) {
      return a > 0
          ? (b < mod / a ? a * b : (int) ((long) a * b % mod))
          : 0;
    }

    private int slightFix(int a) {
      return a >= mod
          ? a - mod
          : a < 0 ? a + mod : a;
    }

  }
}


import java.util.Scanner;

public class Main {

    /**
     * @param args
     */

    int[][][][] asdf = new int[130][130][130][30];
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Main test1 = new Main();
        test1.read();
        test1.write();

    }

    private void write() {
        // TODO Auto-generated method stub

    }

    private void read() {
        // TODO Auto-generated method stub
        Scanner fi = new Scanner(System.in);

        String n = fi.next();
        String kq = "";
        while (n.length() != 0) {

            int temp = Integer.valueOf(n.charAt(n.length() - 1)) - 48;
            if ((n.length() == 1) && (n.charAt(0) == '9'))
                kq = '9' + kq;
            else {

                if ((9 - temp) < temp)
                    kq = String.valueOf(9 - temp) + kq;
                else
                    kq = String.valueOf(temp) + kq;
            }
            n = n.substring(0, n.length() - 1);
            // n /= 10;
        }
        while ((kq.length() >= 1) && (kq.charAt(0) == '0'))
            kq = kq.substring(1, kq.length());
        System.out.println(kq);
    }
}


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

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

    static class B {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni(), m = in.ni(), k = in.ni();
            long mod = (int) 1e9 + 7;
            if (n == 1 || m == 1) {
                if (k == 1) {
                    out.println(1);
                } else {
                    if (n % 2 == 1 && m % 2 == 1) {
                        out.println(1);
                    } else
                        out.println(0);
                }
            } else {
                long pow = (n - 1) % (mod - 1) * (m - 1) % (mod - 1);
                long ans = IntegerUtils.pow(2, pow, mod) % mod;
                out.println(ans);

            }
        }

    }

    static class IntegerUtils {
        public static long pow(long a, long p, long mod) {
            if (p == 0) {
                return 1;
            }
            long t = pow(a, p / 2, mod);

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

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}


import java.util.Scanner;
public class Compare {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int plus = scan.nextInt();
    int minus = scan.nextInt();
    int z = scan.nextInt();
    if ((plus + z) < minus) {
      System.out.println("-");
    } else if ((minus + z) < plus ) {
      System.out.println("-=+");
    } else if (z == 0) {
      System.out.println("0");
    } else {
      System.out.println("?");
    }
  }
}


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

public class Problem190B {
    public static void main(String[] args) throws Exception {
        new Problem190B().solve(new Scanner(System.in), System.out);
    }

    public void solve(Scanner in, PrintStream out) throws Exception{
        int r = in.nextInt();
        int g = in.nextInt();
        int b = in.nextInt();
        boq = new int[r + 1][g + 1][b + 1];

        out.println(f(r, g, b));
    }

    int[][][] boq;

    int f(int r, int g, int b) {
        if (r < 0 || g < 0 || b < 0)
            return 0;

        if (boq[r][g][b] > 0) {
            return boq[r][g][b];
        }

        int m1 = r - 3 >= 0 ? f (r - 3, g, b) + 1 : 0;
        int m2 = g - 3 >= 0 ? f (r, g - 3, b) + 1 : 0;
        int m3 = b - 3 >= 0 ? f (r, g, b - 3) + 1 : 0;
        int m4 = r > 0 && g > 0 && b > 0 ? f (r - 1, g - 1, b - 1) + 1 : 0;

        boq[r][g][b] = Math.max(Math.max(m1, m2), Math.max(m3, m4));

        return boq[r][g][b];
    }
}


import java.util.Scanner;

public class main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        int count=0,temp;
        String n;
        n=input.nextLine();
        int charCount = 0;
        for( int i = 0; i <n.length( ); i++ )
        {

            if( n.charAt(i)=='8')
                charCount++;
        }
        if(charCount>1)
        {
            n=n.replaceFirst("8","9");
            count++;
        }
        else if(charCount==1&&n.charAt(n.length()-1)=='8')
        {
               n=n.replaceFirst("8","9");
               count++;
        }
        else if(charCount==1)
        {
            count=1;
        }

        while(!n.contains("8"))
        {
            count++;
            temp=Integer.parseInt(n);
            temp++;
            n=""+temp;

        }
        System.out.println(count);

    }


import java.util.*;
public class CUBES {
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[][]=new int[n][6];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<6;j++)
			{
			a[i][j]=sc.nextInt();
			}
		}

		boolean v[]=new boolean[100];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<6;j++)
			{
				v[a[i][j]]=true;
				for(int k=0;k<n;k++)
				{
					if(k!=i)
					{
					for(int l=0;l<6;l++)
					{
						v[a[k][l]*10+a[i][j]]=true;
						v[a[i][j]*10+a[k][l]]=true;
					}
					}
				}
			}
		}

		for(int i=0;i<=99;i++)
		{
			if(v[i]==false)
			{
				System.out.println(i-1);
				break;
			}
		}

		sc.close();
	}
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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();
    }

    static class TaskC {
        static boolean[] prime;

        void sieveOfEratosthenes(int n) {
            // Create a boolean array "prime[0..n]" and initialize
            // all entries it as true. A value in prime[i] will
            // finally be false if i is Not a prime, else true.
            for (int i = 0; i < n; i++)
                prime[i] = true;
            prime[1] = false;
            for (int p = 2; p * p <= n; p++) {
                // If prime[p] is not changed, then it is a prime
                if (prime[p] == true) {
                    // Update all multiples of p
                    for (int i = p * p; i <= n; i += p)
                        prime[i] = false;
                }
            }

        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long N = in.nextLong();
            long b = in.nextLong();
            prime = new boolean[(int) (Math.sqrt(b) + 10)];
            sieveOfEratosthenes(prime.length - 1);
            long total = countTotal(N, b);
            HashSet<Long> primesFactors = primeFactors(b);
            ArrayList<Long> primes = new ArrayList<>();
            ArrayList<Long> cnt = new ArrayList<>();
            for (long i : primesFactors) {
                if (b % i == 0 && prime[(int) i]) {
                    long tempN = b;
                    long val = 0;
                    while (tempN % i == 0) {
                        val++;
                        tempN /= i;
                    }
                    cnt.add(val);
                    primes.add((long) i);
                }
            }
            if (primes.size() == 0) {
                primes.add(b);
                cnt.add(1L);
            }
            long min = Long.MAX_VALUE;
            for (int i = 0; i < primes.size(); i++) {
                min = Math.min(min, countTotal(N, primes.get(i)) / (cnt.get(i)));
            }
            out.println(min);
        }

        static HashSet<Long> primeFactors(long n) {
            HashSet<Long> res = new HashSet<>();
            while (n % 2 == 0) {
                res.add((long) (2));
                n /= 2;
            }
            for (int i = 3; i <= Math.sqrt(n); i += 2) {
                while (n % i == 0) {
                    res.add((long) (i));
                    n /= i;
                }
            }

            // This condition is to handle the case whien
            // n is a prime number greater than 2
            if (n > 2)
                res.add((long) n);
            return res;
        }

        static long countTotal(long n, long val) {
            long power = val;
            long cnt = 0;
            while (power <= n) {
                cnt += n / power;
                if (n / val < power) {
                    return cnt;
                }
                power *= val;
            }
            return cnt;
        }

    }

    static 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 long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.util.Scanner;
public class Main{

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

        long l1 = in.nextInt();
        long r1 = in.nextInt();
        long l2 = in.nextInt();
        long r2 = in.nextInt();
        long k = in.nextInt();

        int time = Math.min(r1, r2) - Math.max(l1, l2) + 1;

        if( k <= Math.min(r1, r2) && k >= Math.max(l1, l2)){
            time--;
        }

        System.out.println( Math.max(0,time));

   }

}


import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
//read the question correctly (is y a vowel? what are the exact constraints?)
//look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
public class Main
{
	public static void main(String[] args)
	{
		int red=ni(),green=ni();
		int r=Math.min(red, green),g=Math.max(red, green);
		int tr=(int)((-1+Math.sqrt(1+8*r))/2);
		int sur=r-(tr*(tr+1))/2;
		int rem=g;
		int h=tr;
		if(sur>0)
		{
			h++;
			rem-=sur;
		}
		while(rem>h)
			rem-=++h;
		int dp[][]=new int[h+1][r+1];
		dp[0][r]=1;
		for(int i=0; i<h; i++)
		{
			for(int j=0; j<=i&&j<=r; j++)
			{
				if((i*(i+1))/2-r+j+i+1<=g)
					dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			}
			for(int j=i+1; j<=r; j++)
			{
				if((i*(i+1))/2-r+j+i+1<=g)
					dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
				dp[i+1][j-i-1]=(dp[i+1][j-i-1]+dp[i][j])%mod;
			}
		}
		int ans=0;
		for(int i:dp[h])
			ans=(ans+i)%mod;
		pr(ans);
		System.out.print(output);
	}
	///////////////////////////////////////////
	///////////////////////////////////////////
	///template from here
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static Reader in=new Reader();
	static StringBuilder output=new StringBuilder();
	static Random rn=new Random();
	//output functions////////////////
	static void pr(Object a){output.append(a+"\n");}
	static void pr(){output.append("\n");}
	static void p(Object a){output.append(a);}
	static void pra(int[]a){for(int i:a)output.append(i+" ");output.append("\n");}
	static void pra(long[]a){for(long i:a)output.append(i+" ");output.append("\n");}
	static void pra(String[]a){for(String i:a)output.append(i+" ");output.append("\n");}
	static void pra(double[]a){for(double i:a)output.append(i+" ");output.append("\n");}
	static void sop(Object a){System.out.println(a);}
	static void flush(){System.out.println(output);output=new StringBuilder();}
	//////////////////////////////////
	//input functions/////////////////
	static int ni(){return in.nextInt();}
	static long nl(){return Long.parseLong(in.next());}
	static String ns(){return in.next();}
	static double nd(){return Double.parseDouble(in.next());}
	static int[] nia(int n){int a[]=new int[n];for(int i=0; i<n; i++)a[i]=ni();return a;}
	static int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}
	//////////////////////////////////
	//some utility functions
	static void exit(){System.exit(0);}
	static void psort(int[][] a)
	{
		Arrays.sort(a, new Comparator<int[]>()
		{
			@Override
			public int compare(int[]a,int[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(b[0]>a[0])
					return -1;
				return 0;
			}
		});
	}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static int gcd(int a, int b)
	{
		if(b==0)
			return a;
		else
			return gcd(b, a%b);
	}
	/////////////////////////
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 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 int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.*;
import java.util.stream.Collectors.*;
import java.lang.*;
import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;
public class Ideo
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

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

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

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

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

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

  static boolean compareSeq(char[] S, int x, int y, int n)
    {
        for (int i = 0; i < n; i++)
         {

            if (S[x] < S[y])
               return true;
            else if (S[x] > S[y])
                return false;
            x = (x + 1) % n;
            y = (y + 1) % n;
        }
        return true;
    }

    static void build(long[] sum,int[] arr,int n)
    {
      for(int i=0;i<(1<<n);i++)
      {
        long total=0;
        for(int j=0;j<n;j++)
        {
          if((i & (1 << j)) > 0)
            total+=arr[j];
        }

        sum[i]=total;
      }
    }

       static int parity(int a)
       {
    a^=a>>16;
    a^=a>>8;
    a^=a>>4;
    a^=a>>2;
    a^=a>>1;
    return a&1;
  }
/*
  PriorityQueue<aksh> pq = new PriorityQueue<>((o1, o2) -> {
            if (o1.p < o2.p)
                return 1;
            else if (o1.p > o2.p)
                return -1;
            else
                return 0;

        });//decreasing order acc to p*/
static int power(int x, int y, int m)
    {
        if (y == 0)
            return 1;

        int p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        if (y % 2 == 0)
            return p;
        else
            return (x * p) % m;
    }
/*static int modinv(int a, int m)
    {
        int g = gcd(a, m);
        if (g != 1)
            return 0;
        else
        {
           return power(a, m - 2, m);
        }
        //return 0;
    } */

static int[] product(int[] nums) {
    int[] result = new int[nums.length];

    int[] t1 = new int[nums.length];
    int[] t2 = new int[nums.length];

    t1[0]=1;
    t2[nums.length-1]=1;

    //scan from left to right
    for(int i=0; i<nums.length-1; i++){
        t1[i+1] = nums[i] * t1[i];
    }

    //scan from right to left
    for(int i=nums.length-1; i>0; i--){
        t2[i-1] = t2[i] * nums[i];
    }

    for(int i=0;i<nums.length;i++)
      {
        System.out.print(t1[i]+" "+t2[i]);
        System.out.println();
      }

    //multiply
    for(int i=0; i<nums.length; i++){
        result[i] = t1[i] * t2[i];
    }

    return result;
}

static int getsum(int[] bit,int ind)
{
  int sum=0;
  while(ind>0)
  {
    sum+=bit[ind];
    ind-= ind & (-ind);
  }

  return sum;
}

static void update(int[] bit,int max,int ind,int val)
{
  while(ind<=max)
  {
    bit[ind]+=val;
    ind+= ind & (-ind);
  }
}

    //static ArrayList<Integer>[] adj;

    static boolean check(long mid,long a,long b)
    {
      long count=1;
      while(count<=mid)
      {
        count++;
        if(a<b)
          a+=count;
        else
          b+=count;

        if(a==b)
          return true;
      }
        return false;
    }

    static class aksh implements Comparable<aksh>
    {
      int x;
      int y;
      public aksh(int x,int y)
      {
        this.x=x;
        this.y=y;
      }
      public int compareTo(aksh o)
      {
        if(x!=o.x)
          return x-o.x;
        else
          return y-o.y;
      }
    }
    static int get(int arr[], int n)
    {
        int result = 0;
        int x, sum;

        // Iterate through every bit
        for(int i=0; i<32; i++)
        {
            // Find sum of set bits at ith position in all
            // array elements
            sum = 0;
            x = (1 << i);
            for(int j=0; j<n; j++)
            {
                if((arr[j] & x)!=0)
                sum++;
            }
            if ((sum % 3)!=0)
            result |= x;
        }
        return result;
    }

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

        // This is checked so that we can skip
        // middle five numbers in below loop
        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 int nextPrime(int N)
    {

        // Base case
        if (N <= 1)
            return (2-N);

        int prime = N;
        boolean found = false;
        while (!found)
        {
            if (isPrime(prime))
                {
                  found = true;
                  break;
                }

            prime++;
        }

        return (prime-N);
    }

    static long product(long x)
{
    long prod = 1;
    while (x > 0)
    {
        prod *= (x % 10);
        x /= 10;
    }
    return prod;
}

// This function returns the number having
// maximum product of the digits
static long findNumber(long l, long r)
{
    // Converting both integers to strings
    //string a = l.ToString();
    String b = Long.toString(r);

    // Let the current answer be r
    long ans = r;
    for (int i = 0; i < b.length(); i++)
    {
        if (b.charAt(i) == '0')
            continue;

        // Stores the current number having
        // current digit one less than current
        // digit in b
        char[] curr = b.toCharArray();
        curr[i] = (char)(((int)(curr[i] -
                    (int)'0') - 1) + (int)('0'));

        // Replace all following digits with 9
        // to maximise the product
        for (int j = i + 1; j < curr.length; j++)
            curr[j] = '9';

        // Convert string to number
        int num = 0;
        for (int j = 0; j < curr.length; j++)
            num = num * 10 + (curr[j] - '0');

        // Check if it lies in range and its product
        // is greater than max product
        if (num >= l && product(ans) < product(num))
            ans = num;
    }

    return product(ans);
}

static long mod=998244353;

static long pow(long in, long pow) {
    if(pow == 0) return 1;
    long out = pow(in, pow / 2);
    out = (out * out) % mod;
    if(pow % 2 == 1) out = (out * in) % mod;
    return out;
  }
  static long inv(long in) {
    return pow(in, mod - 2);
  }

  static void swap(int x,int y)
  {
    int temp=x;
    x=y;
    y=temp;
  }

  static int[] par;
  static int[] size;
  static int find(int i)
  {
     if (par[i] == i)
      return i;

    return par[i] = find(par[par[i]]);
  }

  static void union(int x, int y)
  {
      x = find(x);
      y = find(y);
      if (x == y)
        return;
      if (size[x] < size[y])
        swap(x, y);

      par[y] = x;
      size[x] += size[y];
    }

    static void multisourcebfs(long[] arr,int n,int m)
    {
      //HashSet<Long> vis=new HashSet<>();
      HashMap<Long,Long> dis=new HashMap<>();
      Queue<Long> q=new LinkedList<>();

      for(int i=0;i<arr.length;i++)
      {
        dis.put(arr[i],(long)0);
        q.add(arr[i]);
        //vis.add(arr[i]);
      }

      long[] res=new long[m];
      long ans=0;
      int k=0;
      while(!q.isEmpty())
      {
        if(k==m)
          break;
        long x=q.remove();
        if(dis.get(x)!=0)
        {
          ans+=dis.get(x);
          res[k]=x;
          k++;
        }

        if(dis.get(x-1)==null)
        {
          dis.put(x-1, dis.get(x)+1);
          q.add(x-1);
          //vis.add(x-1);
        }

        if(dis.get(x+1)==null)
        {
          dis.put(x+1, dis.get(x)+1);
          q.add(x+1);
          //vis.add(x+1);
        }
      }

      System.out.println(ans);

      for(int i=0;i<m;i++)
        System.out.print(res[i]+" ");

    }

    static int x;
    static int maxcount=0;
    static void dfs(int node,int par,int dist)
    {
        if(dist>=maxcount)
        {
           maxcount=dist;
           x=node;
        }

        List<Integer> l = adj[node];
        for(Integer i: l)
        {
          if(i!=par)
          dfs(i,node,dist+1);
        }
    }

    static int h;
    static int w;
    static int bfs(char[][] ch,int i,int j)
    {
        Queue<aksh> q=new LinkedList<>();
        q.add(new aksh(i,j));

        int[][] dis=new int[h][w];
        int[][] vis=new int[h][w];
        vis[i][j]=1;
        dis[i][j]=0;

        while(!q.isEmpty())
        {
          aksh arr=q.poll();
          int x1=arr.x;
          int y1=arr.y;

          if((x1-1)>=0 && ch[x1-1][y1]!='#' && vis[x1-1][y1]==0)
          {
            vis[x1-1][y1]=1;
            q.add(new aksh(x1-1, y1));
            dis[x1-1][y1]=Math.max(dis[x1-1][y1],dis[x1][y1]+1);
          }

          if((x1+1)<h && ch[x1+1][y1]!='#' && vis[x1+1][y1]==0)
          {
            vis[x1+1][y1]=1;
            dis[x1+1][y1]=Math.max(dis[x1+1][y1],dis[x1][y1]+1);
            q.add(new aksh(x1+1, y1));
          }

          if((y1-1)>=0 && ch[x1][y1-1]!='#' && vis[x1][y1-1]==0)
          {
            vis[x1][y1-1]=1;
            dis[x1][y1-1]=Math.max(dis[x1][y1-1],dis[x1][y1]+1);
            q.add(new aksh(x1,y1-1));
          }

          if((y1+1)<w && ch[x1][y1+1]!='#' && vis[x1][y1+1]==0)
          {
            vis[x1][y1+1]=1;
            dis[x1][y1+1]=Math.max(dis[x1][y1+1],dis[x1][y1]+1);
            q.add(new aksh(x1,y1+1));
          }
        }
        int max=Integer.MIN_VALUE;

        for(int x=0;x<h;x++)
        {
          for(int y=0;y<w;y++)
            max=Math.max(dis[x][y],max);
        }

        return max;
    }

    static ArrayList<Integer> cnt;

    static void primefact(int n)
    {

          for (int i=2;i*i<=n;i++)
           {
              while ((n % i)==0)
              {
                cnt.add(i);
                n /= i;
              }
           }

          if(n>1)
             {
              cnt.add(n);
             }
    }

    static boolean hash[];
    static void sieve(int n)
    {
      Arrays.fill(hash, true);
    for (int p = 2; p * p < n; p++)
        if (hash[p] == true)
            for (int i = p * 2; i < n; i += p)
                hash[i] = false;
    }

    static long div(long n)
  {
    long total = 1;
    for (int p = 2; p <= n; p++)
    {
        if (hash[p])
        {
            int count = 0;
            if (n % p == 0)
            {
                while (n % p == 0)
                {
                    n = n / p;
                    count++;
                }
                total = total * (count + 1);
            }
        }
    }
    return total;
}

    static void SieveOfEratosthenes(long n, boolean prime[],
                                    boolean primesquare[], int a[])
    {
        // Create a boolean array "prime[0..n]" and
        // initialize all entries it as true. A value
        // in prime[i] will finally be false if i is
        // Not a prime, else true.
        for (int i = 2; i <= n; i++)
            prime[i] = true;

        /* Create a boolean array "primesquare[0..n*n+1]"
         and initialize all entries it as false.
         A value in squareprime[i] will finally
         be true if i is square of prime,
         else false.*/
        for (int i = 0; i < ((n * n) + 1); i++)
            primesquare[i] = false;

        // 1 is not a prime number
        prime[1] = false;

        for (int p = 2; p * p <= n; p++) {
            // If prime[p] is not changed,
            // then it is a prime
            if (prime[p] == true) {
                // Update all multiples of p
                for (int i = p * 2; i <= n; i += p)
                    prime[i] = false;
            }
        }

        int j = 0;
        for (int p = 2; p <= n; p++) {
            if (prime[p]) {
                a[j] = p;
                primesquare[p * p] = true;
                j++;
            }
        }
    }

    static boolean countDivisors(long n)
    {
        if (n == 1)
            return false;

        boolean prime[] = new boolean[(int)n + 1];
        boolean primesquare[] = new boolean[(int)(n * n) + 1];

        // for storing primes upto n
        int a[] = new int[(int)n];

        // Calling SieveOfEratosthenes to
        // store prime factors of n and to
        // store square of prime factors of n
        SieveOfEratosthenes(n, prime, primesquare, a);

        // ans will contain total number
        // of distinct divisors
        int ans = 1;

        // Loop for counting factors of n
        for (int i = 0;; i++) {
            // a[i] is not less than cube root n
            if (a[i] * a[i] * a[i] > n)
                break;

            // Calculating power of a[i] in n.
            // cnt is power of prime a[i] in n.
            int cnt = 1;

            // if a[i] is a factor of n
            while (n % a[i] == 0) {
                n = n / a[i];

                // incrementing power
                cnt = cnt + 1;
            }
            ans = ans * cnt;
        }

        // if a[i] is greater than cube root
        // of n

        // First case
        if (prime[(int)n])
            ans = ans * 2;

        // Second case
        else if (primesquare[(int)n])
            ans = ans * 3;

        // Third casse
        else if (n != 1)
            ans = ans * 4;

        return prime[ans]; // Total divisors
    }

    static  int upperbound(ArrayList<Integer> array, int length, int value)
    {
        int low = 0;
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array.get(mid))
            {
                low = mid + 1;
            }
            else
            {
                high = mid;
            }
        }
        return low;
    }

    static final long INF = Long.MAX_VALUE/5;
    static ArrayList<Integer>[] adj;
    static long binpow(long a, long b)
    {
       long res = 1;
       while (b > 0)
       {
        if ((b & 1) !=0)
            res = res * a;
        a = a * a;
        b >>= 1;
        }
    return res;
    }

    public static void main(String args[] ) throws Exception
    {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        FastReader s=new FastReader();
        int n=s.nextInt();
        int l=s.nextInt();
        int r=s.nextInt();
        int m=1000000007;
        long[][] dp=new long[n][3];

        if(l==r)
         {

          System.out.println("1");
          System.exit();
        }
        int c1=r/3 - (l+2)/3 +1;
        int c2=(r-1)/3 - (l-1+2)/3 + 1;
        int c3=(r-2)/3 -  (l-2+2)/3 + 1;

        dp[0][0]=c1;
        dp[0][1]=c2;
        dp[0][2]=c3;
        for(int i=1;i<n;i++)
        {
          dp[i][0]=(dp[i-1][0]*c1%m + dp[i-1][1]*c3%m + dp[i-1][2]*c2%m + m)%m;
          dp[i][1]=(dp[i-1][0]*c2%m + dp[i-1][1]*c1%m + dp[i-1][2]*c3%m + m)%m;
          dp[i][2]=(dp[i-1][0]*c3%m + dp[i-1][1]*c2%m + dp[i-1][2]*c1%m + m)%m;
        }

        System.out.println(dp[n-1][0]);

 }
}


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

public class Main {

    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static long mod = (long)1e9+7;

    static void solve(){
        int n = in.nextInt(), l = in.nextInt(), r = in.nextInt();
        int x = 0,y = 0,z = 0,n1,n2;
        // // for 0
        // n1 = l%3==0?l:l+3-l%3;
        // n2 = r%3==0?r:r-r%3;
        n1 = l; n2 = r;
        if(n1%3==1)n1 = l+2;
        else if(n1%3==2)n1 = l+1;
        if(n2%3==1)n2 = r-1;
    	else if(n2%3==2)n2 = r-2;

        if(n1<=r && n2>=l){
        	x = (n2-n1)/3+1;
        }
        //for 1

        // out.println(n1+" "+n2);

        n1 = l%3==1?l:l+l%3+1;
        n2 = r%3==0?r-2:r-(r%3-1);
        if(n1<=r && n2>=l){
        	y = (n2-n1)/3+1;
        }
        // out.println(n1+" "+n2);

        //for 2
        n1 = l%3==2?l:l+2-l%3;
        n2 = r;
        if(r%3==0)n2 = r-1;
        else if(r%3==1) n = r-2;
        if(n1<=r && n2>=l){
        	z = (n2-n1)/3+1;
        }
        // out.println(n1+" "+n2);
        long[][] dp = new long[n+1][3];
        dp[1][0] = x;
        dp[1][1] = y;
        dp[1][2] = z;
        for(int i=2;i<=n;i++){
        	dp[i][0] = (dp[i-1][0]*x+dp[i-1][1]*z+dp[i-1][2]*y)%mod;
        	dp[i][1] = (dp[i-1][0]*y+dp[i-1][1]*x+dp[i-1][2]*z)%mod;
        	dp[i][2] = (dp[i-1][0]*z+dp[i-1][1]*y+dp[i-1][2]*x)%mod;
        }
        out.println(dp[n][0]);
    }

    public static void main(String[] args) {
        solve();
        out.flush();
        out.close();
    }

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
        int nextInt(){return Integer.parseInt(in.next());}
        long nextLong(){return Long.parseLong(in.next());}
        double nextDouble(){return Double.parseDouble(in.next());}
    }
    static class pair{
        int f,s;
        public pair(int f,int s){
            this.f = f;
            this.s = s;
        }
    }
}


package CodeForce.Div2.Beta_Round.P59_R55;

import java.util.Scanner;

/**
 ** Created by Alik on 11/1/2015.
 */
public class Problem_59A {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();

        int temp;
        int uppercase = 0, lowercase = 0;
        for (int i = 0; i < input.length(); i++){
            temp = input.charAt(i);
            if (temp >= 65 && temp <= 90)
                uppercase++;
            else if(temp >= 97 && temp <= 122)
                lowercase++;
        }

        if (uppercase > lowercase)
            System.out.print(input.toUpperCase());
        else
            System.out.print(input.toLowerCase());
    }
}


import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigDecimal;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;

static void solve(){
 char[][] map=ir.nextCharMap(8,8);
 int a=-1;
 int b=-1;
 for(int i=0;i<8;i++){
  for(int j=0;j<8;j++){
   if(map[j][i]='B') break;
   if(map[j][i]=='W'){
    a=Math.min(a,j);
    break;
   }
  }
  for(int j=7;j>=0;j--){
   if(map[j][i]='W') break;
   if(map[j][i]=='B'){
    b=Math.min(b,7-j);
    break;
   }
  }
 }
 out.println((a<b)?"A":"B");
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}

 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

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

 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}

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

 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

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

 public BigInteger nextBigInteger(){return new BigInteger(next());}

 public BigDecimal nextBigDecimal(){return new BigDecimal(next());}

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

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

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


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder s = new StringBuilder(in.next());
        String protocol = s.substring(0,3);
        if (!protocol.equals("ftp")) {
            protocol = s.substring(0,4);
        }
        String domen = s.substring(protocol.length(), s.indexOf("ru"));
        String context = s.substring(domen.length() + protocol.length()+2);
        if (context.length() !=0) {
            System.out.println(protocol+"://"+domen+".ru/"+context);
        } else {
            System.out.println(protocol+"://"+domen+".ru");
        }
        in.close();
    }
}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Alex
 */
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 {
	//	int[][][] mem = new int[100][100][100]; //change to hashmap with array of 25 elements each later
	HashMap<Long, long[][]> hm = new HashMap<>();
	int[] a;
	int ncubes;
	int kstickers;
	long dp(long sumwant, int curindex, int exclamationsleft){
		if (sumwant < 0) return 0;
		if (curindex == a.length && sumwant == 0) return 1;
		if (curindex == a.length) return 0;
//		O curobject = new O(sumwant, curindex, exclamationsleft);
//		if (tm.containsKey(curobject)){
//			return tm.get(curobject);
//		}
//		long dontchoose = 0, choosenormal = 0, choosefact = 0;
//		dontchoose = dp(sumwant, curindex + 1, exclamationsleft);
//		choosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);
//		if (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);
//		long res = dontchoose + choosenormal + choosefact;
//		tm.put(curobject, res);
//		return res;
		//		return pointer[curindex][exclamationsleft] = res;

				if (hm.containsKey(sumwant)){
					long[][] pointer = hm.get(sumwant);
					if (pointer[curindex][exclamationsleft] != -1) return pointer[curindex][exclamationsleft];
					long dontchoose = 0, choosenormal = 0, choosefact = 0;
					dontchoose = dp(sumwant, curindex + 1, exclamationsleft);
					choosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);
					if (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);
					long res = dontchoose + choosenormal + choosefact;
					return pointer[curindex][exclamationsleft] = res;
				}
				long dontchoose = 0, choosenormal = 0, choosefact = 0;
				dontchoose = dp(sumwant, curindex + 1, exclamationsleft);
				choosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);
				if (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);
				long[][] temp = new long[ncubes + 1][kstickers + 1];
				ArrayUtils.fill(temp, -1);
				hm.put(sumwant, temp);
				long res = dontchoose + choosenormal + choosefact;
				return temp[curindex][exclamationsleft] = res;
	}
	public void solve(int testNumber, InputReader in, OutputWriter out){
		ncubes = in.ri();
		kstickers = in.ri();
		long SumWant = in.readLong();
		int[] a = IOUtils.readIntArray(in, ncubes);
		this.a = a;
		long res = dp(SumWant, 0, kstickers);
		out.print(res);
	}
}

class IntegerUtils {
	public static long factorial(int n) {
		long result = 1;
		for (int i = 2; i <= n; i++)
			result *= i;
		return result;
	}
}

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

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 ri(){
		return readInt();
	}

	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 close() {
		writer.close();
	}
	public void print(long i) {
		writer.print(i);
	}
}

class IOUtils {
	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Round334B {

	public static final int mod = (int)1e9+7;
	public static LinkedList<Integer>[] adj;

	public static boolean[] visited;

	public static void dfs(int curr) {
		visited[curr] = true;
		for(Integer x : adj[curr]) {
			if(!visited[x]) {
				dfs(x);
			}
		}
	}

	public static int components() {
		int n = adj.length;
		int ans = 0;
		visited = new boolean[n];
		for(int i = 1; i < n; i++) {
			if(!visited[i]) {
				dfs(i);
				ans++;
			}
		}
		return ans;
	}

	public static void solve() {
		int p = s.nextInt();
		int k = s.nextInt();
		adj = new LinkedList[p];
		for(int i = 0; i < p; i++) {
			adj[i] = new LinkedList<Integer>();
		}
		for(int i = 1; i < p; i++) {
			long val = (long)k * (long)i;
			val %= p;
			adj[(int)val].add(i);
		}
		int pow = components();
		if(k == 1) {
			pow++;
		}
		long ans = fast(p, pow);
		out.println(ans);
	}

	public static long fast(long a, int n) {
		if(n == 1) {
			return a;
		}
		long ans = fast(a, n/2);
		ans = ans * ans;
		ans %= mod;
		if(n % 2 == 1) {
			ans = ans * a;
			ans %= mod;
		}
		return ans;
	}

	public static void main(String[] args) {
		new Thread(null, null, "Naman", 1 << 27) {
            public void run() {
                try {
                	out = new PrintWriter(new BufferedOutputStream(System.out));
            		s = new FastReader();
            		solve();
            		out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.*;

public class Main {
    final static double mod = 1e9 + 7;
	public static void main (String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String[] input = bf.readLine().split(" ");
		long p = Long.parseLong(input[0]);
		long k = Long.parseLong(input[1]);
		long order = 1;
		long temp = k;

		if (k == 0)
		    System.out.println((int)Math.pow(p, p - 1));
		else {
    	    while (temp != 1) {
    	        temp = (k * temp) % p;
    	        order++;
    	    }

    	    if (k == 1)
		        System.out.println((((int)Math.pow(p,p) % (int) mod));
		    else
		        System.out.println((((int)Math.pow(p, (p - 1)/order)) % (int) mod));
		}
	}
}


import java.util.*;

public class problem282_2 {
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int num=in.nextInt();
        int rem=in.nextInt();
        if(rem>num)
            System.out.println("0");
        else if(rem==num)
            System.out.println("infinity");
        else{
            int number=num-rem;
            ArrayList<Integer> factors=new ArrayList<Integer>();
            int i=1;
            do{
                if(number%i==0){
                    factors.add(i);
                    factors.add(number/i);
                }
            }while(i<(int)Math.sqrt(number));
            int x=(int)Math.sqrt(number);
            if(number%x==0)
                factors.add(x);
            int count=0;
            for(int e:factors){
            if(e>rem)
                ++count;
            }
            System.out.println(""+count);
            }

    }
}


import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main( String args[] )
	{
		Scanner input = new Scanner(System.in);
		long a1 = input.nextInt();
		long b1 = input.nextInt();
		long a2 = input.nextInt();
		long b2 = input.nextInt();
		long l = input.nextInt();
		long r = input.nextInt();
		long first = 2000000000 + 1;
		long counter = 0;
		long gcd = gcd(a1, a2);
		long scm = ( a1 * a2 ) / gcd;

		if( b1 > r || b2 > r)
		{
			System.out.println(0);
			return;
		}

		if( a1 == a2 && b1 % a1 != b2 % a1 )
		{
			System.out.println(0);
			return;
		}

		long max = 0 , am = 0;
		if(a1 >= a2 )
		{
			max = b1;
			am = a1;
		}

		if( a1 < a2 )
		{
			max = b2;
			am = a2;
		}

		for( long i = max ; i <= scm + max; i += am )
		{
			if( i > r )
				break;

			if( (i - b1) % a1 == 0 && (i - b2) % a2 == 0 )
			{
				first = i;
				break;
			}
		}

		if( first != 2000000001 )
		{
			long k = (first - b1) / a1;
			long p = (first - b2) / a2;

			while( k < 0 )
			{
				first += scm;
				k = (first - b1) / a1;
			}

			while( p < 0 )
			{
				first += scm;
				p = (first - b2) / a2;
			}

		}
		if( first < l )
		{
			long m = (l - first) / scm + 1;
			first += m * scm;
		}

		if( first != 2000000000 + 1 && first >= l && first <= r)
			counter = (r - first) / scm + 1;

		if( first != l && (l - b1) % a1 == 0 && (l - b2) % a2 == 0 && (l - b1) / a1 >= 0 && (l - b2) / a2 >= 0)
			counter++;

		System.out.println(counter);

	}

	public static long gcd( long a, long b )
	{
		if( b == 0 )
			return a;

		return gcd (b, a % b );
	}
}


import java.util.*;

public class Domki{
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();
    int cDist=n+10;
    for(int i = 0;i<n;i++){
    int a = sc.nextInt();
    if(a<=k && Math.abs(i-m)<cDist){
	cDist=Math.abs(a-m);
	}
    }
    System.out.println(cDist*10);
}


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

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int x = in.nextInt();
    int hours = in.nextInt();
    int minutes = in.nextInt();
    int sub=0,h=0,k=0,min=0;

    do{
        if(k==0){
            if(minutes>=7){
                sub=7;
                min=minutes-7;
            }
            if(minutes>=17){
                sub=17;
                min=minutes-17;
            }
            if(minutes>=27){
                sub=27;
                min=minutes-27;
            }
            if(minutes>=37){
                sub=37;
                min=minutes-37;
            }
            if(minutes>=47){
                sub=47;
                min=minutes-47;
            }
            if(minutes>=57){
                sub=57;
                min=minutes-57;
            }
            if(minutes<7){
                sub=57;
                min=minutes+3;
                h++;
            }
            continue;
        }
    k=1;
    if(sub==7){
        sub=57;
        h++;
    }
    sub-=10;
    min+=10;
    }while(min%x!=0);

    System.out.println(min/x);

	}
}


import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Locale;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

public class Main {

	public static void main(String[] args) throws Exception {
		//int n = StdIn.readInt();
        solve(1);
    }

    public static void solve(int testCases) throws Exception{

    	char[][] board = new char[3][3];
    	for(int i = 0 ; i < 3 ; i++){
    		board[i] = StdIn.readString().toCharArray();
    	}
    	int crossesN = 0;
    	int noughtsN = 0;
    	int dotsN = 0;
    	for(int i = 0 ; i < 3 ; i++){
    		for(int j = 0 ; j < 3 ; j++){
    			if(board[i][j] == 'X')
    				crossesN++;
    			else if(board[i][j] == '.')
    				dotsN++;
    			else if(board[i][j] == '0')
    				noughtsN++;
    		}
    	}
    	boolean hasFirstWin = hasWin(board, 'X');
    	boolean hasSecondWin = hasWin(board, '0');
    	//StdOut.println("hasFirstWin = " + hasFirstWin + " hasSecondWin = " + hasSecondWin);
    	if(dotsN > 0){
    		if(noughtsN > crossesN || crossesN > noughtsN + 1){
    			StdOut.println("illegal");
    			return;
    		}
    		if(hasFirstWin && hasSecondWin){
    			StdOut.println("illegal");
    			return;
    		}
    		if(hasFirstWin){
    			StdOut.println("the first player won");
    			return;
    		}
    		if(hasSecondWin){
    			StdOut.println("the second player won");
    			return;
    		}
    		if(crossesN == noughtsN + 1){
    			StdOut.println("second");
    			return;
    		}
    		if(noughtsN == crossesN){
    			StdOut.println("first");
    			return;
    		}
    	}
    	if(dotsN == 0){
    		if(noughtsN > crossesN || crossesN > noughtsN + 1){
    			StdOut.println("illegal");
    			return;
    		}
    		if(hasFirstWin && hasSecondWin){
    			StdOut.println("illegal");
    			return;
    		}
    		if(hasFirstWin){
    			StdOut.println("the first player won");
    			return;
    		}
    		if(hasSecondWin){
    			StdOut.println("the second player won");
    			return;
    		}
    		if(!hasFirstWin && !hasSecondWin){
    			StdOut.println("draw");
    			return;
    		}
    	}
    }

    public static boolean hasWin(char[][] board, char c){

    	for(int i = 0 ; i < board.length ; i++){
    		boolean f = true;
    		for(int j = 0 ; j < board[i].length ; j++){
    			f &= (board[i][j] == c);
    		}
    		if(f)
    			return f;
    	}

    	for(int j = 0 ; j < board[0].length ; j++){
    		boolean f = true;
    		for(int i = 0 ; i < board.length ; i++){
    			f &= (board[j][i] == c);
    		}
    		if(f)
    			return f;
    	}

    	return (board[0][0] == c && board[1][1] == c && board[2][2] == c) || (board[0][2] == c && board[1][1] == c && board[2][0] == c) ;
    }

}

final class StdIn {

    private StdIn() { }

    private static Scanner scanner;

    private static final String CHARSET_NAME = "UTF-8";

    private static final Locale LOCALE = Locale.US;

    private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\p{javaWhitespace}+");

    private static final Pattern EMPTY_PATTERN = Pattern.compile("");

    private static final Pattern EVERYTHING_PATTERN = Pattern.compile("\\A");

    public static boolean isEmpty() {
        return !scanner.hasNext();
    }

    public static boolean hasNextLine() {
        return scanner.hasNextLine();
    }

    public static boolean hasNextChar() {
        scanner.useDelimiter(EMPTY_PATTERN);
        boolean result = scanner.hasNext();
        scanner.useDelimiter(WHITESPACE_PATTERN);
        return result;
    }

    public static String readLine() {
        String line;
        try                 { line = scanner.nextLine(); }
        catch (Exception e) { line = null;               }
        return line;
    }

    public static char readChar() {
        scanner.useDelimiter(EMPTY_PATTERN);
        String ch = scanner.next();
        assert (ch.length() == 1) : "Internal (Std)In.readChar() error!"
            + " Please contact the authors.";
        scanner.useDelimiter(WHITESPACE_PATTERN);
        return ch.charAt(0);
    }

    public static String readAll() {
        if (!scanner.hasNextLine())
            return "";

        String result = scanner.useDelimiter(EVERYTHING_PATTERN).next();
        // not that important to reset delimeter, since now scanner is empty
        scanner.useDelimiter(WHITESPACE_PATTERN); // but let's do it anyway
        return result;
    }

    public static String readString() {
        return scanner.next();
    }

    public static int readInt() {
        return scanner.nextInt();
    }

    public static double readDouble() {
        return scanner.nextDouble();
    }

    public static float readFloat() {
        return scanner.nextFloat();
    }

    public static long readLong() {
        return scanner.nextLong();
    }

    public static short readShort() {
        return scanner.nextShort();
    }

    public static byte readByte() {
        return scanner.nextByte();
    }

    public static boolean readBoolean() {
        String s = readString();
        if (s.equalsIgnoreCase("true"))  return true;
        if (s.equalsIgnoreCase("false")) return false;
        if (s.equals("1"))               return true;
        if (s.equals("0"))               return false;
        throw new InputMismatchException();
    }

    public static String[] readAllStrings() {
        // we could use readAll.trim().split(), but that's not consistent
        // because trim() uses characters 0x00..0x20 as whitespace
        String[] tokens = WHITESPACE_PATTERN.split(readAll());
        if (tokens.length == 0 || tokens[0].length() > 0)
            return tokens;

        // don't include first token if it is leading whitespace
        String[] decapitokens = new String[tokens.length-1];
        for (int i = 0; i < tokens.length - 1; i++)
            decapitokens[i] = tokens[i+1];
        return decapitokens;
    }

    public static String[] readAllLines() {
        ArrayList<String> lines = new ArrayList<String>();
        while (hasNextLine()) {
            lines.add(readLine());
        }
        return lines.toArray(new String[0]);
    }

    public static int[] readAllInts() {
        String[] fields = readAllStrings();
        int[] vals = new int[fields.length];
        for (int i = 0; i < fields.length; i++)
            vals[i] = Integer.parseInt(fields[i]);
        return vals;
    }

    public static double[] readAllDoubles() {
        String[] fields = readAllStrings();
        double[] vals = new double[fields.length];
        for (int i = 0; i < fields.length; i++)
            vals[i] = Double.parseDouble(fields[i]);
        return vals;
    }

    static {
        resync();
    }

    private static void resync() {
        setScanner(new Scanner(new java.io.BufferedInputStream(System.in), CHARSET_NAME));
    }

    private static void setScanner(Scanner scanner) {
        StdIn.scanner = scanner;
        StdIn.scanner.useLocale(LOCALE);
    }

    public static int[] readInts() {
        return readAllInts();
    }

    public static double[] readDoubles() {
        return readAllDoubles();
    }

    public static String[] readStrings() {
        return readAllStrings();
    }

}

final class StdOut {

    private static final String CHARSET_NAME = "UTF-8";

    private static final Locale LOCALE = Locale.US;

    private static PrintWriter out;

    static {
        try {
            out = new PrintWriter(new OutputStreamWriter(System.out, CHARSET_NAME), true);
        }
        catch (UnsupportedEncodingException e) { System.out.println(e); }
    }

    private StdOut() { }

    public static void close() {
        out.close();
    }

    public static void println() {
        out.println();
    }

    public static void println(Object x) {
        out.println(x);
    }

    public static void println(boolean x) {
        out.println(x);
    }

    public static void println(char x) {
        out.println(x);
    }

    public static void println(double x) {
        out.println(x);
    }

    public static void println(float x) {
        out.println(x);
    }

    public static void println(int x) {
        out.println(x);
    }

    public static void println(long x) {
        out.println(x);
    }

    public static void println(short x) {
        out.println(x);
    }

    public static void println(byte x) {
        out.println(x);
    }

    public static void print() {
        out.flush();
    }

    public static void print(Object x) {
        out.print(x);
        out.flush();
    }

    public static void print(boolean x) {
        out.print(x);
        out.flush();
    }

    public static void print(char x) {
        out.print(x);
        out.flush();
    }

    public static void print(double x) {
        out.print(x);
        out.flush();
    }

    public static void print(float x) {
        out.print(x);
        out.flush();
    }

    public static void print(int x) {
        out.print(x);
        out.flush();
    }

    public static void print(long x) {
        out.print(x);
        out.flush();
    }

    public static void print(short x) {
        out.print(x);
        out.flush();
    }

    public static void print(byte x) {
        out.print(x);
        out.flush();
    }

    public static void printf(String format, Object... args) {
        out.printf(LOCALE, format, args);
        out.flush();
    }

    public static void printf(Locale locale, String format, Object... args) {
        out.printf(locale, format, args);
        out.flush();
    }

}


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

public class B {

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

	static final int MOD = 1000000007;
	static final int MAX = 100;
	static final int[][] c = new int[MAX + 1][];
	{
		for (int i = 0; i <= MAX; i++) {
			c[i] = new int[i + 1];
			c[i][0] = c[i][i] = 1;
			for (int j = 1; j < i; j++) {
				c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
				if (c[i][j] >= MOD)
					c[i][j] -= MOD;
			}
		}
	}

	int C(int n, int k) {
		if (n > MAX)
			throw new AssertionError();
		if (k < 0 || k > n || n < 0)
			return 0;
		return c[n][k];
	}

	int f(int[] cnt, int len) {
		int[] dp = new int[len + 1];
		dp[0] = 1;
		for (int i = 0; i < 10; i++) {
			int[] next = new int[len + 1];
			for (int j = cnt[i]; j <= len; j++)
				for (int prev = 0; prev + j <= len; prev++)
					if (dp[prev] != 0) {
						// (len - prev) places, j digits
						if (i == 0)
							next[prev + j] += (int) ((long) dp[prev]
									* C(len - prev - 1, j) % MOD);
						else
							next[prev + j] += (int) ((long) dp[prev]
									* C(len - prev, j) % MOD);
					}
			dp = next;
		}
		return dp[len];
	}

	void solve() throws IOException {
		int n = nextInt();
		int[] atLeast = new int[10];
		int tot = 0;
		for (int i = 0; i < 10; i++) {
			atLeast[i] = nextInt();
			tot += atLeast[i];
		}
		int res = 0;
		for (int i = Math.max(1, tot); i <= n; i++) {
			res += f(atLeast, i);
			if (res >= MOD)
				res -= MOD;
		}
		out.println(res);
	}

	void inp() 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 B().inp();
	}

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

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

	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;

public class P58B {

    static boolean r[];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
//      r = new boolean[n+1];
//      for(int i = 2; i < n; i++)
//          if(!r[i])
//              for(int j = 2 * i; j <=n; j += i)
//                  r[j] = true;
        int p = 2;
        do{
            System.out.print(n + " ");
            while((n % p != 0)) p++;
            n /= p;
        }while(n > 1);
        System.out.println("1");
    }

}


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

public class MagicGems {
    public static final long MOD = 1000000007L;
    public static final long MODS = MOD*MOD;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        long N = scanner.nextLong();
        int M = scanner.nextInt();
        long[][] matrix = new long[M][M];
        for(int i= 0; i  < M-1; i++) {
            matrix[i+1][i] = 1;
        }
        //base cases
        matrix[0][0] = 1;
        matrix[0][M-1] = 1;
        long[] ans = new long[M];
        ans[0] = 1;
        out.println(mPow(matrix, ans, N)[0]);
        out.flush();
    }

    public static long[] mPow (long[][] M,  long[] v, int pow) {
        for(int i= 0; i < v.length; i++) if(v[i] >= MOD) v[i]%=MOD;
        long[][] ret = M;
        //>>>= is an unsigned right shift by 1
        for(;pow> 0; pow >>>=1) {
            if ((pow&1)==1) v = mMul(ret, v);
            ret = mSquare(ret);
        }
        return v;
    }

    public static long[] mMul(long[][] M, long[] v) {
        int m = M.length;
        int n= v.length;
        long[] ret = new long[m];
        for(int i= 0; i < m; i++) {
            long sum = 0;
            for(int k = 0; k < n; k++) {
                sum += M[i][k] * v[k];
                if (sum >= MODS) sum-= MODS;
            }
            ret[i] = sum;
        }
        return ret;
    }

    //need to be a square matrix
    //should have efficiency based on lacking mod ops.
    public static long[][] mSquare(long[][] M) {
        int N = M.length;
        long[][] ret = new long[N][N];
        for(int i = 0; i < N; i++) {
            long[] temp = new long[N];
            for(int k = 0; k < N; k++) {
                for(int j = 0; j < N; j++) {
                    temp[j] += M[i][k] * M[k][j];
                    if (temp[j] >= MODS) temp[j]-=MODS;
                }
            }
            for(int k = 0; k < N; k++) {
                ret[i][k] = (temp[k] %MOD);
            }
        }
        return ret;
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

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

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

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

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

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

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


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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(r.readLine().trim());

		int i =0;
		int sum = 0;
		boolean done =false;
		while(sum < n && !done){
			sum = (i*(i+1))/2;
			if(sum == n){
				done = true;
			}
		}
		if(!done){
			System.out.println("NO");
		}else{
			System.out.println("YES");
		}
	}
}


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

public class BaiC {

    int n;
    int[][] a, low, high;
    boolean[][] b;
    int[][] c;
    int[][] edges;
    int[] e;

    int[] best = null;

    void duyet(int pos, int cost) {
        if(pos == edges.length) {
            for(int i=1;i+1<n;++i) if(e[i] != 0) return;

            if(best == null || best[0] > -e[0] || (best[0] == -e[0] && best[1] < cost)) {
                best = new int[]{-e[0], cost};
            }
            return;
        }

        int u = edges[pos][0];
        int v = edges[pos][1];

        if(best != null && best[0] < -e[0]) return;

        boolean tiep = true;
        for(int i=1;i+1<n;++i) if(e[i] < 0) tiep = false;
        for(int i=1;i<u;++i) if(e[i] != 0) tiep = false;
        if(!tiep) return;

        for(int x=low[u][v];x<=high[u][v];++x) {
            c[u][v] = x;
            e[u] -= x;
            e[v] += x;
            duyet(pos+1, cost + (x == 0 ? 0 : (a[u][v] + x * x)));
            e[u] += x;
            e[v] -= x;
        }
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n][n];
        low = new int[n][n];
        high = new int[n][n];
        b = new boolean[n][n];

        for(int i=0;i<n;++i)
            for(int j=i+1;j<n;++j) {
                int u, v, l, h, z;

                u = sc.nextInt();
                v = sc.nextInt();
                l = sc.nextInt();
                h = sc.nextInt();
                z = sc.nextInt();
                // u = i+1; v = j+1; l = 0; h = 5; z = 5;
                a[u-1][v-1] = z;
                low[u-1][v-1] = l;
                high[u-1][v-1] = h;
            }

        edges = new int[n*(n-1)/2][];
        int ne = 0 ;

        for(int i=0;i<n;++i)
            for(int j=i+1;j<n;++j) {
                edges[ne++] = new int[]{i,j};
            }
        e = new int[n];
        c = new int[n][n];
        duyet(0, 0);
        System.out.println(best[0] + " " + best[1]);
    }
    public static void main(String[] args) {
        // long tbegin = System.currentTimeMillis();
        new BaiC().run();
        // System.out.println(System.currentTimeMillis() - tbegin);
    }
}


import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigInteger;
import static java.math.BigInteger.*;
import java.util.*;
public class C{
	int n;
	int[][]min;
	int[][]max;
	int[][]active;
	int[]pFlow;
	int inf=Integer.MAX_VALUE/100;
	void solve()throws Exception
	{

		n=nextInt();
		min=new int[n][n];
		max=new int[n][n];
		active=new int[n][n];
		int sum=0;
		for(int step=1;step<=n*(n-1)/2;step++)
		{
			int a=nextInt()-1;
			int b=nextInt()-1;
			min[a][b]=nextInt();
			max[a][b]=nextInt();
			active[a][b]=nextInt();
			sum+=max[a][b];
		}
		sum++;
		pFlow=new int[n];
		int[]res=rec(0,1);
		if(res==null)
			res=new int[]{-1,-1};
		System.out.println(res[0]+" "+res[1]);
	}

	private int[] rec(int a, int b) {
		if(a==n-1)
		{
			return new int[]{pFlow[0],0};
		}
		int[]res=null;
		if(b==n)
		{
			if(a!=0 && pFlow[a]!=0)
				return null;
			return rec(a+1,a+2);
		}
		else
		{
			for(int x=min[a][b];x<=max[a][b];x++)
			{
				int curCost=x*x+(x>0?active[a][b]:0);
				pFlow[a]+=x;
				pFlow[b]-=x;
				int[]next=rec(a,b+1);
				if(next!=null)
				{
					next[1]+=curCost;
					if(res==null || (res[0]>next[0] || (res[0]==next[0] && res[1]<next[1])))
						{
							res=next;
						}
				}
				pFlow[a]-=x;
				pFlow[b]+=x;
			}
			return res;

		}

	}

	BufferedReader reader;
	PrintWriter writer;
	StringTokenizer stk;
	void run()throws Exception
	{
		reader=new BufferedReader(new InputStreamReader(System.in));
		stk=null;
		writer=new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}
	int nextInt()throws Exception
	{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception
	{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception
	{
		return Double.parseDouble(nextToken());
	}
	String nextString()throws Exception
	{
		return nextToken();
	}
	String nextLine()throws Exception
	{
		return reader.readLine();
	}
	String nextToken()throws Exception
	{
		if(stk==null || !stk.hasMoreTokens())
		{
			stk=new StringTokenizer(nextLine());
			return nextToken();
		}
		return stk.nextToken();
	}

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

	}

}


import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int a=input.nextInt();
		if(a%2==0) {
			System.out.println(a);
		}else {
			System.out.println(0);
		}
	}

}