import java.io.*;
public class arraivalofthegeneral
{
	public static void main(String args[])throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine());
		String a[]=in.readLine().split(" ");
		int b[]=new int[n];
		int min=0,max=0;
		int temp,count=0;
		int maxpos=0,minpos=0;
		for(int i=0;i<n;i++)
		{
			b[i]=Integer.parseInt(a[i]);
			if(b[i]<min)
			{
				min=b[i];
				minpos=i;
			}

		}
		for(int i=minpos;i<n-1;i++)
		{
			temp=b[i];
			b[i]=b[i+1];
			b[i+1]=temp;
			count++;
		}
		for(int i=0;i<n;i++)
		{

			if(b[i]>max)
			{
				max=b[i];
				maxpos=i;
			}
		}
		for(int i=maxpos;i>0;i--)
		{
			temp=b[i];
			b[i]=b[i-1];
			b[i-1]=temp;
			count++;
		}

		System.out.println(count+1);
	}
}


package janz;
import java.io.*;
public class arraivalofthegeneral
{
	public static void main(String args[])throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine());
		String a[]=in.readLine().split(" ");
		int b[]=new int[n];
		int min=0,max=0;
		int temp,count=0;
		int maxpos=0,minpos=0;
		for(int i=0;i<n;i++)
		{
			b[i]=Integer.parseInt(a[i]);
			if(b[i]<min)
			{
				min=b[i];
				minpos=i;
			}

		}
		for(int i=minpos;i<n-1;i++)
		{
			temp=b[i];
			b[i]=b[i+1];
			b[i+1]=temp;
			count++;
		}
		for(int i=0;i<n;i++)
		{

			if(b[i]>max)
			{
				max=b[i];
				maxpos=i;
			}
		}
		for(int i=maxpos;i>0;i--)
		{
			temp=b[i];
			b[i]=b[i-1];
			b[i-1]=temp;
			count++;
		}
		if(count>0)
		System.out.println(count-1);
	}
}


package janz;
import java.io.*;
public class arraivalofthegeneral
{
	public static void main(String args[])throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine());
		String a[]=in.readLine().split(" ");
		int b[]=new int[n];
		int min=0,max=0;
		int temp,count=0;
		int maxpos=0,minpos=0;
		for(int i=0;i<n;i++)
		{
			b[i]=Integer.parseInt(a[i]);
			if(b[i]<min)
			{
				min=b[i];
				minpos=i;
			}

		}
		for(int i=minpos;i<n-1;i++)
		{
			temp=b[i];
			b[i]=b[i+1];
			b[i+1]=temp;
			count++;
		}
		for(int i=0;i<n;i++)
		{

			if(b[i]>max)
			{
				max=b[i];
				maxpos=i;
			}
		}
		for(int i=maxpos;i>0;i--)
		{
			temp=b[i];
			b[i]=b[i-1];
			b[i-1]=temp;
			count++;
		}
		if(count>0)
		System.out.println(count-1);
		else
			System.out.println("0");
	}
}


package janz;
import java.io.*;
public class arraivalofthegeneral
{
	public static void main(String args[])throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine());
		String a[]=in.readLine().split(" ");
		int b[]=new int[n];
		int min=0,max=0;
		int temp,count=0;
		int maxpos=0,minpos=0;
		for(int i=0;i<n;i++)
		{
			b[i]=Integer.parseInt(a[i]);
			if(b[i]<min)
			{
				min=b[i];
				minpos=i;
			}

		}
		for(int i=minpos;i<n-1;i++)
		{
			temp=b[i];
			b[i]=b[i+1];
			b[i+1]=temp;
			count++;
		}
		for(int i=0;i<n;i++)
		{

			if(b[i]>max)
			{
				max=b[i];
				maxpos=i;
			}
		}
		for(int i=maxpos;i>0;i--)
		{
			temp=b[i];
			b[i]=b[i-1];
			b[i-1]=temp;
			count++;
		}
		System.out.println(count-1);
	}
}


import java.io.*;
public class arraivalofthegeneral
{
	public static void main(String args[])throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine());
		String a[]=in.readLine().split(" ");
		int b[]=new int[n];
		int min=0,max=0;
		int temp,count=0;
		int maxpos=0,minpos=0;
		for(int i=0;i<n;i++)
		{
			b[i]=Integer.parseInt(a[i]);
			if(b[i]<min)
			{
				min=b[i];
				minpos=i;
			}

		}
		for(int i=minpos;i<n-1;i++)
		{
			temp=b[i];
			b[i]=b[i+1];
			b[i+1]=temp;
			count++;
		}
		for(int i=0;i<n;i++)
		{

			if(b[i]>max)
			{
				max=b[i];
				maxpos=i;
			}
		}
		for(int i=maxpos;i>0;i--)
		{
			temp=b[i];
			b[i]=b[i-1];
			b[i-1]=temp;
			count++;
		}
		System.out.println(count-1);
	}
}


import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner (System.in);
	    int Count = input.nextInt();

	    int x = -1 ;
	    int max=0;
	    int min=100;
	    int maxpos=0;
	    int minpos=0;
	    for (int i = 1 ; i<=Count ; i++)
	    {
	   	  x = input.nextInt();
	       if (x ==min||x<min)
	       {

	    	   min=x;
	    	   minpos=i;
	       }else if (x>max)
	       {

	    	   max=x;
	    	   maxpos=i;
	       }

	    }
	    int steps=0;
	    if (maxpos<minpos)
	   {
	    	steps = maxpos-1+Count-minpos;
	   }
	    else if (maxpos>minpos)
	    {
	     	steps = maxpos-1+Count-minpos-1;

	    }
	    System.out.print(steps);
	   }

	}


import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner (System.in);
	    int Count = input.nextInt();

	    int x = -1 ;
	    int max=0;
	    int min=100;
	    int maxpos=0;
	    int minpos=0;
	    for (int i = 1 ; i<=Count ; i++)
	    {
	   	  x = input.nextInt();
	       if (x ==min||x<min)
	       {

	    	   min=x;
	    	   minpos=i;
	       }
	       if (x>max)
	       {

	    	   max=x;
	    	   maxpos=i;
	       }

	    }
	    int steps=0;
	    if (maxpos<minpos)
	   {
	    	steps = maxpos-1+Count-minpos;
	   }
	    else if (maxpos>minpos)
	    {
	     	steps = maxpos-1+Count-minpos-1;

	    }
	    System.out.print(steps);
	   }

	}


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {Scanner input = new Scanner (System.in);
    int Count = input.nextInt();

    int x = -1 ;
    int max=0;
    int min=100;
    int maxpos=0;
    int minpos=0;
    for (int i = 1 ; i<=Count ; i++)
    {
   	  x = input.nextInt();
       if (x ==min||x<min)
       {

    	   min=x;
    	   minpos=i;
       }else if (x>max)
       {

    	   max=x;
    	   maxpos=i;
       }

    }
    int steps=0;
    if (maxpos<minpos)
   {
    	steps = maxpos-1+Count-minpos;
   }
    else if (maxpos>minpos)
    {
     	steps = maxpos-1+Count-minpos-1;

    }
    System.out.print(steps);
   }


import java.lang.reflect.Array;
import java.util.*;
public class Solution {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int cases = in.nextInt();
		int[] arr = new int[cases];

		for(int i = 0 ; i <cases;i++)
			arr[i] = in.nextInt();
		int min = 100000 , min_i = 0 ;
		int max = 0, max_i = 0 ;
		for(int i = 0 ; i < arr.length;i++)
		{
			if(arr[i]>max)
				{
					max = arr[i];
					max_i = i;
				}
		}
		for(int i = arr.length-1; i >= 0;i--)
		{
			if(arr[i]<min)
				{
					min = arr[i];
					min_i = i;
				}
		}

		int result = max_i + arr.length-1 - min_i;
		if(min_i<max_i)
			result--;
		System.out.println(result);
	}
}


import java.lang.reflect.Array;
import java.util.*;
public class Solution {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int cases = in.nextInt();
		int[] arr = new int[cases];

		for(int i = 0 ; i <cases;i++)
			arr[i] = in.nextInt();
		int min = 100000 , min_i = 0 ;
		int max = 0, max_i = 0 ;
		for(int i = 0 ; i < arr.length;i++)
		{
			if(arr[i]>max)
				{
					max = arr[i];
					max_i = i;
				}
		}
		for(int i = arr.length-1; i >= 0;i--)
		{
			if(arr[i]<min)
				{
					min = arr[i];
					min_i = i;
				}
		}

