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.HashSet;
import java.util.Scanner;

public class Elementary {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        HashSet<String> table = new HashSet<>();

        String[] arr = {"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl",
                "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se",
                "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb",
                "Te", "I", "Xe", "Cs", "Ba", "La", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb",
                "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ce", "Pr", "Nd", "Pm",
                "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm",
                "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh",
                "Fl", "Mc", "Lv", "Ts", "Og"};

        for (String value : arr) table.add(value.toUpperCase());

        String str = in.nextLine();
        int[] found = new int[str.length()];

        boolean haha = true;

        if (str.length() == 1) {
            System.out.println(table.contains(str) ? "YES" : "NO");
        } else {

            for (int i = 0; i < str.length(); i++) {
                if (table.contains(str.charAt(i) + ""))
                    found[i] = 1;
                if (i + 1 < str.length() && table.contains(str.charAt(i) + "" + str.charAt(i + 1)))
                    found[i] = found[i + 1] = 1;
            }

            for (int value : found)
                if (value == 0) {
                    haha = false;
                    break;
                }

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


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

}


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

public class E implements Runnable {

	final long[][] E = { { 1, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0, 0}, { 0, 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 0, 1 } };
	private void solve() throws IOException {
		long n = nextLong(), sx = nextLong() - 1, sy = nextLong() - 1;
		long dx = ((nextLong() % n) + n) % n, dy = ((nextLong() % n) + n) % n, t = nextLong();
		long[][] start = { { sx, sy, dx, dy, 0, 1 } };
		long[][] next = { { 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 }, { 2, 2, 2, 2, 1, 1 } };
		long[][] end = matrixMultiplication(start, binaryMatrixPower(next, t, n), n);
		print(end[0][0] + 1, end[0][1] + 1);
	}

	long[][] binaryMatrixPower(long[][] a, long pow, long MOD) {
		if (pow == 0) return E;
		if ((pow & 1) == 0) {
			long[][] res = binaryMatrixPower(a, pow >> 1, MOD);
			return matrixMultiplication(res, res, MOD);
		} else {
			long[][] res = binaryMatrixPower(a, pow - 1, MOD);
			return matrixMultiplication(res, a, MOD);
		}
	}

	long[][] matrixMultiplication(long[][] a, long[][] b, long MOD) {
		int n = a.length, m = a[0].length, q = b.length, p = b[0].length;
		long[][] res = new long[n][p];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < p; j++)
				for (int k = 0; k < m; k++) {
					res[i][j] += a[i][k] * b[k][j];
					res[i][j] %= MOD;
				}
		return res;
	}

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

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}

	void halt() {
		writer.close();
		System.exit(0);
	}

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

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

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

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(nextLine());
		return tokenizer.nextToken();
	}

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

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

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


import java.util.Scanner;

public class E {
    static int mod;

    public static long[][] identity() {
        long[][] a = new long[6][6];
        for (int i = 0; i < 6; i++)
            a[i][i] = 1;
        return a;
    }

    public static long[][] modMul(long[][] A, long[][] B) {
        long[][] C = new long[6][6];
        for (int i = 0; i < 6; i++)
            for (int j = 0; j < 6; j++)
                for (int k = 0; k < 6; k++)
                    C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % mod) % mod;
        return C;
    }

    public static long[][] modPow(long[][] M, long p) {
        if (p == 0)
            return identity();
        long[][] temp = modPow(M, p >> 1);
        temp = modMul(temp, temp);
        if ((p & 1) != 0)
            temp = modMul(M, temp);
        return temp;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        mod = in.nextInt();
        long x = in.nextLong() - 1;
        long y = in.nextLong() - 1;
        long dx = (in.nextLong() % mod + mod) % mod;
        long dy = (in.nextLong() % mod + mod) % mod;
        long t = in.nextLong();
        long[][] a = { { 2, 1, 1, 0, 1, 2 }, { 1, 2, 0, 1, 1, 2 },
                { 1, 1, 1, 0, 1, 2 }, { 1, 1, 0, 1, 1, 2 },
                { 0, 0, 0, 0, 1, 1 }, { 0, 0, 0, 0, 0, 1 } };
        long[][] ans = modPow(a, t);
        long[] v = { x, y, dx, dy, 0, 1 };
        long ansX = 0;
        long ansY = 0;
        for (int i = 0; i < 6; i++) {
            ansX = (ansX + (ans[0][i] * v[i]) % mod) % mod;
            ansY = (ansY + (ans[1][i] * v[i]) % mod) % mod;
        }
        System.out.println((ansX + 1) + " " + (ansY + 1));
    }
}


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

