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

/**
 * Copyright © 2018 Chris. All rights reserved.
 *
 * @author Chris
 * 2018/7/9 15:33
 * @see format
 */
public class C {

    private static BufferedReader br;
    private static StreamTokenizer st;
    private static PrintWriter pw;

    static final int INF = 1000000007;
    static final int MOD = 1000000007;

    private static void solve() throws IOException {
        long la = nextInt();
        long ra = nextInt();
        long ta = nextInt();
        long lb = nextInt();
        long rb = nextInt();
        long tb = nextInt();
        if (ra > rb) {
            ra ^= rb;
            rb ^= ra;
            ra ^= rb;

            la ^= lb;
            lb ^= la;
            la ^= lb;
        }
        long ans = 0;
        if (ta % tb == 0 || tb % ta == 0) {
            long k = (rb - ra) / ta;
            ra += k * ta;
            la += k * ta;
            ans = Math.max(ans, ra - Math.max(la, lb) + 1);
            ra += ta;
            la += ta;
            if (la <= rb) {
                ans = Math.max(ans, rb - Math.max(lb, la) + 1);
            }
        } else {
            long g = gcd(ta, tb);
            if (g == 1) {
                ans = Math.min(ra - la, rb - lb) + 1;
            } else {
                ta = g;
                long k = (rb - ra) / ta;
                ra += k * ta;
                la += k * ta;
                ans = Math.max(ans, ra - Math.max(la, lb) + 1);
                ra += ta;
                la += ta;
                if (la <= rb) {
                    ans = Math.max(ans, rb - Math.max(lb, la) + 1);
                }
            }
        }
        pw.print(ans);
    }

    static void getDiv(Map<Integer, Integer> map, int n) {
        int sqrt = (int) Math.sqrt(n);
        for (int i = sqrt; i >= 2; i--) {
            if (n % i == 0) {
                getDiv(map, i);
                getDiv(map, n / i);
                return;
            }
        }
        map.put(n, map.getOrDefault(n, 0) + 1);
    }

    public static boolean[] generatePrime(int n) {
        boolean p[] = new boolean[n + 1];
        p[2] = true;

        for (int i = 3; i <= n; i += 2) {
            p[i] = true;
        }

        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            if (!p[i]) {
                continue;
            }
            for (int j = i * i; j <= n; j += i << 1) {
                p[j] = false;
            }
        }
        return p;
    }

    // 18位素数：154590409516822759
    // 19位素数：2305843009213693951 (梅森素数)
    // 19位素数：4384957924686954497
    static boolean isPrime(long n) { //determines if n is a prime number
        int p[] = {2, 3, 5, 233, 331};
        int pn = p.length;
        long s = 0, t = n - 1;//n - 1 = 2^s * t
        while ((t & 1) == 0) {
            t >>= 1;
            ++s;
        }
        for (int i = 0; i < pn; ++i) {
            if (n == p[i]) {
                return true;
            }
            long pt = pow(p[i], t, n);
            for (int j = 0; j < s; ++j) {
                long cur = llMod(pt, pt, n);
                if (cur == 1 && pt != 1 && pt != n - 1) {
                    return false;
                }
                pt = cur;
            }
            if (pt != 1) {
                return false;
            }
        }
        return true;
    }

    static long llMod(long a, long b, long mod) {
        return (a * b - (long) ((double) a / mod * b + 0.5) * mod + mod) % mod;
//        long r = 0;
//        a %= mod;
//        b %= mod;
//        while (b > 0) {
//            if ((b & 1) == 1) {
//                r = (r + a) % mod;
//            }
//            b >>= 1;
//            a = (a << 1) % mod;
//        }
//        return r;
    }

    static int pow(long a, long n) {
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans = (ans * a) % MOD;
            }
            a = (a * a) % MOD;
            n >>= 1;
        }
        return (int) ans;
    }

    static int pow(long a, long n, long mod) {
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans = llMod(ans, a, mod);
            }
            a = llMod(a, a, mod);
            n >>= 1;
        }
        return (int) ans;
    }

    private static long[][] initC(int n) {
        long c[][] = new long[n][n];

        for (int i = 0; i < n; i++) {
            c[i][0] = 1;
        }

        for (int i = 1; i < n; i++) {
            for (int j = 1; j <= i; j++) {
                c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
            }
        }
        return c;
    }

    /**
     * ps: n >= m, choose m from n;
     */
    private static int c(long n, long m) {
        if (m > n) {
            n ^= m;
            m ^= n;
            n ^= m;
        }
        m = Math.min(m, n - m);

        long top = 1;
        long bot = 1;
        for (long i = n - m + 1; i <= n; i++) {
            top = (top * i) % MOD;
        }
        for (int i = 1; i <= m; i++) {
            bot = (bot * i) % MOD;
        }

        return (int) ((top * pow(bot, MOD - 2)) % MOD);
    }

    static long gcd(long a, long b) {
        if (a < b) {
            a ^= b;
            b ^= a;
            a ^= b;
        }
        while (b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    static boolean even(long n) {
        return (n & 1) == 0;
    }

    public static void main(String args[]) throws IOException {
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        if (!oj) {
            System.setIn(new FileInputStream("in.txt"));
//            System.setOut(new PrintStream("out.txt"));
        }
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StreamTokenizer(br);
        pw = new PrintWriter(new OutputStreamWriter(System.out));
        st.ordinaryChar('\''); //指定单引号、双引号和注释符号是普通字符
        st.ordinaryChar('\"');
        st.ordinaryChar('/');

        long t = System.currentTimeMillis();
        solve();
        if (!oj) {
            pw.println("[" + (System.currentTimeMillis() - t) + "ms]");
        }
        pw.flush();
    }

    private static long[] anLong(int n) throws IOException {
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    private static String next(int len) throws IOException {
        st.nextToken();
        return st.sval;
    }

    private static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }

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

    private static double nextDouble() throws IOException {
        st.nextToken();
        return st.nval;
    }

    private static String[] nextSS(String reg) throws IOException {
        return br.readLine().split(reg);
    }

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


import java.io.*;

public final class solution
{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int b = Integer.parseInt(br.readLine().trim());
    int g = Integer.parseInt(br.readLine().trim());
    int n = Integer.parseInt(br.readLine().trim());
    int num = 0;
    for(int i = 0;i<=n;i++)
    {
        if(i<=b && n-i<=g){num++;}
    }
    System.out.println(num);
}


import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by slycer on 9/24/2016.
 * http://acm.tju.edu.cn/toj/showp1992.html
 */
public class Main {

    static long MOD = 1000000007;
    public static void main ( String [] args ) throws IOException {
        Scanner s = new Scanner ( System.in );
        int n, a, b, k;
        n = s.nextInt();
        a = s.nextInt();
        b = s.nextInt();
        k = s.nextInt();

        int delta = Math.abs( b - a );

        long [][] dp = new long [ k+1 ][ n + 2 ];
        long [][] sum = new long[ k+1 ][ n + 2 ];

        dp[0][a] = 1;
        fillPartialSum( 0, dp, sum );
        for ( int i=1; i<=k; i++ ){
            for ( int j=1; j<=n; j++ ){
                if ( j != b ){

                    if ( j < b ){
                        int m = ( j + b - 1 )/2;
                        dp[i][j] = sum( i-1, 1, m, sum ) - dp[i-1][j];
                    }
                    if ( b < j ){
                        int m = ( j + b + 2 )/2;
                        dp[i][j] = sum( i-1, m, n, sum ) - dp[i-1][j];
                    }
                }
            }
            fillPartialSum( i, dp, sum );
        }

        System.out.println( sum( k, 1, n, sum ) );
    }

    public static long sum( int row, int start, int end, long [][] sum ){
        return ( sum[row][end] - sum[row][start-1] + MOD ) % MOD;
    }
    public static void fillPartialSum( int row, long [][] dp, long [][] sum ){
        for ( int i=1; i<sum[row].length; i++ ){
            sum[row][i] = sum[row][i-1] + dp[row][i];
            sum[row][i] = sum[row][i] % MOD;
        }
    }
}


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

public class MainClass
{
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int k = in.nextInt();
        long M = (long)1e9 + 7;
        if (b < a)
        {
            b = n - b + 1;
            a = n - a + 1;
        }
        long[][] dp = new long[n + 1][k + 2];
        long[][] sum = new long[n + 1][k + 2];
        for (int i=1;i<=n;i++)
        {
            if (i < b)
                dp[i][1] = 1L;
            sum[i][1] = (sum[i - 1][1] + dp[i][1]) % M;
        }
        for (int i=2;i<=k + 1;i++)
        {
            for (int j=1;j<=n;j++)
            {
                int ll = Math.min(2 * j - 1, b - 1);
                dp[j][i] = (sum[ll][i - 1] - dp[j][i - 1] + M) % M;
                sum[j][i] = (sum[j - 1][i] + dp[j][i]) % M;
            }
        }
        System.out.println(dp[b - a][k + 1]);
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * 4 4
 * 1 5 3 4
 * 1 2
 * 1 3
 * 2 3
 * 3 3
 *
 *
 * @author pttrung
 */
public class A {

    public static long Mod = (long) (1e9 + 7);

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

        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int a = in.nextInt() - 1;
        int b = in.nextInt() - 1;
        int k = in.nextInt();
        long[][] dp = new long[k + 1][n];
        Arrays.fill(dp[0], 1);
        dp[0][b] = 0;
        for (int i = 1; i <= k; i++) {
            long[] tmp = new long[n];
            for (int j = 0; j < n; j++) {
                tmp[j] = dp[i - 1][j];
                if (j > 0) {
                    tmp[j] += tmp[j - 1];
                    tmp[j] %= Mod;
                }
            }
            for (int j = 0; j < n; j++) {
                if (j != b) {
                    int dist = Math.abs(j - b);
                    int start = Math.max(0, j - dist + 1);
                    int end = Math.min(n - 1, j + dist - 1);
                    long v = tmp[end] - (start > 0 ? tmp[start - 1] : 0);
                    v += Mod;
                    v %= Mod;
                    v -= dp[i - 1][j];

                    v += Mod;
                    v %= Mod;
                    dp[i][j] = v;
                    //System.out.println(i + " " + j + " " + v + " " + start + " " + end);
                }
            }
        }
        out.println(dp[k][a]);
        out.close();
    }

    public static long pow(int a, int b, long mod) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long v = pow(a, b / 2, mod);
        if (b % 2 == 0) {
            return (v * v) % mod;
        } else {
            return (((v * v) % mod) * a) % mod;
        }
    }

    public static int[][] powSquareMatrix(int[][] A, long p) {
        int[][] unit = new int[A.length][A.length];
        for (int i = 0; i < unit.length; i++) {
            unit[i][i] = 1;
        }
        if (p == 0) {
            return unit;
        }
        int[][] val = powSquareMatrix(A, p / 2);
        if (p % 2 == 0) {
            return mulMatrix(val, val);
        } else {
            return mulMatrix(A, mulMatrix(val, val));
        }

    }

    public static int[][] mulMatrix(int[][] A, int[][] B) {
        int[][] result = new int[A.length][B[0].length];
        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < result[0].length; j++) {
                long temp = 0;
                for (int k = 0; k < A[0].length; k++) {

                    temp += ((long) A[i][k] * B[k][j] % Mod);
                    temp %= Mod;
                }
                temp %= Mod;
                result[i][j] = (int) temp;
            }
        }

        return result;
    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;

    }

    static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        void update(int index, int val) {
            // System.out.println("UPDATE INDEX " + index);
            while (index < data.length) {
                data[index] += val;
                index += index & (-index);

                //    System.out.println("NEXT " +index);
            }
        }

        int get(int index) {
            //  System.out.println("GET INDEX " + index);
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= index & (-index);
                // System.out.println("BACK " + index);
            }
            return result;
        }
    }

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

    static long pow(long a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {

            return val * val % Mod;
        } else {
            return (val * val % Mod) * a % Mod;
        }
    }

