/// Write a rsthon function to identify non-prime numbers.
fn is_not_prime(n: isize) -> bool {
    let mut result = false;
    for i in 2..n {
        if n % i == 0 {
            result = true;
        }
    }
    result
}


/// Write a function to find the n largest integers from a given vector of numbers, returned in descending order.
fn heap_queue_largest(nums: Vec<isize>, n: isize) -> Vec<isize> {
    let mut largest_nums: Vec<isize> = nums;
    largest_nums.sort();
    largest_nums.reverse();
    largest_nums[0..n as usize].to_vec()
}


/// Write a rsthon function to check whether the two numbers differ at one bit position only or not.
fn differ_At_One_Bit_Pos(a: isize, b: isize) -> bool {
    if a == b {
        return false;
    }
    return (a ^ b).count_ones() == 1;
}


/// Write a function to find squares of individual elements in a vector.
fn square_nums(nums: Vec<isize>) -> Vec<isize> {
    nums.iter().map(|x| x * x).collect()
}


/// Write a rsthon function to remove first and last occurrence of a given character from the string.
fn remove_Occ(s: String, ch: String) -> String {
    let mut s = s;
    s = s.replace(ch.as_str(), "");
    s = s.replace(ch.as_str(), "");
    s
}


/// Write a function to sort a given matrix in ascending order according to the sum of its rows.
fn sort_matrix(M: Vec<Vec<isize>>) -> Vec<Vec<isize>> {
    let mut m = M.clone();
    m.sort_by(|a, b| a.iter().sum::<isize>().cmp(&b.iter().sum::<isize>()));
    m
}


/// Write a rsthon function to find the volume of a triangular prism.
fn find_Volume(l: isize, b: isize, h: isize) -> isize {
    (l * b * h) / 2
}


/// Write a function that returns the perimeter of a square given its side length as input.
fn square_perimeter(a: isize) -> isize {
    4 * a
}


/// Write a function to remove characters from the first string which are present in the second string.
fn remove_dirty_chars(string: String, second_string: String) -> String {
	let mut dirty_chars: Vec<char> = second_string.chars().collect();
	let mut result: String = String::new();
	let mut char_count: [u8; 128] = [0; 128];
	for c in dirty_chars.iter() {
		char_count[*c as usize] = 1;
	}

	for c in string.chars() {
		if char_count[c as usize] == 0 {
			result.push(c);
		}
	}

	result
}


/// Write a function to find whether a given vector of integers contains any duplicate element.
fn test_duplicate(arraynums: Vec<isize>) -> bool {
    let nums_set = arraynums.clone().into_iter().collect::<std::collections::HashSet<isize>>();
    arraynums.len() != nums_set.len()
}


/// Write a function to check if the given number is woodball or not.
fn is_woodall(x: isize) -> bool {
    if x % 2 == 0 {
        return false;
    }
    let mut x = x + 1;
    let mut p = 0;
    while x % 2 == 0 {
        x = x / 2;
        p = p + 1;
        if p == x {
            return true;
        }
    }
    false
}


/// Write a rsthon function to find the largest number that can be formed with the given vector of digits.
fn find_Max_Num(arr: Vec<isize>) -> isize {
    let mut arr: Vec<_> = arr.iter().map(|x| *x).collect();
    arr.sort_by(|a, b| b.cmp(a));
    let mut num = 0;
    for i in 0..arr.len() {
        num = num * 10 + arr[i];
    }
    return num;
}


/// Write a rsthon function to check whether the given two integers have opposite sign or not.
fn opposite_Signs(x: isize, y: isize) -> bool {
    (x ^ y) < 0
}


/// Write a function to find the nth octagonal number.
fn is_octagonal(n: isize) -> isize {
	3 * n * n - 2 * n
}


/// Write a rsthon function to find smallest number in a vector.
fn smallest_num(xs: Vec<isize>) -> isize {
    xs.iter().fold(isize::MAX, |a, &b| a.min(b))
}


/// Write a function to find the maximum difference between available pairs in the given tuple vector.
fn max_difference(test_list: Vec<(isize, isize)>) -> isize {
    let mut temp: Vec<isize> = Vec::new();

    for (a, b) in test_list.iter() {
        temp.push((b - a).abs());
    }

    *temp.iter().max().unwrap()
}


/// Write a function to sort a vector of tuples using the second value of each tuple.
fn subject_marks(subjectmarks: Vec<(String, isize)>) -> Vec<(String, isize)> {
    let mut subject_marks = subjectmarks;
    subject_marks.sort_by_key(|k| k.1);
    subject_marks
}


/// Write a rsthon function to count the number of positive numbers in a vector.
fn pos_count(list: Vec<isize>) -> isize {
  let mut pos_count = 0;
  for num in list {
    if num >= 0 {
      pos_count += 1;
    }
  }
  pos_count
}


/// Write a rsthon function to check whether the given vector is monotonic or not.
fn is_Monotonic(A: Vec<isize>) -> bool {
    if A.len() == 1 {
        return true;
    }
    let mut incr = true;
    let mut decr = true;
    for i in 0..A.len() - 1 {
        if A[i] > A[i + 1] {
            incr = false;
        }
        if A[i] < A[i + 1] {
            decr = false;
        }
    }
    (incr || decr)
}


/// Write a function to check whether a vector contains the given subvector or not.
fn is_sublist(l: Vec<isize>, s: Vec<isize>) -> bool {
    if s.is_empty() { return true; }

    for (i, &x) in l.iter().enumerate() {
        if s[0] == x {
            let mut n = 1;
            while n < s.len() && l[i+n] == s[n] {
                n += 1;
            }
            if n == s.len() {
                return true;
            }
        }
    }
    return false;
}


/// Write a function to find whether all the given vectors have equal length or not.
fn get_equal(Input: Vec<Vec<isize>>) -> bool {
    Input.iter().fold(true, |f, tuple| f & (tuple.len() == Input[0].len()))
}


/// Write a rsthon function to check whether the given number can be represented as the difference of two squares or not.
fn dif_Square(n: isize) -> bool {
    n % 4 != 2
}


/// Write a function to check whether it follows the sequence given in the patterns vector.
fn is_samepatterns(colors: Vec<String>, patterns: Vec<String>) -> bool {
    if colors.len() != patterns.len() {
        return false;
    }

    let mut sdict = std::collections::HashMap::new();
    let mut pset: std::collections::HashSet<_> = patterns.iter().collect();
    let mut sset: std::collections::HashSet<_> = colors.iter().collect();

    if pset.len() != sset.len() {
        return false;
    }

    for (i, pattern) in patterns.iter().enumerate() {
        let values = sdict.entry(pattern).or_insert_with(Vec::new);
        values.push(colors[i].clone());
    }

    for values in sdict.values() {
        if values[0] != values[values.len() - 1] {
            return false;
        }
    }

    true
}


/// Write a function to find tuples which have all elements divisible by k from the given vector of tuples.
fn find_tuples(test_list: Vec<(isize, isize, isize)>, K: isize) -> Vec<(isize, isize, isize)> {
    test_list
        .into_iter()
        .filter(|(x, y, z)| x % K == 0 && y % K == 0 && z % K == 0)
        .collect()
}


/// Write a rsthon function to find whether a number is divisible by 11.
fn is_Diff(n: isize) -> bool {
    n % 11 == 0
}


/// Write a rsthon function to check whether the length of the word is odd or not.
fn word_len(s: String) -> bool {
    s.split(' ')
        .any(|word| word.len() % 2 != 0)
}


/// Write a function to find the nth tetrahedral number.
fn tetrahedral_number(n: isize) -> isize {
  (n * (n + 1) * (n + 2)) / 6
}


/// Write a function to find the nth number in the newman conway sequence.
fn sequence(n: isize) -> isize {
    if n == 1 || n == 2 {
        return 1;
    } else {
        return sequence(sequence(n - 1)) + sequence(n - sequence(n - 1));
    }
}


/// Write a function to find nth centered hexagonal number.
fn centered_hexagonal_number(n: isize) -> isize {
    3 * n * (n - 1) + 1
}


use std::collections::HashMap;

/// Write a function to get the frequency of all the elements in a vector, returned as a HashMap.
fn freq_count(list1: Vec<isize>) -> HashMap<isize, isize> {
    let mut freq_count = HashMap::new();
    for i in &list1 {
        *freq_count.entry(*i).or_insert(0) += 1;
    }
    freq_count
}


/// Write a function to find the closest smaller number than n.
fn closest_num(N: isize) -> isize {
    N - 1
}


/// Write a rsthon function to find the length of the longest word.
fn len_log(list1: Vec<String>) -> isize {
    let mut max = 0;
    for i in list1 {
        if i.len() > max {
            max = i.len();
        }
    }
    max as isize
}


/// Write a function to check if a string is present as a substring in a given vector of string values.
fn find_substring(str1: Vec<String>, sub_str: String) -> bool {
    str1.iter().any(|s| s.contains(&sub_str))
}


/// Write a function to check whether the given number is undulating or not.
fn is_undulating(n: isize) -> bool {
    if n > 0 {
        let mut i = 2;
        while i < n.to_string().len() {
            if n.to_string().chars().nth(i) != n.to_string().chars().nth(i - 2) {
                return false;
            }
            i += 1;
        }
        return true;
    }
    false
}


/// Write a function to calculate the value of 'a' to the power 'b'.
fn power(a: isize, b: isize) -> isize {
    if b == 0 {
        1
    } else if a == 0 {
        0
    } else if b == 1 {
        a
    } else {
        a * power(a, b - 1)
    }
}


