/* package codechef; // don't place package name! */

import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
    // Complete the maximumSum function below.
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

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

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

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

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

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

            return res.toString();
        }

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

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

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

    static boolean prime(long a){
        if(a==2||a==3)
            return true;
        if((a-1)%6==0)
            return true;
        if((a+1)%6==0)
            return true;
        return false;
    }
    public static  long gcd(long a,long b){
        if(b==0)
            return a;
        long r=a%b;
        return gcd(b,r);
    }

    static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }

    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
    }

    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    // private static final FastReader scanner = new FastReader();
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader scanner = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        long a=scanner.nextInt(),b=scanner.nextInt();
        long c=a+b;
        long a1=0,b1=0,c1=0;
        while (a>0){
            if(a%10!=0){
                a1=a1*10+(a%10);
            }
            a/=10;
        }
        while (b>0){
            if(b%10!=0){
                b1=b1*10+(b%10);
            }
            b/=10;
        }
        while (c>0){
            if(c%10!=0){
                c1=c1*10+(c%10);
            }
            c/=10;
        }
        a1=Integer.parseInt(new StringBuilder(String.valueOf(a1)).reverse().toString());
        b1=Integer.parseInt(new StringBuilder(String.valueOf(b1)).reverse().toString());
        c1=Integer.parseInt(new StringBuilder(String.valueOf(c1)).reverse().toString());
        if(a1+b1==c1)
            w.println("YES");
        else
            w.println("NO");
        w.close();
    }
}


import static java.lang.Math.min;
import static java.util.Arrays.fill;

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

public class C {

	static void solve() throws IOException {
		int n = nextInt();
		int v = nextInt();
		int edges = nextInt();
		boolean[][] can = new boolean[n][n];
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		for (int i = 0; i < n; i++) {
			b[i] = nextInt();
		}
		for (int i = 0; i < edges; i++) {
			int u = nextInt() - 1, vv = nextInt() - 1;
			can[u][vv] = true;
			can[vv][u] = true;
		}
		// boolean[][] floyd = new boolean[n][];
		// for (int i = 0; i < n; i++) {
		// floyd[i] = can[i].clone();
		// }
		// for (int k = 0; k < n; k++) {
		// for (int i = 0; i < n; i++) {
		// if (!floyd[i][k]) {
		// continue;
		// }
		// for (int j = 0; j < n; j++) {
		// floyd[i][j] |= floyd[k][j];
		// }
		// }
		// }
		int[] parent = new int[n];
		fill(parent, -1);
		List<Integer> from = new ArrayList<>();
		List<Integer> to = new ArrayList<>();
		List<Integer> amount = new ArrayList<>();
		boolean good = true;
		for (int start = 0; start < n && good; start++) {
			if (parent[start] != -1) {
				continue;
			}
			Queue<Integer> queue = new ArrayDeque<>();
			queue.add(start);

			parent[start] = start;
			int[] out = new int[n];

			while (!queue.isEmpty()) {
				int u = queue.poll();
				for (int j = 0; j < n; j++) {
					if (!can[u][j]) {
						continue;
					}
					if (parent[j] == -1) {
						parent[j] = u;
						queue.add(j);
						++out[u];
					}
				}
			}

			long diff = 0;
			for (int i = 0; i < n; i++) {
				if (parent[i] >= 0) {
					diff += a[i] - b[i];
				}
			}

			if (diff != 0) {
				good = false;
				break;
			}
			queue.clear();
			for (int i = 0; i < n; i++) {
				if (out[i] == 0 && parent[i] >= 0) {
					queue.add(i);
				}
			}

			while (!queue.isEmpty()) {
				int leaf = queue.poll();
				if (--out[parent[leaf]] == 0) {
					queue.add(parent[leaf]);
				}
				if (a[leaf] == b[leaf]) {
					parent[leaf] = -2;
					continue;
				}

				int[] curParent = new int[n];
				Queue<Integer> curQueue = new ArrayDeque<>();
				fill(curParent, -1);

				curQueue.add(leaf);
				int[] curOut = new int[n];
				curParent[leaf] = leaf;
				while (!curQueue.isEmpty()) {
					int u = curQueue.poll();
					for (int i = 0; i < n; i++) {
						if (!can[u][i]) {
							continue;
						}
						if (parent[i] < 0 || curParent[i] >= 0) {
							continue;
						}
						++curOut[u];
						curParent[i] = u;
						curQueue.add(i);
					}
				}

				for (int i = 0; i < n; i++) {
					if (curOut[i] == 0 && curParent[i] >= 0) {
						curQueue.add(i);
					}
				}

				while (!curQueue.isEmpty() && a[leaf] != b[leaf]) {
					int x = curQueue.poll();
					int par = curParent[x];

					if (a[leaf] < b[leaf]) {
						int flow = min(v - a[par], a[x]);
						if (par == leaf) {
							flow = min(b[leaf] - a[leaf], flow);
						}
						from.add(x);
						to.add(par);
						amount.add(flow);
						a[x] -= flow;
						a[par] += flow;
					} else {
						int flow = min(v - a[x], a[par]);
						if (par == leaf) {
							flow = min(flow, a[leaf] - b[leaf]);
						}
						from.add(par);
						to.add(x);
						amount.add(flow);
						a[par] -= flow;
						a[x] += flow;
					}
					if (--curOut[par] == 0) {
						curQueue.add(par);
					}
				}
//				System.err.println(a[leaf]+"="+b[leaf]);
				parent[leaf] = -2;
			}

			for (int i = 0; i < n; i++) {
				if (parent[i] >= 0) {
					parent[i] = -2;
				}
			}
		}
//		System.err.println(Arrays.toString(a));
//		System.err.println(Arrays.toString(b));
		if (!good) {
			out.println("NO");
		} else {
			out.println(from.size());
			for (int i = 0; i < from.size(); i++) {
				out.println((from.get(i)+1)+" "+(to.get(i)+1)+" "+amount.get(i));
			}
		}
	}

	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		InputStream input = System.in;
		PrintStream output = System.out;
		File file = new File("c.in");
		if (file.exists() && file.canRead()) {
			input = new FileInputStream(file);
		}
		br = new BufferedReader(new InputStreamReader(input));
		out = new PrintWriter(output);
		solve();
		out.close();
	}

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

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

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

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


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

/**
 * CodeForces : 338
 *
 * @author vinaysaini E. Hexagons
 */
public class cf338e {

	static int dx[] = { 1, -1, -2, -1, 1, 2 };
	static int dy[] = { 2, 2, 0, -2, -2, 0 };

	public static void main(String[] args) {
		long x = 0, y = 0;

		long n = in.nextLong();
		long ringNumber = getRing(n);
		long stepsUpTo = 3 * ringNumber * ringNumber + 3 * ringNumber;
		x = 2 * ringNumber;
		long remainingSteps = n - stepsUpTo;
		if (remainingSteps > 0) {
			x = x + dx[0];
			y = y + dy[0];
			remainingSteps--;
		}
		if (remainingSteps >= ringNumber) {
			x += dx[1] * ringNumber;
			y += dy[1] * ringNumber;
			remainingSteps -= ringNumber;
		} else {
			x += dx[1] * remainingSteps;
			y += dy[1] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[2] * (ringNumber+1);
			y += dy[2] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[2] * remainingSteps;
			y += dy[2] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[3] * (ringNumber+1);
			y += dy[3] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[3] * remainingSteps;
			y += dy[3] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[4] * (ringNumber+1);
			y += dy[4] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[4] * remainingSteps;
			y += dy[4] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[5] * (ringNumber+1);
			y += dy[5] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[5] * remainingSteps;
			y += dy[5] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber) {
			x += dx[0] * ringNumber;
			y += dy[0] * ringNumber;
			remainingSteps -= ringNumber;
		} else {
			x += dx[0] * remainingSteps;
			y += dy[0] * remainingSteps;
			remainingSteps -= remainingSteps;
		}

		out.println(x + " " + y);
		out.close();
	}

	static long getRing(long n) {
		long l = 0;
		long r = (long) 1e9;
		while (l < r) {
			long m = (l + r) / 2;
			long sum = 3 * m * m + 3 * m;
			if (n < sum) {
				r = m;
			} else
				l = m + 1;
		}
		return l - 1;
	}

	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static FastScanner in = new FastScanner();

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			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;
		}
	} // --fast i/o ends here----//

}


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

public class A {
    private static class Solver {
        boolean ok(String s) {
            if(s.charAt(0) == '0') return s.length() == 1;
            if(s.length() >= 8) return false;
            return Integer.parseInt(s) <= 1000000;
        }

        public void run() throws IOException {
            int res = -1;
            final String s = IOFast.next();
            for(int i = 1; i < s.length(); i++)
                for(int j = i + 1; j < s.length(); j++) {
                    String[] ss = new String[] { s.substring(0, i), s.substring(i, j), s.substring(j) };
                    int x = 0;
                    boolean g = true;
                    for(int k = 0; k < ss.length; k++) {
                        g &= ok(ss[k]);
                        if(g) {
                            x += Integer.parseInt(ss[k]);
                        }
                    }
                    if(g) {
                        res = Math.max(res, x);
                    }
                }
            IOFast.out.println(res);
        }
    }