//    static Point intersect(Point a, Point b, Point c) {
//        double D = cross(a, b);
//        if (D != 0) {
//            return new Point(cross(c, b) / D, cross(a, c) / D);
//        }
//        return null;
//    }
//
//    static Point convert(Point a, double angle) {
//        double x = a.x * cos(angle) - a.y * sin(angle);
//        double y = a.x * sin(angle) + a.y * cos(angle);
//        return new Point(x, y);
//    }
    static Point minus(Point a, Point b) {
        return new Point(a.x - b.x, a.y - b.y);
    }
//
//    static Point add(Point a, Point b) {
//        return new Point(a.x + b.x, a.y + b.y);
//    }
//

    /**
     * Cross product ab*ac
     *
     * @param a
     * @param b
     * @param c
     * @return
     */
    static double cross(Point a, Point b, Point c) {
        Point ab = new Point(b.x - a.x, b.y - a.y);
        Point ac = new Point(c.x - a.x, c.y - a.y);
        return cross(ab, ac);
    }

    static double cross(Point a, Point b) {
        return a.x * b.y - a.y * b.x;
    }

    /**
     * Dot product ab*ac;
     *
     * @param a
     * @param b
     * @param c
     * @return
     */
    static long dot(Point a, Point b, Point c) {
        Point ab = new Point(b.x - a.x, b.y - a.y);
        Point ac = new Point(c.x - a.x, c.y - a.y);
        return dot(ab, ac);
    }

    static long dot(Point a, Point b) {
        long total = a.x * b.x;
        total += a.y * b.y;
        return total;
    }

    static double dist(Point a, Point b) {
        long total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
        return Math.sqrt(total);
    }

    static long norm(Point a) {
        long result = a.x * a.x;
        result += a.y * a.y;
        return result;
    }

    static double dist(Point a, Point b, Point x, boolean isSegment) {
        double dist = cross(a, b, x) / dist(a, b);
        // System.out.println("DIST " + dist);

        if (isSegment) {
            Point ab = new Point(b.x - a.x, b.y - a.y);

            long dot1 = dot(a, b, x);
            long norm = norm(ab);
            double u = (double) dot1 / norm;
            if (u < 0) {
                return dist(a, x);
            }

            if (u > 1) {
                return dist(b, x);
            }
        }
        return Math.abs(dist);

    }

    static class Point {

        int x, y;

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

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //br = new BufferedReader(new FileReader(new File("A-large (2).in")));
        }

        public String next() {

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

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


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

public class main479E {
    public static PrintWriter out = new PrintWriter(System.out);
    public static FastScanner enter = new FastScanner(System.in);

    public static void main(String[] args) throws IOException {
        solve();
        out.close();
    }
    static long mod=(long)1e9+7;
    static long dp[][];
    static long summ[][];
    private static void solve() throws IOException {
        int n=enter.nextInt();
        int a=enter.nextInt();
        int b=enter.nextInt();
        int k=enter.nextInt();
        dp=new long[n+1][k+1];
        summ=new long[n+1][k+1];
        for (int i = 1; i <b ; i++) {
            dp[i][0]=1;
        }
        for (int i = b+1; i <n+1 ; i++) {
            dp[i][0]=1;
        }
        for (int j = 1; j <=n ; j++) {
            summ[j][0]+=summ[j-1][0]+dp[j][0];
        }
        for (int i = 1; i <=k ; i++) {
            for (int j = b+1; j <=n ; j++) {
                dp[j][i]=(summ[Math.min(2*j-b-1,n)][i-1]-summ[b][i-1]-dp[j][i-1])%mod;
            }
            for(int j=1;j<b;j++){
                dp[j][i]=(summ[b-1][i-1]-summ[Math.max(0,j-(b-j))][i-1]-dp[j][i-1])%mod;
            }
            for (int j = 1; j <=n ; j++) {
                summ[j][i]+=summ[j-1][i]+dp[j][i];
                summ[j][i]%=mod;
            }
        }
        out.println((dp[a][k]%mod+mod)%mod);
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer stok;

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

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

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

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

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

        char nextChar() throws IOException {
            return (char) (br.read());
        }

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


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

public class D {
    public static void main (String[] args) {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        int a = fs.nextInt(), b = fs.nextInt();
        int k = fs.nextInt();
        int MOD = (int)1e9+7;

        int[][] dp = new int[k+1][n+2];
        int[][] add = new int[k+1][n+2];
        int[][] sub = new int[k+1][n+2];
        dp[0][a] = 1;

        for(int kk = 0; kk < k; kk++) {
            int ssum = 0;

            for(int i = 1; i <= n; i++) {
                ssum = add(ssum, add[kk][i], MOD);
                ssum = add(ssum, -sub[kk][i], MOD);

                dp[kk][i] = add(dp[kk][i], ssum, MOD);

                if(dp[kk][i] == 0) continue;

                int dist = Math.abs(i-b) - 1;
                if(dist == 0) continue;

                int goLeft = Math.max(1, i - dist);
                int goRight = Math.min(n+1, i + dist + 1);

                add[kk+1][goLeft] = add(add[kk+1][goLeft], dp[kk][i], MOD);
                sub[kk+1][i] = add(sub[kk+1][i], dp[kk][i], MOD);

                add[kk+1][i+1] = add(add[kk+1][i+1], dp[kk][i], MOD);
                sub[kk+1][goRight] = add(sub[kk+1][goRight], dp[kk][i], MOD);

            }
        }

        int ssum = 0, res = 0;

        for(int i = 1; i <= n; i++) {
            ssum = add(ssum, add[k][i], MOD);
            ssum = add(ssum, -sub[k][i], MOD);

            res = add(res, ssum, MOD);
        }

        out.println(res%MOD);

        out.close();
    }

    static int add (int a, int b, int MOD) {
        int res = a + b;
        while (res > MOD) res -= MOD;
        while (res < 0) res += MOD;
        return res;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try	{
                br = new BufferedReader(new InputStreamReader(System.in));
//                br = new BufferedReader(new FileReader("testdata.out"));
                st = new StringTokenizer("");
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens())	return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

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

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

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

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }

}


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

public class E274
{

    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int a=s.nextInt();
        int b=s.nextInt();
        int k=s.nextInt();
        long dp[][]=new long[k+1][n+1];
        long p[][]=new long[2][n+1];

        int mod=1000000007;
        for(int i=1;i<b;i++)
        {

            dp[1][i]=(Math.abs(i-b)-1+Math.min(Math.abs(i)-1, Math.abs(i-b)-1))%mod;
            p[0][i]=(p[0][i-1]+dp[1][i])%mod;
            //System.out.println(i+" "+dp[i][1]+" "+Math.abs(i-b-1)+" "+Math.min(Math.abs(i-1), Math.abs(i-b-1)));
            //System.out.println(Arrays.toString(dp[i]));
        }
        for(int i=b+1;i<=n;i++)
        {
            dp[1][i]=(Math.abs(i-b)-1+Math.max(Math.min(Math.abs(n-i), Math.abs(i-b)-1),0))%mod;
            p[0][i]=(p[0][i-1]+dp[1][i])%mod;
            //System.out.println(i+" "+dp[i][1]+" "+(Math.abs(i-b)-1)+" "+Math.min(Math.min(Math.abs(n-i)-1, Math.abs(i-b)-1),0));
            //System.out.println(Arrays.toString(dp[i]));
        }
    //  System.out.println(Arrays.toString(dp[1])+" \n"+Arrays.toString(p[1]));
        //System.out.println("------------------------------------");
        if(a<b)
        {
        for(int j=2;j<=k;j++)
        {
            for(int i=1;i<b;i++)
            {
                long tmp=0;

                tmp=p[0][b-1]-p[0][Math.max(i-Math.abs(b-i),0)];

                tmp-=dp[j-1][i];
                //System.out.println("trip:" +j+"pos"+i+" sum"+tmp+" start"+Math.max(i-Math.abs(b-i),0)+" end "+b+" sub"+dp[j-1][i]);
                dp[j][i]=((tmp+mod)%mod);
                p[1][i]=(p[1][i-1]+dp[j][i])%(long)mod;
            }
            p[0]=Arrays.copyOf(p[1],p[1].length);
            Arrays.fill(p[1],0l);
            //System.out.println(Arrays.toString(dp[j])+"\n"+Arrays.toString(p[j]));
        }
        }
        else
            if(a>b)
        {
            for(int j=2;j<=k;j++)
            {

                for(int i=b+1;i<=n;i++)
                {

                long tmp=0;
                tmp+=p[0][Math.min(i+(i-b)-1,n)];
                //tmp+=p[j-1][Math.max(Math.min(Math.abs(n-i)-1, Math.abs(i-b)-1),0)];
                tmp-=dp[j-1][i];

                dp[j][i]=((tmp+mod)%mod);

                p[1][i]=(p[1][i-1]+dp[j][i])%mod;
            }
                p[0]=Arrays.copyOf(p[1],p[1].length);
                Arrays.fill(p[1],0l);
            //System.out.println(Arrays.toString(dp[j]));
        }
        }

        System.out.println(dp[k][a]%(mod));
    }
}


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

public class RidingInALift
{

	public static void main(String[] args)
	{
		FastReader sc = new FastReader();

		int n = sc.nextInt();
		int a = sc.nextInt()-1;
		int b = sc.nextInt()-1;
		int k = sc.nextInt();

		int range;

		int st = a;
		int lab = b;

		if(a < b)
		{
			range = b+1;
		}
		else
		{
			range = n - (b+1) + 1;
//			System.out.println("Range " + range);
			lab = range-1;
			st -= b;

			st = range-1 - st;
		}
//		System.out.println(st + " " + lab + " " + range);

		long MOD = 1000000007;
		long[][] dp = new long[range][k+1];
		//room, trips left

		for(int i = 0; i < lab; i++)
		{
			dp[i][0] = 1;
		}

		long[][] sum = new long[range][k+1];

//		System.out.println("Rooms " + (lab) + ", start " + st);
		for(int t = 1; t <= k; t++)
		{
			long cursum = 0;
			for(int i = lab-1; i >= 0; i--)
			{
//				System.out.println("Referring " + i +" " + (t-1));
				cursum = (cursum + dp[i][t-1])%MOD;

				sum[i][t-1] = cursum;
			}

			for(int i = lab-1; i >= 0; i--)
			{
				int fromright = lab - i - 1;

				int sumleftfromright = Math.min(lab-1, fromright*2);
				int sumleft = lab - 1 - sumleftfromright;

				dp[i][t] = (sum[sumleft][t-1] - dp[i][t-1])%MOD;
//				System.out.println("dp[" + i + "][" + t + "] = " + dp[i][t]);
			}
		}
		if(dp[st][k] < 0)dp[st][k] += MOD;

		System.out.println(dp[st][k]);
	}

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


import java.util.*;
import java.io.*;
public class codeforces {
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
        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();
        }
    }
    public static void main(String[] args) throws IOException {
        Scanner sc  =new Scanner(System.in);PrintWriter pw=new PrintWriter(System.out);
        long n=sc.nextLong();long k=sc.nextLong();long m = sc.nextLong();long d=sc.nextLong();long c = (long) Math.ceil((double) n/(k*d));
        long ans= -1;
        //System.out.println((double) n/(k*d));
        for (long i=c;i<=m;i++){
            long sum=(n/(k*i));
            if (n%(k*i)!=0)sum++;
            ans=Math.max(ans,sum*i);
        }
        System.out.print(ans);
    }
}


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

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long k = in.nextLong();
            long M = in.nextLong();
            long D = in.nextLong();
            long maxAns = 0;
            for (long curD = D; curD > 0; curD--) {
                long xMin = n / (curD * k) + (n % (curD * k) > 0 ? 1 : 0);
                long xMax = Math.min(n / ((curD - 1) * k + 1) + (n % ((curD - 1) * k + 1) > 0 ? 1 : 0), M);
                for (long x = xMin; x <= xMax; x++) {
                    maxAns = Math.max(maxAns, em(x, n, k));
                }
            }
            out.println(maxAns);
        }

        long em(long x, long n, long k) {
            long res = (n / (x * k)) * x;
            if (n % (x * k) >= x) res += x;
            return res;
        }

    }

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

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

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

    }
}