		int result = max_i + arr.length-1 - min_i;
		if(min_i<=arr.length/2 && max_i>=arr.length/2)
			result--;
		System.out.println(result);
	}
}


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

public class Cakeminator {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();

		int a=sc.nextInt();
		int cur;
		int per=0;
		int ind1=1,ind2=1;
		int pos=101;
		for(int i=2;i<n+1;i++){
			cur=sc.nextInt();
			if(cur>per){
				per=cur;
				ind1=i;
			}
			if(cur<=pos){
				pos=cur;
				ind2=i;
			}
		}
		System.out.println(ind1-1+n-ind2>n-1?ind1-1+n-ind2-1:ind1-1+n-ind2);
	}
}


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

public class Cakeminator {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();

		int cur;
		int per=0;
		int ind1=1,ind2=1;
		int pos=101;
		for(int i=1;i<n+1;i++){
			cur=sc.nextInt();
			if(cur>per){
				per=cur;
				ind1=i;
			}
			if(cur<=pos){
				pos=cur;
				ind2=i;
			}
		}
		System.out.println(ind1-1+n-ind2>n-1?ind1-1+n-ind2-1:ind1-1+n-ind2);
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import static java.lang.Math.*;

public class B {

	// @SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintStream ps = new PrintStream(new BufferedOutputStream(System.out));
		long n = sc.nextLong();

		long minV = Long.MAX_VALUE, minI = 0, maxI = Long.MIN_VALUE, maxV = 0;
		for (int i = 0; i < n; i++) {
			int as = sc.nextInt();
			if (as < minV) {
				minV = as;
				minI = i;
			}
			if (as > maxV) {
				maxV = as;
				maxI = i;
			}
		}
		int sum = 0;
//		System.out.println(maxV + "  " + maxI);

//		System.out.println(minV + "  " + minI);
		if (maxI != 0) {
			sum += maxI;
		}
		if (minI != n - 1) {
			sum += n - 1 - minI;
		}
		if (minI < maxI) {
			sum--;
		}
		ps.println(sum);
		ps.flush();
		ps.close();
		sc.close();
	}

	static class FastReader {
		BufferedReader r;

		FastReader() {
			r = new BufferedReader(new InputStreamReader(System.in));
		}

		long nl() throws NumberFormatException, IOException {
			return Long.parseLong(r.readLine());
		}

		String nxtLine() throws IOException {
			return r.readLine();
		}
	}

	static long g(long a, long b) {
		if (b == 0)
			return a;
		return g(b, a % b);
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import static java.lang.Math.*;

public class B {

	// @SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintStream ps = new PrintStream(new BufferedOutputStream(System.out));
		long n = sc.nextLong();

		long minV = Long.MAX_VALUE, minI = 0, maxI = Long.MIN_VALUE, maxV = 0;
		for (int i = 0; i < n; i++) {
			int as = sc.nextInt();
			minV = min(minV, as);
			maxV = max(maxV, as);
			if (maxV == as)
				maxI = i;
			if (minV == as)
				minI = i;
		}
		int sum = 0;
		if (maxI != 0) {
			sum += maxI;
		}
		if (minI != n - 1) {
			sum += n - 1 - minI;
		}
		if (minI < maxI) {
			sum--;
		}
		ps.println(sum);
		ps.flush();
		ps.close();
		sc.close();
	}

	static class FastReader {
		BufferedReader r;

		FastReader() {
			r = new BufferedReader(new InputStreamReader(System.in));
		}

		long nl() throws NumberFormatException, IOException {
			return Long.parseLong(r.readLine());
		}

		String nxtLine() throws IOException {
			return r.readLine();
		}
	}

	static long g(long a, long b) {
		if (b == 0)
			return a;
		return g(b, a % b);
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;

public class A {

	// @SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintStream ps = new PrintStream(new BufferedOutputStream(System.out));
		int n = sc.nextInt();
		int mii = 0, miv = 0, mai = 0, mav = 0;
		for (int i = 0; i < n; i++) {
			int sx = sc.nextInt();
			if (sx < miv) {
				miv = sx;
				mii = i;
			}
			if (sx > mav) {
				mav = sx;
				mai = i;
			}
		}
//		System.out.println(mav + " " + mai);
//		System.out.println(miv + " " + mii);
		int left = mai;
		int right = n - 2 - mii;
		int ans = left + right;
		if (mii < mai)
			ans--;
		ps.println(ans);

		ps.flush();
		ps.close();
		sc.close();
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import static java.lang.Math.*;

public class B {

	// @SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintStream ps = new PrintStream(new BufferedOutputStream(System.out));
		long n = sc.nextLong();

		long minV = Long.MAX_VALUE, minI = 0, maxI = Long.MIN_VALUE, maxV = 0;
		for (int i = 0; i < n; i++) {
			int as = sc.nextInt();
			if (as <= minV) {
				minV = as;
				minI = i;
			}
			if (as > maxV) {
				maxV = as;
				maxI = i;
			}
		}
		int sum = 0;
//		System.out.println(n);
//		System.out.println(maxV + "  " + maxI);

//		System.out.println(minV + "  " + minI);
		if (maxI != 0) {
			sum += maxI;
		}
//		System.out.println("after max before ");
		if (minI != n - 1) {
			sum += n - 1 - minI;
		}
//		System.out.println("before dec: " + sum);
		if (minI < maxI) {
			sum--;
		}
		ps.println(sum);
		ps.flush();
		ps.close();
		sc.close();
	}

	static class FastReader {
		BufferedReader r;

		FastReader() {
			r = new BufferedReader(new InputStreamReader(System.in));
		}

		long nl() throws NumberFormatException, IOException {
			return Long.parseLong(r.readLine());
		}

		String nxtLine() throws IOException {
			return r.readLine();
		}
	}

	static long g(long a, long b) {
		if (b == 0)
			return a;
		return g(b, a % b);
	}
}


import java.util.Scanner;

/**
 *
 * @author user
 */
public class ArrivaloftheGeneral
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in) ;

        int row  = scanner.nextInt() ;
        int[] arr = new int[row] ;
        int min = 10000000 ;
        int max = 0 ;
        int EndxMin = 0 ;
        int EndxMax = 0 ;
        for (int i = 0; i < row; i++)
        {
            arr[i] = scanner.nextInt() ;
            if(arr[i] > max)
            {
                max = arr[i];
                EndxMax = i ;
            }

            if(arr[i] <= min)
            {
                min = arr[i] ;
                EndxMin = i ;
            }
        }

        int sol = EndxMax + (row - 1 - EndxMin) ;

        if(EndxMax > EndxMin)
        {
        System.out.println(sol- 1);
        }
        else
        {
            System.out.println(sol);
        }
    }

}


import java.util.Scanner;

/**
 *
 * @author user
 */
public class Main
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in) ;

        int rows  = scanner.nextInt() ;
        int[] arr = new int[rows] ;
        int min = 10000000 ;
        int max = 0 ;
        int EndxMin = 0 ;
        int EndxMax = 0 ;
        for (int i = 0; i < rows; i++)
        {
            arr[i] = scanner.nextInt() ;
            if(arr[i] > max)
            {
                max = arr[i];
                EndxMax = i ;
            }

            if(arr[i] <= min)
            {
                min = arr[i] ;
                EndxMin = i ;
            }
        }

        int sol = EndxMax + (rows - 1 - EndxMin) ;

        if(EndxMax > EndxMin)
        {
        System.out.println(sol- 1);
        }
        else
        {
            System.out.println(sol);
        }
    }

}


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

public class ArrivalOfGeneral {

	public static void main(String[] args) throws IOException  {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str1=br.readLine();
		String str=br.readLine();
		String strArr[]=str.split(" ");
		int arr[]=new int[strArr.length];
		int min=1000;
				int max=0;
		int minIndex=strArr.length;
		int maxIndex=0;
		for(int i=0;i<arr.length;i++){
			arr[i]=Integer.parseInt(strArr[i]);
			if(arr[i]>max){
				max=arr[i];
				maxIndex=i;

			}
			if(arr[i]<=min){
				min=arr[i];
				minIndex=i;
			}
		}
		int miSteps=(arr.length-1)-minIndex;
		int maxSteps=maxIndex>minIndex?maxIndex-1:maxIndex;
		//System.out.println(miSteps+" : "+maxSteps);
		System.out.println(miSteps+maxSteps);

	}

}


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