    public static void main(String[] args) throws IOException {
        new Solver().run();
        IOFast.out.flush();
    }

    static public class IOFast {
        private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        private static PrintWriter out = new PrintWriter(System.out);

//      private static final int BUFFER_SIZE = 50 * 200000;
        private static final StringBuilder buf = new StringBuilder();
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];

        static {
            for(int i = 0; i < 10; i++) {
                isDigit['0' + i] = true;
            }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
        }

        static boolean endInput;

        private static int nextInt() throws IOException {
            boolean plus = false;
            int ret = 0;
            while(true) {
                final int c = in.read();

                if(c == -1) {
                    endInput = true;
                    return Integer.MIN_VALUE;
                }

                if(isDigit[c]) {
                    if(c != '-') {
                        plus = true;
                        ret = c - '0';
                    }
                    break;
                }
            }

            while(true) {
                final int c = in.read();
                if(c == -1 || !isDigit[c]) {
                    break;
                }
                ret = ret * 10 + c - '0';
            }

            return plus ? ret : -ret;
        }

        private static long nextLong() throws IOException {
            boolean plus = false;
            long ret = 0;
            while(true) {
                final int c = in.read();

                if(c == -1) {
                    endInput = true;
                    return Integer.MIN_VALUE;
                }

                if(isDigit[c]) {
                    if(c != '-') {
                        plus = true;
                        ret = c - '0';
                    }
                    break;
                }
            }

            while(true) {
                final int c = in.read();
                if(c == -1 || !isDigit[c]) {
                    break;
                }
                ret = ret * 10 + c - '0';
            }

            return plus ? ret : -ret;
        }

        private static String next() throws IOException {
            buf.setLength(0);

            while(true) {
                final int c = in.read();

                if(c == -1) {
                    endInput = true;
                    return "-1";
                }

                if(!isSpace[c]) {
                    buf.append((char)c);
                    break;
                }
            }

            while(true) {
                final int c = in.read();

                if(c == -1 || isSpace[c]) {
                    break;
                }
                buf.append((char)c);
            }

            return buf.toString();
        }

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

    }

}


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

import static java.lang.Math.*;

public class Cf182 implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

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

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

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

			return res.toString();
		}

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

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

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Cf182(),"Main",1<<27).start();
	}

	public static long gcd(long a, long b)
	{
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}
	//  array sorting by colm
public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override
          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }

	// gcd

	public static long findGCD(long arr[], int n)
	{
		long result = arr[0];
		for (int i = 1; i < n; i++)
			result = gcd(arr[i], result);
		return result;
	}
	// fibonaci
	static int fib(int n)
    {
        int a = 0, b = 1, c;
        if (n == 0)
            return a;
        for (int i = 2; i <= n; i++)
        {
            c = a + b;
            a = b;
            b = c;
        }
        return b;
    }

// sort a string
    public static String sortString(String inputString)
    {

        char tempArray[] = inputString.toCharArray();

        Arrays.sort(tempArray);

        return new String(tempArray);
    }
    // pair function

    // list.add(new Pair<>(sc.nextInt(), i + 1));
    //     Collections.sort(list, (a, b) -> Integer.compare(b.first, a.first));
    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {}

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }

    static  boolean isPerfectSquare(int x)
    {
        int s = (int) Math.sqrt(x);
        return (s*s == x);
    }

    static boolean isFibonacci(int n)
    {

        return isPerfectSquare(5*n*n + 4) ||
               isPerfectSquare(5*n*n - 4);
    }

	public void run()
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int x = sc.nextInt();
		int h = sc.nextInt();
		int m = sc.nextInt();

		int count = 0;
		while (!(h+""+m).contains("7"))
		{
			m -= x;
			if (m < 0)
			{
				m += 60;
				h--;
				if(h<0)
					h+=24;
			}
			count++;
		}
		System.out.println(count);
	//		System.out.println(42 + 60*7 - 9*60 -24);
	}
}


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

public class RougeClock {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] buf = br.readLine().split(" ");

		long n = Long.parseLong(buf[0]);
		long m = Long.parseLong(buf[1]);

		int size_h = 1;
		int size_m = 1;
		for (int degree = 7; degree<n; degree*=7)
			size_h++;
		for (int degree = 7; degree<m; degree*=7)
			size_m++;

		int ans = 0;
		if(size_h+size_m<=7){
			for(int i =0;i<n;i++){
				for(int j =0;j<m;j++){
					int[] used = new int[7];
					for(int a=i, k = 0; k<size_h; a/=7, ++k)
						used[a%7]+=1;
					for(int a=j, k = 0; k<size_m; a/=7, ++k)
						used[a%7]+=1;
					if (max(used)<=1)
						ans++;
				}
			}
		}else{
			if(size_h<=6){
				for(int i =0;i<n;i++){
					int[] used = new int[6];
					for(int a=i, k = 0; k<=size_h; a/=7, k++){
						if(a%7==0)
							used[0]=2;
						else{
							used[a%7-1]+=1;
						}
					}
					if (max(used)<=1)
						ans++;
				}
			}
			if(size_m<=6){
				for(int i =0;i<m;i++){
					int[] used = new int[6];
					for(int a=i, k = 0; k<=size_h; a/=7, k++){
						if(a%7==0)
							used[0]=2;
						else
							used[a%7-1]+=1;
					}
					if (max(used)<=1)
						ans++;
				}
			}
		}

		System.out.println(ans);
	}

	private static int max(int[] used) {
		int max =0;
		for(int i =0; i<used.length;i++){
			if(used[i]>max){
				max = used[i];
			}
		}
		return max;
	}
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String s = new Scanner(System.in).nextLine();
        String chars = "><+-.,[]";
        int res =0;
        for(char c:s.toCharArray()) {
            int x = chars.indexOf(c)+8;
            res = (res *16+x)%1000003;
        }
        System.out.println(res);
    }
}


import java.util.*;
import java.io.*;
public class F2 {

	static long mod = 998244353;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		String[] s = new String[n];
		for(int i = 0; i < n; i++) {
			s[i] = sc.next();
		}

		HashSet<String> suffs = new HashSet<>();
		for(int i = 0; i < n; i++){
			for(int j = 1; j < s[i].length(); j++){
				suffs.add(s[i].substring(j));
			}
		}
		suffs.add("");
		HashSet<Pair> nodes = new HashSet<>();
		for(String a: suffs){
			for(String b: suffs){
				if(isPref(a, b)) {
					nodes.add(new Pair(a, b));
				}
			}
		}
		int N = nodes.size();
//		System.out.println(N);
		HashMap<Pair, Integer> code = new HashMap<>();
		Pair[] decode = new Pair[N];
		int count = 0;
		for(Pair p: nodes) {
			decode[count] = p;
			code.put(p, count++);
		}
		int[][] aut = new int[N][N];
		Pair p0 = new Pair("","");
		for(String t: s) {
			for(String u: s) {
				if(isPref(t, u)) {
					String a = t.substring(1);
					String b = u.substring(1);
					Pair p = new Pair(a, b);
					aut[code.get(p0)][code.get(p)]++;
				}
				else if(isPref(u, t)) {
					String a = u.substring(1);
					String b = t.substring(1);
					Pair p = new Pair(a, b);
					aut[code.get(p0)][code.get(p)]++;
				}
			}
		}
		for(Pair p: nodes) {
			Pair q = next(p);
			if(p.equals(p0)){
				continue;
			}
			else if(q != null) {
				aut[code.get(p)][code.get(q)]++;
			}
			else {
				for(String t: s) {
					q = next(p, t);
					if(q != null && nodes.contains(q)) {
						aut[code.get(p)][code.get(q)]++;
					}
				}
			}
		}
		Matrix mat = new Matrix(aut);
		Matrix matp = pow(mat, m);
		System.out.println(matp.mat[code.get(p0)][code.get(p0)]);
	}
	static Pair next(Pair p, String s) {
		if(p.a.equals("")) {
			if(isPref(s, p.b)) {
				String a = s.substring(1);
				String b = p.b.substring(1);
				return new Pair(a, b);
			}
			else if(isPref(p.b, s)) {
				String a = p.b.substring(1);
				String b = s.substring(1);
				return new Pair(a, b);
			}
			else return null;
		}
		else return null;
	}
	static Pair next(Pair p) {
		if(p.a.equals("")) return null;
		String a = p.a.substring(1);
		String b = p.b.substring(1);
		return new Pair(a, b);
	}
	static boolean isPref(String a, String b) { //a of b
		if(a.length() > b.length()) return false;
		else return b.substring(0, a.length()).equals(a);
	}
	static class Pair {
		String a, b;
		public Pair(String a, String b) {
			this.a = a; this.b = b;
		}
		@Override
		public int hashCode() {
			return a.hashCode() + b.hashCode();
		}
		@Override
		public boolean equals(Object o) {
			Pair p = (Pair)o;
			return a.equals(p.a) && b.equals(p.b);
		}
		public String toString() {
			return "'"+a+"' '"+b;
		}
	}

	static Matrix pow(Matrix m, int exp) {
		Matrix res = new Matrix(m.n);
		Matrix mapow = m;
		while(exp > 0) {
			if((exp & 1) == 1) {
				res = res.mult(mapow);
			}
			mapow = mapow.mult(mapow);
			exp >>= 1;
		}
		return res;
	}
	static class Matrix{
		int[][] mat; int n;
		public Matrix(int[][] mat) {
			n = mat.length;
			this.mat = mat;
		}
		public Matrix(int n) {
			mat = new int[n][n];
			this.n = n;
			for(int i = 0; i < n; i++) mat[i][i] = 1;
		}
		Matrix mult(Matrix m) {
			int[][] res = new int[n][n];
			for(int k = 0; k < n; k++) {
				for(int i = 0; i < n; i++) {
					for(int j = 0; j < n; j++) {
						long a = mat[i][k];
						long b = m.mat[k][j];
						long c = res[i][j];
						res[i][j] = (int)((c + a*b%mod)%mod);
					}
				}
			}
			return new Matrix(res);
		}
		public String toString(){
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < n; i++) {
				sb.append(Arrays.toString(mat[i])+"\n");
			}
			return sb.toString();
		}
	}

}


