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


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

public class Main {
    static int n, t;
    static double p;
    static double[][] dp;
    public static void main(String[] args) throws IOException {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            PrintWriter out = new PrintWriter(System.out);
            StringTokenizer st = new StringTokenizer(br.readLine());

            n = Integer.parseInt(st.nextToken());
            p = Double.parseDouble(st.nextToken());
            t = Integer.parseInt(st.nextToken());
            dp = new double[t+1][n+1];
            for (double[] d : dp)
                Arrays.fill(d, -1);
            out.printf("%.6f%n", solve(0, 0));
            out.flush();
            out.close();
        }
    }
    static double solve(int i, int pep) {
        if (i == t)
            return pep;
        if (pep == n)
            return pep;
        if (dp[i][pep] != -1)
            return dp[i][pep];
        return dp[i][pep] = p * solve(i+1, pep+1) + (1-p)*solve(i+1, pep);

    }
}


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

public class D
{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = null;

    private void solve() throws IOException
    {
        int n = nextInt();
        double p = nextDouble();
        int t = nextInt();
        double d[][] = new double[t + 2][n + 2];
        d[0][0] = 1;
        for(int i = 0; i <= t; i++)
        {
            for(int j = 0; j <= n; j++)
            {
                if(j == n)
                {
                    d[i + 1][j] += d[i][j];
                    break;
                }

                d[i + 1][j + 1] += d[i][j] * p;
                d[i + 1][j] += d[i][j] * (1 - p);
            }

        }

        double ans = 0;
        for(int i = 0; i <= n; i++)
        {
            ans += i * d[t][i];
        }

        System.out.println(String.format("%.6f", ans));
    }

    String nextToken() throws IOException
    {
        if (st == null || !st.hasMoreTokens())
        {
            st = new StringTokenizer(bf.readLine());
        }

        return st.nextToken();
    }

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

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

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

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

}


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

public class Main {

    static int n, t;
    static double p;
    static double memo[][];

    static double dp (int time, int soFar) {
        if (time == t) return soFar;
        if (memo[time][soFar] != -1) {
            return memo[time][soFar];
        }

        if (soFar == n) {
           return memo[time][soFar] = dp(time + 1, soFar);
        } else {
            return memo[time][soFar] = dp(time + 1, soFar) * (1 - p) + (soFar == n ? 0 : dp(time + 1, soFar + 1) * p);
        }
    }
    public static void main (String [] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        n = sc.nextInt();
        p = sc.nextDouble();
        t = sc.nextInt();

        memo = new double[t + 1][t + 1];
        for (int i = 0; i <= t; i++) {
            Arrays.fill(memo[i], -1);
        }
        out.printf("%.7f\n", dp(0, 0));
        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
        public Scanner (FileReader f) { br = new BufferedReader(f);}

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

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

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

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

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}


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

public class Task1 {

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

	PrintWriter out;
	boolean[] u;
	ArrayList<Integer>[] g;
	ArrayList<Integer>[] prev;
	int cnt = 0;
	int[] ew = new int[200020];
	int[] word = new int[20];
	int ind = 0;
	Set<String> h;
	void solve() throws IOException{
		Reader in = new Reader("input.txt");
		out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
		//out = new PrintWriter(new FileWriter(new File("output.txt")));

		int n = in.nextInt();
		double p = in.nextDouble();
		int t = in.nextInt();

		double[][] dp = new double[n+2][t+2];

		dp[1][1] = p;
		dp[0][1] = 1-p;

		double res = 0;

		for (int i = 0; i <= n; i++)
			for (int j = 1; j <= t; j++) {

				if (i == n)
					dp[i][j+1] += dp[i][j];
				else
				{
					dp[i+1][j+1] += dp[i][j]*p;
					dp[i][j+1] += dp[i][j]*(1-p);
				}
			}

		for (int i = 1; i <= n; i++) {
				res += i*dp[i][t];
		}

		out.format("%.6f", res);
		out.flush();
		out.close();
	}

	class Reader {

	    StringTokenizer token;
	    BufferedReader in;

	    public Reader(String file) throws IOException {
	        //in = new BufferedReader( new FileReader( file ) );
	        in = new BufferedReader( new InputStreamReader( System.in ) );
	    }

	    public byte nextByte() throws IOException {
	        return Byte.parseByte(Next());
	    }

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

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

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

	    public String nextString() throws IOException {
	        return in.readLine();
	    }

	    private String Next() throws IOException {
	        while (token == null || !token.hasMoreTokens()) {
	            token = new StringTokenizer(in.readLine());
	        }
	        return token.nextToken();
	    }

	}

}


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

public class Test
{