public class ArrivalOfGeneral {

	public static void main(String[] args) throws IOException  {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str1=br.readLine();
		String str=br.readLine();
		String strArr[]=str.split(" ");
		int arr[]=new int[strArr.length];
		int min=1000;
				int max=0;
		int minIndex=strArr.length;
		int maxIndex=0;
		for(int i=0;i<arr.length;i++){
			arr[i]=Integer.parseInt(strArr[i]);
			if(arr[i]>max){
				max=arr[i];
				maxIndex=i;

			}
			if(arr[i]<=min){
				min=arr[i];
				minIndex=i;
			}
		}
		int miSteps=(arr.length-1)-minIndex;
		int maxSteps=maxIndex-1;
		System.out.println(miSteps+" : "+maxSteps);
		System.out.println(miSteps+maxSteps);

	}

}


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

public class ArrivalOfGeneral {

	public static void main(String[] args) throws IOException  {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str1=br.readLine();
		String str=br.readLine();
		String strArr[]=str.split(" ");
		int arr[]=new int[strArr.length];
		int min=1000;
				int max=0;
		int minIndex=strArr.length;
		int maxIndex=0;
		for(int i=0;i<arr.length;i++){
			arr[i]=Integer.parseInt(strArr[i]);
			if(arr[i]>max){
				max=arr[i];
				maxIndex=i;

			}
			if(arr[i]<=min){
				min=arr[i];
				minIndex=i;
			}
		}
		int miSteps=(arr.length-1)-minIndex;
		int maxSteps=maxIndex;
		System.out.println(miSteps+maxSteps);

	}

}


import java.io.*;
import java.util.*;
public class Main
{
        static Scanner in = new Scanner(System.in);
        static PrintWriter out = new PrintWriter(System.out);
        //Scanner scanner = new Scanner(new BufferedReader(new FileReader("input.txt")));
        //PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
      /*static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        static int nextInt() throws IOException
        {
            in.nextToken();
            return (int) in.nval;
        }
        static double nextDouble() throws IOException
        {
            in.nextToken();
            return (double) in.nval;
        }
        */
    public static void main(String[] args) throws IOException
    {
        int n = in.nextInt();
        int[] a = new int[n];
        int min = 0, max = 0, t1 = 0, t2 = 0;
        for(int i = 0; i < n; i++)
        {
            a[i] = in.nextInt();
            if(i == 0)
            {
                max = a[i];
                min = a[i];
            }
            if(max < a[i])
            {
                t1 = i;
                max = a[i];
            }
            if(min >= a[i])
            {
                t2 = i;
                min = a[i];
            }
        }
        int c = 0;
        for(int i = t1; i > 0; i--)
        {
            int b = a[i];
            a[i] = a[i-1];
            a[i-1] = b;
            c++;
        }
        if(t1 > t2)
            t2++;
        for(int i = t2; i < n - 1; i++)
        {
            int b = a[i];
            a[i] = a[i+1];
            a[i+1] = b;
            c++;
        }
    /*  for(int i = 0; i < n; i++)
        {
            if(i != n - 1)
                out.print(a[i] + " ");
            else
                out.println(a[i]);
        }
    */  out.println(c);

        out.flush();
    }
}
/*
4
33 44 11 22
2

7
10 10 58 31 63 40 76
10
*/


import java.io.*;
import java.util.*;
public class Main
{
	    static Scanner in = new Scanner(System.in);
	    static PrintWriter out = new PrintWriter(System.out);
	    //Scanner scanner = new Scanner(new BufferedReader(new FileReader("input.txt")));
	    //PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
	  /*static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	    static int nextInt() throws IOException
	    {
	        in.nextToken();
	        return (int) in.nval;
	    }
	    static double nextDouble() throws IOException
	    {
	        in.nextToken();
	        return (double) in.nval;
	    }
	    */
	public static void main(String[] args) throws IOException
	{
		int n = in.nextInt();
		int[] a = new int[n];
		int min = 0, max = 0, t1 = 0, t2 = 0;
		for(int i = 0; i < n; i++)
		{
			a[i] = in.nextInt();
			if(i == 0)
			{
				max = a[i];
				min = a[i];
		    }
			if(max < a[i])
			{
				t1 = i;
				max = a[i];
			}
			if(min >= a[i])
			{
				t2 = i;
				min = a[i];
			}
		}
		int c = 0;
		for(int i = t1; i > 0; i--)
		{
			int b = a[i];
			a[i] = a[i-1];
			a[i-1] = b;
			c++;
		}
		if(t1 > t2)
			t2++;
		for(int i = t2; i < n - 1; i++)
		{
			int b = a[i];
			a[i] = a[i+1];
			a[i+1] = b;
			c++;
		}
		for(int i = 0; i < n; i++)
		{
			if(i != n - 1)
			    out.print(a[i] + " ");
			else
				out.println(a[i]);
		}
		out.println(c);

		out.flush();
    }
}
/*
4
33 44 11 22
2

7
10 10 58 31 63 40 76
10
*/


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,y=0,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[1];
	min=a[1];
	max=a[1];
	for(i=2;i<=n;i++){
	cin>>a[i];
		if(max<=a[i]){

			max=a[i];}

		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max){
			y++;
			if(y==1){
			k=i;}
		}
		else if(a[i]==min){
			l=i;

		}
	}
//	cout<<k<<endl<<l;

	for(i=1;i<=n;i++){

		cout<<a[i]<<" ";}
		cout<<endl;

	if(max==a[1]&&a[n]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<(k-1)+(n-l);

	}else{

		cout<<((k-1)+(n-l))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){
			max=a[i];
		}
		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=0;i<n;i++){
	//	k++;
	//	l++;
		if(a[i]==max){
			k+=i;
		}
		else if(a[i]==min){
			l+=i;

		}
	}
	n--;
	s=abs(0-k)+abs(n-l);
	cout<<abs(s);
//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){
			max=a[i];
		}
		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max&&a[i+1]!=max){
			k=i;
		}
		else if(a[i]==min&&a[i+1]!=min){
			l=i;

		}
	}
	cout<<k<<endl<<l;

	if(max==a[0]&&a[n-1]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<abs(k-1)+abs(l-n);

	}else{

		cout<<abs(abs(k-1)+abs(l-n))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){
			max=a[i];
		}
		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max&&a[i+1]!=max){
			k=i;
		}
		else if(a[i]==min&&a[i+1]!=min){
			l=i;

		}
	}
//	cout<<k<<endl<<l;

	if(max==a[0]&&a[n-1]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<abs(k-1)+abs(l-n);

	}else{

		cout<<abs(abs(k-1)+abs(l-n))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,y=0,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){

			max=a[i];}

		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max){
			y++;
			if(y==1){
			k=i;}
		}
		else if(a[i]==min&&a[i+1]!=min){
			l=i;

		}
	}
//	cout<<k<<endl<<l;

	if(max==a[0]&&a[n-1]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<(k-1)+(n-l);

	}else{

		cout<<((k-1)+(n-l))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){
			max=a[i];
		}
		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max&&a[i+1]!=max){
			k=i;
		}
		else if(a[i]==min&&a[i+1]!=min){
			l=i;

		}
	}
	if(k<l){

		cout<<abs(k-1)+abs(l-n);

	}else{

		cout<<abs(abs(k-1)+abs(l-n))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,y=0,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[1];
	min=a[1];
	max=a[1];
	for(i=2;i<=n;i++){
	cin>>a[i];
		if(max<=a[i]){

			max=a[i];}

		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max){
			y++;
			if(y==1){
			k=i;}
		}
		else if(a[i]==min){
			l=i;

		}
	}
//	cout<<k<<endl<<l;

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

		cout<<a[i]<<" ";}
		cout<<endl;*/

	if(max==a[1]&&a[n]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<(k-1)+(n-l);

	}else{

		cout<<((k-1)+(n-l))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,y=0k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){

			max=a[i];}
		}
		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max){
			y++;
			if(y==1){
			k=i;}
		}
		else if(a[i]==min&&a[i+1]!=min){
			l=i;

		}
	}
