import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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);
        HZSShufflesCards solver = new HZSShufflesCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class HZSShufflesCards {
        NumberTheory.Mod998 mod = new NumberTheory.Mod998();
        int n;
        int m;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            mod.fInv(n + m);

            long phaseSize = 1;
            long p = 1;
            for (int i = 0; p != 0; i++) {
                p = mod.mult(p, n - i, mod.smallInv(n + m - i));
                phaseSize = mod.add(phaseSize, p);
            }

            long answer = 0;
            for (int k = 1; k <= n; k++) {
                long numPhases = mod.mult(m + k, mod.smallInv(k));
                long e = mod.mult(numPhases, phaseSize);
                long term = mod.mult(mod.ncr(n, k), e);

                if (k % 2 == 1)
                    answer = mod.add(answer, term);
                else
                    answer = mod.subtract(answer, term);
            }

            out.println(answer);
        }

    }

    static class NumberTheory {
        private static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            final ArrayList<Long> factorial = new ArrayList<>();
            final ArrayList<Long> invFactorial = new ArrayList<>();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.add(1L);
                invFactorial.add(1L);
            }

            public long fact(int n) {
                while (factorial.size() <= n) {
                    factorial.add(mult(factorial.get(factorial.size() - 1), factorial.size()));
                }

                return factorial.get(n);
            }

            public long fInv(int n) {
                int lastKnown = invFactorial.size() - 1;

                if (lastKnown < n) {
                    long[] fInv = new long[n - lastKnown];
                    fInv[0] = inv(fact(n));
                    for (int i = 1; i < fInv.length; i++) {
                        fInv[i] = mult(fInv[i - 1], n - i + 1);
                    }
                    for (int i = fInv.length - 1; i >= 0; i--) {
                        invFactorial.add(fInv[i]);
                    }
                }

                return invFactorial.get(n);
            }

            public long ncr(int n, int r) {
                ASSERT(n >= 0);
                if (r < 0 || n < r)
                    return 0;
                return mult(fact(n), mult(fInv(r), fInv(n - r)));
            }

            public long smallInv(int n) {
                return mult(fInv(n), fact(n - 1));
            }

            public long normalize(long x) {
                x %= modulus();
                if (x < 0)
                    x += modulus();
                return x;
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

            public long subtract(long a, long b) {
                long v = a - b;
                return v < 0 ? v + modulus() : v;
            }

            public long mult(long... x) {
                long r = 1;
                for (long i : x)
                    r = mult(r, i);
                return r;
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

            public long inv(long value) {
                long g = modulus(), x = 0, y = 1;
                for (long r = value; r != 0; ) {
                    long q = g / r;
                    g %= r;

                    long temp = g;
                    g = r;
                    r = temp;

                    x -= q * y;

                    temp = x;
                    x = y;
                    y = temp;
                }

                ASSERT(g == 1);
                ASSERT(y == modulus() || y == -modulus());

                return normalize(x);
            }

        }

        public static class Mod998 extends NumberTheory.Modulus<NumberTheory.Mod998> {
            public long modulus() {
                return 998_244_353L;
            }

        }

    }

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

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

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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);
        HZSShufflesCards solver = new HZSShufflesCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class HZSShufflesCards {
        NumberTheory.Mod998 mod = new NumberTheory.Mod998();
        int n;
        int m;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            mod.fInv(n + m);

            long phaseSize = 1;
            long p = 1;
            for (int i = 0; p != 0; i++) {
                p = mod.mult(p, n - i, mod.smallInv(n + m - i));
                phaseSize = mod.add(phaseSize, p);
            }

            long answer = 0;
            for (int k = 1; k <= n; k++) {
                long sign = mod.paritySign(k + 1);
                long numPhases = mod.div(m + k, k);
                long term = mod.mult(sign, mod.ncr(n, k), numPhases, phaseSize);
                answer = mod.add(answer, term);
            }

            out.println(answer);
        }

    }

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

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

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

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

    }

    static class Util {
        public static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        private Util() {
        }

    }

    static class IntStack {
        int[] array;
        int size = 0;

        public IntStack() {
            this(8);
        }

        public IntStack(int capacity) {
            array = new int[capacity];
        }

        public void push(int item) {
            if (size >= array.length)
                array = resize(array);
            array[size++] = item;
        }

        public int size() {
            return size;
        }

        public int get(int i) {
            Util.ASSERT(i < size);
            return array[i];
        }

        private static int[] resize(int[] array) {
            int[] newArray = new int[array.length << 1];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        public String toString() {
            int[] trimmed = new int[size];
            System.arraycopy(array, 0, trimmed, 0, size);
            return Arrays.toString(trimmed);
        }

    }

    static class NumberTheory {
        private static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            final IntStack factorial = new IntStack();
            final IntStack invFactorial = new IntStack();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.push(1);
                invFactorial.push(1);
            }

            public long fact(int n) {
                while (factorial.size() <= n) {
                    factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));
                }

                return factorial.get(n);
            }

            public long fInv(int n) {
                int lastKnown = invFactorial.size() - 1;

                if (lastKnown < n) {
                    long[] fInv = new long[n - lastKnown];
                    fInv[0] = inv(fact(n));
                    for (int i = 1; i < fInv.length; i++) {
                        fInv[i] = mult(fInv[i - 1], n - i + 1);
                    }
                    for (int i = fInv.length - 1; i >= 0; i--) {
                        invFactorial.push((int) fInv[i]);
                    }
                }

                return invFactorial.get(n);
            }

            public long paritySign(long k) {
                return (k & 1) == 0 ? 1 : modulus() - 1;
            }

            public long ncr(int n, int r) {
                ASSERT(n >= 0);
                if (r < 0 || n < r)
                    return 0;
                return mult(fact(n), mult(fInv(r), fInv(n - r)));
            }

            public long smallInv(int n) {
                return mult(fInv(n), fact(n - 1));
            }

            public long normalize(long x) {
                x %= modulus();
                if (x < 0)
                    x += modulus();
                return x;
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

            public long mult(long... x) {
                long r = 1;
                for (long i : x)
                    r = mult(r, i);
                return r;
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

            public long div(long a, long b) {
                return mult(a, inv(b));
            }

            public long inv(long value) {
                long g = modulus(), x = 0, y = 1;
                for (long r = value; r != 0; ) {
                    long q = g / r;
                    g %= r;

                    long temp = g;
                    g = r;
                    r = temp;

                    x -= q * y;

                    temp = x;
                    x = y;
                    y = temp;
                }

                ASSERT(g == 1);
                ASSERT(y == modulus() || y == -modulus());

                return normalize(x);
            }

        }

        public static class Mod998 extends NumberTheory.Modulus<NumberTheory.Mod998> {
            public long modulus() {
                return 998_244_353L;
            }

        }

    }
}