// upsolve with rainboy
import java.io.*;
import java.util.*;

public class CF1187G extends PrintWriter {
	CF1187G() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1187G o = new CF1187G(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	ArrayList[] aa_;
	int n_, m_;
	int[] pi, dd, bb;
	int[] uu, vv, uv, cost;
	int[] cc;
	void init() {
		aa_ = new ArrayList[n_];
		for (int u = 0; u < n_; u++)
			aa_[u] = new ArrayList<Integer>();
		pi = new int[n_];
		dd = new int[n_];
		bb = new int[n_];
		qq = new int[nq];
		iq = new boolean[n_];
		uu = new int[m_];
		vv = new int[m_];
		uv = new int[m_];
		cost = new int[m_];
		cc = new int[m_ * 2];
		m_ = 0;
	}
	void link(int u, int v, int cap, int cos) {
		int h = m_++;
		uu[h] = u;
		vv[h] = v;
		uv[h] = u ^ v;
		cost[h] = cos;
		cc[h << 1 ^ 0] = cap;
		aa_[u].add(h << 1 ^ 0);
		aa_[v].add(h << 1 ^ 1);
	}
	int[] qq;
	int nq = 1 << 20, head, cnt;
	boolean[] iq;
	void enqueue(int v) {
		if (iq[v])
			return;
		if (head + cnt == nq) {
			if (cnt * 2 <= nq)
				System.arraycopy(qq, head, qq, 0, cnt);
			else {
				int[] qq_ = new int[nq *= 2];
				System.arraycopy(qq, head, qq_, 0, cnt);
				qq = qq_;
			}
			head = 0;
		}
		qq[head + cnt++] = v; iq[v] = true;
	}
	int dequeue() {
		int u = qq[head++]; cnt--; iq[u] = false;
		return u;
	}
	boolean spfa(int s, int t) {
		Arrays.fill(pi, INF);
		pi[s] = 0;
		head = cnt = 0;
		enqueue(s);
		while (cnt > 0) {
			int u = dequeue();
			int d = dd[u] + 1;
			ArrayList<Integer> adj = aa_[u];
			for (int h_ : adj)
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
					int v = u ^ uv[h];
					if (pi[v] > p || pi[v] == p && dd[v] > d) {
						pi[v] = p;
						dd[v] = d;
						bb[v] = h_;
						enqueue(v);
					}
				}
		}
		return pi[t] != INF;
	}
	void push(int s, int t) {
		int c = INF;
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			c = Math.min(c, cc[h_]);
		}
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_] -= c; cc[h_ ^ 1] += c;
		}
	}
	void push1(int s, int t) {
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_]--; cc[h_ ^ 1]++;
		}
	}
	int edmonds_karp(int s, int t) {
		while (spfa(s, t))
			push1(s, t);
		int c = 0;
		for (int h = 0; h < m_; h++)
			c += cost[h] * cc[h << 1 ^ 1];
		return c;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int[] ii = new int[k];
		for (int h = 0; h < k; h++)
			ii[h] = sc.nextInt() - 1;
		ArrayList[] aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i].add(j);
			aa[j].add(i);
		}
		int t = n + k + 1;
		n_ = n * t + 1;
		m_ = k + (m * 2 * k + n) * (t - 1);
		init();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> adj = aa[i];
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s;
				for (int j : adj) {
					int v = j * t + s + 1;
					for (int x = 1; x <= k; x++)
						link(u, v, 1, c + (x * 2 - 1) * d);
				}
			}
		}
		for (int i = 0; i < n; i++)
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s, v = u + 1;
				link(u, v, k, i == 0 ? 0 : c);
			}
		for (int h = 0; h < k; h++)
			link(n_ - 1, ii[h] * t + 0, 1, 0);
		println(edmonds_karp(n_ - 1, 0 * t + t - 1));
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class E {
	public static int answer = 0;
	public static int[][] adj;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int len = in.nextInt();
		adj = new int[len][len];
		go(0,0,in);
		gog(0,0,0);
		gor(0,0);
		System.out.println(answer);
	}
	public static int go(int a, int b, Scanner in){
	   b=b>=adj.length?0+(++a)-a:b;
	   a = a<adj.length?a+complete(a,b,in)+go(a,b+1,in):a;
	   return 0;
	}
	public static int gog(int a, int b, int c){
		   c=c>=adj.length?0+(++b)-b:c;
		   b=b>=adj.length?0+(++a)-a:b;
		   a = a<adj.length?a+complete2( c,b,a)+gog(a,b,c+1):a;
		   return 0;
		}
	public static int gor(int a, int b){
	   b=b>=adj.length?0+(++a)-a:b;
	   a = a<adj.length?a+complete3(a,b)+gor(a,b+1):a;
	   return 0;
	}
	public static int complete3(int a, int b){
		answer=adj[a][b]>answer?adj[a][b]:answer;
		return 0;
	}
	public static int complete(int a, int b, Scanner in){
		adj[a][b]=in.nextInt();
		return 0;
	}
	public static int complete2(int a, int b,int c){
		adj[a][b] = Math.min(adj[a][b], adj[a][c]+adj[c][b]);
		return 0;
	}
}


import java.io.*;

//Codeforces Beta Round #41 (Div. 1), B
public class Chess {

    public static void main(String[] args) throws IOException {
		File file = new File("input.txt");
		if(file.exists())
			System.setIn(new FileInputStream(file));
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String[] ss = r.readLine().split(" ");
		boolean a[][] = new boolean[10][10];
		for(int i = 0; i < 10; i++)
			a[0][i] = a[i][0] = a[9][i] = a[i][9] = true;
		int k1 = ss[2].charAt(0) - 'a' + 1, k2 = ss[2].charAt(1) - '0';
		for(String s : new String[]{ss[0], ss[1]}) {
			int l1 = s.charAt(0) - 'a' + 1, l2 = s.charAt(1) - '0';
			for(int i = 1; i < 9; i++) {
				if(i != l1 && (l2 != k2 || i <= k1 && l1 < k1 || i >= k1 && l1 > k1))
					a[i][l2] = true;
				if(i != l2 && (l1 != k1 || i <= k2 && l2 < k2 || i >= k2 && l2 > k2))
					a[l1][i] = true;
			}
		}
		a[k1][k2] = a[k1][k2 - 1] = a[k1][k2 + 1] = a[k1 - 1][k2 - 1] = a[k1 - 1][k2] = a[k1 - 1][k2 + 1] = a[k1 + 1][k2 - 1] = a[k1 + 1][k2] = a[k1 + 1][k2 + 1] = true;
		/*for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++)
				System.out.print(a[i][j] ? 'X' : ' ');
			System.out.println();
		}*/
		int p1 = ss[3].charAt(0) - 'a' + 1, p2 = ss[3].charAt(1) - '0';
		boolean result = a[p1][p2] && a[p1][p2 - 1] && a[p1][p2 + 1] && a[p1 - 1][p2 - 1] && a[p1 - 1][p2] && a[p1 - 1][p2 + 1] && a[p1 + 1][p2 - 1] && a[p1 + 1][p2] && a[p1 + 1][p2 + 1];
		System.out.println(result ? "CHECKMATE" : "OTHER");
    }

}


import java.util.*;
import java.lang.*;

public class Greedy {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] firstLine = sc.nextLine().split(" ");
        int d = Integer.parseInt(firstLine[0]);
        int toStudy = Integer.parseInt(firstLine[1]);
        int[] arr = new int[d * 2];
        int[] gb = new int[d];
        for(int i = 0; i < d; i++) {
            String[] nextLine = sc.nextLine().split(" ");
            arr[i * 2] = Integer.parseInt(nextLine[0]);
            arr[i * 2 + 1] = Integer.parseInt(nextLine[1]);
            toStudy -= arr[i * 2]; // greedy subtraction of the minimum;
            gb[i] = arr[i * 2];
        }
        if(toStudy < 0) {
            System.out.println("NO"); // the mins are too high for the study time
            return;
        }
        for(int i = 0; i < d; i++) {
            toStudy -= (arr[i * 2 + 1] - arr[i * 2]);
            gb[i] = arr[i * 2 + 1];
            if(toStudy <= 0) {
                gb[i] -= Math.abs(toStudy);
                System.out.println("YES");
                printString(gb);
                return;
            }
        }
        System.out.println("NO");

    }

    private static void printString(int[] arr) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);
            sb.append(" ");
        }
        System.out.println(sb.toString());
    }

}


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