import java.util.*;
public class next
{
    public static void main(String args[])
    throws Exception
    {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int m=scan.nextInt();
        int num=0;
        for(int i=n+1;;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    num=num+1;
                }
            }
            if(num==2)
            {
                if(i==m)
                {
                    System.out.print("YES");
                    break;
                    }
                    else
                    {
                        System.out.print("NO");
                        break;
                        }
            }

        }
    }
}


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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();// 人数
        int m = scan.nextInt();// 信息量
        boolean boss[] = new boolean[n + 1];// 是否是leader
        boolean find[] = new boolean[n + 1];// 消息中出现的人中的leader
        Arrays.fill(boss, true);
        int home = 0;// 房间人数
        boolean in[] = new boolean[n + 1];// 是否在房间中
        int leader = 0;// 当前leader
        int sum = 0;// leader人数;
        for (int i = 1; i <= m; i++) {
            String s = scan.next();
            int x = scan.nextInt();
            boss[x] = false;
            if (s.equals("+")) {
                if (home == 0&&x!=leader) {
                    leader = x;
                    sum++;
                }
                home++;
                in[x] = true;
            } else if (s.equals("-")) {
                if (in[x] == false) {
                    sum = 0;
                    if (home == 0&&x!=leader) {
                        leader = x;
                        sum++;
                    }
                    // System.out.println(sum+"　"+home);
                } else if (in[x] == true) {
                    if (home == 0&&x!=leader) {
                        leader = x;
                        sum++;
                        in[x] = false;
                    }
                    home--;
                }
            }
//          System.out.println(home+" "+leader+" "+sum);
        }