//package global10;
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 G2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int mod = 998244353;
		int n = ni(),  m = ni();
		long ans = (1 + invl(m+1, mod) * n) % mod;
		long base = invl(m+1, mod) * ((long)m * (m+2 + (n-1)) % mod) % mod;
		long u = 0;
		for(int i = 1;i <= n;i++){
			u += invl(i, mod);
			u %= mod;
		}
		ans = (base * u + ans) % mod;
		out.println(ans);
	}

	public static long[] guessFrac(long n, int mod)
	{
		long min = mod;
		long argnum = -1, argden = 0;
		for(int den = 1;den <= 200000;den++){
			long num = n*den%mod;
			if(num*2 >= mod)num -= mod;
			if(Math.abs(num) + den < min){
				min = Math.abs(num) + den;
				argnum = num;
				argden = den;
			}
		}
		return argden == 0 ? null : new long[]{argnum, argden};
	}

	public static long invl(long a, long mod) {
		long b = mod;
		long p = 1, q = 0;
		while (b > 0) {
			long c = a / b;
			long d;
			d = a;
			a = b;
			b = d % b;
			d = p;
			p = q;
			q = d - c * q;
		}
		return p < 0 ? p + mod : p;
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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);
        HZSShufflesCards solver = new HZSShufflesCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class HZSShufflesCards {
        NumberTheory.Mod998 mod = new NumberTheory.Mod998();
        int n;
        int m;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            mod.fInv(n + m);

            long phaseSize = 1;
            long p = 1;
            for (int i = 0; p != 0; i++) {
                p = mod.mult(p, n - i, mod.smallInv(n + m - i));
                phaseSize = mod.add(phaseSize, p);
            }

            long answer = 0;
            for (int k = 1; k <= n; k++) {
                long numPhases = mod.mult(m + k, mod.smallInv(k));
                long e = mod.mult(numPhases, phaseSize);
                long term = mod.mult(mod.ncr(n, k), e);

                if (k % 2 == 1)
                    answer = mod.add(answer, term);
                else
                    answer = mod.subtract(answer, term);
            }

            out.println(answer);
        }

    }

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

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

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

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

    }

    static class IntStack {
        int[] array;
        int size = 0;

        public IntStack() {
            this(8);
        }

        public IntStack(int capacity) {
            array = new int[capacity];
        }

        public void add(long i) {
            push((int) i);
        }

        public int get(int i) {
            return array[i];
        }

        public void push(int item) {
            if (size >= array.length)
                array = resize(array);
            array[size++] = item;
        }

        public int size() {
            return size;
        }

        private static int[] resize(int[] array) {
            int[] newArray = new int[array.length << 1];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        public String toString() {
            int[] trimmed = new int[size];
            System.arraycopy(array, 0, trimmed, 0, size);
            return Arrays.toString(trimmed);
        }

    }

    static class NumberTheory {
        private static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            final IntStack factorial = new IntStack();
            final IntStack invFactorial = new IntStack();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.add(1L);
                invFactorial.add(1L);
            }

            public long fact(int n) {
                while (factorial.size() <= n) {
                    factorial.add(mult(factorial.get(factorial.size() - 1), factorial.size()));
                }

                return factorial.get(n);
            }

            public long fInv(int n) {
                int lastKnown = invFactorial.size() - 1;

                if (lastKnown < n) {
                    long[] fInv = new long[n - lastKnown];
                    fInv[0] = inv(fact(n));
                    for (int i = 1; i < fInv.length; i++) {
                        fInv[i] = mult(fInv[i - 1], n - i + 1);
                    }
                    for (int i = fInv.length - 1; i >= 0; i--) {
                        invFactorial.add(fInv[i]);
                    }
                }

                return invFactorial.get(n);
            }

            public long ncr(int n, int r) {
                ASSERT(n >= 0);
                if (r < 0 || n < r)
                    return 0;
                return mult(fact(n), mult(fInv(r), fInv(n - r)));
            }

            public long smallInv(int n) {
                return mult(fInv(n), fact(n - 1));
            }

            public long normalize(long x) {
                x %= modulus();
                if (x < 0)
                    x += modulus();
                return x;
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

            public long subtract(long a, long b) {
                long v = a - b;
                return v < 0 ? v + modulus() : v;
            }

            public long mult(long... x) {
                long r = 1;
                for (long i : x)
                    r = mult(r, i);
                return r;
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

            public long inv(long value) {
                long g = modulus(), x = 0, y = 1;
                for (long r = value; r != 0; ) {
                    long q = g / r;
                    g %= r;

                    long temp = g;
                    g = r;
                    r = temp;

                    x -= q * y;

                    temp = x;
                    x = y;
                    y = temp;
                }

                ASSERT(g == 1);
                ASSERT(y == modulus() || y == -modulus());

                return normalize(x);
            }

        }

        public static class Mod998 extends NumberTheory.Modulus<NumberTheory.Mod998> {
            public long modulus() {
                return 998_244_353L;
            }

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            HZSShufflesCards solver = new HZSShufflesCards();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class HZSShufflesCards {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();

            Modular mod = new Modular(998244353);
            Power pow = new Power(mod);

            int exp1 = pow.inverse(m + 1);
            exp1 = mod.mul(exp1, n);
            exp1 = mod.plus(exp1, 1);

            InverseNumber inv = new ModPrimeInverseNumber(n, mod);
            int exp2 = 0;
            for (int i = 1; i <= n; i++) {
                exp2 = mod.plus(exp2, inv.inverse(i));
            }
            exp2 = mod.mul(exp2, m);
            exp2 = mod.plus(exp2, 1);

            int ans = mod.mul(exp1, exp2);
            out.println(ans);
        }

    }

    static class ExtGCD {
        public static int extGCD(int a, int b, int[] xy) {
            if (a >= b) {
                return extGCD0(a, b, xy);
            }
            int ans = extGCD0(b, a, xy);
            SequenceUtils.swap(xy, 0, 1);
            return ans;
        }

        private static int extGCD0(int a, int b, int[] xy) {
            if (b == 0) {
                xy[0] = 1;
                xy[1] = 0;
                return a;
            }
            int ans = extGCD0(b, a % b, xy);
            int x = xy[0];
            int y = xy[1];
            xy[0] = y;
            xy[1] = x - a / b * y;
            return ans;
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public int valueOf(int x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return x;
        }

        public int valueOf(long x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return (int) x;
        }

        public int mul(int x, int y) {
            return valueOf((long) x * y);
        }

        public int plus(int x, int y) {
            return valueOf(x + y);
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class ModPrimeInverseNumber implements InverseNumber {
        int[] inv;

        public ModPrimeInverseNumber(int[] inv, int limit, Modular modular) {
            this.inv = inv;
            inv[1] = 1;
            int p = modular.getMod();
            for (int i = 2; i <= limit; i++) {
                int k = p / i;
                int r = p % i;
                inv[i] = modular.mul(-k, inv[r]);
            }
        }

        public ModPrimeInverseNumber(int limit, Modular modular) {
            this(new int[limit + 1], limit, modular);
        }

        public int inverse(int x) {
            return inv[x];
        }

    }

    static class Power implements InverseNumber {
        static IntExtGCDObject extGCD = new IntExtGCDObject();
        final Modular modular;

        public Power(Modular modular) {
            this.modular = modular;
        }

        public int inverse(int x) {
            int ans = inverseExtGCD(x);
//        if(modular.mul(ans, x) != 1){
//            throw new IllegalStateException();
//        }
            return ans;
        }

        public int inverseExtGCD(int x) {
            if (extGCD.extgcd(x, modular.getMod()) != 1) {
                throw new IllegalArgumentException();
            }
            return modular.valueOf(extGCD.getX());
        }

    }

    static interface InverseNumber {
        int inverse(int x);

    }

    static class SequenceUtils {
        public static void swap(int[] data, int i, int j) {
            int tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

    }

    static class IntExtGCDObject {
        private int[] xy = new int[2];

        public int extgcd(int a, int b) {
            return ExtGCD.extGCD(a, b, xy);
        }

        public int getX() {
            return xy[0];
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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);
        HZSShufflesCards solver = new HZSShufflesCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class HZSShufflesCards {
        NumberTheory.Mod998 mod = new NumberTheory.Mod998();
        int n;
        int m;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            mod.fInv(n + m);

            long phaseSize = 1;
            long p = 1;
            for (int i = 0; p != 0; i++) {
                p = mod.mult(p, n - i, mod.smallInv(n + m - i));
                phaseSize = mod.add(phaseSize, p);
            }

            long answer = 0;
            for (int k = 1; k <= n; k++) {
                long term = mod.mult(mod.ncr(n, k), m + k, mod.smallInv(k), phaseSize);

                if (k % 2 == 1)
                    answer = mod.add(answer, term);
                else
                    answer = mod.subtract(answer, term);
            }

            out.println(answer);
        }

    }

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

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

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

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

    }

    static class Util {
        public static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        private Util() {
        }

    }

    static class IntStack {
        int[] array;
        int size = 0;

        public IntStack() {
            this(8);
        }

        public IntStack(int capacity) {
            array = new int[capacity];
        }

        public void push(int item) {
            if (size >= array.length)
                array = resize(array);
            array[size++] = item;
        }

        public int size() {
            return size;
        }

        public int get(int i) {
            Util.ASSERT(i < size);
            return array[i];
        }

        private static int[] resize(int[] array) {
            int[] newArray = new int[array.length << 1];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        public String toString() {
            int[] trimmed = new int[size];
            System.arraycopy(array, 0, trimmed, 0, size);
            return Arrays.toString(trimmed);
        }

    }

    static class NumberTheory {
        private static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            final IntStack factorial = new IntStack();
            final IntStack invFactorial = new IntStack();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.push(1);
                invFactorial.push(1);
            }

            public long fact(int n) {
                while (factorial.size() <= n) {
                    factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));
                }

                return factorial.get(n);
            }

            public long fInv(int n) {
                int lastKnown = invFactorial.size() - 1;

                if (lastKnown < n) {
                    long[] fInv = new long[n - lastKnown];
                    fInv[0] = inv(fact(n));
                    for (int i = 1; i < fInv.length; i++) {
                        fInv[i] = mult(fInv[i - 1], n - i + 1);
                    }
                    for (int i = fInv.length - 1; i >= 0; i--) {
                        invFactorial.push((int) fInv[i]);
                    }
                }

                return invFactorial.get(n);
            }

            public long ncr(int n, int r) {
                ASSERT(n >= 0);
                if (r < 0 || n < r)
                    return 0;
                return mult(fact(n), mult(fInv(r), fInv(n - r)));
            }

            public long smallInv(int n) {
                return mult(fInv(n), fact(n - 1));
            }

            public long normalize(long x) {
                x %= modulus();
                if (x < 0)
                    x += modulus();
                return x;
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

            public long subtract(long a, long b) {
                long v = a - b;
                return v < 0 ? v + modulus() : v;
            }

            public long mult(long... x) {
                long r = 1;
                for (long i : x)
                    r = mult(r, i);
                return r;
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

            public long inv(long value) {
                long g = modulus(), x = 0, y = 1;
                for (long r = value; r != 0; ) {
                    long q = g / r;
                    g %= r;

                    long temp = g;
                    g = r;
                    r = temp;

                    x -= q * y;

                    temp = x;
                    x = y;
                    y = temp;
                }

                ASSERT(g == 1);
                ASSERT(y == modulus() || y == -modulus());

                return normalize(x);
            }

        }

        public static class Mod998 extends NumberTheory.Modulus<NumberTheory.Mod998> {
            public long modulus() {
                return 998_244_353L;
            }

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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);
        HZSShufflesCards solver = new HZSShufflesCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class HZSShufflesCards {
        NumberTheory.Mod998 mod = new NumberTheory.Mod998();
        int n;
        int m;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            mod.fInv(n + m);

            long phaseSize = 1;
            long p = 1;
            for (int i = 0; p != 0; i++) {
                p = mod.mult(p, n - i, mod.smallInv(n + m - i));
                phaseSize = mod.add(phaseSize, p);
            }

            long answer = 0;
            for (int k = 1; k <= n; k++) {
                answer = mod.add(answer, mod.mult(mod.paritySign(k + 1), mod.ncr(n, k), m + k, mod.smallInv(k), phaseSize));
            }

            out.println(answer);
        }

    }

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

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

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

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

    }

    static class Util {
        public static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        private Util() {
        }

    }

    static class IntStack {
        int[] array;
        int size = 0;

        public IntStack() {
            this(8);
        }

        public IntStack(int capacity) {
            array = new int[capacity];
        }

        public void push(int item) {
            if (size >= array.length)
                array = resize(array);
            array[size++] = item;
        }

        public int size() {
            return size;
        }

        public int get(int i) {
            Util.ASSERT(i < size);
            return array[i];
        }

        private static int[] resize(int[] array) {
            int[] newArray = new int[array.length << 1];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        public String toString() {
            int[] trimmed = new int[size];
            System.arraycopy(array, 0, trimmed, 0, size);
            return Arrays.toString(trimmed);
        }

    }

    static class NumberTheory {
        private static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            final IntStack factorial = new IntStack();
            final IntStack invFactorial = new IntStack();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.push(1);
                invFactorial.push(1);
            }

            public long fact(int n) {
                while (factorial.size() <= n) {
                    factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));
                }

                return factorial.get(n);
            }

            public long fInv(int n) {
                int lastKnown = invFactorial.size() - 1;

                if (lastKnown < n) {
                    long[] fInv = new long[n - lastKnown];
                    fInv[0] = inv(fact(n));
                    for (int i = 1; i < fInv.length; i++) {
                        fInv[i] = mult(fInv[i - 1], n - i + 1);
                    }
                    for (int i = fInv.length - 1; i >= 0; i--) {
                        invFactorial.push((int) fInv[i]);
                    }
                }

                return invFactorial.get(n);
            }

            public long paritySign(long k) {
                return (k & 1) == 0 ? 1 : modulus() - 1;
            }

            public long ncr(int n, int r) {
                ASSERT(n >= 0);
                if (r < 0 || n < r)
                    return 0;
                return mult(fact(n), mult(fInv(r), fInv(n - r)));
            }

            public long smallInv(int n) {
                return mult(fInv(n), fact(n - 1));
            }

            public long normalize(long x) {
                x %= modulus();
                if (x < 0)
                    x += modulus();
                return x;
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

            public long mult(long... x) {
                long r = 1;
                for (long i : x)
                    r = mult(r, i);
                return r;
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

            public long inv(long value) {
                long g = modulus(), x = 0, y = 1;
                for (long r = value; r != 0; ) {
                    long q = g / r;
                    g %= r;

                    long temp = g;
                    g = r;
                    r = temp;

                    x -= q * y;

                    temp = x;
                    x = y;
                    y = temp;
                }

                ASSERT(g == 1);
                ASSERT(y == modulus() || y == -modulus());

                return normalize(x);
            }

        }

        public static class Mod998 extends NumberTheory.Modulus<NumberTheory.Mod998> {
            public long modulus() {
                return 998_244_353L;
            }

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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);
        HZSShufflesCards solver = new HZSShufflesCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class HZSShufflesCards {
        NumberTheory.Mod998 mod = new NumberTheory.Mod998();
        int n;
        int m;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            mod.fInv(n + m);

            long phaseSize = 1;
            long p = 1;
            for (int i = 0; p != 0; i++) {
                p = mod.mult(mod.mult(p, n - i), mod.smallInv(n + m - i));
                phaseSize = mod.add(phaseSize, p);
            }

            long answer = 0;
            for (int k = 1; k <= n; k++) {
                long numPhases = mod.mult(m + k, mod.smallInv(k));
                long term = mod.mult(mod.ncr(n, k), mod.mult(numPhases, phaseSize));
                if ((k & 1) == 1)
                    answer = mod.add(answer, term);
                else
                    answer = mod.subtract(answer, term);
            }

            out.println(answer);
        }

    }

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

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

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

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

    }

    static class Util {
        public static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        private Util() {
        }

    }

    static class IntStack {
        int[] array;
        int size = 0;

        public IntStack() {
            this(8);
        }

        public IntStack(int capacity) {
            array = new int[capacity];
        }

        public void push(int item) {
            if (size >= array.length)
                array = resize(array);
            array[size++] = item;
        }

        public int size() {
            return size;
        }

        public int get(int i) {
            Util.ASSERT(i < size);
            return array[i];
        }

        private static int[] resize(int[] array) {
            int[] newArray = new int[array.length << 1];
            System.arraycopy(array, 0, newArray, 0, array.length);
            return newArray;
        }

        public String toString() {
            int[] trimmed = new int[size];
            System.arraycopy(array, 0, trimmed, 0, size);
            return Arrays.toString(trimmed);
        }

    }

    static class NumberTheory {
        private static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            final IntStack factorial = new IntStack();
            final IntStack invFactorial = new IntStack();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.push(1);
                invFactorial.push(1);
            }

            public long fact(int n) {
                while (factorial.size() <= n) {
                    factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));
                }

                return factorial.get(n);
            }

            public long fInv(int n) {
                int lastKnown = invFactorial.size() - 1;

                if (lastKnown < n) {
                    long[] fInv = new long[n - lastKnown];
                    fInv[0] = inv(fact(n));
                    for (int i = 1; i < fInv.length; i++) {
                        fInv[i] = mult(fInv[i - 1], n - i + 1);
                    }
                    for (int i = fInv.length - 1; i >= 0; i--) {
                        invFactorial.push((int) fInv[i]);
                    }
                }

                return invFactorial.get(n);
            }

            public long ncr(int n, int r) {
                ASSERT(n >= 0);
                if (r < 0 || n < r)
                    return 0;
                return mult(fact(n), mult(fInv(r), fInv(n - r)));
            }

            public long smallInv(int n) {
                return mult(fInv(n), fact(n - 1));
            }

            public long normalize(long x) {
                x %= modulus();
                if (x < 0)
                    x += modulus();
                return x;
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

            public long subtract(long a, long b) {
                long v = a - b;
                return v < 0 ? v + modulus() : v;
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

            public long inv(long value) {
                long g = modulus(), x = 0, y = 1;
                for (long r = value; r != 0; ) {
                    long q = g / r;
                    g %= r;

                    long temp = g;
                    g = r;
                    r = temp;

                    x -= q * y;

                    temp = x;
                    x = y;
                    y = temp;
                }

                ASSERT(g == 1);
                ASSERT(y == modulus() || y == -modulus());

                return normalize(x);
            }

        }

        public static class Mod998 extends NumberTheory.Modulus<NumberTheory.Mod998> {
            public long modulus() {
                return 998_244_353L;
            }

        }

    }
}