public class AntonAndFairyTale {
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    long L_INF = (1L << 60L);

    void solve() {
        long n = nl(), m = nl(), start = 0, end = (long)2e9, mid;
        if (m >= n) {
            pw.println(n);
            return;
        }
        n -= m;
        while (start < end) {
            mid = start + (end - start) / 2;
            long x = mid * (mid + 1) / 2;
            if (n <= x)
                end = mid;
            else
                start = mid + 1;
        }
        pw.println(start + m);
    }

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

        long s = System.currentTimeMillis();
        //        int t = ni();
        //        while (t-- > 0)
        solve();
        pw.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

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

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

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

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

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

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

    private char nc() {
        return (char) skip();
    }

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

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

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

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

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

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

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

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

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

    private void tr(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }
}


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

public class Main {

    static long n, k, a, b;
    static long mn = Long.MAX_VALUE;
    static long mx = Long.MIN_VALUE;

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

    static void check(long start, long finish) {
        long len = (finish - start + n * k) % (n * k);
        long g = gcd(n * k, len);
        long cnt = n * k / g;
        mn = Math.min(mn, cnt);
        mx = Math.max(mx, cnt);
//        System.err.println(len + " " + mn + " " + mx);
    }

    public static void main(String[] args) throws Exception {
        FastScanner scanner = new FastScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        n = scanner.nextInt();
        k = scanner.nextInt();

        a = scanner.nextInt();
        b = scanner.nextInt();

        for (long i = 0; i < n; i++) {
            check(1 + a, 1 + i * k + b);
            check(1 + a, 1 + i * k - b);
            check(1 - a, 1 + i * k + b);
            check(1 - a, 1 + i * k - b);
        }

        writer.println(mn + " " + mx);
        writer.close();
    }

    final static class FastScanner implements AutoCloseable {
        private final int BUFFER_CAPACITY = 1024;

        private final InputStream stream;
        private final byte[] buffer = new byte[BUFFER_CAPACITY];
        private int size = 0;
        private int current = 0;
        private char lastReadedChar = '\0';

        FastScanner(InputStream stream) {
            this.stream = stream;
        }

        FastScanner(String filename) throws IOException {
            this.stream = new FileInputStream(filename);
        }

        public void close() throws Exception {
            stream.close();
        }

        boolean hasNextLine() throws Exception {
            try {
                return Character.isWhitespace(lastReadedChar) || !endOfInputReached();
            } catch (IOException e) {
                return false;
            }
        }

        char nextChar() throws Exception {
            byte firstByte = nextByte();
            int octets = 0;
            for (int i = 7; (firstByte >> i & 1) == 1; i--) {
                octets++;
            }
            if (octets == 0) {
                return (char) firstByte;
            }
            char res = 0;
            for (int bit = 7 - octets; bit >= 0; bit--) {
                res <<= 1;
                res += (firstByte >> bit) & 1;
            }
            for (int i = 1; i < octets; i++) {
                res <<= 6;
                res += nextByte() + 128;
            }
            return res;
        }

        String next() throws Exception {
            do {
                lastReadedChar = nextChar();
            } while (Character.isWhitespace(lastReadedChar));
            StringBuilder res = new StringBuilder();
            while (!endOfInputReached() && !Character.isWhitespace(lastReadedChar)) {
                res.append(lastReadedChar);
                lastReadedChar = nextChar();
            }
            if (!Character.isWhitespace(lastReadedChar)) {
                res.append(lastReadedChar);
            }
            return res.toString();
        }

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

        private byte nextByte() throws Exception {
            if (endOfInputReached()) {
                throw new Exception();
            }
            return buffer[current++];
        }

        private void fillBuffer() throws Exception {
            do {
                size = stream.read(buffer);
            } while (size == 0);
            current = 0;
        }

        private boolean endOfInputReached() throws Exception {
            if (current >= size) {
                fillBuffer();
            }
            return size == -1;
        }
    }
}


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;

public class D {

	static int N;
	static Vec ar[];
	static boolean used[];
	static char S[];
	static int sId;
	static ArrayList<Integer> res;
	static boolean largerY = false;
	public static void main(String[] args) {
		JS in = new JS();
		PrintWriter out = new PrintWriter(System.out);

		N = in.nextInt();
		res = new ArrayList<Integer>();
		ar = new Vec[N];
		for(int i = 0; i < N; i++) {
			ar[i] = new Vec(in.nextLong(),in.nextLong(),i);
		}

		S = in.next().toCharArray();

		Vec b = ar[0];
		if(S[0] == 'L') {
			for(int i = 1; i < N; i++) if(ar[i].x < b.x || (ar[i].x == b.x && ar[i].y > b.y)) b = ar[i];
		}
		else {
			for(int i = 1; i < N; i++) if(ar[i].x < b.x || (ar[i].x == b.x && ar[i].y < b.y)) b = ar[i];
		}
		used = new boolean[N];
		add(b.id);

		for(int sId = 0; sId < S.length; sId++) {
			if(S[sId] == 'L') {
				Vec next = null;
				for(int i = 0; i < N; i++) {
					if(used[ar[i].id])continue;
					if(next == null || ar[i].sub(b).cross(next.sub(b)) > 0) next = ar[i];
				}
				add(next.id);
				b = next;
			}
			else {
				Vec next = null;
				for(int i = 0; i < N; i++) {
					if(used[ar[i].id])continue;
					if(next == null || ar[i].sub(b).cross(next.sub(b)) < 0) next = ar[i];
				}
				add(next.id);
				b = next;
			}

		}

		for(int i = 0; i < N; i++) {
			if(!used[ar[i].id]) res.add(ar[i].id);
		}

		for(int ii : res) out.print((ii+1)+" ");
		out.println();
		out.close();
	}

	static void add(int x) {
		res.add(x);
		used[x]=true;
	}

	static class Vec implements Comparable<Vec>{
		long x,y;
		int id;
		public Vec(long xx, long yy) {
			x=xx;
			y=yy;
		}
		public Vec(long xx, long yy, int ii) {
			x=xx;
			y=yy;
			id=ii;
		}
		public long cross(Vec o) {
			return x*o.y - y*o.x;
		}
		public Vec sub(Vec o) {
			return new Vec(x-o.x, y-o.y);
		}
		@Override
		public int compareTo(Vec o) {
			if(x == o.x) return  largerY ? -Long.compare(y, o.y) : Long.compare(y, o.y);
			return Long.compare(x, o.x);
		}
	}

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

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

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

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

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

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

		public double nextDouble() {
		    while(c!='.'&&c!='-'&&(c <'0' || c>'9')) c = nextChar();
		    boolean neg = c=='-';
		    if(neg)c=nextChar();
		    boolean fl = c=='.';
		    double cur = nextLong();
		    if(fl) return neg ? -cur/num : cur/num;
		    if(c == '.') {
			double next = nextLong();
			return neg ? -cur-next/num : cur+next/num;
		    }
		    else return neg ? -cur : cur;
		}

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

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

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

}


import java.util.*;

public class BearAndCompressing {

    int n, q, ans = 0;
    String[][] op = new String[36][2];

    BearAndCompressing() {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        q = scanner.nextInt();

        for (int i = 0; i < q; i++) {
            op[i][0] = scanner.next();
            op[i][1] = scanner.next();
        }

        for (int i = 0; i < q; i++) {
            if (op[i][1].equals("a")) {
                recursive(op[i][0]);
            }
        }
        System.out.println(ans);
        scanner.close();
    }

    void recursive(String res){
        if (res.length() >= n) {
            ans++;
            return;
        }
        String temp;
        for (int i = 0; i < q; i++) {
            if (op[i][1].charAt(0) == res.charAt(0)) {
                temp = res;
                res = op[i][0] + res.substring(1);
                //System.out.println(res);
                recursive(res);
                res = temp;
            }
        }
    }

    public static void main(String[] args) {
        BearAndCompressing solve = new BearAndCompressing();
    }
}


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

