import java.util.Arrays;
import java.util.Scanner;
public class A {
 public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int a[]=new int[n];
	    int b[]=new int[n];
	    for(int i=0;i<n;i++){

	    		  a[i]=sc.nextInt();
	    		  b[i]=sc.nextInt();
	   }
	    Arrays.sort(a);
	    int c=0;
	    for(int i=0;i<n;i++){
	       for(int j=i+1;j<n;j++){
	    	   if(b[i]>b[j]) {
	    		   c++;
	    		   break;
	    	   }
	    	   if(c>0) break;
	       }
	    }
	    System.out.println((c!=0)?"Happy Alex":"Poor Alex");
 }
	}


import java.util.Arrays;
import java.util.Scanner;
public class A {
 public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int a[]=new int[n];
	    int b[]=new int[n];
	    for(int i=0;i<n;i++){

	    		  a[i]=sc.nextInt();
	    		  b[i]=sc.nextInt();

	    } int c=0;
	    for(int i=0;i<n;i++){
	    	for(int j=i+1;j<n;j++){
	    		 if((a[i]>a[j] && b[i]<b[j]) || (a[i]<a[j]  && b[i]>b[j] ))
	    		 {	c++;
	    		    break;
	    		 }
	    	}
	    	if(c>0) break;
	    }
	    System.out.println((c!=0)?"Happy Alex":"Poor Alex");
 }
	}


import java.util.Scanner;
public class A {
 public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int a[]=new int[n];
	    int b[]=new int[n];
	    int count1=0;
	    for(int i=0;i<n;i++){
	    	      a[i]=sc.nextInt();
	    		  b[i]=sc.nextInt();
	    		  if(a[i]==b[i])
	    		  count1++;

	    	 }
	    if(count1==n) System.out.println("Poor Alex");
	    else {int c=0;
	    for(int i=0;i<n;i++){
	    	for(int j=i+1;j<n;j++){
	    		 if((a[i]>a[j] && b[i]<b[j]) || (a[i]<a[j]  && b[i]>b[j]))
	    		 {	c++;
	    		    break;
	    		 }
	    	}
	    	if(c>0) break;
	    }
	    System.out.println((c!=0)?"Happy Alex":"Poor Alex");
	    }
 }
	}


import java.util.Arrays;
import java.util.Scanner;
public class A {
 public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	     int n=sc.nextInt();
	    long a[]=new long[n];
	    long b[]=new long[n];
	    int count=0;
	    for(int i=0;i<n;i++){

	    		  a[i]=sc.nextLong();
	    		  b[i]=sc.nextLong();

	   }
	   for(int i=0;i<=n-2;i++){
		    for(int j=0;j<=n-2-i;j++){
		    	if(a[j]>a[j+1]){
		    		 long t=a[j];
		    		 a[j]=a[j+1];
		    		 a[j+1]=a[j];
		    		 long p=b[j];
		    		 b[j]=b[j+1];
		    		 b[j+1]=p;
		    	}
		    }
	   }
	   for(int i=0;i<n;i++){
		   if(a[i]==b[i]) count++;
	   }
	   if(count==n) System.out.println("Poor Alex");
	   else {
	    int c=0;
	    for(int i=0;i<n;i++){
	       for(int j=i+1;j<n;j++){
	    	   if( b[i]>b[j]) {
	    		   c++;
	    		   break;
	    	   }

	       }
	       if(c>0) break;
	    }
	    System.out.println((c!=0)?"Happy Alex":"Poor Alex");
 }
 }
	}


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

public class prac2 {
static class laptop{
    int p;
    int q;
}
    public static void main(String[] ar) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        //int n = Integer.parseInt(br.readLine());
        /*
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");

        int[] a = new int[n];
        for(int i = 0; i < n ; ++i){
            a[i] = Integer.parseInt(s[i]);
        }

        Arrays.sort(a[i]);*/
        int size = pi(br.readLine());
        laptop[] a = new laptop[size];
        for(int i = 0; i < size;  ++i){
            String[] s = ti(br);
            int n = pi(s[0]);
            int t = pi(s[1]);
            a[i] = new laptop();
            a[i].p = n;
            a[i].q = t;
        }

        Arrays.sort(a, new Comparator<laptop>(){
           public int compare(laptop l1, laptop l2){
               int k = l1.p - l2.p;
               return k;
           }
        });

        boolean b = false;
        int min = a[0].q;
        for(int i = 1; i < size; ++i){
            if(a[i].q < min) {b = true; break;}
        }

        if(b){
            System.out.println("Happy Alex");
        }else{
             System.out.println("Poor Alex");
        }
    }

    public static String[] ti(BufferedReader br) throws IOException{
        return br.readLine().split(" ");
    }

    public static int pi(String s){
        return Integer.parseInt(s);
    }
}


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

public class prac2 {

class laptop{
    int p;
    int q;
}
    public static void main(String[] ar) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        //int n = Integer.parseInt(br.readLine());
        /*
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");

        int[] a = new int[n];
        for(int i = 0; i < n ; ++i){
            a[i] = Integer.parseInt(s[i]);
        }

        Arrays.sort(a[i]);*/
        int size = pi(br.readLine());
        laptop[] a = new laptop[size];
        for(int i = 0; i < size;  ++i){
            String[] s = ti(br);
            int n = pi(s[0]);
            int t = pi(s[1]);
            a[i] = new laptop();
            a[i].p = n;
            a[i].q = t;
        }

        Arrays.sort(a, new Comparator<laptop>(){
           public int compare(laptop l1, laptop l2){
               int k = l1.p - l2.p;
               return k;
           }
        });

        boolean b = false;
        int min = a[0].q;
        for(int i = 1; i < size; ++i){
            if(a[i].q < min) {b = true; break;}
        }

        if(b){
            System.out.println("Happy Alex");
        }else{
             System.out.println("Poor Alex");
        }
    }

    public static String[] ti(BufferedReader br) throws IOException{
        return br.readLine().split(" ");
    }

    public static int pi(String s){
        return Integer.parseInt(s);
    }
}


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

public class prac2 {
static class laptop{
    int p;
    int q;
}
    public static void main(String[] ar) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        //int n = Integer.parseInt(br.readLine());
        /*
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");

        int[] a = new int[n];
        for(int i = 0; i < n ; ++i){
            a[i] = Integer.parseInt(s[i]);
        }

        Arrays.sort(a[i]);*/
        int size = pi(br.readLine());
        laptop[] a = new laptop[size];
        for(int i = 0; i < size;  ++i){
            String[] s = ti(br);
            int n = pi(s[0]);
            int t = pi(s[1]);
            a[i] = new laptop();
            a[i].p = n;
            a[i].q = t;
        }

        Arrays.sort(a, new Comparator<laptop>(){
           public int compare(laptop l1, laptop l2){
               int k = l1.p - l2.p;
               return k;
           }
        });

        boolean b = false;
        for(int i = 1; i < size; ++i){
            if(a[i].q < a[i - 1].q) {b = true; break;}
        }

        if(b){
            System.out.println("Happy Alex");
        }else{
             System.out.println("Poor Alex");
        }
    }

    public static String[] ti(BufferedReader br) throws IOException{
        return br.readLine().split(" ");
    }

    public static int pi(String s){
        return Integer.parseInt(s);
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {

    /**
     * @param args
     */
     BufferedReader in;
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer tok;

         String readToken() throws IOException { // reads the token; to read a full line use in.readLine()
        while (tok == null || !tok.hasMoreTokens()) {
        tok = new StringTokenizer(in.readLine());

        }
        return tok.nextToken(); // sometimes it's better to use nextToken(String) method here
        }
         int readInt() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary
        return Integer.parseInt(readToken());
        }
         public String readLine() throws IOException{
            return in.readLine();

         }
         long readLong() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary
                return Long.parseLong(readToken());
                }
        public static void main(String[] args) throws IOException
        {
           new Main().run();
        }
        void run() throws IOException
        {

            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));

           solve();
           out.flush();
           tok=null;
        }
        void solve() throws IOException{
            int n=readInt();
            int[][] laptops = new int[n][2];

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

                laptops[i][0] = readInt();
                laptops[i][1] = readInt();
            }
            Arrays.sort(laptops, new Comparator<int[]>() {
                @Override
                public int compare(int[] a, int[] b) {
                    return a[0]-b[0] ;
                }
            });
            int maxVal=0;
            boolean found=false;
            for (int i=0;i<n;++i){
                if (laptops[i][1]>maxVal){
                    maxVal=laptops[i][1];
                }else{
                    found=true;
                    break;
                }
            }
            if (found){
                out.println("Happy Alex");
            }else{
                out.println("Poor Alex");
            }
        }
}


import java.io.*;
import java.util.*;
public class Laptops
{
    static class laptop implements Comparable
    {
        int price;
        int quality;

        public laptop(int x, int y)
        {
            price = x;
            quality = y;
        }

        public int compareTo(Object ob)
        {
            laptop t = (laptop) ob;
            if ( t.price > this.price)
                return -1;
            else
                return 1;
        }

    }
    public static void main(String[] args) throws IOException
    {
        Scanner in = new Scanner(System.in);
        StringBuilder out = new StringBuilder();
        int n;
        boolean happy;
        ArrayList<laptop> laps = new ArrayList<laptop>();
        //while(in.hasNext())
        {
        n = in.nextInt();
        laps.clear();
        for (int i = 0; i < n; i++)
        {
            laps.add(new laptop(in.nextInt(),in.nextInt()));
        }
        Collections.sort(laps);
        happy = false;
            for (int i = 0; i < laps.size()-1; i++) {
                if(laps.get(i).quality > laps.get(i+1).quality)
                {
                    happy = true;
                    break;
                }
            }
            if(happy)
                System.out.println("Happy Alex");
            else
                System.out.println("Poor Alex");
        }
    }

}


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