//	cout<<k<<endl<<l;

	if(max==a[0]&&a[n-1]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<abs(k-1)+abs(l-n);

	}else{

		cout<<abs(abs(k-1)+abs(l-n))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,y=0,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){

			max=a[i];}

		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max){
			y++;
			if(y==1){
			k=i;}
		}
		else if(a[i]==min&&a[i+1]!=min){
			l=i;

		}
	}
//	cout<<k<<endl<<l;

	if(max==a[0]&&a[n-1]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<abs(k-1)+abs(n-l);

	}else{

		cout<<(abs(k-1)+abs(n-l)-1);
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include <math.h>
using namespace std;

int  main(int argc, char *argv[])
{
	long long int n,i,y=0,k=0,l=0,min,max,s=0;
	cin>>n;
	long long int a[n];
	cin>>a[0];
	min=a[0];
	max=a[0];
	for(i=1;i<n;i++){
	cin>>a[i];
		if(max<=a[i]){

			max=a[i];}

		else if(min>=a[i]){
			min=a[i];

		}
	}
	for(i=1;i<=n;i++){
	//	k++;
	//	l++;
		if(a[i]==max){
			y++;
			if(y==1){
			k=i;}
		}
		else if(a[i]==min&&a[i+1]!=min){
			l=i;

		}
	}
//	cout<<k<<endl<<l;

	if(max==a[0]&&a[n-1]==min){
		cout<<"0";

	}
else	if(k<l){

		cout<<abs(k-1)+abs(l-n);

	}else{

		cout<<abs(abs(k-1)+abs(l-n))-1;
	}

//	cout<<"max"<<max<<" "<<k<<endl;
//	cout<<" min"<<min<<" "<<l<<endl;
/*	sort(a,a+n);

	if(n%2==0){
		cout<<abs(n-1-k)+abs(0-l);

	}
	else{
		cout<<(abs(n-1-k)+abs(0-l)-1);

	}*/
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	vector<int>v;
	vector <int> c;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	   {
	     int x;
	     cin>>x;
	     v.push_back(x);
	     c.push_back(x);
	   }
	   	sort(c.begin(),c.end());
	   	int min=c[0];
	   	int max=c[n-1];
	   	int ma;
	   	int mi;
	for(int i=0;i<n;i++)
        {
	       if(v[i]==max)
	       {

		   	ma=i;
		   	break;
	        }
	   }
	   	for(int i=n-1;i>=0;i--)
        {
	       if(v[i]==min)
	       {
		   	mi=i;

		   	break;

	        }
	   }
	   if(mi>ma)
	   {
	   	cout<<n-1-mi+ma;
	   }
	   else
	   cout<<n-1-mi+ma+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	vector<int>v;
	vector <int> c;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	   {
	     int x;
	     cin>>x;
	     v.push_back(x);
	     c.push_back(x);
	   }
	   	sort(c.begin(),c.end());
	   	int min=c[0];
	   	int max=c[n-1];
	   	int ma;
	   	int mi;
	for(int i=0;i<n;i++)
        {
	       if(v[i]==max)
	       {

		   	ma=i;
		   	break;
	        }
	   }
	   	for(int i=n-1;i>=0;i--)
        {
	       if(v[i]==min)
	       {
		   	mi=i;

		   	break;

	        }
	   }
	   if(mi>ma)
	   {
	   	cout<<n-1-mi+ma;
	   }
	   else
	   cout<<n-1-mi+ma-1;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count=0;
	vector<int> a;
	vector<int> b1;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
		b1.push_back(x);

	}
	sort(b1.begin(),b1.end());
	int min=b1[0];
	int mi;
	int ma;
	int max=b1[n-1];
	for(int i=0;i<n;i++)
	{
		if(a[i]==max)
		ma=i;
		break;
	}
	for(int i=n-1;i>0;i--)
	{
		if(a[i]==min)
		mi=i;
		break;
	}

	if(ma>mi)
	{
		cout<<n-1-mi+ma-1;
	}
	else
	cout<<n-1-mi+ma;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count=0;
	vector<int> a;
	vector<int> b;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
		b.push_back(x);

	}
	sort(b.begin(),b.end());
	int min=b[0];
	int mi;
	int ma;
	int max=b[n-1];
	for(int i=0;i<n;i++)
	{
		if(a[i]==max)
		ma=i;
		break;
	}
	for(int i=n-1;i>0;i--)
	{
		if(a[i]==min)
		mi=i;
		break;
	}

	if(ma>mi)
	{
		cout<<n-1-mi+ma-1;
	}
	else
	cout<<n-1-mi+ma;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count=0;
	vector<int> a;
	vector<int> b;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
		b.push_back(x);

	}
	sort(b.begin(),b.end());
	int min=b[0];
	int mi;
	int ma;
	int max=b[n-1];
	for(int i=0;i<n;i++)
	{
		if(a[i]==min)
		mi=i;
		break;
	}
	for(int i=n-1;i>0;i--)
	{
		if(a[i]==max)
		ma=i;
		break;
	}

	if(ma>mi)
	{
		cout<<n-1-mi+ma-1;
	}
	else
	cout<<n-1-mi+ma;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	vector<int>v;
	vector <int> c;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	   {
	     int x;
	     cin>>x;
	     v.push_back(x);
	     c.push_back(x);
	   }
	   	sort(c.begin(),c.end());
	   	int min=c[0];
	   	int max=c[n-1];
	   	int ma;
	   	int mi;
	for(int i=0;i<n;i++)
        {
	       if(v[i]==max)
	       {

		   	ma=i;
		   	cout<<ma;
		   	break;
	        }
	   }
	   	for(int i=n-1;i>=0;i--)
        {
	       if(v[i]==min)
	       {
		   	mi=i;
		   	cout<<mi;
		   	break;

	        }
	   }
	   if(mi>ma)
	   {
	   	cout<<n-1-mi+ma;
	   }
	   else
	   cout<<n-1-mi+ma+1;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count=0;
	vector<int> a;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);

	}
	for(int i=0;i<n-1;i++)
	{
		if(a[i]<a[i+1])
		{
			int temp=a[i];
			a[i]=a[i+1];
			a[i+1]=temp;
			count++;
		}

	}
	for(int i=n-1;i>0;i--)
	{
		if(a[i]>a[i-1])
		{
			int temp=a[i];
			a[i]=a[i-1];
			a[i-1]=temp;
			count++;
		}

	}
	cout<<count;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count=0;
	vector<int> a;
	vector<int> b1;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
		b1.push_back(x);

	}
	sort(b.begin(),b1.end());
	int min=b1[0];
	int mi;
	int ma;
	int max=b1[n-1];
	for(int i=0;i<n;i++)
	{
		if(a[i]==max)
		ma=i;
		break;
	}
	for(int i=n-1;i>0;i--)
	{
		if(a[i]==min)
		mi=i;
		break;
	}

	if(ma>mi)
	{
		cout<<n-1-mi+ma-1;
	}
	else
	cout<<n-1-mi+ma;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count=0;
	vector<int> a;
	vector<int> b;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
		b.push_back(x);

	}
	sort(b.begin(),b.end());
	int min=b[0];
	int mi;
	int ma;
	int max=b[n-1];
	for(int i=0;i<n;i++)
	{
		if(a[i]==min)
		mi=i;
		break;
	}
	for(int i=n-1;i>0;i--)
	{
		if(a[i]==max)
		ma=i;
		break;
	}

	if(ma>mi)
	{
		cout<<n-1-mi+ma-1;
	}
	else
	cout<<n-1-mi+ma-1;

}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min , con = 0 , maxpos , minpos , s , s1 , test;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); ++i){
        if(max < h[i]){
            max = h[i];
            maxpos = i;
        }
    }
    min = max;
    for(int i = h.size()-1; i > 0; --i){
        if(min > h[i]){
            min = h[i];
            minpos = i;
        }
    }
    con += maxpos;
    con +=( h.size() - minpos);
    con--;
    if(maxpos > minpos){
        con--;
        cout << con << endl;
    }else{
        cout << con << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min , con = 0 , maxpos , minpos , s , s1 , test;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); ++i){
        if(max < h[i]){
            max = h[i];
            maxpos = i;
        }
    }
    min = max;
    for(int i = h.size()-1; i > 0; --i){
        if(min > h[i]){
            min = h[i];
            minpos = i;
        }
    }
    con += maxpos;
    test = minpos;
    while(h[h.size()-1] != min){
        s = h[minpos];
        s1 = h[minpos+1];
        h[minpos] = s1;
        h[minpos+1] = s;
        minpos++;
        con++;
    }
    if(maxpos > test && h.size() != 2){
        con--;
        cout << con << endl;
    }else{
        cout << con << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min , con = 0 , maxpos , minpos , s , s1 , test;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); ++i){
        if(max < h[i]){
            max = h[i];
            maxpos = i;
        }
    }
    min = max;
    for(int i = h.size()-1; i >= 0; --i){
        if(min > h[i]){
            min = h[i];
            minpos = i;
        }
    }
    con += maxpos;
    con +=( h.size() - minpos);
    con--;
    if(maxpos > minpos){
        con--;
        cout << con << endl;
    }else{
        cout << con << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min = 0 , con = 0 , maxpos , minpos;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); i++){
        if(max < h[i]){
            max = h[i];
        }
        if(min > h[i]){
            min = h[i];
        }
    }
    while(h[0] != max){
        maxpos = upper_bound(h.begin(),h.end(),max) - h.begin();
        swap(h[maxpos],h[maxpos-1]);
        con++;
    }while(h[h.size()-1] != min){
        minpos = upper_bound(h.begin(),h.end(),min) - h.begin();
        swap(h[minpos],h[minpos+1]);
        con++;
    }
    cout << con << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min , con = 0 , maxpos , minpos , s , s1 , test;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); ++i){
        if(max < h[i]){
            max = h[i];
            maxpos = i;
        }
    }
    min = max;
    for(int i = h.size()-1; i >= 0; --i){
        if(min > h[i]){
            min = h[i];
            minpos = i;
        }
    }
    con += maxpos;
    con +=( h.size() - minpos);
    con--;
    if(maxpos > minpos){
        con--;
        cout << con << endl;
    }else if(maxpos == minpos){
        cout << 0 << endl;
    }else{
        cout << con << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min = 0 , con = 0;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); i++){
        if(max < h[i]){
            max = h[i];
        }
        if(min > h[i]){
            min = h[i];
        }
    }
    while(h[0] != max && h[h.size()-1] != min){
        for(int y = 0; y < h.size()-1; y++){
            if(h[y+1] > h[y]){
                swap(h[y+1],h[y]);
                con++;
            }
        }
    }
    cout << con << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min , con = 0 , maxpos , minpos , s , s1 , test;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); ++i){
        if(max < h[i]){
            max = h[i];
            maxpos = i;
        }
    }
    min = max;
    for(int i = h.size()-1; i > 0; --i){
        if(min > h[i]){
            min = h[i];
            minpos = i;
        }
    }
    con += maxpos;
    con += h.size() - minpos;
    con--;
    if(maxpos > minpos && h.size() != 2){
        con--;
        cout << con << endl;
    }else{
        cout << con << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min , con = 0 , maxpos , minpos , s , s1 , test;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); ++i){
        if(max < h[i]){
            max = h[i];
            maxpos = i;
        }
    }
    min = max;
    for(int i = h.size()-1; i > 0; --i){
        if(min > h[i]){
            min = h[i];
            minpos = i;
        }
    }
    con += maxpos;
    test = minpos;
    while(h[h.size()-1] != min){
        s = h[minpos];
        s1 = h[minpos+1];
        h[minpos] = s1;
        h[minpos+1] = s;
        minpos++;
        con++;
    }
    if(maxpos > test){
        con--;
        cout << con << endl;
    }else{
        cout << con << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
/*
There's No Impossible
         Once You Start Trying
 */

int main() {
    vector<int> h;
    int cases , num , max = 0 , min , con = 0 , maxpos , minpos , s , s1;
    cin >> cases;
    while(cases--){
        cin >> num;
        h.push_back(num);
    }
    for(int i = 0; i < h.size(); ++i){
        if(max < h[i]){
            max = h[i];
            maxpos = i;
        }
    }
    min = max;
    for(int i = h.size()-1; i > 0; --i){
        if(min > h[i]){
            min = h[i];
            minpos = i;
        }
    }
    while(h[0] != max){
        swap(h[maxpos],h[maxpos-1]);
        maxpos--;
        con++;
    }
    while(h[h.size()-1] != min){
        swap(h[minpos],h[minpos+1]);
        minpos++;
        con++;
    }
    if(maxpos < minpos)
        cout << con - 1 << endl;
    else{
        cout << con << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>=max) {
      max= a[j];
      maxi=j;
break;
    }
}
for(int j=0;j<n;j++){
 if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }// cout<<maxi<<"p" <<mini <<"q" <<n<<"l";
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);

  }else{
    cout <<maxi + (n-1-mini);
  }

  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=0;
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
break;
    }
}
for(int j=0;j<n;j++){
 if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }// cout<<maxi<<"p" <<mini <<"q" <<n<<"l";
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);

  }else{
    cout <<maxi + (n-1-mini);
  }

  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }
  }
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);
  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }else if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);

  }else{
    cout <<'0';
  }

  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }else if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }// cout<<maxi <<mini;
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);

  }else{
    cout <<maxi + (n-1-mini);
  }

  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  max=0;
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;

    }
}
min=a[0];
for(int j=0;j<n;j++){
 if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  } //cout<<maxi<<"p" <<mini <<"q" <<n<<"l";
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);

  }else{
    cout <<maxi + (n-1-mini);
  }

  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }else if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);
  }
  cout <<'0';
  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }
  }
  if(maxi !=0){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

   }
  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }

  cout << maxi+(n-1-mini);
  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }else if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  }
  cout << maxi+(n-1-mini);
  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }else if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  } cout<<maxi <<mini;
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);

  }else{
    cout <<maxi + (n-1-mini);
  }

  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }else if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }// cout<<maxi <<mini;
  if(maxi!=0 || mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);

  }else{
    cout <<'0';
  }

  }


