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

public class CodingLegacy {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Palindrome solver = new Palindrome();
        int t = 1;

        for(int i=0;i<t;i++) {
            solver.solve(i+1, in, out);
        }
        out.close();
    }

    static class Palindrome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            String s = in.next();
            boolean[] a = new boolean[n];

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

            char[] c = new char[k];
            for(int i = 0;i<k;i++){
                c[i] = in.next().charAt(0);
            }

            int count=0;
            for(int i =0;i<k;i++){
                for (int j = 0;j<n;j++){
                    if(s.charAt(j)==c[i]){
                        a[j] = true;
                        count++;
                    }
                }
            }

//            out.println(Arrays.toString(a));

            if(count==0){
                out.println("0");
                return;
            }

            boolean b = false;
            int m=-1;

            long ans = 0;
            for(int i = 0;i<n;i++){
                if(a[i]){
                    if(!b){
                        m=i;
                        b = true;
                    }
                }else{
                    if(b){
                        ans += (i-m)*(i-m+1)/2;
                        b = false;
                    }
                }
            }

            if(b){
                ans += (n-m)*(n-m + 1)/2;
            }

            out.println(ans);
        }
    }

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

        public static long factorial(int n){
            long fact = 1;
            for(int i=1;i<=n;i++){
                fact *= i;
            }
            return fact;
        }
    }

    static class Characters{
        public static boolean isVovel(char a){
            if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u'){
                return true;
            }
            return false;
        }
    }

    static class Binary {
        public static long numberOfBits(long n){
            long count=0;
            while(n>0){
                count++;
                n >>=1;
            }
            return count;
        }

        public static long numberOfSetBits(long n){
            long count = 0;
            int p = 1;
            while (n>0){
                if((n&p) == 1){
                    count++;
                }
                n >>= 1;
            }
            return count;
        }
    }

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

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

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

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

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


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

public class CodingLegacy {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Palindrome solver = new Palindrome();
        int t = 1;

        for(int i=0;i<t;i++) {
            solver.solve(i+1, in, out);
        }
        out.close();
    }

    static class Palindrome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            long ans = 0;
            String s = in.next();

            HashSet<Character> set = new HashSet<>();
            for(int i = 0;i<k;i++){
                set.add(in.next().charAt(0));
            }

            long num = 0;
            for(int i=0;i<n;i++){
                if(!set.contains(s.charAt(i))){
                    ans += num*(num+1)/2;
                    num = 0;
                } else {
                    num++;
                }
            }

            ans += num*(num + 1)/2;

            out.println(ans);
        }
    }

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

        public static long factorial(int n){
            long fact = 1;
            for(int i=1;i<=n;i++){
                fact *= i;
            }
            return fact;
        }
    }

    static class Characters{
        public static boolean isVovel(char a){
            if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u'){
                return true;
            }
            return false;
        }
    }

    static class Binary {
        public static long numberOfBits(long n){
            long count=0;
            while(n>0){
                count++;
                n >>=1;
            }
            return count;
        }

        public static long numberOfSetBits(long n){
            long count = 0;
            int p = 1;
            while (n>0){
                if((n&p) == 1){
                    count++;
                }
                n >>= 1;
            }
            return count;
        }
    }

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

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

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

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

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


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

public class Solution {

	public static void main(String[] args) {

		/*
		 *
		 */
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		String str = scan.next();
		//int[] arr = new int[n];
		Set<Integer> set = new HashSet<Integer>();
		for(int i=0;i<k;i++) {
			String s=scan.next();
			set.add((int)s.charAt(0));
		}
		long count=0;
		long ans=0;
		for(int i=0;i<n;i++) {
			int num=(int) str.charAt(i);
			if(!set.contains(num)) {
				ans+=(count*(count+1))/2;
				count=0;
			}else {
				count++;
			}
		}
		ans+=(count*(count+1))/2;
		System.out.println(ans);

		scan.close();

	}

}


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

public class Solution {

	public static void main(String[] args) {

		/*
		 *
		 */
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		String str = scan.next();
		//int[] arr = new int[n];
		Set<Integer> set = new HashSet<Integer>();
		for(int i=0;i<k;i++) {
			String s=scan.next();
			set.add((int)s.charAt(0));
		}
		int count=0;
		long ans=0;
		for(int i=0;i<n;i++) {
			int num=(int) str.charAt(i);
			if(!set.contains(num)) {
				ans+=(count*(count+1))/2;
				count=0;
			}else {
				count++;
			}
		}
		ans+=(count*(count+1))/2;
		System.out.println(ans);

		scan.close();

	}

}


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

public class Solution {

	public static void main(String[] args) {

		/*
		 *
		 */
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		String str = scan.next();
		//int[] arr = new int[n];
		Set<Integer> set = new HashSet<Integer>();
		for(int i=0;i<k;i++) {
			String s=scan.next();
			set.add((int)s.charAt(0));
		}
		int count=0;
		int ans=0;
		for(int i=0;i<n;i++) {
			int num=(int) str.charAt(i);
			if(!set.contains(num)) {
				ans+=(count*(count+1))/2;
				count=0;
			}else {
				count++;
			}
		}
		ans+=(count*(count+1))/2;
		System.out.println(ans);

		scan.close();

	}

}


import java.util.*;

public class vasu {
	public static void main(String args[]) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		String s = input.next();
		int count[] = new int[26];
		for(int i=0;i<k;i++) {
			count[input.next().charAt(0)-'a']++;
		}
		int temp = 0;int res = 0;
		for(int i=0;i<n;i++) {
			if(i==n-1) {
				if(count[s.charAt(i)-'a']>0) {
					res++;
				}
				temp+=res*(res+1)/2;
			}
			if(count[s.charAt(i)-'a']>0) {
				res++;
			}
			else {
				temp+=res*(res+1)/2;
				res = 0;
			}
		}
		System.out.println(temp);
	}
}


import java.util.*;

public class vasu {
	public static void main(String args[]) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		String s = input.next();
		int count[] = new int[26];
		for(int i=0;i<k;i++) {
			count[input.next().charAt(0)-'a']++;
		}
		long temp = 0;long res = 0;
		for(int i=0;i<n;i++) {
			if(i==n-1) {
				if(count[s.charAt(i)-'a']>0) {
					res++;
				}
				temp+=res*(res+1)/2;
			}
			if(count[s.charAt(i)-'a']>0) {
				res++;
			}
			else {
				temp+=res*(res+1)/2;
				res = 0;
			}
		}
		System.out.println(temp);
	}
}


import java.util.*;

public class vasu {
	public static void main(String args[]) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		String s = input.next();
		int count[] = new int[26];
		for(int i=0;i<k;i++) {
			count[input.next().charAt(0)-'a']++;
		}
		int temp = 0;int res = 0;
		for(int i=0;i<n;i++) {
			if(i==n-1 && res>0) {
				res++;
				temp+=res*(res+1)/2;
			}
			if(count[s.charAt(i)-'a']>0) {
				res++;
			}
			else {
				temp+=res*(res+1)/2;
				res = 0;
			}
		}
		System.out.println(temp);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		int n = Integer.parseInt(input[0]);
		int k = Integer.parseInt(input[1]);
		//sc.nextLine();
		String text = br.readLine();
		//System.out.println(text);
		Set<Character> set = new HashSet<>();

		String available = br.readLine();

		for (int i=0; i<available.length(); ++i) {
			set.add(available.charAt(i));
		}

		/*
		 * for(char ch: set) { System.out.println(ch); }
		 */
		int total = 0;