public class BearAndRaspberries {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		sx = sc.nextInt();
		sy = sc.nextInt();
		dx = sc.nextInt();
		dy = sc.nextInt();
		T = sc.nextLong();
		String[] S = new String[]{"100001", "021110", "012110", "010100", "001010", "011111"};
		int[][] M = new int[6][6];
		for(int i=0; i<6; i++){
			for(int j=0; j<6; j++){
				M[i][j] = (int) (S[i].charAt(j)-'0');
			}
		}
		int[][] power = pow(M, T);
		int[][] initial = new int[1][6];
		initial[0] = new int[]{1, sx, sy, dx, dy, 0};
		int[][] result = multiply(initial, power);
		System.out.println(format(result[0][1])+" "+format(result[0][2]));
	}

	static int format(int x){
		return x!=0 ? x : n;
	}

	static int[][] pow(int[][] A, long p){
		if(p==0) return getIdentity(A.length);
		if(p==1) return A;
		int[][] H = pow(A, p>>1);
		H = multiply(H, H);
		return p%2==0 ? H : multiply(A, H);
	}

	static int[][] getIdentity(int len){
		int[][] res = new int[len][len];
		for(int i=0; i<res.length; i++){
			res[i][i] = 1;
		}
		return res;
	}

	static int[][] multiply(int[][] a, int[][] b){ // a[0].length = b.length
		int[][] res = new int[a.length][b[0].length];
		for(int i=0; i<a.length; i++){
			for(int j=0; j<b[0].length; j++){
				long ans = 0;
				for(int k=0; k<a[0].length; k++){
					ans += (1L * a[i][k] * 1L * b[k][j])%n;
				}
				if(ans < 0) ans += 1L*n*1000000000;
				ans %= n;
				res[i][j] = (int) ans;
			}
		}
		return res;
	}

	static int n, sx, sy, dx, dy;

	static long T;

}


public class E {

	private final static boolean autoflush = false;

	long [][] A = {
			{ 1, 0, 0, 0, 0, 0 },
			{ 1, 1, 0, 0, 0, 0 },
			{ 2, 1, 2, 1, 1, 0 },
			{ 2, 1, 1, 2, 0, 1 },
			{ 2, 1, 1, 1, 1, 0 },
			{ 2, 1, 1, 1, 0, 1 }
	};

	public E () {
		int N = sc.nextInt();
		int X = sc.nextInt() - 1;
		int Y = sc.nextInt() - 1;
		int VX = sc.nextInt();
		int VY = sc.nextInt();
		long T = sc.nextLong();

		long [] V = { 1, 0, X, Y, VX, VY };
		long [] W = prod(pow(A, T, N), V, N);
		exit(W[2] + 1, W[3] + 1);
	}

	long [] prod(long [][] A, long [] V, long mod) {
		long [][] W = new long [V.length][1];
		for (int i : rep(V.length))
			W[i][0] = V[i];
		long [][] X = prod(A, W, mod);
		long [] res = new long [X.length];
		for (int i : rep(X.length))
			res[i] = X[i][0];
		return res;
	}

	long [][] sum (long [][] A, long [][] B, long mod) {
		int M = A.length, K = A[0].length, N = B[0].length;
		assert(K == B.length);
		long [][] res = new long [M][N];

		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				res[i][j] = mod(A[i][j] + B[i][j], mod);
		return res;
	}