import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.util.Set;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.util.NavigableMap;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.SortedMap;
import java.io.InputStream;

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

class TaskE {

    static final int MOD = 1000000007;

    public void solve(int testNumber, FastScanner in, FastPrinter out) {
        int n = in.nextInt();
        int p = in.nextInt();
        NavigableMap<Integer, Integer> g = new TreeMap<Integer, Integer>();
        g.put(1, 0);
        g.put(3, 1);
        int lastG = 1;
        for (int d = 3; d < p - 1; ) {
            int a = d / 3;
            int b = d - d / 3;
            Integer na = g.higherKey(a);
            Integer nb = g.higherKey(b);
            long z1 = na * 3L;
            long z2 = 3L * nb / 2;
            while (z2 - z2 / 3 >= nb) {
                z2--;
            }
            while (z2 - z2 / 3 < nb) {
                ++z2;
            }
            long z = Math.min(z1, z2);
            if (z > p - 1) {
                break;
            }
            int zi = (int) z;
            int ga = g.get(g.floorKey(zi / 3));
            int gb = g.get(g.floorKey(zi - zi / 3));
            int ng = -1;
            for (int j = 0; j < 3; j++) {
                if (j == ga || j == gb) {
                    continue;
                }
                ng = j;
                break;
            }
            if (ng != lastG) {
                g.put(zi, ng);
            }
            lastG = ng;
            d = zi;
        }
        long[] count = new long[3];
        for (int i : g.keySet()) {
            Integer ni = g.higherKey(i);
            if (ni == null) {
                ni = p;
            }
            int first = p - i;
            int second = p - ni;
            count[g.get(i)] += s(second + 1, first + 1);
        }
        for (int i = 0; i < 3; i++) {
            count[i] %= MOD;
        }
        int[][] dp = new int[n + 1][4];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int x = 0; x < 3; x++) {
                for (int y = 0; y < 4; y++) {
                    dp[i][x ^ y] = (int) ((dp[i][x ^ y] + (long) dp[i - 1][y] * count[x]) % MOD);
                }
            }
        }
        long ans = 0L + dp[n][1] + dp[n][2] + dp[n][3];
        out.println(ans % MOD);
    }

    static long s(int a, int b) {
        if (a >= b) {
            return 0;
        }
        --b;
        --a;
        long ret = ss(b) - ss(a);
        return ret;
    }

    static long ss(int n) {
        return (long) n * (n + 1) / 2;
    }
}