		int num = 0;

		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				total += (num * (num + 1))  / 2;
				num = 0;
			}
		}
		total += num * (num + 1)  / 2;
		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.nextLine();
		String text = sc.nextLine();

		Set<Character> set = new HashSet<>();

		for (int i=0; i<k; ++i) {
			char ch = sc.next().charAt(0);
			set.add(ch);
			//System.out.println(ch);

		}

		/*
		 * for(char ch: set) { System.out.println(ch); }
		 */
		int total = 0;

		int num = 0;

		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				total += (num * (num + 1))  / 2;
				num = 0;
			}
		}
		total += num * (num + 1)  / 2;
		System.out.println(total);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		int n = Integer.parseInt(input[0]);
		int k = Integer.parseInt(input[1]);
		//sc.nextLine();
		String text = br.readLine();
		//System.out.println(text);
		Set<Character> set = new HashSet<>();

		String[] available = br.readLine().split(" ");

		for (int i=0; i<available.length; ++i) {
			set.add(available[i].charAt(0));
		}

		/* for(char ch: set) { System.out.println(ch); } */

		int total = 0;

		int num = 0;
		//System.out.println(text);
		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				total += (num * (num + 1))  / 2;
				num = 0;
			}
		}
		total += num * (num + 1)  / 2;
		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.nextLine();
		String text = sc.nextLine();

		String availableKey = sc.nextLine();

		Set<Character> set = new HashSet<>();

		for (int i=0; i<availableKey.length(); ++i) {
			set.add(availableKey.charAt(i));
		}
		int total = 0;

		int num = 0;

		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				if (num == 0) continue;
				total += num * (num + 1)  / 2;
				num = 0;
			}
		}
		if (num != 0) {
			total += num * (num + 1)  / 2;
		}
		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.nextLine();
		String text = sc.nextLine();

		Set<Character> set = new HashSet<>();

		for (int i=0; i<k; ++i) {
			char ch = sc.next().charAt(0);
			set.add(ch);
			//System.out.println(ch);

		}
		int total = 0;

		int num = 0;

		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				total += num * (num + 1)  / 2;
				num = 0;
			}
		}
		total += num * (num + 1)  / 2;
		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		/*
		 * BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 * String[] input = br.readLine().split(" "); int n =
		 * Integer.parseInt(input[0]); int k = Integer.parseInt(input[1]);
		 * //sc.nextLine(); String text = br.readLine(); //System.out.println(text);
		 * Set<Character> set = new HashSet<>();
		 *
		 * String[] available = br.readLine().split(" ");
		 *
		 * for (int i=0; i<available.length; ++i) { set.add(available[i].charAt(0)); }
		 */
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		String text = scan.next();

		Set<Character> set = new HashSet<>();
		for (int i = 0; i < k; i++) {
			String ss = scan.next();
			set.add(ss.charAt(0));
		}

		/* for(char ch: set) { System.out.println(ch); } */

		long total = 0;

		long num = 0;

		// System.out.println(text);

		for (int i = 0; i < text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			} else {

				total += (num * (num + 1)) / 2;
				num = 0;
			}
		}
		total += num * (num + 1) / 2;
		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.nextLine();
		String text = sc.nextLine();

		Set<Character> set = new HashSet<>();

		for (int i=0; i<k; ++i) {
			set.add(sc.next().charAt(0));
		}
		int total = 0;

		int num = 0;

		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				if (num == 0) continue;
				total += num * (num + 1)  / 2;
				num = 0;
			}
		}
		if (num != 0) {
			total += num * (num + 1)  / 2;
		}
		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.nextLine();
		String text = sc.nextLine();

		Set<Character> set = new HashSet<>();

		for (int i=0; i<k; ++i) {
			char ch = sc.next().charAt(0);
			set.add(ch);
			//System.out.println(ch);

		}
		int total = 0;

		int num = 0;

		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				total += num * (num + 1)  / 2;
				num = 0;
			}
		}

		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.nextLine();
		String text = sc.nextLine();

		Set<Character> set = new HashSet<>();

		for (int i=0; i<k; ++i) {
			char ch = sc.next().charAt(0);
			set.add(ch);
			//System.out.println(ch);

		}
		int total = 0;

		int num = 0;

		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				if (num == 0) continue;
				total += num * (num + 1)  / 2;
				num = 0;
			}
		}
		if (num != 0) {
			total += num * (num + 1)  / 2;
		}
		System.out.println(total);

	}

}


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

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		/*
		 * BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 * String[] input = br.readLine().split(" "); int n =
		 * Integer.parseInt(input[0]); int k = Integer.parseInt(input[1]);
		 * //sc.nextLine(); String text = br.readLine(); //System.out.println(text);
		 * Set<Character> set = new HashSet<>();
		 *
		 * String[] available = br.readLine().split(" ");
		 *
		 * for (int i=0; i<available.length; ++i) { set.add(available[i].charAt(0)); }
		 */
		 Scanner scan = new Scanner(System.in);
	        int n = scan.nextInt();
	        int k = scan.nextInt();
	        String text = scan.next();

	        Set<Character>set = new HashSet<>();
	        for(int i=0;i<k;i++) {
	            String ss = scan.next();
	            set.add(ss.charAt(0));
	        }

		/* for(char ch: set) { System.out.println(ch); } */

		int total = 0;

		int num = 0;
		//System.out.println(text);
		for (int i=0; i<text.length(); ++i) {

			if (set.contains(text.charAt(i))) {
				num++;
			}else {

				total += (num * (num + 1))  / 2;
				num = 0;
			}
		}
		total += num * (num + 1)  / 2;
		System.out.println(total);

	}

}


// Java program For handling Input/Output
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main
{
    Scanner sc;
        //actual logic
    void solve(){
            int n = ni();
            int k = ni();
            ns();
            String s = ns() + " ";
            char c[] = new char[k];
            int ans = 0;
            for(int i = 0;i < k;i++)
            {
                c[i] = sc.next().charAt(0);
            }
            String cs = new String(c);
            int temp = 0;
            for(int i = 0;i < s.length();i++)
            {
                if(cs.contains(s.charAt(i)+""))
                    temp++;
                else
                {
                    ans += (temp * (temp+1)) / 2;
                    temp = 0;
                }
            }

            System.out.println(ans);
    }

    //constructor
    Main(){
        try{
            sc = new Scanner(System.in);
        }catch(Exception e){
            System.out.println(e);
        }
    }

    //main metohd
    public static void main(String[] args)
    {
     new Main().solve();
 }

    //Utility methods
        //input an integer from scanner
 int ni()
 {
    int a = sc.nextInt();
    return a;
}
        //input a long from scanner
long nl()
{
    return sc.nextLong();
}
        //input a float from scanner
float nf(){
    float a = sc.nextFloat();
    return a;
}
        //input a double from scanner
double nd(){
    double a = sc.nextDouble();
    return a;
}
        //input a sentence from scanner
String ns(){
    return sc.nextLine();
}
        //converts a string to stringtokenizer
StringTokenizer nst(String s){
    return new StringTokenizer(s);
}
        //input an intger array
void ia(int a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextInt();
}
        //
void la(long a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextLong();
}
        //input a float array
void fa(float a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextFloat();
}
        //input a double array
void da(double a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextDouble();
}
        //input a string array either with all empty input or from scanner
void sa(String a[], boolean empty){
    if(empty)
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = "";
        }
    }
    else
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = ns();
        }
    }
}
        //input two dimensional integer array
void ida(int a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = ni();
        }
    }
}
        //input two dimentional long array
void lda(long a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nl();
        }
    }
}
        //input two dimensional double array
void dda(double a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nd();
        }
    }
}
        //convert string to integer
int stoi(String s){
    return Integer.parseInt(s);
}
        //convert string to double
double stod(String s){
    return Double.parseDouble(s);
}
        //find minimum in a long array
long lmin(long a[])
{
    long min = Long.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find minimum in a integer array
int imin(int a[])
{
    int min = Integer.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find maximum in a long array
long lmax(long a[])
{
    long max = Long.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //find maximum in an integer array
int imax(int a[])
{
    int max = Integer.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //check whether an element is present in an integer array by binary search
boolean ibs(int a[], int toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}
        //check whether an element is present in a long array
boolean lbs(long a[], long toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}

int stb(String s)
{
    int sum = 0;
    int k = 0;
    for(int i = s.length()-1;i >= 0;i--)
    {
        sum += stoi(s.charAt(i)+"") * Math.pow(2, k++);
    }
    return sum;
}

}


// Java program For handling Input/Output
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main
{
    Scanner sc;
        //actual logic
    void solve(){
            int n = ni();
            int k = ni();
            ns();
            String s = ns() + " ";
            char c[] = new char[k];
            long ans = 0;
            for(int i = 0;i < k;i++)
            {
                c[i] = sc.next().charAt(0);
            }
            String cs = new String(c);
            long temp = 0;
            for(int i = 0;i < s.length();i++)
            {
                if(cs.contains(s.charAt(i)+""))
                    temp++;
                else
                {
                    ans += (temp * (temp+1)) / 2;
                    temp = 0;
                }
            }
            System.out.println(ans);
    }

    //constructor
    Main(){
        try{
            sc = new Scanner(System.in);
        }catch(Exception e){
            System.out.println(e);
        }
    }

    //main metohd
    public static void main(String[] args)
    {
     new Main().solve();
 }

    //Utility methods
        //input an integer from scanner
 int ni()
 {
    int a = sc.nextInt();
    return a;
}
        //input a long from scanner
long nl()
{
    return sc.nextLong();
}
        //input a float from scanner
float nf(){
    float a = sc.nextFloat();
    return a;
}
        //input a double from scanner
double nd(){
    double a = sc.nextDouble();
    return a;
}
        //input a sentence from scanner
String ns(){
    return sc.nextLine();
}
        //converts a string to stringtokenizer
StringTokenizer nst(String s){
    return new StringTokenizer(s);
}
        //input an intger array
void ia(int a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextInt();
}
        //
void la(long a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextLong();
}
        //input a float array
void fa(float a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextFloat();
}
        //input a double array
void da(double a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextDouble();
}
        //input a string array either with all empty input or from scanner
void sa(String a[], boolean empty){
    if(empty)
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = "";
        }
    }
    else
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = ns();
        }
    }
}
        //input two dimensional integer array
void ida(int a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = ni();
        }
    }
}
        //input two dimentional long array
void lda(long a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nl();
        }
    }
}
        //input two dimensional double array
void dda(double a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nd();
        }
    }
}
        //convert string to integer
int stoi(String s){
    return Integer.parseInt(s);
}
        //convert string to double