	long [][] prod (long [][] A, long [][] B, long mod) {
		int M = A.length, K = A[0].length, N = B[0].length;
		assert(K == B.length);
		long [][] res = new long [M][N];

		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				for (int k = 0; k < K; ++k)
					res[i][j] = mod(res[i][j] + A[i][k] * B[k][j], mod);
		return res;
	}

	long [][] pow (long [][] A, long e, long mod) {
		long [][] res = id(A.length);
		if (e > 0) {
			int M = 1 + Long.numberOfTrailingZeros(Long.highestOneBit(e));
			long [][][] P = new long[M][][]; P[0] = A;
			for (int i : rep(1, M))
				P[i] = prod(P[i-1], P[i-1], mod);
			for (int i : rep(M))
				if ((e & (1L << i)) != 0)
					res = prod(res, P[i], mod);
		}
		return res;
	}

	long [][] id (int N) {
		long [][] res = new long [N][N];
		for (int i : rep(N))
			res[i][i] = 1;
		return res;
	}

	///////////////////////////////////////////////////////////////////////////
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		public String next() { newLine(); return line[index++]; }
		public int nextInt() { return Integer.parseInt(next()); }
		public long nextLong() { return Long.parseLong(next()); }
		//////////////////////////////////////////////
		private boolean eol() { return index == line.length; }
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) { printDelim(" ", o, a); }
	private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
	private static void exit (Object o, Object... a) { print(o, a); exit(); }
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.substring(delim.length());
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() { t = millis(); }
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() { return System.currentTimeMillis(); }
	public static void main (String[] args) { new E(); exit(); }
}


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;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Árysson Cavalcanti
 */
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.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;

public class Main {
    public static void main(String[] args) throws IOException {
        new Solver().run();
    }
}