/// Given a vector of tuples, write a function that returns the first value of the tuple with the smallest second value.
fn index_minimum(test_list: Vec<(String, isize)>) -> String {
    test_list
        .iter()
        .min_by_key(|&(_, value)| value)
        .unwrap()
        .0
        .to_owned()
}


/// Write a rsthon function to find the number of divisors of a given integer.
fn divisor(n: isize) -> isize {
  let mut divs:isize = 0;
  for i in 1..(n+1) {
    if n % i == 0 {
      divs += 1;
    }
  }
  return divs;
}


use std::collections::HashMap;

/// Write a function to find frequency of each element in a flattened vector of vectors, returned in a HashMap.
fn frequency_lists(list1: Vec<Vec<isize>>) -> HashMap<isize, isize> {
    let mut map = HashMap::new();
    for v in list1 {
        for item in v {
            let count = map.entry(item).or_insert(0);
            *count += 1;
        }
    }
    map
}


/// Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.
fn decimal_to_binary(n: isize) -> String {
    let mut binary_str = String::new();
    let mut n = n;
    loop {
        let rem = n % 2;
        binary_str.push_str(&rem.to_string());
        n /= 2;
        if n == 0 {
            break;
        }
    }
    binary_str.chars().rev().collect()
}


/// Write a function to convert a snake case string to camel case string.
fn snake_to_camel(word: String) -> String {
    let mut res = String::new();
    let mut first_char = true;
    for c in word.chars() {
        if c == '_' {
            first_char = true;
        } else {
            let c = if first_char { c.to_uppercase().next().unwrap() } else { c };
            res.push(c);
            first_char = false;
        }
    }
    res
}


/// Write a function to find the Eulerian number a(n, m).
fn eulerian_num(n: isize, m: isize) -> isize {
    if m >= n || n == 0 {
        return 0;
    }
    if m == 0 {
        return 1;
    }
    (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m)
}


/// Write a function to sort each subvector of strings in a given vector of vectors.
fn sort_sublists(input_list: Vec<Vec<String>>) -> Vec<Vec<String>> {
    let mut result = vec![];
    for sub in input_list {
        let mut sub_result = vec![];
        for x in sub {
            sub_result.push(x.to_string());
        }
        sub_result.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()));
        result.push(sub_result);
    }
    return result;
}


/// Write a rsthon function to count true booleans in the given vector.
fn count(lst: Vec<bool>) -> isize {
    lst.iter()
        .filter(|&&b| b == true)
        .count() as isize
}


/// Write a function to check if a string represents an integer or not.
fn check_integer(text: String) -> bool {
    text.trim().is_empty()
        || text.chars().all(|c| c.is_ascii_digit())
}


/// Write a function to convert a given tuple of positive integers into a single integer.
fn tuple_to_int(nums: (isize, isize, isize)) -> isize {
    return (nums.0 * 100) + (nums.1 * 10) + nums.2;
}


/// Write a function to convert a string to a vector of strings split on the space character.
fn string_to_list(string: String) -> Vec<String> {
    return string.split(" ").map(|x| x.to_string()).collect();
}


/// Write a rsthon function to find the element that appears only once in a sorted vector.
fn search(arr: Vec<isize>) -> isize {
    let mut XOR: isize = 0;
    for i in &arr {
        XOR = XOR ^ i;
    }
    return XOR;
}


/// Write a function to find the maximum absolute product between numbers in pairs of tuples within a given vector.
fn max_product_tuple(list1: Vec<(isize, isize)>) -> isize {
    list1.iter().map(|(x, y)| x * y).map(|y| y.abs()).max().unwrap()
}


/// Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.
fn find_length(string: String) -> isize {
	let n = string.len();
	let mut current_sum = 0;
	let mut max_sum = 0;

	for i in 0..n {
		current_sum += if string.as_bytes()[i] == b'0' { 1 } else { -1 };

		if current_sum < 0 {
			current_sum = 0;
		}
		max_sum = max_sum.max(current_sum);
	}

	if max_sum == 0 {
		0
	} else {
		max_sum as isize
	}
}


/// Write a rsthon function to find the sum of common divisors of two given numbers.
fn sum(a: isize, b: isize) -> isize {
    let mut sum: isize = 0;
    for i in 1..a.min(b) {
        if a % i == 0 && b % i == 0 {
            sum += i
        }
    }
    sum
}


/// Write a function to multiply two integers.
fn multiply_int(x: isize, y: isize) -> isize {
    if y < 0 {
        -multiply_int(x, -y)
    } else if y == 0 {
        0
    } else if y == 1 {
        x
    } else {
        x + multiply_int(x, y - 1)
    }
}


/// Write a function to find words that are longer than n characters from a given vector of words.
fn long_words(n: isize, str: String) -> Vec<String> {
    let mut result = Vec::new();
    for word in str.split_whitespace() {
        if word.len() > n as usize {
            result.push(word.to_string());
        }
    }
    result
}


/// Write a function to calculate whether the matrix is a magic square.
fn magic_square_test(my_matrix: Vec<Vec<isize>>) -> bool {
    // First, we get the dimension of the matrix.
    let i_size = my_matrix[0].len();

    // Then we calculate the sum of each row and add it to a list.
    let mut sum_list = vec![];
    for lines in my_matrix.iter() {
        sum_list.push(lines.iter().sum::<isize>());
    }

    // We iterate through the columns of the matrix and add the elements of each column to the list.
    for col in 0..i_size {
        let mut sum_col = 0;
        for row in 0..i_size {
            sum_col += my_matrix[row][col];
        }
        sum_list.push(sum_col);
    }

    // We add the main diagonal to the list.
    let mut sum_main_diag = 0;
    for i in 0..i_size {
        sum_main_diag += my_matrix[i][i];
    }
    sum_list.push(sum_main_diag);

    // We add the anti-diagonal to the list.
    let mut sum_anti_diag = 0;
    for i in 0..i_size {
        sum_anti_diag += my_matrix[i][i_size - 1 - i];
    }
    sum_list.push(sum_anti_diag);

    // We remove the duplicate sums and check whether the list is empty.
    let sum_list_without_duplicates = sum_list.iter().cloned().collect::<std::collections::HashSet<_>>();
    if sum_list_without_duplicates.len() > 1 {
        return false;
    }

    return true;
}


/// Write a function to find the item with maximum frequency in a given vector.
fn max_occurrences(nums: Vec<isize>) -> isize {
    let mut dict = std::collections::HashMap::new();
    for i in nums {
        let count = dict.entry(i).or_insert(0);
        *count += 1;
    }
    let mut max_key = None;
    let mut max_value = 0;
    for (key, value) in dict.iter() {
        if *value > max_value {
            max_key = Some(*key);
            max_value = *value;
        }
    }
    match max_key {
        Some(key) => key,
        None => panic!("No elements in array"),
    }
}


/// Write a function to convert a vector to a string.
fn tup_string(tup1: Vec<String>) -> String {
    let mut str = "".to_string();
    for s in tup1 {
        str = str + &s;
    }
    str
}


/// Write a function to calculate the sum of the negative numbers of a given vector of numbers.
fn sum_negativenum(nums: Vec<isize>) -> isize {
    nums.iter().filter(|&&x| x < 0).sum()
}


/// Write a function to find the nth hexagonal number.
fn hexagonal_num(n: isize) -> isize {
	n * (2 * n - 1)
}


/// Write a rsthon function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
fn is_Sum_Of_Powers_Of_Two(n: isize) -> bool {
    if n % 2 == 1 {
        return false;
    } else {
        return true;
    }
}


/// Write a function to count number items that are identical in the same position of three given vectors.
fn count_samepair(list1: Vec<isize>, list2: Vec<isize>, list3: Vec<isize>) -> isize {
    let mut result = 0;
    for i in 0..list1.len() {
        if list1[i] == list2[i] && list1[i] == list3[i] {
            result += 1;
        }
    }
    result
}


/// Write a rsthon function to find the maximum difference between any two elements in a given vector.
fn max_Abs_Diff(arr: Vec<isize>) -> isize {
    let mut min = arr[0];
    let mut max = arr[0];

    for i in 1..arr.len() {
        min = min.min(arr[i]);
        max = max.max(arr[i]);
    }
    max - min
}


/// Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.
fn find_solution(a: isize, b: isize, n: isize) -> Option<(isize, isize)> {
	let mut i = 0;
	while i * a <= n {
		if (n - (i * a)) % b == 0 {
			return Some((i, (n - (i * a)) / b));
		}
		i += 1;
	}
	None
}


/// Write a function to remove all elements from a given vector present in another vector.
fn remove_elements(list1: Vec<isize>, list2: Vec<isize>) -> Vec<isize> {
    list1.into_iter().filter(|x| !list2.contains(x)).collect()
}


/// Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4)... (until n-x =< 0).
fn sum_series(n: isize) -> isize {
  if n < 1 {
    return 0;
  } else {
    return n + sum_series(n - 2);
  }
}


/// Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive).
fn count_char_position(str1: String) -> isize {
    let mut count_chars = 0;
    let str1 = str1.to_lowercase();
    for (index, c) in str1.chars().enumerate() {
        if (c as u32 - 'a' as u32) as isize == index as isize {
            count_chars += 1
        }
    }
    count_chars
}


/// Write a function that counts the number of pairs of integers in a vector that xor to an even number.
fn find_even_pair(A: Vec<isize>) -> isize {
    A.iter().enumerate()
        .flat_map(|(i, &a)| A.iter().enumerate().skip(i + 1).map(move |(j, &b)| (i, j, a, b)))
        .filter(|&(_, _, a, b)| (a ^ b) % 2 == 0)
        .count() as isize
}


/// Write a function to count the number of occurrences of a number in a given vector.
fn frequency(a: Vec<isize>, x: isize) -> isize {
    let mut count = 0;
    for i in a {
        if i == x {
            count += 1
        }
    }
    count
}