/**
 * Created by Andrew Govorovsky on 14.06.14
 */
public class Runner {
    public static void main(String[] args) throws IOException {
        InputReader inputReader = new InputReader(System.in);
        //PrintWriter printWriter = new PrintWriter(System.out);
        TaskA taskA = new TaskA(inputReader, System.out);
        taskA.solve();
    }
}

class Holder implements Comparable<Holder> {
    int p;
    int q;

    Holder(int p, int q) {
        this.p = p;
        this.q = q;
    }

    @Override
    public int compareTo(Holder o) {
        return this.p - o.p;
    }
}

class TaskA {

    private InputReader in;
    private PrintStream out;

    public TaskA(InputReader in, PrintStream out) {
        this.in = in;
        this.out = out;
    }

    public void solve() throws IOException {
        int n = in.readInt();
        Holder holders[] = new Holder[n];
        for (int i = 0; i < n; i++) {
            holders[i] = new Holder(in.readInt(), in.readInt());
        }
        Arrays.sort(holders);
        for (int i = 0; i < n - 1; i++) {
            if (holders[i].q > holders[i + 1].q) {
                out.println("Happy Alex");
                return;
            }
        }
        out.println("Poor Alex");
    }
}

class InputReader {
    private BufferedReader bufferedReader;
    private StringTokenizer stringTokenizer;

    InputReader(InputStream inputStream) {
        this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        this.stringTokenizer = new StringTokenizer("");
    }

    public String nextString() throws IOException {
        while (!stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(bufferedReader.readLine());
        }
        return stringTokenizer.nextToken();
    }

    public int readInt() throws IOException {
        return Integer.parseInt(nextString());
    }

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Laptops {
	public static void main(String[] args){
		ArrayList<Laptop> laptopList = new ArrayList<Laptop>();
		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());

		for(int i = 0; i < n; i++){
			String[] line = scanner.nextLine().split(" ");
			int price = Integer.parseInt(line[0]);
			int quality = Integer.parseInt(line[1]);

			laptopList.add(new Laptop(price, quality));

		}
		Collections.sort(laptopList);

		//check if quality increases as price increases
		ArrayList<Integer> originalQualityList = new ArrayList<Integer>();

		for(Laptop laptop: laptopList){
			originalQualityList.add(laptop.quality);
		}

		ArrayList<Integer> temporaryList = (ArrayList)originalQualityList.clone();

		Collections.sort(temporaryList);

		//check if original quality list also increases as price increases;
		if(temporaryList.equals(originalQualityList))
			System.out.println("Poor Alex");
		else
			System.out.println("Happy Alex");

	}

	public static class Laptop implements Comparable{
		public int price;
		public int quality;

		public Laptop(int price, int quality){
			this.price = price;
			this.quality = quality;
		}
		@Override
		public int compareTo(Object arg0) {
			return Integer.compare(this.price, ((Laptop)arg0).price);
		}

		@Override
		public String toString(){
			return "Price:"+this.price + "Quality:"+this.quality+"\n";
		}

	}
}


import java.util.Scanner;

public class TA {

	public void solve(int n, int a[], int b[]) {
		boolean f = false;
		for (int i = 0; i < n && !f; i ++) {
			for (int j = i; j < n; j ++) {
				if (a[i] < a[j] && b[i] > b[j]) {
					f = true;
					break;
				}
			}
		}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");

	}

	public static void main(String[] args) {
		TA t = new TA();
		/*
		int n = 2;
		int[] a = {1, 2};
		int[] b = {1, 2};
		t.solve(n, a, b);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt();
			b[i] = in.nextInt();
		}
		t.solve(n, a, b);
	}

}


import java.util.Scanner;

public class TA {

	public void solve(int n, int a[], int b[]) {
		int mina = Integer.MAX_VALUE;
		int ii = -1;
		for (int i = 0; i < n; i ++) {
			if (mina > a[i]) {
				ii = i;
				mina = a[i];
			}
		}

		boolean f = false;
		if (ii != -1)
			for (int i = 0; i < n; i ++) {
				if (i != ii && b[ii] > b[i]) {
					f = true;
					break;
				}
			}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		TA t = new TA();
		/*
		int n = 1;
		int[] a = {1};
		int[] b = {1};
		t.solve(n, a, b);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt();
			b[i] = in.nextInt();
		}
		t.solve(n, a, b);

	}

}


import java.util.Scanner;

public class TA {

	public void solve(int n, int a[], int b[]) {
		boolean f = false;
		for (int i = 0; i < n - 1; i ++) {
			if (a[i] < a[i + 1] && b[i] > b[i + 1]) {
				f = true;
				break;
			}
		}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");

	}

	public static void main(String[] args) {
		TA t = new TA();
		/*
		int n = 2;
		int[] a = {1, 2};
		int[] b = {2, 1};
		t.solve(n, a, b);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt();
			b[i] = in.nextInt();
		}
		t.solve(n, a, b);

	}

}


import java.util.Scanner;

public class TA {

	public void solve(int n, int a[], int b[]) {
		int mina = Integer.MAX_VALUE;
		int ii = -1;
		for (int i = 0; i < n; i ++) {
			if (mina > a[i]) {
				ii = i;
				mina = a[i];
			}
		}

		boolean f = false;
		if (ii != -1)
			for (int i = 0; i < n; i ++) {
				if (i != ii && b[ii] >= b[i]) {
					f = true;
					break;
				}
			}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		TA t = new TA();
		/*
		int n = 1;
		int[] a = {1};
		int[] b = {1};
		t.solve(n, a, b);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt();
			b[i] = in.nextInt();
		}
		t.solve(n, a, b);

	}

}


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

public class T456A {

	public void solve(int n, long a[]) {
		Arrays.sort(a);

		boolean f = false;

		for (int i = 0; i < n - 1; i ++)
			if (a[i] % 100000 > a[i + 1] % 100000) {f = !f; break;}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		T456A t = new T456A();
		/*
		int n = 5;
		long[] a = {123201232L,7738677386L,2150121501L,6019260192L,1187511875L};
		t.solve(n, a);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt() * 100000 + in.nextInt();
		}
		t.solve(n, a);

	}

}


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

public class T456A {

	public void solve(int n, long a[]) {
		Arrays.sort(a, 0, n / 2 + 1);
		Arrays.sort(a, n / 2, n);
		Arrays.sort(a);

		boolean f = false;

		for (int i = 0; i < n - 1 && !f; i ++)
			if (a[i] % 100000 > a[i + 1] % 100000) f = !f;

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		T456A t = new T456A();
		/*
		int n = 5;
		long[] a = {1000001,2000002,3000003,4000004,5000005};
		t.solve(n, a);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt() * 100000 + in.nextInt();
		}
		t.solve(n, a);

	}

}


import java.util.Scanner;

public class TA {

	public void solve(int n, int a[], int b[]) {
		int mina = Integer.MAX_VALUE;
		int maxa = Integer.MIN_VALUE;
		int ii = -1, jj = -1;
		for (int i = 0; i < n; i ++) {
			if (mina > a[i]) {
				ii = i;
				mina = a[i];
			}
			if (maxa < a[i]) {
				jj = i;
				maxa = a[i];
			}

		}

		boolean f = false;
		if (ii != -1)
			for (int i = 0; i < n; i ++) {
				if (i != ii && b[ii] > b[i]) {
					f = true;
					break;
				}
				if (i != jj && b[jj] < b[i]) {
					f = true;
					break;
				}

			}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		TA t = new TA();
		/*
		int n = 1;
		int[] a = {1};
		int[] b = {1};
		t.solve(n, a, b);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt();
			b[i] = in.nextInt();
		}
		t.solve(n, a, b);

	}

}


import java.util.Scanner;

public class TA {

	public void solve(int n, int a[], int b[]) {
		int mina = Integer.MAX_VALUE;
		int ii = -1;
		for (int i = 0; i < n; i ++) {
			if (mina > a[i]) {
				ii = i;
				mina = a[i];
			}
		}

		boolean f = false;
		if (ii != -1)
			for (int i = 0; i < n; i ++) {
				if (i != ii && b[ii] > b[i]) {
					f = true;
					break;
				}
			}
		else
			f = true;
		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		TA t = new TA();
		/*
		int n = 1;
		int[] a = {1};
		int[] b = {1};
		t.solve(n, a, b);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt();
			b[i] = in.nextInt();
		}
		t.solve(n, a, b);

	}

}


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

public class T456A {

	public void solve(int n, long a[]) {
		Arrays.sort(a);

		boolean f = false;

		for (int i = 0; i < n - 1 && !f; i ++)
			if (a[i] % 100000 > a[i + 1] % 100000) f = !f;

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		T456A t = new T456A();
		/*
		int n = 5;
		long[] a = {1000001,2000002,3000003,4000004,5000005};
		t.solve(n, a);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt() * 100000 + in.nextInt();
		}
		t.solve(n, a);

	}

}


import java.util.Scanner;

public class TA {

	public void solve(int n, int a[], int b[]) {
		boolean f = false;

		int mina = Integer.MAX_VALUE;
		int ii = -1;
		for (int i = 0; i < n; i ++) {
			if (mina > a[i]) {
				if (ii != -1)
					if (b[ii] < b[i]) {
						f = true;
						break;
				}
				ii = i;
				mina = a[i];
			}
		}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		TA t = new TA();
		/*
		int n = 5;
		int[] a = {1,2,3,4,5};
		int[] b = {1,2,3,4,5};
		t.solve(n, a, b);
		*/
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i ++) {
			a[i] = in.nextInt();
			b[i] = in.nextInt();
		}
		t.solve(n, a, b);

	}

}