class FastScanner extends BufferedReader {

    boolean isEOF;

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
            if (isEOF && ret < 0) {
                throw new InputMismatchException();
            }
            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= -1 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (!isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    }

class FastPrinter extends PrintWriter {

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

    public FastPrinter(Writer out) {
        super(out);
    }

}


import java.util.*;
public class CodeforcesD268 {
	public static int[][][][][] memo;
	public static int n, h;
	public static int mod = 1000000009;
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		n = br.nextInt();
		h = br.nextInt();

		memo = new int[2][h+1][h+1][h+1][n];
		for(int i = 0;i<2;i++){
			for(int j = 0;j<h+1;j++){
				for(int k = 0;k<h+1;k++){
					for(int l = 0;l<h+1;l++){
						Arrays.fill(memo[i][j][k][l], -1);
					}
				}
			}
		}
		System.out.println(go(0, new int[3], 0));
	}
	public static int go(int flag, int[] lasts, int pos){
		for(int i = 0;i<lasts.length;i++){
			lasts[i] = Math.min(lasts[i], h);
		}
		int last1 = (flag == 0 ? 0 : h);
		int last2 = lasts[0];
		int last3 = lasts[1];
		int last4 = lasts[2];
		if(last1 < h || last2 < h || last3 < h || last4 < h){

		}
		else{
			return 0;
		}
		if(pos == n){

			if(last1 < h || last2 < h || last3 < h || last4 < h){
				return 1;
			}
			return 0;
		}

		if(memo[flag][last2][last3][last4][pos] != -1){
			return memo[flag][last2][last3][last4][pos];
		}

		int ans = 0;
		ans+=go(flag, new int[]{last2+1, last3+1, last4+1}, pos+1);
		ans%=mod;

		//Place second
		ans+=go((last2 == h) ? 1 : 0, new int[]{last1+1, last3+1, last4+1}, pos+1);
		ans%=mod;

		//Place third
		ans+=go((last3 == h) ? 1 : 0, new int[]{last1+1, last2+1, last4+1}, pos+1);
		ans%=mod;

		//Place fourth
		ans+=go((last4 == h) ? 1 : 0, new int[]{last1+1, last2+1, last3+1}, pos+1);
		ans%=mod;

		return memo[flag][last2][last3][last4][pos] = ans;
	}
}