//      System.out.println(leader);
//       System.out.println(sum);
        if (sum == 1) {
            boss[leader] = true;
        }
        int count = 0;
        for (int i = 1; i <= n; i++) {
            if (boss[i])
                count++;
        }
        System.out.println(count);
        for (int i = 1; i <= n; i++) {
            if (boss[i])
                System.out.print(i + " ");
        }
    }
}


import java.util.*;
public class PlayingWithNumbers {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        int n =input.nextInt();

        int [] a=new int[n];

        for (int i = 0; i <n; i++) {
            a[i]=input.nextInt();
        }

        Arrays.sort(a);

        while (a[0]!=a[a.length-1]) {

        for (int i = a.length-1; i>0; i--) {
            a[i]=a[i]-a[i-1];
        }

    Arrays.sort(a);

        }
        System.out.println(a[0]*n);

    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	static class Task {

		int NN = 100005;
		int MOD = 1000000007;

		int [] a;

		List<Integer> distinct;
		int [] freq = new int[102];

		int rec(int w, int k, int sz) {
			if(w == 0) {
				return k == 0 ? 1 : 0;
			}
			if(k == 0) {
				return 0;
			}
			if(sz == 0) {
				return 0;
			}
			int num = distinct.get(sz - 1);
			int cnt = freq[num];
			int ret = 0;
			for(int i=0;i<=Math.min(k, cnt) && i*num <= w;++i) {
				ret += rec(w-i*num, k - i, sz - 1);
			}
			return ret;
		}

		int [][][] dp = new int[10004][102][2];

		public void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt();
			a = new int[n];
			int totalSum = 0;
			for(int i=0;i<n;++i) {
				a[i] = in.nextInt();
				totalSum += a[i];
				++freq[a[i]];
			}

			int sz = 0;distinct = new ArrayList<>();
			for(int i=0;i<102;++i) {
				if(freq[i] > 0) {
					++sz;
					distinct.add(i);
				}
			}
			dp[0][0][0] = 1;
			for(int k=1;k<=sz;++k) {
				for(int i=1;i<=totalSum;++i) {
					for(int j=1;j<=n;++j) {
						int num = distinct.get(k - 1);
						int cnt = freq[num];
						dp[i][j][1] = 0;
						int mn = cnt;
						if(j < mn) {
							mn = j;
						}
						for(int ii=0;ii<=mn && ii*num<=i;++ii) {
							dp[i][j][1] += dp[i-ii*num][j - ii][0];
							if(dp[i][j][1] > 2) {
								dp[i][j][1] = 2;
							}
						}
					}
				}
				for(int i=1;i<=totalSum;++i) {
					for(int j=1;j<=n;++j) {
						dp[i][j][0] = dp[i][j][1];
					}
				}
			}
			int ans = 1;
			for(int num: distinct) {
				int count = freq[num];
				for(int i=1;i<=count;++i) {
					int sum = i * num;
					int cnt = i;
					if(dp[sum][cnt][0] == 1) {
						if(ans < i) {
							ans = i;
						}
						if(i == cnt && sz == 2) {
							if(ans < n) {
								ans = n;
							}
						}
					}
				}
			}
			out.println(ans);
		}

		class Pair {
			int sum;
			int count;
			public Pair(int sum, int cnt) {
				this.sum = sum;
				this.count = cnt;
			}
			@Override
			public int hashCode() {
				final int prime = 31;
				int result = 1;
				result = prime * result + getOuterType().hashCode();
				result = prime * result + count;
				result = prime * result + sum;
				return result;
			}
			@Override
			public boolean equals(Object obj) {
				if (this == obj)
					return true;
				if (obj == null)
					return false;
				if (getClass() != obj.getClass())
					return false;
				Pair other = (Pair) obj;
				if (!getOuterType().equals(other.getOuterType()))
					return false;
				if (count != other.count)
					return false;
				if (sum != other.sum)
					return false;
				return true;
			}
			private Task getOuterType() {
				return Task.this;
			}
			@Override
			public String toString() {
				return "(" + this.sum+","+this.count+")";
			}
		}

	}

	static void prepareIO(boolean isFileIO) {
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        fout.close();
		}
	}

	public static void main(String[] args) {
        prepareIO(false);
	}

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

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

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

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

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

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

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

    }

}


import java.util.*;
import java.io.*;
/*
200
NESENEESEESWWWNWWSWSWNWNNWNNESWSWNNWNWNENESENNESSWSESWWSSSEEEESSENNNESSWWSSSSESWSWWNNEESSWWNNWSWSSWWNWNNEENNENWWNESSSENWNESWNESWNESEESSWNESSSSSESESSWNNENENESSWWNNWWSWWNESEENWWWWNWWNWWNENESESSWWSWWSES
NWNESESSENNNESWNWWSWWWNWSESSSWWNWWNNWSENWSWNENNNWWSWWSWNNNESWWWSSESSWWWSSENWSENWWNENESESWNENNESWNWNNENNWWWSENWSWSSSENNWWNEESENNESEESSEESWWWWWWNWNNNESESWSSEEEESWNENWSESEEENWNNWWNWNNNNWWSSWNEENENEEEEEE
 */
public class e
{
	public static void main(String[] arg)
	{
		new e();
	}
	public e()
	{
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt()-1;
		String s1 = in.next();
		String s2 = in.next();
		char[] c = new char['X'];
		int[] arr = new int[2*n];
		c['N'] = 'S';
		c['S'] = 'N';
		c['E'] = 'W';
		c['W'] = 'E';
		StringBuilder sb = new StringBuilder();
		for(int i = n-1; i >= 0; i--)
		{
			sb.append(c[s1.charAt(i)]);
		}
		sb.append(s2);
		for(int i = 1; i < 2*n; i++)
		{
			arr[i] = arr[i-1];
			while(arr[i] != 0 && sb.charAt(i) != sb.charAt(arr[i]))
			{
				arr[i] = arr[arr[i]]-1;
			}
			if(sb.charAt(i) == sb.charAt(arr[i]))
			{
				arr[i]++;
			}
		}
//		out.println(Arrays.toString(arr));
		out.println(arr[2*n-1] == 0 ? "YES":"NO");
		in.close(); out.close();
	}
}


//package marbles;

import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author Adreno
 */
public class Marbles {

    public static char reverse(char c) {
        if (c == 'N') return 'S';
        if (c == 'S') return 'N';
        if (c == 'W') return 'E';
        if (c == 'E') return 'W';
        return '-';
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        n--;
        scanner.nextLine();
        String a = scanner.nextLine();
        String b = scanner.nextLine();

        // käännetään merkkijono a
        StringBuilder uusA = new StringBuilder();
        for (int i=n-1; i>=0; i--) {
            uusA.append(reverse(a.charAt(i)));
        }
        a = uusA.toString();

        StringHasher sh = new StringHasher();
        ;HashedString ah = sh.hashString(a);
        ;HashedString bh = sh.hashString(b);
        HashedString[] hstrings = sh.hashString(a, b);

        for (int i=0; i<n; i++) {
            if (sh.getHash(hstrings[0], 0, i) == sh.getHash(hstrings[1], n-1-i, n-1)) {
                System.out.println("NO");
                return;
            }
        }

        System.out.println("YES");
    }

}

class StringHasher {

    long modA;
    long modB;

    public StringHasher() {
        // TODO: satunnaisuutta mod lukujen valintaan
        modA = 192389845L;
        modB = 219386759L;
    }

    HashedString hashString(String s) {
        int n = s.length();
        long[] hashes = new long[n];
        long[] modifiers = new long[n];
        hashes[0] = s.charAt(0);
        modifiers[0] = 1;
        for (int i=1; i<n; i++) {
            hashes[i] = (hashes[i-1] * modA + s.charAt(i)) % modB;
            modifiers[i] = (modifiers[i-1] * modA) % modB;
        }
        return new HashedString(hashes, modifiers);
    }