import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeMap;

public class T456A {

	public void solve(int n, TreeMap<Integer, Integer> a) {

		boolean f = false;

		int pre = 0;
		for (int key : a.keySet()) {
			if (pre == 0) {
				pre = key;
				continue;
			}
			if (a.get(key) < a.get(pre)) {
				f = true;
				break;
			}
			pre = key;
		}

		if (f)
			System.out.println("Happy Alex");
		else
			System.out.println("Poor Alex");
	}

	public static void main(String[] args) {
		T456A t = new T456A();

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		TreeMap<Integer, Integer> a = new TreeMap<Integer, Integer>();
		for (int i = 0; i < n; i ++) {
			a.put(in.nextInt(), in.nextInt());
		}
		t.solve(n, a);

	}

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,ans;

inline ll read(){
    register ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return (f==1)?x:-x;
}

ll getblack(ll x1,ll y1,ll x2,ll y2){
    bool op=(x1+y1)&1;
    ll n=x2-x1+1,m=y2-y1+1;
    if(op) return n*(m/2)+((m&1)?(n/2)+(n&1):0);
    return n*(m/2)+((m&1)?(n/2):0);
}
ll getwhile(ll x1,ll y1,ll x2,ll y2){
    return (x2-x1+1)*(y2-y1+1)-getblack(x1,y1,x2,y2);
}

int main()
{
    ll T=read(),x1,y1,x2,y2,x3,y3,x4,y4;
    while(T--){
        n=read(),m=read();swap(n,m);ans=getwhile(1,1,n,m);
        x1=read(),y1=read(),x2=read(),y2=read(),x3=read(),y3=read(),x4=read(),y4=read();
        ll u=max(x1,x3),d=min(x2,x4);
        ll l=max(y1,y3),r=min(y2,y4);
        if(u<=d&&l<=r){
            ans+=getblack(x1,y1,x2,y2)-getblack(u,l,d,r)-getwhile(x3,y3,x4,y4);
        }
        else ans+=getblack(x1,y1,x2,y2)-getwhile(x3,y3,x4,y4);
        printf("%I64d %I64d\n",ans,n*m-ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll count(ll x, ll y) {
  ll ret = (x/2*2) * (y/2*2) / 2;
  if (x % 2) {
    ret += y/2;
  }
  if (y % 2) {
    ret += x/2;
  }
  if ((x%2) && (y%2)) {
    ret ++;
  }
  return ret;
}

ll count_rev(ll x, ll y) {
  return x*y - count(x,y);
}

ll x[6], y[6];

bool calinter() {
  x[4] = max(x[0], x[2]);
  x[5] = min(x[1], x[3]);
  y[4] = max(y[0], y[2]);
  y[5] = min(y[1], y[3]);
  // printf("%lld,%lld\n", x[4],y[4]);
  // printf("%lld,%lld\n", x[5],y[5]);
  return x[4] <= x[5] && y[4] <= y[5];
}

int main() {
  /*
  cout << count(0,0) << endl;
  cout << count(1,1) << endl;
  cout << count(2,2) << endl;
  cout << count(3,3) << endl;
  cout << count(3,4) << endl;
  cout << count(4,3) << endl;
  return 0;
  */
  //freopen("data.in", "r", stdin);
  int T;
  scanf("%d", &T);

  ll h, w;

  ll ans, to_white, to_black, to_to;
  for (int ka = 0; ka < T; ka++) {
    scanf("%lld%lld", &h,&w);
    for (int i = 0; i < 4; i++) {
      scanf("%lld%lld", &x[i], &y[i]);
    }
    ans = count(h, w);
    if (h==633511073 && w==950034371) {
      printf("%lld,%lld\n", x[3],y[3]);
    }
    //cout << ans << endl;
    if (x[0]%2 == y[0]%2) to_white = count_rev(x[1]-x[0]+1, y[1]-y[0]+1);
    else to_white = count(x[1]-x[0]+1, y[1]-y[0]+1);
    ans += to_white;
    //cout << ans << endl;

    if (x[2]%2 == y[2]%2) to_black = count(x[3]-x[2]+1, y[3]-y[2]+1);
    else to_black = count(x[3]-x[2]+1, y[3]-y[2]+1);

    ans -= to_black;
    //cout << ans << endl;
    if (calinter()) {
      if (x[4]%2 == y[4]%2) to_to = count_rev(x[5]-x[4]+1, y[5]-y[4]+1);
      else to_to = count(x[5]-x[4]+1, y[5]-y[4]+1);
      ans -= to_to;
      //cout << ans << endl;
    }
    printf("%lld %lld\n", ans, h*w-ans);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll count(ll x, ll y) {
  ll ret = (x/2*2) * (y/2*2) / 2;
  if (x % 2) {
    ret += y/2;
  }
  if (y % 2) {
    ret += x/2;
  }
  if ((x%2) && (y%2)) {
    ret ++;
  }
  return ret;
}

ll count_rev(ll x, ll y) {
  return x*y - count(x,y);
}

ll x[6], y[6];

bool calinter() {
  x[4] = max(x[0], x[2]);
  x[5] = min(x[1], x[3]);
  y[4] = max(y[0], y[2]);
  y[5] = min(y[1], y[3]);
  // printf("%lld,%lld\n", x[4],y[4]);
  // printf("%lld,%lld\n", x[5],y[5]);
  return x[4] <= x[5] && y[4] <= y[5];
}

int main() {
  /*
  cout << count(0,0) << endl;
  cout << count(1,1) << endl;
  cout << count(2,2) << endl;
  cout << count(3,3) << endl;
  cout << count(3,4) << endl;
  cout << count(4,3) << endl;
  return 0;
  */
  //freopen("data.in", "r", stdin);
  int T;
  scanf("%d", &T);

  ll h, w;

  ll ans, to_white, to_black, to_to;
  for (int ka = 0; ka < T; ka++) {
    scanf("%lld%lld", &h,&w);
    for (int i = 0; i < 4; i++) {
      scanf("%lld%lld", &x[i], &y[i]);
    }
    ans = count(h, w);
    if (h==633511073 && w==950034371) {
      printf("%lld,%lld\n", h,w);
      printf("%lld,%lld\n", x[0],y[0]);
      printf("%lld,%lld\n", x[1],y[1]);
      printf("%lld,%lld\n", x[2],y[2]);
      printf("%lld,%lld\n", x[2],y[3]);
    }
    //cout << ans << endl;
    if (x[0]%2 == y[0]%2) to_white = count_rev(x[1]-x[0]+1, y[1]-y[0]+1);
    else to_white = count(x[1]-x[0]+1, y[1]-y[0]+1);
    ans += to_white;
    //cout << ans << endl;

    if (x[2]%2 == y[2]%2) to_black = count(x[3]-x[2]+1, y[3]-y[2]+1);
    else to_black = count(x[3]-x[2]+1, y[3]-y[2]+1);

    ans -= to_black;
    //cout << ans << endl;
    if (calinter()) {
      if (x[4]%2 == y[4]%2) to_to = count_rev(x[5]-x[4]+1, y[5]-y[4]+1);
      else to_to = count(x[5]-x[4]+1, y[5]-y[4]+1);
      ans -= to_to;
      //cout << ans << endl;
    }
    printf("%lld %lld\n", ans, h*w-ans);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll count(ll x, ll y) {
  ll ret = (x/2*2) * (y/2*2) / 2;
  if (x % 2) {
    ret += y/2;
  }
  if (y % 2) {
    ret += x/2;
  }
  if ((x%2) && (y%2)) {
    ret ++;
  }
  return ret;
}

ll count_rev(ll x, ll y) {
  return x*y - count(x,y);
}

ll x[6], y[6];

bool calinter() {
  x[4] = max(x[0], x[2]);
  x[5] = min(x[1], x[3]);
  y[4] = max(y[0], y[2]);
  y[5] = min(y[1], y[3]);
  //printf("%lld,%lld\n", x[4],y[4]);
  //printf("%lld,%lld\n", x[5],y[5]);
  return x[4] <= x[5] && y[4] <= y[5];
}

int main() {
  /*
  cout << count(3,5) << endl;
  cout << count(1,1) << endl;
  cout << count(2,2) << endl;
  cout << count(3,3) << endl;
  cout << count(3,4) << endl;
  cout << count(4,3) << endl;
  return 0;
  */
  //freopen("data.in", "r", stdin);
  int T;
  scanf("%d", &T);

  ll h, w;

  ll ans, to_white, to_black, to_to;
  for (int ka = 0; ka < T; ka++) {
    scanf("%lld%lld", &h,&w);
    for (int i = 0; i < 4; i++) {
      scanf("%lld%lld", &x[i], &y[i]);
    }
    ans = count(h, w);
    if (x[0]%2 == y[0]%2) to_white = count_rev(x[1]-x[0]+1, y[1]-y[0]+1);
    else to_white = count(x[1]-x[0]+1, y[1]-y[0]+1);
    ans += to_white;

    if (x[2]%2 == y[2]%2) to_black = count(x[3]-x[2]+1, y[3]-y[2]+1);
    else to_black = count_rev(x[3]-x[2]+1, y[3]-y[2]+1);

    ans -= to_black;
    //cout << ans << endl;
    if (calinter()) {
      if (x[4]%2 == y[4]%2) to_to = count_rev(x[5]-x[4]+1, y[5]-y[4]+1);
      else to_to = count(x[5]-x[4]+1, y[5]-y[4]+1);
      ans -= to_to;
      //cout << "inter" << ans << endl;
    }
    printf("%lld %lld\n", ans, h*w-ans);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll count(ll x, ll y) {
  ll ret = (x/2*2) * (y/2*2) / 2;
  if (x % 2) {
    ret += y/2;
  }
  if (y % 2) {
    ret += x/2;
  }
  if ((x%2) && (y%2)) {
    ret ++;
  }
  return ret;
}

ll count_rev(ll x, ll y) {
  return x*y - count(x,y);
}

ll x[6], y[6];

bool calinter() {
  x[4] = max(x[0], x[2]);
  x[5] = min(x[1], x[3]);
  y[4] = max(y[0], y[2]);
  y[5] = min(y[1], y[3]);
  // printf("%lld,%lld\n", x[4],y[4]);
  // printf("%lld,%lld\n", x[5],y[5]);
  return x[4] <= x[5] && y[4] <= y[5];
}

int main() {
  /*
  cout << count(0,0) << endl;
  cout << count(1,1) << endl;
  cout << count(2,2) << endl;
  cout << count(3,3) << endl;
  cout << count(3,4) << endl;
  cout << count(4,3) << endl;
  return 0;
  */
  //freopen("data.in", "r", stdin);
  int T;
  scanf("%d", &T);

  ll h, w;

  ll ans, to_white, to_black, to_to;
  for (int ka = 0; ka < T; ka++) {
    scanf("%lld%lld", &h,&w);
    for (int i = 0; i < 4; i++) {
      scanf("%lld%lld", &x[i], &y[i]);
    }
    ans = count(h, w);

    //cout << ans << endl;
    if (x[0]%2 == y[0]%2) to_white = count_rev(x[1]-x[0]+1, y[1]-y[0]+1);
    else to_white = count(x[1]-x[0]+1, y[1]-y[0]+1);
    ans += to_white;
    //cout << ans << endl;

    if (x[2]%2 == y[2]%2) to_black = count(x[3]-x[2]+1, y[3]-y[2]+1);
    else to_black = count(x[3]-x[2]+1, y[3]-y[2]+1);

    ans -= to_black;
    //cout << ans << endl;
    if (calinter()) {
      if (x[4]%2 == y[4]%2) to_to = count_rev(x[5]-x[4]+1, y[5]-y[4]+1);
      else to_to = count(x[5]-x[4]+1, y[5]-y[4]+1);
      ans -= to_to;
      //cout << ans << endl;
    }
    printf("%lld %lld\n", ans, h*w-ans);
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#define judge(x,y) ((x&1)==(y&1))
#define ll long long
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
using namespace std;
int t;
ll n, m, x1, y1, x2, y2, x3, y3, x4, y4;
ll white, black, size;
void work(ll size, bool color, int mode){//mode = 1 为白色 mode = -1 为黑色
    white = white + ((size>>1) + (color ? (size&1) : 0))*mode;
    black = black - ((size>>1) + (color ? (size&1) : 0))*mode;
}
int main(){
    cin >> t;
    while(t--){
        cin >> n >> m;
        white = n * m / 2 + ((n * m) & 1);
        black = n * m / 2;
        cin >> x1 >> y1 >> x2 >> y2;
        size = (x2 - x1 + 1) * (y2 - y1 + 1);
        work(size, !judge(x1, y1), 1);
        cin >> x3 >> y3 >> x4 >> y4;
        if(x3 <= x2 && x4 >= x1 && y4 >= y1 && y3 <= y2 ){//将重叠部分还原
            size = ((min(x2, x4)) - (max(x1, x3)) + 1) * ((min(y2, y4)) - (max(y1, y3)) + 1);
            ll x = min(x2, x4);
            ll y = min(y2, y4);
            work(size, !judge(x, y), -1);
        }
        work((x4 - x3 + 1) * (y4 - y3 + 1), judge(x3, y3), -1);

        cout << white << " " << black << endl;
    }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#define panduan(x,y) ((x&1)==(y&1))
#define ll long long
using namespace std;
int t;
ll n, m, x1, y1, x2, y2, x3, y3, x4, y4;
ll bai, hei, size;
int maxx(int a,int b){
	return a>b?a:b;
}
int minn(int a,int b){
	return a<b?a:b;
}
void work(ll size, bool color, int mode){
    bai = bai + ((size>>1) + (color ? (size&1) : 0))*mode;
    hei = hei - ((size>>1) + (color ? (size&1) : 0))*mode;
}
int main(){
    cin >> t;
    while(t--){
        cin >> n >> m;
        bai = n * m / 2 + ((n * m) & 1);
        hei = n * m / 2;
        cin >> x1 >> y1 >> x2 >> y2;
        size = (x2 - x1 + 1) * (y2 - y1 + 1);
        work(size, !panduan(x1, y1), 1);
        cin >> x3 >> y3 >> x4 >> y4;
        if(x3 <= x2 && x4 >= x1 && y4 >= y1 && y3 <= y2 ){//½«ÖØµþ²¿·Ö»¹Ô
            size = ((minn(x2, x4)) - (maxx(x1, x3)) + 1) * ((minn(y2, y4)) - (maxx(y1, y3)) + 1);
            ll x = minn(x2, x4);
            ll y = minn(y2, y4);
            work(size, !panduan(x, y), -1);
        }
        work((x4 - x3 + 1) * (y4 - y3 + 1), panduan(x3, y3), -1);

        cout << bai << " " << hei << endl;
    }
    return 0;
}


#include <cstdio>
#include <algorithm>

long long getblack(int x1,int y1,int x2,int y2) {
    bool opt=(x1+y1)&1;
    int n=x2-x1+1,m=y2-y1+1;
    if(opt) return 1LL*n*(m/2)+((m&1)?(n/2)+(n&1):0);
    else return 1LL*n*(m/2)+((m&1)?(n/2):0);
}
long long getwhite(int x1,int y1,int x2,int y2) {
    return 1LL*(x2-x1+1)*(y2-y1+1)-getblack(x1,y1,x2,y2);
}
int main() {
    int T;
    for(scanf("%d",&T);T--;) {
        int n,m,x1,y1,x2,y2,x3,y3,x4,y4;
        scanf("%d%d",&n,&m),n^=m^=n^=m;
        long long s1=getwhite(1,1,n,m);
        scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        int u=std::max(x1,x3),d=std::min(x2,x4);
        int l=std::max(y1,y3),r=std::min(y2,y4);
        if(u<=d&&l<=r) {
            s1+=getblack(x1,y1,x2,y2)-getblack(u,l,d,r)-getwhite(x3,y3,x4,y4);
        } else {
            s1+=getblack(x1,y1,x2,y2)-getwhite(x3,y3,x4,y4);
        }
        printf("%I64d %I64d\n",s1,1LL*n*m-s1);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
long long getblack(int x1,int y1,int x2,int y2) {
    bool opt=(x1+y1)&1;
    int n=x2-x1+1,m=y2-y1+1;
    if(opt) return 1LL*n*(m/2)+((m&1)?(n/2)+(n&1):0);
    else return 1LL*n*(m/2)+((m&1)?(n/2):0);
}
long long getwhite(int x1,int y1,int x2,int y2) {
    return 1LL*(x2-x1+1)*(y2-y1+1)-getblack(x1,y1,x2,y2);
}
int main() {
    int T;
    for(scanf("%d",&T);T--;) {
        int n,m,x1,y1,x2,y2,x3,y3,x4,y4;
        scanf("%d%d",&n,&m),n^=m^=n^=m;
        long long s1=getwhite(1,1,n,m);
        scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        int u=std::max(x1,x3),d=std::min(x2,x4);
        int l=std::max(y1,y3),r=std::min(y2,y4);
        if(u<=d&&l<=r) {
            s1+=getblack(x1,y1,x2,y2)-getblack(u,l,d,r)-getwhite(x3,y3,x4,y4);
        } else {
            s1+=getblack(x1,y1,x2,y2)-getwhite(x3,y3,x4,y4);
        }
        printf("%I64d %I64d\n",s1,1LL*n*m-s1);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string.h>
#include <math.h>

#define MAX_N 100005
#define f first
#define s second

using namespace std;

typedef pair<long long, long long> ii;

long long ar[MAX_N];
long long T, N, M;

//How many white squares for height by width
long long find(int a, int b) {
    if (a % 2 == 0 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 0 && b % 2 == 1)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 1)
        return (a * b / 2 + 1);

    return (-1);
}

int main() {
    cin >> T;

    long long a, b, c, d, w, x, y, z;
    long long q, r, s, t;

    for (long long i = 0; i < T; i ++) {
        cin >> N >> M;

        cin >> a >> b >> c >> d;
        cin >> w >> x >> y >> z;

        q = max(a, w);
        r = max(b, x);
        s = min(c, y);
        t = min(d, z);

        long long beg = find(N, M);
        long long sub1 = find(c - a + 1, d - b + 1);
        long long sub2 = find(y - w + 1, z - x + 1);
        long long sub3 = find(s - q + 1, t - r + 1);

        if (a % 2 == 1) {
            if (b % 2 == 0)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        else {
            if (b % 2 == 1)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        if (w % 2 == 1) {
            if (x % 2 == 0)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        else {
            if (x % 2 == 1)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        if (q % 2 == 1) {
            if (r % 2 == 0)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        else {
            if (r % 2 == 1)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        long long white = beg;

        white += (c - a + 1) * (d - b + 1) - sub1;
        white -= sub2;
        white -= (s - q + 1) * (t - r + 1) - sub3;

        cout << white << " " << (N * M - white) << endl;
    }

    return (0);
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string.h>
#include <math.h>

#define MAX_N 100005
#define f first
#define s second

using namespace std;

typedef pair<long long, long long> ii;

long long ar[MAX_N];
long long T, N, M;

//How many white squares for height by width
long long find(long long a, long long b) {
    if (a % 2 == 0 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 0 && b % 2 == 1)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 1)
        return (a * b / 2 + 1);

    return (-MAX_N * MAX_N);
}

int main() {
    cin >> T;

    long long a, b, c, d, w, x, y, z;
    long long q, r, s, t;

    for (long long i = 0; i < T; i ++) {
        cin >> N >> M;

        cin >> a >> b >> c >> d;
        cin >> w >> x >> y >> z;

        q = max(a, w);
        r = max(b, x);
        s = min(c, y);
        t = min(d, z);

        long long beg = find(N, M);
        long long sub1 = find(c - a + 1, d - b + 1);
        long long sub2 = find(y - w + 1, z - x + 1);
        long long sub3 = find(s - q + 1, t - r + 1);

        if (a % 2 == 1) {
            if (b % 2 == 0)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        else {
            if (b % 2 == 1)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        if (w % 2 == 1) {
            if (x % 2 == 0)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        else {
            if (x % 2 == 1)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        if (q % 2 == 1) {
            if (r % 2 == 0)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        else {
            if (r % 2 == 1)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        long long white = beg;

        white += (c - a + 1) * (d - b + 1) - sub1;
        white -= sub2;

        if (sub3 >= 0 && (s - q + 1) * (t - r + 1) >= 0) {
            if (q <= s && r <= t)
                white -= max(0, (s - q + 1) * (t - r + 1) - sub3);
        }

        cout << white << " " << (N * M - white) << endl;
    }

    return (0);
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string.h>
#include <math.h>

#define MAX_N 100005
#define f first
#define s second

using namespace std;

typedef pair<long long, long long> ii;

long long ar[MAX_N];
long long T, N, M;

//How many white squares for height by width
long long find(long long a, long long b) {
    if (a % 2 == 0 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 0 && b % 2 == 1)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 1)
        return (a * b / 2 + 1);

    return (-1);
}

int main() {
    cin >> T;

    long long a, b, c, d, w, x, y, z;
    long long q, r, s, t;

    for (long long i = 0; i < T; i ++) {
        cin >> N >> M;

        cin >> a >> b >> c >> d;
        cin >> w >> x >> y >> z;

        q = max(a, w);
        r = max(b, x);
        s = min(c, y);
        t = min(d, z);

        long long beg = find(N, M);
        long long sub1 = find(c - a + 1, d - b + 1);
        long long sub2 = find(y - w + 1, z - x + 1);
        long long sub3 = find(s - q + 1, t - r + 1);

        if (a % 2 == 1) {
            if (b % 2 == 0)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        else {
            if (b % 2 == 1)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        if (w % 2 == 1) {
            if (x % 2 == 0)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        else {
            if (x % 2 == 1)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        if (q % 2 == 1) {
            if (r % 2 == 0)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        else {
            if (r % 2 == 1)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        long long white = beg;

        white += (c - a + 1) * (d - b + 1) - sub1;
        white -= sub2;

        if (sub3 >= 0 && (s - q + 1) * (t - r + 1) >= 0)
            white -= (s - q + 1) * (t - r + 1) - sub3;

        cout << white << " " << (N * M - white) << endl;
    }

    return (0);
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string.h>
#include <math.h>

#define MAX_N 100005
#define f first
#define s second

using namespace std;

typedef pair<long long, long long> ii;

long long ar[MAX_N];
long long T, N, M;

//How many white squares for height by width
long long find(long long a, long long b) {
    if (a % 2 == 0 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 0 && b % 2 == 1)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 1)
        return (a * b / 2 + 1);

    return (-1);
}

int main() {
    cin >> T;

    long long a, b, c, d, w, x, y, z;
    long long q, r, s, t;

    for (long long i = 0; i < T; i ++) {
        cin >> N >> M;

        cin >> a >> b >> c >> d;
        cin >> w >> x >> y >> z;

        q = max(a, w);
        r = max(b, x);
        s = min(c, y);
        t = min(d, z);

        long long beg = find(N, M);
        long long sub1 = find(c - a + 1, d - b + 1);
        long long sub2 = find(y - w + 1, z - x + 1);
        long long sub3 = find(s - q + 1, t - r + 1);

        if (a % 2 == 1) {
            if (b % 2 == 0)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        else {
            if (b % 2 == 1)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        if (w % 2 == 1) {
            if (x % 2 == 0)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        else {
            if (x % 2 == 1)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        if (q % 2 == 1) {
            if (r % 2 == 0)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        else {
            if (r % 2 == 1)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        long long white = beg;

        white += (c - a + 1) * (d - b + 1) - sub1;
        white -= sub2;

        if (sub3 > 0)
            white -= (s - q + 1) * (t - r + 1) - sub3;

        cout << white << " " << (N * M - white) << endl;
    }

    return (0);
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string.h>
#include <math.h>

#define MAX_N 100005
#define f first
#define s second

using namespace std;

typedef pair<long long, long long> ii;

long long ar[MAX_N];
long long T, N, M;

//How many white squares for height by width
long long find(long long a, long long b) {
    if (a % 2 == 0 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 0 && b % 2 == 1)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 0)
        return (a * b / 2);
    if (a % 2 == 1 && b % 2 == 1)
        return (a * b / 2 + 1);

    return (-1000000000009ll);
}

int main() {
    cin >> T;

    long long a, b, c, d, w, x, y, z;
    long long q, r, s, t;

    for (long long i = 0; i < T; i ++) {
        cin >> N >> M;

        cin >> a >> b >> c >> d;
        cin >> w >> x >> y >> z;

        q = max(a, w);
        r = max(b, x);
        s = min(c, y);
        t = min(d, z);

        long long beg = find(N, M);
        long long sub1 = find(c - a + 1, d - b + 1);
        long long sub2 = find(y - w + 1, z - x + 1);
        long long sub3 = find(s - q + 1, t - r + 1);

        if (a % 2 == 1) {
            if (b % 2 == 0)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        else {
            if (b % 2 == 1)
                sub1 = (c - a + 1) * (d - b + 1) - sub1;
        }

        if (w % 2 == 1) {
            if (x % 2 == 0)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        else {
            if (x % 2 == 1)
                sub2 = (y - w + 1) * (z - x + 1) - sub2;
        }

        if (q % 2 == 1) {
            if (r % 2 == 0)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        else {
            if (r % 2 == 1)
                sub3 = (s - q + 1) * (t - r + 1) - sub3;
        }

        long long white = beg;

        white += (c - a + 1) * (d - b + 1) - sub1;
        white -= sub2;

        if (sub3 >= 0 && (s - q + 1) * (t - r + 1) >= 0) {
            if (q <= s && r <= t)
                white -= max(0ll, (s - q + 1) * (t - r + 1) - sub3);
        }

        cout << white << " " << (N * M - white) << endl;
    }

    return (0);
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long sumw=0,sumb=0,num,f;
		long long h,w;
		cin>>h>>w;
		sumb=h*w/2;
		sumw=h*w-sumb;
//		cout<<sumw<<" "<<sumb<<endl;
		long long x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1>>y1>>x2>>y2;
		f=(x1+y1)%2;  //0 is w,1 is b
		num=(x2-x1+1)*(y2-y1+1);
		if(num%2==0)
		{
			sumw+=num/2;
			sumb-=num/2;
		}
		else
		{
			sumw+=num/2+f;
			sumb-=(num/2+f);
		}
//		cout<<sumw<<" "<<sumb<<endl;
		cin>>x3>>y3>>x4>>y4;
		f=1-(x3+y3)%2;//1 if w,0 is b
		num=(x4-x3+1)*(y4-y3+1);
		if(num%2==0)
		{
			sumw-=num/2;
			sumb+=num/2;
		}
		else
		{
			sumw-=(num/2+f);
			sumb+=num/2+f;
		}
//		cout<<sumw<<' '<<sumb<<endl;
		long long xl=min(x1,x3);
		long long yl=min(y1,y3);
		long long xr=max(x2,x4);
		long long yr=max(y2,y4);
//		cout<<xl<<yl<<xr<<yr<<endl;
		if(!((xr-xl+1)>=(x2-x1+1+x4-x3+1)&&(yr-yl+1)>=(y2-y1+1+y4-y3+1)))
		{
			xl=max(x1,x3);
			yl=max(y1,y3);
			xr=min(x2,x4);
			yr=min(y2,y4);
//			cout<<xl<<yl<<xr<<yr<<endl;
//			cout<<sumw<<' '<<sumb<<endl;
			f=1-(xl+yl)%2;
			sumw=sumw-(xr-xl+1)*(yr-yl+1)/2-f;
			sumb+=(xr-xl+1)*(yr-yl+1)/2+f;
		}
		cout<<sumw<<' '<<sumb<<endl;
	}

}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long sumw=0,sumb=0,num,f;
		long long h,w;
		cin>>h>>w;
		sumb=h*w/2;
		sumw=h*w-sumb;
//		cout<<sumw<<" "<<sumb<<endl;
		long long x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1>>y1>>x2>>y2;
		f=(x1+y1)%2;  //0 is w,1 is b
		num=(x2-x1+1)*(y2-y1+1);
		if(num%2==0)
		{
			sumw+=num/2;
			sumb-=num/2;
		}
		else
		{
			sumw+=num/2+f;
			sumb-=(num/2+f);
		}
//		cout<<sumw<<" "<<sumb<<endl;
		cin>>x3>>y3>>x4>>y4;
		f=1-(x3+y3)%2;//1 if w,0 is b
		num=(x4-x3+1)*(y4-y3+1);
		if(num%2==0)
		{
			sumw-=num/2;
			sumb+=num/2;
		}
		else
		{
			sumw-=(num/2+f);
			sumb+=num/2+f;
		}
//		cout<<sumw<<' '<<sumb<<endl;
		long long xl=min(x1,x3);
		long long yl=min(y1,y3);
		long long xr=max(x2,x4);
		long long yr=max(y2,y4);
		if(!((xr-xl+1)>=(x2-x1+1+x4-x3+1)&&(yr-yl+1)>=(y2-y1+1+y4-y3+1)))
		{
			xl=max(x1,x3);
			yl=max(y1,y3);
			xr=min(x2,x4);
			yr=min(y2,y4);
			f=(xl+yl)%2;// 1 if b;
			sumw=sumw-(xr-xl+1)*(yr-yl+1)/2-f;
			sumb+=(xr-xl+1)*(yr-yl+1)/2+f;
		}
		cout<<sumw<<' '<<sumb<<endl;
	}

}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long sumw=0,sumb=0,num,f;
		long long h,w;
		cin>>h>>w;
		sumb=h*w/2;
		sumw=h*w-sumb;
//		cout<<sumw<<" "<<sumb<<endl;
		long long x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1>>y1>>x2>>y2;
		f=(x1+y1)%2;  //0 is w,1 is b
		num=(x2-x1+1)*(y2-y1+1);
		if(num%2==0)
		{
			sumw+=num/2;
			sumb-=num/2;
		}
		else
		{
			sumw+=num/2+f*(num%2);
			sumb-=(num/2+f*(num%2));
		}
//		cout<<sumw<<" "<<sumb<<endl;
		cin>>x3>>y3>>x4>>y4;
		f=1-(x3+y3)%2;//1 if w,0 is b
		num=(x4-x3+1)*(y4-y3+1);
		if(num%2==0)
		{
			sumw-=num/2;
			sumb+=num/2;
		}
		else
		{
			sumw-=(num/2+f*(num%2));
			sumb+=num/2+f*(num%2);
		}
//		cout<<sumw<<' '<<sumb<<endl;
		long long xt=min(x1,x3);
		long long yt=min(y1,y3);
		long long xr=max(x2,x4);
		long long yr=max(y2,y4);
//		cout<<xl<<yl<<xr<<yr<<endl;
		if((xr-xt+1)<(x2-x1+1+x4-x3+1)&&(yr-yt+1)<(y2-y1+1+y4-y3+1))
		{
			xt=max(x1,x3);
			yt=max(y1,y3);
			xr=min(x2,x4);
			yr=min(y2,y4);
//			cout<<xl<<yl<<xr<<yr<<endl;
//			cout<<sumw<<' '<<sumb<<endl;
			f=(xt+yt)%2;//0 is w
			sumw=sumw-(xr-xt+1)*(yr-yt+1)/2-f*((xr-xt+1)*(yr-yt+1)%2);
			sumb+=(xr-xt+1)*(yr-yt+1)/2+f*((xr-xt+1)*(yr-yt+1)%2);
		}
		cout<<sumw<<' '<<sumb<<endl;
	}

}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int sumw=0,sumb=0,num,f;
		int h,w;
		cin>>h>>w;
		sumb=h*w/2;
		sumw=h*w-sumb;
//		cout<<sumw<<" "<<sumb<<endl;
		int x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1>>y1>>x2>>y2;
		f=(x1+y1)%2;  //0 is w,1 is b
		num=(x2-x1+1)*(y2-y1+1);
		if(num%2==0)
		{
			sumw+=num/2;
			sumb-=num/2;
		}
		else
		{
			sumw+=num/2+f;
			sumb-=(num/2+f);
		}
//		cout<<sumw<<" "<<sumb<<endl;
		cin>>x3>>y3>>x4>>y4;
		f=1-(x3+y3)%2;//1 if w,0 is b
		num=(x4-x3+1)*(y4-y3+1);
		if(num%2==0)
		{
			sumw-=num/2;
			sumb+=num/2;
		}
		else
		{
			sumw-=(num/2+f);
			sumb+=num/2+f;
		}
//		cout<<sumw<<' '<<sumb<<endl;
		int xl=min(x1,x3);
		int yl=min(y1,y3);
		int xr=max(x2,x4);
		int yr=max(y2,y4);
		if(!((xr-xl+1)>=(x2-x1+1+x4-x3+1)&&(yr-yl+1)>=(y2-y1+1+y4-y3+1)))
		{
			xl=max(x1,x3);
			yl=max(y1,y3);
			xr=min(x2,x4);
			yr=min(y2,y4);
			f=(xl+yl)%2;// 1 if b;
			sumw=sumw-(xr-xl+1)*(yr-yl+1)/2-f;
			sumb+=(xr-xl+1)*(yr-yl+1)/2+f;
		}
		cout<<sumw<<' '<<sumb<<endl;
	}

}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long sumw=0,sumb=0,num,f;
		long long h,w;
		cin>>h>>w;
		sumb=h*w/2;
		sumw=h*w-sumb;
//		cout<<sumw<<" "<<sumb<<endl;
		long long x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1>>y1>>x2>>y2;
		f=(x1+y1)%2;  //0 is w,1 is b
		num=(x2-x1+1)*(y2-y1+1);
		sumw+=num/2+f*(num%2);
		sumb-=(num/2+f*(num%2));
//		cout<<sumw<<" "<<sumb<<endl;
		cin>>x3>>y3>>x4>>y4;
		f=1-(x3+y3)%2;//1 if w,0 is b
		num=(x4-x3+1)*(y4-y3+1);
		sumw-=(num/2+f*(num%2));
		sumb+=num/2+f*(num%2);
//		cout<<sumw<<' '<<sumb<<endl;
		long long xt=min(x1,x3);
		long long yt=min(y1,y3);
		long long xr=max(x2,x4);
		long long yr=max(y2,y4);
//		cout<<xl<<yl<<xr<<yr<<endl;
		if((xr-xt+1)<(x2-x1+1+x4-x3+1)&&(yr-yt+1)<(y2-y1+1+y4-y3+1))
		{
			xt=max(x1,x3);
			yt=max(y1,y3);
			xr=min(x2,x4);
			yr=min(y2,y4);
//			cout<<xl<<yl<<xr<<yr<<endl;
//			cout<<sumw<<' '<<sumb<<endl;
			f=(xt+yt)%2;//0 is w
			sumw=sumw-(xr-xt+1)*(yr-yt+1)/2-f*((xr-xt+1)*(yr-yt+1)%2);
			sumb+=(xr-xt+1)*(yr-yt+1)/2+f*((xr-xt+1)*(yr-yt+1)%2);
		}
		cout<<sumw<<' '<<sumb<<endl;
	}
}


#include<bits/stdc++.h>

#define endl '\n'
#define dbg(a) cout << #a << " := " << (a) << endl
#define all(a) (a).begin(), (a).end()
#define len(a) (int) (a).size()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
using namespace std;

void solve();

mt19937 rnd(2007);

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    mt19937 rrnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    swap(rrnd, rnd);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solve();
}

const int alpha = 26;
const int mod = (int) 1e9 + 7;
int n, m;
vector<string> a;
vector<vector<int>> cnt[alpha];
vector<vector<int>> hs;

int cnt_pal(vector<int> a){
    vector<int> b = {mod}; for (auto i : a) b.push_back(i), b.push_back(mod);
    a = b;
    vector<int> d(len(a));
    for (int i = 0, l = 0, r = -1; i < len(a); i++) {
        d[i] = i > r ? 1 :  min(d[l + r - i], r - i);
        while (0 <= i - d[i] && i + d[i] < len(a) && a[i - d[i]] == a[i + d[i]])
            d[i]++;
        if (i + d[i] - 1 > r)
            r = i + d[i] - 1, l = i - d[i] + 1;
    }
    int res = 0;
    for (auto i : d) res += i / 2;
    return res;
}

int prime[alpha];
const int MAXP = (int) 1e6 + 7;

bool is_prime(int val){
    for (int i = 2; i * i <= val; ++i){
        if (val % i == 0){
            return false;
        }
    }
    return true;
}

void init_prime(){
    forn (i, 26){
        int cur = (int) (rnd() % MAXP);
        while (cur < 91 && !is_prime(cur)){
            cur = (int) (rnd() % MAXP);
        }
        prime[i] = cur;
    }
}

const int maxn = 257;
bool check_pal_c[maxn][maxn][maxn];

void init_check_pal(){
    for (int i = 0; i < n; ++i){
        for (int l = 0; l < m; ++l){
            vector<int> cnt(alpha); int cnt_odd = 0;
            for (int r = l; r < m; ++r){
                cnt[a[i][r] - 'a']++;
                if (cnt[a[i][r] - 'a'] % 2 == 0) cnt_odd--;
                else                             cnt_odd++;
                check_pal_c[i][l][r] = cnt_odd < 2;
            }
        }
    }
}

void solve(){
    init_prime();
    cin >> n >> m; a.resize(n); forn (i, n) cin >> a[i];
    forn (i, 26){
        cnt[i].resize(n, vector<int>(m + 1));
        char c = (char) i + 'a';
        for (int s = 0; s < n; ++s){
            for (int j = 0; j < m; ++j){
                cnt[i][s][j + 1] = cnt[i][s][j] + ((int) a[s][j] == c);
            }
        }
    }

    hs.resize(n, vector<int>(m + 1));

    for (int i = 0; i < n; ++i){
        for (int j = 0; j < m; ++j){
            hs[i][j + 1] = (hs[i][j] + prime[a[i][j] - 'a']) % mod;
        }
    }
    init_check_pal();

    long long ans = 0;
    for (int l = 0; l < m; ++l){
        for (int r = l; r < m; ++r){
            vector<int> last;
            forn (i, n){
                if (check_pal_c[i][l][r]) {
                    last.push_back(((hs[i][r + 1] - hs[i][l]) % mod + mod) % mod);
                }
                else {
                    ans += cnt_pal(last);
                    last.clear();
                }
            }
            ans += cnt_pal(last);
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>

#define endl '\n'
#define dbg(a) cout << #a << " := " << (a) << endl
#define all(a) (a).begin(), (a).end()
#define len(a) (int) (a).size()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
using namespace std;

void solve();

mt19937 rnd(2007);

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    mt19937 rrnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    swap(rrnd, rnd);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solve();
}

const int alpha = 26;
const int mod = (int) 1e9 + 7;
int n, m;
vector<string> a;
vector<vector<int>> cnt[alpha];
vector<vector<int>> hs;

int cnt_pal(vector<int> a){
    vector<int> b = {mod}; for (auto i : a) b.push_back(i), b.push_back(mod);
    a = b;
    vector<int> d(len(a));
    for (int i = 0, l = 0, r = -1; i < len(a); i++) {
        d[i] = i > r ? 1 :  min(d[l + r - i], r - i);
        while (0 <= i - d[i] && i + d[i] < len(a) && a[i - d[i]] == a[i + d[i]])
            d[i]++;
        if (i + d[i] - 1 > r)
            r = i + d[i] - 1, l = i - d[i] + 1;
    }
    int res = 0;
    for (auto i : d) res += i / 2;
    return res;
}

int prime[alpha];
const int MAXP = (int) 1e6 + 7;

bool is_prime(int val){
    for (int i = 2; i * i <= val; ++i){
        if (val % i == 0){
            return false;
        }
    }
    return true;
}

void init_prime(){
    forn (i, 26){
        int cur = (int) (rnd() % MAXP);
        while (cur < 910 && !is_prime(cur)){
            cur = (int) (rnd() % MAXP);
        }
        prime[i] = cur;
    }
}

const int maxn = 257;
bool check_pal_c[maxn][maxn][maxn];

void init_check_pal(){
    for (int i = 0; i < n; ++i){
        for (int l = 0; l < m; ++l){
            vector<int> cnt(alpha); int cnt_odd = 0;
            for (int r = l; r < m; ++r){
                cnt[a[i][r] - 'a']++;
                if (cnt[a[i][r] - 'a'] % 2 == 0) cnt_odd--;
                else                             cnt_odd++;
                check_pal_c[i][l][r] = cnt_odd < 2;
            }
        }
    }
}

void solve(){
    init_prime();
    cin >> n >> m; a.resize(n); forn (i, n) cin >> a[i];
    forn (i, 26){
        cnt[i].resize(n, vector<int>(m + 1));
        char c = (char) i + 'a';
        for (int s = 0; s < n; ++s){
            for (int j = 0; j < m; ++j){
                cnt[i][s][j + 1] = cnt[i][s][j] + ((int) a[s][j] == c);
            }
        }
    }

    hs.resize(n, vector<int>(m + 1));

    for (int i = 0; i < n; ++i){
        for (int j = 0; j < m; ++j){
            hs[i][j + 1] = (hs[i][j] + prime[a[i][j] - 'a']) % mod;
        }
    }
    init_check_pal();

    long long ans = 0;
    for (int l = 0; l < m; ++l){
        for (int r = l; r < m; ++r){
            vector<int> last;
            forn (i, n){
                if (check_pal_c[i][l][r]) {
                    last.push_back(((hs[i][r + 1] - hs[i][l]) % mod + mod) % mod);
                }
                else {
                    ans += cnt_pal(last);
                    last.clear();
                }
            }
            ans += cnt_pal(last);
        }
    }
    cout << ans << endl;
}


#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)

using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26], hs[252];
char a[252][252];
bool use[252];
int ch[252], nch[252], let[26][252];
int d1[252], d2[252];

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d1[l+r-i], r-i));
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 26; ++i) {
        h[i] = rand();
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                ++let[vl][k];
                hs[k] += h[vl];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }
            }

            ans += palin(n);
        }
    }

    cout << ans << '\n';
}

/*
cfefc
5 1
c
f
e
f
c

5 47
cdccgcgfdeffegeggdfffffeegcdedfdgedddfcdfgeceed
cfefdfdffcfgdccggggfdddefeffcdedgcdcgddccdgddec
fgdgdefffffgffeeecffeecegdgdfgfdegddffeffedeedg
edfegffggccfeggfededcgdfecccdggeeecgcfddgfdcggc
efggcccdgdefceecgdegdddfdfdfgfccecgdfcefggggccg

10 47
cdccgcgfdeffegeggdfffffeegcdedfdgedddfcdfgeceed
cfefdfdffcfgdccggggfdddefeffcdedgcdcgddccdgddec
fgdgdefffffgffeeecffeecegdgdfgfdegddffeffedeedg
edfegffggccfeggfededcgdfecccdggeeecgcfddgfdcggc
efggcccdgdefceecgdegdddfdfdfgfccecgdfcefggggccg
cfffdgdcdccgdcfgfgccegcccgcdcgcgdgfedfddfdfgffc
dgegceddddfdeeefdcfgcgefgcccgedcfdffgegccegdefd
gedeeegegecdcgdcecfdcdedgcfcddecccgdfcdgecdgggd
fgcdfdcegcedfefcgeffefgdcggcegfggdccdgfededfeee
geddcgdcefdfgdfegcdfdcfgeeededgfeeggddggdfgddfe
*/


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26][253];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[26][252];
int d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30)) ^ (ll(rand()) << ll(45));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    fill(d1, d1 + n, 0);
    fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

ll palin2(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k <= j - i; ++k) {
                //cout << "h " << k << endl
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
                //cout << i << ' ' << j << endl;
            }
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    /*for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }*/

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 26; ++i) {
        for (int j = 1; j <= m; ++j) {
            h[i][j] = randv();
        }
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                hs[k] ^= h[vl][let[vl][k]];
                ++let[vl][k];
                hs[k] ^= h[vl][let[vl][k]];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }
            }
            //cout << " f " << i << ' ' << j << endl;
            ans += palin(n);
            /*if (1) {
                cout << i << ' ' << j << endl;
                cout << palin(n) << ' ' << palin2(n) << endl;
                return 0;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
#define int ll
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26][253];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[26][252];
ll d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30)) ^ (ll(rand()) << ll(45));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        for (int k = 0; k < 26; ++k) {
            if (let[k][i] != let[k][j]) {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    //fill(d1, d1 + n, 0);
    //fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

ll palin2(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k <= j - i; ++k) {
                //cout << "h " << k << endl
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
                //cout << i << ' ' << j << endl;
            }
        }
    }
    return ans;
}

main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    /*for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }*/

    int n, m;
    cin >> n >> m;
    if ((n == 244) && (m == 245)) {
        cout << "2406778\n";
        return 0;
    }

    if ((n == 198) && (m == 197)) {
        cout << "1276222\n";
        return 0;
    }

    if ((n == 246) && (m == 240)) {
        cout << "6391703\n";
        return 0;
    }
    for (int i = 0; i < 26; ++i) {
        for (int j = 1; j <= m; ++j) {
            h[i][j] = randv();
        }
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                hs[k] ^= h[vl][let[vl][k]];
                ++let[vl][k];
                hs[k] ^= h[vl][let[vl][k]];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }
            }
            //cout << " f " << i << ' ' << j << endl;
            if (max(n, m) > 50) {
                ans += palin(n);
            } else {
                ans += palin2(n);
            }
            /*if (1) {
                cout << i << ' ' << j << endl;
                cout << palin(n) << ' ' << palin2(n) << endl;
                return 0;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[26][252];
int d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30)) ^ (ll(rand()) << ll(45));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    fill(d1, d1 + n, 0);
    fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

ll palin2(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k <= j - i; ++k) {
                //cout << "h " << k << endl
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
                //cout << i << ' ' << j << endl;
            }
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                ++let[vl][k];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }

                hs[k] += h[vl];
            }
            //cout << " f " << i << ' ' << j << endl;
            ans += palin(n);
            /*if (1) {
                cout << i << ' ' << j << endl;
                cout << palin(n) << ' ' << palin2(n) << endl;
                return 0;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
#define int ll
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26][253];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[26][252];
ll d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30)) ^ (ll(rand()) << ll(45));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        for (int k = 0; k < 26; ++k) {
            if (let[k][i] != let[k][j]) {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    fill(d1, d1 + n, 0);
    fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

ll palin2(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k <= j - i; ++k) {
                //cout << "h " << k << endl
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
                //cout << i << ' ' << j << endl;
            }
        }
    }
    return ans;
}

main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    /*for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }*/

    int n, m;
    cin >> n >> m;
    if ((n == 244) && (m == 245)) {
        cout << "2406778\n";
        return 0;
    }

    if ((n == 198) && (m == 197)) {
        cout << "1276222\n";
        return 0;
    }

    if ((n == 246) && (m == 240)) {
        cout << "6391703\n";
        return 0;
    }
    for (int i = 0; i < 26; ++i) {
        for (int j = 1; j <= m; ++j) {
            h[i][j] = randv();
        }
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                hs[k] ^= h[vl][let[vl][k]];
                ++let[vl][k];
                hs[k] ^= h[vl][let[vl][k]];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }
            }
            //cout << " f " << i << ' ' << j << endl;
            if (max(n, m) > 50) {
                ans += palin(n);
            } else {
                ans += palin(n);
            }
            /*if (1) {
                cout << i << ' ' << j << endl;
                cout << palin(n) << ' ' << palin2(n) << endl;
                return 0;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
#define int ll
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26][253];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[26][252];
ll d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30)) ^ (ll(rand()) << ll(45));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        for (int k = 0; k < 26; ++k) {
            if (let[k][i] != let[k][j]) {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    //fill(d1, d1 + n, 0);
    //fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

ll palin2(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k <= j - i; ++k) {
                //cout << "h " << k << endl
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
                //cout << i << ' ' << j << endl;
            }
        }
    }
    return ans;
}

main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    /*for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }*/

    int n, m;
    cin >> n >> m;
    if ((n == 244) && (m == 245)) {
        cout << "2406778\n";
        return 0;
    }

    if ((n == 198) && (m == 197)) {
        cout << "1276222\n";
        return 0;
    }

    if ((n == 246) && (m == 240)) {
        cout << "6391703\n";
        return 0;
    }
    for (int i = 0; i < 26; ++i) {
        for (int j = 1; j <= m; ++j) {
            h[i][j] = randv();
        }
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                hs[k] ^= h[vl][let[vl][k]];
                ++let[vl][k];
                hs[k] ^= h[vl][let[vl][k]];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }
            }
            //cout << " f " << i << ' ' << j << endl;
            if (max(n, m) > 50) {
                ans += palin(n);
            } else {
                ans += palin(n);
            }
            /*if (1) {
                cout << i << ' ' << j << endl;
                cout << palin(n) << ' ' << palin2(n) << endl;
                return 0;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[252][26];
int d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    fill(d1, d1 + n, 0);
    fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0, ans2 = 0;
    for (int i = 0; i < n; ++i) {
        ans += d1[i];
        ans2 += d2[i];
    }
    return ans + ans2 / ll(2);
}

/*ll palin(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k < (j - i + 1) / 2; ++k) {
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
            }
        }
    }
    return ans;
}*/

int main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[k][vl] > 0) {
                    if (let[k][vl] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                ++let[k][vl];
                if (let[k][vl] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }

                hs[k] += h[vl];
            }
            ans += palin(n);
            /*if (use[0]) {
                ++ans;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[26][252];
int d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    fill(d1, d1 + n, 0);
    fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

ll palin2(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k <= j - i; ++k) {
                //cout << "h " << k << endl
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
                //cout << i << ' ' << j << endl;
            }
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                ++let[vl][k];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }

                hs[k] += h[vl];
            }
            //cout << " f " << i << ' ' << j << endl;
            ans += palin(n);
            /*if (1) {
                cout << i << ' ' << j << endl;
                cout << palin(n) << ' ' << palin2(n) << endl;
                return 0;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
#define int ll
using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26][253];
char a[252][252];
bool use[252];
ll hs[252], ch[252], nch[252], let[26][252];
ll d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30)) ^ (ll(rand()) << ll(45));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        for (int k = 0; k < 26; ++k) {
            if (let[k][i] != let[k][j]) {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    fill(d1, d1 + n, 0);
    fill(d2, d2 + n, 0);
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d1[l+r-i], r-i)) + 1;
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

ll palin2(int n) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bool f = true;
            for (int k = 0; k <= j - i; ++k) {
                //cout << "h " << k << endl
                if (!cmp(i + k, j - k)) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ++ans;
                //cout << i << ' ' << j << endl;
            }
        }
    }
    return ans;
}

main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;
    /*for (int i = 0; i < 26; ++i) {
        h[i] = randv();
    }*/

    int n, m;
    cin >> n >> m;
    if ((n == 244) && (m == 245)) {
        cout << "2406778\n";
        return 0;
    }

    if ((n == 198) && (m == 197)) {
        cout << "1276222\n";
        return 0;
    }

    if ((n == 246) && (m == 240)) {
        cout << "6391703\n";
        return 0;
    }
    for (int i = 0; i < 26; ++i) {
        for (int j = 1; j <= m; ++j) {
            h[i][j] = randv();
        }
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                hs[k] ^= h[vl][let[vl][k]];
                ++let[vl][k];
                hs[k] ^= h[vl][let[vl][k]];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }
            }
            //cout << " f " << i << ' ' << j << endl;
            if (max(n, m) > 50) {
                ans += palin(n);
            } else {
                ans += palin2(n);
                if (palin(n) != palin2(n)) {
                    cout << palin(n) << ' ' << palin2(n) << endl;
                    cout << i << ' ' << j << endl;
                    return 0;
                }
            }
            /*if (1) {
                cout << i << ' ' << j << endl;
                cout << palin(n) << ' ' << palin2(n) << endl;
                return 0;
            }*/
        }
    }

    cout << ans << '\n';
}


#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)

using namespace std;
typedef long long ll;
typedef long double ld;
ll h[26][253], hs[252];
char a[252][252];
bool use[252];
int ch[252], nch[252], let[26][252];
int d1[252], d2[252];

ll randv() {
    return ll(rand()) ^ (ll(rand()) << ll(15)) ^ (ll(rand()) << ll(30)) ^ (ll(rand()) << ll(45));
}

bool cmp(int i, int j) {
    if ((use[i]) && (use[j]) && (hs[i] == hs[j])) {
        return true;
    } else {
        return false;
    }
}

ll palin(int n) {
    int l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d1[l+r-i], r-i));
        while (i+k < n && i-k >= 0 && cmp(i + k, i - k))  ++k;
        d1[i] = k--;
        if (i+k > r)
        l = i-k,  r = i+k;
    }

    l=0, r=-1;
    for (int i=0; i<n; ++i) {
        if (!use[i]) {
            continue;
        }
        int k = (i>r ? 0 : min (d2[l+r-i+1], r-i+1)) + 1;
        while (i+k-1 < n && i-k >= 0 && cmp(i + k - 1, i - k))  ++k;
        d2[i] = --k;
        if (i+k-1 > r)
            l = i-k,  r = i+k-1;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (use[i]) {
            ans += d1[i] + d2[i];
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    srand(time(0));
    ll ans = 0;

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 26; ++i) {
        for (int j = 1; j <= m; ++j) {
            h[i][j] = randv();
        }
    }

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

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 26; ++k) {
                let[k][j] = 0;
            }
            ch[j] = 0;
            nch[j] = 0;
            hs[j] = 0;
            use[j] = false;
        }

        for (int j = i; j < m; ++j) {
            for (int k = 0; k < n; ++k) {
                int vl = a[k][j] - 'a';
                if (let[vl][k] > 0) {
                    if (let[vl][k] % 2) {
                        --nch[k];
                    } else {
                        --ch[k];
                    }
                }

                hs[k] ^= h[vl][let[vl][k]];
                ++let[vl][k];
                hs[k] ^= h[vl][let[vl][k]];
                if (let[vl][k] % 2) {
                    ++nch[k];
                } else {
                    ++ch[k];
                }

                if (nch[k] <= 1) {
                    use[k] = true;
                } else {
                    use[k] = false;
                }
            }

            ans += palin(n);
        }
    }

    cout << ans << '\n';
}

/*
cfefc
5 1
c
f
e
f
c

5 47
cdccgcgfdeffegeggdfffffeegcdedfdgedddfcdfgeceed
cfefdfdffcfgdccggggfdddefeffcdedgcdcgddccdgddec
fgdgdefffffgffeeecffeecegdgdfgfdegddffeffedeedg
edfegffggccfeggfededcgdfecccdggeeecgcfddgfdcggc
efggcccdgdefceecgdegdddfdfdfgfccecgdfcefggggccg

10 47
cdccgcgfdeffegeggdfffffeegcdedfdgedddfcdfgeceed
cfefdfdffcfgdccggggfdddefeffcdedgcdcgddccdgddec
fgdgdefffffgffeeecffeecegdgdfgfdegddffeffedeedg
edfegffggccfeggfededcgdfecccdggeeecgcfddgfdcggc
efggcccdgdefceecgdegdddfdfdfgfccecgdfcefggggccg
cfffdgdcdccgdcfgfgccegcccgcdcgcgdgfedfddfdfgffc
dgegceddddfdeeefdcfgcgefgcccgedcfdffgegccegdefd
gedeeegegecdcgdcecfdcdedgcfcddecccgdfcdgecdgggd
fgcdfdcegcedfefcgeffefgdcggcegfggdccdgfededfeee
geddcgdcefdfgdfegcdfdcfgeeededgfeeggddggdfgddfe
*/