import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;

// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

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

        String Str(){
            return next();
        }
    }

    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        //reading /writing file
        //Scanner in=new Scanner(System.in);
        //Scanner in=new Scanner(new File("input.txt"));
        //PrintWriter pr=new PrintWriter("output.txt");

        int T=1;
        for(int t=0;t<T;t++){
            Solution sol1=new Solution(out,fs);
            sol1.solution(T,t);
        }
        out.flush();

    }

    public static int[] Arr(int n){
        int A[]=new int[n];
        for(int i=0;i<n;i++)A[i]=Int();
        return A;
    }
    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}

class Solution {
    PrintWriter out;
    int INF = Integer.MAX_VALUE;
    int NINF = Integer.MIN_VALUE;
    int MOD = 998244353;
    int mod = 1000000007;
    Main.FastScanner fs;

    public Solution(PrintWriter out, Main.FastScanner fs) {
        this.out = out;
        this.fs = fs;

    }

    public void solution(int all, int testcase) {
        int n = fs.Int();
        mod = fs.Int();

        long dp[][] = new long[n][n * n + 5];
        dp[0][0] = 1;
        for(int i = 1; i < n; i++) {
            for(int j = 0; j < dp[0].length; j++) {
                for(int cnt = 0; cnt <= i; cnt++){
                    if(j - cnt >= 0) {
                        dp[i][j] += dp[i - 1][j - cnt];
                        dp[i][j] %= mod;
                        if(dp[i][j] == 0){
                            dp[i][j] += mod;
                        }
                    }
                }
            }
        }

        long sums[][] = new long[dp.length][dp[0].length];
        for(int i = 0; i < dp.length;i++){
            int sum = 0;
            for(int j = 0; j < dp[0].length; j++){
                sum += dp[i][j];
                sum %= mod;
                if(sum == 0) sum += mod;
                sums[i][j] = sum;
            }
        }

        //init
        long fact[] = new long[501 * 501];
        fact[0] = fact[1] = 1;
        for(int i = 2; i < fact.length;i++){
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }
        long ncr[][] = new long[501][501];
        ncr[0][0]=1;
        for (int i=1;i<ncr.length;i++) {
            ncr[i][0]=1;
            for (int j=1;j<ncr[0].length;j++) {
                ncr[i][j]=(ncr[i-1][j] + ncr[i-1][j-1])%mod;
                if(ncr[i][j] == 0)ncr[i][j] += mod;
            }
        }
        //

        long res = 0;
        for(int i = n - 2; i >= 0; i--) {
            int cnt = n - i;
            int pre = n - cnt;
            long com = (ncr[n][pre] * fact[pre]) % mod;
            if(com == 0) com += mod;
            long sum = 0;

            for(int dif = 1; dif < cnt; dif++){
                for(int inv = dif; inv < dp[0].length; inv++){
                    if(dp[cnt - 1][inv] == 0){
                        break;
                    }
                    if(inv - dif - 1 < 0)continue;
                    long x = dp[cnt - 2][inv];
                    long y = sums[cnt - 2][inv - dif - 1];
                    x *= y;
                    x %= mod;
                    if(x == 0) x += mod;
                    sum += x * (cnt - dif);
                    sum %= mod;
                }
            }
            res += sum * com;
            res%=mod;
            if(res == 0) res += mod;
        }

        out.println(res % mod);
    }

}