#include <iostream>
#include <string>
#include<cstring>

using namespace std;

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

  int min,max,mini,maxi;
  min=max=a[0];
  for(int j=0;j<n;j++){
     if( a[j]>max) {
      max= a[j];
      maxi=j;
    }else if(a[j]<=min){
       min=a[j];
       mini=j;
    }
  }
  if(maxi!=0 && mini!=(n-1)){
  for(int k=maxi; k>0;k--){
    int temp=0;
    temp =a[k];
    a[k]= a[k-1];
    a[k-1]=temp;
  }

  for(int l=0;l<n;l++){
    if(a[l]<=min){
       min=a[l];
       mini=l;
    }
  }
  cout << maxi+(n-1-mini);
  }
  cout << '0';
  }


#include<iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int arr[n],maxi=0,mini=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int max=arr[0],min=arr[0];
	for(int i=0; i<n; i++){
		if(arr[i]>max){
			max=arr[i];
			maxi=i;
		}
		if(arr[i]<min){
			min=arr[i];
			mini=i;
		}
	}
		if(mini<maxi){
		cout<<(maxi+n-mini-3)<<endl;
	}
	else
		cout<<(maxi+n-mini-1)<<endl;
	return 0;
}


#include<iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int arr[n],maxi=0,mini=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int max=arr[0],min=arr[0];
	for(int i=0; i<n; i++){
		if(arr[i]>max){
			max=arr[i];
			maxi=i;
		}
		if(arr[i]<min){
			min=arr[i];
			mini=i;
		}
	}
	cout<<mini<<"  "<<min<<endl;
	cout<<maxi<<"  "<<max<<endl;
		if(mini<maxi){
		cout<<(maxi+n-mini-3)<<endl;
	}
	else
		cout<<(maxi+n-mini-1)<<endl;
	return 0;
}


#include<iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int arr[n],maxi=0,mini=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int max=arr[0],min=arr[0];
	for(int i=0; i<n; i++){
		if(arr[i]>max){
			max=arr[i];
			maxi=i;
		}
		if(arr[i]<min){
			min=arr[i];
			mini=i;
		}
	}
	if(mini<maxi){
		cout<<(maxi-1+n-mini-1)<<endl;
	}
	else
		cout<<(maxi-1+n-mini)<<endl;
	return 0;
}