public class ar {

    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 (final 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 (final IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static boolean[] seen;
    static Map<Integer, Integer> map;
    static Set<Character> charset;
    static Set<Integer> set;
    static int[] arr;
    static int[][] dp;
    static int rem = (int) 1e9 + 7;
    static List<List<Integer>> graph;
static int[][] kmv ={{2,1},{1,2},{2,-1},{-1,2},{-2,1},{1,-2},{-1,-2},{-2,-1}};
static char[]car;
static boolean[] primes;
static int MAX=(int)1e4+1;
static double[] dar;
static long[] lar;
static void Sieve(){

primes=new boolean[MAX];
primes[0]=true;
primes[1]=true;

for(int i=2;i*i<MAX;i++){
    if(!primes[i]){
        for(int j=i*i;j<MAX;j+=i){
            primes[j]=true;
        }
    }
}

}

public static void main( String[] args) throws java.lang.Exception {
         FastReader scn = new FastReader();
int n=scn.nextInt();
String s=scn.next();
int cnt=0;
int ans=0;
int i=0;
while(i<n){
    if(s.charAt(i)>='a' && s.charAt(i)<='z'){
        charset=new HashSet<>();
    for(int j=i;j<n;j++){
        if(s.charAt(j)<='Z'){
          ans=Math.max(ans,cnt);
          cnt = 0; break;}
        if(s.charAt(j)>='a' && s.charAt(j)<='z'){
           if(!charset.contains(s.charAt(j)))
           {charset.add(s.charAt(j));
               cnt++;}
       }
    i++;
    }
    if(cnt>ans)ans=cnt;
}else i++;
}
System.out.print(ans);
return;
}

}


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

public class B {

  void solve() {
    Input in = new Input(System.in);
    int n = in.nextInt();
    int r = in.nextInt();
    int v = in.nextInt();

    for(int i = 0; i < n; i++) {
      int s = in.nextInt();
      int f = in.nextInt();
      int d = f - s;

      double gain = 0.0;
      while(true) {
        double newGain = calculateGain(gain, d, r);
        if(Math.abs(newGain - gain) < 10e-7) {
          break;
        } else {
          gain = (newGain + gain) / 2;
        }
      }

      double result = (d - gain) / v;

      System.out.println(result);
    }
  }

  double calculateGain(double gain, int d, int r) {
    double rounds = Math.floor((d -gain) / (2 * Math.PI * r));
    double diff = d -gain - rounds * 2 * Math.PI * r;
    double angle = diff / r;

    if(angle > Math.PI) angle = 2 * Math.PI - angle;

    double newGain = 2 * r * Math.sin(angle / 2);

    return newGain;
  }

  public static void main(String[] args) {
    new B().solve();
  }

  class Input {

    BufferedReader br;
    StringTokenizer st;

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

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

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

  }

}


import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println((int)Math.signum(s.nextLine().toLowerCase().compareTo(s.nextLine().toLowerCase())));
    }
}


import java.util.*;
import java.lang.*;

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

		int num = scan.nextInt();

		int[] numbers = new int[num];

		for (int i = 0; i < num; i++) {
			numbers[i] = scan.nextInt();
		}

		Arrays.sort(numbers);

		if (num == 0) {
			System.out.println("YES");
			System.out.println(1);
			System.out.println(1);
			System.out.println(3);
			System.out.println(3);
			return;
		}
		else if (num == 1) {
			System.out.println("YES");
			System.out.println(numbers[0]);
			System.out.println(3*numbers[0]);
			System.out.println(3*numbers[0]);
			return;
		}

		else if (num == 2) {
			if (numbers[0] == numbers[1]) {
				System.out.println("YES");
				System.out.println(3*numbers[0]);
				System.out.println(3*numbers[0]);
				return;
			}

			else if (numbers[1]/numbers[0] == 3) {
				System.out.println("YES");
				System.out.println(3*numbers[0]);
				System.out.println(3*numbers[1]);
				return;
			}

			else if (numbers[0]/numbers[1] == 3) {
				System.out.println("YES");
				System.out.println(3*numbers[0]);
				System.out.println(3*numbers[1]);
			}

			else {
				for(int i = 1; i <= 1500; i++) {
					for (int j = 1; j <= 1500; j++) {
						if (check2(numbers, i, j)) {
							System.out.println("YES");
							System.out.println(i);
							System.out.println(j);
							return;
						}
					}
				}
				System.out.println("NO");
				return;
			}
		}

		else if (num == 3) {
//			if (numbers[0] == numbers[1]) {
//				if (numbers[2]/numbers[0] == 3) {
//					System.out.println("YES");
//					System.out.println(numbers[2]);
//					return;
//				}
//				else if (numbers[0]/numbers[2] == 3) {
//					System.out.println("YES");
//					System.out.println(numbers[2]);
//					return;
//				}
//				else {
//					System.out.println("NO");
//					return;
//				}
//			}
//
//			else if (numbers[0] == numbers[2]) {
//				if (numbers[1]/numbers[0] == 3 || numbers[0]/numbers[1] == 3) {
//					System.out.println("YES");
//					System.out.println(numbers[1]);
//					return;
//				}
//				else {
//					System.out.println("NO");
//					return;
//				}
//			}
//
//			else if (numbers[1] == numbers[2]) {
//				if (numbers[0]/numbers[1] == 3 || numbers[1]/numbers[0] == 3) {
//					System.out.println("YES");
//					System.out.println(numbers[0]);
//					return;
//				}
//				else {
//					System.out.println("NO");
//					return;
//				}
//			}
			//no duplicates at all
			//else {
				if (3*numbers[0]<numbers[2]) {
					System.out.println("NO");
				}
				else {
					for(int i = 1; i <= 1500; i++) {
						if(check3(numbers, i)) {
							System.out.println("YES");
							System.out.println(i);
							return;
						}
					}
					System.out.println("NO");
					return;
				}
			//}
		}

		else {
			check4(numbers[0], numbers[1], numbers[2], numbers[3]);
			return;
		}
	}

	public static void check4(int a, int b, int c, int d) {
		if ((d-a) == ((b+c)/2) && (d-a) == ((a+b+c+d)/4)) {
				System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}

	public static boolean check3(int[] numbers, int i) {
		int[]num = new int[4];

		int index = 0;

		for(int x: numbers) {
			num[index] = x;
			index++;
		}
		num[index] = i;

		Arrays.sort(num);

		if ( ((num[3]-num[0]) == ((num[1]+num[2])/2.0)) && ((num[3]-num[0]) == ((num[0]+num[1]+num[2]+num[3])/4.0)) ) {
//			for(int x: num) {
//				System.out.println(x);;
//			}
			return true;
		}

		return false;

	}
	public static boolean check2(int[] numbers, int i, int j) {
		int[]num = new int[4];

		int index = 0;

		for(int x: numbers) {
			num[index++] = x;
		}

		num[index++] = i;
		num[index] = j;

		Arrays.sort(num);

		if ((num[3]-num[0]) == ((num[1]+num[2])/2.0) && (num[3]-num[0]) == ((num[0]+num[1]+num[2]+num[3])/4.0)) {
				return true;
		}

		else {
			return false;
		}

	}
}


/*
I am dead inside
Do you like NCT, sKz, BTS?
5 4 3 2 1 Moonwalk
Imma knock it down like domino
Is this what you want? Is this what you want?
Let's ttalkbocky about that
 */
import static java.lang.Math.*;
import java.util.*;
import java.io.*;
import java.math.*;

public class lolE
{
    static String target = "theseus";
    static String reverse = "sueseth";
    //static int[] dx = {-1, 1, 0, 0, -1, -1, 1, 1};
    //static int[] dy = {0, 0, -1, 1, -1, 1, -1, 1};
    //static int[] dx = {0, 1, 1};
    //static int[] dy = {1, 0, 1};
    public static void main(String omkar[]) throws Exception
    {
        BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(infile.readLine());
        int N = Integer.parseInt(st.nextToken());
        char[][] grid = new char[N][N];
        for(int r=0; r < N; r++)
            grid[r] = infile.readLine().trim().toCharArray();
        String res = "NO";
        for(int r=0; r < N; r++)
            for(int c=0; c < N-6; c++)
            {
                String temp = "";
                for(int i=c; i < c+7; i++)
                    temp += grid[r][i];
                if(temp.equals(target))
                    res = "YES";
            }
        for(int c=0; c < N; c++)
            for(int r=0; r < N-6; r++)
            {
                String temp = "";
                for(int i=r; i < r+7; i++)
                    temp += grid[i][c];
                if(temp.equals(target))
                    res = "YES";
            }
        //diagonals
        for(int r=0; r < N; r++)
            for(int c=0; c < N; c++)
            {
                String temp = "";
                int lol = 0;
                while(temp.length() < 7)
                {
                    if(max(r, c)+lol >= N)
                        break;
                    temp += grid[r+lol][c+lol];
                    lol++;
                }
                if(temp.equals(target))
                    res = "YES";
            }
        System.out.println(res);
    }
}


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

public class Codeforces553B {

	public static void main(String[] args) {
		try {
			BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
			StringTokenizer st = new StringTokenizer(f.readLine());
			int n = Integer.parseInt(st.nextToken());
			long k = Long.parseLong(st.nextToken()) - 1;
			f.close();
			StringBuffer permutation = new StringBuffer("");
			long[] fibonacci = new long[n + 1];
			fibonacci[1] = 1;
			for(int i = 2; i <= n; i++)
				fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
			int current = 1;
			int counter = n;
			while(counter > 0)
			{
				if(k < fibonacci[counter])
				{
					permutation.append(current + " ");
					current++;
					counter--;
				}
				else
				{
					permutation.append((current + 1) + " " + current + " ");
					k -= fibonacci[counter];
					current += 2;
					counter -= 2;
				}
				//System.out.println(permutation.toString().trim());
			}
			System.out.println(permutation.toString().trim());
			//System.out.println(Arrays.toString(binary));
			//System.out.println(Arrays.toString(groups));
		}
		catch(IOException e) {
			e.printStackTrace();
		}
	}

}


import static java.util.Arrays.sort;
import java.util.Scanner;

public class third
{
	public static void main(String arr[])
	{
		Scanner sc= new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long count=0;
		if(b==1)
		{
			System.out.println(a);
			return ;
		}
		while(a%b!=1)
		{
			count+=a/b;
			long temp=b;
			b=a%b;
			a=temp;
		}
		count+=a/b;
		count+=b;
		System.out.println(count);

	}
}