import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;

// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

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

        String Str(){
            return next();
        }
    }

    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        //reading /writing file
        //Scanner in=new Scanner(System.in);
        //Scanner in=new Scanner(new File("input.txt"));
        //PrintWriter pr=new PrintWriter("output.txt");

        int T=1;
        for(int t=0;t<T;t++){
            Solution sol1=new Solution(out,fs);
            sol1.solution(T,t);
        }
        out.flush();

    }

    public static int[] Arr(int n){
        int A[]=new int[n];
        for(int i=0;i<n;i++)A[i]=Int();
        return A;
    }
    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}

class Solution {
    PrintWriter out;
    int INF = Integer.MAX_VALUE;
    int NINF = Integer.MIN_VALUE;
    int MOD = 998244353;
    int mod = 1000000007;
    Main.FastScanner fs;

    public Solution(PrintWriter out, Main.FastScanner fs) {
        this.out = out;
        this.fs = fs;

    }

    public void solution(int all, int testcase) {
        int n = fs.Int();
        mod = fs.Int();

        long dp[][] = new long[n][n * n + 5];
        dp[0][0] = 1;
        for(int i = 1; i < n; i++) {
            for(int j = 0; j < dp[0].length; j++) {
                for(int cnt = 0; cnt <= i; cnt++){
                    if(j - cnt >= 0) {
                        dp[i][j] += dp[i - 1][j - cnt];
                        dp[i][j] %= mod;
                        if(dp[i][j] == 0){
                            dp[i][j] += mod;
                        }
                    }
                }
            }
        }

        long sums[][] = new long[dp.length][dp[0].length];
        for(int i = 0; i < dp.length;i++){
            int sum = 0;
            for(int j = 0; j < dp[0].length; j++){
                sum += dp[i][j];
                sum %= mod;
                if(sum == 0) sum += mod;
                sums[i][j] = sum;
            }
        }

        //init
        long fact[] = new long[501 * 501];
        fact[0] = fact[1] = 1;
        for(int i = 2; i < fact.length;i++){
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }
        long ncr[][] = new long[501][501];
        ncr[0][0]=1;
        for (int i=1;i<ncr.length;i++) {
            ncr[i][0]=1;
            for (int j=1;j<ncr[0].length;j++) {
                ncr[i][j]=(ncr[i-1][j] + ncr[i-1][j-1])%mod;
                if(ncr[i][j] == 0)ncr[i][j] += mod;
            }
        }

        long res = 0;
        for(int i = 0; i <= n - 2; i++) {
            int cnt = n - i;
            int pre = n - cnt;
            long com = (ncr[n][pre] * fact[pre]) % mod;
            if(com == 0) com += mod;
            long sum = 0;

            long last[] = dp[cnt - 2];
            long ssum = 0;
            long total =0;
            for(int j = 2; j < dp[0].length; j++) { // j == inversions
                total += sums[cnt - 2][j - 2] * (cnt - 1);
                total %= mod;
                if(total == 0) total += mod;

                sum += last[j] * total;
                sum %= mod;
                if(sum == 0) sum += mod;

                ssum += sums[cnt - 2][j - 2];
                if(j - cnt - 1 >= 0) {
                    ssum -= sums[cnt - 2][j - cnt - 1];
                }
                ssum += mod;
                ssum %= mod;
                if(ssum == 0) ssum += mod;

                total -= ssum;
                total += mod;
                total %= mod;
                if(total == 0)total += mod;
            }
            res += sum * com;
            res%=mod;
            if(res == 0) res += mod;
        }
        out.println(res % mod);
    }
}


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

import static java.lang.Integer.min;
import static java.lang.Integer.max;

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

        solve(s.nextInt(), s.nextInt());
    }

    public static void solve(int n, int mod) {
        ArrayList<long[]> inversions = new ArrayList<>();
        inversions.add(new long[]{1});

        long last[];
        long next[];
        for (int i = 1; i < n; i++) {
            last = inversions.get(i - 1);
            next = new long[i * (i + 1) / 2 + 1];

            int e;
            for (int j = 0; j < next.length; j++) {
                e = 0;
                for (int k = min(j, i); k >= 0; k--) {
                    if (j - k < last.length) {
                        e += last[j - k];
                        e = e % mod;
                    }
                }
                next[j] = e;
            }

            inversions.add(next);
        }

        for (int i = 0; i < n; i++) {
            //System.out.println(Arrays.toString(inversions.get(i)));
        }

        long perms[] = new long[n];
        perms[0] = 0;

        long c;
        long inv[];
        long m;
        for (int i = 1; i < n; i++) {
            c = (perms[i - 1] * (i + 1)) % mod;

            inv = inversions.get(i - 1);
            for (int j = 0; j < inv.length; j++) {
                for (int k = j + 2; k < inv.length; k++) {
                    m = min(k - j, i + 1);
                    c = (c + ((inv[j] * inv[k]) % mod) * ((m - 1) * (2 * i - (m - 2)) / 2)) % mod;
                }
            }

            perms[i] = c;
        }

        //System.out.println(Arrays.toString(perms));
        System.out.println(perms[n - 1]);
    }
}


import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;

// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

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

        String Str(){
            return next();
        }
    }

    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        //reading /writing file
        //Scanner in=new Scanner(System.in);
        //Scanner in=new Scanner(new File("input.txt"));
        //PrintWriter pr=new PrintWriter("output.txt");

        int T=1;
        for(int t=0;t<T;t++){
            Solution sol1=new Solution(out,fs);
            sol1.solution(T,t);
        }
        out.flush();

    }

    public static int[] Arr(int n){
        int A[]=new int[n];
        for(int i=0;i<n;i++)A[i]=Int();
        return A;
    }
    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}

class Solution {
    PrintWriter out;
    int INF = Integer.MAX_VALUE;
    int NINF = Integer.MIN_VALUE;
    int MOD = 998244353;
    int mod = 1000000007;
    Main.FastScanner fs;

    public Solution(PrintWriter out, Main.FastScanner fs) {
        this.out = out;
        this.fs = fs;

    }