double stod(String s){
    return Double.parseDouble(s);
}
        //find minimum in a long array
long lmin(long a[])
{
    long min = Long.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find minimum in a integer array
int imin(int a[])
{
    int min = Integer.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find maximum in a long array
long lmax(long a[])
{
    long max = Long.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //find maximum in an integer array
int imax(int a[])
{
    int max = Integer.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //check whether an element is present in an integer array by binary search
boolean ibs(int a[], int toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}
        //check whether an element is present in a long array
boolean lbs(long a[], long toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}

int stb(String s)
{
    int sum = 0;
    int k = 0;
    for(int i = s.length()-1;i >= 0;i--)
    {
        sum += stoi(s.charAt(i)+"") * Math.pow(2, k++);
    }
    return sum;
}

}


// Java program For handling Input/Output
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main
{
    Scanner sc;
        //actual logic
    void solve(){
            int n = ni();
            int k = ni();
            ns();
            String s = ns() + " ";
            char c[] = new char[k];
            int ans = 0;
            for(int i = 0;i < k;i++)
            {
                c[i] = sc.next().charAt(0);
            }
            String cs = new String(c);
            String temp = "";
            for(int i = 0;i < s.length();i++)
            {
                if(cs.contains(s.charAt(i)+""))
                    temp += s.charAt(i);
                else
                {
                    int l = temp.length();
                    ans += (l * (l+1)) / 2;
                    temp = "";
                }
            }

            System.out.println(ans);
    }

    //constructor
    Main(){
        try{
            sc = new Scanner(System.in);
        }catch(Exception e){
            System.out.println(e);
        }
    }

    //main metohd
    public static void main(String[] args)
    {
     new Main().solve();
 }

    //Utility methods
        //input an integer from scanner
 int ni()
 {
    int a = sc.nextInt();
    return a;
}
        //input a long from scanner
long nl()
{
    return sc.nextLong();
}
        //input a float from scanner
float nf(){
    float a = sc.nextFloat();
    return a;
}
        //input a double from scanner
double nd(){
    double a = sc.nextDouble();
    return a;
}
        //input a sentence from scanner
String ns(){
    return sc.nextLine();
}
        //converts a string to stringtokenizer
StringTokenizer nst(String s){
    return new StringTokenizer(s);
}
        //input an intger array
void ia(int a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextInt();
}
        //
void la(long a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextLong();
}
        //input a float array
void fa(float a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextFloat();
}
        //input a double array
void da(double a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextDouble();
}
        //input a string array either with all empty input or from scanner
void sa(String a[], boolean empty){
    if(empty)
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = "";
        }
    }
    else
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = ns();
        }
    }
}
        //input two dimensional integer array
void ida(int a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = ni();
        }
    }
}
        //input two dimentional long array
void lda(long a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nl();
        }
    }
}
        //input two dimensional double array
void dda(double a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nd();
        }
    }
}
        //convert string to integer
int stoi(String s){
    return Integer.parseInt(s);
}
        //convert string to double
double stod(String s){
    return Double.parseDouble(s);
}
        //find minimum in a long array
long lmin(long a[])
{
    long min = Long.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find minimum in a integer array
int imin(int a[])
{
    int min = Integer.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find maximum in a long array
long lmax(long a[])
{
    long max = Long.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //find maximum in an integer array
int imax(int a[])
{
    int max = Integer.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //check whether an element is present in an integer array by binary search
boolean ibs(int a[], int toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}
        //check whether an element is present in a long array
boolean lbs(long a[], long toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}

int stb(String s)
{
    int sum = 0;
    int k = 0;
    for(int i = s.length()-1;i >= 0;i--)
    {
        sum += stoi(s.charAt(i)+"") * Math.pow(2, k++);
    }
    return sum;
}

}


// Java program For handling Input/Output
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main
{
    Scanner sc;
        //actual logic
    void solve(){
            int n = ni();
            int k = ni();
            ns();
            String s = ns() + " ";
            char c[] = new char[k];
            long ans = 0;
            for(int i = 0;i < k;i++)
            {
                c[i] = sc.next().charAt(0);
            }
            String cs = new String(c);
            int temp = 0;
            for(int i = 0;i < s.length();i++)
            {
                if(cs.contains(s.charAt(i)+""))
                    temp++;
                else
                {
                    ans += (long)(temp * (temp+1)) / 2;
                    temp = 0;
                }
            }

            System.out.println(ans);
    }

    //constructor
    Main(){
        try{
            sc = new Scanner(System.in);
        }catch(Exception e){
            System.out.println(e);
        }
    }

    //main metohd
    public static void main(String[] args)
    {
     new Main().solve();
 }

    //Utility methods
        //input an integer from scanner
 int ni()
 {
    int a = sc.nextInt();
    return a;
}
        //input a long from scanner
long nl()
{
    return sc.nextLong();
}
        //input a float from scanner
float nf(){
    float a = sc.nextFloat();
    return a;
}
        //input a double from scanner
double nd(){
    double a = sc.nextDouble();
    return a;
}
        //input a sentence from scanner
String ns(){
    return sc.nextLine();
}
        //converts a string to stringtokenizer
StringTokenizer nst(String s){
    return new StringTokenizer(s);
}
        //input an intger array
void ia(int a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextInt();
}
        //
void la(long a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextLong();
}
        //input a float array
void fa(float a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextFloat();
}
        //input a double array
void da(double a[]){
    for(int i = 0;i < a.length;i++)
        a[i] = sc.nextDouble();
}
        //input a string array either with all empty input or from scanner
void sa(String a[], boolean empty){
    if(empty)
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = "";
        }
    }
    else
    {
        for(int i = 0;i < a.length;i++)
        {
            a[i] = ns();
        }
    }
}
        //input two dimensional integer array
void ida(int a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = ni();
        }
    }
}
        //input two dimentional long array
void lda(long a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nl();
        }
    }
}
        //input two dimensional double array
void dda(double a[][], int n, int m)
{
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            a[i][j] = nd();
        }
    }
}
        //convert string to integer
int stoi(String s){
    return Integer.parseInt(s);
}
        //convert string to double
double stod(String s){
    return Double.parseDouble(s);
}
        //find minimum in a long array
long lmin(long a[])
{
    long min = Long.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find minimum in a integer array
int imin(int a[])
{
    int min = Integer.MAX_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(min > a[i])
            min = a[i];
    }
    return min;
}
        //find maximum in a long array
long lmax(long a[])
{
    long max = Long.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //find maximum in an integer array
int imax(int a[])
{
    int max = Integer.MIN_VALUE;
    for(int i = 0;i < a.length;i++)
    {
        if(max < a[i])
            max = a[i];
    }
    return max;
}
        //check whether an element is present in an integer array by binary search
boolean ibs(int a[], int toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}
        //check whether an element is present in a long array
boolean lbs(long a[], long toFind)
{
    Arrays.sort(a);
    int min = 0;
    int max = a.length-1;
    boolean found = false;

    while(min <= max && !found)
    {
        int mid = min + (max-min)/2;
        if(a[mid] == toFind)
        {
           found = true;
       }
       else if(toFind > a[mid])
       {
        min = mid+1;
    }
    else
    {
        max = mid-1;
    }

}
return found;
}

int stb(String s)
{
    int sum = 0;
    int k = 0;
    for(int i = s.length()-1;i >= 0;i--)
    {
        sum += stoi(s.charAt(i)+"") * Math.pow(2, k++);
    }
    return sum;
}

}


import java.util.*;

public class T {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int k=sc.nextInt();
			boolean[] c=new boolean[26];
			String s=sc.next();
			for(int i=0;i<k;i++){
				c[(int)(sc.next().charAt(0)-'a')]=true;
			}
			ArrayList<String> set=new ArrayList<String>();
			set.add(s);
			for(int i=0;i<26;i++){
//				System.out.println(setize());
				if(c[i])continue;
				int len=set.size();
				for(int j=0;j<len;j++){
					String ss[]=set.get(0).split(""+(char)(i+'a'));
					for(int l=0;l<ss.length;l++){
						set.add(ss[l]);
					}
					set.remove(0);
				}
			}
			int ans=0;
			for(String temp:set){
				ans+=(temp.length()+1)*temp.length()/2;
//				System.out.println(1);
			}
			System.out.println(ans);
		}
	}
}


import java.util.*;

public class C605 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt();
		ArrayList<String> list=new ArrayList<String>();
		String s=sc.next();
		list.add(s);
		boolean ch[]=new boolean[26];
		for(int i=0;i<k;i++){
			ch[sc.next().charAt(0)-'a']=true;
		}
		for(int i=0;i<26;i++){
			if(ch[i])continue;

			int len=list.size();
			for(int j=0;j<len;j++){
				String ss[]=list.get(0).split(""+(char)('a'+i));
				for(int ii=0;ii<ss.length;ii++){
					list.add(ss[ii]);
				}
				list.remove(0);
			}
		}
		int ans=0;
		for(String sss:list){
			ans+=(sss.length()*(sss.length()+1))/2;
		}
		System.out.println(ans);
	}
}