#include<iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int arr[n],maxi=0,mini=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int max=arr[0],min=arr[0];
	for(int i=0; i<n; i++){
		if(arr[i]>max){
			max=arr[i];
			maxi=i;
		}
		if(arr[i]<min){
			min=arr[i];
			mini=i;
		}
	}
	if(mini<maxi){
		cout<<(maxi+n-mini-2)<<endl;
	}
	else
		cout<<(maxi+n-mini-1)<<endl;
	return 0;
}


#include<iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int arr[n],maxi=0,mini=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int max=arr[0],min=arr[0];
	for(int i=0; i<n; i++){
		if(arr[i]>max){
			max=arr[i];
			maxi=i;
					}
		if(arr[i]<min){
			min=arr[i];
			mini=i;
		}
	}
		if(mini<maxi){
		cout<<(maxi-1+n-mini-2)<<endl;
	}
	else
		cout<<(maxi+n-mini-1)<<endl;
	return 0;
}


#include<iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int arr[n],maxi=0,mini=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int max=arr[0],min=arr[0];
	for(int i=0; i<n; i++){
		if(arr[i]>max){
			max=arr[i];
			maxi=i;
		}
		if(arr[i]<min){
			min=arr[i];
			mini=i;
		}
	}
	if(mini<maxi){
		cout<<(maxi-1+n-mini-2)<<endl;
	}
	else
		cout<<(maxi-1+n-mini-1)<<endl;
	return 0;
}


#include<iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int arr[n],maxi=0,mini=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int max=arr[0],min=arr[0];
	for(int i=0; i<n; i++){
		if(arr[i]>max){
			max=arr[i];
			maxi=i;
		}
		if(arr[i]<min){
			min=arr[i];
			mini=i;
		}
	}
	if(mini<maxi){
		cout<<(maxi+n-mini-1)<<endl;
	}
	else
		cout<<(maxi+n-mini)<<endl;
	return 0;
}


#include<iostream>
 using namespace std;

 int main()
 {
     int n,i;
     cin>>n;

     int a[n];

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

     int min,max,min_index,max_index;

     min=a[0];
     min_index=0;
     max=a[0];
     max_index=0;

     for ( i=0; i<n; i++)
     {
         if ( min>=a[i])
         {
             min=a[i];
             min_index=i;
         }
         if ( max<a[i])
         {
             max=a[i];
             max_index=i;
         }

     }

     if ( min_index<max_index)
     {

          min_index=(n-1)-min_index;
          cout<<(min_index+max_index-1)<<endl;
     }
     else
     {

      min_index=(n-1)-min_index;
     cout<<(min_index+max_index)<<endl;
     }
 }


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1,m,b;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[2];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1)
        {
            max1=a[i];
            m=i;
        }
    }
    if(a[1]<a[2])
    {
        min1=a[1];
        b=1;
    }
    for(int i=3; i<=n; i++)
    {
        if(a[i]<min1)
        {
            min1=a[i];
            b=i;
        }
    }
    cout << m-b+n-1;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1,m,b;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[2];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1)
        {
            max1=a[i];
            m=i;
        }
    }
    if(a[1]<a[2]) min1=a[1];
    for(int i=3; i<=n; i++)
    {
        if(a[i]<min1)
        {
            min1=a[i];
            b=i;
        }
    }
    cout << m-b+n-1;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,a[101],max1,min1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) max1=a[i];
        if(a[i]<min1) min1=a[i];
    }
    int m=1,b=1;
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) m=i;
        if(a[i]<min1) b=i;
    }
    int s=m+b-1-n;
    if(b<m) cout << abs(s);
    if(b>m) cout << abs(s-1);
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) max1=a[i];
        if(a[i]<min1) min1=a[i];
    }
    int m=1,b=1;
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) m=i
        if(a[i]<min1) b=i;
    }
    int s=m+b-1-n;
    if(b==m) cout << 0;
    if(b<m) cout << s;
    if(b>m) cout << s-1;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,a[101],max1,min1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) max1=a[i];
        if(a[i]<min1) min1=a[i];
    }
    int m=1,b=1;
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) m=i;
        if(a[i]<min1) b=i;
    }
    int s=m+b-1-n;
    if(b==m) cout << 0;
    if(b<m) cout << abs(s);
    if(b>m) cout << abs(s-1);
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) max1=a[i];
        if(a[i]<min1) min1=a[i];
    }
    int m=1,b=1;
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) m=i;
        if(a[i]<min1) b=i;
    }
    int s=m+b-1-n;
    if(b==m) cout << 0;
    if(b<m) cout << s;
    if(b>m) cout << s-1;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[2];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) max1=a[i];
    }
    if(a[1]<a[2]) min1=a[1];
    for(int i=3; i<=n; i++)
    {
        if(a[i]<min1) min1=a[i];
    }
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) max1=a[i];
        if(a[i]<=min1) min1=a[i];
    }
    cout << m-b+n-1;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>max1) max1=a[i];
        if(a[i]<min1) min1=a[i];
    }
    int m,b;
    for(int i=1; i<=n; i++)
    {
        if(a[i]==max1) m=i;
        if(a[i]==min1) b=i;
    }
    cout << m-1+n-b;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],x=0,y=0;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        if(a[i]>a[x]) x=i;
        if(a[i]<=a[y]) y=i;
    }
    cout << n-y-1+x-(y<x);
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1,m=1,b=1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1)
        {
            max1=a[i];
            m=i;
        }
    }
    for(int i=2; i<=n; i++)
    {
        if(a[i]<=min1)
        {
            min1=a[i];
            b=i;
        }
    }
    cout << m-1+n-b;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a[101],max1,min1;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    max1=a[1];
    min1=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]>=max1) max1=a[i];
        if(a[i]<=min1) min1=a[i];
    }
    int m,b;
    for(int i=1; i<=n; i++)
    {
        if(a[i]==max1) m=i;
        if(a[i]==min1) b=i;
    }
    cout << m-1+n-b;
}


#include <iostream>
using namespace std;
int Largest(int A[], unsigned int L){
	int Lr = 0;
	for (unsigned int i = 0; i < L; i++)
		if (A[i] > A[Lr])
			Lr = i;
	return Lr;
}
int Smallest(int A[], unsigned int L){
	int S = L - 1;
	for (unsigned int i = L - 1; i > 0; i--)
		if (A[i] < A[S])
			S = i;
	return S;
}
//For Tracing
void Print(int A[], unsigned int L){
	for (unsigned int i = 0; i < L; i++)
		cout << A[i] << ' ';
	cout << '\n';
}
int main(){
	int C = 0, N, *S, D;
	cin >> N;
	S = new int[N];
	for (unsigned int i = 0; i < N; i++){
		cin >> S[i];
	}
	unsigned int T, inS = Smallest(S, N), inL = Largest(S, N);
	if (inS < inL)
		D = 1;
	else
		D = 0;
	while (inS != N - 1){
		T = S[inS + 1];
		S[inS + 1] = S[inS];
		S[inS] = T;
		inS++;
		C++;
		//Print(S, N); //Trace
	}
	while (inL != 0){
		T = S[inL - 1];
		S[inL - 1] = S[inL];
		S[inL] = T;
		inL--;
		C++;
		//Print(S, N); //Trace
	}
	if (C > 2)
	cout << C - D << '\n';
	else cout << '0' << '\n';
	delete S;
	return 0;
}


#include <iostream>
using namespace std;
int Largest(int A[], unsigned int L){
	int Lr = 0;
	for (unsigned int i = 0; i < L; i++)
		if (A[i] > A[Lr])
			Lr = i;
	return Lr;
}
int Smallest(int A[], unsigned int L){
	int S = L - 1;
	for (unsigned int i = L - 1; i > 0; i--)
		if (A[i] < A[S])
			S = i;
	return S;
}
//For Tracing
void Print(int A[], unsigned int L){
	for (unsigned int i = 0; i < L; i++)
		cout << A[i] << ' ';
	cout << '\n';
}
int main(){
	int C = 0, N, *S, D;
	cin >> N;
	S = new int[N];
	for (unsigned int i = 0; i < N; i++){
		cin >> S[i];
	}
	unsigned int T, inS = Smallest(S, N), inL = Largest(S, N);
	if (inS < inL)
		D = 1;
	else
		D = 0;
	while (inS != N - 1){
		T = S[inS + 1];
		S[inS + 1] = S[inS];
		S[inS] = T;
		inS++;
		C++;
		//Print(S, N); //Trace
	}
	while (inL != 0){
		T = S[inL - 1];
		S[inL - 1] = S[inL];
		S[inL] = T;
		inL--;
		C++;
		//Print(S, N); //Trace
	}
	cout << C - D<< '\n';
	delete S;
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	unsigned short int N, n, M, i = 1, Min = 100, Max = 0, Mini = 0, Maxi = 0;
	cin >> N;
	n = N;
	while (N--){
		cin >> M;
		if (M > Max){
			Max = M;
			Maxi = i;
		}
		if (M < Min){
			Min = M;
			Mini = i;
		}
		i++;
	}
	if (Maxi > Mini)
		cout << n - Mini + Maxi - 2 << endl;
	else
		cout << n - Mini + Maxi - 1 << endl;

	return 0;
}