class Solver {
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        //in = new BufferedReader(new FileReader("division.in"));
        //out = new PrintWriter(new File("division.out"));
        solve();
        out.close();
    }

    long n;

    public void solve() throws IOException {
        long[][] mat = {
                {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},
                {1, 1, 1, 1, 1, 1}
        };

        n = nextLong();
        long x = nextLong() - 1;
        long y = nextLong() - 1;
        long dx = nextLong();
        long dy = nextLong();
        long t = nextLong();
        dx = mod(dx);
        dy = mod(dy);
        long[] cur = new long[6];
        cur[0] = x;
        cur[1] = y;
        cur[2] = dx;
        cur[3] = dy;
        cur[4] = 1;
        cur[5] = 1;

        if (t > 0) {
            mat = power(mat, t);
            cur = mult(cur, mat);
        }
        out.println((cur[0] + 1) + " " + (cur[1] + 1));
    }

    long mod(long x) {
        x %= n;
        if (x < 0) x += n;
        return x;
    }

    long[][] power(long[][] A, long b) {
        if (b == 1) return A;
        if (b % 2 == 1) return mult2(A, power(A, b - 1));
        long[][] ret = power(A, b / 2);
        return mult2(ret, ret);
    }

    long[][] mult2(long[][] A, long[][] B) {
        long[][] C = new long[6][6];
        for (int i = 0; i < 6; ++i) {
            for (int j = 0; j < 6; ++j) {
                for (int k = 0; k < 6; ++k) {
                    C[i][j] += A[i][k] * B[k][j];
                }
                C[i][j] = mod(C[i][j]);
            }
        }
        return C;
    }

    long[] mult(long[] cur, long[][] mat) {
        long[] res = new long[6];
        for (int i = 0; i < 6; ++i) {
            for (int j = 0; j < 6; ++j) {
                res[i] += cur[j] * mat[j][i];
            }
            res[i] = mod(res[i]);
        }
        return res;
    }

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

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

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

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

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


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) throws IOException {
        try(Scanner scan = new Scanner(System.in);
            PrintWriter print = new PrintWriter(System.out)) {
            final int n = scan.nextInt();
            int x = scan.nextInt();
            int y = scan.nextInt();
            final int dx = scan.nextInt();
            final int dy = scan.nextInt();
            final long t = scan.nextLong();
            --x; --y;
            final Pair<Integer, Integer> res = bearOnMatrixGo(n, x, y, dx, dy, t);
            print.println((res.first + 1) + " " + (res.second + 1));
        }
    }

    public static Pair<Integer, Integer> bearOnMatrixGo(final int n, final int x, final int y, final int dx, final int dy, final long t) {
        final MatrixIntMod matrix = new MatrixIntMod(new int[][] {
                {2, 1, 1, 0, 1, 2},
                {1, 2, 0, 1, 1, 2},
                {1, 1, 1, 0, 1, 2},
                {1, 1, 0, 1, 1, 2},
                {0, 0, 0, 0, 1, 1},
                {0, 0, 0, 0, 0, 1}
        }, n);
        final int[] result = matrix.power(t).mult(new int[] {x, y, dx, dy, 0, 1});
        return new Pair(result[0], result[1]);
    }

    public static class MatrixIntMod {
        final int mod;
        final int[][] data;

        public MatrixIntMod(final int n, final int m, final int mod) {
            this.mod = mod;
            this.data = new int[n][m];
            for(int i = 0; i < n; ++i) {
                Arrays.fill(data[i], 0);
            }
        }

        public MatrixIntMod(final int[][] data, final int mod) {
            this(data.length, data[0].length, mod);
            for(int i = 0; i < data.length; ++i) {
                for(int j = 0; j < data[i].length; ++j) {
                    this.data[i][j] = ModNumberUtils.norm(mod, data[i][j]);
                }
            }
        }

        public MatrixIntMod(final int[] data, final int mod) {
            this(data.length, 1, mod);
            for(int i = 0; i < data.length; ++i) {
                this.data[i][0] = ModNumberUtils.norm(mod, data[i]);
            }
        }

        public int[] all() {
            int n = data.length;
            int m = data[0].length;
            final int[] res = new int[n * m];
            int k = 0;
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < m; ++j) {
                    res[k++] = data[i][j];
                }
            }
            return res;
        }

        public MatrixIntMod mult(final MatrixIntMod val) {
            if(data[0].length != val.data.length) throw new RuntimeException("dimensions for mult are wrong");
            final int n = data.length;
            final int m = data[0].length;
            final int l = val.data[0].length;
            final MatrixIntMod res = new MatrixIntMod(n, l, mod);
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < l; ++j) {
                    for(int k = 0; k < m; ++k) {
                        res.data[i][j] = ModNumberUtils.add(mod, res.data[i][j],
                                ModNumberUtils.mult(mod, data[i][k], val.data[k][j]));
                    }
                }
            }
            return res;
        }

        public int[] mult(final int[] ar) {
            return mult(new MatrixIntMod(ar, mod)).all();
        }

        public MatrixIntMod power(final long t) {
            if(t == 0) return eye(data.length, mod);
            MatrixIntMod res = power(t >> 1);
            res = res.mult(res);
            if((t & 1) == 1) {
                res = res.mult(this);
            }
            return res;
        }

        public static MatrixIntMod eye(final int n, final int mod) {
            final MatrixIntMod res = new MatrixIntMod(n, n, mod);
            if(mod > 1) {
                for(int i = 0; i < n; ++i) {
                    res.data[i][i] = 1;
                }
            }
            return res;
        }
    }

    public static class ModNumberUtils {
        public static int add(int mod, int a, int b) {
            a += b;
            if(a >= mod) {
                a -= mod;
            }
            return a;
        }

        public static int norm(int mod, int a) {
            a %= mod;
            if(a < 0) {
                a += mod;
            }
            return a;
        }

        public static int mult(int mod, int a, int b) {
            return (int)((long)a * b % mod);
        }
    }

    public static class Pair<X, Y>{
        public X first;
        public Y second;

        public Pair(final X first, final Y second) {
            this.first = first;
            this.second = second;
        }
    }

    public static class NumberUtils {
        public static interface Factorizer {
            List<Integer> factorize(int number);
        }

        /**
         * thread safe Factorizer
         */
        public static Factorizer createSmallNumberFactorizer(final int upperBound) {
            return new SmallNumberFactorizer(upperBound);
        }

        /**
         * thread safe
         */
        private static class SmallNumberFactorizer implements Factorizer {
            private int[] divisors;
            private final int upperBound;
            private boolean prepared = false;

            /**
             * lazy
             * time complexity O(n * log(n) * log(log(n))
             * memory complexity O(n)
             */
            public SmallNumberFactorizer(final int upperBound) {
                this.upperBound = upperBound;
            }

            private synchronized void prepare() {
                divisors = new int[upperBound];
                Arrays.fill(divisors, 0);
                for(int i = 2; i * i < upperBound; ++i) {
                    if(divisors[i] == 0) {
                        for(int j = i * i; j < upperBound; j += i) {
                            if(divisors[j] == 0) {
                                divisors[j] = i;
                            }
                        }
                    }
                }
                prepared = true;
            }

            /**
             * complexity O(result)
             */
            public List<Integer> factorize(int number) {
                synchronized (this) {
                    if(!prepared) {
                        prepare();
                    }
                }
                final List<Integer> result = CollectionFactory.createArrayList();
                if(number < 2) return result;
                if(number >= upperBound) throw new RuntimeException("number should be less than upper bound");
                while(divisors[number] > 0) {
                    result.add(divisors[number]);
                    number /= divisors[number];
                }
                result.add(number);
                return result;
            }
        }
    }

    public static class CollectionFactory {
        public static<T> List<T> createArrayList() {
            return new ArrayList<>();
        }

        public static<T> List<T> createArrayList(final int capacity) {
            return new ArrayList<>(capacity);
        }
    }

    public static class CollectionUtils {
        public static<T> List<T> unique(final List<T> list) {
            final List<T> result = CollectionFactory.createArrayList();
            T p = null;
            for(T elem : list) {
                if(!elem.equals(p)) {
                    result.add(elem);
                    p = elem;
                }
            }
            return result;
        }

        public static<T extends Comparable<T>> T max(final List<T> list, final T lowerBound) {
            T result = lowerBound;
            for(T elem : list) {
                if(elem.compareTo(result) > 0) {
                    result = elem;
                }
            }
            return result;
        }
    }

}


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