import java.util.*;

public class C605 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt();
		ArrayList<String> list=new ArrayList<String>();
		String s=sc.next();
		list.add(s);
		boolean ch[]=new boolean[26];
		for(int i=0;i<k;i++){
			ch[sc.next().charAt(0)-'a']=true;
		}
		for(int i=0;i<26;i++){
			if(ch[i])continue;

			int len=list.size();
			for(int j=0;j<len;j++){
				String ss[]=list.get(0).split(""+(char)('a'+i));
				for(int ii=0;ii<ss.length;ii++){
					list.add(ss[ii]);
				}
				list.remove(0);
			}
		}
		long ans=0;
		for(String sss:list){
			ans+=((long)sss.length()*(long)(sss.length()+1))/2;
		}
		System.out.println(ans);
	}
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.lang.StringBuffer;
public class ProbA {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int c = sc.nextInt();
        Map<Character, Boolean> hm = new HashMap<>();
        String s = sc.next();
        for (char ch = 'a'; ch <= 'z'; ch++){
            hm.put(ch, false);
        }
        for (int i = 0; i < c; i++){
            char ch = sc.next().charAt(0);
            hm.put(ch, true);
        }
        int beg = 0;
        int res = 0;
        while (beg < l){
            int end = beg;
            while (end < l){
                if (hm.get(s.charAt(end))){
                    ++end;
                }
                else{
                    res += ((end - beg + 1) * (end - beg)) / 2;
                    beg = end + 1;
                    break;
                }
            }
            if (end == l) {
                res += ((end - beg + 1) * (end - beg)) / 2;
                break;
            }
        }
        System.out.println(res);
    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.lang.StringBuffer;
public class ProbA {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int c = sc.nextInt();
        Map<Character, Boolean> hm = new HashMap<>();
        String s = sc.next();
        for (char ch = 'a'; ch <= 'z'; ch++){
            hm.put(ch, false);
        }
        for (int i = 0; i < c; i++){
            char ch = sc.next().charAt(0);
            hm.put(ch, true);
        }
        int beg = 0;
        long res = 0;
        while (beg < l){
            int end = beg;
            while (end < l){
                if (hm.get(s.charAt(end))){
                    ++end;
                }
                else{
                    res += ((end - beg + 1) * (end - beg)) / 2;
                    beg = end + 1;
                    break;
                }
            }
            if (end == l) {
                res += ((end - beg) * (end - beg - 1)) / 2;
                break;
            }
        }
        System.out.println(res);
    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.lang.StringBuffer;
public class ProbA {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int c = sc.nextInt();
        Map<Character, Boolean> hm = new HashMap<>();
        String s = sc.next();
        for (char ch = 'a'; ch <= 'z'; ch++){
            hm.put(ch, false);
        }
        for (int i = 0; i < c; i++){
            char ch = sc.next().charAt(0);
            hm.put(ch, true);
        }
        long beg = 0;
        long res = 0;
        while (beg < l){
            long end = beg;
            while (end < l){
                if (hm.get(s.charAt((int)end))){
                    ++end;
                }
                else{
                    res += ((end - beg + 1) * (end - beg)) / 2;
                    beg = end + 1;
                    break;
                }
            }
            if (end == l) {
                res += ((end - beg + 1) * (end - beg)) / 2;
                break;
            }
        }
        System.out.println(res);
    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.lang.StringBuffer;
public class ProbA {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int c = sc.nextInt();
        Map<Character, Boolean> hm = new HashMap<>();
        String s = sc.next();
        for (char ch = 'a'; ch <= 'z'; ch++){
            hm.put(ch, false);
        }
        for (int i = 0; i < c; i++){
            char ch = sc.next().charAt(0);
            hm.put(ch, true);
        }
        int beg = 0;
        long res = 0;
        while (beg < l){
            int end = beg;
            while (end < l){
                if (hm.get(s.charAt(end))){
                    ++end;
                }
                else{
                    res += ((end - beg + 1) * (end - beg)) / 2;
                    beg = end + 1;
                    break;
                }
            }
            if (end == l) {
                res += ((end - beg + 1) * (end - beg)) / 2;
                break;
            }
        }
        System.out.println(res);
    }
}


import java.util.*;
public class cf6
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();

        String s=sc.next();
        sc.nextLine();

        String t=sc.nextLine();
        int c=0;int ans=0;char ch;int i=0;
        for(i=0;i<n;i++)
        {
            ch=s.charAt(i);
            if(t.indexOf(ch)>=0)
            {
            c=c+1;

            if(i==n-1)
            {
            ans+=(c*(c+1))/2;

            }
            }
            else
            {

            ans+=(c*(c+1))/2;
            c=0;

            }
        }
        System.out.println(ans);
    }
}


import java.util.*;
public class cf6
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();

        String s=sc.next();
        sc.nextLine();

        String t=sc.nextLine();
        int c=0;int ans=0;char ch;int i=0;
        for(i=0;i<=n;i++)
        {
            ch=s.charAt(i);
            if(t.indexOf(ch)>=0)
            {
            c=c+1;

            if(i==n)
            {
            ans+=(c*(c+1))/2;

            }
            }
            else
            {

            ans+=(c*(c+1))/2;
            c=0;

            }
        }
        System.out.println(ans);
    }
}


import java.util.*;
public class cf6
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();

        String s=sc.next();
        sc.nextLine();

        String t=sc.nextLine();
        long c=0;long ans=0;char ch;int i=0;
        for(i=0;i<n;i++)
        {
            ch=s.charAt(i);
            if(t.indexOf(ch)>=0)
            {
            c=c+1;

            if(i==n-1)
            {
            ans+=(c*(c+1))/2;

            }
            }
            else
            {

            ans+=(c*(c+1))/2;
            c=0;

            }
        }
        System.out.println(ans);
    }
}


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

public class Div2_605_C {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]), k = Integer.parseInt(str[1]);
		String s = br.readLine();
		int[] c = new int[26];
		str = br.readLine().split(" ");
		for(int i=0; i<k; i++) {
				c[str[i].charAt(0)-97] = 1;
			}
			long[] dp = new long[n+1];
			int tmp = 0;
			for(int i=0; i<n; i++) {
				if(c[s.charAt(i)-97]==1) {
				dp[i+1] = dp[i]+(tmp+1);
				tmp++;
			}
			else {
				dp[i+1] = dp[i];
				tmp = 0;
			}
		}
		System.out.println(dp[n]);
	}
}


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

public class Div2_605_C {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]), k = Integer.parseInt(str[1]);
		String s = br.readLine();
		int[] c = new int[26];
		str = br.readLine().split(" ");
		for(int i=0; i<k; i++) {
				c[str[i].charAt(0)-97] = 1;
			}
			int[] dp = new int[n+1];
			int tmp = 0;
			for(int i=0; i<n; i++) {
				if(c[s.charAt(i)-97]==1) {
				dp[i+1] = dp[i]+(tmp+1);
				tmp++;
			}
			else {
				dp[i+1] = dp[i];
				tmp = 0;
			}
		}
		System.out.println(dp[n]);
	}
}


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

public class Div2_605_C {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]), k = Integer.parseInt(str[1]);
		String s = br.readLine();
		int[] c = new int[26];
		str = br.readLine().split(" ");
		for(int i=0; i<k; i++) {
			c[str[i].charAt(0)-96] = 1;
		}
		int[] dp = new int[n+1];
		int tmp = 0;
		for(int i=0; i<n; i++) {
			if(c[s.charAt(i)-96]==1) {
				dp[i+1] = dp[i]+(tmp+1);
				tmp++;
			}
			else {
				dp[i+1] = dp[i];
				tmp = 0;
			}
		}
		System.out.println(dp[n]);
	}
}


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

public class C1272 {
    private StreamTokenizer in;
    private PrintWriter out;

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

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

    public C1272() {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
    }

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