import java.io.PrintWriter;
import java.util.Scanner;

public class A {
   public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter pw = new PrintWriter(System.out);
    String s = sc.next();
    int t = Integer.valueOf(s.substring(0,1));
    int h = Integer.valueOf(s.substring(1,2));
    int [] a = {2,7,2,3,3,4,2,5,1,2};
    pw.print(a[t] * a[h]);
    pw.flush();
}
}


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

public class Main {
    public static void main (String[] args) throws java.lang.Exception {
		InputReader scan = new InputReader(System.in);
		PrintWriter writer = new PrintWriter(System.out, true);
		(new Main(scan, writer)).run();
		writer.close();
    }

    private InputReader jin;
    private PrintWriter jout;

    public Main(InputReader in, PrintWriter out) {
    	this.jin  = in;
    	this.jout = out;
    }

    public void run() throws Exception {
		int n = jin.integer();
		if(n == 0) {
			jout.println("0 0 0");
		} else if(n == 1) {
		 	jout.println("0 0 1");
		} else {
			int[] fib = new int[(int)1e6];
			fib[0] = 0; fib[1] = 1;
			int i = 2;
			for(; fib[i - 1] < n; i++) {
				fib[i] = fib[i - 1] + fib[i - 2];
			}
			jout.println(fib[0] + " " + fib[i - 2] + " " + fib[i - 3]);
		}

    }
}

class InputReader {
    private static final int bufferMaxLength = 1024;
    private InputStream in;
    private byte[] buffer;
    private int currentBufferSize;
    private int currentBufferTop;
    private static final String tokenizers = " \t\r\f\n";

    public InputReader(InputStream stream) {
        this.in = stream;
        buffer = new byte[bufferMaxLength];
        currentBufferSize = 0;
        currentBufferTop = 0;
    }

    private boolean refill() throws IOException {
        this.currentBufferSize = this.in.read(this.buffer);
        this.currentBufferTop = 0;
        return this.currentBufferSize > 0;
    }

    private Byte readChar() throws IOException {
        if(currentBufferTop < currentBufferSize) {
            return this.buffer[this.currentBufferTop++];
        } else {
            if(!this.refill()) {
                return null;
            } else {
                return readChar();
            }
        }
    }

    public String token() throws IOException {
        StringBuffer tok = new StringBuffer();
        Byte first;
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));
        if(first == null) return null;
        tok.append((char)first.byteValue());
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {
            tok.append((char)first.byteValue());
        }
        return tok.toString();
    }

    public String line() throws IOException {
		Byte first;
		StringBuffer line = new StringBuffer();
		while ((first = readChar()) != null && (char)first.byteValue() != '\n') {
			line.append((char)first.byteValue());
		}
		return (first == null && line.length() == 0)? null : line.toString();
    }

    public Integer integer() throws NumberFormatException, IOException {
        String tok = token();
        return tok == null? null : Integer.parseInt(tok);
    }

}


import java.util.Scanner;

public class RectanglePuzzleII {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		double n = sc.nextDouble();
		double m = sc.nextDouble();
		double x = sc.nextDouble();
		double y = sc.nextDouble();
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double abgcd = gcd(a,b);

		if (abgcd>1) {
			a = a/abgcd;
			b = b/abgcd;
		}

		double ratio = 1;

		if ((Math.abs(n))/a > (Math.abs(m))/b) {
			ratio = Math.floor((Math.abs(m))/b);
		} else if ((Math.abs(n))/a < (Math.abs(m))/b) {
			ratio = Math.floor((Math.abs(n))/a);
		} else if ((Math.abs(n))/a == (Math.abs(m))/b) {
			ratio = Math.floor((Math.abs(m))/b);
		}

		double xxsize = a*ratio;
		double xx1 = x-Math.ceil(xxsize/2);
		double xx2 = x+Math.floor(xxsize/2);
		if (n > 0) {
			if (xx1 <= 0) {
				double move = 0-xx1;
				xx1 += move;
				xx2 += move;
			} else if (xx2 >= n) {
				double move = xx2-n;
				xx1 -= move;
				xx2 -= move;
			}
		} else if (n < 0) {
			if (xx1 >= 0) {
				double move = xx1;
				xx1 -= move;
				xx2 -= move;
			} else if (xx2 <= n) {
				double move = xx2-n;
				xx1 += move;
				xx2 += move;
			}
		}

		double yysize = b*ratio;
		double yy1 = y-Math.ceil(yysize/2);
		double yy2 = y+Math.floor(yysize/2);
		if (m > 0) {
			if (yy1 <= 0) {
				double move = 0-yy1;
				yy1 += move;
				yy2 += move;
			} else if (yy2 >= m) {
				double move = yy2-m;
				yy1 -= move;
				yy2 -= move;
			}
		} else if (m < 0) {
			if (yy1 >= 0) {
				double move = yy1;
				yy1 -= move;
				yy2 -= move;
			} else if (yy2 <= m) {
				double move = yy2-m;
				yy1 += move;
				yy2 += move;
			}
		}

		System.out.printf("%.0f %.0f %.0f %.0f",xx1,yy1,xx2,yy2);

	}

	public static double gcd(double x ,double y ) {

	    if ( y == 0 )
	        return x;
	    else if ( x >= y && y > 0)
	        return gcd ( y , x % y );
	    else return gcd ( y , x );

	}
}


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

import static java.lang.Math.* ;
import static java.util.Arrays.* ;

public class C {

	static Long t = System.currentTimeMillis() ;
	public static void main(String[] args) throws IOException {

//		Random r = new Random() ;
//		int n = 1000 ;
//		out.println(n) ;
//		for( int i = 1 ; i < n ; i++ )
//			out.println(i + " " + (i+1)) ;
//		for( int i = 0 ; i < n ; i++ )
//			out.println(r.nextInt() + " " + r.nextInt()) ;
//

		new C().solveProblem();
		time() ;
		out.close();
	}

	static void time() {
		//out.println(System.currentTimeMillis()-t);
	}
	static Scanner in = new Scanner(new InputStreamReader(System.in));
	static BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
	static PrintStream out = new PrintStream(new BufferedOutputStream(System.out));

	int n ;

	public void solveProblem() throws IOException {

		n = Int() ;
		t = System.currentTimeMillis() ;
		bouwGraaf(n,n-1) ;

		Point[] ps = new Point[n];

		for( int i = 0 ; i < n ; i++ )
			ps[i] = new Point(Long(),Long(),i) ;
		opl = new int[n] ;

		kind = new int[n][] ;
		ak = new int[n] ;
		dfs(0,-1) ;

		int van = 0 ;
		int tot = n ;
		int pi = van ;
		Point pivot = ps[van] ;
		for( int i = van + 1 ; i < tot; i++ ){
			Point pnu = ps[i] ;
			if( pnu.y < pivot.y || (pnu.y == pivot.y && pnu.x < pivot.x)){
				pi = i ;
				pivot = ps[i] ;
			}
		}

		ps[pi] = ps[van] ;
		ps[van] = pivot ;

		losOp(ps,0,0,n) ;
		wr(opl) ;
	}

	private int dfs(int u,int p) {

		int nk = buren[u].size() ;
		if( p != -1 )
			nk-- ;
		kind[u] = new int[nk] ;

		int som = 1 ;
		int t = 0 ;
		for( int v : buren[u] )
			if( v != p ){
				kind[u][t++] = v ;
				som += dfs(v,u) ;
			}

		return ak[u] = som  ;
	}

	int[][] kind ;
	int[] ak ;
	private void losOp(Point[] ps, int u, int van, int tot) {

		Point pivot = ps[van] ;

		Point.pivot = pivot ;
		sort(ps,van+1,tot) ;

//		p((u+1),van,tot,pivot.index) ;
//		p(ps);
		opl[pivot.index] = u + 1 ;

		int t = van + 1 ;
		for( int v : kind[u]){
			losOp(ps,v,t,t+ak[v]) ;
			t += ak[v] ;
		}

	}

	int[] opl ;

	ArrayList<Integer>[] buren ;
	void bouwGraaf(int nv, int ne){

		buren = new ArrayList[nv] ;
		for( int i = 0 ; i < nv ; i++ )
			buren[i] = new ArrayList<Integer>() ;

		for( int i = 0 ; i < ne ; i++ ){
			int u = Int() - 1 ;
			int v = Int() - 1 ;
			buren[u].add(v) ;
			buren[v].add(u) ;
		}
	}

	static String Line() throws IOException{
		return buf.readLine() ;
	}

	static int bufI = 0 ;
	static int[] bufInts = new int[0] ;

	static int Int() {
		if( bufI == bufInts.length )
			bufReaderNInts() ;
		return bufInts[bufI++] ;
	}

	static int[] Int( int n ) {
		int[] res = new int[n] ;
		for( int i = 0 ; i < n ; i++ )
			res[i] = Int() ;
		return res ;
	}

