For this Question: Aniket considers a string happy if at least one pair of characters exist at positions i and j (i < j) such that character at position i is lexographically smaller than character at position j. 
For example strings "aab", "aba", "zxy" are happy, while strings "aaa", "zyx", "ccb" are not happy.

You are given N strings, you need to find the number of pairs (k, l) such that s<sub>k</sub>+s<sub>l</sub> is a happy string. (Consider all N*N pairs)The first line of the input contains a single integer N.
Next N lines contain N strings consisting of only lowercase letters of the english alphabet.

Constraints
1 <= N <= 100000
1 <= length of string <= 5Output the number of pairs (k, l) such that the concatenation of strings s<sub>k</sub> and s<sub>l</sub> is happy.Sample Input
5
a
a
b
d
c

Sample Output
9

The happy strings are the concatenation of the following pairs (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (5, 4)

Sample Input
3
cbcb
fffee
d

Sample Output
7

Explanation: Concatenation of all pairs except (2, 3) and (3, 3) form happy strings., I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		String[] arr=new String[n];
		int start=0;
		int end=n;
		int happy=0;
		for(int i=0;i<n;i++){
			String input1=br.readLine();
			if(check(input1)){

				happy++;
				arr[start]=input1;
				start++;
			}
			else{
				end--;
				arr[end]=input1;
			}
		}
		long unhappy=n-end;
		long count=(happy*(happy + unhappy) + (unhappy * happy));

		int startletter[]=new int[26];
		int endletter[]=new int[26];
		for(int i=end;i<n;i++){
			char startChar=arr[i].charAt(0);
			char lastChar=arr[i].charAt(arr[i].length()-1);
			startletter[startChar-'a']++;
			endletter[lastChar-'a']++;
		}

		for(int i=0;i<26;i++){
			int occur=0;
			for(int j=0;j<i;j++){
				occur+=endletter[j];
			}
			count+=startletter[i]*occur;
		}

		System.out.println(count);
	}
	static boolean check(String str){
		int least = (str.charAt(0) - 'a');
        for(int i = 1 ; i <str.length() ; i++){
            char ch = str.charAt(i);
            if((ch -'a') < least) {
                least = (ch -'a');
            }
            else if((ch -'a') > least)
                return true;
        }
        return false;
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?