    public void solve() throws IOException {
        MyScanner ss = new MyScanner();

        int n = ss.nextInt();
        int k = ss.nextInt();
        char[] line = new char[n];
        for (int i = 0; i < n; i++) {
            line[i] = (char) ss.nextChar();
        }

        Set<Character> letters = new HashSet<>();
        while (letters.size() != k) {
            Character character = Character.valueOf((char) ss.nextChar());
            if (Character.isLetter(character))
                letters.add(character);
        }
        long sum = 0;

        long count = 0;
        for (int i = 0; i <= n; i++) {
            if (i == n) {
                sum += count * (count + 1) / 2;
                continue;
            }
            if (!letters.contains(line[i])) {
                sum += count * (count + 1) / 2;
                count = 0;
            } else count++;

        }
        System.out.println(sum);
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        int nextChar() {
            try {
                return br.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return -1;
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


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

public class C1272 {
    private StreamTokenizer in;
    private PrintWriter out;

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

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

    public C1272() {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
    }

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

    public void solve() throws IOException {
        MyScanner ss = new MyScanner();

        int n = ss.nextInt();
        int k = ss.nextInt();
        char[] line = new char[n];
        for (int i = 0; i < n; i++) {
            line[i] = (char) ss.nextChar();
        }

        Set<Character> letters = new HashSet<>();
        while (letters.size() != k) {
            Character character = Character.valueOf((char) ss.nextChar());
            if (Character.isLetter(character))
                letters.add(character);
        }
        long sum = 0;

        int count = 0;
        for (int i = 0; i <= n; i++) {
            if (i == n) {
                sum += count * (count + 1) / 2;
                continue;
            }
            if (!letters.contains(line[i])) {
                sum += count * (count + 1) / 2;
                count = 0;
            } else count++;

        }
        System.out.println(sum);
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        int nextChar() {
            try {
                return br.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return -1;
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class C1272 {
    private StreamTokenizer in;
    private PrintWriter out;

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

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

    public C1272() {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
    }

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

    public void solve()  throws IOException{
        int n = nextInt();
        int k = nextInt();
        String s = nextString();

        Set<Character> letters = new HashSet<>();
        for (int i = 0; i < k; i++) {
            letters.add(nextString().trim().charAt(0));
        }
        long sum = 0;

        int count = 0;
        for (int i = 0; i <= s.length(); i++) {
            if (i == s.length()) {
                sum += count*(count+1)/2;
                continue;
            }
            if (!letters.contains(s.charAt(i))) {
                sum += count*(count+1)/2;
                count=0;
            }else count++;

        }
        System.out.println(sum);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(System.out);
        String [] inp = reader.readLine().split(" ");
        int n = Integer.parseInt(inp[0]);
        int k = Integer.parseInt(inp[1]);
        String input = reader.readLine();
        String [] split = reader.readLine().split(" ");
        HashSet<Character> set = new HashSet<>();
        for(int i=0; i<k ; i++){
            set.add(split[i].charAt(0));
        }
        long ans = 0;
        long cnt = 0;
        for (int i = 0; i < n; i++) {
            if(set.contains(input.charAt(i))){
                cnt++;
                continue;
            }
            ans += ((cnt * (cnt+1) ) / 2);
            cnt=0;
        }
        ans += (cnt * (cnt+1) ) / 2;
        writer.println(ans);
        writer.flush();

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(System.out);
        String [] inp = reader.readLine().split(" ");
        int n = Integer.parseInt(inp[0]);
        int k = Integer.parseInt(inp[1]);
        String input = reader.readLine();
        String [] split = reader.readLine().split(" ");
        HashSet<String> set = new HashSet<>();
        for(int i=0; i<k ; i++){
            set.add(split[i]);
        }
        long ans = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if(!set.contains(Character.toString(input.charAt(i)))){
                ans += (cnt * (cnt+1) ) / 2;
                cnt = 0;
                continue;
            }
            cnt++;
        }
        ans += (cnt * (cnt+1) ) / 2;
        writer.println(ans);
        writer.flush();

    }

}


#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i;

	cin >> n >> k;
	int arri[2 * n + 1];
	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

	for (int i = 0; i < 2 * n+1; i++){

		if (arri[i]>arri[i + 1]+1 && k   && arri[i]>arri[i - 1]+1)
		{
			--k;
			arri[i] -= 1;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[100];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

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

		if (arri[i]>arri[i + 1]+1 && k  && arri[i]>arri[i - 1]+1)
		{
			--k;
			arri[i] -= 1;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[100];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

	for (int i = 1; i <= (2 * n + 1); i++){
		a = 1;
		if (arri[i]>arri[i + 1] && arri[i]>arri[i - 1])
		{
			arri[i] -= 1;
			++a;
		}
		if (a==3)
		{
			break;
		}
	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[100];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

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

		if (arri[i]>arri[i + 1]+1 && k  && arri[i]>arri[i - 1]+1)
		{
			--k;
			arri[i] -= 1;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[100];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

	for (int i = 1; i <= (2 * n + 1); i++){
		a = 1;
		if (arri[i]>arri[i + 1] && arri[i]>arri[i - 1])
		{
			arri[i] -= 1;
			a++;
		}
		if (a==3)
		{
			break;
		}
	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[100];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

	a = 0;
	for (int i = 1; i <= (2 * n + 1); i++){

		if (a == k)
		{
			 break;
		}

		if (arri[i]>arri[i + 1] && arri[i]>arri[i - 1])
		{
			arri[i] -= 1;
			a++;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[100];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

	a = 1;
	for (int i = 1; i <= (2 * n + 1); i++){

		if (a == 3)
		{
			 break;
		}

		if (arri[i]>arri[i + 1] && arri[i]>arri[i - 1])
		{
			arri[i] -= 1;
			a++;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[99];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

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

		if (arri[i]>arri[i + 1]+1 && k  && arri[i]>arri[i - 1]+1)
		{
			--k;
			arri[i] -= 1;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i;
	int arri[2 * n + 1];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

	for (int i = 0; i < 2 * n+1; i++){

		if (arri[i]>arri[i + 1]+1 && k   && arri[i]>arri[i - 1]+1)
		{
			--k;
			arri[i] -= 1;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[101];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

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

		if (arri[i]>arri[i + 1]+1 && k   && arri[i]>arri[i - 1]+1)
		{
			--k;
			arri[i] -= 1;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n, k, i,a;
	int arri[101];
	cin >> n >> k;

	for (int j = 0; j < ((2 * n + 1) ); j++){
		cin >> i;
		arri[j] = i;}

	for (int i = 0; i < 2 * n+1; i++){

		if (arri[i]>arri[i + 1]+1 && k && i%2==1  && arri[i]>arri[i - 1]+1)
		{
			--k;
			arri[i] -= 1;
		}

	}

	for (int i = 0; i < (2*n+1) ; i++)
	{
		cout << arri[i]<<" ";
	}

	cout << endl;
		return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
n = 2*n + 1;
int a[n+10];
for(int i=1;i<=n;i++)
    cin>>a[i];
for(int i=1;i<=n,k;i++){
    if( a[i] - 1 > 0 && a[i]-1 != a[i-1] && a[i]-1 != a[i+1])
        {
            a[i]--;
            k --;
        }
}
for(int i=1;i<=n;i++)
    cout<<a[i]<<" ";
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
n = 2*n + 1;
int a[n+10];
for(int i=1;i<=n;i++)
    cin>>a[i];
int l = k;
for(int i=l;i<=n,k;i+=l){
    if( a[i] - 1 > 0 && a[i]-1 != a[i-1] && a[i]-1 != a[i+1])
        {
            a[i]--;
            k --;
        }
}
for(int i=1;i<=n;i++)
    cout<<a[i]<<" ";
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
n = 2*n + 1;
int a[n+10];
for(int i=1;i<=n;i++)
    cin>>a[i];
int l = k;
for(int i=l;i<=n,k;i+=l){
    if( a[i]!=0 && a[i]-1 != a[i-1] && a[i]-1 != a[i+1])
        {
            a[i]--;
            k --;
        }
}
for(int i=1;i<=n;i++)
    cout<<a[i]<<" ";
}


#include <iostream>
using namespace std;
int main(){
int n,r;
cin>>n>>r;
n =2*n + 1;
int a[n+10];
for(int i = 1; i <= n;i ++)
    cin>>a[i];
int k = 1;
for(int i=r*r;i<=n,k<=r;i+=r){
    if(a[i]!=0)
        a[i]--,k++;
}
for(int i=1;i<=n;i++)
    cout<<a[i]<<" ";
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
n = 2*n + 1;
int a[n+10];
for(int i=1;i<=n;i++)
    cin>>a[i];
for(int i=2;i<=n,k;i+=2){
    if( a[i] - 1 > 0 && a[i]-1 != a[i-1] && a[i]-1 != a[i+1])
        {
            a[i]--;
            k --;
        }
}
for(int i=1;i<=n;i++)
    cout<<a[i]<<" ";
}


#include <cstdio>

int n,k,a[220];
bool boo[220];

void work() {
	int temp=0;
	for (int i=2;i<=n+n;++i)
		if ((!boo[i])&&(a[i-1]<a[i]-1)&&(a[i]-1>a[i+1]))
				if ((!temp)||(a[temp]<a[i])) temp=i;
	--a[temp];
	boo[temp]=true;
}

int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<n+n+1;++i) scanf("%d",&a[i]);
	for (int i=1;i<=k;++i) work();
	for (int i=1;i<=n+n;++i) printf("%d ",a[i]);
	printf("%d\n",a[n+n+1]);
	return 0;
}


#include <cstdio>

int n,k,a[220];

void work() {
	int temp=0;
	for (int i=1;i<=n;++i)
		if ((a[i+i-1]<a[i+i]-1)&&(a[i+i]-1>a[i+i+1]))
			if ((!temp)||(a[temp]<a[i+i])) temp=i+i;
	--a[temp];
}

int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<n+n+1;++i) scanf("%d",&a[i]);
	for (int i=1;i<=k;++i) work();
	for (int i=1;i<=n+n;++i) printf("%d ",a[i]);
	printf("%d\n",a[n+n+1]);
	return 0;
}


#include <cstdio>

int n,k,a[220];
bool boo[220];

void work() {
	int temp;
	for (temp=1;temp<=n;++temp)
		if (!boo[temp+temp]) break;
	--a[temp+temp];
	boo[temp+temp]=true;
}

int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<n+n+1;++i) scanf("%d",&a[i]);
	for (int i=1;i<=k;++i) work();
	for (int i=1;i<=n+n;++i) printf("%d ",a[i]);
	printf("%d\n",a[n+n+1]);
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
long long n, m, k, i, j=1, a[10000], b[10000], c[10000], i1, p=1;
main(){
       cin>>n>>k;
       m=n*2+1;
       for(i=1;i<=m;i++){
                         cin>>a[i];
                         if(i%2==0 && p<=k){
                                    c[i]=a[i]-1;
                                    p++;
                                    }
                         }
       p=1;
       sort(c+1,c+i1+1);
       for(i=1;i<=m;i++){
                         if(i%2==0 && p<=k){
                                            cout<<c[i]<<" ";
                                            p++;
                                            }
                         else{
                              cout<<a[i]<<" ";
                              }
                         }
       //system("pause");
       }


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
long long n, m, k, i, j=1, a[10000], b[10000], c[10000], i1, p=1;
main(){
       cin>>n>>k;
       m=n*2+1;
       for(i=1;i<=m;i++){
                         cin>>a[i];
                         if(i%2==0 && j<=k){
                                            c[j]=a[i]-1;
                                            j++;
                                            }
                                            }

       sort(c+1,c+j);
       reverse(c+1,c+j);
       j=1;
       for(i=m;i>=1;i--){
                         if(i%2==0 && j<=k){
                                            a[i]=c[j];
                                            j++;
                                            }
                         }
       for(i=1;i<=m;i++){
                         cout<<a[i]<<" ";
                         }
      // system("pause");
       }


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
long long n, m, k, i, j=1, a[10000], b[10000], c[10000], i1, p=1;
main(){
       cin>>n>>k;
       m=n*2+1;
       for(i=1;i<=m;i++){
                         cin>>a[i];
                         if(i%2==0 && j<=k){
                                            c[j]=a[i]-1;
                                            j++;
                                            }
                         }
       cout<<endl;
       sort(c+1,c+j);
       j=1;
       for(i=1;i<=m;i++){
                         if(i%2==0 && j<=k){
                                            cout<<c[j]<<" ";
                                            j++;
                                            }
                         else{
                              cout<<a[i]<<" ";
                              }
                         }
       //system("pause");
       }


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
long long n, m, k, i, j=1, a[10000], b[10000], p=1;
main(){
       cin>>n>>k;
       m=n*2+1;
       for(i=1;i<=m;i++){
                         cin>>a[i];
                         if(i%2==0 && p<=k){
                                    cout<<a[i]-1<<" ";
                                    p++;
                                    }
                         else{
                              cout<<a[i]<<" ";
                              }
                         }
       //system("pause");
       }


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
long long n, m, k, i, j=1, a[10000], b[10000], c[10000], i1, p=1;
main(){
       cin>>n>>k;
       m=n*2+1;
       for(i=1;i<=m;i++){
                         cin>>a[i];
                         if(i%2==0 && p<=k){
                                    c[i]=a[i]-1;
                                    p++;
                                    }
                         }
       p=1;
       sort(c+1,c+i+1);
       for(i=1;i<=m;i++){
                         if(i%2==0 && p<=k){
                                            cout<<c[i]<<" ";
                                            p++;
                                            }
                         else{
                              cout<<a[i]<<" ";
                              }
                         }
       //system("pause");
       }


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <string>
# include <vector>
# include <algorithm>
# include <map>
# include <set>
# include <cmath>
# include <queue>
# define pb push_back

using namespace std;

typedef long long ll;
const int MAXN = 503;

int cnt[1000];
int a[1000];

int main () {

	int n, k;
	scanf("%d%d", &n, &k);
		for(int i = 1; i <= 2 * n + 1; ++i) {
			scanf("%d", &a[i]);
		if(k > 0 && i % 2 == 0 && a[i] - a[i - 1] > 1 && a[i] - a[i + 1] > 1) {
			cout << a[i] - 1 << ' ' ;
			k --;
		}
		else cout << a[i] << ' ';
	}

			return 0;

}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <string>
# include <vector>
# include <algorithm>
# include <map>
# include <set>
# include <cmath>
# include <queue>
# define pb push_back

using namespace std;

typedef long long ll;
const int MAXN = 503;

int cnt[MAXN];
int a[MAXN];

int main () {

	int n, k;
	scanf("%d%d", &n, &k);
		for(int i = 1; i <= 2 * n + 1; ++i) {
			scanf("%d", &a[i]);
			if(i % 2 == 0)cnt[a[i]] ++;
		}

	for(int j = 0; j <= MAXN; ++j)
		if(cnt[j] >= k) {
			for(int i = 1; i <= 2 * n + 1; ++i)
			   if(a[i] == j && k > 0) {
					cout << a[i] - 1 << ' ';
					k --;
				}
				else cout << a[i] << ' ';
			return 0;
		}

}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <string>
# include <vector>
# include <algorithm>
# include <map>
# include <set>
# include <cmath>
# include <queue>
# define pb push_back

using namespace std;

typedef long long ll;
const int MAXN = 103;

int cnt[MAXN];
int a[MAXN];

int main () {

	int n, k;
	scanf("%d%d", &n, &k);
		for(int i = 1; i <= 2 * n + 1; ++i) {
			scanf("%d", &a[i]);
			if(i % 2 == 0)cnt[a[i]] ++;
		}

	for(int j = 0; j <= MAXN; ++j)
		if(cnt[j] >= k) {
			for(int i = 1; i <= 2 * n + 1; ++i)
			   if(a[i] == j && k > 0) {
					cout << a[i] - 1 << ' ';
					k --;
				}
				else cout << a[i] << ' ';
			return 0;
		}

}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <string>
# include <vector>
# include <algorithm>
# include <map>
# include <set>
# include <cmath>
# include <queue>
# define pb push_back

using namespace std;

typedef long long ll;
const int MAXN = 503;

int cnt[1000];
int a[1000];

int main () {

	int n, k;
	scanf("%d%d", &n, &k);
		for(int i = 1; i <= 2 * n + 1; ++i) {
			scanf("%d", &a[i]);
			if(i % 2 == 0)cnt[a[i]] ++;
		}

	for(int j = 0; j <= MAXN; ++j)
		if(cnt[j] >= k) {
			for(int i = 1; i <= 2 * n + 1; ++i)
			   if(a[i] == j && k > 0 && i % 2 == 0) {
					cout << a[i] - 1 << ' ';
					k --;
				}
				else cout << a[i] << ' ';
			return 0;
		}

}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <string>
# include <vector>
# include <algorithm>
# include <map>
# include <set>
# include <cmath>
# include <queue>
# define pb push_back

using namespace std;

typedef long long ll;
const int MAXN = 503;

int cnt[1000];
int a[1000];

int main () {

	int n, k;
	scanf("%d%d", &n, &k);
		for(int i = 1; i <= 2 * n + 1; ++i) {
			scanf("%d", &a[i]);
		if(k > 0 && i % 2 == 0) {
			cout << a[i] - 1 << ' ' ;
			k --;
		}
		else cout << a[i] << ' ';
	}

			return 0;

}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <string>
# include <vector>
# include <algorithm>
# include <map>
# include <set>
# include <cmath>
# include <queue>
# define pb push_back

using namespace std;

typedef long long ll;
const int MAXN = 503;

int cnt[1000];
int a[1000];

int main () {

	int n, k;
	scanf("%d%d", &n, &k);
		for(int i = 1; i <= 2 * n + 1; ++i) {
			scanf("%d", &a[i]);
		}
	for(int i = 1; i <= 2 * n + 1; ++i) {
		if(k > 0 && i % 2 == 0 && a[i] - a[i - 1] > 1 && a[i] - a[i + 1] > 1) {
			cout << a[i] - 1 << ' ' ;
			k --;
		}
		else cout << a[i] << ' ';
	}

			return 0;

}


#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int a[250];
int main(){
   int n, i, k, j;
   while(!(cin >> n >> k).eof()){
      int temp = -100;
      for(i = 0;i < 2 * n + 1 ; i ++){
         cin >> a[i];
      }
      for(i = 1,j = 0; i < 2 * n;i ++){
            if((a[i] - 2 >= a[0] )&& (a[i] - 2 >= a[2 * n])){
               j ++;
               a[i] = a[i] - 1;
            }
            if(j == k)
               break;
         }
      cout << a[0];
      for(i = 1;i < 2 * n + 1;i ++){
         printf(" %d",a[i]);
      }
      cout << endl;
   }
}


#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int a[250];
int main(){
   int n, i, k, j;
   while(!(cin >> n >> k).eof()){
      int temp = -100;
      for(i = 0;i < 2 * n + 1 ; i ++){
         cin >> a[i];
         if(a[i] > temp)
            temp = a[i];
      }
      if(temp != 0)
         for(i = 0,j = 0; i < 2 * n + 1;i ++){
            if(a[i] == temp){
               j ++;
               a[i] = a[i] - 1;
            }
            if(j == k)
               break;
         }
      cout << a[0];
      for(i = 1;i < 2 * n + 1;i ++){
         printf(" %d",a[i]);
      }
      cout << endl;
   }
}


#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int a[250];
int main(){
   int n, i, k, j;
   while(!(cin >> n >> k).eof()){
      int temp = -100;
      for(i = 0;i < 2 * n + 1 ; i ++){
         cin >> a[i];
         if(a[i] > temp)
            temp = a[i];
      }
      for(i = 0,j = 0; i < 2 * n + 1;i ++){
         if(a[i] == temp){
            j ++;
            a[i] = a[i] - 1;
         }
         if(j == k)
            break;
      }
      cout << a[0];
      for(i = 1;i < 2 * n + 1;i ++){
         printf(" %d",a[i]);
      }
      cout << endl;
   }
}


#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int a[250];
int main(){
   int n, i, k, j;
   while(!(cin >> n >> k).eof()){
      int temp = -100;
      for(i = 0;i < 2 * n + 1 ; i ++){
         cin >> a[i];
      }
      for(i = 1,j = 0; i < 2 * n;i ++){
            if((a[i] - 2 > a[0] )&& (a[i] - 2 > a[2 * n])){
               j ++;
               a[i] = a[i] - 1;
            }
            if(j == k)
               break;
         }
      cout << a[0];
      for(i = 1;i < 2 * n + 1;i ++){
         printf(" %d",a[i]);
      }
      cout << endl;
   }
}


#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int a[250];
int main(){
   int n, i, k, j;
   while(!(cin >> n >> k).eof()){
      int temp = -100;
      for(i = 0;i < 2 * n + 1 ; i ++){
         cin >> a[i];
      }
      for(i = 1,j = 0; i < 2 * n;i ++){
            if((a[i] - 2 >= a[i-1] )&& (a[i] - 2 >= a[i + 1])){
               j ++;
               a[i] = a[i] - 1;
            }
            if(j == k)
               break;
         }
      cout << a[0];
      for(i = 1;i < 2 * n + 1;i ++){
         printf(" %d",a[i]);
      }
      cout << endl;
   }
}


#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int a[250];
int main(){
   int n, i, k, j;
   while(!(cin >> n >> k).eof()){
      int temp = INT_MIN;
      for(i = 0;i < 2 * n + 1 ; i ++){
         cin >> a[i];
         if(a[i] > temp)
            temp = a[i];
      }
      for(i = 0,j = 0; i < 2 * n + 1;i ++){
         if(a[i] == temp){
            j ++;
            a[i] = a[i] - 1;
         }
         if(j == k)
            break;
      }
      cout << a[0];
      for(i = 1;i < 2 * n + 1;i ++){
         printf(" %d",a[i]);
      }
      cout << endl;
   }
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int freq[11];

int main()
{
	io();
	int n, m;
	cin >> n >> m;
	int a[n];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		++freq[a[i]];
	}
	ll cnt = 0;
	for (int i = 1; i < 11; ++i) {
		cnt += ((n - freq[i]) * freq[i]);
		n -= freq[i];
	}
	cout << cnt;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main()
{
	io();
	int n, m;
	cin >> n >> m;
	ll a[n], cnt = 0;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			if (a[i] != a[j]) ++cnt;
	cout << cnt / 2;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000000
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto c:v) cout<<" "<<c; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
void solve(){
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	ll a[n];
	ll cnt[m+1]={0};
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	ll ans=0;
	//dbg_v(cnt);
	for(int i=0;i<n;i++){
		ans=ans+n-cnt[a[i]];
	}
	cout<<ans/2<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000000
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto c:v) cout<<" "<<c; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
void solve(){
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	ll a[n];
	ll cnt[m+1]={0};
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	ll ans=0;
	//dbg_v(cnt);
	for(int i=0;i<n;i++){
		ans+=n-cnt[a[i]];
	}
	cout<<ans/2<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000000
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto c:v) cout<<" "<<c; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
void solve(){
	int n;
	cin>>n;
	int m;
	cin>>m;
	int a[n];
	int cnt[m+1]={0};
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	int ans=0;
	//dbg_v(cnt);
	for(int i=0;i<n;i++){
		ans+=n-cnt[a[i]];
	}
	cout<<ans/2<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;

ll fact(ll n) {
	if(n == 1 || n == 0)
		return 1;
	return n * fact(n - 1);
}

int main () {
	ll n, m;
	cin >> n >> m;
	vector<ll>books(m+1, 0);
	for(ll i = 0; i < n; i++) {
		ll temp;
		cin >> temp;
		books[temp]++;
	}
	ll sum = 0;
	for(ll i = 1; i <= m; i++) {
		ll p = (fact(books[i]) / fact(books[i] - 1));
		for(ll j = i+1; j <= m; j++) {
			sum += p * (fact(books[j]) / fact(books[j] - 1));
		}
	}
	// cout << fact(10) << endl;
	cout << sum << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;

ll fact(ll n) {
	if(n == 1 || n == 0)
		return 1;
	return n * fact(n - 1);
}

int main () {
	ll n, m;
	cin >> n >> m;
	vector<ll>books(m+1, 0);
	for(ll i = 0; i < n; i++) {
		ll temp;
		cin >> temp;
		books[temp]++;
	}
	ll sum = 0;
	for(ll i = 1; i < m; i++) {
		ll p = (fact(books[i]) / fact(books[i] - 1));
		for(ll j = i+1; j <= m; j++) {
			sum += p * (fact(books[j]) / fact(books[j] - 1));
		}
	}
	// cout << fact(10) << endl;
	cout << sum << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll fact(ll n) {
	if(n == 1 || n == 0)
		return 1;
	return n * fact(n - 1);
}

int main () {
	ll n, m;
	cin >> n >> m;
	vector<ll>books(m+1, 0);
	for(ll i = 0; i < n; i++) {
		ll temp;
		cin >> temp;
		books[temp]++;
	}
	ll sum = 0;
	for(ll i = 1; i <= m; i++) {
		ll p = (fact(books[i]) / fact(books[i] - 1));
		for(ll j = i+1; j <= m; j++) {
			sum += p * (fact(books[j]) / fact(books[j] - 1));
		}
	}
	cout << sum << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;

ll fact(ll n) {
	if(n == 1 || n == 0)
		return 1;
	return n * fact(n - 1);
}

int main () {
	ll n, m;
	cin >> n >> m;
	vector<ll>books(m+1, 0);
	for(ll i = 0; i < n; i++) {
		ll temp;
		cin >> temp;
		books[temp]++;
	}
	ll sum = 0;
	for(ll i = 1; i < m; i++) {
		// ll p = (fact(books[i]) / fact(books[i] - 1));
		for(ll j = i+1; j <= m; j++) {
			// sum += p * (fact(books[j]) / fact(books[j] - 1));
			sum += books[i] * books[j];
		}
	}
	// cout << fact(0) << endl;
	cout << sum << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
	ll co[11];
int main()
{
	ll n,m,sum=0;
	cin>>n>>m;
	memset(co,0,sizeof co);
	std::vector<int> v;
	for(int i=0;i<n;i++)
	{	ll x;
		cin>>x;
		co[x]++;
//		sum+=x;
//		v.push_back(x);
	}
//	sort(v.begin(),v.end());

	for(int i=1;i<=m;i++)
	{
		for(int j=i+1;j<=m;j++)
		{
			sum+=co[i]*co[j];
		}
	}
	cout<<sum<<endl;
}


#include<bits/stdc++.h>

#define sf(x) scanf("%d",&x)
#define MN 1234567

#define fr(i,a,b) for(i=a;i<b;i++)
using namespace std;

int main()
{
int i,j,n,x,m;
cin>>n>>m;
int b[15];
memset(b,0,sizeof(b));
for(i=0;i<n;i++)
{
cin>>x;
b[x]++;
}
int ans=0;
for(i=1;i<=m;i++)
{
    fr(j,i+1,m+1)
{

    ans+=b[i]*b[j];
}    }

cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,m,sum=0;
	cin>>n>>m;
	std::vector<int> v;
	for(int i=0;i<n;i++)
	{	int x;
		cin>>x;
//		sum+=x;
		v.push_back(x);
	}
	sort(v.begin(),v.end());

	for(int i=0;i<v.size();i++)
	{
		for(int j=i+1;j<v.size();j++)
		{
			if(v[j]-v[i]<1)
				continue;
			sum+=(v.size()-j);
			break;
		}
	}
	cout<<sum<<endl;

}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    int n,m;

    cin>>n>>m;

    map<int,int>mp;

    for(int i=0;i<n;i++)    {
        int a;
        cin>>a;
        mp[a]++;
    }

    int cnt=0;

    for(int i=1;i<=m;i++)   {
        for(int j=i+1;j<=m;j++) {
            cnt+=mp[i]*mp[j];
        }
    }
    cout<<cnt<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    int n,m;

    cin>>n>>m;

    int a[n+1];

    for(int i=1;i<=n;i++)    cin>>a[i];

    sort(a+1,a+n+1);

    if(a[1]==a[n])  {
        cout<<0<<endl;
        return 0;
    }

    int cnt=0;

    for(int i=1;i<=n;i++)    {
        if(a[i]!=a[i+1])    {
            cnt+=(n-i);
        }
        else {
            int j=i;
            while(j<=n && a[j]==a[j+1]) {
                j++;
            }
            cnt+=(n-j);
        }
    }
    cout<<cnt<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    int n,m;

    cin>>n>>m;

    int a[n+1];

    for(int i=1;i<=n;i++)    cin>>a[i];

    sort(a+1,a+n+1);

    int cnt=0;

    for(int i=1;i<=n;i++)    {
        if(a[i]!=a[i+1])    {
            cnt+=(n-i);
        }
        else {
            int j=i;
            while(j<=n && a[j]==a[j+1]) {
                j++;
            }
            cnt+=(n-j);
        }
    }
    cout<<cnt<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define fori(i,sar,tah) for (int (i)=(sar);(i)<(tah);++(i))
#define SQRT 107
#define MAXN 1000000007
#define INF 1e9+1
#define ERR (1e-7)
#define equals(a,b) (fabs((a)-(b))<ERR)
#define pi pair<int,int>
#define pii pair<ll,ll>
#define x first
#define y second
#define e 2.7182818284590452353602874713527
const ll MOD = 1e9 + 7;
const int SIZE = 1e5+3;
int n, m, a;
ll ans = 0;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    vector<int> arr(m+3);
    rep(i,n){
    	cin>>a;
    	arr[a]++;
	}
	for(int i=1;i<=m;i++){
		for(int j=i+1;j<=m;j++){

				ans += arr[i]*arr[j];

		}
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define fori(i,sar,tah) for (int (i)=(sar);(i)<(tah);++(i))
#define SQRT 107
#define MAXN 1000000007
#define INF 1e9+1
#define ERR (1e-7)
#define equals(a,b) (fabs((a)-(b))<ERR)
#define pi pair<int,int>
#define pii pair<ll,ll>
#define x first
#define y second
#define e 2.7182818284590452353602874713527
const ll MOD = 1e9 + 7;
const int SIZE = 1e5+3;
int n, m, a;
ll ans = 0;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    int *arr = new int[m+1];
    rep(i,n){
    	cin>>a;
    	arr[a]++;
	}
	for(int i=1;i<=m;i++){
		for(int j=i+1;j<=m;j++){

				ans += arr[i]*arr[j];

		}
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define fori(i,sar,tah) for (int (i)=(sar);(i)<(tah);++(i))
#define SQRT 107
#define MAXN 1000000007
#define INF 1e9+1
#define ERR (1e-7)
#define equals(a,b) (fabs((a)-(b))<ERR)
#define pi pair<int,int>
#define pii pair<ll,ll>
#define x first
#define y second
#define e 2.7182818284590452353602874713527
const ll MOD = 1e9 + 7;
const int SIZE = 1e5+3;
int n, m, a;
ll ans = 0;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    int *arr = new int[m+1];
    rep(i,n){
    	cin>>a;
    	arr[a]++;
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++){
			if(i!=j){
				ans += arr[i]*arr[j];
			}
		}
	}
	cout<<ans/2;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef priority_queue<int> pqi1; //priority queue int
typedef priority_queue<int, vector<int>, greater<int>> pqi2; //reverse pq int

#define F first
#define S second
#define PB push_back
#define V vector
#define FOR1(i,a,b) for(int i=a; i<b; i++)
#define FOR(i,a) for (int i=0; i<a; i++)
int n, m;

int main()
{
    int n, m;
    cin >> n >> m;
    ll arr[11];
    FOR(i, 11) {
        arr[i] = 0;
    }
    FOR(i, n) {
        int a;
        cin >> a;
        arr[a]++;
    }
    ll ans = n * n;
    FOR(i, 11) {
        ans -= arr[i] * arr[i];
    }
    ans /= 2;
    cout << ans << endl;

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef priority_queue<int> pqi1; //priority queue int
typedef priority_queue<int, vector<int>, greater<int>> pqi2; //reverse pq int

#define F first
#define S second
#define PB push_back
#define V vector
#define FOR1(i,a,b) for(int i=a; i<b; i++)
#define FOR(i,a) for (int i=0; i<a; i++)
int n, m;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll arr[11];
    FOR(i, 11) {
        arr[i] = 0;
    }
    FOR(i, n) {
        ll a;
        cin >> a;
        arr[a]++;
    }
    ll ans = n * n;
    FOR(i, 11) {
        ans -= (arr[i] * arr[i]);
    }
    ans /= 2;
    cout << ans << endl;

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef priority_queue<int> pqi1; //priority queue int
typedef priority_queue<int, vector<int>, greater<int>> pqi2; //reverse pq int

#define F first
#define S second
#define PB push_back
#define V vector
#define FOR1(i,a,b) for(int i=a; i<b; i++)
#define FOR(i,a) for (int i=0; i<a; i++)
int n, m;

int main()
{
    int n, m;
    cin >> n >> m;
    int arr[11];
    FOR(i, m + 1) {
        arr[i] = 0;
    }
    FOR(i, n) {
        int a;
        cin >> a;
        arr[a]++;
    }
    int ans = n * n;
    FOR(i, m+1) {
        ans -= arr[i] * arr[i];
    }
    ans /= 2;
    cout << ans << endl;

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef priority_queue<int> pqi1; //priority queue int
typedef priority_queue<int, vector<int>, greater<int>> pqi2; //reverse pq int

#define F first
#define S second
#define PB push_back
#define V vector
#define FOR1(i,a,b) for(int i=a; i<b; i++)
#define FOR(i,a) for (int i=0; i<a; i++)
int n, m;

int main()
{
    int n, m;
    cin >> n >> m;
    int arr[11];
    FOR(i, 11) {
        arr[i] = 0;
    }
    FOR(i, n) {
        int a;
        cin >> a;
        arr[a]++;
    }
    int ans = n * n;
    FOR(i, 11) {
        ans -= arr[i] * arr[i];
    }
    ans /= 2;
    cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std;

int minit(vector<long long> t) {
    long long mini = 100000000000000;
    int mini_s;
    for (int i = 1; i < t.size(); i++) {
        mini = min(t[i], mini);
        mini_s = i;
    }
    return mini_s;
}

int maxt(vector<long long> t) {
    long long maxi = 0;
    int max_s;
    for (int i = 0; i < t.size(); i++) {
        maxi = max(t[i], maxi);
        max_s = i;
    }
    return max_s;
}

int min_flash(int m, vector<int> cards) {
    int sum = 0;
    sort(cards.begin(), cards.end());
    for(int i = cards.size() - 1; i > -1 ; i--) {
        sum += cards[i];
        if (sum >= m) {
            return cards.size() - i;
        }
    }
}

//map <int, int> read_map(int n) {
//    map <int, int> elems;
//    for(int i = 0; i < n; ++i) {
//        int t;
//        cin >> t;
//        if (elems.count(t) > 0){
//            elems[t] += 1;
//        } else {
//            elems[t] = 1;
//        }
//    }
//    return elems;
//}

int main() {
    int n, m;
    cin >> n >> m;
    int ar[10] = {0};
    for(int i = 0; i < n; i++) {
        int t;
        cin >> t;
        ar[t] += 1;
    }
    int sum = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = i + 1; j < 10; j++) {
            sum += ar[i]*ar[j];
        }
    }
    cout << sum;
    //auto books = read_map(n);

}


#include <bits/stdc++.h>

using namespace std;

int minit(vector<long long> t) {
    long long mini = 100000000000000;
    int mini_s;
    for (int i = 1; i < t.size(); i++) {
        mini = min(t[i], mini);
        mini_s = i;
    }
    return mini_s;
}

int maxt(vector<long long> t) {
    long long maxi = 0;
    int max_s;
    for (int i = 0; i < t.size(); i++) {
        maxi = max(t[i], maxi);
        max_s = i;
    }
    return max_s;
}

int min_flash(int m, vector<int> cards) {
    int sum = 0;
    sort(cards.begin(), cards.end());
    for(int i = cards.size() - 1; i > -1 ; i--) {
        sum += cards[i];
        if (sum >= m) {
            return cards.size() - i;
        }
    }
}

//map <int, int> read_map(int n) {
//    map <int, int> elems;
//    for(int i = 0; i < n; ++i) {
//        int t;
//        cin >> t;
//        if (elems.count(t) > 0){
//            elems[t] += 1;
//        } else {
//            elems[t] = 1;
//        }
//    }
//    return elems;
//}

int main() {
    int n, m;
    cin >> n >> m;
    int ar[10] = {0};
    for(int i = 0; i < n; i++) {
        int t;
        cin >> t;
        ar[t] += 1;
    }
    long long sum = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = i + 1; j < 10; j++) {
            sum += ar[i]*ar[j];
        }
    }
    cout << sum;
    //auto books = read_map(n);

}