    /**
     * Strings MUST BE SAME LENGTH. More efficient than multiple hashString calls.
     */
    HashedString[] hashString(String... strings) {
        HashedString[] array = new HashedString[strings.length];
        int n = strings[0].length();
        long[] modifiers = new long[n];
        modifiers[0] = 1;
        for (int j=0; j<strings.length; j++) {
            long[] hashes = new long[n];
            hashes[0] = strings[j].charAt(0);
            array[j] = new HashedString(hashes, modifiers);
        }
        for (int i=1; i<n; i++) {
            modifiers[i] = (modifiers[i-1] * modA) % modB;
            for (int j=0; j<strings.length; j++) {
                String s = strings[j];
                long[] hashes = array[i].hashes;
                hashes[i] = (hashes[i-1] * modA + s.charAt(i)) % modB;
            }
        }
        return array;
    }

    long getHash(HashedString hashedString, int startIndex, int endIndex) {
        long[] hashes = hashedString.hashes;
        long[] modifiers = hashedString.modifiers;
        long result = hashes[endIndex];
        if (startIndex > 0) result -= (hashes[startIndex-1] * modifiers[endIndex-startIndex+1]) % modB;
        if (result < 0) result += modB;
        return result;
    }
}

class HashedString {
    long[] hashes;
    long[] modifiers;

    public HashedString(long[] hashes, long[] modifiers) {
        this.hashes = hashes;
        this.modifiers = modifiers;
    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package codeforces;

import java.util.Scanner;

/**
 *
 * @author Dhruv
 */
public class Inscribed_Figures {
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
            arr[i]=sc.nextInt();
        int count = 0;
        for(int i=0;i<n-1;i++){
            if((arr[i]==1 && arr[i+1]==2 )||(arr[i]==2 && arr[i+1]==1)){
                count+=3;
            }
            if((arr[i]==1 && arr[i+1]==3 )||(arr[i]==3 && arr[i+1]==1)){
                count+=4;
            }
            if((i-1>=0 && arr[i-1]==3 && arr[i]==1 && arr[i]==2)){
                count--;
            }
            if((arr[i]==2 && arr[i+1]==3 )||(arr[i]==3 && arr[i+1]==2)){
                System.out.println("Infinite");
                System.exit(0);
            }

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


import java.util.*;

public class MyClass {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int arr[] = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }

        int count=0;
        for(int i=1;i<n;i++){
            if((arr[i-1]==2 && arr[i]==3) || (arr[i-1]==3 && arr[i]==2)|| (arr[i-1]==arr[i])){
                System.out.println("Infinite");
                return;
            }
            else{
                if((arr[i-1]==1 && arr[i]==2)|| (arr[i-1]==2 && arr[i]==1)){
                    count +=3;
                }
                else{
                    count+=4;
                }
            }
        }
        System.out.println("Finite");
        System.out.println(count);
    }
}


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

public class EC32P4
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt(); //number of fixed spots

        long counter = 1;

        if(k >= 2){
            counter += (n*(n-1)/2);
        }

        if(k >= 3){
            counter += (n*(n-1)*(n-2)/3);
        }

        if(k >= 4){
            counter += (3*n*(n-1)*(n-2)*(n-3)/8);
        }

        System.out.println(counter);
    }
    }

}


import java.util.*;
import java.io.*;
public class Random_Teams
{
	public static void main(String args[]) throws Exception
	{
		BufferedReader f=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(f.readLine());
		int one=Integer.parseInt(st.nextToken());
		int two=Integer.parseInt(st.nextToken());
		long[] arr=new long[two];
		for(int x=0;x<two;x++)
			arr[x]=one/two;
		for(int x=0;x<one%two;x++)
			arr[x]++;
		long res=0;
		for(int x=0;x<two;x++)
			res+=arr[x]*(arr[x]-1)/2;
		long three=one-two+1;
		System.out.println(res+" "+three*(three-1)/2);
	}
}


import java.util.Scanner;

public class Task58B {

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

		int[] pr = new int[100000];
		pr[0] = 2;
		pr[1] = 3;
		int pc = 2;
		ext:
		for (int i = 5; i <= n; i += 2) {
			for (int j = 1; j < pc; j++) {
				if (i % pr[j] == 0) {
					continue ext;
				}
			}
			pr[pc] = i;
			pc++;
		}

		StringBuilder res = new StringBuilder();
		res.append(n + " ");
		while (n != 1) {
			for (int i = 0; i < pc; i++) {
				if (n % pr[i] == 0) {
					res.append((n /= pr[i]) + " ");
					break;
				}
			}
		}