/// Write a function to find the sum of numbers in a vector within a range specified by two indices.
fn sum_range_list(list1: Vec<isize>, m: isize, n: isize) -> isize {
    let mut sum_range = 0;
    for i in m..=n {
        sum_range += list1[i as usize];
    }
    sum_range
}


/// Write a function to find the perimeter of a regular pentagon from the length of its sides.
fn perimeter_pentagon(a: isize) -> isize {
    a * 5
}


/// Write a function to count the number of occurence of the string 'std' in a given string.
fn count_occurance(s: String) -> isize {
    let count: isize = s.match_indices("std").count() as isize;
    return count;
}


/// Write a rsthon function to remove the characters which have odd index values of a given string.
fn odd_values_string(str: String) -> String {
    let mut result = String::new();
    for i in 0..str.len() {
        if i % 2 == 0 {
            result.push_str(&str[i..i + 1]);
        }
    }
    result
}


/// Write a function to find minimum of three numbers.
fn min_of_three(a: isize, b: isize, c: isize) -> isize {
    if (a <= b) && (a <= c) {
        a
    } else if (b <= a) && (b <= c) {
        b
    } else {
        c
    }
}


/// Write a rsthon function to check whether all the bits are unset in the given range or not.
fn all_Bits_Set_In_The_Given_Range(n: isize, l: isize, r: isize) -> bool {
    let mut num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1)) & n;
    if num == 0 {
        return true;
    }
    return false;
}


/// Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.
fn replace_blank(str1: String, char: String) -> String {
    let mut res = String::new();
    for i in str1.chars() {
        if i == ' ' {
            res.push_str(char.as_str());
        } else {
            res.push(i);
        }
    }
    return res;
}


/// Write a function to find the volume of a cube given its side length.
fn volume_cube(l: isize) -> isize {
    l * l * l
}


/// Write a rsthon function to count the number of non-empty substrings of a given string.
fn number_of_substrings(str: String) -> isize {
    let mut str_len = 0;
    let mut res = 0;
    for s in str.chars() {
        str_len += 1;
        res += str_len;
    }
    res
}


/// Write a function to count the total number of characters in a string.
fn count_charac(str1: String) -> isize {
    let mut count = 0;
    for _ in str1.chars() {
        count += 1;
    }
    count
}


/// Write a function to find the length of the longest palindromic subsequence in the given string.
fn lps(str: String) -> isize {
    let n = str.len();
    let mut L = vec![vec![0; n]; n];
    for i in 0..n {
        L[i][i] = 1;
    }
    for cl in 2..=n {
        for i in 0..n-cl+1 {
            let j = i + cl - 1;
            if str.as_bytes()[i] == str.as_bytes()[j] {
                L[i][j] = L[i + 1][j - 1] + 2;
            } else {
                L[i][j] = L[i][j - 1].max(L[i + 1][j]);
            }
        }
    }
    L[0][n - 1]
}


/// Write a function to find the intersection of two vectors.
fn intersection_array(array_nums1: Vec<isize>, array_nums2: Vec<isize>) -> Vec<isize> {
    let mut result = Vec::new();

    for n in array_nums1 {
        if array_nums2.contains(&n) {
            result.push(n);
        }
    }

    result
}


/// Write a rsthon function that takes in a tuple and an element and counts the occcurences of the element in the vector.
fn count_X(tup: Vec<isize>, x: isize) -> isize {
    let mut count = 0;
    for ele in tup {
        if ele == x {
            count += 1;
        }
    }
    count
}


/// Write a function that takes in a vector and an element and inserts the element before each element in the vector, and returns the resulting vector.
fn insert_element(list: Vec<String>, element: String) -> Vec<String> {
    let mut ret = Vec::new();
    for i in list {
        ret.push(element.clone());
        ret.push(i);
    }
    ret
}


/// Write a rsthon function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number.
fn count_Primes_nums(n: isize) -> isize {
    let mut ctr: isize = 0;
    for num in 2..n {
        let mut isPrime = true;
        for i in 2..num {
            if (num % i) == 0 {
                isPrime = false;
                break;
            }
        }
        if isPrime {
            ctr += 1;
        }
    }
    return ctr
}


/// Write a function that takes in two numbers and returns a vector with the second number and then the first number.
fn swap_numbers(a: isize, b: isize) -> Vec<isize> {
    vec![b, a]
}