public class Div2_482E {

	static int nV;
	static int p;

	static int[] color;

	static long[] pow2;

	static long[][][][] dp;

	static long MOD = 1_000_000_007;

	public static void main(String[] args) throws IOException {
		pow2 = new long[500];
		pow2[0] = 1;
		for (int i = 1; i < 500; i++) {
			pow2[i] = pow2[i - 1] * 2 % MOD;
		}

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		nV = Integer.parseInt(inputData.nextToken());
		p = Integer.parseInt(inputData.nextToken());

		color = new int[nV];
		inputData = new StringTokenizer(reader.readLine());
		for (int i = 0; i < nV; i++) {
			color[i] = Integer.parseInt(inputData.nextToken());
		}

		dp = new long[nV + 1][nV + 1][nV + 1][nV + 1];
		dp[nV][0][0][0] = 1;
		pushDP(nV, 0, 0, 0);

		for (int cV = nV - 1; cV > 0; cV--) {
			for (int i = 0; i <= nV; i++) {
				for (int j = 0; j <= nV; j++) {
					for (int k = 0; k <= nV; k++) {
						int l = nV - cV - i - j - k;
						if (l >= 0 && dp[cV][i][j][k] != 0) {
							pushDP(cV, i, j, k);
						}
					}
				}
			}
		}
		long ans = 0;
		for (int wE = 0; wE <= nV; wE++) {
			for (int wO = 0; wO <= nV; wO++) {
				for (int bE = 0; bE <= nV; bE++) {
					int bO = nV - wE - wO - bE;

					if (bO >= 0 && ((wO + bO) & 1) == p) {
						ans = (ans + dp[0][wE][wO][bE]) % MOD;
					}
				}
			}
		}
		printer.println(ans);
		printer.close();
	}