		System.out.println(res);
	}
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class A {

    public static void main(String[] Args) throws IOException {
        new A().solve();
    }

    int o = -INF;

    void solve() throws IOException {
        String[] ss = new String[8];
        for (int i = 0; i < 8; i++) {
            ss[i] = ss();
        }
        for (int i = 0; i < ss.length; i++) {
            String s = ss[i];
            for (int j = 0; j + 1 < 8; j += 2) {
                if (s.charAt(j) == s.charAt(j + 1)) {
                    System.out.println("NO");
                    return;
                }
            }
        }

        System.out.println("YES");
    }

    // ----------------------- Library ------------------------
    void initSystem() throws IOException {
        if (br != null)
            br.close();
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    void initFile() throws IOException {
        if (br != null)
            br.close();
        br = new BufferedReader(new InputStreamReader(new FileInputStream(
                "input.txt")));
    }

    void printWriter() {
        try {
            PrintWriter pr = new PrintWriter("output.txt");
            pr.println("hello world");
            pr.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    void comparator() {
        Point[] v = new Point[10];
        Arrays.sort(v, new Comparator<Point>() {
            @Override
            public int compare(Point a, Point b) {
                if (a.x != b.x)
                    return -(a.x - b.x);
                return a.y - b.y;
            }
        });
    }

    double distance(Point a, Point b) {
        double dx = a.x - b.x, dy = a.y - b.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    Scanner in = new Scanner(System.in);

    String ss() {
        return in.next();
    }

    String sline() {
        return in.nextLine();
    }

    int si() {
        return in.nextInt();
    }

    int[] sai(int n) {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    int[] sai_(int n) {
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    BufferedReader br;
    StringTokenizer tokenizer;
    {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    void tok() throws IOException {
        tokenizer = new StringTokenizer(br.readLine());
    }

    int toki() throws IOException {

        return Integer.parseInt(tokenizer.nextToken());
    }

    int[] rint(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++)
            a[i] = Integer.parseInt(tokenizer.nextToken());

        return a;
    }

    int[] rint_(int n) throws IOException {
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++)
            a[i] = Integer.parseInt(tokenizer.nextToken());

        return a;
    }

    String[] rstrlines(int n) throws IOException {
        String[] a = new String[n];
        for (int i = 0; i < n; i++) {
            a[i] = br.readLine();
        }
        return a;
    }

    long tokl() {
        return Long.parseLong(tokenizer.nextToken());
    }

    double tokd() {
        return Double.parseDouble(tokenizer.nextToken());
    }

    String toks() {
        return tokenizer.nextToken();
    }

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

    List<Integer> toList(int[] a) {
        List<Integer> v = new ArrayList<Integer>();
        for (int i : a)
            v.add(i);
        return v;
    }

    static void pai(int[] a) {
        System.out.println(Arrays.toString(a));
    }

    static int toi(Object s) {
        return Integer.parseInt(s.toString());
    }

    static int[] dx_ = { 0, 0, 1, -1 };
    static int[] dy_ = { 1, -1, 0, 0 };

    static int[] dx3 = { 1, -1, 0, 0, 0, 0 };
    static int[] dy3 = { 0, 0, 1, -1, 0, 0 };
    static int[] dz3 = { 0, 0, 0, 0, 1, -1 };

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

    static int INF = 2147483647; // =2^31-1 // -8
    static long LINF = 922337203854775807L; // -8
    static short SINF = 32767; // -32768

    // finds GCD of a and b using Euclidian algorithm
    public int GCD(int a, int b) {
        if (b == 0)
            return a;
        return GCD(b, a % b);
    }

    static List<String> toList(String[] a) {
        return Arrays.asList(a);
    }

    static String[] toArray(List<String> a) {
        String[] o = new String[a.size()];
        a.toArray(o);
        return o;
    }

    static int[] pair(int... a) {
        return a;
    }
}


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

public class Template implements Runnable {

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

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

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

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

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

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

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

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

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

    long timeBegin, timeEnd;

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

    long memoryTotal, memoryFree;

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

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

    long ff(long x) {
        if (x == 1) return 1;
        long sum = 1;
        for (long i = 2; i * i <= x; i++) {
            if (x % i == 0) {
                sum += ff(i);
                if (x / i != i) sum += ff(x / i);
            }
        }
        return x - sum;
    }

    int F(int n, int k) {
        if (k == 1) return f(n);
        int F = F(n, k - 1);
        if (k % 2 == 0) return g(F);
        else return f(F);
    }

    int f(int n) {
        if (n == 1) return 1;
        int res = 0;
        for (int x = 1; x < n; x++) {
            if (gcd(x, n - x) == 1) {
                res++;
            }
        }
        return res;
    }

    int g(int n) {
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (n % i == 0) {
                System.err.println(n / i + "  " + f(n / i));
                ans += f(n / i);
            }
        }
        return ans;
    }

    int gcd(int x, int y) {
        if (x == 0) return y;
        return gcd(y % x, x);
    }

    void solve() throws IOException {
//        for (int n = 1; n <= 1000; n++) {
//            System.err.println("--------------");
//            System.err.println("N = " + n);
//            for (int k = 1; k <= 100; k++) {
//                System.err.println("k = " + k + " : " + F(n, k));
//            }
//        }
        //System.err.println(g(24));
//        System.err.println(ff(6));
//        System.err.println(g(6));
//        System.err.println(f(6) + " " + ff(6));
//        System.err.println(g(10));
//        System.err.println(f(10) + " " + ff(10));
//        for (int i = 1; i < 1000000; i++) {
//            if (i != g(i)) throw new RuntimeException();
//        }
        long x = readInt();
        long y = readInt();
        if (y % 2 == 0) y--;
        while (y >= 1) {
            x = ff(x);
            if (x == 1) break;
            y-=2;
        }
        out.println(x);

    }

}


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

public class Main implements Runnable
{
   void solution() throws Exception
   {
      int n = nextInt();
      for (int i = 2; ; i++) {
         ArrayList<Integer> p = new ArrayList<Integer>();
         int k = i;
         for (int j = 2; j*j <= k; j++)
            if (k%j == 0) {
               int pw = 0;
               while (k%j == 0) { k /= j; pw++; }
               p.add(pw);
            }
         if (k != 1)
            p.add(1);
         int ret = 1;
         for (int x : p) ret *= x+1;
         if (ret == n) {
            out.println(i);
            break;
         }
         //out.println(i + ": " + ret);
      }
   }

   ///////////////////// Template definitions //////////////////////////
   int nextInt() throws IOException { return Integer.parseInt(next()); }
   long nextLong() throws IOException { return Long.parseLong(next()); }
   double nextDouble() throws IOException { return Double.parseDouble(next()); }

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

   public static void main(String args[]) {
      Locale.setDefault(Locale.UK);
      new Thread(new Main()).start();
   }

   public void run() {
      try {
         boolean online = System.getProperty("ONLINE_JUDGE") != null;
         Reader reader = online
            ? new InputStreamReader(System.in)
            : new FileReader("my.in");
         in = new BufferedReader(reader);
         out = new PrintWriter(System.out);
         solution();
         out.flush();
         out.close();
      }
      catch (Exception e) {
         e.printStackTrace();
         System.exit(202);
      }
   }

   BufferedReader in;
   StringTokenizer st;
   PrintWriter out;
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package test3;
import java .util.Scanner;
/**
 *
 * @author User
 */
public class Test3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
       char c=sc.;
    }

}


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

public class A {
	static long nCk(long n, long k) {
		if (k > n)
			return 0;
		if (k * 2 > n)
			k = n - k;
		if (k == 0)
			return 1;

		long result = n;
		for (int i = 2; i <= k; ++i) {
			result *= (n - i + 1);
			result /= i;
		}
		return result;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(bf.readLine());
		System.out.println(4 * 9 * pow(4, n - 4) + 2 * 12 * pow(4, n - 3));
	}

	private static long pow(long i, long l) {
		if (l == 0)
			return 1;
		return i * pow(i, l - 1);
	}
}


import java.util.*;
import java.io.*;
public class C643
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = 1;
        while (t > 0) {
            int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt();
            long [] stor = new long [b + c + 1];
            for (int z = a + b; z <= b + c; z++) {
                int lo = z - b; int hi = z - a;
                if (b > hi) stor[z] = 0;
                if (c < lo) stor[z] = 0;
                if (b <= lo && c >= hi) stor[z] = hi - lo + 1;
                if (b >= lo && c >= hi) stor[z] = hi - b + 1;
                if (b < lo && c <= hi) stor[z] = c - lo + 1;
                if (b >= lo && c <= hi) stor[z] = c - b + 1;
            }
            long [] pref = new long [b + c + 2];
            for (int i = b + c - 1; i >= 0; i--) {
                pref[i] = pref[i + 1] + stor[i + 1];
            }
            long ans = 0;
            for (int i = c; i <= d; i++) ans += pref[i];
            out.println(ans);
            t--;
        }
        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

    }

}


import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
public class he
{
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
        int l = in.nextInt();
        int r = in.nextInt();
        int x = in.nextInt();
        int y = in.nextInt();
        double p = in.nextDouble();

        double ans[] = new double[(r-l+1)*(y-x+1)];
        int k=0;
        for(int i=l;i<=r;i++){
        	for(int j=x;j<=y;j++){
        		ans[k++] = i/j;
        	}
        }
        Arrays.sort(ans);
        if(Arrays.binarySearch(ans,p)>=0){
        	System.out.println("YES");

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

	}
}


import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class PlayGround {

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

	}

	public static void testName() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String bark = br.readLine();
		String [] barkArray = bark.split(" ");
		int[] barkIntArray = new int[barkArray.length];
		for(int i = 0; i<barkArray.length; i++){
			barkIntArray[i] = Integer.parseInt(barkArray[i]);
		}
		int first = barkIntArray[0];
		int barkInterval = barkIntArray[1];
		int eat = barkIntArray[2];
		boolean [] checkArray = new boolean[1000000000];
		checkArray[first]=true;
		for(int i =first+barkInterval; i<eat; i+=barkInterval){
			checkArray[i]=true;
			checkArray[i+1]=true;
		}
		if(checkArray[eat+1]){
			System.out.println("NO");
		}
		else{
			System.out.println("YES");
		}

	}

	}


import java.util.Scanner;

public class Main{
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        int h=input.nextInt();
        int m=input.nextInt();
        int s=input.nextInt();
        int t1=input.nextInt();
        int t2=input.nextInt();
        boolean verif=false;
        h*=5;
        t1*=5;
        t2*=5;
        if(m==0){
            m=60;
        }
        if(s==0){
            s=60;
        }
        for(int i=(t1+1);;i++){
            if(i==61){
                i=1;
            }
            if(i==h || i==m || i==s){
                break;
            }
            if(i==t2){
                verif=true;
                break;
            }
        }
            for(int i=(t1-1);;i--){
                if(i==h || i==m || i==s){
                    break;
                }
                if(i==t2){
                    verif=true;
                    break;
                }
            }

        if(verif==true) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


import java.util.Scanner;

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

        String start = scanner.nextLine();
        String finish = scanner.nextLine();

        int h1,h2, m1,m2, hcenter, mcenter;

        h1 = Integer.valueOf(start.split(":")[0]);
        m1 = Integer.valueOf(start.split(":")[1]);
        h2 = Integer.valueOf(finish.split(":")[0]);
        m2 = Integer.valueOf(finish.split(":")[1]);

        if((h2-h1) %2 >0)
        {
            m2 = m2+60;
            h2 = h2-1;
        }

        mcenter = (m2+m1)/2;
        hcenter = (h2+h1)/2;

        if(mcenter > 60)
        {
            hcenter+=1;
            mcenter -=60;
        }

        String hourValue = String.valueOf(hcenter);
        if(hourValue.length()==1)
        {
            hourValue = "0"+hourValue;
        }

        String minuteValue = String.valueOf(mcenter);
        if(minuteValue.length()==1)
        {
            minuteValue = "0"+minuteValue;
        }