	static void bufReaderNInts() {
		String[] ss;
		try {
			ss = buf.readLine().split(" ");
			bufInts = new int[ss.length] ;
			for( int i = 0 ; i < ss.length ; i++ ){
				bufInts[i] = Integer.parseInt(ss[i]) ;
			}
			bufI = 0 ;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	static int bufL = 0 ;
	static long[] bufLongs = new long[0] ;

	static long Long() {
		if( bufL == bufLongs.length )
			bufReaderNLongs() ;
		return bufLongs[bufL++] ;
	}

	static long[] Long( int n ) {
		long[] res = new long[n] ;
		for( int i = 0 ; i < n ; i++ )
			res[i] = Long() ;
		return res ;
	}

	static void bufReaderNLongs(){
		String[] ss;
		try {
			ss = buf.readLine().split(" ");
			bufLongs = new long[ss.length] ;
			for( int i = 0 ; i < ss.length ; i++ ){
				bufLongs[i] = Long.parseLong(ss[i]) ;
			}
			bufL = 0 ;
		} catch (IOException e) {

		}

	}

	static int[] toArray( ArrayList<Integer> lijst ){
		int[] res = new int[lijst.size()] ;
		int t = 0 ;
		for( int i : lijst)
			res[t++] = i;
		return res ;
	}

	static void p( Object ...p){
		System.out.println(Arrays.deepToString(p));
	}

	static void wr( int[] rij ){
		for( int i = 0 ; i < rij.length - 1 ; i++ )
			out.print(rij[i] + " ") ;
		out.println(rij[rij.length-1]);

	}

	static void wr( long[] rij ){
		for( int i = 0 ; i < rij.length - 1 ; i++ )
			out.print(rij[i] + " ") ;
		out.println(rij[rij.length-1]);

	}

}
class Point implements Comparable<Point>{

	static double EPS = 1e-11 ;

	long x ;
	long y ;
	int index ;
	static Point pivot ;
	public Point(long x, long y, int index) {
		this.x = x;
		this.y = y;
		this.index = index;
	}

	@Override
	public int compareTo(Point o) {

		long a = (x-pivot.x)*(o.y-pivot.y) - (o.x-pivot.x)*(y-pivot.y)  ;
		if( a > 0 )	return -1 ;
		else if( a == 0 ) return 0 ;
		else return 1 ;

	}

	private double pretty(double v) {
		v %= 2 * Math.PI;
		if (v < 0)
			v += 2 * Math.PI;
		return v;
	}

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


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

public class p926J {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer st;
		int times = Integer.parseInt(f.readLine());
		IntervalList list = new IntervalList();
		while(times-- > 0)
		{
			st = new StringTokenizer(f.readLine());
			int s = Integer.parseInt(st.nextToken());
			int e = Integer.parseInt(st.nextToken());
			list.add(s, e);
			out.println(list.size());
		}
		out.close();
	}

	static class IntervalList
	{
		public TreeSet<Interval> set;
		public IntervalList()
		{
			set = new TreeSet<Interval>();
		}

		public void add(int s, int e)
		{
			Iterator<Interval> iter = set.tailSet(new Interval(s, s), true).iterator();
			while(iter.hasNext())
			{
				Interval i = iter.next();
				if(i.s > e)
					break;
				if(i.s < s)
					s = i.s;
				if(i.e > e)
					e = i.e;
				iter.remove();
			}
			set.add(new Interval(s, e));
		}

		public int size()
		{
			return set.size();
		}
	}

	static class Interval implements Comparable<Interval>
	{
		int s, e;
		public Interval(int s, int e)
		{
			this.s = s;
			this.e = e;
		}

		public int compareTo(Interval i)
		{
			return e - i.e;
		}

		public String toString()
		{
			return s + " " + e;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        ExpectedEarnings solver = new ExpectedEarnings();
        solver.solve(1, in, out);
        out.close();
    }
    static class ExpectedEarnings {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt(), X = in.nextInt();
            double c = X / 1_000_000.0;
            double[] cprob = new double[n + 1];
            for (int i = 0; i <= n; i++) {
                cprob[i] = in.nextInt();
            }
            double[] dp = new double[n + 1];
            for (int nballs = n - 1; nballs >= 0; nballs--) {
                double[] next = new double[nballs + 1];
                double[] nprob = new double[nballs + 1];
                for (int red = 0; red <= nballs; red++) {
                    if (cprob[red] < 1e-10 && cprob[red + 1] < 1e-10) continue;
                    int black = nballs - red;
                    double probred = cprob[red + 1] * (red + 1) / (cprob[red + 1] * (red + 1) + cprob[red] * (black + 1));
                    nprob[red] = ((red + 1) * cprob[red + 1] + (black + 1) * cprob[red]) / (double) (nballs + 1);
                    next[red] = Math.max(0, -c + probred * (1 + dp[red + 1]) + (1 - probred) * dp[red]);
                }
                dp = next;
                cprob = nprob;
            }
            out.printf("%.10f\n", dp[0]);
        }
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;
                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }
                    if (this.numChars <= 0) {
                        return -1;
                    }
                }
                return this.buf[this.curChar++];
            }
        }
        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }
            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }
            int res = 0;
            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }
            throw new InputMismatchException();
        }
        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }
    }
    static class OutputWriter {
        private final PrintWriter writer;
        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }
        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }
        public void printf(String format, Object... objects) {
            writer.printf(format, objects);
        }
        public void close() {
            writer.close();
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class q5 {

	public static void main(String[] args) throws IOException {

		Reader.init(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int x=Reader.nextInt(),y=Reader.nextInt(),z=Reader.nextInt();
		int x1=Reader.nextInt(),y1=Reader.nextInt(),z1=Reader.nextInt();
		int v1=Reader.nextInt(),v2=Reader.nextInt(),v3=Reader.nextInt();
		int v4=Reader.nextInt(),v5=Reader.nextInt(),v6=Reader.nextInt();
		long ans=0;
		if(y<0) ans+=v1;
		else if(y>y1) ans+=v2;
		if(z<0) ans+=v3;
		else if(z>z1) ans+=v4;
		if(x<0) ans+=v5;
		else if(x>x1) ans+=v6;
		out.print(ans);
		out.flush();
	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init() throws IOException {
    	 reader = new BufferedReader(
                 new FileReader("input.txt"));
    tokenizer = new StringTokenizer("");
    }
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


import java.util.Scanner;

public class Main {
 public static void main(String[] args){
  Scanner in = new Scanner(System.in);
  long b, c=0, i;
   b = in.nextLong();

    for (i = 1; i * i <= b; i++) {
       if (b % i == 0) {
      	 c += 2;
       }
       if (i * i == b) {
      	 c--;
       }
    }

    System.out.println(c);
 }
}


import java.util.Arrays;
import java.util.Scanner;

public class C {

    long mod = 1000000007;
    long memo[] = new long[101];
    long memoNot[] = new long[101];
    int n;
    int k;
    int d;

    long go(int curr, boolean contains, String space) {
        //System.out.println(space + curr + " " + contains);
        if (curr < 0) return 0;
        if (curr == 0 && contains) return 1;
        if (curr == 0 && !contains) return 0;
        if (memo[curr] > -1 && contains)
            return memo[curr];
        if (memoNot[curr] > -1 && !contains)
            return memoNot[curr];

        long ans = 0;
        for (int i = 1; curr - i >= 0 && i <= k; i++) {
            ans += go(curr - i, ((i >= d) ? true : contains), space + " ");
        }

        ans = ans % mod;
        if (contains)
            memo[curr] = ans;
        else
            memoNot[curr] = ans;
        return ans;

    }

    public void solve() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        d = sc.nextInt();

        Arrays.fill(memo, -1);
        Arrays.fill(memoNot, -1);

        System.out.println(go(n, false, "") % mod);
    }

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

}


import java.util.Scanner;

public class Main {

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

      Scanner scanner=new Scanner(System.in);
      long n=scanner.nextLong();
      long m=scanner.nextLong();
      long  build=scanner.nextLong();
      long dem=scanner.nextLong();
      long rem=n%m;
      long  a=rem*dem;
      long  b=(m-rem)*build;
      if (a>b)
      {
          System.out.println(b);
      }
      else
      {
          System.out.println(a);
      }

    }
}


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

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

    static class SwapPrefixesDp {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.next(), t = in.next();
            List<Integer> ans1 = solve("a" + s, "b" + t);
            List<Integer> ans2 = solve("b" + s, "a" + t);
            if (ans1.size() > ans2.size()) {
                ans1 = ans2;
            }
            out.println(ans1.size() / 2);
            for (int i = 0; i < ans1.size(); i += 2) {
                out.println(ans1.get(i) + " " + ans1.get(i + 1));
            }
        }

        private void makeSwap(List<Integer> realAns, List<Pair> compressedS, List<Pair> compressedT, int lenS, int lenT) {
            List<Pair> newS = new ArrayList<>();
            List<Pair> newT = new ArrayList<>();

            int realLenS = 0, realLenT = 0;
            for (int i = 0; i < lenS; i++) {
                realLenS += compressedS.get(i).count;
            }
            for (int i = 0; i < lenT; i++) {
                realLenT += compressedT.get(i).count;
            }
            realAns.add(realLenS - 1);
            realAns.add(realLenT - 1);
            concatLists(compressedS, compressedT, lenS, lenT, newS);
            concatLists(compressedT, compressedS, lenT, lenS, newT);
            compressedS.clear();
            compressedS.addAll(newS);
            compressedT.clear();
            compressedT.addAll(newT);
        }

        private void concatLists(List<Pair> compressedS, List<Pair> compressedT, int lenS, int lenT, List<Pair> newS) {
            newS.addAll(compressedT.subList(0, lenT));
            newS.addAll(compressedS.subList(lenS, compressedS.size()));
            if (lenT < newS.size() && newS.get(lenT - 1).ch == newS.get(lenT).ch) {
                newS.get(lenT - 1).count += newS.get(lenT).count;
                newS.remove(lenT);
            }
        }

        private List<Integer> solve(String s, String t) {
            List<Pair> compressedS = compress(s);
            List<Pair> compressedT = compress(t);
            if (compressedS.size() == 1 && compressedT.size() == 1) {
                return new ArrayList<>();
            }
            int curI = compressedS.size(), curJ = compressedT.size();

            int bestI = -1, bestJ = -1;
            int bestCost = Integer.MAX_VALUE;

            for (int lenI = 1; lenI <= compressedS.size(); lenI++) {
                for (int lenJ = 1; lenJ <= compressedT.size(); lenJ++) {
                    if (lenI % 2 != lenJ % 2) {
                        continue;
                    }
                    if (lenI > 3 && lenJ > 3) {
                        break;
                    }
                    int nextI = lenJ + (curI - lenI) - ((curI != lenI && lenJ % 2 == lenI % 2) ? 1 : 0);
                    int nextJ = lenI + (curJ - lenJ) - ((curJ != lenJ && lenJ % 2 == lenI % 2) ? 1 : 0);

                    int cost = 1 + Math.max(nextI, nextJ);
                    if (cost < bestCost) {
                        bestCost = cost;
                        bestI = lenI;
                        bestJ = lenJ;
                    }
                }
            }

            List<Integer> ans = new ArrayList<>();
            makeSwap(ans, compressedS, compressedT, bestI, bestJ);

            int nextI = compressedS.size(), nextJ = compressedT.size();

            int prefixA = 0, prefixB = 0;
            for (int i = 0; i < Math.max(nextI, nextJ) - 1; i++) {
                if (i % 2 == 0) {
                    prefixA += i >= compressedS.size() ? 0 : compressedS.get(i).count;
                    prefixB += i >= compressedT.size() ? 0 : compressedT.get(i).count;
                    ans.add(prefixA - 1);
                    ans.add(prefixB - 1);
                } else {
                    prefixA += i >= compressedT.size() ? 0 : compressedT.get(i).count;
                    prefixB += i >= compressedS.size() ? 0 : compressedS.get(i).count;
                    ans.add(prefixB - 1);
                    ans.add(prefixA - 1);
                }
            }

            return ans;
        }

        private List<Pair> compress(String s) {
            List<Pair> result = new ArrayList<>();
            for (int i = 0; i < s.length(); ) {
                int j = i;
                while (j < s.length() && s.charAt(i) == s.charAt(j)) {
                    j++;
                }
                result.add(new Pair(s.charAt(i), j - i));
                i = j;
//                System.err.println(result);
            }
            return result;
        }

        class Pair {
            char ch;
            int count;

            public Pair(char ch, int count) {
                this.ch = ch;
                this.count = count;
            }

            @Override
            public String toString() {
                return "Pair{" +
                        "ch=" + ch +
                        ", count=" + count +
                        '}';
            }
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

    }
}


//package codeforces.R462;

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

public class D
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		long p = sc.nextLong();
		int k = sc.nextInt();
		long[] arr = new long[1000];
		boolean neg = true;
		long cur = p;
		for (int i = 0; i < 100; i++)
		{
			if(cur == 0)
				break;
			long res = 0;
			if(neg)
				res = cur/k;
			else
				res = (cur+k-1)/k;
			arr[i] = res;
			cur = arr[i];
			neg = neg?false:true;
		}

		BigInteger[] ans = new BigInteger[100];
		for (int i = 0; i < ans.length; i++)
		{
			BigInteger v1 = BigInteger.valueOf(arr[i]);
			v1 = v1.multiply(BigInteger.valueOf(k));
			BigInteger v2 = BigInteger.ZERO;
			if(i > 0)
				v2 = v2.add(BigInteger.valueOf(arr[i-1]));

			if(i%2 == 0)
				v1 = v1.multiply(BigInteger.valueOf(-1));
			if(i > 0 && (i-1)%2 == 0)
				v2 = v2.multiply(BigInteger.valueOf(-1));
			v1 = v1.add(v2);
			ans[i] = v1;
		}

		ans[0] = ans[0].add(BigInteger.valueOf(p));

		int lst = 0;
		boolean ok = true;
		for (int i = 0; i < 100; i++)
		{
			if(!ans[i].equals(new BigInteger("0")))
				lst = i;
			if(ans[i].compareTo(BigInteger.valueOf(k)) != -1)
				ok = false;
		}

		if(!ok)
			System.out.println(-1);
		else
		{
			pw.println(lst+1);
			for (int i = 0; i <= lst; i++)
			{
				pw.print(ans[i] + " ");
			}
			pw.println();

		}

		pw.flush();
		pw.close();
	}

	static int[][] packD(int n, int[] from, int[] to) {
		int[][] g = new int[n][];
		int[] p = new int[n];
		for (int f : from) p[f]++;
		for (int i = 0; i < n; i++) g[i] = new int[p[i]];
		for (int i = 0; i < from.length; i++) {g[from[i]][--p[from[i]]] = to[i];}
		return g;
	}
	static class Scanner
	{
		StringTokenizer st; BufferedReader br;
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		public String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public long nextLong() throws IOException {return Long.parseLong(next());}
		public String nextLine() throws IOException {return br.readLine();}
		public boolean ready() throws IOException {return br.ready();}
	}
}


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