    void solve() throws Exception
    {
        int n = nextInt();
        double p = nextDouble();
        int t = nextInt();
        double[][] a = new double[n + 1][t + 1];
        for( int nn = 1; nn <= n; nn++ )
        {
            for( int tt = 1; tt <= t; tt++ )
            {
                a[nn][tt] = p * ( 1 + a[nn - 1][tt - 1] ) + ( 1 - p ) * a[nn][tt - 1];
            }
        }
        out.printf( "%.7f\n", a[n][t] );
    }

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

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

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

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

    public void run()
    {
        try
        {
            in = new BufferedReader( new InputStreamReader( System.in ) );
            out = new PrintWriter( System.out );
            st = new StringTokenizer( "" );
            Locale.setDefault( Locale.US );
            solve();
        }
        catch( Exception e )
        {
            e.printStackTrace();
            System.exit( 1 );
        }
        finally
        {
            out.close();
        }
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;
}


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

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

  static class TaskG {
    final int MOD = 1_000_000_007;
    int n;
    int k;
    byte[] moebius;
    int[] powN;
    long[] val;

    public void solve(int testNumber, InputStreamReader in, PrintWriter out) {
      SvScanner sc = new SvScanner(in);
      n = sc.nextInt();
      k = sc.nextInt();

//    moebius = SvNumberTheoryUtils.genMoebiusFuncForIntsUpTo(k);
      int[] lowestPrimeFactors = SvPrimalityUtils.genLowestPrimeFactorOfIntsUpTo(k);
      moebius = SvNumberTheoryUtils.genMoebiusFuncOfIntsUpTo(k, lowestPrimeFactors);

      powN = new int[k + 1];
      for (int i = 1; i <= k; ++i) {
        powN[i] = SvCommonMathUtils.pow(i, n, MOD);
      }

      val = new long[k + 1];
      for (int g = 1; g <= k; ++g) {
        for (int i = g; i <= k; i += g) {
          val[i] += moebius[g] * powN[i / g];
          val[i] -= moebius[g] * powN[(i - 1) / g];
        }
      }
      for (int i = 2; i <= k; ++i) {
        val[i] = (val[i] + val[i - 1]) % MOD;
      }

      long ans = 0;
      for (int i = 1; i <= k; ++i) {
        long v = (val[i] % MOD + MOD) % MOD;
        ans = (ans + (v ^ i)) % MOD;
      }
      out.println(ans);
    }

  }

  static class SvScanner {
    private BufferedReader reader;
    private StringTokenizer tokenizer = new StringTokenizer("");

    public SvScanner(InputStreamReader in) {
      reader = new BufferedReader(in);
    }

    public String next() {
      try {
        while (!tokenizer.hasMoreTokens()) {
          String nextLine = reader.readLine();
          if (nextLine == null) {
            throw new IllegalStateException("next line is null");
          }
          tokenizer = new StringTokenizer(nextLine);
        }
        return tokenizer.nextToken();
      } catch (IOException e) {
        throw new IllegalStateException(e);
      }
    }

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

  }

  static class SvNumberTheoryUtils {
    public static byte[] genMoebiusFuncOfIntsUpTo(int n, int[] lowestPrimeFactorOf) {
      byte[] moebius = new byte[n + 1];
      moebius[1] = 1;
      for (int i = 2; i <= n; i++) {
        int j = i / lowestPrimeFactorOf[i];
        if (lowestPrimeFactorOf[j] == lowestPrimeFactorOf[i]) {
          moebius[i] = 0;
        } else {
          moebius[i] = (byte) -moebius[j];
        }
      }
      return moebius;
    }

  }

  static class InputReader {
    private InputStream stream;

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

  }

  static class SvPrimalityUtils {
    public static int[] genLowestPrimeFactorOfIntsUpTo(int n) {
      // Allocate enough memory for the primes up to n.
      int u = n + 32;
      double lu = Math.log(u);
      int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
      int numPrimes = 0;

      int[] lowestPrimeFactorOf = new int[n + 1];
      for (int i = 2; i <= n; i++) {
        lowestPrimeFactorOf[i] = i;
      }

      for (int p = 2; p <= n; ++p) {
        if (lowestPrimeFactorOf[p] == p) {
          primes[numPrimes++] = p;
        }
        for (int i = 0; i < numPrimes && primes[i] <= lowestPrimeFactorOf[p]; ++i) {
          int tmp = primes[i] * p;
          if (tmp > n) break;
          lowestPrimeFactorOf[tmp] = primes[i];
        }
      }
      return lowestPrimeFactorOf;
    }

  }