        System.out.println(hourValue+":" +minuteValue);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class sample {

    public static int main(String[] args) throws IOException {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String rowndcolumns=null;
         rowndcolumns=br.readLine();
         int row=Integer.parseInt(rowndcolumns.split(" ")[0]);
         int column=Integer.parseInt(rowndcolumns.split(" ")[1]);
        int i=0;
        char[][] matrix =new char[row][column];
        int[] rows=new int[row];
        int[] columns=new int[column];
         while(i<row)
         {
             int j=0;
             String temp=br.readLine();
             while(j<column)
             {
             char ch=(temp.split(" ")[j]).charAt(0);

             if(ch=='S')
             {
                rows[i]=1;
                columns[j]=1;
             }
                 matrix[i][j]=ch;
             j++;
             }

             i++;
         }
         int noofrows=0;
         int totalcakes=0;
         for(int k=0;k<rows.length;k++)
         {
            if(rows[k]==0)
            {
            noofrows++;
                totalcakes=totalcakes+column;
            }
         }
         for(int k=0;k<columns.length;k++)
         {
             if(columns[k]==0)
             {
                 totalcakes=totalcakes+row-noofrows;
             }
         }
         System.out.println(totalcakes);
         return totalcakes;

    }

}


import java.util.Scanner;

/**
 * Created by Nowrin on 26-Aug-16.
 */
public class camp {
    public static void main(String[] args){
        int n,i=1;
        String s = "",a;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        while (s.length()!=n){
            a = String.valueOf(i);
            s+=a;
            //System.out.println(s);
            i++;
        //System.out.println(i);
        }
        a = s.substring(n-1);
        i = Integer.parseInt(a);
        System.out.println(i);
    }
}


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--;
			for (int i = 0; i < ringNumber && remainingSteps > 0; i++) {
				x += dx[1];
				y += dy[1];
				remainingSteps--;
			}
			for (int i = 0; i < ringNumber + 1 && remainingSteps > 0; i++) {
				x += dx[2];
				y += dy[2];
				remainingSteps--;
			}
			for (int i = 0; i < ringNumber + 1 && remainingSteps > 0; i++) {
				x += dx[3];
				y += dy[3];
				remainingSteps--;
			}
			for (int i = 0; i < ringNumber + 1 && remainingSteps > 0; i++) {
				x += dx[4];
				y += dy[4];
				remainingSteps--;
			}
			for (int i = 0; i < ringNumber + 1 && remainingSteps > 0; i++) {
				x += dx[5];
				y += dy[5];
				remainingSteps--;
			}
			for (int i = 0; i < ringNumber && remainingSteps > 0; i++) {
				x += dx[0];
				y += dy[0];
				remainingSteps--;
			}
		}
		out.println(x + " " + y);
		out.close();
	}

	static long getRing(long n) {
		long l = 0;
		long r = (long) 1e16;
		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.util.*;
import java.io.*;
import java.lang.*;

public class BINARY
{
      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 int[] swap(int[] arr, int i, int j)
	{
		int k=arr[j];
		arr[j]=arr[i];
		arr[i]=k;
		return arr;

	}

	public static void main(String []args)
	{
		FastReader obj=new FastReader();
        int w= obj.nextInt();
        int h= obj.nextInt();
        int t = w+h-2;
        int out=4;
        for(int i=0;i<t;i++)
        {
            out*=2;
            out=%998244353;
        }

        {System.out.print(""+out);}

	}
}


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

public class B {
    int[] map = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        long ans = 0;
        for (int i = a; i <= b; i++) {
            while (i > 0){
                ans += map[i%10];
                i /= 10;
            }
        }
        out.print(ans);
    }

    InputReader in;
    PrintWriter out;

    void runIO() {

        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    class InputReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


/*package whatever //do not write package name here */

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

public class GFG {
	public static void main (String[] args) {
		int flag=0;
		Scanner ss = new Scanner(System.in);
		String pass= ss.next();
	    int n= ss.nextInt();
	    String s = new String();
	    for(int i=0;i<n;i++)
	    {   String s1=ss.next();
	    	s+=s1;
	    	s+=s;

	    }

	    for(int i=0;i<s.length()-1;i+=2)
	    { String h=s.substring(i,i+2);
	    	if(h.charAt(1)==pass.charAt(0))
	    	{
              flag++;break;
	    	}
	    }
	    if(flag<1){System.out.print("NO");System.exit(0);}
	    	 for(int i=0;i<s.length()-1;i+=2)
	    { String h=s.substring(i,i+2);
	    	if(h.charAt(0)==pass.charAt(1))
	    	{
              flag++;break;
	    	}
	   	 }

	   if(flag>1){System.out.print("YES");System.exit(0);}
	    System.out.print("NO");

	}
}


import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static Queue<Node> queue;
	static Queue<Node> queue1;
	static int x;
	static int y;
	static int vis[];
	static int vis1[];
	static int dir[] = {2, 3};
	static void bfs() {
		Node f = new Node();
		Node p = new Node();
		Node s = new Node();
		Node q = new Node();

		while (!queue.isEmpty() && !queue1.isEmpty()) {
			f = queue.poll();
			p = queue1.poll();
			for (int i = 0; i < dir.length; i++) {
				s.x = f.x * dir[i];
				s.time = f.time + 1;
				if (check(s)) {
					return;
				}
				if (p.x % dir[i] == 0) {
					q.x = p.x /dir[i];
					q.time = p.time + 1;
					if (check1(q)) {
						return;
					}
				}

			}
		}
		System.out.println(-1);
	}
	private static boolean check1(Node q) {
		// TODO Auto-generated method stub
		if (q.x < x) {
			return false;
		}
		if (vis[q.x] != -1) {
			System.out.println(vis[q.x] + q.time);
			return true;
		}
		if (vis1[q.x] == -1) {
			vis1[q.x] = q.time;
			queue1.add(q);
		}
		return false;
	}
	private static boolean check(Node s) {
		// TODO Auto-generated method stub
		if (s.x > y) {
			return false;
		}
		if (vis1[s.x] != -1) {
			System.out.println(vis1[s.x] + s.time);
			return true;
		}
		if (vis[s.x] == -1) {
			vis[s.x] = s.time;
			queue.add(s);
		}
		return false;
	}
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			queue = new LinkedList<>();
			queue1 = new LinkedList<>();
			x = scanner.nextInt();
			y = scanner.nextInt();
			if (x == y) {
				System.out.println(0);
			} else {
				vis = new int[y + 1];
				vis1 = new int[y + 1];
				Node node = new Node();
				node.x = x;
				node.time = 0;
				Node node2 = new Node();
				node2.x = y;
				node2.time = 0;
				Arrays.fill(vis, -1);
				Arrays.fill(vis1, -1);
				vis[x] = 0;
				vis1[y] = 0;
				queue.add(node);
				queue1.add(node2);
				bfs();
			}
		}
	}
}
class Node{
	int x;
	int time;
}


import java.util.*;
public class M  {
    public static void main (String [] args){
        Scanner in = new Scanner (System.out);
        int n=in.nextInt();
         int sum=0;
if (n>=2520){
    sum+=n;
}
System.out.println(sum);

    }
}


import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import static java.lang.System.*;

public class pon {

    static BufferedReader br;

    public static void init() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public static String getString() {
        try {
            if (br == null) {
                init();
            }
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            if (br == null) {
                init();
            }
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            if (br == null) {
                init();
            }
            String temp[] = br.readLine().split(" ");
            Integer temp2[] = new Integer[temp.length];
            for (int i = 0; i < temp.length; i++) {
                temp2[i] = Integer.parseInt(temp[i]);
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }
    static int inp = 0;
    static ArrayList<Integer> ans=new ArrayList<Integer>();
    public static void main(String[] ar) {
        int init[] = {1, 1};
        int c = 0;
        inp = getInt();
        //sol(init, c);
        new solver(init, c, inp, ans).start();
        try{
            Thread.sleep(900);
        }catch(Exception e){

        }
        int min=ans.get(0);
        for(int i=0;i<ans.size();i++){
            if(ans.get(i)<min){
                min=ans.get(i);
            }
        }
        System.out.println(min);
    }

    public static void sol(int[] init, int c) {

        int max = Math.max(init[0], init[1]);
        int min = Math.min(init[0], init[1]);
        if (max > inp) {
            return;
        } else if (max == inp) {
            //System.out.println(c);
            ans.add(c);
            return;
        } else if (max < inp) {
            c++;
            sol(new int[]{max + min, max}, c);
            sol(new int[]{max + min, min}, c);
        }

    }
}
class solver extends Thread{
    int init[];
    int c;
    int inp;
    ArrayList<Integer> ans;
    solver(int[] init,int c,int inp,ArrayList<Integer> ans){
        this.init=init;
        this.c=c;
        this.inp=inp;
        this.ans=ans;
    }

    public void run(){

        int max = Math.max(init[0], init[1]);
        int min = Math.min(init[0], init[1]);
        if (max > inp) {
            return;
        } else if (max == inp) {
            //System.out.println(c);
            ans.add(c);
            return;
        } else if (max < inp) {
            c++;
            new solver(new int[]{max + min, max}, c,inp,ans).start();
            new solver(new int[]{max + min, min}, c,inp,ans).start();
        }

    }
}


import java.util.Scanner;

public class B {
    public static int getMin(int f,int s) {
        if(f==s) {
            if(f==1&&s==1) return 0;
            return 3000000;
        }
        int min=Math.min(f,s);
        int max=Math.max(f,s);
        if(min==1) return max-1;
        return ((max/min))+getMin(max%min,min);
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n==1){
            System.out.println(0); return;
        }
        int min=2*n;
        for(int i=1;i<=n/2;i++) {
            //System.out.println(getMin(i,n-i));
            min=Math.min(min,1+getMin(i,n-i));
        }
        System.out.println(min);
    }
}


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

public class Main implements Runnable {
    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter out;
    static Random rand;

