import java.util.*;
import java.util.stream.Stream;

public class Arraz {

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

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

    public int averageOfArray(int[] intArr){
        return sumValuesOfArray(intArr) / intArr.length;
    }

    public double averageDoubleOfArray(double[] dbArr){
        return sumDoublesOfArray(dbArr) / dbArr.length;
    }

    public boolean containsValue(int[] intArr, int value){
        for (int anIntArr : intArr) {
            if (anIntArr == value) {
                return true;
            }
        }
        return false;
    }

    public int[] reverseArray(int[] intArr){
        int[] newArr = new int[intArr.length];
        int count = 0;
        for (int i = intArr.length-1; i >= 0; i--) {
            newArr[count] = intArr[i];
            count++;
        }
        return newArr;
    }

    public Integer countOdds(Integer[] intArr){
        Integer odds = 0;
        for (int i = 0; i < intArr.length; i++) {
            if (intArr[i] % 2 != 0){
                odds++;
            }
        }
        return odds;
    }

    public Integer countEvens(Integer[] intArr){
        Integer evens = 0;
        for (int i = 0; i < intArr.length; i++) {
            if(intArr[i] % 2 == 0){
                evens++;
            }
        }
        return evens;
    }



    public int countOdds(int[] intArr){
        int odds = 0;
        for (int i = 0; i < intArr.length; i++) {
            if (intArr[i] % 2 != 0){
                odds++;
            }
        }
        return odds;
    }

    public int countEvens(int[] intArr){
        int evens = 0;
        for (int i = 0; i < intArr.length; i++) {
            if(intArr[i] % 2 == 0){
                evens++;
            }
        }
        return evens;
    }


    public int[] getOddEvensOfArray(int[] intArr){
        int odds = countOdds(intArr);
        int evens = countEvens(intArr);
        int[] newArr = new int[]{odds, evens};

        return newArr;
    }

    public int findIndexOf(int[] intArr, int value){
        int index = 0;
        for (int i = 0; i <intArr.length ; i++) {
            if(intArr[i] == value){
                index = i;
            }
        }
        return index;
    }

    public Integer[] copyArrayByIterator(Integer[] intArr, Integer[] copyArr){
        Iterator<Integer> list = Arrays.asList(intArr).iterator();
        int c = 0;
        while (list.hasNext()){
            copyArr[c] = list.next();
            c++;
        }
        return copyArr;
    }

    public int[] copyArrayByLoop(int[] intArr, int[] copyArr){
        for (int i = 0; i <intArr.length ; i++) {
            copyArr[i] = intArr[i];
        }
        return copyArr;
    }

    public int[] removeElementFromArray(int[] intArr, int valueToRemove){
        int[] newArr = new int[intArr.length - 1];
        for (int i = 0; i < intArr.length - 1; i++) {
            if(intArr[i] != valueToRemove){
                newArr[i] = intArr[i];
            }
        }
        return newArr;
    }

    public void insertIntoArrayAt(int[] intArr,int value, int index){
        intArr[index] = value;
    }

    public int[] findMaxMinOfArray(int[] intArr){
        int min = 0;
        int max = 0;

        Arrays.sort(intArr);
        min = intArr[0];
        max = intArr[intArr.length-1];
        int[] minMax = new int[]{min, max};
        return minMax;
    }


    public Integer[] removeDupeFromArray(Integer[] arr) {
        Arrays.sort(arr);
        ArrayList<Integer> temp = new ArrayList<>();
        temp.add(arr[0]);

        for (int i = 1; i < arr.length; i++) {
            if(!arr[i -1].equals(arr[i])){
                temp.add(arr[i]);
            }
        }
        Integer[] newArr = new Integer[temp.size()];
        newArr = temp.toArray(new Integer[temp.size()]);

        return newArr;
    }

    public double find2ndLargestValueFromArray(double[] dbArr){
        Arrays.sort(dbArr);
        return dbArr[dbArr.length - 2];
    }

    public ArrayList makeMeAnArrayListFromArray(int[] intArr){
        ArrayList<Integer> list = new ArrayList<>();

        for (int i = 0; i < intArr.length; i++) {
            list.add(intArr[i]);
        }

        return list;
    }

    public Object[] makeMeAnArrayFromArrayList(ArrayList list){

        return list.stream().toArray(Integer::new);
    }

    public boolean check2ArraysForEqual(int[] arr1, int[]arr2){
        return Arrays.equals(arr1, arr2);
    }

    public int averageArrayWithoutMaxMin(int[] arr){
        int sum = 0;
        Arrays.sort(arr);
        for (int i = 1; i < arr.length - 1; i++) {
                sum += arr[i];
        }
        return sum/(arr.length-2);
    }

    public boolean arrayHas65and77(int[] arr){
        ArrayList<Integer> list = new ArrayList<>();
        for (int anArr : arr) {
            list.add(anArr);
        }
        return list.contains(65) && list.contains(77);
    }

    public boolean theTotalofTensIs30(int[] arr){
        int sumOfTens = 0;
        for (int anArr : arr) {
            if (anArr == 10) {
                sumOfTens += anArr;
            }
        }
        return sumOfTens == 30;
    }

    public int[] twoSmallestInArray(int[] arr){
        Arrays.sort(arr);
        return new int[]{arr[0], arr[1]};
    }

    public Integer[] makeMeACopyPlease(Integer[] arr){
        Integer[] newArr = new Integer[arr.length];
        Integer count = 0;
        for (int i = arr.length-1; i >= 0; i--) {
            newArr[count] = arr[i];
            count++;
        }
        return newArr;
    }

    public Integer[] removeLastItemAndCopy(Integer[] arr){
        Integer[] arr1 = new Integer[arr.length-1];
        for (int i = 0; i <arr.length-1; i++) {
            arr1[i] = arr[i];
        }
        return arr1;
    }

    public Integer[] removeFirstItemAndCopy(Integer[] arr){
        Integer[] arr1 = new Integer[arr.length-1];
        int c =0;
        for (int i = 1; i <arr.length; i++) {
            arr1[c] = arr[i];
            c++;
        }
        return arr1;
    }

    public Integer[] insertAtStartAndCopy(Integer[] arr, Integer number){
        Integer[] arr1 = new Integer[arr.length + 1];
        arr1[0] = number;
        int c = 1;
        for (int i = 0; i < arr.length; i++) {
            arr1[c] = arr[i];
            c++;
        }
        return arr1;
    }

    public Integer[] insertAtEndAndCopy(Integer[] arr, Integer number){
        Integer[] newArr = Arrays.copyOf(arr, arr.length+1);
        newArr[arr.length] = number;
        return newArr;
    }

    public Integer[] evensArray(Integer[] arr){
        Integer[] evensArr = new Integer[countEvens(arr)];
        int c = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0){
                evensArr[c] = arr[i];
                c++;
            }
        }
        return evensArr;
    }

    public Integer[] oddsArray(Integer[] arr){
        Integer[] oddsArr = new Integer[countOdds(arr)];
        int c = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 != 0){
                oddsArr[c] = arr[i];
                c++;
            }
        }
        return oddsArr;
    }


    public Integer[] mergeArrays(Integer[] arr1, Integer[] arr2){
        return Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2))
                .toArray(Integer[]::new);
    }

    public Integer[] sortArrayIntoEvensThenOdds(Integer[] arr){
        Integer[] newArr = evensArray(arr);
        Integer[] newArr2 = oddsArray(arr);
        return mergeArrays(newArr, newArr2);
    }



}
