using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    ReadData re;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        re = new ReadData();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long N = re.i();
        int K = re.i();
        long count = 0;
        for(int i=0;i<=K;i++){
            if(i == 0){
                count++;
            }
            else if(i == 2){
                count += N*(N-1)/2;
            }
            else if(i == 3){
                count += N*(N-1)*(N-2)/3;
            }
            else if(i == 4){
                count += N*(N-1)*(N-2)*(N-3)/24*9;
            }
        }
        sb.Append(count+"\n");
    }
}
class ReadData{
    string[] str;
    int counter;
    public ReadData(){
        counter = 0;
    }
    public string s(){
        if(counter == 0){
            str = Console.ReadLine().Split(' ');
            counter = str.Length;
        }
        counter--;
        return str[str.Length-counter-1];
    }
    public int i(){
        return int.Parse(s());
    }
    public long l(){
        return long.Parse(s());
    }
    public double d(){
        return double.Parse(s());
    }
    public int[] ia(int N){
        int[] ans = new int[N];
        for(int j=0;j<N;j++){
            ans[j] = i();
        }
        return ans;
    }
    public int[] ia(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        int[] ans = new int[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = int.Parse(str[j]);
        }
        return ans;
    }
    public long[] la(int N){
        long[] ans = new long[N];
        for(int j=0;j<N;j++){
            ans[j] = l();
        }
        return ans;
    }
    public long[] la(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        long[] ans = new long[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = long.Parse(str[j]);
        }
        return ans;
    }
    public double[] da(int N){
        double[] ans = new double[N];
        for(int j=0;j<N;j++){
            ans[j] = d();
        }
        return ans;
    }
    public double[] da(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        double[] ans = new double[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = double.Parse(str[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int[] f,int[] t){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<f.Length;j++){
            ans[f[j]].Add(t[j]);
            ans[t[j]].Add(f[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int M){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
    public List<int>[] g(){
        int N = i();
        int M = i();
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
}
public static class Define{
    public const long mod = 1000000007;
}
public static class Debug{
    public static void Print(double[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(double[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(double[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
    public static void Print(long[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(long[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(long[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
    public static void Print(int[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(int[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(int[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Kavi_on_Pairing_Duty
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            const int mod = 998244353;

            int n = Next();

            var p = new int[n + 1];
            var s = new long[n + 1];
            s[1] = 1;
            long sum = 2;

            for (int i = 2; i < p.Length; i++)
            {
                for (int j = i + i; j < p.Length; j += i)
                {
                    p[j]++;
                }

                s[i] = (1 + sum + p[i])%mod;
                sum += s[i];
                sum %= mod;
            }
            writer.WriteLine(s[n]);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
public class Wool
{
    public static void Main(string [] args)
    {
        int n, m,i;
        string[] input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        m = int.Parse(input[1]);
        long res = 1;
        const long d = 1000000009;
        for (i = 0; i < m; ++i)
        {
            res = res * 2;
            res = res % d;
        }
        long ans = 1;
        for (i = 1; i <= n; ++i)
            ans = (ans * (res - i)) % d;
        Console.WriteLine(ans);
        Console.ReadLine();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    private int N, M, A, B;
    private int G0, X, Y, Z;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();

        int[] g = new int[N * M];
        g[0] = sc.NextInt();
        X = sc.NextInt();
        Y = sc.NextInt();
        Z = sc.NextInt();
        for (int i = 1; i < N * M; i++)
        {
            g[i] = (int) (((long) g[i - 1] * X + Y) % Z);
        }

        var mq = new MinQueue[N];
        for (int i = 0; i < N; i++)
        {
            mq[i] = new MinQueue();
        }

        for (int j = 0; j < B - 1; j++)
        {
            for (int i = 0; i < N; i++)
            {
                mq[i].Enqueue(g[i * M + j]);
            }
        }

        long ans = 0;
        for (int j = B - 1; j < M; j++)
        {
            for (int i = 0; i < N; i++)
            {
                mq[i].Enqueue(g[i * M + j]);
            }

            var mq2 = new MinQueue();
            for (int i = 0; i < A - 1; i++)
            {
                mq2.Enqueue(mq[i].GetMin());
            }

            for (int i = A - 1; i < N; i++)
            {
                mq2.Enqueue(mq[i].GetMin());
                ans += mq2.GetMin();
                mq2.Dequeue();
            }

            for (int i = 0; i < N; i++)
            {
                mq[i].Dequeue();
            }
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

class MinStack
{
    private Stack<(int val, int min)> S;

    public MinStack()
    {
        S = new Stack<(int val, int min)>();
    }

    public int GetMin()
    {
        if (S.Count == 0) return int.MaxValue;
        return S.Peek().min;
    }

    public void Push(int val)
    {
        S.Push((val, Math.Min(val, GetMin())));
    }

    public int Pop()
    {
        return S.Pop().val;
    }

    public int Count
    {
        get { return S.Count; }
    }
}

class MinQueue
{
    public MinStack L, R;

    public MinQueue()
    {
        L = new MinStack();
        R = new MinStack();
    }

    public void Enqueue(int val)
    {
        R.Push(val);
    }

    public void Dequeue()
    {
        if (L.Count == 0)
        {
            while (R.Count > 0)
            {
                L.Push(R.Pop());
            }
        }

        L.Pop();
    }

    public int GetMin()
    {
        return Math.Min(L.GetMin(), R.GetMin());
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lab11
{
    using li = System.Int64;
    using mt = System.Int64;
    class Program
    {
        const int N = 100 + 5;
        public static li INF = 1000000000000000;
        static li[,] mt = new li[N, N];

        static int n;
        static int[] a = new int[N];
        static li T;
        static mt[,] d = new mt[N,N];
        static mt[,] dt = new mt[N,N];

        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToArray<int>();
            n = input[0];
            T = input[1];
            input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToArray<int>();
            for (int i = 0; i < n; ++i)
                a[i] = input[i];
            for (int s = 0; s < n; ++s)
            {
                for (int i = 0; i < n; ++i)
                {
                    if (a[i] < a[s])
                    {
                        d[s, i] = -INF;
                    }
                    else
                    {
                        d[s, i] = 1;
                        for (int j = 0; j < i; ++j)
                            if (a[j] <= a[i])
                                d[s, i] = Math.Max(d[s, i], d[s, j] + 1);
                    }
                }
            }
            binpow(d, T, dt);
            li res = 0;
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    res = Math.Max(res, dt[i, j]);
            Console.WriteLine(res);
        }

        static void one(mt[,] a)
        {
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    a[i,j] = 0;
        }

        static void copy(mt[,] a, mt[,] b)
        {
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    b[i, j] = a[i, j];
        }

        static void mul(mt[,] a, mt[,] b, mt[,] c)
        {
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j) {
                    c[i,j] = -INF;
                    for (int k = 0; k < n; ++k)
                        c[i,j] = Math.Max(c[i,j], a[i,k] + b[k,j]);
                }
        }

        static mt[,] t = new mt[N, N];
        static mt[,] r = new mt[N, N];

        static void binpow(mt[,] a, li b, mt[,] c)
        {
            copy(a, t);
            one(c);
            while (b != 0) {
                if ((b & 1) != 0) {
                    mul(c, t, r);
                    copy(r, c);
                }
                mul(t, t, r);
                copy(r, t);
                b >>= 1;
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using System.Linq;
class Program
{
    class Point
    {
        public double x, y;
        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
    }
    class Line
    {
        public double a, b, c;
        public Line(Point p1, Point p2)
        {
            a = p2.y - p1.y;
            b = p1.x - p2.x;
            c = a * p1.x + b * p1.y;
        }
        public  Line()
        {

        }

        public Line prep( Point p)
        {
            Line res=new Line();
            res.a = -b;
            res.b = a;
            res.c = res.a * p.x + res.b * p.y;
            return res;

        }
        public Point Intersect(Line l)
        {
            Point res = new Point(0,0);
            double d = a * l.b - b * l.a;
            res.x = (l.b * c - b * l.c) / d;
            res.y = (a * l.c - l.a * c) / d;
            return res;
        }

    }
    double eps = 1e-9;
    void solve()
    {
        Point p = new Point(nextInt(), nextInt());
        Point v=new Point(nextInt(),nextInt());
        Point[]w=new Point[2];

        for (int i = 0; i < 2; i++)
            w[i] = new Point(nextInt(), nextInt());
        Point[] mir = new Point[2];
        for (int i = 0; i < 2; i++)
            mir[i] = new Point(nextInt(), nextInt());

        bool ok = false;
        if (good(p, v, w[0], w[1]) && (good(p,v,mir[0],mir[1]) || sign(cross(mir[0],mir[1],p))==0))
        {
            ok = true;
        }
        else if (sign(cross(mir[0], mir[1], p)) * sign(cross(mir[0], mir[1], v)) == 1)
        {
            Line lm = new Line(mir[0], mir[1]);
            Line pr = lm.prep(p);
            Point inter = lm.Intersect(pr);
            Point other = new Point(inter.x + (inter.x - p.x), inter.y + (inter.y - p.y));
            {
                Line l = new Line(other, v);
                Point x = l.Intersect(lm);
                if (good(x, p, w[0], w[1]) && good(x, v, w[0], w[1]) && on(mir[0], mir[1], x))
                    ok = true;
            }

        }
        if (ok)
            println("YES");
        else
            println("NO");

    }

    private bool good(Point p1, Point p2, Point p3, Point p4)
    {
        double d1 = cross(p1, p2, p3);
        double d2 = cross(p1, p2, p4);
        double d3 = cross(p3, p4,p1);
        double d4 = cross(p3, p4, p2);
        int x1 = sign(d1);
        int x2 = sign(d2);
        int x3 = sign(d3);
        int x4 = sign(d4);
        if (x1 * x2 < 0 && x3 * x4 < 0)
            return false;
        if (x1 == 0)
        {
            if (on(p1, p2, p3))
                return false;
        }
        if (x2 == 0)
        {
            if (on(p1, p2, p4))
                return false;
        }
        if (x3 == 0)
        {
            if (on(p3, p4, p1))
                return false;
        }
        if (x4 == 0)
        {
            if (on(p3, p4, p2))
                return false;
        }

        return true;

    }

    private bool on(Point p1, Point p2, Point p3)
    {
        return on(p1.x, p2.x, p3.x) && on(p1.y, p2.y, p3.y);
    }

    private bool on(double x, double y, double z)
    {
        return z >= Math.Min(x, y) - eps && z <= Math.Max(x, y) + eps;
    }

    private int sign(double d1)
    {
        return Math.Abs(d1) < eps ? 0 : Math.Sign(d1);
    }

    private double cross(Point p1, Point p2, Point p3)
    {
        return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}