    public void solution(int all, int testcase) {
        int n = fs.Int();
        mod = fs.Int();

        long dp[][] = new long[n][n * n + 5];
        dp[0][0] = 1;
        for(int i = 1; i < n; i++) {
            for(int j = 0; j < dp[0].length; j++) {
                for(int cnt = 0; cnt <= i; cnt++){
                    if(j - cnt >= 0) {
                        dp[i][j] += dp[i - 1][j - cnt];
                        dp[i][j] %= mod;
                        if(dp[i][j] == 0){
                            dp[i][j] += mod;
                        }
                    }
                }
            }
        }

        long sums[][] = new long[dp.length][dp[0].length];
        for(int i = 0; i < dp.length;i++){
            int sum = 0;
            for(int j = 0; j < dp[0].length; j++){
                sum += dp[i][j];
                sum %= mod;
                if(sum == 0) sum += mod;
                sums[i][j] = sum;
            }
        }

        //init
        long fact[] = new long[501 * 501];
        fact[0] = fact[1] = 1;
        for(int i = 2; i < fact.length;i++){
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }
        long ncr[][] = new long[501][501];
        ncr[0][0]=1;
        for (int i=1;i<ncr.length;i++) {
            ncr[i][0]=1;
            for (int j=1;j<ncr[0].length;j++) {
                ncr[i][j]=(ncr[i-1][j] + ncr[i-1][j-1])%mod;
                if(ncr[i][j] == 0)ncr[i][j] += mod;
            }
        }
        //

        long res = 0;
        for(int i = n - 2; i >= 0; i--) {
            int cnt = n - i;
            int pre = n - cnt;
            long com = (ncr[n][pre] * fact[pre]) % mod;
            if(com == 0) com += mod;
            long sum = 0;

            for(int dif = 1; dif < cnt; dif++){
                for(int inv = dif; inv < dp[0].length; inv++){
                    if(dp[cnt - 2][inv] == 0){
                        break;
                    }
                    if(inv - dif - 1 < 0)continue;
                    long x = dp[cnt - 2][inv];
                    long y = sums[cnt - 2][inv - dif - 1];
                    x *= y;
                    x %= mod;
                    if(x == 0) x += mod;
                    sum += x * (cnt - dif);
                    sum %= mod;
                }
            }
            res += sum * com;
            res%=mod;
            if(res == 0) res += mod;
        }

        out.println(res % mod);
    }

}


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

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

    static class E2AbnormalPermutationPairsHardVersion {
        ModInt mod;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            mod = new ModInt(m);
            int[] factorial = new int[n + 1];
            factorial[0] = n;
            for (int i = 1; i < n; i++) factorial[i] = mod.multiply(factorial[i - 1], n - i);
            int[] dp = new int[n * (n - 1) + 1];
            int middle = (n * (n - 1)) / 2;
            int[] temp = dp.clone();
            dp[middle] = 1;
            int answer = 0;
            for (int i = n - 1; i >= 0; i--) {
                int c = n - 1 - i;
                temp = dp.clone();
                Arrays.fill(dp, 0);
                int limit = (c * (c - 1)) / 2;
                int count = 0;
                for (int cur = -c; cur < 0; cur++) {
                    int pairs = c + cur + 1;
                    for (int j = middle - cur + 1; j <= middle + limit; j++)
                        count = mod.add(count, mod.multiply(temp[j], pairs));
                }
                answer = mod.add(answer, mod.multiply(count, i == 0 ? 1 : factorial[i - 1]));
                for (int j = middle - limit; j <= middle + limit; j++) {
                    for (int cur = -c; cur <= c; cur++) {
                        int pairs = c - Math.abs(cur) + 1;
                        dp[j + cur] = mod.add(dp[j + cur], mod.multiply(pairs, temp[j]));
                    }
                }
            }
            out.println(answer);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

    static class ModInt {
        int modulo;

        public ModInt(int m) {
            modulo = m;
        }

        public int add(int x, int y) {
            x += y;
            if (x >= modulo) x -= modulo;
            return x;
        }

        public int multiply(int x, int y) {
            return (int) ((x * 1L * y) % modulo);
        }

    }

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

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

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

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

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

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

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

        }

    }
}


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

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

class TaskE {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        // [x y dx dy 1]
        long n = in.nextLong();

        long sx = ((in.nextLong() - 1) % n + n) % n;
        long sy = ((in.nextLong() - 1) % n + n) % n;
        long dx = (in.nextLong() % n + n) % n;
        long dy = (in.nextLong() % n + n) % n;

        long t = in.nextLong();

        Matrix move = Matrix.getUnitMatrix(6);
        long[][] mat = move.arr;
        mat[0][2] = 1;
        mat[1][2] = 1;
        mat[0][3] = 1;
        mat[1][3] = 1;

        mat[2][0] = 1;
        mat[3][1] = 1;

        mat[0][0] = 2;
        mat[1][0] = 1;
        mat[0][1] = 1;
        mat[1][1] = 2;

        mat[4][2] = 1;
        mat[4][3] = 1;
        mat[4][0] = 1;
        mat[4][1] = 1;

        mat[5][4] = 1;

        Matrix result = NumberUtils.powMod(move, t, n);

        // [sx sy dx dy 1]
        mat = result.arr;
        long x = (sx * mat[0][0] + sy * mat[1][0] + dx * mat[2][0] + dy * mat[3][0] + 2 * mat[4][0] + mat[5][0]) % n;
        long y = (sx * mat[0][1] + sy * mat[1][1] + dx * mat[2][1] + dy * mat[3][1] + 2 * mat[4][1] + mat[5][1]) % n;

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

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

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

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

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

    }

class Matrix {

    public long[][] arr;

    public Matrix(int size) {
        arr = new long[size][size];
    }

    public Matrix(long[][] arr) {
        if (arr.length != arr[0].length) {
            throw new IllegalArgumentException();
        }
        this.arr = new long[arr.length][arr.length];
        for (int i = 0; i < arr.length; ++i) {
            System.arraycopy(arr[i], 0, this.arr[i], 0, arr.length);
        }
    }

    public Matrix(int[][] arr) {
        if (arr.length != arr[0].length) {
            throw new IllegalArgumentException();
        }
        this.arr = new long[arr.length][arr.length];
        for (int i = 0; i < arr.length; ++i) {
            for (int j = 0; j < arr.length; ++j) {
                this.arr[i][j] = arr[i][j];
            }
        }
    }

    public Matrix multiply(Matrix to, Long mod) {
        if (arr.length != to.arr.length) {
            throw new IllegalArgumentException();
        }

        Matrix res = new Matrix(arr.length);
        for (int k = 0; k < arr.length; ++k) {
            for (int i = 0; i < arr.length; ++i) {
                if (arr[i][k] == 0) continue;
                for (int j = 0; j < arr.length; ++j) {
                    res.arr[i][j] += arr[i][k] * to.arr[k][j];
                    if (mod != null && res.arr[i][j] >= mod) {
                        res.arr[i][j] %= mod;
                    }
                }
            }
        }

        return res;
    }

    public int size() {
        return arr.length;
    }

    public static Matrix getUnitMatrix(int size) {
        Matrix matrix = new Matrix(size);
        for (int i = 0; i < size; ++i) {
            matrix.arr[i][i] = 1;
        }
        return matrix;
    }

    public String toString() {
        return Arrays.deepToString(arr);
    }
}

class NumberUtils {