#include <iostream>
using namespace std;
int main(){
	unsigned short int N, n, M, i = 1, Min = 100, Max = 0, Mini = 0, Maxi = 0;
	cin >> N;
	n = N;
	while (N--){
		cin >> M;
		if (M >= Max){
			Max = M;
			Maxi = i;
		}
		if (M <= Min){
			Min = M;
			Mini = i;
		}
		i++;
	}
	if (Maxi > Mini)
		cout << n - Mini + Maxi - 2 << endl;
	else
		cout << n - Mini + Maxi - 1 << endl;

	return 0;
}


#include <iostream>
using namespace std;
int Largest(int A[], unsigned int L){
	int Lr = 0;
	for (unsigned int i = 0; i < L; i++)
		if (A[i] > A[Lr])
			Lr = i;
	return Lr;
}
int Smallest(int A[], unsigned int L){
	int S = L - 1;
	for (unsigned int i = L - 1; i > 0; i--)
		if (A[i] < A[S])
			S = i;
	return S;
}
//For Tracing
void Print(int A[], unsigned int L){
	for (unsigned int i = 0; i < L; i++)
		cout << A[i] << ' ';
	cout << '\n';
}
int main(){
	int C = 0, N, *S;
	cin >> N;
	S = new int[N];
	for (unsigned int i = 0; i < N; i++){
		cin >> S[i];
	}
	unsigned int T, inS = Smallest(S, N), inL = Largest(S, N);
	bool Stop = false;
	while (inS != N - 1 || inL != 0){
		//cout << inS << ' ' << inL << '\n'; //Trace
		if (inS != N - 1){
			T = S[inS + 1];
			S[inS + 1] = S[inS];
			S[inS] = T;
			if (inS + 1 == inL){
				Stop = true;
				inL--;
			}
			inS++;
			C++;
		}
		if (inL != 0 && !Stop){
			T = S[inL - 1];
			S[inL - 1] = S[inL];
			S[inL] = T;
			inL--;
			C++;
		}
		Stop = false;
		//Print(S, N); //Trace
	}
	cout << C << '\n';
	delete S;
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	unsigned short int N, n, M, i = 1, Min = 100, Max = 0, Mini = 0, Maxi = 0;
	cin >> N;
	n = N;
	while (N--){
		cin >> M;
		if (M > Max){
			Max = M;
			Maxi = i;
		}
		if (M <= Min){
			Min = M;
			Mini = i;
		}
		i++;
	}
	if (Maxi > Mini)
		cout << n - Mini + Maxi - 2 << endl;
	else
		cout << n - Mini + Maxi - 1 << endl;

	return 0;
}


#include <iostream>
using namespace std;
int Largest(int A[], unsigned int L){
	int Lr = 0;
	for (unsigned int i = 0; i < L; i++)
		if (A[i] > A[Lr])
			Lr = i;
	return Lr;
}
int Smallest(int A[], unsigned int L){
	int S = L - 1;
	for (unsigned int i = L - 1; i > 0; i--)
		if (A[i] < A[S])
			S = i;
	return S;
}
//For Tracing
void Print(int A[], unsigned int L){
	for (unsigned int i = 0; i < L; i++)
		cout << A[i] << ' ';
	cout << '\n';
}
int main(){
	int C = 0, N, *S, D;
	cin >> N;
	S = new int[N];
	for (unsigned int i = 0; i < N; i++){
		cin >> S[i];
	}
	unsigned int T, inS = Smallest(S, N), inL = Largest(S, N);
	if (inS < inL)
		D = 1;
	else
		D = 0;
	while (inS != N - 1){
		T = S[inS + 1];
		S[inS + 1] = S[inS];
		S[inS] = T;
		inS++;
		C++;
		//Print(S, N); //Trace
	}
	while (inL != 0){
		T = S[inL - 1];
		S[inL - 1] = S[inL];
		S[inL] = T;
		inL--;
		C++;
		//Print(S, N); //Trace
	}
	int A = C - D;
	if (A < 0)
		A = 5;
	cout << A << '\n';
	delete S;
	return 0;
}


#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<long , long> pll;

const ll mx = 105;
const ll mod = 998244353;
const ll maxn = 1e17;

void solve(){

  ll n, i, j, k;

  string s;

  cin>>s;

  int syms[26], symc[26];

  for(i = 0;i < 26;i++){
      syms[i] = -1;
      symc[i] = -1;
  }
  syms[1] = 3;
  syms[3] = 1;
  syms[12] = 12;
  syms[14] = 14;
    syms[21] = 21;
     syms[22] = 22;
      syms[23] = 23;

      symc[0] = 0;
            symc[7] = 7;
                        symc[8] = 8;
                                    symc[12] = 12;
            symc[14] = 14;
                        symc[20] = 20;
            symc[21] = 21;
                        symc[22] = 22;
            symc[23] = 23;
            symc[24] = 24;

            int flag = 1;
             j = sz(s) - 1;
            for(i =0 ;i < sz(s)/2;i++){
                if(s[i] >= 'a' && s[j] >= 'a'){
                    if(syms[s[i] - 'a'] == s[j] - 'a' &&  syms[s[j] - 'a'] == s[i]-'a'){

                    }
                    else{
                        flag = 0;
                        break;
                    }
                }
                else if(s[i] <= 'Z' && s[j] <= 'Z'){
                      if(symc[s[i] - 'A'] == s[j] - 'A' &&  symc[s[j] - 'A'] == s[i]-'A'){

                    }
                    else{
                        flag = 0;
                        break;
                    }
                }
                else{
                    break;
                }
            }

            if(sz(s)%2 != 0){
                ll mi = sz(s)/2;
                if(s[mi] >= 'a'){
                    if(syms[s[mi]- 'a'] == -1)
                    {
                        flag = 0;

                    }
                }
                else if(s[mi] >= 'A'){
                      if(symc[s[mi]- 'A'] == -1)
                    {
                        flag = 0;

                    }
                }
            }

        if(flag){
            cout<<"TAK\n";
        }else{
            cout<<"NIE\n";
        }

}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(0);

    ll t = 1;

    //cin>>t;

    while(t--){
        solve();
    }

}


