public class PrisonBreak{
		
	static public void main(String...z){
		int cellCount = 20;
		int[] prisnorNum = new int[]{14,6,3};
		int[] prisnorNum1 = new int[]{3,6,14};
		System.out.println(getNumberOfCoins(cellCount, prisnorNum));
		System.out.println("......................................................");
		System.out.println(getNumberOfCoins(cellCount, prisnorNum1));
	}
	
	public static int getNumberOfCoins(int cellCount, int[] prisnorNum){
		int coins = 0;
		int prisons[] = new int[cellCount+1];
		
		//intializing prisons with a prisnor in each
		for(int i = 1 ; i <= cellCount ; i++)
			prisons[i] = 1;
		
		for(int j=0 ; j<prisnorNum.length ; j++){
			if(j == 0){
				coins = cellCount - 1;
				prisons[prisnorNum[j]] = 0;
			}
			else{
				
				for(int k = prisnorNum[j]+1 ; k <= cellCount ; k++)
				{
					if(prisons[k] == 0)	break;
					coins++;
				}
				
				for(int k = prisnorNum[j]-1 ; k > 0 ; k--)
				{
					if(prisons[k] == 0)	break;
					coins++;
				}
				
				prisons[prisnorNum[j]] = 0;
			}
			
		}
			return coins;
	}
}