public class Solution {

    static long maxCnt = 0, maxX = 0;

    static void calc(long m, long cnt, long x) {
        if (m <= 7) {
            cnt += m;
            x += m;

            if (cnt > maxCnt || (cnt == maxCnt && x > maxX)) {
                maxCnt = cnt;
                maxX = x;
            }
            return;
        }

        long a = (long) Math.floor(Math.pow(m, 1.0 / 3));
        calc(m - (long) Math.pow(a, 3), cnt + 1, x + (long) Math.pow(a, 3));
        calc((long) Math.pow(a, 3) - 1 - (long) Math.pow(a - 1, 3), cnt + 1, x + (long) Math.pow(a - 1, 3));
    }

    static void solve(InputReader in, OutputWriter out) {
        long m = in.nextLong();
        calc(m, 0, 0);
        out.print(maxCnt + " " + maxX);
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        solve(in, out);
        in.close();
        out.close();
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        InputReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

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

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

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

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

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

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    static class OutputWriter {
        BufferedWriter bw;

        OutputWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        void print(int i) {
            print(Integer.toString(i));
        }

        void println(int i) {
            println(Integer.toString(i));
        }

        void print(long l) {
            print(Long.toString(l));
        }

        void println(long l) {
            println(Long.toString(l));
        }

        void print(double d) {
            print(Double.toString(d));
        }

        void println(double d) {
            println(Double.toString(d));
        }

        void print(boolean b) {
            print(Boolean.toString(b));
        }

        void println(boolean b) {
            println(Boolean.toString(b));
        }

        void print(char c) {
            try {
                bw.write(c);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(char c) {
            println(Character.toString(c));
        }

        void print(String s) {
            try {
                bw.write(s);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(String s) {
            print(s);
            print('\n');
        }

        void close() {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


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

public class Main

{
    class Pair<S extends Comparable<S>, T extends Comparable<T>> implements Comparable<Pair<S, T>>
    {
        S first;
        T second;

        Pair(S f, T s)
        {
            first = f;
            second = s;
        }

        @Override
        public int compareTo(Pair<S, T> o)
        {
            int t = first.compareTo(o.first);
            if (t == 0) return second.compareTo(o.second);
            return t;
        }

        @Override
        public int hashCode()
        {
            return (31 + first.hashCode()) * 31 + second.hashCode();
        }

        @Override
        public boolean equals(Object o)
        {
            if (!(o instanceof Pair)) return false;
            if (o == this) return true;
            Pair p = (Pair) o;
            return first.equals(p.first) && second.equals(p.second);
        }

        @Override
        public String toString()
        {
            return "Pair{" + first + ", " + second + "}";
        }
    }
    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;
        }
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        try
        {
            System.setIn(new FileInputStream("input.txt"));
            System.setOut(new PrintStream(new FileOutputStream("output.txt")));
        }
        catch (Exception e)
        {
            System.err.println("Error");
        }

        FastReader sc = new FastReader();

        int t = sc.nextInt();
        PrintWriter out = new PrintWriter(System.out);
        while(t-- > 0)
        {
            solve(sc, out);
        }
        out.close();
    }
    static void solve(FastReader sc, PrintWriter out)
    {
        long n = sc.nextLong();
        long k = sc.nextInt();

        out.println(binpow(n,k));

    }
    static long binpow(long a, long b)
    {
        long m = 1000000007;
        long res = 1;
        while (b > 0)
        {
            if (b %2== 1)
                res = res * a % m;
            a = a * a % m;
            b >>= 1;
        }
        return res % m;
    }
}