/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
	// AabBcCdDeEfFgGhHIijJkKlLmMnMNoOpPqQrRsSTTUuvVwWxXYyzZ
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	// s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		if(st[i]=='p'&&st[st.length()-1-i]!='q')
		p=0;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]!='p')
		p=0;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]!='b')
		p=0;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]!='d')
		p=0;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
	// AabBcCdDeEfFgGhHIijJkKlLmMnMNoOpPqQrRsSTTUuvVwWxXYyzZ
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	// s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	// s.insert('l');
	// s.insert('m');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	s.insert('l');
	// s.insert('m');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
    set<char> s;

	s.insert('H');
	s.insert('I');
	s.insert('l');
	s.insert('m');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	s.insert('l');
	s.insert('m');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	s.insert('l');
	s.insert('m');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	s.insert('i');
	s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	// s.insert('l');
	// s.insert('m');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	// s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
	AabBcCdDeEfFgGhHIijJkKlLmMnMNoOpPqQrRsSTTUuvVwWxXYyzZ
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	// s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
	// AabBcCdDeEfFgGhHIijJkKlLmMnMNoOpPqQrRsSTTUuvVwWxXYyzZ
    set<char> s;
	s.insert('A');
	s.insert('H');
	s.insert('I');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	// s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');
	// s.insert('i');
	// s.insert('u');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


       /*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;
int main()
{
    set<char> s;

	s.insert('H');
	s.insert('I');
	s.insert('l');
	s.insert('m');
	s.insert('M');
	s.insert('O');
	s.insert('o');
	s.insert('T');
	s.insert('U');
	s.insert('v');
	s.insert('V');
	s.insert('W');
	s.insert('w');
	s.insert('Y');
	s.insert('y');
	s.insert('x');
	s.insert('X');
	s.insert('b');
	s.insert('d');
	s.insert('p');
	s.insert('q');

	string st;

	cin>>st;

	// for(auto it: s)
	// cout<<it<<endl;

	for(int i=0;i<st.length();i++)
	{
		if(s.find(st[i])==s.end())
		{
			cout<<"NIE"<<endl;
			return 0;
		}
	}

	bool p=1;

	if(st.length()%2)
	{
		if(st[st.length()/2]=='b' || st[st.length()/2]=='d' || st[st.length()/2]=='p' ||st[st.length()/2]=='q')
		p=0;
	}

	for(int i=0;i<st.length()/2;i++)
	{
		if(st[i]=='p'&&st[st.length()-1-i]=='q')
		continue;
		else if(st[i]=='q'&&st[st.length()-1-i]=='p')
		continue;
		else if(st[i]=='d'&&st[st.length()-1-i]=='b')
		continue;
		else if(st[i]=='b'&&st[st.length()-1-i]=='d')
		continue;
		else
		if(st[i]!=st[st.length()-1-i])
		{
			p=0;
		}
	}
	if(p)
	cout<<"TAK";
	else
	cout<<"NIE";
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d'; is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y'; is['p']='q'; is['q']='p';
    is['T']='T'; is['U']='U';
    string s; cin>>s;

    for(int i=0;i<s.length()/2+1;i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d'; is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y'; is['p']='q'; is['q']='p';
    is['T']='T'; is['U']='U';
    string s; cin>>s;

    for(int i=0;i<s.length();i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d';
    is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I'; is['i']='i';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y';
    string s; cin>>s;

    for(int i=0;i<s.length()/2+1;i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d'; is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I';
    is['M']='M';  is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y'; is['p']='q'; is['q']='p';
    is['T']='T'; is['U']='U';
    string s; cin>>s;

    for(int i=0;i<s.length();i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d';
    is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I'; is['i']='i';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y'; is['p']='q'; is['q']='p';
    string s; cin>>s;

    for(int i=0;i<s.length()/2+1;i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d';
    is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I'; is['i']='i';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y'; is['p']='q'; is['q']='p';
    is['T']='T';
    string s; cin>>s;

    for(int i=0;i<s.length()/2+1;i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d'; is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y'; is['p']='q'; is['q']='p';
    is['T']='T'; is['U']='U'; is['i']='i';
    string s; cin>>s;

    for(int i=0;i<s.length()/2+1;i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    is['b']='d';
    is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I'; is['i']='i';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y';
    string s; cin>>s;
    for(int i=0;i<s.length()/2;i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN=200001;
int is[MAXN]={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(is,-1,sizeof(is));
    is['b']='d';
    is['d']='b';
    is['A']='A'; is['O']='O'; is['o']='o';
    is['H']='H'; is['I']='I'; is['i']='i';
    is['M']='M'; is['m']='m'; is['U']='U';
    is['V']='V'; is['v']='v'; is['W']='W';
    is['w']='w'; is['X']='X'; is['x']='x';
    is['Y']='Y';
    string s; cin>>s;

    for(int i=0;i<s.length()/2;i++){
        int L=s[i];
        int R=is[s[i]];
        if(s[i]==L && s[s.length()-i-1]==R){

        }
        else{
            cout<<"NIE";
            exit(0);
        }
    }
    cout<<"TAK";

    return 0;
}


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

#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
const int N=1e4+5;
string s;
map<char,char>mp;
bool check()
{
    mp['o']='o',mp['O']='O',mp['p']='q',mp['q']='p',mp['d']='b',mp['H']='H',
    mp['A']='A',mp['I']='I',mp['i']='i',mp['l']='l',mp['M']='M',mp['T']='T',
    mp['V']='V',mp['v']='v',mp['w']='w',mp['W']='W',mp['x']='x',mp['X']='X',
    mp['Y']='Y',mp['b']='d';
    int a=0, b=s.size()-1;

    while(a<=b)
    {
        if(mp[s[a]]!=s[b])return 0;
        a++,b--;
    }

    return 1;
}

int main(){ speed;
cin>>s;

check()?cout<<"TAK":cout<<"NIE";

return 0;}


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

#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
const int N=1e4+5;
string s;
map<char,char>mp;
bool check()
{
    mp['o']='o',mp['O']='O',mp['p']='q',mp['q']='p',mp['d']='b',mp['H']='H',
    mp['A']='A',mp['I']='I',mp['M']='M',mp['T']='T',
    mp['V']='V',mp['v']='v',mp['w']='w',mp['W']='W',mp['x']='x',mp['X']='X',
    mp['Y']='Y',mp['b']='d',mp['U']='U';
    int a=0, b=s.size()-1;

    while(a<=b)
    {
        if(mp[s[a]]!=s[b])return 0;
        a++,b--;
    }

    return 1;
}

int main(){ speed;
cin>>s;

check()?cout<<"TAK":cout<<"NIE";

return 0;}


#include<bits/stdc++.h>
using namespace std;
/*

██╗    ██╗██████╗ ██╗████████╗████████╗███████╗███╗   ██╗    ██████╗ ██╗   ██╗
██║    ██║██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗  ██║    ██╔══██╗╚██╗ ██╔╝
██║ █╗ ██║██████╔╝██║   ██║      ██║   █████╗  ██╔██╗ ██║    ██████╔╝ ╚████╔╝
██║███╗██║██╔══██╗██║   ██║      ██║   ██╔══╝  ██║╚██╗██║    ██╔══██╗  ╚██╔╝
╚███╔███╔╝██║  ██║██║   ██║      ██║   ███████╗██║ ╚████║    ██████╔╝   ██║
 ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝   ╚═╝      ╚═╝   ╚══════╝╚═╝  ╚═══╝    ╚═════╝    ╚═╝

     ███╗   ███╗   ██╗██████╗ ██████╗  █████╗ ██╗  ██╗██╗███╗   ███╗
     ████╗ ████║   ██║██╔══██╗██╔══██╗██╔══██╗██║  ██║██║████╗ ████║
     ██╔████╔██║   ██║██████╔╝██████╔╝███████║███████║██║██╔████╔██║
     ██║╚██╔╝██║   ██║██╔══██╗██╔══██╗██╔══██║██╔══██║██║██║╚██╔╝██║
     ██║ ╚═╝ ██║██╗██║██████╔╝██║  ██║██║  ██║██║  ██║██║██║ ╚═╝ ██║
     ╚═╝     ╚═╝╚═╝╚═╝╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝     ╚═╝
*/
#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
const int N=1e4+5;
string s;
map<char,char>mp;
bool check()
{
    mp['o']='o',mp['O']='O',mp['p']='q',mp['q']='p',mp['d']='b',mp['H']='H',
    mp['A']='A',mp['I']='I',mp['M']='M',mp['T']='T',
    mp['V']='V',mp['v']='v',mp['w']='w',mp['W']='W',mp['x']='x',mp['X']='X',
    mp['Y']='Y',mp['b']='d';
    int a=0, b=s.size()-1;

    while(a<b)
    {
        if(mp[s[a]]!=s[b])return 0;
        a++,b--;
    }

    return 1;
}

int main(){ speed;
cin>>s;

check()?cout<<"TAK":cout<<"NIE";

return 0;}


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

#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
const int N=1e4+5;
string s;
map<char,char>mp;
bool check()
{
    mp['o']='o',mp['O']='O',mp['p']='q',mp['q']='p',mp['d']='b',mp['H']='H',
    mp['A']='A',mp['I']='I',mp['i']='i',mp['l']='l',mp['M']='M',mp['T']='T',
    mp['V']='V',mp['v']='v',mp['w']='w',mp['W']='W',mp['x']='x',mp['X']='X',
    mp['Y']='Y',mp['b']='d',mp['U']='U';
    int a=0, b=s.size()-1;

    while(a<=b)
    {
        if(mp[s[a]]!=s[b])return 0;
        a++,b--;
    }

    return 1;
}

int main(){ speed;
cin>>s;

check()?cout<<"TAK":cout<<"NIE";

return 0;}