/// Write a function to maximize the given two vectors.
fn maximize_elements(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {
    let mut res = Vec::new();
    for (a, b) in test_tup1.iter().zip(test_tup2.iter()) {
        let c = a.iter().zip(b.iter()).map(|(&a, &b)| a.max(b)).collect();
        res.push(c);
    }
    res
}


/// Write a function to find the nth newman–shanks–williams prime number.
fn newman_prime(n: isize) -> isize {
    if n == 0 || n == 1 {
        return 1
    }
    2 * newman_prime(n - 1) + newman_prime(n - 2)
}


/// Write a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples.
fn division_elements(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {
    (test_tup1.0 / test_tup2.0, test_tup1.1 / test_tup2.1, test_tup1.2 / test_tup2.2, test_tup1.3 / test_tup2.3)
}


/// Write a function to find the lateral surface area of a cube given its side length.
fn lateralsurface_cube(l: isize) -> isize {
  l * l * 4
}


/// Write a rsthon function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers.
fn square_Sum(n: isize) -> isize {
    return n*(4*n*n-1)/3;
}


/// Write a function to find the n'th star number.
fn find_star_num(n: isize) -> isize {
	6 * n * (n - 1) + 1
}


/// Write a function to find the ascii value of a character.
fn ascii_value(k: String) -> isize {
    let ch = k.chars().nth(0).unwrap();
    ch as isize
}


/// Write a rsthon function to find the sum of even numbers at even positions of a vector.
fn sum_even_and_even_index(arr: Vec<isize>) -> isize {
    let mut sum = 0;
    for i in (0..arr.len()).step_by(2) {
        if arr[i] % 2 == 0 {
            sum += arr[i];
        }
    }
    sum
}


/// Write a rsthon function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power.
fn even_Power_Sum(n: isize) -> isize {
    let mut sum = 0;
    for i in 1..n+1 {
        let j = 2*i;
        sum += j.pow(5)
    }
    sum
}


/// Write a function that takes in a vector of tuples and returns a vector containing the rear element of each tuple.
fn rear_extract(test_list: Vec<(isize, String, isize)>) -> Vec<isize> {
    let res = test_list.iter().map(|x| x.2).collect();
    res
}


/// Write a function that takes in two tuples and subtracts the elements of the first tuple by the elements of the second tuple with the same index.
fn substract_elements(test_tup1: (isize, isize, isize), test_tup2: (isize, isize, isize)) -> (isize, isize, isize) {
    let (a, b, c) = test_tup1;
    let (d, e, f) = test_tup2;
    (a - d, b - e, c - f)
}


/// Write a rsthon function that takes in a positive integer n and finds the sum of even index binomial coefficients.
fn even_binomial_Coeff_Sum(n: isize) -> isize {
    1 << (n - 1)
}


use std::collections::HashMap;

/// Write a function that takes in a HashMap and integer n and filters the HashMap to only include entries with values greater than or equal to n.
fn dict_filter(dict: HashMap<String, isize>, n: isize) -> HashMap<String, isize> {
    dict.into_iter().filter(|(k, v)| *v >= n).collect()
}


/// Write a function to find the nth decagonal number.
fn is_num_decagonal(n: isize) -> isize {
	4 * n * n - 3 * n
}


/// Write a rsthon function to check if the elements of a given vector are unique or not.
fn all_unique(test_list: Vec<isize>) -> bool {
    if test_list.len() > test_list.iter().collect::<std::collections::HashSet<_>>().len() {
        return false;
    }
    return true;
}


/// Write a function to subtract two vectors element-wise.
fn sub_list(nums1: Vec<isize>, nums2: Vec<isize>) -> Vec<isize> {
    nums1
        .iter()
        .zip(nums2.iter())
        .map(|(x, y)| *x - *y)
        .collect::<Vec<isize>>()
}


/// Write a rsthon function takes in an integer and check whether the frequency of each digit in the integer is less than or equal to the digit itself.
fn validate(n: isize) -> bool {
    let mut digit_count = [0; 10];
    let mut temp = n;
    while temp > 0 {
        let digit = (temp % 10) as usize;
        digit_count[digit] += 1;
        temp /= 10;
    }
    digit_count
        .iter()
        .enumerate()
        .all(|(i, &count)| count <= i)
}


/// Write a rsthon function takes in an integer n and returns the sum of squares of first n even natural numbers.
fn square_Sum(n: isize) -> isize {
    return 2*n*(n+1)*(2*n+1)/3
}


/// Write a rsthon function to find quotient of two numbers (rounded down to the nearest integer).
fn find(n: isize, m: isize) -> isize {
    n / m
}


/// Write a function to find the third side of a right angled triangle.
fn otherside_rightangle(w: isize, h: isize) -> f64 {
    let s = (w as f64).powf(2.0) + (h as f64).powf(2.0);
    s.sqrt() as f64
}


/// Write a function to return the sum of all divisors of a number.
fn sum_div(number: isize) -> isize {
    let mut sum = 1;
    for i in 2..number {
        if number % i == 0 {
            sum += i;
        }
    }
    return sum;
}


/// Write a rsthon function to count inversions in a vector.
fn get_Inv_Count(arr: Vec<isize>) -> isize {
    let n = arr.len();
    let mut inv_count = 0;

    for i in 0..n {
        for j in i + 1..n {
            if arr[i] > arr[j] {
                inv_count += 1;
            }
        }
    }
    inv_count
}


/// Write a function to calculate the maximum aggregate from the vector of tuples.
fn max_aggregate(stdata: Vec<(String, isize)>) -> (String, isize) {
    let mut temp = std::collections::HashMap::new();
    for (name, marks) in stdata {
        *temp.entry(name).or_insert(0) += marks;
    }
    temp.into_iter().max_by_key(|x| x.1).unwrap()
}


/// Write a function to return two words from a vector of words starting with letter 'p'.
fn start_withp(words: Vec<String>) -> (String, String) {
    for w in words {
        if w.starts_with("P") {
            let mut m = w.split(' ');
            let w1 = m.next().unwrap();
            let w2 = m.next().unwrap();
            return (w1.to_string(), w2.to_string());
        }
    }
    panic!("No words start with 'P'");
}


/// Write a function to find the specified number of largest products from two given vectors, selecting one factor from each vector.
fn large_product(nums1: Vec<isize>, nums2: Vec<isize>, N: isize) -> Vec<isize> {
    // 1. Create an empty vector to store the products.
    let mut products = Vec::new();
    // 2. Loop through each element in the first vector.
    for &num1 in nums1.iter() {
        // 3. Loop through each element in the second vector.
        for &num2 in nums2.iter() {
            // 4. Append the product of the two elements to the products vector.
            products.push(num1 * num2);
        }
    }
    // 5. Sort the products vector in descending order.
    products.sort_by(|a, b| b.cmp(a));
    // 6. Return a new vector containing the first N products.
    products[..N as usize].to_vec()
}


/// Write a rsthon function to find the maximum of two numbers.
fn maximum(a: isize, b: isize) -> isize {
    if a > b {
        a
    } else {
        b
    }
}


/// Write a function to convert a given string to a vector of characters.
fn string_to_tuple(str1: String) -> Vec<String> {
    let mut result = Vec::new();
    for c in str1.chars() {
        if !c.is_whitespace() {
            result.push(c.to_string());
        }
    }
    result
}


/// Write a rsthon function to find the highest power of 2 that is less than or equal to n.
fn highest_Power_of_2(n: isize) -> isize {
    if n < 1 {
        return 0;
    } else if n == 1 {
        return 1;
    }
    let mut res = 1;
    while res * 2 <= n {
        res *= 2;
    }
    res
}


/// Write a function to find the n'th lucas number.
fn find_lucas(n: isize) -> isize {
    if n == 0 {
        return 2;
    }
    if n == 1 {
        return 1;
    }
    find_lucas(n - 1) + find_lucas(n - 2)
}


/// Write a function to check if given vector contains no duplicates.
fn check_distinct(test_tup: Vec<isize>) -> bool {
    let mut temp: Vec<isize> = test_tup.clone();
    temp.sort();
    let result: bool = temp.windows(2).all(|x| x[0] != x[1]);
    result
}


/// Write a rsthon function to find the first non-repeated character in a given string.
fn first_non_repeating_character(str1: String) -> Option<String> {
    let mut ctr = std::collections::HashMap::new();

    for ch in str1.chars() {
        let count = ctr.entry(ch).or_insert(0);
        *count += 1;
    }

    for ch in str1.chars() {
        if ctr.get(&ch) == Some(&1) {
            return Some(ch.to_string());
        }
    }
    None
}


/// Write a function to check whether the given string starts and ends with the same character or not.
fn check_char(string: String) -> String {
    let string_char: Vec<char> = string.chars().collect();
    let first_char: char = string_char[0];
    let last_char: char = string_char[string_char.len() - 1];
    if first_char == last_char {
        "Valid".to_string()
    } else {
        "Invalid".to_string()
    }
}


/// Write a function to find the median of three numbers.
fn median_numbers(a: isize, b: isize, c: isize) -> f64 {
    if a > b {
        if a < c {
            return a as f64;
        } else if b > c {
            return b as f64;
        } else {
            return c as f64;
        }
    } else {
        if a > c {
            return a as f64;
        } else if b < c {
            return b as f64;
        } else {
            return c as f64;
        }
    }
}


/// Write a function to perform the mathematical bitwise xor operation across the given tuples.
fn bitwise_xor(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {
  (test_tup1.0 ^ test_tup2.0, test_tup1.1 ^ test_tup2.1, test_tup1.2 ^ test_tup2.2, test_tup1.3 ^ test_tup2.3)
}


/// Write a function to perform index wise addition of vector elements in the given two nested vectors.
fn add_nested_tuples(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {
    test_tup1.into_iter()
        .zip(test_tup2.into_iter())
        .map(|(tup1, tup2)| tup1.into_iter().zip(tup2.into_iter()).map(|(a, b)| a + b).collect())
        .collect()
}


/// Write a rsthon function to find the minimum of two numbers.
fn minimum(a: isize, b: isize) -> isize {
    if a <= b {
        a
    } else {
        b
    }
}


/// Write a rsthon function to find whether the parity of a given number is odd.
fn find_Parity(x: isize) -> bool {
    let mut y: isize = x ^ (x >> 1);
    y = y ^ (y >> 2);
    y = y ^ (y >> 4);
    y = y ^ (y >> 8);
    y = y ^ (y >> 16);
    y & 1 == 1
}


/// Write a function to find the minimum product from the pairs of tuples within a given vector.
fn min_product_tuple(list1: Vec<(isize, isize)>) -> isize {
    list1.into_iter().map(|(x, y)| x * y).min().unwrap()
}


/// Write a function to convert the given snake case string to camel case string.
fn snake_to_camel(word: String) -> String {
    let mut result = String::new();
    let mut is_first_char = true;

    for c in word.chars() {
        if c == '_' {
            is_first_char = true;
        } else if is_first_char {
            result.push(c.to_uppercase().next().unwrap());
            is_first_char = false;
        } else {
            result.push(c);
        }
    }

    result
}


/// Write a rsthon function to remove odd numbers from a given vector.
fn remove_odd(l: Vec<isize>) -> Vec<isize> {
    let mut v: Vec<isize> = l;
    v.retain(|&x| x % 2 == 0);
    v
}


/// Write a rsthon function to check whether any value in a sequence exists in a sequence or not.
fn overlapping(list1: Vec<isize>, list2: Vec<isize>) -> bool {
    let c = list1.len();
    let d = list2.len();
    for i in 0..c {
        for j in 0..d {
            if list1[i] == list2[j] {
                return true;
            }
        }
    }
    false
}


/// Write a rsthon function to find a pair with highest product from a given vector of integers.
fn max_Product(arr: Vec<isize>) -> (isize, isize) {
    if arr.len() < 2 {
        panic!("No pairs exists");
    }

    let mut x = arr[0];
    let mut y = arr[1];

    for i in 0..arr.len() {
        for j in i + 1..arr.len() {
            if arr[i] * arr[j] > x * y {
                x = arr[i];
                y = arr[j];
            }
        }
    }

    (x, y)
}


/// Write a rsthon function to find the cube sum of first n even natural numbers.
fn cube_Sum(n: isize) -> isize {
    let mut sum = 0;
    for i in 1..n + 1 {
        sum += (2 * i) * (2 * i) * (2 * i);
    }
    sum
}


/// Write a function to filter odd numbers.
fn filter_oddnumbers(nums: Vec<isize>) -> Vec<isize> {
    nums.into_iter().filter(|&x| x % 2 != 0).collect()
}


/// Write a function to sort the given vector by using shell sort.
fn shell_sort(my_list: Vec<isize>) -> Vec<isize> {
    let mut my_list = my_list;
    let length = my_list.len();

    let mut gap = length / 2;

    while gap > 0 {
        for i in (gap..length).step_by(gap) {
            let current_item = my_list[i];
            let mut j = i;
            while j >= gap && my_list[j - gap] > current_item {
                my_list[j] = my_list[j - gap];
                j -= gap;
            }
            my_list[j] = current_item;
        }
        gap = gap / 2;
    }

    my_list
}


/// Write a function to extract the elementwise and tuples from the given two tuples.
fn and_tuples(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {
    let res = (test_tup1.0 & test_tup2.0, test_tup1.1 & test_tup2.1, test_tup1.2 & test_tup2.2, test_tup1.3 & test_tup2.3);
    res
}


/// Write a function to find the directrix of a parabola.
fn parabola_directrix(a: isize, b: isize, c: isize) -> isize {
    (c - (b * b + 1) * 4 * a) as isize
}


/// Write a function to find the median length of a trapezium.
fn median_trapezium(base1: isize, base2: isize, height: isize) -> f64 {
    let median = 0.5 * (base1 + base2) as f64;
    median
}


/// Write a function to check whether the entered number is greater than the elements of the given vector.
fn check_greater(arr: Vec<isize>, number: isize) -> bool {
    let mut arr = arr;
    arr.sort();
    let index = arr.len() - 1;
    if number > arr[index] {
        return true;
    } else {
        return false;
    }
}


/// Write a rsthon function to find the last digit of a given number.
fn last_Digit(n: isize) -> isize {
    n % 10
}


/// Write a rsthon function to return the negative numbers in a vector.
fn neg_nos(list1: Vec<isize>) -> Vec<isize> {
  let mut result: Vec<isize> = Vec::new();
  for num in list1 {
    if num < 0 {
      result.push(num);
    }
  }
  result
}


/// Write a function to count bidirectional tuple pairs.
fn count_bidirectional(test_list: Vec<(isize, isize)>) -> isize {
    let mut res = 0;
    for idx in 0..test_list.len() {
        for iidx in idx + 1..test_list.len() {
            if test_list[iidx].0 == test_list[idx].1 && test_list[idx].1 == test_list[iidx].0 {
                res += 1;
            }
        }
    }
    res
}


/// Write a function to join a vector of multiple integers into a single integer.
fn multiple_to_single(L: Vec<isize>) -> isize {
    let s = L.into_iter().map(|x| x.to_string()).collect::<String>();
    isize::from_str_radix(&s, 10).unwrap()
}


/// Write a function to find the surface area of a cube of a given size.
fn surfacearea_cube(l: isize) -> isize {
    6 * l * l
}


/// Write a rsthon function to find the largest negative number from the given vector.
fn largest_neg(list1: Vec<isize>) -> isize {
    let mut max = list1[0];
    for x in list1 {
        if x < max {
            max = x
        }
    }
    max
}


/// Write a function to trim each vector by k in the given vectors.
fn trim_tuple(test_list: Vec<Vec<isize>>, K: isize) -> Vec<Vec<isize>> {
    let mut res = vec![];
    for ele in test_list {
        let N = ele.len();
        let ele = ele[K as usize..N as usize - K as usize].to_vec();
        res.push(ele);
    }
    res
}


/// Write a function to perform index wise multiplication of vector elements in the given two vectors.
fn index_multiplication(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {
    test_tup1
        .iter()
        .zip(test_tup2.iter())
        .map(|(a, b)| {
            a.iter()
                .zip(b.iter())
                .map(|(x, y)| x * y)
                .collect()
        })
        .collect()
}


/// Write a function to find cubes of individual elements in a vector.
fn cube_nums(nums: Vec<isize>) -> Vec<isize> {
    nums.iter()
        .map(|&x| x.pow(3))
        .collect()
}


/// Write a function to extract specified size of strings from a given vector of string values.
fn extract_string(str: Vec<String>, l: isize) -> Vec<String> {
    str.into_iter().filter(|e| e.len() == l as usize).collect()
}


/// Write a function to remove all whitespaces from the given string.
fn remove_whitespaces(text1: String) -> String {
    text1.replace(" ", "")
}


/// Write a function that gives loss amount on a sale if the given amount has loss else return 0.
fn loss_amount(actual_cost: isize, sale_amount: isize) -> isize {
    if sale_amount > actual_cost {
        sale_amount - actual_cost
    } else {
        0
    }
}


/// Write a function to check whether the given month number contains 31 days or not.
fn check_monthnumb_number(monthnum2: isize) -> bool {
    match monthnum2 {
        1 | 3 | 5 | 7 | 8 | 10 | 12 => true,
        _ => false
    }
}


/// Write a function to reverse each string in a given vector of string values.
fn reverse_string_list(stringlist: Vec<String>) -> Vec<String> {
    stringlist.into_iter().map(|string| string.chars().rev().collect()).collect()
}


/// Write a function to find the area of a rectangle.
fn rectangle_area(l: isize, b: isize) -> isize {
    l * b
}


/// Write a rsthon function to get the first element of each subvector.
fn Extract(lst: Vec<Vec<isize>>) -> Vec<isize> {
    let mut result = Vec::new();
    for v in lst {
        result.push(v[0]);
    }
    result
}


use std::collections::HashMap;

/// Write a function to check if all values are same in a HashMap.
fn check_value(dict: HashMap<String, isize>, n: isize) -> bool {
    dict.values().all(|&x| x == n)
}


/// Write a function to find the pairwise addition of the neighboring elements of the given tuple.
fn add_pairwise(test_tup: (isize, isize, isize, isize, isize)) -> (isize, isize, isize, isize) {
    let add = (test_tup.0 + test_tup.1, test_tup.1 + test_tup.2, test_tup.2 + test_tup.3, test_tup.3 + test_tup.4);
    return add;
}


/// Write a rsthon function to find the product of the vector multiplication modulo n.
fn find_remainder(arr: Vec<isize>, n: isize) -> isize {
    let mut mul = 1;
    for &i in &arr {
        mul = (mul * (i % n)) % n;
    }
    return mul % n;
}


/// Write a rsthon function to check whether the given vector contains consecutive numbers or not.
fn check_Consecutive(l: Vec<isize>) -> bool {
    let mut s = l.to_owned();
    s.sort();
    for i in 0..s.len() - 1 {
        if s[i] + 1 != s[i + 1] {
            return false;
        }
    }
    true
}


/// Write a function to replace characters in a string.
fn replace_char(str1: String, ch: String, newch: String) -> String {
    let mut str2 = str1.replace(&ch, &newch);
    str2
}


use std::collections::HashMap;

/// Write a function to sort a HashMap by value.
fn sort_counter(dict1: HashMap<String, isize>) -> Vec<(String, isize)> {
    let mut x: Vec<(String, isize)> = vec![];
    for (key, value) in dict1 {
        x.push((key, value));
    }
    x.sort_by(|a, b| b.1.cmp(&a.1));
    x
}


/// Write a rsthon function to find the sum of the largest and smallest value in a given vector.
fn big_sum(nums: Vec<isize>) -> isize {
    let sum = nums[0] + nums[nums.len() - 1];
    sum
}


/// Write a rsthon function to convert the given string to lower case.
fn is_lower(string: String) -> String {
    string.to_lowercase()
}


/// Write a function to remove lowercase substrings from a given string.
fn remove_lowercase(str1: String) -> String {
    let mut new_str = String::new();
    for c in str1.chars() {
        if c.is_ascii_uppercase() {
            new_str.push(c);
        }
    }
    return new_str;
}


/// Write a rsthon function to find the first digit of a given number.
fn first_Digit(n: isize) -> isize {
    let mut n = n;
    while n >= 10 {
        n = n / 10;
    }
    n
}


/// Write a rsthon function which takes a vector of integers and only returns the odd ones.
fn Split(list: Vec<isize>) -> Vec<isize> {
    list.into_iter().filter(|&x| x % 2 != 0).collect()
}


/// Write a rsthon function to find the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers.
fn difference(n: isize) -> isize {
    let mut s = (n * (n + 1)) / 2;
    let res = s * (s - 1);
    return res;
}


/// Write a function to toggle the case of all characters in a string.
fn toggle_string(string: String) -> String {
    string.chars().map(|c| if c.is_uppercase() { c.to_lowercase().to_string() } else { c.to_uppercase().to_string() }).collect::<String>()
}


/// Write a rsthon function to find the sum of the per-digit difference between two integers.
fn digit_distance_nums(n1: isize, n2: isize) -> isize {
    let diff = n1.abs_diff(n2);
    diff.to_string().chars().map(|c| c.to_digit(10).unwrap()).sum::<u32>() as isize
}


/// Write a function to find the sum of the largest contiguous subvector in the given vector.
fn max_sub_array_sum(a: Vec<isize>, size: isize) -> isize {
  let mut max_so_far = 0;
  let mut max_ending_here = 0;

  for i in 0..size {
    max_ending_here = max_ending_here + a[i as usize];

    if max_ending_here < 0 {
      max_ending_here = 0;
    } else if max_so_far < max_ending_here {
      max_so_far = max_ending_here;
    }
  }
  max_so_far
}


/// Write a function to find the union of the elements of two given vectors and output them in sorted order.
fn union_elements(test_tup1: Vec<isize>, test_tup2: Vec<isize>) -> Vec<isize> {
    let mut vec: Vec<isize> = vec![];
    for elem in test_tup1.iter() {
        vec.push(*elem);
    }
    for elem in test_tup2.iter() {
        vec.push(*elem);
    }
    vec.sort();
    vec.dedup();
    vec
}


/// Write a rsthon function to find the length of the longest subvectors.
fn Find_Max_Length(lst: Vec<Vec<isize>>) -> isize {
    lst.iter().fold(0, |max, x| {
        let length = x.len() as isize;
        max.max(length)
    })
}


/// Write a rsthon function which takes a vector of integers and counts the number of possible unordered pairs where both elements are unequal.
fn count_Pairs(arr: Vec<isize>, n: isize) -> isize {
    let mut cnt = 0;
    for i in 0..n as usize {
        for j in i + 1..n as usize {
            if arr[i] != arr[j] {
                cnt += 1;
            }
        }
    }
    cnt
}


/// Write a rsthon function to split a string into characters.
fn split(word: String) -> Vec<String> {
    word.chars().map(|x| x.to_string()).collect()
}


/// Write a function to get the sum of the digits of a non-negative integer.
fn sum_digits(n: isize) -> isize {
    match n {
        0 => 0,
        _ => n % 10 + sum_digits(n / 10),
    }
}


/// Write a function to check whether a specified vector is sorted or not.
fn issort_list(list1: Vec<isize>) -> bool {
    let result = list1
        .iter()
        .zip(list1.iter().skip(1))
        .all(|(a, b)| *a <= *b);
    result
}


/// Write a rsthon function to calculate the product of the unique numbers in a given vector.
fn unique_product(list_data: Vec<isize>) -> isize {
    let mut temp: Vec<isize> = vec![];
    let mut p: isize = 1;
    for i in list_data {
        if !temp.contains(&i) {
            temp.push(i);
        }
    }
    for i in temp {
        p *= i;
    }
    p
}


/// Write a function to find the surface area of a cylinder.
fn surfacearea_cylinder(r: isize, h: isize) -> f64 {
    let surfacearea: f64 = (2.0 * 3.1415 * r as f64 * r as f64) + (2.0 * 3.1415 * r as f64 * h as f64);
    return surfacearea;
}


/// Write a rsthon function to check whether a vector is subvector of another or not.
fn is_Sub_Array(A: Vec<isize>, B: Vec<isize>) -> bool {
    let mut i = 0;
    let mut j = 0;

    while i < A.len() && j < B.len() {
        if A[i] == B[j] {
            i += 1;
            j += 1;
        } else {
            i = i - j + 1;
            j = 0;
        }
    }

    j == B.len()
}


/// Write a rsthon function to find the last digit in factorial of a given number.
fn last_Digit_Factorial(n: isize) -> isize {
    if (n == 0) { return 1; }
    else if (n <= 2) { return n; }
    else if (n == 3) { return 6; }
    else if (n == 4) { return 4; }
    else { return 0; }
}


/// Write a function to interleave 3 vectors of the same length into a single flat vector.
fn interleave_lists(list1: Vec<isize>, list2: Vec<isize>, list3: Vec<isize>) -> Vec<isize> {
    // return [el for pair in zip(list1, list2, list3) for el in pair]
    let mut result: Vec<isize> = Vec::new();
    for i in 0..list1.len() {
        result.push(list1[i]);
        result.push(list2[i]);
        result.push(list3[i]);
    }
    result
}


/// Write a rsthon function to find the surface area of a square rsramid with a given base edge and height.
fn surface_Area(b: isize, s: isize) -> isize {
    2 * b * s + b.pow(2)
}


/// Write a function which returns nth catalan number.
fn catalan_number(num: isize) -> isize {
    if num <= 1 {
        return 1;
    }
    let mut res_num = 0;
    for i in 0..num {
        res_num += catalan_number(i) * catalan_number(num - i - 1);
    }
    res_num
}


/// Write a rsthon function to split a vector at the nth eelment and add the first part to the end.
fn split_Arr(l: Vec<isize>, n: isize) -> Vec<isize> {
    let v1 = &l[0..n as usize];
    let v2 = &l[n as usize..];
    let mut result: Vec<isize> = v2.iter().chain(v1.iter()).cloned().collect();
    return result;
}


/// Write a rsthon function to find the difference between largest and smallest value in a given vector.
fn big_diff(nums: Vec<isize>) -> isize {
    let mut max = 0;
    let mut min = 1000; // set to max possible value

    for n in nums.iter() {
        if *n > max {
            max = *n;
        }
        if *n < min {
            min = *n;
        }
    }

    max - min
}


/// Write a function to find perfect squares between two given numbers.
fn perfect_squares(a: isize, b: isize) -> Vec<isize> {
    let mut res = Vec::new();
    let mut i = a;
    while i <= b {
        let mut j = 1;
        while j * j <= i {
            if j * j == i {
                res.push(i);
            }
            j += 1;
        }
        i += 1;
    }
    res
}


/// Write a function to remove leading zeroes from an ip address.
fn removezero_ip(ip: String) -> String {
    let string = ip.replace(".0", ".");
    string
}


/// Write a function to find the difference of the first even and first odd number of a given vector.
fn diff_even_odd(list1: Vec<isize>) -> isize {
    let first_even = list1.iter().find(|&&x| x % 2 == 0).cloned().unwrap_or(-1);
    let first_odd = list1.iter().find(|&&x| x % 2 != 0).cloned().unwrap_or(-1);

    first_even - first_odd
}


/// Write a function to find kth element from the given two sorted vectors.
fn find_kth(arr1: Vec<isize>, arr2: Vec<isize>, k: isize) -> isize {
    let mut i = 0;
    let mut j = 0;
    let mut d = 0;

    while i < arr1.len() && j < arr2.len() {
        if arr1[i] < arr2[j] {
            d += 1;
            if d == k {
                return arr1[i];
            }
            i += 1;
        } else {
            d += 1;
            if d == k {
                return arr2[j];
            }
            j += 1;
        }
    }

    while i < arr1.len() {
        d += 1;
        if d == k {
            return arr1[i];
        }
        i += 1;
    }

    while j < arr2.len() {
        d += 1;
        if d == k {
            return arr2[j];
        }
        j += 1;
    }

    0
}


/// Write a function to check whether the given number is armstrong or not.
fn armstrong_number(number: isize) -> bool {
    let mut sum = 0;
    let mut times = 0;
    let mut temp = number;
    while temp > 0 {
        times = times + 1;
        temp = temp / 10;
    }
    temp = number;
    while temp > 0 {
        let mut reminder = temp % 10;
        sum = sum + (reminder as isize).pow(times);
        temp = temp / 10;
    }
    number == sum
}


/// Write a function to find sum and average of first n natural numbers.
fn sum_average(number: isize) -> (isize, f64) {
    let mut total = 0;
    for value in 1..number+1 {
        total += value;
    }
    let average = total as f64 / number as f64;
    (total, average)
}


/// Write a rsthon function to check whether the given number is even or not.
fn is_Even(n: isize) -> bool {
    if n ^ 1 == n + 1 {
        true
    } else {
        false
    }
}


/// Write a rsthon function to find the first repeated character in a given string.
fn first_repeated_char(str1: String) -> Option<String> {
    let mut chars = Vec::new();
    for c in str1.chars() {
        if chars.contains(&c) {
            return Some(c.to_string());
        }
        chars.push(c);
    }
    None
}


/// Write a function to reverse words seperated by spaces in a given string.
fn reverse_words(s: String) -> String {
    s.split_whitespace().rev().collect::<Vec<&str>>().join(" ")
}


/// Write a function to check if the given integer is a prime number.
fn prime_num(num: isize) -> bool {
    if num >= 1 {
        for i in 2..num / 2 {
            if num % i == 0 {
                return false;
            }
        }
        true
    } else {
        false
    }
}


/// Write a function to convert degrees to radians.
fn radian_degree(degree: isize) -> f64 {
    let pi: f64 = std::f64::consts::PI;
    return degree as f64 * pi / 180.;
}


/// Write a rsthon function which takes a vector and returns a vector with the same elements, but the k'th element removed.
fn remove_kth_element(list1: Vec<isize>, L: isize) -> Vec<isize> {
    let mut new_vector = vec![];
    for i in 0..list1.len() {
        if i != L as usize - 1 {
            new_vector.push(list1[i]);
        }
    }
    new_vector
}


/// Write a function which given a matrix represented as a vector of vectors returns the max of the n'th column.
fn max_of_nth(test_list: Vec<Vec<isize>>, N: isize) -> isize {
    let res = test_list.iter().map(|x| x[N as usize]).max().unwrap();
    return res;
}


/// Write a function to find the cumulative sum of all the values that are present in the given vector of vectors.
fn cummulative_sum(test_list: Vec<Vec<isize>>) -> isize {
    let result: isize = test_list.iter().fold(0, |acc, x| acc + x.iter().sum::<isize>());
    result
}


/// Write a function which takes two tuples of the same length and performs the element wise modulo.
fn tuple_modulo(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {
    let (x1, y1, z1, w1) = test_tup1;
    let (x2, y2, z2, w2) = test_tup2;
    let res = (x1 % x2, y1 % y2, z1 % z2, w1 % w2);
    res
}


/// Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.
fn min_Jumps(steps: (isize, isize), d: isize) -> f64 {
    let a = steps.0;
    let b = steps.1;
    if d >= b {
        return (d + b - 1) as f64 / b as f64;
    }
    if d == 0 {
        return 0.0;
    }
    if d == a {
        return 1.0;
    }
    2.0
}


/// Write a function to divide two vectors element wise.
fn div_list(nums1: Vec<isize>, nums2: Vec<isize>) -> Vec<f64> {
    nums1
        .into_iter()
        .zip(nums2.into_iter())
        .map(|(num1, num2)| num1 as f64 / num2 as f64)
        .collect()
}


/// Write a function to move all the numbers to the end of the given string.
fn move_num(test_str: String) -> String {
  let mut res = "".to_string();
  let mut dig = "".to_string();
  for ele in test_str.chars() {
    if ele.is_digit(10) {
      dig += &ele.to_string();
    } else {
      res += &ele.to_string();
    }
  }
  res += &dig;
  res
}


/// Write a function to compute the n-th power of each number in a vector.
fn nth_nums(nums: Vec<isize>, n: isize) -> Vec<isize> {
    let mut output = Vec::new();
    for num in nums {
        output.push(num.pow(n as u32));
    }
    output
}


/// Write a rsthon function to convert a given string to uppercase.
fn is_upper(string: String) -> String {
    string.to_uppercase()
}


/// Write a rsthon function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius.
fn triangle_area(r: isize) -> Option<isize> {
    if r < 0 {
        return None;
    }
    Some(r * r)
}


/// Write a rsthon function to find the smallest missing number from a sorted vector of natural numbers.
fn find_First_Missing(array: Vec<isize>) -> isize {
    if (array[0] != 0) {
        return 0
    }
    let mut start = 0;
    let mut end = array.len() - 1;
    while start <= end {
        let mid = (start + end) / 2;
        if (array[mid] != mid as isize) {
            if mid > 0 && array[mid - 1] == (mid - 1) as isize {
                return mid as isize;
            } else {
                end = mid - 1;
            }
        } else {
            start = mid + 1;
        }
    }
    return end as isize + 1;
}


/// Write a rsthon function to find even numbers from a vector of numbers.
fn Split(list: Vec<isize>) -> Vec<isize> {
    let mut ev_li = Vec::new();
    for i in list {
        if i % 2 == 0 {
            ev_li.push(i);
        }
    }
    ev_li
}


/// Write a function to extract all the adjacent coordinates of the given coordinate tuple.
fn get_coordinates(test_tup: (isize, isize)) -> Vec<Vec<isize>> {
    let mut coordinates: Vec<Vec<isize>> = vec![];
    let mut i = test_tup.0 - 1;
    let mut j = test_tup.1 - 1;
    while i <= test_tup.0 + 1 {
        j = test_tup.1 - 1;
        while j <= test_tup.1 + 1 {
            coordinates.push(vec![i, j]);
            j += 1;
        }
        i += 1;
    }
    coordinates
}


/// Write a function to replace whitespaces with an underscore and vice versa in a given string.
fn replace_spaces(text: String) -> String {
  let mut result = String::new();
  for c in text.chars() {
    if c == ' ' {
      result.push('_');
    } else if c == '_' {
      result.push(' ');
    } else {
      result.push(c);
    }
  }
  result
}


/// Write a rsthon function to move all zeroes to the end of the given vector.
fn move_zero(num_list: Vec<isize>) -> Vec<isize> {
    let mut a = Vec::new();
    let mut x = Vec::new();
    for i in 0..num_list.len() {
        if num_list[i] == 0 {
            a.push(0);
        } else {
            x.push(num_list[i]);
        }
    }
    x.extend(a);
    x
}


/// Write a rsthon function to find the sum of xor of all pairs of numbers in the given vector.
fn pair_xor_Sum(arr: Vec<isize>, n: isize) -> isize {
    let mut ans: isize = 0;

    for i in 0..n as usize {
        for j in i + 1..n as usize {
            ans = ans + (arr[i] ^ arr[j]);
        }
    }
    ans
}


/// Write a function to sort the given vector.
fn heap_sort(iterable: Vec<isize>) -> Vec<isize> {
    let mut h = Vec::new();
    for value in iterable {
        h.push(value);
    }
    h.sort();
    h
}


/// Write a function to check whether the given amount has no profit and no loss
fn noprofit_noloss(actual_cost: isize, sale_amount: isize) -> bool {
  sale_amount == actual_cost
}


/// Write a function to sum the length of the names of a given vector of names after removing the names that start with a lowercase letter.
fn sample_nam(sample_names: Vec<String>) -> isize {
    let mut len: isize = 0;
    let names = sample_names
        .iter()
        .filter(|el| el.chars().next().unwrap().is_uppercase())
        .collect::<Vec<&String>>();
    for name in names {
        len += name.len() as isize;
    }
    return len;
}


/// Write a function to find the nth nonagonal number.
fn is_nonagonal(n: isize) -> isize {
    (n * (7 * n - 5)) / 2
}


/// Write a rsthon function to reverse a vector upto a given position.
fn reverse_Array_Upto_K(input: Vec<isize>, k: isize) -> Vec<isize> {
    let mut temp = Vec::new();
    for i in (0..(k as usize)).rev() {
        temp.push(input[i]);
    }
    for i in (k as usize..input.len()) {
        temp.push(input[i]);
    }
    temp
}


/// Given a square matrix of size N*N given as a vector of vectors, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells that starts from the top-left cell move only right or down and ends on bottom right cell. We want to find a path with the maximum average over all existing paths. Average is computed as total cost divided by the number of cells visited in the path.
fn maxAverageOfPath(cost: Vec<Vec<isize>>) -> f64 {
    let n = cost.len();
    let mut dp = vec![vec![0; n]; n];
    dp[0][0] = cost[0][0];
    for i in 1..n {
        dp[i][0] = dp[i - 1][0] + cost[i][0];
    }
    for j in 1..n {
        dp[0][j] = dp[0][j - 1] + cost[0][j];
    }
    for i in 1..n {
        for j in 1..n {
            dp[i][j] = std::cmp::max(dp[i - 1][j], dp[i][j - 1]) + cost[i][j];
        }
    }
    let sum = dp[n - 1][n - 1];
    let num_cells = (2 * n) - 1;
    (sum as f64) / (num_cells as f64)
}


/// The input is defined as two vectors of the same length. Write a function to count indices where the vectors have the same values.
fn count_same_pair(nums1: Vec<isize>, nums2: Vec<isize>) -> isize {
    let mut result = 0;

    for i in 0..nums1.len() {
        if nums1[i] == nums2[i] {
            result += 1;
        }
    }

    result
}


/// Write a function takes as input two vectors [a_1,...,a_n], [b_1,...,b_n] and returns [a_1+b_1,...,a_n+b_n].
fn sum_list(lst1: Vec<isize>, lst2: Vec<isize>) -> Vec<isize> {
    return lst1.iter().zip(lst2.iter()).map(|(x, y)| x + y).collect();
}


/// Write a function to find the lateral surface area of a cone given radius r and the height h.
fn lateralsurface_cone(r: isize, h: isize) -> f64 {
    // Calculate the lateral surface area using the provided formula
    // and return the result
    let l = f64::sqrt(r as f64 * r as f64 + h as f64 * h as f64);
    let LSA = std::f64::consts::PI * r as f64 * l;
    return LSA
}


/// Write a function to replace all occurrences of spaces, commas, or dots with a colon.
fn replace_specialchar(text: String) -> String {
    let mut new_string = String::new();
    for ch in text.chars() {
        match ch {
            ' ' => new_string.push(':'),
            ',' => new_string.push(':'),
            '.' => new_string.push(':'),
            _ => new_string.push(ch),
        }
    }
    new_string
}


/// Write a function to find the index of the first occurrence of a given number in a sorted vector.
fn find_first_occurrence(A: Vec<isize>, x: isize) -> isize {
    let mut left = 0;
    let mut right = A.len() - 1;
    let mut result = -1;
    while left <= right {
        let mid = (left + right) / 2;
        if A[mid] == x {
            result = mid as isize;
            right = mid - 1;
        } else if x < A[mid] {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    result
}


/// Write a function to calculate the geometric sum of n-1. https://www.w3resource.com/rsthon-exercises/data-structures-and-algorithms/rsthon-recursion-exercise-9.php
fn geometric_sum(n: isize) -> f64 {
    if n < 0 {
        0.0
    } else {
        1.0 / (2.0f64.powf(n as f64)) + geometric_sum(n - 1)
    }
}


/// Write a rsthon function to check whether all the characters are same or not.
fn all_Characters_Same(s: String) -> bool {
    let n = s.len();
    for i in 1..n {
        if s.chars().nth(i).unwrap() != s.chars().nth(0).unwrap() {
            return false;
        }
    }
    true
}


/// Write a function to rotate a given vector by specified number of items to the right direction. https://www.geeksforgeeks.org/rsthon-program-right-rotate-vector-n/
fn rotate_right(list: Vec<isize>, m: isize) -> Vec<isize> {
    let mut result = list.clone();
    let m = (list.len() as isize + m) % list.len() as isize;
    result.rotate_right(m as usize);
    result
}


/// Write a function to find the longest common subsequence for the given three string sequence. https://www.geeksforgeeks.org/lcs-longest-common-subsequence-three-strings/
fn lcs_of_three(X: String, Y: String, Z: String) -> isize {
    let m = X.len();
    let n = Y.len();
    let o = Z.len();
    let mut L = vec![vec![vec![0; o + 1]; n + 1]; m + 1];
    for i in 0..m + 1 {
        for j in 0..n + 1 {
            for k in 0..o + 1 {
                if i == 0 || j == 0 || k == 0 {
                    L[i][j][k] = 0;
                } else if X.chars().nth(i - 1) == Y.chars().nth(j - 1) && X.chars().nth(i - 1) == Z.chars().nth(k - 1) {
                    L[i][j][k] = L[i - 1][j - 1][k - 1] + 1;
                } else {
                    L[i][j][k] = std::cmp::max(
                        std::cmp::max(L[i - 1][j][k], L[i][j - 1][k]),
                        L[i][j][k - 1],
                    );
                }
            }
        }
    }
    L[m][n][o]
}


/// Write a function to check if the given vector represents min heap or not. https://www.geeksforgeeks.org/how-to-check-if-a-given-vector-represents-a-binary-heap/
fn check_min_heap(arr: Vec<isize>) -> bool {
    let n = arr.len();
    for i in 0..n / 2 {
        let left_child = 2 * i + 1;
        let right_child = 2 * i + 2;
        if left_child < n && arr[i] > arr[left_child] {
            return false;
        }
        if right_child < n && arr[i] > arr[right_child] {
            return false;
        }
    }
    true
}


/// Write a function to find the nth jacobsthal number. https://www.geeksforgeeks.org/jacobsthal-and-jacobsthal-lucas-numbers/ 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, 2731, ...
fn jacobsthal_num(n: isize) -> isize {
    let mut dp = vec![0; (n + 1) as usize];
    dp[0] = 0;
    dp[1] = 1;
    for i in 2..=n {
        dp[i as usize] = dp[i as usize - 1] + 2 * dp[i as usize - 2];
    }
    dp[n as usize]
}


/// Write a function to find minimum k records from tuple vector. https://www.geeksforgeeks.org/rsthon-find-minimum-k-records-from-tuple-vector/ - in this case a verbatim cors of test cases
fn min_k(test_list: Vec<(String, isize)>, K: isize) -> Vec<(String, isize)> {
    // sort the vector by the second value (the time) in ascending order
    let mut sorted_vec = test_list;
    sorted_vec.sort_by(|a, b| a.1.cmp(&b.1));

    // return the first K records
    sorted_vec[..K as usize].to_vec()
}


/// Write a function to count the pairs of reverse strings in the given string vector. https://www.geeksforgeeks.org/rsthon-program-to-count-the-pairs-of-reverse-strings/
fn count_reverse_pairs(test_list: Vec<String>) -> isize {
    let mut res = 0;
    for i in 0..test_list.len() {
        for j in i..test_list.len() {
            if test_list[j] == test_list[i].chars().rev().collect::<String>() {
                res += 1;
            }
        }
    }
    res
}


/// Write a rsthon function to check whether a vector of numbers contains only one distinct element or not.
fn unique_Element(arr: Vec<isize>) -> bool {
    let s = arr.iter().collect::<std::collections::HashSet<_>>();
    if (s.len() == 1) {
        return true;
    } else {
        return false;
    }
}


/// Write a function to check whether the given month number contains 30 days or not. Months are given as number from 1 to 12.
fn check_monthnumber_number(monthnum3: isize) -> bool {
    if monthnum3 == 4 || monthnum3 == 6 || monthnum3 == 9 || monthnum3 == 11 {
        true
    } else {
        false
    }
}


/// Write a rsthon function to count number of digits in a given string.
fn number_ctr(str: String) -> isize {
    let mut ctr = 0;
    for i in str.chars() {
        if i.is_ascii_digit() {
            ctr += 1;
        }
    }
    ctr
}


/// Write a function to return a vector of all pairs of consecutive items in a given vector.
fn pair_wise(l1: Vec<isize>) -> Vec<(isize, isize)> {
    let mut temp = vec![];

    for i in 0..l1.len() - 1 {
        let current_element = l1[i];
        let next_element = l1[i + 1];
        temp.push((current_element, next_element));
    }

    temp
}


/// Write a rsthon function to count the number of pairs whose sum is equal to ‘sum’. The funtion gets as input a vector of numbers and the sum,
fn get_pairs_count(arr: Vec<isize>, sum: isize) -> isize {
    let mut count = 0;
    for i in 0..arr.len() {
        for j in i + 1..arr.len() {
            if arr[i] + arr[j] == sum {
                count += 1;
            }
        }
    }
    count
}


/// Write a rsthon function to find the sum of fourth power of first n odd natural numbers.
fn odd_num_sum(n: isize) -> isize {
    let mut sm: isize = 0;
    for i in 1..=n {
        let j: isize = (2 * i - 1);
        sm = sm + (j * j * j * j);
    }
    sm
}


/// Write a function to check if the given expression is balanced or not. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
fn check_expression(exp: String) -> bool {
    let mut stack = Vec::new();
    for ch in exp.chars() {
        match ch {
            '(' | '{' | '[' => stack.push(ch),
            ')' | '}' | ']' => {
                if stack.is_empty() {
                    return false;
                }
                let top = stack.pop().unwrap();
                if (top == '(' && ch != ')') || (top == '{' && ch != '}') || (top == '[' && ch != ']') {
                    return false;
                }
            }
            _ => panic!("Unexpected character {}", ch),
        }
    }
    stack.is_empty()
}


/// Write a function to remove all the words with k length in the given string.
fn remove_length(test_str: String, K: isize) -> String {
    let temp: Vec<&str> = test_str.split(' ').collect();
    let res: Vec<&str> = temp.into_iter().filter(|&w| w.len() != K as usize).collect();
    res.join(" ")
}


/// Write a function to count those characters which have vowels as their neighbors in the given string.
fn count_vowels(test_str: String) -> isize {
    let mut res: isize = 0;
    let vow_list: Vec<char> = ['a', 'e', 'i', 'o', 'u'].iter().map(|&x| x).collect();
    for i in 1..test_str.len() - 1 {
        if !vow_list.contains(&test_str.chars().nth(i).unwrap())
            && (vow_list.contains(&test_str.chars().nth(i - 1).unwrap())
                || vow_list.contains(&test_str.chars().nth(i + 1).unwrap()))
        {
            res += 1;
        }
    }
    if !vow_list.contains(&test_str.chars().nth(0).unwrap())
        && test_str.chars().nth(1).unwrap() == 'a' || test_str.chars().nth(1).unwrap() == 'e'
            || test_str.chars().nth(1).unwrap() == 'i'
            || test_str.chars().nth(1).unwrap() == 'o'
            || test_str.chars().nth(1).unwrap() == 'u'
    {
        res += 1;
    }
    if !vow_list.contains(&test_str.chars().nth(test_str.len() - 1).unwrap())
        && test_str.chars().nth(test_str.len() - 2).unwrap() == 'a'
            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'e'
            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'i'
            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'o'
            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'u'
    {
        res += 1;
    }
    res
}


/// Write a rsthon function to find the sum of non-repeated elements in a given vector.
fn find_sum(arr: Vec<isize>) -> isize {
    let mut arr = arr.clone();
    arr.sort();
    let mut sum = arr[0];
    for i in 0..arr.len()-1 {
        if arr[i] != arr[i+1] {
            sum += arr[i+1];
        }
    }
    sum
}


/// Write a rsthon function to check whether the count of divisors is even. https://www.w3resource.com/rsthon-exercises/basic/rsthon-basic-1-exercise-24.php
fn count_divisors(n: isize) -> bool {
    let mut count = 0;
    for i in 1..=((n as f32).sqrt() as isize) + 2 {
        if n % i == 0 {
            if n / i == i {
                count = count + 1
            } else {
                count = count + 2
            }
        }
    }
    count % 2 == 0
}


/// Write a function to find the product of first even and odd number of a given vector.
fn mul_even_odd(list1: Vec<isize>) -> isize {
    match (list1.iter().filter(|&&x| x % 2 == 0).next(), list1.iter().filter(|&&x| x % 2 != 0).next()) {
        (Some(x), Some(y)) => x * y,
        _ => -1,
    }
}


/// Write a function to locate the right insertion point for a specified value in sorted order.
fn right_insertion(a: Vec<isize>, x: isize) -> isize {
    let index = a.binary_search(&x).unwrap_or_else(|x| x);
    index as isize
}


/// Write a rsthon function to check whether every even index contains even numbers of a given vector.
fn even_position(nums: Vec<isize>) -> bool {
    // Loop through the vector and check if every even index contains even numbers.
    for i in 0..nums.len() {
        if i % 2 == 0 && nums[i] % 2 != 0 {
            return false;
        }
    }

    true
}


/// Write a rsthon function to count the number of vectors in a given number of vectors.
fn count_list(input_list: Vec<Vec<isize>>) -> isize {
    input_list.len() as isize
}


use std::collections::HashMap;

/// Write function to find the sum of all items in the given HashMap.
fn return_sum(dict: HashMap<String, isize>) -> isize {
    let mut sum = 0;
    for v in dict.values() {
        sum += v;
    }
    sum
}


/// Write a rsthon function to find the sum of a vector.
fn _sum(arr: Vec<isize>) -> isize {
    let mut sum = 0;
    for i in arr {
        sum += i;
    }
    sum
}


/// Write a function to that rotate left bits by d bits a given number. We assume that the number is 32 bit.
fn left_rotate(n: isize, d: isize) -> isize {
    // let bits = 32 as isize;
    (n << d) | (n >> (32 - d))
}


/// Write a function to remove all whitespaces from a string.
fn remove_all_spaces(text: String) -> String {
    text.replace(" ", "")
}


/// Write a rsthon function to count the number of equal numbers from three given integers.
fn test_three_equal(x: isize, y: isize, z: isize) -> isize {
    match [x, y, z].iter().collect::<std::collections::HashSet<_>>().len() {
        3 => 0,
        2 => 4 - 2,
        1 => 4 - 1,
        _ => panic!("unexpected number of numbers")
    }
}


/// Write a rsthon function to count the number of rotations required to generate a sorted vector. https://www.geeksforgeeks.org/count-of-rotations-required-to-generate-a-sorted-vector/
fn count_rotation(arr: Vec<isize>) -> isize {
    // loop over the vector
    for i in 1..arr.len() {
        // if arr[i] < arr[i - 1] then return i
        if arr[i] < arr[i - 1] {
            return i as isize;
        }
    }
    // if no rotations then return 0
    return 0;
}


/// Write a function to check whether the given number is a perfect square or not. https://www.geeksforgeeks.org/check-if-given-number-is-perfect-square-in-cpp/
fn is_perfect_square(n: isize) -> bool {
    let mut i = 1;
    while i * i <= n {
        if n % i == 0 && n / i == i {
            return true;
        }
        i += 1;
    }
    false
}


/// Write a function to check whether the product of numbers in a vector is even or not.
fn is_product_even(arr: Vec<isize>) -> bool {
    for i in arr {
        if i % 2 == 0 {
            return true;
        }
    }
    false
}


/// Write a function that returns the vector in a vector of vectors whose sum of elements is the highest.
fn max_sum_list(lists: Vec<Vec<isize>>) -> Vec<isize> {
    let mut max_sum_vec = vec![];
    let mut max_sum = 0;

    for v in lists.iter() {
        let sum: isize = v.iter().sum();
        if sum > max_sum {
            max_sum = sum;
            max_sum_vec = v.clone();
        }
    }

    max_sum_vec
}


/// Write a function to find maximum run of uppercase characters in the given string.
fn max_run_uppercase(test_str: String) -> isize {
    let mut cnt = 0;
    let mut res = 0;
    for c in test_str.chars() {
        if c.is_uppercase() {
            cnt += 1;
        } else {
            res = cnt;
            cnt = 0;
        }
    }
    if test_str.chars().last().unwrap().is_uppercase() {
        res = cnt;
    }
    res as isize
}


/// Write a rsthon function to find the first odd number in a given vector of numbers.
fn first_odd(nums: Vec<isize>) -> isize {
    match nums.iter().find(|&&el| el % 2 != 0) {
        Some(x) => *x,
        None => -1,
    }
}


/// Write a function to check if the given tuples contain the k or not.
fn check_K(test_tup: Vec<isize>, K: isize) -> bool {
    test_tup.contains(&K)
}


/// Write a function to check if each element of second tuple is smaller than its corresponding element in the first tuple.
fn check_smaller(test_tup1: (isize, isize, isize), test_tup2: (isize, isize, isize)) -> bool {
  test_tup1.0 > test_tup2.0 && test_tup1.1 > test_tup2.1 && test_tup1.2 > test_tup2.2
}