    public static void main(String[] args) throws IOException {
    rand = new Random();
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(new OutputStreamWriter(System.out));
    new Main().run();
    out.flush();
    }

    String nline() {
    try {
        return br.readLine();
    } catch (Exception e) {
        return null;
    }
    }

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

    int ni() {
    return Integer.valueOf(ns());
    }

    long nl() {
    return Long.valueOf(ns());
    }

    double nd() {
    return Double.valueOf(ns());
    }

    public void run() {
    Solve();
    }

    void Solve() {
    int n = ni(), x1 = ni(), y1 = ni(), x2 = ni(), y2 = ni();
    int ans = 0.0;
    if ((x1 == 0 && x2 == 0) || (x1 == n && x2 == n)) {
        ans = abs(y1 - y2);
    } else if ((y1 == 0 && y2 == 0) || (y1 == n && y2 == n)) {
        ans = abs(x1 - x2);
    } else if ((x1 == 0 && x2 == n) || (x1 == n && x2 == 0)) {
        ans = min((n + y1 + y2), (n + (n - y1) + (n - y2)));
    } else if ((y1 == 0 && y2 == n) || (y1 == n && y2 == 0)) {
        ans = min((n + x1 + x2), (n + (n - x1) + (n - x2)));
    } else if (x1 == 0 && y2 == 0) {
        ans = y1 + x2;
    } else if (x2 == 0 && y1 == 0) {
        ans = y2 + x1;
    } else if (x1 == 0 && y2 == n) {
        ans = n - y1 + x2;
    } else if (x2 == 0 && y1 == n) {
        ans = n - y2 + x1;
    } else if (x1 == n && y2 == 0) {
        ans = y1 + n - x2;
    } else if (x2 == n && y1 == 0) {
        ans = y2 + n - x1;
    } else if (x1 == n && y2 == n) {
        ans = n - x2 + n - y1;
    } else if (x2 == n && y1 == n) {
        ans = n - x1 + n - y2;
    }

    out.println(ans);
    }

}


import java.util.Scanner;
public class Program
{
	public static void main(String[] args) {
	Scanner input= new Scanner(System.in);
	String str = input.next();
	int count=0;
	 for(int i=0 ; i<str.length(); i++){
	 for(int j=(i+1); j<str.length() ; j++){
	   if(str.charAt(i)== str.charAt(j)){
 str=str.substring(0,j)+str.substring(j);
 j--;
 count++;

	   }
		}
	   }
	   if ((str.length()-count) %2 ==0)
	   System.out.println("CHAT WITH HER!");
	else
	System.out.println("I GNORE HIM!");
	}
}


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

public class Parallelepiped {
	public static void main(String[] args) {
		MyScanner in = new MyScanner();

		int a1=in.nextInt(), a2=in.nextInt(), a3=in.nextInt();
		for(int i=0; i<10000; i++) {
			for(int j=0; j<10000; j++) {
				for(int k=0; k<10000; k++) {
					if(i*j==a1&&i*k==a2&&j*k==a3) {
						System.out.println(4*k+4*j+4*i);
						return;
					}
				}
			}
		}
	}

	static class MyScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while(st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println(Integer.toString(110, 15));
        Scanner r = new Scanner(System.in);

        String a = r.next();
        String b = r.next();

        int ai = Integer.parseInt(a);
        int bi = Integer.parseInt(b);

        int base = 2;

        for(int i = 0; i < a.length(); i++)
            base = Math.max(base, a.charAt(i)-'0'+1);
        for(int i = 0; i < b.length(); i++)
            base = Math.max(base, b.charAt(i)-'0'+1);

        System.out.println(Integer.toString(Integer.parseInt(a, base)+Integer.parseInt(b, base), base).length());

    }
}


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

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

	void solve()
	{
		int n = ni(), K = ni();
		int mod = 1000000007;
		int[] dp = new int[n+1];
		Arrays.fill(dp, 1);
		dp[0] = 0;
		for(int i = 0;i < K-1;i++){
			for(int j = n;j >= 1;j--){
				for(int k = 2*j;k <= n;k+=j){
					dp[k] += dp[j];
					if(dp[k] >= mod)dp[k] -= mod;
				}
			}
		}
		long ret = 0;
		for(int j = 1;j <= n;j++){
			ret += dp[j];
		}
		out.println(ret%mod);
	}

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

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

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


// https://codeforces.com/contest/1174/submission/55043857 (rainboy)
import java.io.*;

public class CF1174E {
	static final int MD = 1000000007;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] aa = new int[n + 1];
		for (int i = 1; i <= n; i++)
			aa[i] = i % 2 == 0 ? aa[i / 2] + 1 : 0;
		int k = 0;
		while (1 << k + 1 <= n)
			k++;
		int[] cnt = new int[k + 1];
		int[] cnt3 = new int[k + 1];
		for (int i = 1; i <= n; i++) {
			int a = aa[i];
			cnt[a]++;
			if (i % 3 == 0)
				cnt3[a]++;
		}
		long[][] dp = new long[n + 1][k + 1];
		dp[1][k] = 1;
		for (int i = 1; i < n; i++)
			for (int h = 0; h <= k; h++) {
				long x = dp[i][h];
				if (x != 0) {
					if (h > 0)
						dp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;
					dp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;
				}
			}
		long ans = dp[n][0];
		if (3 << k - 1 <= n) {
			dp = new long[n + 1][k];
			long[][] dq = new long[n + 1][k];
			dq[1][k - 1] = 1;
			for (int i = 1; i < n; i++)
				for (int h = 0; h < k; h++) {
					long x = dq[i][h];
					if (x != 0) {
						if (h > 0)
							dq[i + 1][h - 1] = (dq[i + 1][h - 1] + x * cnt3[h - 1]) % MD;
						dq[i + 1][h] = (dq[i + 1][h] + x * (n / (3 << h) - i)) % MD;
						dp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - n / (3 << h))) % MD;
					}
					x = dp[i][h];
					if (x != 0) {
						if (h > 0)
							dp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;
						dp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;
					}
				}
			ans = (ans + dp[n][0]) % MD;
		}
		System.out.println(ans);
	}
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1174E
   {
      static long MOD = 1000000007L;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         dp = new long[N+1][20][2];
         for(int i=0; i <= N; i++)
            for(int a=0; a < 20; a++)
               Arrays.fill(dp[i][a], -1);
         for(int a=0; a < 20; a++)
            Arrays.fill(dp[0][a], 0);
         base(dp, N);
         cnt = new long[20][2];
         for(int curr=0; (1<<curr) <= N; curr++)
            for(int b=1; b <= 3; b+=2)
            {
               int temp = (1<<curr)*b;
               cnt[curr][Math.max(b-2, 0)] = N/temp;
            }
         System.out.println(dfs(N, 0, 0));
      }
      static long[][][] dp;
      static long[][] cnt;
      public static long dfs(int i, int a, int b)
      {
         if(dp[i][a][b] != -1)
            return dp[i][a][b];
         long res = 0L;
         if(cnt[a][b]-i >= 0)
            res = (dfs(i-1,a,b)*(cnt[a][b]-i+1+MOD))%MOD;
         if(a+1 < 20)
         {
            res += (dfs(i-1,a+1,b)*(cnt[a][b]-cnt[a+1][b]))%MOD;
            res %= MOD;
         }
         if(b == 0)
         {
            res += (dfs(i-1,a,1)*(cnt[a][0]-cnt[a][1]))%MOD;
            res %= MOD;
         }
         return dp[i][a][b] = res;
      }
      public static void base(long[][][] dp, int N)
      {
         int curr = 1;
         while((1<<curr) <= N)
            curr++;
         curr--;
         dp[1][curr][0] = 1L;
         int oth = 1<<(curr-1);
         oth *= 3;
         if(oth <= N)
            dp[1][curr-1][1] = 1L;
      }
   }