    public static Matrix powMod(Matrix mat, long p, long mod) {

        if (p == 0) {
            return Matrix.getUnitMatrix(mat.size());
        }

        if (p == 1) {
            return mat;
        }

        if (p % 2 == 0) {
            Matrix res = powMod(mat, p / 2, mod);
            return res.multiply(res, mod);
        }

        return powMod(mat, p - 1, mod).multiply(mat, mod);
    }

    }


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

public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskE solver = new TaskE();
    solver.solve(1, in, out);
    out.close();
  }
}

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

class InputReader {

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

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

  public int read() {
    if (numChars == -1)
      throw new InputMismatchException();
    if (curChar >= numChars) {
      curChar = 0;
      try {
        numChars = stream.read(buf);
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      if (numChars <= 0)
        return -1;
    }
    return buf[curChar++];
  }

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

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

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

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

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

class OutputWriter {
  private final PrintWriter writer;

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

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

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

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

}

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

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

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

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

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

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

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

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

class TaskE {
   /////////////////////////////////////////////////////////////
   static int mod;

    public void solve(int testNumber, FastScanner in, FastPrinter out) {
    long n=in.nextLong();
        mod=(int)n;
        int sx=in.nextInt(),sy=in.nextInt();
        long dx=in.nextInt(),dy=in.nextInt(),t=in.nextLong();
     int[][] A={{2,1,1,1,0,0},
             {1,2,1,1,0,0},
             {1,0,1,0,0,0},
             {0,1,0,1,0,0},
             {1,1,1,1,1,0},
             {0,0,0,0,1,1}
     };
        int[][] B={{sx,sy,(int)dx,(int)dy,0,1},
                {1,2,1,1,0,0},
                {1,0,1,0,0,0},
                {0,1,0,1,0,0},
                {1,1,1,1,1,0},
                {0,0,0,0,1,1}
        };
        Matrix base= new Matrix(A),init= new Matrix(B);
        Matrix fin=Matrix.powMod(base,t,mod);
        Matrix ans= init.multiplyMod(fin,mod);
        int x=ans.get(0,0),y=ans.get(0,1);
        if(x<0)x+=mod;
        if(y<0)y+=mod;
        if(x==0)x=mod;
        if(y==0)y=mod;

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

    }
}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    public String next() {
        StringBuilder sb = new StringBuilder();
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        if (c < 0) {
            return null;
        }
        while (c >= 0 && !isWhiteSpace(c)) {
            sb.appendCodePoint(c);
            c = read();
        }
        return sb.toString();
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (c >= 0 && !isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

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

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    }

class FastPrinter extends PrintWriter {

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

    public FastPrinter(Writer out) {
        super(out);
    }

}

class Matrix {
    final int[][] a;
    public final int n;
    public final int m;

    public Matrix(int n, int m) {
        this.n = n;
        this.m = m;
        a = new int[n][m];
    }

    public Matrix(int n) {
        this(n, n);
    }

    public Matrix(int[][] a) {
        n = a.length;
        if (n == 0) {
            throw new AssertionError();
        }
        m = a[0].length;
        this.a = new int[n][];
        for (int i = 0; i < n; i++) {
            if (m != a[i].length) {
                throw new AssertionError();
            }
            this.a[i] = a[i].clone();
        }
    }

    public int get(int x, int y) {
        return a[x][y];
    }

    public static Matrix getOne(int n) {
        Matrix ret = new Matrix(n);
        for (int i = 0; i < n; i++) {
            ret.a[i][i] = 1;
        }
        return ret;
    }

    public Matrix multiplyMod(Matrix b, int mod) {
        if (m != b.n) {
            throw new AssertionError();
        }
        Matrix ret = new Matrix(n, b.m);
        long modmod = (long) mod * mod;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < b.m; j++) {
                long d = 0;
                for (int k = 0; k < m; k++) {
                    d = (d + (long) a[i][k] * b.a[k][j]);
                    if (d >= modmod) {
                        d -= modmod;
                    }
                }
                ret.a[i][j] = (int) (d % mod);
            }
        }
        return ret;
    }

    public static Matrix powMod(Matrix a, long b, int mod) {
        if (a.n != a.m) {
            throw new AssertionError();
        }
        Matrix ret = getOne(a.n);
        while (b > 0) {
            if ((b & 1) == 1) {
                ret = ret.multiplyMod(a, mod);
            }
            a = a.multiplyMod(a, mod);
            b >>= 1;
        }
        return ret;
    }

    }


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

public class Main {
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

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

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

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

    static void print(Matrix a) {
        for (int i = 0; i < a.n; ++i) {
            for (int j = 0; j < a.n; ++j) {
                out.print(a.a[i][j] + " ");
            }
            out.println();
        }
    }

    static int mod, n;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        mod = nextInt();
        n = 6;
        int[] u = new int[n];
        u[0] = nextInt() - 1;
        u[1] = nextInt() - 1;
        u[2] = (nextInt() % mod + mod) % mod;
        u[3] = (nextInt() % mod + mod) % mod;
        u[4] = 2;
        u[5] = 1;
        long t = nextLong();
        if (t == 0) {
            out.println((u[0] + 1) + " " + (u[1] + 1));
        } else {
            Matrix res = new Matrix(n, mod);
            Matrix a = new Matrix(n, mod);
            // print(res);
            t--;
            while (t > 0) {
                if (t % 2 == 1) {
                    res = res.mult(a);
                }
                t /= 2;
                a = a.mult(a);
            }
            for (int i = 0; i < 2; ++i) {
                if (i > 0) {
                    out.print(' ');
                }
                int x = 0;
                for (int j = 0; j < n; ++j) {
                    x = (int)((1L * res.a[i][j] * u[j] + x) % mod);
                }
                out.print(x + 1);
            }
            out.println();
        }
        out.close();
    }

}

class Matrix {
    int n, mod;
    int[][] a;
    Matrix(int n, int mod) {
        this.n = n;
        this.mod = mod;
        a = new int[n][n];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                a[i][j] = 1;
            }
        }
        a[0][3] = a[1][2] = a[2][3] = a[3][2] = 0;
        a[4][0] = a[4][1] = a[4][2] = a[4][3] = 0;
        a[0][5] = a[1][5] = a[2][5] = a[3][5] = 0;
        a[5][0] = a[5][1] = a[5][2] = a[5][3] = a[5][4] = 0;
        a[0][0] = a[1][1] = 2;
    }

    Matrix mult(Matrix b) {
        Matrix res = new Matrix(n, mod);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                res.a[i][j] = 0;
                for (int k = 0; k < n; ++k) {
                    res.a[i][j] = (int)((1L * a[i][k] * b.a[k][j] + res.a[i][j]) % mod);
                }
            }
        }
        return res;
    }

}