	static void pushDP(int cV, int wE, int wO, int bE) {
		int bO = nV - cV - wE - wO - bE;
		long cDP = dp[cV][wE][wO][bE];
		if (cDP == 0) {
			return;
		}

		// white
		if (color[cV - 1] == 0 || color[cV - 1] == -1) {
			if (bO != 0) {
				dp[cV - 1][wE + 1][wO][bE] = (dp[cV - 1][wE + 1][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
				dp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
			} else {
				dp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bE] * cDP) % MOD;
			}
		}
		// black
		if (color[cV - 1] == 1 || color[cV - 1] == -1) {
			if (wO != 0) {
				dp[cV - 1][wE][wO][bE + 1] = (dp[cV - 1][wE][wO][bE + 1] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
				dp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
			} else {
				dp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wE + bE + bO] * cDP) % MOD;
			}
		}
	}

}


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

public class Main {

    public static final double EPS = 1e-8;
    private static StreamTokenizer in;
    private static Scanner ins;
    private static PrintWriter out;
    private double p;

    public static void main(String[] args) {
        try {
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            ins = new Scanner(System.in);
            out = new PrintWriter(System.out);
            try {
                if (System.getProperty("xDx") != null) {
                    in = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
                    ins = new Scanner(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                }
            } catch (Exception e) {
                in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
                ins = new Scanner(System.in);
                out = new PrintWriter(System.out);
            }
            new Main().run();
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    private double[][] dp;

    private void run() throws IOException {
        int n = nextInt();
        p = nextDouble();
        int t = nextInt();

        dp = new double[n + 1][t + 1];
        for (int i = 0; i <= n; i++) {
            Arrays.fill(dp[i], -1.0);
        }

        out.printf("%.6f", calcDp(n, t));
    }

    private double calcDp(int n, int t) {
        if (n == 0 || t == 0) {
            return 0;
        }

        if (dp[n][t] >= 0) {
            return dp[n][t];
        }

        return dp[n][t] = p * (1.0 + calcDp(n - 1, t - 1)) + (1.0 - p) * calcDp(n, t - 1);
    }

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

    private long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

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

    private String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	  double [][] z = new double [2001][2001];
	  double res = 0;
	  Scanner in = new Scanner(System.in);
	   int n = in.nextInt();
	   double p = in.nextDouble();
	   int t = in.nextInt();
        z[1][0] = 1 - p;
	    z[1][1] = p;
	     for (int i = 2; i <= t; ++i) {
           for (int j = 0; j <= n && j <= i; ++j) {
		    if (j - 1 >= 0) z[i][j] += z[i - 1][j - 1] * p;
		    z[i][j] = (j < n ? z[i][j] + z[i - 1][j] * (1 - p) : z[i][j] + z[i - 1][j]);
	       }
	     }
	      for (int j = 1; j <= n; ++j)
	        res += z[t][j] * j;
	       System.out.printf("%.6f", res);
	}
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,t;
    static double p;
    static double dp[][][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        n=input.scanInt();
        p=input.scanDouble();
        t=input.scanInt();
        double not=1;
        for(int i=0;i<t;i++) {
            not*=(1-p);
        }
        dp=new double[2000][2000][2];
        for(int i=0;i<dp.length;i++) {
            for(int j=0;j<dp[0].length;j++) {
                for(int k=0;k<dp[0][0].length;k++) {
                    dp[i][j][k]=-1;
                }
            }
        }
        System.out.println(solve(0,0,true));
    }
    public static double solve(int indx,int time,boolean prev) {
//        System.out.println(indx+" "+time+" "+prev);
        if(indx==n || time==t) {
            if(prev) {
                return 1;
            }
            return 0;
        }
        if(dp[indx][time][prev?0:1]!=-1) {
            return dp[indx][time][prev?0:1];
        }
        double ways=0;
        if(indx!=n-1 && time!=t-1) {
            ways+=p;
        }
        ways+=p*solve(indx+1,time+1,true);
        ways+=(1-p)*solve(indx,time+1,false);
        dp[indx][time][prev?0:1]=ways;
        return ways;
    }
}