import com.sun.tools.javac.util.ArrayUtils;

import java.util.*;

public class Arraz {


    public int sumOfValues(int[] array) {

        int sum = 0;

        for (int i = 0; i < array.length; i++) {
            sum = sum + array[i];
        }
        return sum;
    }

    public double sumDoublesOfArra(double[] array) {
        double sum = 0.0;
        for (int i = 0; i < array.length; i++) {
            sum = sum + array[i];
        }

        return sum;
    }

    public int averageOfArray(int[] array) {
        int length = array.length;
        int avg = sumOfValues(array) / length;
        return avg;
    }

    public double doubleaverageOfArray(double[] array) {
        int length = array.length;
        double avg = sumDoublesOfArra(array) / length;
        return avg;
    }

    public boolean containsValue(int[] array, int value) {
        boolean flag = true;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == value) {
                return true;

            } else {
                flag = false;
            }

        }
        return flag;
    }

    public Integer[] reverseArray(Integer[] array) {
        Integer arr[] = new Integer[array.length];
        for (int i = 0; i < array.length; i++) {
            arr[i] = array[array.length - i - 1];
            System.out.println(arr[i]);
        }
        return arr;
    }

    public static OddEven oddEven(int[] array) {
        int oddcount = 0;
        int evencount = 0;

        for (int i = 0; i < array.length; i++) {
            if (array[i] % 2 == 0) {
                evencount++;

            } else
                oddcount++;

        }
        return new OddEven(oddcount, evencount);
    }

    public int indexOf(int[] array, int value) {
        int index = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == value) {
                index = i;

            }
        }
        return index;
    }

    public Integer[] copyArrayByInterator(Integer[] array) {
        List<Integer>list=new ArrayList<Integer>(Arrays.asList(array ) ) ;
        int i=0;
        Iterator<Integer>itr=list.iterator() ;
        Integer[] exp=new Integer[ list.size()];
        while(itr.hasNext() ){
            exp[i]=itr.next() ;
            i++;
        }


        return  exp;
    }

    public Integer[] copyArrayLoop(Integer[] array) {
        Integer[] exp = new Integer[array.length];
        for (int i = 0; i < array.length; i++) {
            exp[i] = array[i];
            System.out.println(exp[i]);
        }
        return exp;
    }

    public Integer[] removeElementFromArray(Integer[] array, int valueToRemove) {
//            int count=0;
//        Integer exp[] = new Integer[array.length - 1];
//        for (int i = 0; i <array.length; i++) {
//            if (array[i] != valueToRemove) {
//                exp[count ] = array[i];
//               count ++;
//            } else {
//                continue;
//
//            }
//            System.out.println(exp[count]);
//        }
        Arrays.sort(array ) ;
        ArrayList<Integer > list=new ArrayList<Integer>() ;
        int n=array.length -1;
        for(int i=0;i<n;i++){
            if(array[i]==valueToRemove  ){
                continue;
            }
            else
                list.add(array[i] );
        }
        System.out.println(list);
       // list.add(array[n]);
        return list.toArray(new Integer[list.size()]);


    }

    public Integer[]  insertIntoArrayat(Integer  array[], int insertValue, int index) {
            ArrayList<Integer>list=new ArrayList<Integer>();

        for (int i = 0; i < index ;i++) {
            list.add(array[i]);
        }
         list.add(insertValue );
        for (int i = index; i < array.length   ;i++) {
            list.add(array[i]);
        }
            Integer[] exp=list.toArray(new Integer[list.size() ] );
       // System.arraycopy(array,index,exp,insertValue ,1) ;
       return exp;
    }

    public static MaxMin maxMinarray(int array[]){
        int max=0;
        int min=array[0];
        for(int i=0;i<array.length;i++ ) {
            if (array[i] > max)
                 max=array[i] ;
        else
            { if(array[i]<min )
               min=array[i];
            }
        }
        System.out.println(max) ;
        System.out.println(min);
         return new MaxMin(max,min);

    }

   public Integer [] duplicates(Integer array[]) {

       Arrays.sort(array);
       ArrayList <Integer> al =new ArrayList<Integer>();

       int arrayLength = array.length -1;
       for (int i = 0; i < arrayLength; i++) {
           if (array[i] != array[i + 1]) {
               al.add(array[i]);
           } else {
               continue;
           }
       }
       al.add(array[arrayLength]);
       return al.toArray(new Integer[al.size()]);

   }

       public int fib(int n){
        if(n<=1){
            return n;
        }
        return fib(n-1)+fib(n-2);
        }

        public int fibanocci(int n){
            int a = 0, b = 1, c;
            if (n == 0)
                return a;
            for (int i = 2; i <= n; i++)
            {
                c = a + b;
                a = b;
                b = c;
            }
            return b;

        }
        public int secondLargest(int array[]){
        int max=array [0];
        int secondmax=array[0];

        for(int i=0;i<array.length;i++ ){
            if(array[i]>max){
                secondmax =max;
                max=array[i];
            }
            else
                if(array [i]>secondmax )
                secondmax =array[i];
        }
        return secondmax ;
        }

        public ArrayList <Integer> makemeArrayList(Integer[] array){
        ArrayList <Integer> list=new ArrayList<Integer>(Arrays.asList(array ));
        return list;
        }
        public Integer[] makemearray(ArrayList <Integer> list){
             list = new ArrayList<Integer>();
             //Object [] object=list.toArray() ;
            Integer [] arr=list.toArray(new Integer[list.size() ]);
           return  arr;


        }
        public boolean arrayEquals(int arr[],int array[]) {
            boolean flag = false;
            if (Arrays.equals(arr,array ) ) {
                flag = true;
            } else{
                flag = false;
        }
            return flag;
        }

        public Integer averageValueWithoutMaxMin(Integer arra[]){

            Arrays.sort(arra);
            int sum =0;
            for (int i=1;i<arra.length -1; i++){
                sum +=arra [i];
            }

        return (sum/(arra.length-2) );
        }

        public boolean checkvalues(int[] array,int n,int m){
        boolean flag=false;
        for(int i=0;i<array.length;i++ ){
            if(array[i]==m || array[i]== n){
               flag=true;

            }
            else
                array[i]=array[i];
        }
         return flag;
        }
      public boolean sumOfTens(int array[],int n){
        int sum=0;
        boolean flag=false;
        for(int i=0;i<array.length ;i++ ){
            if(array[i]==n) {
                sum = sum + array[i];
            }
                if(sum==30){
                flag=true;
            }
            else
                flag=false;
        }
        return flag;
      }

      public Integer[]  smallestSecondsmallest(Integer array[]){
        Arrays.sort(array);
          Integer [] smallest= { array[0], array[1]};


        return smallest ;
      }
     public Integer[] makeMeACopyPlease(Integer array[]){
        Integer copy[]=copyArrayLoop(array);
        Integer rev[]=new Integer [array.length ];
        for(int i=0;i<rev.length;i++ ){
            rev[i]=copy[copy.length -i-1];
        }
        return rev;
     }
     public Integer[] removeLastItemandCopy(Integer arra[],int valueToRemove){
        valueToRemove =arra.length;
        Integer[] copy=new Integer[arra.length -1];
        for(int i=0;i<arra.length -1 ;i++ ){
            if(arra[i]==valueToRemove ){
                continue;
            }
            else
                copy[i]=arra[i];
        }
        return copy;
     }

     public Integer[] removeFirstItemandCopy(Integer[] array,int valueToRemove ){
         valueToRemove =array[0];
         //Integer[] copy=new Integer[array.length -1];
         ArrayList<Integer> al = new ArrayList<Integer>();

         for(int i=1;i<array.length;i++ ){
           al.add(array[i]);
         }
         return al.toArray(new Integer[al.size() ] ) ;
     }


     public Integer[] insertAtStartAndCopy(Integer[] array,int insertValue){

        Integer[] newArray=new Integer[array.length +1 ];
           newArray [0]=insertValue ;
         for(int i=1;i<newArray.length;i++ ){
             newArray[i]=array[i-1];

         }
         return newArray ;
     }

     public Integer[] insertAtTheEnd(Integer[]  array,int insertValue ) {

         Integer[] newArray=new Integer[array.length +1 ];
         newArray [newArray .length-1]=insertValue ;

         for(int i=0;i<array.length;i++ ){
             newArray[i]=array[i];

            System.out.println(newArray[i] ) ;
         }
       // newArray [newArray .length-1]=insertValue ;

         return newArray ;
     }

     public Integer[] sortArrayIntoEvensThenOdds(Integer[] array){
        ArrayList <Integer> even=new ArrayList<Integer>();
        ArrayList <Integer>odd=new ArrayList<Integer>();
        for(int i=0;i<array.length;i++ ){
            if(array[i]%2==0){
                even.add(array[i]);
            }
            else
                odd.add(array[i]);
        }
         Collections.sort(even);
        Collections.sort(odd);
        even.addAll(odd);
        Integer[] sorting=even.toArray(new Integer[even.size() ] ) ;
        return sorting;
     }
}