  static class SvCommonMathUtils {
    public static int pow(int n, long deg, int mod) {
      if (n < 0 || deg < 0 || mod <= 0) {
        throw new IllegalArgumentException();
      }
      if (deg == 0) {
        return 1;
      } else if (deg % 2 == 0) {
        long tmp = pow(n, deg / 2, mod);
        return (int) ((tmp * tmp) % mod);
      } else {
        return (int) (((n % mod) * (long) pow(n, deg - 1, mod)) % mod);
      }
    }

  }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/29/11
 * Time: 7:56 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskD {

    final int MOD = 1000000007;

    void run() {
        String start = next();
        String end = next();
        int K = nextInt();
        int N = start.length();

        if (K == 0) {
            if (start.equals(end)) {
                System.out.println(1);
            } else {
                System.out.println(0);
            }

            return;
        }

        int[] dp = new int[N];
        Arrays.fill(dp, 1);
        dp[0] = 0;
        int sum = N - 1;

        for (int i = 1; i < K; i++) {
            int nsum = 0;
            for (int j = 0; j < N; j++) {
                dp[j] = (sum - dp[j] + MOD) % MOD;
                nsum += dp[j];
                if (nsum >= MOD) nsum -= MOD;
            }
            sum = nsum;
        }

        int ans = 0;
        String s1, s2;
        for (int i = 0; i < N; i++) {
            s1 = start.substring(0, i);
            s2 = start.substring(i);

            if (end.equals(s2.concat(s1))) {
                ans += dp[i];
                if (ans >= MOD) ans -= MOD;
            }
        }

        System.out.println(ans);
    }

    int nextInt() {
        try {
            int c = System.in.read();
            if (c == -1) return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return c;
            }
            if (c == '-') return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    long nextLong() {
        try {
            int c = System.in.read();
            if (c == -1) return -1;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return -1;
            }
            if (c == '-') return -nextLong();
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

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

    String next() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (Character.isWhitespace(c))
                c = System.in.read();
            do {
                res.append((char) c);
            } while (!Character.isWhitespace(c = System.in.read()));
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    String nextLine() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (c == '\r' || c == '\n')
                c = System.in.read();
            do {
                res.append((char) c);
                c = System.in.read();
            } while (c != '\r' && c != '\n');
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

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


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

public class CF1096G {
	static final int MD = 998244353;
	static long[] ww, ww_;
	static long power(int a, int k) {
		if (k == 0)
			return 1;
		long p = power(a, k / 2);
		p = p * p % MD;
		if (k % 2 == 1)
			p = p * a % MD;
		return p;
	}
	static void init() {
		ww = new long[21];
		ww_ = new long[21];
		for (int h = 0; h <= 20; h++) {
			ww[h] = power(3, MD - 1 >> h);
			ww_[h] = power(3, MD - 1 - (MD - 1 >> h));
		}
	}
	static void ntt(int[] aa, int n, boolean inverse) {
		for (int i = 1, j = 0; i < n; i++) {
			int b = n;
			do
				j ^= b >>= 1;
			while ((j & b) == 0);
			if (i < j) {
				int tmp = aa[i]; aa[i] = aa[j]; aa[j] = tmp;
			}
		}
		for (int h = 0, b; (b = 1 << h) < n; h++) {
			long w_ = inverse ? ww_[h + 1] : ww[h + 1];
			for (int i = 0; i < n; i += b * 2) {
				long w = 1;
				for (int j = 0; j < b; j++) {
					int l = i + j, r = l + b;
					long u = aa[l], v = aa[r] * w;
					aa[l] = (int) ((u + v) % MD);
					aa[r] = (int) ((u - v) % MD);
					w = w * w_ % MD;
				}
			}
		}
	}
	public static void main(String[] args) throws IOException {
		init();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken()) / 2;
		int k = Integer.parseInt(st.nextToken());
		int n_ = 1;
		while (n_ < n * 9 + 1)
			n_ *= 2;
		int[] aa = new int[n_];
		st = new StringTokenizer(br.readLine());
		while (k-- > 0) {
			int d = Integer.parseInt(st.nextToken());
			aa[d] = 1;
		}
		ntt(aa, n_, false);
		for (int i = 0; i < n_; i++)
			aa[i] = (int) power(aa[i], n);
		ntt(aa, n_, true);
		long v = power(n_, MD - 2);
		for (int i = 0; i < n_; i++) {
			aa[i] = (int) (aa[i] * v % MD);
			if (aa[i] < 0)
				aa[i] += MD;
		}
		long ans = 0;
		for (int i = 0; i <= n * 9; i++) {
			long a = aa[i];
			ans = (ans + a * a) % MD;
		}
		System.out.println(ans);
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        static double[] cs = new double[1 << 20];
        static double[] sn = new double[1 << 20];
        static double[] csi = new double[1 << 20];
        static double[] sni = new double[1 << 20];

        static {
            for (int len = 1; len <= cs.length; len <<= 1) {
                for (int i = len / 2; i < len; i++) {
                    cs[i] = Math.cos(2 * Math.PI * (i - len / 2) / len);
                    sn[i] = Math.sin(2 * Math.PI * (i - len / 2) / len);
                    csi[i] = Math.cos(-2 * Math.PI * (i - len / 2) / len);
                    sni[i] = Math.sin(-2 * Math.PI * (i - len / 2) / len);
                }
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int mod = 998244353;
            int n = in.nextInt();
            int k = in.nextInt();
            int[] v = new int[10];
            for (int i = 0; i < k; i++) {
                int x = in.nextInt();
                v[x] = 1;
            }
            int[] ans = {1};
            int p = n / 2;
            while (true) {
                if (p % 2 != 0) {
                    ans = multiplyMod(ans, v, mod);
                }
                p /= 2;
                if (p == 0) break;
                v = multiplyMod(v, v, mod);
            }
            int res = 0;
            for (int x : ans) {
                res = (int) ((res + (long) x * x) % mod);
            }
            out.println(res);
        }

        static int[] multiplyMod(int[] a, int[] b, int mod) {
            int need = a.length + b.length - 1;
            int n = Math.max(2, Integer.highestOneBit(need - 1) << 1);

            double[] aReal = new double[n];
            double[] aImaginary = new double[n];
            for (int i = 0; i < a.length; i++) {
                int x = (a[i] % mod + mod) % mod;
                aReal[i] = x & ((1 << 15) - 1);
                aImaginary[i] = x >> 15;
            }
            fft(aReal, aImaginary, false);

            double[] bReal = new double[n];
            double[] bImaginary = new double[n];
            for (int i = 0; i < b.length; i++) {
                int x = (b[i] % mod + mod) % mod;
                bReal[i] = x & ((1 << 15) - 1);
                bImaginary[i] = x >> 15;
            }
            fft(bReal, bImaginary, false);

            double[] faReal = new double[n];
            double[] faImaginary = new double[n];
            double[] fbReal = new double[n];
            double[] fbImaginary = new double[n];

            for (int i = 0; i < n; i++) {
                int j = (n - i) & (n - 1);

                double a1r = (aReal[i] + aReal[j]) / 2;
                double a1i = (aImaginary[i] - aImaginary[j]) / 2;
                double a2r = (aImaginary[i] + aImaginary[j]) / 2;
                double a2i = (aReal[j] - aReal[i]) / 2;

                double b1r = (bReal[i] + bReal[j]) / 2;
                double b1i = (bImaginary[i] - bImaginary[j]) / 2;
                double b2r = (bImaginary[i] + bImaginary[j]) / 2;
                double b2i = (bReal[j] - bReal[i]) / 2;

                faReal[i] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;
                faImaginary[i] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;

                fbReal[i] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;
                fbImaginary[i] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;
            }

            fft(faReal, faImaginary, true);
            fft(fbReal, fbImaginary, true);
            int[] res = new int[need];
            for (int i = 0; i < need; i++) {
                long aa = (long) (faReal[i] + 0.5);
                long bb = (long) (fbReal[i] + 0.5);
                long cc = (long) (faImaginary[i] + 0.5);
                res[i] = (int) ((aa + ((bb % mod) << 15) + ((cc % mod) << 30)) % mod);
            }
            return res;
        }

        static void fft(double[] a, double[] b, boolean inverse) {
            int n = a.length;
            int shift = 32 - Integer.numberOfTrailingZeros(n);
            for (int i = 1; i < n; i++) {
                int j = Integer.reverse(i << shift);
                if (i < j) {
                    double temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                    temp = b[i];
                    b[i] = b[j];
                    b[j] = temp;
                }
            }
            for (int len = 2; len <= n; len <<= 1) {
                int halfLen = len >> 1;
                for (int i = 0; i < n; i += len) {
                    int w = cs.length / len;
                    for (int j = 0, k = 0; j < halfLen; j++, k += w) {
                        double wA = inverse ? csi[halfLen + j] : cs[halfLen + j];
                        double wB = inverse ? sni[halfLen + j] : sn[halfLen + j];
                        double uA = a[i + j];
                        double uB = b[i + j];
                        double vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;
                        double vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;
                        a[i + j] = uA + vA;
                        b[i + j] = uB + vB;
                        a[i + j + halfLen] = uA - vA;
                        b[i + j + halfLen] = uB - vB;
                    }
                }
            }
            if (inverse) {
                for (int i = 0; i < n; i++) {
                    a[i] /= n;
                    b[i] /= n;
                }
            }
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buf = new byte[1024];
        int pos;
        int size;

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

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

        int read() {
            if (size == -1)
                throw new InputMismatchException();
            if (pos >= size) {
                pos = 0;
                try {
                    size = is.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (size <= 0)
                    return -1;
            }
            return buf[pos++] & 255;
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.util.HashMap;
import java.util.Random;
import java.util.Deque;
import java.util.function.Supplier;
import java.util.ArrayList;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.Collection;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Consumer;
import java.util.List;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.util.ArrayDeque;
import java.io.InputStream;

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

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

    static class TaskG {
        Modular mod = new Modular(998244353);

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int k = in.readInt();
            int[] allow = new int[10];
            for (int i = 0; i < k; i++) {
                allow[in.readInt()] = 1;
            }
            IntList p = new IntList();
            p.addAll(allow);

            int m = n / 2;
            IntList last = p.clone();
            NumberTheoryTransform ntt = new NumberTheoryTransform(mod, 3);

            List<IntList> lists = new ArrayList<>();
            while (m > 1) {
                if (m % 2 == 1) {
                    lists.add(last.clone());
                }
                int proper = CachedLog2.ceilLog(2 * last.size());
                last.expandWith(0, (1 << proper));
                NTT.ntt(last.getData(), 1 << proper, false, mod.getMod(), 3);
                ntt.dotMul(last.getData(), last.getData(), last.getData(), proper);
                NTT.ntt(last.getData(), 1 << proper, true, mod.getMod(), 3);
                Polynomials.normalize(last);
                m /= 2;
            }
            lists.add(last);

            IntList prod = new IntList();
            ntt.mulByPQ(lists.toArray(new IntList[0]), prod);

            int ans = 0;
            for (int i = 0; i < prod.size(); i++) {
                int plus = prod.get(i);
                ans = mod.plus(ans, mod.mul(plus, plus));
            }

            out.println(ans);
        }

    }

    static class PrimitiveRoot {
        private int[] factors;
        private Modular mod;
        private Power pow;
        int phi;
        private static PollardRho rho = new PollardRho();

        public PrimitiveRoot(Modular x) {
            phi = x.getMod() - 1;
            mod = x;
            pow = new Power(mod);
            factors = rho.findAllFactors(phi).keySet().stream().mapToInt(Integer::intValue).toArray();
        }

        public PrimitiveRoot(int x) {
            this(new Modular(x));
        }

        public int findMinPrimitiveRoot() {
            return findMinPrimitiveRoot(2);
        }

        public int findMinPrimitiveRoot(int since) {
            for (int i = since; i < mod.m; i++) {
                boolean flag = true;
                for (int f : factors) {
                    if (pow.pow(i, phi / f) == 1) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    return i;
                }
            }
            return -1;
        }

    }

    static class CachedLog2 {
        private static final int BITS = 16;
        private static final int LIMIT = 1 << BITS;
        private static final byte[] CACHE = new byte[LIMIT];

        static {
            int b = 0;
            for (int i = 0; i < LIMIT; i++) {
                while ((1 << (b + 1)) <= i) {
                    b++;
                }
                CACHE[i] = (byte) b;
            }
        }

        public static int ceilLog(int x) {
            int ans = floorLog(x);
            if ((1 << ans) < x) {
                ans++;
            }
            return ans;
        }

        public static int floorLog(int x) {
            return x < LIMIT ? CACHE[x] : (BITS + CACHE[x >>> BITS]);
        }

    }

    static class PollardRho {
        MillerRabin mr = new MillerRabin();
        Random random = new Random();

        public int findFactor(int n) {
            if (mr.mr(n, 10)) {
                return n;
            }
            while (true) {
                int f = findFactor0(random.nextInt(n), random.nextInt(n), n);
                if (f != -1) {
                    return f;
                }
            }
        }

        public Map<Integer, Integer> findAllFactors(int n) {
            Map<Integer, Integer> map = new HashMap();
            findAllFactors(map, n);
            return map;
        }

        private void findAllFactors(Map<Integer, Integer> map, int n) {
            if (n == 1) {
                return;
            }
            int f = findFactor(n);
            if (f == n) {
                Integer value = map.get(f);
                if (value == null) {
                    value = 1;
                }
                map.put(f, value * f);
                return;
            }
            findAllFactors(map, f);
            findAllFactors(map, n / f);
        }

        private int findFactor0(int x, int c, int n) {
            int xi = x;
            int xj = x;
            int j = 2;
            int i = 1;
            while (i < n) {
                i++;
                xi = (int) ((long) xi * xi + c) % n;
                int g = GCDs.gcd(n, Math.abs(xi - xj));
                if (g != 1 && g != n) {
                    return g;
                }
                if (i == j) {
                    j = j << 1;
                    xj = xi;
                }
            }
            return -1;
        }

    }

    static class MillerRabin {
        Modular modular;
        Power power;
        Random random = new Random();

        public boolean mr(int n, int s) {
            if (n == 2) {
                return true;
            }
            if (n % 2 == 0) {
                return false;
            }
            modular = new Modular(n);
            power = new Power(modular);
            for (int i = 0; i < s; i++) {
                int x = random.nextInt(n - 2) + 2;
                if (!mr0(x, n)) {
                    return false;
                }
            }
            return true;
        }

        private boolean mr0(int x, int n) {
            int exp = n - 1;
            while (true) {
                int y = power.pow(x, exp);
                if (y != 1 && y != n - 1) {
                    return false;
                }
                if (y != 1 || exp % 2 == 1) {
                    break;
                }
                exp = exp / 2;
            }
            return true;
        }

    }

    static class IntList implements Cloneable {
        private int size;
        private int cap;
        private int[] data;
        private static final int[] EMPTY = new int[0];

        public int[] getData() {
            return data;
        }

        public IntList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
        }

        public IntList(IntList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public IntList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

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

        public void addAll(int[] x) {
            addAll(x, 0, x.length);
        }

        public void addAll(int[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(IntList list) {
            addAll(list.data, 0, list.size);
        }

        public void expandWith(int x, int len) {
            ensureSpace(len);
            while (size < len) {
                data[size++] = x;
            }
        }

        public void retain(int n) {
            if (n < 0) {
                throw new IllegalArgumentException();
            }
            if (n >= size) {
                return;
            }
            size = n;
        }

        public int size() {
            return size;
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public void clear() {
            size = 0;
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof IntList)) {
                return false;
            }
            IntList other = (IntList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + data[i];
            }
            return h;
        }

        public IntList clone() {
            IntList ans = new IntList();
            ans.addAll(this);
            return ans;
        }

    }

    static class NumberTheoryTransform {
        private Modular modular;
        private Power power;
        private int g;
        private int[] wCache = new int[30];
        private int[] invCache = new int[30];
        public static Buffer<IntList> listBuffer = Polynomials.listBuffer;
        private Log2 log2 = new Log2();

        public NumberTheoryTransform(Modular mod) {
            this(mod, mod.getMod() == 998244353 ? 3 : new PrimitiveRoot(mod.getMod()).findMinPrimitiveRoot());
        }

        public NumberTheoryTransform(Modular mod, int g) {
            this.modular = mod;
            this.power = new Power(mod);
            this.g = g;
            for (int i = 0, until = wCache.length; i < until; i++) {
                int s = 1 << i;
                wCache[i] = power.pow(this.g, (modular.getMod() - 1) / 2 / s);
                invCache[i] = power.inverse(s);
            }
        }

        public void dotMul(int[] a, int[] b, int[] c, int m) {
            for (int i = 0, n = 1 << m; i < n; i++) {
                c[i] = modular.mul(a[i], b[i]);
            }
        }

        public void prepareReverse(int[] r, int b) {
            int n = 1 << b;
            r[0] = 0;
            for (int i = 1; i < n; i++) {
                r[i] = (r[i >> 1] >> 1) | ((1 & i) << (b - 1));
            }
        }

        public void dft(int[] p, int m) {
            int n = 1 << m;

            IntList rev = listBuffer.alloc();
            rev.expandWith(0, 1 << m);
            int[] r = rev.getData();
            prepareReverse(r, m);

            for (int i = 0; i < n; i++) {
                if (r[i] > i) {
                    int tmp = p[i];
                    p[i] = p[r[i]];
                    p[r[i]] = tmp;
                }
            }

            int w = 0;
            int t = 0;
            for (int d = 0; d < m; d++) {
                int w1 = wCache[d];
                int s = 1 << d;
                int s2 = s << 1;
                for (int i = 0; i < n; i += s2) {
                    w = 1;
                    for (int j = 0; j < s; j++) {
                        int a = i + j;
                        int b = a + s;
                        t = modular.mul(w, p[b]);
                        p[b] = modular.plus(p[a], -t);
                        p[a] = modular.plus(p[a], t);
                        w = modular.mul(w, w1);
                    }
                }
            }

            listBuffer.release(rev);
        }

        public void idft(int[] p, int m) {
            dft(p, m);

            int n = 1 << m;
            int invN = invCache[m];

            p[0] = modular.mul(p[0], invN);
            p[n / 2] = modular.mul(p[n / 2], invN);
            for (int i = 1, until = n / 2; i < until; i++) {
                int a = p[n - i];
                p[n - i] = modular.mul(p[i], invN);
                p[i] = modular.mul(a, invN);
            }
        }

        public void mulByPQ(IntList[] lists, IntList ans) {
            PriorityQueue<IntList> pqs = new PriorityQueue<>(lists.length, (a, b) -> a.size() - b.size());
            for (IntList list : lists) {
                IntList clone = listBuffer.alloc();
                clone.addAll(list);
                pqs.add(clone);
            }
            while (pqs.size() > 1) {
                IntList a = pqs.remove();
                IntList b = pqs.remove();
                multiplyAndStoreAnswerIntoA(a, b);
                listBuffer.release(b);
                pqs.add(a);
            }

            IntList last = pqs.remove();
            ans.clear();
            ans.addAll(last);
            listBuffer.release(last);
            return;
        }

        private void multiplyAndStoreAnswerIntoA(IntList a, IntList b) {
            int rankAns = a.size() - 1 + b.size() - 1;
            int proper = log2.ceilLog(rankAns + 1);
            a.expandWith(0, (1 << proper));
            b.expandWith(0, (1 << proper));
            dft(a.getData(), proper);
            dft(b.getData(), proper);
            dotMul(a.getData(), b.getData(), a.getData(), proper);
            idft(a.getData(), proper);
            Polynomials.normalize(a);
        }

    }

    static class NTT {
        static int pow(int x, int n, int mod) {
            int res = 1;
            for (long p = x; n > 0; n >>= 1, p = (p * p) % mod)
                if ((n & 1) != 0)
                    res = (int) (res * p % mod);
            return res;
        }

        public static void ntt(int[] a, int n, boolean invert, int mod, int root) {
            int shift = 32 - Integer.numberOfTrailingZeros(n);
            for (int i = 1; i < n; i++) {
                int j = Integer.reverse(i << shift);
                if (i < j) {
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }

            int root_inv = pow(root, mod - 2, mod);

            for (int len = 1; len < n; len <<= 1) {
                int wlen = pow(invert ? root_inv : root, (mod - 1) / (2 * len), mod);
                for (int i = 0; i < n; i += 2 * len)
                    for (int j = 0, w = 1; j < len; ++j) {
                        int u = a[i + j];
                        int v = (int) ((long) a[i + j + len] * w % mod);
                        a[i + j] = (u + v) % mod;
                        a[i + j + len] = (u - v + mod) % mod;
                        w = (int) ((long) w * wlen % mod);
                    }
            }
            if (invert) {
                int nrev = pow(n, mod - 2, mod);
                for (int i = 0; i < n; ++i)
                    a[i] = (int) ((long) a[i] * nrev % mod);
            }
        }

    }

    static class Polynomials {
        public static Buffer<IntList> listBuffer = new Buffer<>(IntList::new, list -> list.clear());

        public static int rankOf(IntList p) {
            int[] data = p.getData();
            int r = p.size() - 1;
            while (r >= 0 && data[r] == 0) {
                r--;
            }
            return Math.max(0, r);
        }

        public static void normalize(IntList list) {
            list.retain(rankOf(list) + 1);
        }

    }

    static class SequenceUtils {
        public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

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

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

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

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

        public int readInt() {
            int sign = 1;

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

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

            return val;
        }

    }

    static class Power {
        final Modular modular;

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

        public int pow(int x, int n) {
            if (n == 0) {
                return modular.valueOf(1);
            }
            long r = pow(x, n >> 1);
            r = modular.valueOf(r * r);
            if ((n & 1) == 1) {
                r = modular.valueOf(r * x);
            }
            return (int) r;
        }

        public int inverse(int x) {
            return pow(x, modular.m - 2);
        }

    }

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

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

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

        public FastOutput println(int c) {
            cache.append(c).append('\n');
            return this;
        }

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

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

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

    }

    static class Buffer<T> {
        private Deque<T> deque;
        private Supplier<T> supplier;
        private Consumer<T> cleaner;

        public Buffer(Supplier<T> supplier) {
            this(supplier, (x) -> {
            });
        }

        public Buffer(Supplier<T> supplier, Consumer<T> cleaner) {
            this(supplier, cleaner, 0);
        }

        public Buffer(Supplier<T> supplier, Consumer<T> cleaner, int exp) {
            this.supplier = supplier;
            this.cleaner = cleaner;
            deque = new ArrayDeque<>(exp);
        }

        public T alloc() {
            return deque.isEmpty() ? supplier.get() : deque.removeFirst();
        }

        public void release(T e) {
            cleaner.accept(e);
            deque.addLast(e);
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

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

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

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

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

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

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

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

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

    }

    static class Log2 {
        public int ceilLog(int x) {
            return 32 - Integer.numberOfLeadingZeros(x - 1);
        }

    }

    static class GCDs {
        private GCDs() {
        }

        public static int gcd(int a, int b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

        private static int gcd0(int a, int b) {
            return b == 0 ? a : gcd0(b, a % b);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int mod = 998244353;
            int n = in.nextInt();
            int k = in.nextInt();
            int[] v = new int[10];
            for (int i = 0; i < k; i++) {
                int x = in.nextInt();
                v[x] = 1;
            }
            int[] ans = {1};
            int p = n / 2;
            while (true) {
                if (p % 2 != 0) {
                    ans = multiplyMod(ans, v, mod);
                }
                p /= 2;
                if (p == 0) break;
                v = multiplyMod(v, v, mod);
            }
            int res = 0;
            for (int x : ans) {
                res = (int) ((res + (long) x * x) % mod);
            }
            out.println(res);
        }

        static int[] multiplyMod(int[] a, int[] b, int mod) {
            int need = a.length + b.length - 1;
            int n = Math.max(2, Integer.highestOneBit(need - 1) << 1);

            double[] aReal = new double[n];
            double[] aImaginary = new double[n];
            for (int i = 0; i < a.length; i++) {
                int x = (a[i] % mod + mod) % mod;
                aReal[i] = x & ((1 << 15) - 1);
                aImaginary[i] = x >> 15;
            }
            fft(aReal, aImaginary, false);

            double[] bReal = new double[n];
            double[] bImaginary = new double[n];
            for (int i = 0; i < b.length; i++) {
                int x = (b[i] % mod + mod) % mod;
                bReal[i] = x & ((1 << 15) - 1);
                bImaginary[i] = x >> 15;
            }
            fft(bReal, bImaginary, false);

            double[] faReal = new double[n];
            double[] faImaginary = new double[n];
            double[] fbReal = new double[n];
            double[] fbImaginary = new double[n];

            double cf = 0.25 / n;
            for (int i = 0; i < n; i++) {
                int j = (n - i) & (n - 1);

                double a1r = (aReal[i] + aReal[j]) / 2;
                double a1i = (aImaginary[i] - aImaginary[j]) / 2;
                double a2r = (aImaginary[i] + aImaginary[j]) / 2;
                double a2i = (aReal[j] - aReal[i]) / 2;

                double b1r = (bReal[i] + bReal[j]) / 2;
                double b1i = (bImaginary[i] - bImaginary[j]) / 2;
                double b2r = (bImaginary[i] + bImaginary[j]) / 2;
                double b2i = (bReal[j] - bReal[i]) / 2;

                faReal[i] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;
                faImaginary[i] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;

                fbReal[i] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;
                fbImaginary[i] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;
            }

            fft(faReal, faImaginary, true);
            fft(fbReal, fbImaginary, true);
            int[] res = new int[need];
            for (int i = 0; i < need; i++) {
                long aa = (long) (faReal[i] + 0.5);
                long bb = (long) (fbReal[i] + 0.5);
                long cc = (long) (faImaginary[i] + 0.5);
                res[i] = (int) ((aa + ((bb % mod) << 15) + ((cc % mod) << 30)) % mod);
            }
            return res;
        }

        static void fft(double[] a, double[] b, boolean inverse) {
            int n = a.length;
            int shift = 32 - Integer.numberOfTrailingZeros(n);
            for (int i = 1; i < n; i++) {
                int j = Integer.reverse(i << shift);
                if (i < j) {
                    double temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                    temp = b[i];
                    b[i] = b[j];
                    b[j] = temp;
                }
            }
            for (int len = 2; len <= n; len <<= 1) {
                int halfLen = len >> 1;
                double[] cs = new double[halfLen];
                double[] sn = new double[halfLen];
                for (int i = 0; i < halfLen; i++) {
                    cs[i] = Math.cos(2 * Math.PI * i / len * (inverse ? -1 : 1));
                    sn[i] = Math.sin(2 * Math.PI * i / len * (inverse ? -1 : 1));
                }
                for (int i = 0; i < n; i += len) {
                    for (int j = 0; j < halfLen; j++) {
                        double wA = cs[j];
                        double wB = sn[j];
                        double uA = a[i + j];
                        double uB = b[i + j];
                        double vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;
                        double vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;
                        a[i + j] = uA + vA;
                        b[i + j] = uB + vB;
                        a[i + j + halfLen] = uA - vA;
                        b[i + j + halfLen] = uB - vB;
                    }
                }
            }
            if (inverse) {
                for (int i = 0; i < n; i++) {
                    a[i] /= n;
                    b[i] /= n;
                }
            }
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buf = new byte[1024];
        int pos;
        int size;

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

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

        int read() {
            if (size == -1)
                throw new InputMismatchException();
            if (pos >= size) {
                pos = 0;
                try {
                    size = is.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (size <= 0)
                    return -1;
            }
            return buf[pos++] & 255;
        }

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

    }
}