R = 3
C = 3
def min_cost(cost, m, n):
	tc = [[0 for x in range(C)] for x in range(R)]
	tc[0][0] = cost[0][0]
	for i in range(1, m+1):
		tc[i][0] = tc[i-1][0] + cost[i][0]
	for j in range(1, n+1):
		tc[0][j] = tc[0][j-1] + cost[0][j]
	for i in range(1, m+1):
		for j in range(1, n+1):
			tc[i][j] = min(tc[i-1][j-1], tc[i-1][j], tc[i][j-1]) + cost[i][j]
	return tc[m][n]


def similar_elements(test_tup1, test_tup2):
  res = tuple(set(test_tup1) & set(test_tup2))
  return (res)


import math
def is_not_prime(n):
    result = False
    for i in range(2,int(math.sqrt(n)) + 1):
        if n % i == 0:
            result = True
    return result


import heapq as hq
def heap_queue_largest(nums,n):
  largest_nums = hq.nlargest(n, nums)
  return largest_nums


def count_ways(n):
	A = [0] * (n + 1)
	B = [0] * (n + 1)
	A[0] = 1
	A[1] = 0
	B[0] = 0
	B[1] = 1
	for i in range(2, n+1):
		A[i] = A[i - 2] + 2 * B[i - 1]
		B[i] = A[i - 1] + B[i - 2]
	return A[n]


def is_Power_Of_Two (x):
    return x and (not(x & (x - 1)))
def differ_At_One_Bit_Pos(a,b):
    return is_Power_Of_Two(a ^ b)


import re
def find_char_long(text):
  return (re.findall(r"\b\w{4,}\b", text))


def square_nums(nums):
 square_nums = list(map(lambda x: x ** 2, nums))
 return square_nums


def find_Rotations(str):
    tmp = str + str
    n = len(str)
    for i in range(1,n + 1):
        substring = tmp[i: i+n]
        if (str == substring):
            return i
    return n


import heapq
def small_nnum(list1,n):
  smallest=heapq.nsmallest(n,list1)
  return smallest


def remove_Occ(s,ch):
    for i in range(len(s)):
        if (s[i] == ch):
            s = s[0 : i] + s[i + 1:]
            break
    for i in range(len(s) - 1,-1,-1):
        if (s[i] == ch):
            s = s[0 : i] + s[i + 1:]
            break
    return s


def sort_matrix(M):
    result = sorted(M, key=sum)
    return result


from collections import Counter
def count_common(words):
  word_counts = Counter(words)
  top_four = word_counts.most_common(4)
  return (top_four)


def find_Volume(l,b,h) :
    return ((l * b * h) / 2)


import re
def split_lowerstring(text):
 return (re.findall('[a-z][^a-z]*', text))


import re
def text_lowercase_underscore(text):
        patterns = '^[a-z]+_[a-z]+$'
        if re.search(patterns,  text):
                return 'Found a match!'
        else:
                return('Not matched!')


def square_perimeter(a):
  perimeter=4*a
  return perimeter


NO_OF_CHARS = 256
def str_to_list(string):
	temp = []
	for x in string:
		temp.append(x)
	return temp
def lst_to_string(List):
	return ''.join(List)
def get_char_count_array(string):
	count = [0] * NO_OF_CHARS
	for i in string:
		count[ord(i)] += 1
	return count
def remove_dirty_chars(string, second_string):
	count = get_char_count_array(second_string)
	ip_ind = 0
	res_ind = 0
	temp = ''
	str_list = str_to_list(string)
	while ip_ind != len(str_list):
		temp = str_list[ip_ind]
		if count[ord(temp)] == 0:
			str_list[res_ind] = str_list[ip_ind]
			res_ind += 1
		ip_ind+=1
	return lst_to_string(str_list[0:res_ind])


def test_duplicate(arraynums):
    nums_set = set(arraynums)
    return len(arraynums) != len(nums_set)


def is_woodall(x):
	if (x % 2 == 0):
		return False
	if (x == 1):
		return True
	x = x + 1
	p = 0
	while (x % 2 == 0):
		x = x/2
		p = p + 1
		if (p == x):
			return True
	return False


def multiples_of_num(m,n):
    multiples_of_num= list(range(n,(m+1)*n, n))
    return list(multiples_of_num)


def find_first_duplicate(nums):
    num_set = set()
    no_duplicate = -1

    for i in range(len(nums)):

        if nums[i] in num_set:
            return nums[i]
        else:
            num_set.add(nums[i])

    return no_duplicate


def maximum_Sum(list1):
    maxi = -100000
    for x in list1:
        sum = 0
        for y in x:
            sum+= y
        maxi = max(sum,maxi)
    return maxi


def binary_to_decimal(binary):
    binary1 = binary
    decimal, i, n = 0, 0, 0
    while(binary != 0):
        dec = binary % 10
        decimal = decimal + dec * pow(2, i)
        binary = binary//10
        i += 1
    return (decimal)


def find_Product(arr,n):
    arr.sort()
    prod = 1
    for i in range(0,n,1):
        if (arr[i - 1] != arr[i]):
            prod = prod * arr[i]
    return prod;


def check_k_elements(test_list, K):
  res = True
  for tup in test_list:
    for ele in tup:
      if ele != K:
        res = False
  return (res)


import re
def remove(list):
    pattern = '[0-9]'
    list = [re.sub(pattern, '', i) for i in list]
    return list


def binomial_Coeff(n,k):
    if k > n :
       return 0
    if k==0 or k ==n :
        return 1
    return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k)


def get_Odd_Occurrence(arr,arr_size):
    for i in range(0,arr_size):
        count = 0
        for j in range(0,arr_size):
            if arr[i] == arr[j]:
                count+=1
        if (count % 2 != 0):
            return arr[i]
    return -1


def check_Equality(s):
    return (ord(s[0]) == ord(s[len(s) - 1]));
def count_Substring_With_Equal_Ends(s):
    result = 0;
    n = len(s);
    for i in range(n):
        for j in range(1,n-i+1):
            if (check_Equality(s[i:i+j])):
                result+=1;
    return result;


def func(nums, k):
    import collections
    d = collections.defaultdict(int)
    for row in nums:
        for i in row:
            d[i] += 1
    temp = []
    import heapq
    for key, v in d.items():
        if len(temp) < k:
            temp.append((v, key))
            if len(temp) == k:
                heapq.heapify(temp)
        else:
            if v > temp[0][0]:
                heapq.heappop(temp)
                heapq.heappush(temp, (v, key))
    result = []
    while temp:
        v, key = heapq.heappop(temp)
        result.append(key)
    return result


import math
def max_Prime_Factors (n):
    maxPrime = -1
    while n%2 == 0:
        maxPrime = 2
        n >>= 1
    for i in range(3,int(math.sqrt(n))+1,2):
        while n % i == 0:
            maxPrime = i
            n = n / i
    if n > 2:
        maxPrime = n
    return int(maxPrime)


def decimal_To_Binary(N):
    B_Number = 0
    cnt = 0
    while (N != 0):
        rem = N % 2
        c = pow(10,cnt)
        B_Number += rem*c
        N //= 2
        cnt += 1
    return B_Number


def find_missing(ar,N):
    l = 0
    r = N - 1
    while (l <= r):
        mid = (l + r) / 2
        mid= int (mid)
        if (ar[mid] != mid + 1 and ar[mid - 1] == mid):
            return (mid + 1)
        elif (ar[mid] != mid + 1):
            r = mid - 1
        else:
            l = mid + 1
    return (-1)


def find_rect_num(n):
  return n*(n + 1)


def find_Nth_Digit(p,q,N) :
    while (N > 0) :
        N -= 1;
        p *= 10;
        res = p // q;
        p %= q;
    return res;


def sort_mixed_list(mixed_list):
    int_part = sorted([i for i in mixed_list if type(i) is int])
    str_part = sorted([i for i in mixed_list if type(i) is str])
    return int_part + str_part


def div_even_odd(list1):
    first_even = next((el for el in list1 if el%2==0),-1)
    first_odd = next((el for el in list1 if el%2!=0),-1)
    return (first_even/first_odd)


import heapq
from collections import Counter
def rearange_string(S):
    ctr = Counter(S)
    heap = [(-value, key) for key, value in ctr.items()]
    heapq.heapify(heap)
    if (-heap[0][0]) * 2 > len(S) + 1:
        return ""
    ans = []
    while len(heap) >= 2:
        nct1, char1 = heapq.heappop(heap)
        nct2, char2 = heapq.heappop(heap)
        ans.extend([char1, char2])
        if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1))
        if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2))
    return "".join(ans) + (heap[0][1] if heap else "")


from collections import Counter
from itertools import chain
def freq_element(nums):
  result = Counter(chain.from_iterable(nums))
  return result


def filter_evennumbers(nums):
 even_nums = list(filter(lambda x: x%2 == 0, nums))
 return even_nums


def find_Sum(arr,n):
    return sum([x for x in arr if arr.count(x) > 1])


import re
def text_match(text):
  patterns = '^[a-z]+_[a-z]+$'
  if re.search(patterns,  text):
    return ('Found a match!')
  else:
    return ('Not matched!')


import re
def text_match_string(text):
        patterns = '^\w+'
        if re.search(patterns,  text):
                return 'Found a match!'
        else:
                return 'Not matched!'


def find_gcd(x, y):
	while(y):
		x, y = y, x % y
	return x
def get_gcd(l):
  num1 = l[0]
  num2 = l[1]
  gcd = find_gcd(num1, num2)
  for i in range(2, len(l)):
    gcd = find_gcd(gcd, l[i])
  return gcd


def test_distinct(data):
  if len(data) == len(set(data)):
    return True
  else:
    return False;


def compute_Last_Digit(A,B):
    variable = 1
    if (A == B):
        return 1
    elif ((B - A) >= 5):
        return 0
    else:
        for i in range(A + 1,B + 1):
            variable = (variable * (i % 10)) % 10
        return variable % 10


def odd_bit_set_number(n):
    count = 0;res = 0;temp = n
    while temp > 0:
        if count % 2 == 0:
            res |= (1 << count)
        count += 1
        temp >>= 1
    return (n | res)


def specified_element(nums, N):
    result = [i[N] for i in nums]
    return result


def min_length_list(input_list):
    min_length = min(len(x) for x in input_list )
    min_list = min(input_list, key = lambda i: len(i))
    return(min_length, min_list)


def check_equilateral(x,y,z):
  if x == y == z:
	   return True
  else:
     return False


def parallelogram_area(b,h):
  area=b*h
  return area


def check_Equality(str):
  if (str[0] == str[-1]):
    return ("Equal")
  else:
    return ("Not Equal")


def counting_sort(my_list):
    max_value = 0
    for i in range(len(my_list)):
        if my_list[i] > max_value:
            max_value = my_list[i]
    buckets = [0] * (max_value + 1)
    for i in my_list:
        buckets[i] += 1
    i = 0
    for j in range(max_value + 1):
         for a in range(buckets[j]):
             my_list[i] = j
             i += 1
    return my_list


import math
def tn_gp(a,n,r):
  tn = a * (math.pow(r, n - 1))
  return tn


def rev(num):
    rev_num = 0
    while (num > 0):
        rev_num = (rev_num * 10 + num % 10)
        num = num // 10
    return rev_num
def check(n):
    return (2 * rev(n) == n + 1)


def find_Max_Num(arr,n) :
    arr.sort(reverse = True)
    num = arr[0]
    for i in range(1,n) :
        num = num * 10 + arr[i]
    return num


def opposite_Signs(x,y):
    return ((x ^ y) < 0);


def is_octagonal(n):
	return 3 * n * n - 2 * n


def max_len_sub( arr, n):
	mls=[]
	max = 0
	for i in range(n):
		mls.append(1)
	for i in range(n):
		for j in range(i):
			if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1):
				mls[i] = mls[j] + 1
	for i in range(n):
		if (max < mls[i]):
			max = mls[i]
	return max


from collections import defaultdict
def count_Substrings(s,n):
    count,sum = 0,0
    mp = defaultdict(lambda : 0)
    mp[0] += 1
    for i in range(n):
        sum += ord(s[i]) - ord('0')
        count += mp[sum - (i + 1)]
        mp[sum - (i + 1)] += 1
    return count


def smallest_num(xs):
  return min(xs)


def max_difference(test_list):
  temp = [abs(b - a) for a, b in test_list]
  res = max(temp)
  return (res)


def subject_marks(subjectmarks):
#subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])
 subjectmarks.sort(key = lambda x: x[1])
 return subjectmarks


def recursive_list_sum(data_list):
	total = 0
	for element in data_list:
		if type(element) == type([]):
			total = total + recursive_list_sum(element)
		else:
			total = total + element
	return total


def pos_count(list):
  pos_count= 0
  for num in list:
    if num >= 0:
      pos_count += 1
  return pos_count


def bell_number(n):
    bell = [[0 for i in range(n+1)] for j in range(n+1)]
    bell[0][0] = 1
    for i in range(1, n+1):
        bell[i][0] = bell[i-1][i-1]
        for j in range(1, i+1):
            bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
    return bell[n][0]


def is_Monotonic(A):
    return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or
            all(A[i] >= A[i + 1] for i in range(len(A) - 1)))


def is_sublist(l, s):
	sub_set = False
	if s == []:
		sub_set = True
	elif s == l:
		sub_set = True
	elif len(s) > len(l):
		sub_set = False
	else:
		for i in range(len(l)):
			if l[i] == s[0]:
				n = 1
				while (n < len(s)) and (l[i+n] == s[n]):
					n += 1
				if n == len(s):
					sub_set = True
	return sub_set


def find_equal_tuple(Input, k):
  flag = 1
  for tuple in Input:
    if len(tuple) != k:
      flag = 0
      break
  return flag
def get_equal(Input, k):
  if find_equal_tuple(Input, k) == 1:
    return ("All tuples have same length")
  else:
    return ("All tuples do not have same length")


def comb_sort(nums):
    shrink_fact = 1.3
    gaps = len(nums)
    swapped = True
    i = 0
    while gaps > 1 or swapped:
        gaps = int(float(gaps) / shrink_fact)
        swapped = False
        i = 0
        while gaps + i < len(nums):
            if nums[i] > nums[i+gaps]:
                nums[i], nums[i+gaps] = nums[i+gaps], nums[i]
                swapped = True
            i += 1
    return nums


def dif_Square(n):
    if (n % 4 != 2):
        return True
    return False


import re
def multiple_split(text):
  return (re.split('; |, |\*|\n',text))


def is_samepatterns(colors, patterns):
    if len(colors) != len(patterns):
        return False
    sdict = {}
    pset = set()
    sset = set()
    for i in range(len(patterns)):
        pset.add(patterns[i])
        sset.add(colors[i])
        if patterns[i] not in sdict.keys():
            sdict[patterns[i]] = []

        keys = sdict[patterns[i]]
        keys.append(colors[i])
        sdict[patterns[i]] = keys

    if len(pset) != len(sset):
        return False

    for values in sdict.values():

        for i in range(len(values) - 1):
            if values[i] != values[i+1]:
                return False

    return True


def find_tuples(test_list, K):
  res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)]
  return (str(res))


def count_Squares(m,n):
    if(n < m):
        temp = m
        m = n
        n = temp
    return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))


def is_Diff(n):
    return (n % 11 == 0)


def count_With_Odd_SetBits(n):
    if (n % 2 != 0):
        return (n + 1) / 2
    count = bin(n).count('1')
    ans = n / 2
    if (count % 2 != 0):
        ans += 1
    return ans


def word_len(s):
    s = s.split(' ')
    for word in s:
        if len(word)%2!=0:
            return True
        else:
          return False


def tetrahedral_number(n):
	return (n * (n + 1) * (n + 2)) / 6


def zip_tuples(test_tup1, test_tup2):
  res = []
  for i, j in enumerate(test_tup1):
    res.append((j, test_tup2[i % len(test_tup2)]))
  return (res)


import math
def volume_sphere(r):
  volume=(4/3)*math.pi*r*r*r
  return volume


def get_Char(strr):
    summ = 0
    for i in range(len(strr)):
        summ += (ord(strr[i]) - ord('a') + 1)
    if (summ % 26 == 0):
        return ord('z')
    else:
        summ = summ % 26
        return chr(ord('a') + summ - 1)


def sequence(n):
	if n == 1 or n == 2:
		return 1
	else:
		return sequence(sequence(n-1)) + sequence(n-sequence(n-1))


import math
def surfacearea_sphere(r):
  surfacearea=4*math.pi*r*r
  return surfacearea


def centered_hexagonal_number(n):
  return 3 * n * (n - 1) + 1


import collections as ct
def merge_dictionaries_three(dict1,dict2, dict3):
    merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3))
    return merged_dict


import collections
def freq_count(list1):
  freq_count= collections.Counter(list1)
  return freq_count


def closest_num(N):
  return (N - 1)


def len_log(list1):
    max=len(list1[0])
    for i in list1:
        if len(i)>max:
            max=len(i)
    return max


def find_substring(str1, sub_str):
   if any(sub_str in s for s in str1):
       return True
   return False


def is_undulating(n):
	if (len(n) <= 2):
		return False
	for i in range(2, len(n)):
		if (n[i - 2] != n[i]):
			return False
	return True


def power(a,b):
	if b==0:
		return 1
	elif a==0:
		return 0
	elif b==1:
		return a
	else:
		return a*power(a,b-1)


from operator import itemgetter
def index_minimum(test_list):
  res = min(test_list, key = itemgetter(1))[0]
  return (res)


def Find_Min_Length(lst):
    minLength = min(len(x) for x in lst )
    return minLength


def divisor(n):
  for i in range(n):
    x = len([i for i in range(1,n+1) if not n % i])
  return x


def frequency_lists(list1):
    list1 = [item for sublist in list1 for item in sublist]
    dic_data = {}
    for num in list1:
        if num in dic_data.keys():
            dic_data[num] += 1
        else:
            key = num
            value = 1
            dic_data[key] = value
    return dic_data


def multiply_num(numbers):
    total = 1
    for x in numbers:
        total *= x
    return total/len(numbers)


def decimal_to_binary(n):
    return bin(n).replace("0b","")


import sys
def next_smallest_palindrome(num):
    numstr = str(num)
    for i in range(num+1,sys.maxsize):
        if str(i) == str(i)[::-1]:
            return i


def kth_element(arr, n, k):
  for i in range(n):
    for j in range(0, n-i-1):
      if arr[j] > arr[j+1]:
        arr[j], arr[j+1] == arr[j+1], arr[j]
  return arr[k-1]


def snake_to_camel(word):
        import re
        return ''.join(x.capitalize() or '_' for x in word.split('_'))


def eulerian_num(n, m):
	if (m >= n or n == 0):
		return 0
	if (m == 0):
		return 1
	return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))


def sort_sublists(input_list):
    result = [sorted(x, key = lambda x:x[0]) for x in input_list]
    return result


def count(lst):
    return sum(lst)


def add_lists(test_list, test_tup):
  res = tuple(list(test_tup) + test_list)
  return (res)


def count_Hexadecimal(L,R) :
    count = 0;
    for i in range(L,R + 1) :
        if (i >= 10 and i <= 15) :
            count += 1;
        elif (i > 15) :
            k = i;
            while (k != 0) :
                if (k % 16 >= 10) :
                    count += 1;
                k = k // 16;
    return count;


import heapq
def merge_sorted_list(num1,num2,num3):
  num1=sorted(num1)
  num2=sorted(num2)
  num3=sorted(num3)
  result = heapq.merge(num1,num2,num3)
  return list(result)


def odd_Equivalent(s,n):
    count=0
    for i in range(0,n):
        if (s[i] == '1'):
            count = count + 1
    return count


def extract_missing(test_list, strt_val, stop_val):
  res = []
  for sub in test_list:
    if sub[0] > strt_val:
      res.append((strt_val, sub[0]))
      strt_val = sub[1]
    if strt_val < stop_val:
      res.append((strt_val, stop_val))
  return (res)


def common_in_nested_lists(nestedlist):
    result = list(set.intersection(*map(set, nestedlist)))
    return result


def perimeter(diameter,height) :
    return 2*(diameter+height)


def check_integer(text):
 text = text.strip()
 if len(text) < 1:
    return None
 else:
     if all(text[i] in "0123456789" for i in range(len(text))):
          return True
     elif (text[0] in "+-") and \
         all(text[i] in "0123456789" for i in range(1,len(text))):
         return True
     else:
        return False


from collections import Counter
def assign_freq(test_list):
  res = [(*key, val) for key, val in Counter(test_list).items()]
  return (str(res))


def empty_dit(list1):
 empty_dit=all(not d for d in list1)
 return empty_dit


def tuple_to_int(nums):
    result = int(''.join(map(str,nums)))
    return result


def list_to_float(test_list):
  res = []
  for tup in test_list:
    temp = []
    for ele in tup:
      if ele.isalpha():
        temp.append(ele)
      else:
        temp.append(float(ele))
    res.append((temp[0],temp[1]))
  return (str(res))


def string_to_list(string):
    lst = list(string.split(" "))
    return lst


def search(arr,n) :
    XOR = 0
    for i in range(n) :
        XOR = XOR ^ arr[i]
    return (XOR)


def max_product_tuple(list1):
    result_max = max([abs(x * y) for x, y in list1] )
    return result_max


def check_triplet(A, n, sum, count):
    if count == 3 and sum == 0:
        return True
    if count == 3 or n == 0 or sum < 0:
        return False
    return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\
           check_triplet(A, n - 1, sum, count)


MAX = 3000
def smartNumber(n):
	primes = [0] * MAX
	result = []
	for i in range(2, MAX):
		if (primes[i] == 0):
			primes[i] = 1
			j = i * 2
			while (j < MAX):
				primes[j] -= 1
				if ( (primes[j] + 3) == 0):
					result.append(j)
				j = j + i
	result.sort()
	return result[n - 1]


def amicable_numbers_sum(limit):
    if not isinstance(limit, int):
        return "Input is not an integer!"
    if limit < 1:
        return "Input must be bigger than 0!"
    amicables = set()
    for num in range(2, limit+1):
        if num in amicables:
            continue
        sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
        sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
        if num == sum_fact2 and num != sum_fact:
            amicables.add(num)
            amicables.add(sum_fact2)
    return sum(amicables)


import cmath
def angle_complex(a,b):
  cn=complex(a,b)
  angle=cmath.phase(a+b)
  return angle


def find_length(string, n):
	current_sum = 0
	max_sum = 0
	for i in range(n):
		current_sum += (1 if string[i] == '0' else -1)
		if current_sum < 0:
			current_sum = 0
		max_sum = max(current_sum, max_sum)
	return max_sum if max_sum else 0


def sum(a,b):
    sum = 0
    for i in range (1,min(a,b)):
        if (a % i == 0 and b % i == 0):
            sum += i
    return sum


def multiply_int(x, y):
    if y < 0:
        return -multiply_int(x, -y)
    elif y == 0:
        return 0
    elif y == 1:
        return x
    else:
        return x + multiply_int(x, y - 1)


def long_words(n, str):
    word_len = []
    txt = str.split(" ")
    for x in txt:
        if len(x) > n:
            word_len.append(x)
    return word_len


def magic_square_test(my_matrix):
    iSize = len(my_matrix[0])
    sum_list = []
    sum_list.extend([sum (lines) for lines in my_matrix])
    for col in range(iSize):
        sum_list.append(sum(row[col] for row in my_matrix))
    result1 = 0
    for i in range(0,iSize):
        result1 +=my_matrix[i][i]
    sum_list.append(result1)
    result2 = 0
    for i in range(iSize-1,-1,-1):
        result2 +=my_matrix[i][i]
    sum_list.append(result2)
    if len(set(sum_list))>1:
        return False
    return True


from collections import defaultdict
def max_occurrences(nums):
    dict = defaultdict(int)
    for i in nums:
        dict[i] += 1
    result = max(dict.items(), key=lambda x: x[1])
    return result


def reverse_vowels(str1):
	vowels = ""
	for char in str1:
		if char in "aeiouAEIOU":
			vowels += char
	result_string = ""
	for char in str1:
		if char in "aeiouAEIOU":
			result_string += vowels[-1]
			vowels = vowels[:-1]
		else:
			result_string += char
	return result_string


def tup_string(tup1):
  str =  ''.join(tup1)
  return str


def sum_negativenum(nums):
  sum_negativenum = list(filter(lambda nums:nums<0,nums))
  return sum(sum_negativenum)


def check_last (arr,n,p):
    _sum = 0
    for i in range(n):
        _sum = _sum + arr[i]
    if p == 1:
        if _sum % 2 == 0:
            return "ODD"
        else:
            return "EVEN"
    return "EVEN"


def hexagonal_num(n):
	return n*(2*n - 1)


def cal_electbill(units):
 if(units < 50):
    amount = units * 2.60
    surcharge = 25
 elif(units <= 100):
    amount = 130 + ((units - 50) * 3.25)
    surcharge = 35
 elif(units <= 200):
    amount = 130 + 162.50 + ((units - 100) * 5.26)
    surcharge = 45
 else:
    amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
    surcharge = 75
 total = amount + surcharge
 return total


from array import array
def zero_count(nums):
    n = len(nums)
    n1 = 0
    for x in nums:
        if x == 0:
            n1 += 1
        else:
          None
    return round(n1/n,2)


def is_Sum_Of_Powers_Of_Two(n):
    if (n % 2 == 1):
        return False
    else:
        return True


def circle_circumference(r):
  perimeter=2*3.1415*r
  return perimeter


def extract_singly(test_list):
  res = []
  temp = set()
  for inner in test_list:
    for ele in inner:
      if not ele in temp:
        temp.add(ele)
        res.append(ele)
  return (res)


def pancake_sort(nums):
    arr_len = len(nums)
    while arr_len > 1:
        mi = nums.index(max(nums[0:arr_len]))
        nums = nums[mi::-1] + nums[mi+1:len(nums)]
        nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
        arr_len -= 1
    return nums


def count_samepair(list1,list2,list3):
    result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
    return result


def find_lists(Input):
	if isinstance(Input, list):
		return 1
	else:
		return len(Input)


def sum_Pairs(arr,n):
    sum = 0
    for i in range(n - 1,-1,-1):
        sum += i*arr[i] - (n-1-i) * arr[i]
    return sum


def max_Abs_Diff(arr,n):
    minEle = arr[0]
    maxEle = arr[0]
    for i in range(1, n):
        minEle = min(minEle,arr[i])
        maxEle = max(maxEle,arr[i])
    return (maxEle - minEle)


def ascii_value_string(str1):
  for i in range(len(str1)):
   return ord(str1[i])


def max_path_sum(tri, m, n):
	for i in range(m-1, -1, -1):
		for j in range(i+1):
			if (tri[i+1][j] > tri[i+1][j+1]):
				tri[i][j] += tri[i+1][j]
			else:
				tri[i][j] += tri[i+1][j+1]
	return tri[0][0]


def sum_digits_single(x) :
    ans = 0
    while x :
        ans += x % 10
        x //= 10
    return ans
def closest(x) :
    ans = 0
    while (ans * 10 + 9 <= x) :
        ans = ans * 10 + 9
    return ans
def sum_digits_twoparts(N) :
    A = closest(N)
    return sum_digits_single(A) + sum_digits_single(N - A)


def longest_subseq_with_diff_one(arr, n):
	dp = [1 for i in range(n)]
	for i in range(n):
		for j in range(i):
			if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)):
				dp[i] = max(dp[i], dp[j]+1)
	result = 1
	for i in range(n):
		if (result < dp[i]):
			result = dp[i]
	return result


def does_Contain_B(a,b,c):
    if (a == b):
        return True
    if ((b - a) * c > 0 and (b - a) % c == 0):
        return True
    return False


def gcd(p,q):
    while q != 0:
        p, q = q,p%q
    return p
def is_coprime(x,y):
    return gcd(x,y) == 1


def merge(a,b):
    c = []
    while len(a) != 0 and len(b) != 0:
        if a[0] < b[0]:
            c.append(a[0])
            a.remove(a[0])
        else:
            c.append(b[0])
            b.remove(b[0])
    if len(a) == 0:
        c += b
    else:
        c += a
    return c
def merge_sort(x):
    if len(x) == 0 or len(x) == 1:
        return x
    else:
        middle = len(x)//2
        a = merge_sort(x[:middle])
        b = merge_sort(x[middle:])
        return merge(a,b)


def parabola_vertex(a, b, c):
  vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a))))
  return vertex


def specified_element(nums, N):
    result = [i[N] for i in nums]
    return result


def even_bit_toggle_number(n) :
    res = 0; count = 0; temp = n
    while (temp > 0) :
        if (count % 2 == 1) :
            res = res | (1 << count)
        count = count + 1
        temp >>= 1
    return n ^ res


def tuple_int_str(tuple_str):
    result = tuple((int(x[0]), int(x[1])) for x in tuple_str)
    return result


from itertools import groupby
def encode_list(list1):
    return [[len(list(group)), key] for key, group in groupby(list1)]


def min_Ops(arr,n,k):
    max1 = max(arr)
    res = 0
    for i in range(0,n):
        if ((max1 - arr[i]) % k != 0):
            return -1
        else:
            res += (max1 - arr[i]) / k
    return int(res)


def month_season(month,days):
 if month in ('January', 'February', 'March'):
	 season = 'winter'
 elif month in ('April', 'May', 'June'):
	 season = 'spring'
 elif month in ('July', 'August', 'September'):
	 season = 'summer'
 else:
	 season = 'autumn'
 if (month == 'March') and (days > 19):
	 season = 'spring'
 elif (month == 'June') and (days > 20):
	 season = 'summer'
 elif (month == 'September') and (days > 21):
	 season = 'autumn'
 elif (month == 'October') and (days > 21):
	 season = 'autumn'
 elif (month == 'November') and (days > 21):
	 season = 'autumn'
 elif (month == 'December') and (days > 20):
	 season = 'winter'
 return season


def solution (a, b, n):
	i = 0
	while i * a <= n:
		if (n - (i * a)) % b == 0:
			return ("x = ",i ,", y = ",
			int((n - (i * a)) / b))
			return 0
		i = i + 1
	return ("No solution")


def remove_elements(list1, list2):
    result = [x for x in list1 if x not in list2]
    return result


def sum_series(n):
  if n < 1:
    return 0
  else:
    return n + sum_series(n - 2)


from math import tan, pi
def area_polygon(s,l):
  area = s * (l ** 2) / (4 * tan(pi / s))
  return area


import math
def divSum(n):
    sum = 1;
    i = 2;
    while(i * i <= n):
        if (n % i == 0):
            sum = (sum + i +math.floor(n / i));
        i += 1;
    return sum;
def areEquivalent(num1,num2):
    return divSum(num1) == divSum(num2);


def count_char_position(str1):
    count_chars = 0
    for i in range(len(str1)):
        if ((i == ord(str1[i]) - ord('A')) or
            (i == ord(str1[i]) - ord('a'))):
            count_chars += 1
    return count_chars


def find_even_Pair(A,N):
    evenPair = 0
    for i in range(0,N):
        for j in range(i+1,N):
            if ((A[i] ^ A[j]) % 2 == 0):
                evenPair+=1
    return evenPair;


def next_Power_Of_2(n):
    count = 0;
    if (n and not(n & (n - 1))):
        return n
    while( n != 0):
        n >>= 1
        count += 1
    return 1 << count;


def frequency(a,x):
    count = 0
    for i in a:
        if i == x: count += 1
    return count


def get_pell(n):
	if (n <= 2):
		return n
	a = 1
	b = 2
	for i in range(3, n+1):
		c = 2 * b + a
		a = b
		b = c
	return b


def sum_range_list(list1, m, n):
    sum_range = 0
    for i in range(m, n+1, 1):
        sum_range += list1[i]
    return sum_range


import math
def perimeter_pentagon(a):
  perimeter=(5*a)
  return perimeter


def count_occurance(s):
  count=0
  for i in range(len(s)):
    if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'):
      count = count + 1
  return count


import re
def remove_splchar(text):
 pattern = re.compile('[\W_]+')
 return (pattern.sub('', text))


def group_keyvalue(l):
    result = {}
    for k, v in l:
         result.setdefault(k, []).append(v)
    return result


def is_valid_parenthese( str1):
        stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
        for parenthese in str1:
            if parenthese in pchar:
                stack.append(parenthese)
            elif len(stack) == 0 or pchar[stack.pop()] != parenthese:
                return False
        return len(stack) == 0


def perimeter_triangle(a,b,c):
  perimeter=a+b+c
  return perimeter


def answer(L,R):
    if (2 * L <= R):
        return (L ,2*L)
    else:
        return (-1)


import re
def string_literals(patterns,text):
  for pattern in patterns:
     if re.search(pattern,  text):
       return ('Matched!')
     else:
       return ('Not Matched!')


def is_num_keith(x):
	terms = []
	temp = x
	n = 0
	while (temp > 0):
		terms.append(temp % 10)
		temp = int(temp / 10)
		n+=1
	terms.reverse()
	next_term = 0
	i = n
	while (next_term < x):
		next_term = 0
		for j in range(1,n+1):
			next_term += terms[i - j]
		terms.append(next_term)
		i+=1
	return (next_term == x)


from math import radians, sin, cos, acos
def distance_lat_long(slat,slon,elat,elon):
 dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
 return dist


def common_prefix_util(str1, str2):
	result = "";
	n1 = len(str1)
	n2 = len(str2)
	i = 0
	j = 0
	while i <= n1 - 1 and j <= n2 - 1:
		if (str1[i] != str2[j]):
			break
		result += str1[i]
		i += 1
		j += 1
	return (result)
def common_prefix (arr, n):
	prefix = arr[0]
	for i in range (1, n):
		prefix = common_prefix_util(prefix, arr[i])
	return (prefix)


import re
def find_character(string):
  uppercase_characters = re.findall(r"[A-Z]", string)
  lowercase_characters = re.findall(r"[a-z]", string)
  numerical_characters = re.findall(r"[0-9]", string)
  special_characters = re.findall(r"[, .!?]", string)
  return uppercase_characters, lowercase_characters, numerical_characters, special_characters


def count_pairs(arr, n, k):
  count=0;
  for i in range(0,n):
    for j in range(i+1, n):
      if arr[i] - arr[j] == k or arr[j] - arr[i] == k:
        count += 1
  return count


def greater_specificnum(list,num):
 greater_specificnum=all(x >= num for x in list)
 return greater_specificnum


def parabola_focus(a, b, c):
  focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a))))
  return focus


import re
def check_literals(text, patterns):
  for pattern in patterns:
    if re.search(pattern,  text):
        return ('Matched!')
    else:
        return ('Not Matched!')


def longest_common_subsequence(X, Y, m, n):
    if m == 0 or n == 0:
       return 0
    elif X[m-1] == Y[n-1]:
       return 1 + longest_common_subsequence(X, Y, m-1, n-1)
    else:
       return max(longest_common_subsequence(X, Y, m, n-1), longest_common_subsequence(X, Y, m-1, n))


def prod_Square(n):
    for i in range(2,(n) + 1):
        if (i*i < (n+1)):
            for j in range(2,n + 1):
                if ((i*i*j*j) == n):
                    return True;
    return False;


def first_Missing_Positive(arr,n):
    ptr = 0
    for i in range(n):
        if arr[i] == 1:
            ptr = 1
            break
    if ptr == 0:
        return(1)
    for i in range(n):
        if arr[i] <= 0 or arr[i] > n:
            arr[i] = 1
    for i in range(n):
        arr[(arr[i] - 1) % n] += n
    for i in range(n):
        if arr[i] <= n:
            return(i + 1)
    return(n + 1)


def count_Intgral_Points(x1,y1,x2,y2):
    return ((y2 - y1 - 1) * (x2 - x1 - 1))


def check_monthnumber(monthname3):
  if monthname3 =="April" or monthname3== "June" or monthname3== "September" or monthname3== "November":
    return True
  else:
    return False


def check_String(str):
    flag_l = False
    flag_n = False
    for i in str:
        if i.isalpha():
            flag_l = True
        if i.isdigit():
            flag_n = True
    return flag_l and flag_n


def remove_tuple(test_tup):
  res = tuple(set(test_tup))
  return (res)


def octal_To_Decimal(n):
    num = n;
    dec_value = 0;
    base = 1;
    temp = num;
    while (temp):
        last_digit = temp % 10;
        temp = int(temp / 10);
        dec_value += last_digit*base;
        base = base * 8;
    return dec_value;


def first(arr,x,n):
    low = 0
    high = n - 1
    res = -1
    while (low <= high):
        mid = (low + high) // 2
        if arr[mid] > x:
            high = mid - 1
        elif arr[mid] < x:
            low = mid + 1
        else:
            res = mid
            high = mid - 1
    return res


def remove_tuples(test_list, K):
  res = [ele for ele in test_list if len(ele) != K]
  return (res)


def find_exponentio(test_tup1, test_tup2):
  res = tuple(ele1 ** ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
  return (res)


import math
def largest_triangle(a,b):
    if (a < 0 or b < 0):
        return -1
    area = (3 * math.sqrt(3) * pow(a, 2)) / (4 * b);
    return area


def highest_Power_of_2(n):
    res = 0;
    for i in range(n, 0, -1):
        if ((i & (i - 1)) == 0):
            res = i;
            break;
    return res;


def position_max(list1):
    max_val = max(list1)
    max_result = [i for i, j in enumerate(list1) if j == max_val]
    return max_result


def chkList(lst):
    return len(set(lst)) == 1


def remove_even(str1):
 str2 = ''
 for i in range(1, len(str1) + 1):
    if(i % 2 != 0):
        str2 = str2 + str1[i - 1]
 return str2


def hamming_Distance(n1,n2) :
    x = n1 ^ n2
    setBits = 0
    while (x > 0) :
        setBits += x & 1
        x >>= 1
    return setBits


def count(s,c) :
    res = 0
    for i in range(len(s)) :
        if (s[i] == c):
            res = res + 1
    return res


def inversion_elements(test_tup):
  res = tuple(list(map(lambda x: ~x, list(test_tup))))
  return (res)


def concatenate_elements(test_tup):
  res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))
  return (res)


def find_longest_repeating_subseq(str):
	n = len(str)
	dp = [[0 for k in range(n+1)] for l in range(n+1)]
	for i in range(1, n+1):
		for j in range(1, n+1):
			if (str[i-1] == str[j-1] and i != j):
				dp[i][j] = 1 + dp[i-1][j-1]
			else:
				dp[i][j] = max(dp[i][j-1], dp[i-1][j])
	return dp[n][n]


import re
def is_decimal(num):
  num_fetch = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""")
  result = num_fetch.search(num)
  return bool(result)


import heapq as hq
def heap_replace(heap,a):
  hq.heapify(heap)
  hq.heapreplace(heap, a)
  return heap


import re
def is_allowed_specific_char(string):
    get_char = re.compile(r'[^a-zA-Z0-9.]')
    string = get_char.search(string)
    return not bool(string)


def count_Num(n):
    if (n == 1):
        return 1
    count = pow(2,n - 2)
    return count


import math
def fourth_Power_Sum(n):
    sum = 0
    for i in range(1,n+1) :
        sum = sum + (i*i*i*i)
    return sum


def concatenate_strings(test_tup1, test_tup2):
  res = tuple(ele1 + ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
  return (res)


import math
def degree_radian(radian):
 degree = radian*(180/math.pi)
 return degree


def decode_list(alist):
    def aux(g):
        if isinstance(g, list):
            return [(g[1], range(g[0]))]
        else:
            return [(g, [0])]
    return [x for g in alist for x, R in aux(g) for i in R]


def check_subset_list(list1, list2):
    l1, l2 = list1[0], list2[0]
    exist = True
    for i in list2:
        if i not in list1:
            exist = False
    return exist


def first_Repeated_Char(str):
    h = {}
    for ch in str:
        if ch in h:
            return ch;
        else:
            h[ch] = 0
    return '\0'


import math
def min_Operations(A,B):
    if (A > B):
        swap(A,B)
    B = B // math.gcd(A,B);
    return B - 1


def extract_min_max(test_tup, K):
  res = []
  test_tup = list(test_tup)
  temp = sorted(test_tup)
  for idx, val in enumerate(temp):
    if idx < K or idx >= len(temp) - K:
      res.append(val)
  res = tuple(res)
  return (res)


import re
def replace_max_specialchar(text,n):
 return (re.sub("[ ,.]", ":", text, n))


def first_even(nums):
    first_even = next((el for el in nums if el%2==0),-1)
    return first_even


def check_type(test_tuple):
  res = True
  for ele in test_tuple:
    if not isinstance(ele, type(test_tuple[0])):
      res = False
      break
  return (res)


def is_majority(arr, n, x):
	i = binary_search(arr, 0, n-1, x)
	if i == -1:
		return False
	if ((i + n//2) <= (n -1)) and arr[i + n//2] == x:
		return True
	else:
		return False
def binary_search(arr, low, high, x):
	if high >= low:
		mid = (low + high)//2
		if (mid == 0 or x > arr[mid-1]) and (arr[mid] == x):
			return mid
		elif x > arr[mid]:
			return binary_search(arr, (mid + 1), high, x)
		else:
			return binary_search(arr, low, (mid -1), x)
	return -1


def count_Set_Bits(n):
    count = 0
    while (n):
        count += n & 1
        n >>= 1
    return count


def find_Min(arr,low,high):
    while (low < high):
        mid = low + (high - low) // 2;
        if (arr[mid] == arr[high]):
            high -= 1;
        elif (arr[mid] > arr[high]):
            low = mid + 1;
        else:
            high = mid;
    return arr[high];


def odd_values_string(str):
  result = ""
  for i in range(len(str)):
    if i % 2 == 0:
      result = result + str[i]
  return result


def min_of_three(a,b,c):
      if (a <= b) and (a <= c):
        smallest = a
      elif (b <= a) and (b <= c):
        smallest = b
      else:
        smallest = c
      return smallest


def all_Bits_Set_In_The_Given_Range(n,l,r):
    num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1))
    new_num = n & num
    if (new_num == 0):
        return True
    return False


def re_arrange_array(arr, n):
  j=0
  for i in range(0, n):
    if (arr[i] < 0):
      temp = arr[i]
      arr[i] = arr[j]
      arr[j] = temp
      j = j + 1
  return arr


def replace_blank(str1,char):
 str2 = str1.replace(' ', char)
 return str2


def max_sum(tri, n):
	if n > 1:
		tri[1][1] = tri[1][1]+tri[0][0]
		tri[1][0] = tri[1][0]+tri[0][0]
	for i in range(2, n):
		tri[i][0] = tri[i][0] + tri[i-1][0]
		tri[i][i] = tri[i][i] + tri[i-1][i-1]
		for j in range(1, i):
			if tri[i][j]+tri[i-1][j-1] >= tri[i][j]+tri[i-1][j]:
				tri[i][j] = tri[i][j] + tri[i-1][j-1]
			else:
				tri[i][j] = tri[i][j]+tri[i-1][j]
	return (max(tri[n-1]))


import heapq
def larg_nnum(list1,n):
 largest=heapq.nlargest(n,list1)
 return largest


def lateralsuface_cylinder(r,h):
  lateralsurface= 2*3.1415*r*h
  return lateralsurface


def volume_cube(l):
  volume = l * l * l
  return volume


def even_bit_set_number(n):
    count = 0;res = 0;temp = n
    while(temp > 0):
        if (count % 2 == 1):
            res |= (1 << count)
        count+=1
        temp >>= 1
    return (n | res)


def No_of_Triangle(N,K):
    if (N < K):
        return -1;
    else:
        Tri_up = 0;
        Tri_up = ((N - K + 1) *(N - K + 2)) // 2;
        Tri_down = 0;
        Tri_down = ((N - 2 * K + 1) *(N - 2 * K + 2)) // 2;
        return Tri_up + Tri_down;


from collections import Counter
def check_occurences(test_list):
  res = dict(Counter(tuple(ele) for ele in map(sorted, test_list)))
  return  (res)


def number_of_substrings(str):
	str_len = len(str);
	return int(str_len * (str_len + 1) / 2);


def get_total_number_of_sequences(m,n):
	T=[[0 for i in range(n+1)] for i in range(m+1)]
	for i in range(m+1):
		for j in range(n+1):
			if i==0 or j==0:
				T[i][j]=0
			elif i<j:
				T[i][j]=0
			elif j==1:
				T[i][j]=i
			else:
				T[i][j]=T[i-1][j]+T[i//2][j-1]
	return T[m][n]


def replace_list(list1,list2):
 list1[-1:] = list2
 replace_list=list1
 return replace_list


def array_3d(m,n,o):
 array_3d = [[ ['*' for col in range(m)] for col in range(n)] for row in range(o)]
 return array_3d


def count_charac(str1):
 total = 0
 for i in str1:
    total = total + 1
 return total


def sort_on_occurence(lst):
	dct = {}
	for i, j in lst:
		dct.setdefault(i, []).append(j)
	return ([(i, *dict.fromkeys(j), len(j))
				for i, j in dct.items()])


import math
def next_Perfect_Square(N):
    nextN = math.floor(math.sqrt(N)) + 1
    return nextN * nextN


def max_sum(arr, n):
	MSIBS = arr[:]
	for i in range(n):
		for j in range(0, i):
			if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
				MSIBS[i] = MSIBS[j] + arr[i]
	MSDBS = arr[:]
	for i in range(1, n + 1):
		for j in range(1, i):
			if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
				MSDBS[-i] = MSDBS[-j] + arr[-i]
	max_sum = float("-Inf")
	for i, j, k in zip(MSIBS, MSDBS, arr):
		max_sum = max(max_sum, i + j - k)
	return max_sum


def babylonian_squareroot(number):
    if(number == 0):
        return 0;
    g = number/2.0;
    g2 = g + 1;
    while(g != g2):
        n = number/ g;
        g2 = g;
        g = (g + n)/2;
    return g;


def lps(str):
	n = len(str)
	L = [[0 for x in range(n)] for x in range(n)]
	for i in range(n):
		L[i][i] = 1
	for cl in range(2, n+1):
		for i in range(n-cl+1):
			j = i+cl-1
			if str[i] == str[j] and cl == 2:
				L[i][j] = 2
			elif str[i] == str[j]:
				L[i][j] = L[i+1][j-1] + 2
			else:
				L[i][j] = max(L[i][j-1], L[i+1][j]);
	return L[0][n-1]


def harmonic_sum(n):
  if n < 2:
    return 1
  else:
    return 1 / n + (harmonic_sum(n - 1))


def intersection_array(array_nums1,array_nums2):
 result = list(filter(lambda x: x in array_nums1, array_nums2))
 return result


def count_X(tup, x):
    count = 0
    for ele in tup:
        if (ele == x):
            count = count + 1
    return count


def insert_element(list,element):
 list = [v for elt in list for v in (element, elt)]
 return list


import cmath
def convert(numbers):
  num = cmath.polar(numbers)
  return (num)


def count_integer(list1):
    ctr = 0
    for i in list1:
        if isinstance(i, int):
            ctr = ctr + 1
    return ctr


import re
def words_ae(text):
 list = re.findall("[ae]\w+", text)
 return list


from itertools import combinations_with_replacement
def combinations_colors(l, n):
    return list(combinations_with_replacement(l,n))


def count_Primes_nums(n):
    ctr = 0
    for num in range(n):
        if num <= 1:
            continue
        for i in range(2,num):
            if (num % i) == 0:
                break
        else:
            ctr += 1
    return ctr


def swap_numbers(a,b):
 temp = a
 a = b
 b = temp
 return (a,b)


def count_odd(array_nums):
   count_odd = len(list(filter(lambda x: (x%2 != 0) , array_nums)))
   return count_odd


def maximize_elements(test_tup1, test_tup2):
  res = tuple(tuple(max(a, b) for a, b in zip(tup1, tup2))
   for tup1, tup2 in zip(test_tup1, test_tup2))
  return (res)


def newman_prime(n):
	if n == 0 or n == 1:
		return 1
	return 2 * newman_prime(n - 1) + newman_prime(n - 2)


def division_elements(test_tup1, test_tup2):
  res = tuple(ele1 // ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
  return (res)


def split_two_parts(list1, L):
    return list1[:L], list1[L:]


def merge_dict(d1,d2):
 d = d1.copy()
 d.update(d2)
 return d


def dog_age(h_age):
 if h_age < 0:
 	exit()
 elif h_age <= 2:
	 d_age = h_age * 10.5
 else:
	 d_age = 21 + (h_age - 2)*4
 return d_age


def list_split(S, step):
    return [S[i::step] for i in range(step)]


def lateralsurface_cube(l):
  LSA = 4 * (l * l)
  return LSA


def square_Sum(n):
    return int(n*(4*n*n-1)/3)


def find_star_num(n):
	return (6 * n * (n - 1) + 1)


def ascii_value(k):
  ch=k
  return ord(ch)


def sum_even_and_even_index(arr,n):
    i = 0
    sum = 0
    for i in range(0,n,2):
        if (arr[i] % 2 == 0) :
            sum += arr[i]
    return sum


def even_Power_Sum(n):
    sum = 0;
    for i in range(1,n+1):
        j = 2*i;
        sum = sum + (j*j*j*j*j);
    return sum;


def rear_extract(test_list):
  res = [lis[-1] for lis in test_list]
  return (res)


def substract_elements(test_tup1, test_tup2):
  res = tuple(map(lambda i, j: i - j, test_tup1, test_tup2))
  return (res)


import math
def even_binomial_Coeff_Sum( n):
    return (1 << (n - 1))


import math as mt
def get_Position(a,n,m):
    for i in range(n):
        a[i] = (a[i] // m + (a[i] % m != 0))
    result,maxx = -1,-1
    for i in range(n - 1,-1,-1):
        if (maxx < a[i]):
            maxx = a[i]
            result = i
    return result + 1


def volume_cylinder(r,h):
  volume=3.1415*r*r*h
  return volume


def dict_filter(dict,n):
 result = {key:value for (key, value) in dict.items() if value >=n}
 return result


def count_first_elements(test_tup):
  for count, ele in enumerate(test_tup):
    if isinstance(ele, tuple):
      break
  return (count)


def is_num_decagonal(n):
	return 4 * n * n - 3 * n


def sequential_search(dlist, item):
    pos = 0
    found = False
    while pos < len(dlist) and not found:
        if dlist[pos] == item:
            found = True
        else:
            pos = pos + 1
    return found, pos


def all_unique(test_list):
    if len(test_list) > len(set(test_list)):
        return False
    return True


def sub_list(nums1,nums2):
  result = map(lambda x, y: x - y, nums1, nums2)
  return list(result)


def validate(n):
    for i in range(10):
        temp = n;
        count = 0;
        while (temp):
            if (temp % 10 == i):
                count+=1;
            if (count > i):
                return False
            temp //= 10;
    return True


def check_element(list,element):
  check_element=all(v== element for v in list)
  return check_element


import re
def text_match_two_three(text):
        patterns = 'ab{2,3}'
        if re.search(patterns,  text):
                return 'Found a match!'
        else:
                return('Not matched!')


def max_sub_array_sum_repeated(a, n, k):
	max_so_far = -2147483648
	max_ending_here = 0
	for i in range(n*k):
		max_ending_here = max_ending_here + a[i%n]
		if (max_so_far < max_ending_here):
			max_so_far = max_ending_here
		if (max_ending_here < 0):
			max_ending_here = 0
	return max_so_far


def square_Sum(n):
    return int(2*n*(n+1)*(2*n+1)/3)


def modular_inverse(arr, N, P):
	current_element = 0
	for i in range(0, N):
		if ((arr[i] * arr[i]) % P == 1):
			current_element = current_element + 1
	return current_element


def odd_Days(N):
    hund1 = N // 100
    hund4 = N // 400
    leap = N >> 2
    ordd = N - leap
    if (hund1):
        ordd += hund1
        leap -= hund1
    if (hund4):
        ordd -= hund4
        leap += hund4
    days = ordd + leap * 2
    odd = days % 7
    return odd


def max_length(list1):
    max_length = max(len(x) for x in  list1 )
    max_list = max((x) for x in   list1)
    return(max_length, max_list)


def count_no_of_ways(n, k):
	dp = [0] * (n + 1)
	total = k
	mod = 1000000007
	dp[1] = k
	dp[2] = k * k
	for i in range(3,n+1):
		dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
	return dp[n]


def find(n,m):
    q = n//m
    return (q)


import math
def otherside_rightangle(w,h):
  s=math.sqrt((w*w)+(h*h))
  return s


def max_val(listval):
     max_val = max(i for i in listval if isinstance(i, int))
     return(max_val)


def sum_div(number):
    divisors = [1]
    for i in range(2, number):
        if (number % i)==0:
            divisors.append(i)
    return sum(divisors)


def get_Inv_Count(arr,n):
    inv_count = 0
    for i in range(n):
        for j in range(i + 1,n):
            if (arr[i] > arr[j]):
                inv_count += 1
    return inv_count


def flatten_list(list1):
    result_list = []
    if not list1: return result_list
    stack = [list(list1)]
    while stack:
        c_num = stack.pop()
        next = c_num.pop()
        if c_num: stack.append(c_num)
        if isinstance(next, list):
            if next: stack.append(list(next))
        else: result_list.append(next)
    result_list.reverse()
    return result_list


def intersection_nested_lists(l1, l2):
    result = [[n for n in lst if n in l1] for lst in l2]
    return result


from collections import defaultdict
def max_aggregate(stdata):
    temp = defaultdict(int)
    for name, marks in stdata:
        temp[name] += marks
    return max(temp.items(), key=lambda x: x[1])


def count_binary_seq(n):
	nCr = 1
	res = 1
	for r in range(1, n + 1):
		nCr = (nCr * (n + 1 - r)) / r
		res += nCr * nCr
	return res


def dict_depth(d):
    if isinstance(d, dict):
        return 1 + (max(map(dict_depth, d.values())) if d else 0)
    return 0


def set_Bit_Number(n):
    if (n == 0):
        return 0;
    msb = 0;
    n = int(n / 2);
    while (n > 0):
        n = int(n / 2);
        msb += 1;
    return (1 << msb)


import sys
def solve(a,n):
    mx = -sys.maxsize - 1
    for j in range(1,n):
        if (mx > a[j]):
            return False
        mx = max(mx,a[j - 1])
    return True


def find_Element(arr,ranges,rotations,index) :
    for i in range(rotations - 1,-1,-1 ) :
        left = ranges[i][0]
        right = ranges[i][1]
        if (left <= index and right >= index) :
            if (index == left) :
                index = right
            else :
                index = index - 1
    return arr[index]


import re
def start_withp(words):
 for w in words:
        m = re.match("(P\w+)\W(P\w+)", w)
        if m:
            return m.groups()


def max_sum_increasing_subseq(a, n, index, k):
	dp = [[0 for i in range(n)]
			for i in range(n)]
	for i in range(n):
		if a[i] > a[0]:
			dp[0][i] = a[i] + a[0]
		else:
			dp[0][i] = a[i]
	for i in range(1, n):
		for j in range(n):
			if a[j] > a[i] and j > i:
				if dp[i - 1][i] + a[j] > dp[i - 1][j]:
					dp[i][j] = dp[i - 1][i] + a[j]
				else:
					dp[i][j] = dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j]
	return dp[index][k]


from copy import deepcopy
def colon_tuplex(tuplex,m,n):
  tuplex_colon = deepcopy(tuplex)
  tuplex_colon[m].append(n)
  return tuplex_colon


def large_product(nums1, nums2, N):
    result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
    return result


def maximum(a,b):
    if a >= b:
        return a
    else:
        return b


def string_to_tuple(str1):
    result = tuple(x for x in str1 if not x.isspace())
    return result


def set_left_most_unset_bit(n):
    if not (n & (n + 1)):
        return n
    pos, temp, count = 0, n, 0
    while temp:
        if not (temp & 1):
            pos = count
        count += 1; temp>>=1
    return (n | (1 << (pos)))


import math
def volume_cone(r,h):
  volume = (1.0/3) * math.pi * r * r * h
  return volume


def pos_nos(list1):
  for num in list1:
    if num >= 0:
       return num


def max_sum_rectangular_grid(grid, n) :
	incl = max(grid[0][0], grid[1][0])
	excl = 0
	for i in range(1, n) :
		excl_new = max(excl, incl)
		incl = excl + max(grid[0][i], grid[1][i])
		excl = excl_new
	return max(excl, incl)


def find_Max_Len_Even(str):
    n = len(str)
    i = 0
    currlen = 0
    maxlen = 0
    st = -1
    while (i < n):
        if (str[i] == ' '):
            if (currlen % 2 == 0):
                if (maxlen < currlen):
                    maxlen = currlen
                    st = i - currlen
            currlen = 0
        else :
            currlen += 1
        i += 1
    if (currlen % 2 == 0):
        if (maxlen < currlen):
            maxlen = currlen
            st = i - currlen
    if (st == -1):
        return "-1"
    return str[st: st + maxlen]


def find_last_occurrence(A, x):
    (left, right) = (0, len(A) - 1)
    result = -1
    while left <= right:
        mid = (left + right) // 2
        if x == A[mid]:
            result = mid
            left = mid + 1
        elif x < A[mid]:
            right = mid - 1
        else:
            left = mid + 1
    return result


from itertools import groupby
def modified_encode(alist):
        def ctr_ele(el):
            if len(el)>1: return [len(el), el[0]]
            else: return el[0]
        return [ctr_ele(list(group)) for key, group in groupby(alist)]


def max_volume (s):
    maxvalue = 0
    i = 1
    for i in range(s - 1):
        j = 1
        for j in range(s):
            k = s - i - j
            maxvalue = max(maxvalue, i * j * k)
    return maxvalue


import re
def find_long_word(text):
  return (re.findall(r"\b\w{5}\b", text))


def sum_difference(n):
    sumofsquares = 0
    squareofsum = 0
    for num in range(1, n+1):
        sumofsquares += num * num
        squareofsum += num
    squareofsum = squareofsum ** 2
    return squareofsum - sumofsquares


def find_demlo(s):
	l = len(s)
	res = ""
	for i in range(1,l+1):
		res = res + str(i)
	for i in range(l-1,0,-1):
		res = res + str(i)
	return res


def position_min(list1):
    min_val = min(list1)
    min_result = [i for i, j in enumerate(list1) if j == min_val]
    return min_result


def right_rotate(arr, n, out_of_place, cur):
	temp = arr[cur]
	for i in range(cur, out_of_place, -1):
		arr[i] = arr[i - 1]
	arr[out_of_place] = temp
	return arr
def re_arrange(arr, n):
	out_of_place = -1
	for index in range(n):
		if (out_of_place >= 0):
			if ((arr[index] >= 0 and arr[out_of_place] < 0) or
			(arr[index] < 0 and arr[out_of_place] >= 0)):
				arr = right_rotate(arr, n, out_of_place, index)
				if (index-out_of_place > 2):
					out_of_place += 2
				else:
					out_of_place = - 1
		if (out_of_place == -1):
			if ((arr[index] >= 0 and index % 2 == 0) or
			 (arr[index] < 0 and index % 2 == 1)):
				out_of_place = index
	return arr


def sum_of_alternates(test_tuple):
  sum1 = 0
  sum2 = 0
  for idx, ele in enumerate(test_tuple):
    if idx % 2:
      sum1 += ele
    else:
      sum2 += ele
  return ((sum1),(sum2))


def get_Min_Squares(n):
    if n <= 3:
        return n;
    res = n
    for x in range(1,n + 1):
        temp = x * x;
        if temp > n:
            break
        else:
            res = min(res,1 + get_Min_Squares(n  - temp))
    return res;


from collections import defaultdict

def most_occurrences(test_list):
  temp = defaultdict(int)
  for sub in test_list:
    for wrd in sub.split():
      temp[wrd] += 1
  res = max(temp, key=temp.get)
  return (str(res))


def check_isosceles(x,y,z):
  if x==y or y==z or z==x:
	   return True
  else:
     return False


def rotate_left(list1,m,n):
  result =  list1[m:]+list1[:n]
  return result


def neg_count(list):
  neg_count= 0
  for num in list:
    if num <= 0:
      neg_count += 1
  return neg_count


import re
def find_char(text):
  return (re.findall(r"\b\w{3,5}\b", text))


def count_unset_bits(n):
    count = 0
    x = 1
    while(x < n + 1):
        if ((x & n) == 0):
            count += 1
        x = x << 1
    return count


def char_frequency(str1):
    dict = {}
    for n in str1:
        keys = dict.keys()
        if n in keys:
            dict[n] += 1
        else:
            dict[n] = 1
    return dict


def Sort(sub_li):
    sub_li.sort(key = lambda x: x[1])
    return sub_li


def check_Validity(a,b,c):
    if (a + b <= c) or (a + c <= b) or (b + c <= a) :
        return False
    else:
        return True


def ap_sum(a,n,d):
  total = (n * (2 * a + (n - 1) * d)) / 2
  return total


def check_monthnum(monthname1):
  if monthname1 == "February":
    return True
  else:
    return False


import re
def text_match_word(text):
        patterns = '\w+\S*$'
        if re.search(patterns,  text):
                return 'Found a match!'
        else:
                return 'Not matched!'


def check_Equality(s):
    return (ord(s[0]) == ord(s[len(s) - 1]));
def count_Substring_With_Equal_Ends(s):
    result = 0;
    n = len(s);
    for i in range(n):
        for j in range(1,n-i+1):
            if (check_Equality(s[i:i+j])):
                result+=1;
    return result;


def find_Divisor(x,y):
    if (x==y):
        return y
    return 2


def sum_three_smallest_nums(lst):
	return sum(sorted([x for x in lst if x > 0])[:3])


def set_to_tuple(s):
  t = tuple(sorted(s))
  return (t)


from heapq import heappop, heappush
class Node:
    def __init__(self, value, list_num, index):
        self.value = value
        self.list_num = list_num
        self.index = index
    def __lt__(self, other):
        return self.value < other.value
def find_minimum_range(list):
    high = float('-inf')
    p = (0, float('inf'))
    pq = []
    for i in range(len(list)):
        heappush(pq, Node(list[i][0], i, 0))
        high = max(high, list[i][0])
    while True:
        top = heappop(pq)
        low = top.value
        i = top.list_num
        j = top.index
        if high - low < p[1] - p[0]:
            p = (low, high)
        if j == len(list[i]) - 1:
            return p
        heappush(pq, Node(list[i][j + 1], i, j + 1))
        high = max(high, list[i][j + 1])


def dig_let(s):
 d=l=0
 for c in s:
    if c.isdigit():
        d=d+1
    elif c.isalpha():
        l=l+1
    else:
        pass
 return (l,d)


def count_Odd_Squares(n,m):
    return int(m**0.5) - int((n-1)**0.5)


def diff_consecutivenums(nums):
    result = [b-a for a, b in zip(nums[:-1], nums[1:])]
    return result


def zigzag(n, k):
	if (n == 0 and k == 0):
		return 1
	if (k == 0):
		return 0
	return zigzag(n, k - 1) + zigzag(n - 1, n - k)


def count_Squares(m,n):
    if (n < m):
        temp = m
        m = n
        n = temp
    return n * (n + 1) * (3 * m - n + 1) // 6


def bin_coff(n, r):
	val = 1
	if (r > (n - r)):
		r = (n - r)
	for i in range(0, r):
		val *= (n - i)
		val //= (i + 1)
	return val
def find_ways(M):
	n = M // 2
	a = bin_coff(2 * n, n)
	b = a // (n + 1)
	return (b)


def check(string) :
    p = set(string)
    s = {'0', '1'}
    if s == p or p == {'0'} or p == {'1'}:
        return ("Yes")
    else :
        return ("No")


def minimum_Length(s) :
    maxOcc = 0
    n = len(s)
    arr = [0]*26
    for i in range(n) :
        arr[ord(s[i]) -ord('a')] += 1
    for i in range(26) :
        if arr[i] > maxOcc :
            maxOcc = arr[i]
    return n - maxOcc


def first_Element(arr,n,k):
    count_map = {};
    for i in range(0, n):
        if(arr[i] in count_map.keys()):
            count_map[arr[i]] += 1
        else:
            count_map[arr[i]] = 1
        i += 1
    for i in range(0, n):
        if (count_map[arr[i]] == k):
            return arr[i]
        i += 1
    return -1


def unique_Characters(str):
    for i in range(len(str)):
        for j in range(i + 1,len(str)):
            if (str[i] == str[j]):
                return False;
    return True;


def remove_column(list1, n):
   for i in list1:
    del i[n]
   return list1


def tn_ap(a,n,d):
  tn = a + (n - 1) * d
  return tn


def count_Rectangles(radius):
    rectangles = 0
    diameter = 2 * radius
    diameterSquare = diameter * diameter
    for a in range(1, 2 * radius):
        for b in range(1, 2 * radius):
            diagnalLengthSquare = (a * a +  b * b)
            if (diagnalLengthSquare <= diameterSquare) :
                rectangles += 1
    return rectangles


def find_angle(a,b):
 c = 180 - (a + b)
 return c


def find_max(test_list):
  res = max(int(j) for i in test_list for j in i)
  return (res)


def moddiv_list(nums1,nums2):
  result = map(lambda x, y: x % y, nums1, nums2)
  return list(result)


def Check_Solution(a,b,c):
    if (2*b*b == 9*a*c):
        return ("Yes");
    else:
        return ("No");


def get_carol(n):
	result = (2**n) - 1
	return result * result - 2


def remove_empty(list1):
  remove_empty = [x for x in list1 if x]
  return remove_empty


def max_occurrences(nums):
    max_val = 0
    result = nums[0]
    for i in nums:
        occu = nums.count(i)
        if occu > max_val:
            max_val = occu
            result = i
    return result


def add_K_element(test_list, K):
  res = [tuple(j + K for j in sub ) for sub in test_list]
  return (res)


def make_flip(ch):
	return '1' if (ch == '0') else '0'
def get_flip_with_starting_charcter(str, expected):
	flip_count = 0
	for i in range(len( str)):
		if (str[i] != expected):
			flip_count += 1
		expected = make_flip(expected)
	return flip_count
def min_flip_to_make_string_alternate(str):
	return min(get_flip_with_starting_charcter(str, '0'),get_flip_with_starting_charcter(str, '1'))


def count_Digit(n):
    count = 0
    while n != 0:
        n //= 10
        count += 1
    return count


def adjacent_num_product(list_nums):
    return max(a*b for a, b in zip(list_nums, list_nums[1:]))


class Node:
	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None
def get_height(root):
	if root is None:
		return 0
	return max(get_height(root.left), get_height(root.right)) + 1
def is_tree_balanced(root):
	if root is None:
		return True
	lh = get_height(root.left)
	rh = get_height(root.right)
	if (abs(lh - rh) <= 1) and is_tree_balanced(
	root.left) is True and is_tree_balanced( root.right) is True:
		return True
	return False


def repeat_tuples(test_tup, N):
  res = ((test_tup, ) * N)
  return (res)


def lateralsurface_cuboid(l,w,h):
  LSA = 2*h*(l+w)
  return LSA


def float_sort(price):
  float_sort=sorted(price, key=lambda x: float(x[1]), reverse=True)
  return float_sort


def smallest_missing(A, left_element, right_element):
    if left_element > right_element:
        return left_element
    mid = left_element + (right_element - left_element) // 2
    if A[mid] == mid:
        return smallest_missing(A, mid + 1, right_element)
    else:
        return smallest_missing(A, left_element, mid - 1)


import heapq as hq
def heap_assending(nums):
  hq.heapify(nums)
  s_result = [hq.heappop(nums) for i in range(len(nums))]
  return s_result


def volume_cuboid(l,w,h):
  volume=l*w*h
  return volume


def permute_string(str):
    if len(str) == 0:
        return ['']
    prev_list = permute_string(str[1:len(str)])
    next_list = []
    for i in range(0,len(prev_list)):
        for j in range(0,len(str)):
            new_str = prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1]
            if new_str not in next_list:
                next_list.append(new_str)
    return next_list


def round_num(n,m):
    a = (n //m) * m
    b = a + m
    return (b if n - a > b - n else a)


def remove_replica(test_tup):
  temp = set()
  res = tuple(ele if ele not in temp and not temp.add(ele)
				else 'MSP' for ele in test_tup)
  return (res)


def remove_Char(s,c) :
    counts = s.count(c)
    s = list(s)
    while counts :
        s.remove(c)
        counts -= 1
    s = '' . join(s)
    return (s)


def move_first(test_list):
  test_list = test_list[-1:] + test_list[:-1]
  return test_list


def surfacearea_cuboid(l,w,h):
  SA = 2*(l*w + l * h + w * h)
  return SA


def multi_list(rownum,colnum):
  multi_list = [[0 for col in range(colnum)] for row in range(rownum)]
  for row in range(rownum):
    for col in range(colnum):
        multi_list[row][col]= row*col
  return multi_list


from operator import itemgetter
def index_on_inner_list(list_data, index_no):
    result = sorted(list_data, key=itemgetter(index_no))
    return result


def find_rotation_count(A):
    (left, right) = (0, len(A) - 1)
    while left <= right:
        if A[left] <= A[right]:
            return left
        mid = (left + right) // 2
        next = (mid + 1) % len(A)
        prev = (mid - 1 + len(A)) % len(A)
        if A[mid] <= A[next] and A[mid] <= A[prev]:
            return mid
        elif A[mid] <= A[right]:
            right = mid - 1
        elif A[mid] >= A[left]:
            left = mid + 1
    return -1


def even_bit_toggle_number(n) :
    res = 0; count = 0; temp = n
    while(temp > 0 ) :
        if (count % 2 == 0) :
            res = res | (1 << count)
        count = count + 1
        temp >>= 1
    return n ^ res


def frequency_Of_Smallest(n,arr):
    mn = arr[0]
    freq = 1
    for i in range(1,n):
        if (arr[i] < mn):
            mn = arr[i]
            freq = 1
        elif (arr[i] == mn):
            freq += 1
    return freq


def get_perrin(n):
  if (n == 0):
    return 3
  if (n == 1):
    return 0
  if (n == 2):
    return 2
  return get_perrin(n - 2) + get_perrin(n - 3)


def swap_count(s):
	chars = s
	count_left = 0
	count_right = 0
	swap = 0
	imbalance = 0;
	for i in range(len(chars)):
		if chars[i] == '[':
			count_left += 1
			if imbalance > 0:
				swap += imbalance
				imbalance -= 1
		elif chars[i] == ']':
			count_right += 1
			imbalance = (count_right - count_left)
	return swap


def even_or_odd(N):
    l = len(N)
    if (N[l-1] =='0'or N[l-1] =='2'or
        N[l-1] =='4'or N[l-1] =='6'or
        N[l-1] =='8'or N[l-1] =='A'or
        N[l-1] =='C'or N[l-1] =='E'):
        return ("Even")
    else:
        return ("Odd")


def highest_Power_of_2(n):
    res = 0;
    for i in range(n, 0, -1):
        if ((i & (i - 1)) == 0):
            res = i;
            break;
    return res;


def find_lucas(n):
	if (n == 0):
		return 2
	if (n == 1):
		return 1
	return find_lucas(n - 1) + find_lucas(n - 2)


def add_string(list,string):
 add_string=[string.format(i) for i in  list]
 return add_string


def convert_list_dictionary(l1, l2, l3):
     result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
     return result


def get_max_sum (n):
	res = list()
	res.append(0)
	res.append(1)
	i = 2
	while i<n + 1:
		res.append(max(i, (res[int(i / 2)]
						+ res[int(i / 3)] +
							res[int(i / 4)]
						+ res[int(i / 5)])))
		i = i + 1
	return res[n]


def max_length_list(input_list):
    max_length = max(len(x) for x in input_list )
    max_list = max(input_list, key = lambda i: len(i))
    return(max_length, max_list)


def check_distinct(test_tup):
  res = True
  temp = set()
  for ele in test_tup:
    if ele in temp:
      res = False
      break
    temp.add(ele)
  return (res)


def first_non_repeating_character(str1):
  char_order = []
  ctr = {}
  for c in str1:
    if c in ctr:
      ctr[c] += 1
    else:
      ctr[c] = 1
      char_order.append(c)
  for c in char_order:
    if ctr[c] == 1:
      return c
  return None


import re
regex = r'^[a-z]$|^([a-z]).*\1$'
def check_char(string):
	if(re.search(regex, string)):
		return "Valid"
	else:
		return "Invalid"


def median_numbers(a,b,c):
 if a > b:
    if a < c:
        median = a
    elif b > c:
        median = b
    else:
        median = c
 else:
    if a > c:
        median = a
    elif b < c:
        median = b
    else:
        median = c
 return median


def sum_of_digits(nums):
    return sum(int(el) for n in nums for el in str(n) if el.isdigit())


def bitwise_xor(test_tup1, test_tup2):
  res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
  return (res)


def extract_freq(test_list):
  res = len(list(set(tuple(sorted(sub)) for sub in test_list)))
  return (res)


def add_nested_tuples(test_tup1, test_tup2):
  res = tuple(tuple(a + b for a, b in zip(tup1, tup2))
   for tup1, tup2 in zip(test_tup1, test_tup2))
  return (res)


def ncr_modp(n, r, p):
    C = [0 for i in range(r+1)]
    C[0] = 1
    for i in range(1, n+1):
        for j in range(min(i, r), 0, -1):
            C[j] = (C[j] + C[j-1]) % p
    return C[r]


import re
def is_valid_URL(str):
	regex = ("((http|https)://)(www.)?" +
			"[a-zA-Z0-9@:%._\\+~#?&//=]" +
			"{2,256}\\.[a-z]" +
			"{2,6}\\b([-a-zA-Z0-9@:%" +
			"._\\+~#?&//=]*)")
	p = re.compile(regex)
	if (str == None):
		return False
	if(re.search(p, str)):
		return True
	else:
		return False


def minimum(a,b):
    if a <= b:
        return a
    else:
        return b


def check_tuplex(tuplex,tuple1):
  if tuple1 in tuplex:
    return True
  else:
     return False


def find_Parity(x):
    y = x ^ (x >> 1);
    y = y ^ (y >> 2);
    y = y ^ (y >> 4);
    y = y ^ (y >> 8);
    y = y ^ (y >> 16);
    if (y & 1):
        return ("Odd Parity");
    return ("Even Parity");


def rearrange_bigger(n):
    nums = list(str(n))
    for i in range(len(nums)-2,-1,-1):
        if nums[i] < nums[i+1]:
            z = nums[i:]
            y = min(filter(lambda x: x > z[0], z))
            z.remove(y)
            z.sort()
            nums[i:] = [y] + z
            return int("".join(nums))
    return False


import heapq
def k_smallest_pairs(nums1, nums2, k):
   queue = []
   def push(i, j):
       if i < len(nums1) and j < len(nums2):
           heapq.heappush(queue, [nums1[i] + nums2[j], i, j])
   push(0, 0)
   pairs = []
   while queue and len(pairs) < k:
       _, i, j = heapq.heappop(queue)
       pairs.append([nums1[i], nums2[j]])
       push(i, j + 1)
       if j == 0:
           push(i + 1, 0)
   return pairs


def min_product_tuple(list1):
    result_min = min([abs(x * y) for x, y in list1] )
    return result_min


def min_val(listval):
     min_val = min(i for i in listval if isinstance(i, int))
     return min_val


import re
def snake_to_camel(word):
  return ''.join(x.capitalize() or '_' for x in word.split('_'))


def remove_odd(l):
    for i in l:
        if i % 2 != 0:
            l.remove(i)
    return l


def extract_nth_element(list1, n):
    result = [x[n] for x in list1]
    return result


def overlapping(list1,list2):
    c=0
    d=0
    for i in list1:
        c+=1
    for i in list2:
        d+=1
    for i in range(0,c):
        for j in range(0,d):
            if(list1[i]==list2[j]):
                return 1
    return 0


def max_Product(arr):
    arr_len = len(arr)
    if (arr_len < 2):
        return ("No pairs exists")
    x = arr[0]; y = arr[1]
    for i in range(0,arr_len):
        for j in range(i + 1,arr_len):
            if (arr[i] * arr[j] > x * y):
                x = arr[i]; y = arr[j]
    return x,y


MAX = 1000000
def breakSum(n):
	dp = [0]*(n+1)
	dp[0] = 0
	dp[1] = 1
	for i in range(2, n+1):
		dp[i] = max(dp[int(i/2)] + dp[int(i/3)] + dp[int(i/4)], i);
	return dp[n]


def group_tuples(Input):
	out = {}
	for elem in Input:
		try:
			out[elem[0]].extend(elem[1:])
		except KeyError:
			out[elem[0]] = list(elem)
	return [tuple(values) for values in out.values()]


def Find_Max(lst):
    maxList = max((x) for x in lst)
    return maxList


def round_and_sum(list1):
  lenght=len(list1)
  round_and_sum=sum(list(map(round,list1))* lenght)
  return round_and_sum


def cube_Sum(n):
    sum = 0
    for i in range(1,n + 1):
        sum += (2*i)*(2*i)*(2*i)
    return sum


def concatenate_tuple(test_tup):
    delim = "-"
    res = ''.join([str(ele) + delim for ele in test_tup])
    res = res[ : len(res) - len(delim)]
    return (str(res))


def find_Average_Of_Cube(n):
    sum = 0
    for i in range(1, n + 1):
        sum += i * i * i
    return round(sum / n, 6)


def get_maxgold(gold, m, n):
    goldTable = [[0 for i in range(n)]
                        for j in range(m)]
    for col in range(n-1, -1, -1):
        for row in range(m):
            if (col == n-1):
                right = 0
            else:
                right = goldTable[row][col+1]
            if (row == 0 or col == n-1):
                right_up = 0
            else:
                right_up = goldTable[row-1][col+1]
            if (row == m-1 or col == n-1):
                right_down = 0
            else:
                right_down = goldTable[row+1][col+1]
            goldTable[row][col] = gold[row][col] + max(right, right_up, right_down)
    res = goldTable[0][0]
    for i in range(1, m):
        res = max(res, goldTable[i][0])
    return res


def extract_rear(test_tuple):
  res = list(sub[len(sub) - 1] for sub in test_tuple)
  return (res)


def count_element_in_list(list1, x):
    ctr = 0
    for i in range(len(list1)):
        if x in list1[i]:
            ctr+= 1
    return ctr


def filter_oddnumbers(nums):
 odd_nums = list(filter(lambda x: x%2 != 0, nums))
 return odd_nums


import re
def change_date_format(dt):
        return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt)


def shell_sort(my_list):
    gap = len(my_list) // 2
    while gap > 0:
        for i in range(gap, len(my_list)):
            current_item = my_list[i]
            j = i
            while j >= gap and my_list[j - gap] > current_item:
                my_list[j] = my_list[j - gap]
                j -= gap
            my_list[j] = current_item
        gap //= 2

    return my_list


def and_tuples(test_tup1, test_tup2):
  res = tuple(ele1 & ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
  return (res)


def parabola_directrix(a, b, c):
  directrix=((int)(c - ((b * b) + 1) * 4 * a ))
  return directrix


def common_element(list1, list2):
     result = False
     for x in list1:
         for y in list2:
             if x == y:
                 result = True
                 return result


def median_trapezium(base1,base2,height):
 median = 0.5 * (base1+ base2)
 return median


def check_greater(arr, number):
  arr.sort()
  if number > arr[-1]:
    return ('Yes, the entered number is greater than those in the array')
  else:
    return ('No, entered number is less than those in the array')


import re
def text_match_one(text):
        patterns = 'ab+?'
        if re.search(patterns,  text):
                return 'Found a match!'
        else:
                return('Not matched!')


def last_Digit(n) :
    return (n % 10)


def neg_nos(list1):
  for num in list1:
    if num < 0:
       return num


def remove_odd(str1):
 str2 = ''
 for i in range(1, len(str1) + 1):
    if(i % 2 == 0):
        str2 = str2 + str1[i - 1]
 return str2


def count_bidirectional(test_list):
  res = 0
  for idx in range(0, len(test_list)):
    for iidx in range(idx + 1, len(test_list)):
      if test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0]:
        res += 1
  return (str(res))


def multiple_to_single(L):
  x = int("".join(map(str, L)))
  return x


import re
def find_adverb_position(text):
 for m in re.finditer(r"\w+ly", text):
    return (m.start(), m.end(), m.group(0))


def surfacearea_cube(l):
  surfacearea= 6*l*l
  return surfacearea


from array import array
def positive_count(nums):
    n = len(nums)
    n1 = 0
    for x in nums:
        if x > 0:
            n1 += 1
        else:
          None
    return round(n1/n,2)


def largest_neg(list1):
    max = list1[0]
    for x in list1:
        if x < max :
             max = x
    return max


def trim_tuple(test_list, K):
  res = []
  for ele in test_list:
    N = len(ele)
    res.append(tuple(list(ele)[K: N - K]))
  return (str(res))


def index_multiplication(test_tup1, test_tup2):
  res = tuple(tuple(a * b for a, b in zip(tup1, tup2))
   for tup1, tup2 in zip(test_tup1, test_tup2))
  return (res)


from collections import Counter
def count_Occurrence(tup, lst):
    count = 0
    for item in tup:
        if item in lst:
            count+= 1
    return count


def cube_nums(nums):
 cube_nums = list(map(lambda x: x ** 3, nums))
 return cube_nums


def cal_sum(n):
	a = 3
	b = 0
	c = 2
	if (n == 0):
		return 3
	if (n == 1):
		return 3
	if (n == 2):
		return 5
	sum = 5
	while (n > 2):
		d = a + b
		sum = sum + d
		a = b
		b = c
		c = d
		n = n-1
	return sum


def check_Triangle(x1,y1,x2,y2,x3,y3):
    a = (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))
    if a == 0:
        return ('No')
    else:
        return ('Yes')


def extract_string(str, l):
    result = [e for e in str if len(e) == l]
    return result


import re
def remove_whitespaces(text1):
  return (re.sub(r'\s+', '',text1))


def loss_amount(actual_cost,sale_amount):
  if(sale_amount > actual_cost):
    amount = sale_amount - actual_cost
    return amount
  else:
    return None


import math
def sumofFactors(n) :
    if (n % 2 != 0) :
        return 0
    res = 1
    for i in range(2, (int)(math.sqrt(n)) + 1) :
        count = 0
        curr_sum = 1
        curr_term = 1
        while (n % i == 0) :
            count= count + 1
            n = n // i
            if (i == 2 and count == 1) :
                curr_sum = 0
            curr_term = curr_term * i
            curr_sum = curr_sum + curr_term
        res = res * curr_sum
    if (n >= 2) :
        res = res * (1 + n)
    return res


import re
def text_match_wordz(text):
        patterns = '\w*z.\w*'
        if re.search(patterns,  text):
                return 'Found a match!'
        else:
                return('Not matched!')


def check_monthnumb_number(monthnum2):
  if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2==8 or monthnum2==10 or monthnum2==12):
    return True
  else:
    return False


def reverse_string_list(stringlist):
    result = [x[::-1] for x in stringlist]
    return result


def Find_Min(lst):
    minList = min((x) for x in lst)
    return minList


def rectangle_area(l,b):
  area=l*b
  return area


import re
def remove_uppercase(str1):
  remove_upper = lambda text: re.sub('[A-Z]', '', text)
  result =  remove_upper(str1)
  return (result)


def Extract(lst):
    return [item[0] for item in lst]


def upper_ctr(str):
    upper_ctr = 0
    for i in range(len(str)):
          if str[i] >= 'A' and str[i] <= 'Z': upper_ctr += 1
          return upper_ctr


def combinations_list(list1):
    if len(list1) == 0:
        return [[]]
    result = []
    for el in combinations_list(list1[1:]):
        result += [el, el+[list1[0]]]
    return result


def max_subarray_product(arr):
	n = len(arr)
	max_ending_here = 1
	min_ending_here = 1
	max_so_far = 0
	flag = 0
	for i in range(0, n):
		if arr[i] > 0:
			max_ending_here = max_ending_here * arr[i]
			min_ending_here = min (min_ending_here * arr[i], 1)
			flag = 1
		elif arr[i] == 0:
			max_ending_here = 1
			min_ending_here = 1
		else:
			temp = max_ending_here
			max_ending_here = max (min_ending_here * arr[i], 1)
			min_ending_here = temp * arr[i]
		if (max_so_far < max_ending_here):
			max_so_far = max_ending_here
	if flag == 0 and max_so_far == 0:
		return 0
	return max_so_far


def check_value(dict, n):
    result = all(x == n for x in dict.values())
    return result


def drop_empty(dict1):
  dict1 = {key:value for (key, value) in dict1.items() if value is not None}
  return dict1


def find_peak_util(arr, low, high, n):
	mid = low + (high - low)/2
	mid = int(mid)
	if ((mid == 0 or arr[mid - 1] <= arr[mid]) and
		(mid == n - 1 or arr[mid + 1] <= arr[mid])):
		return mid
	elif (mid > 0 and arr[mid - 1] > arr[mid]):
		return find_peak_util(arr, low, (mid - 1), n)
	else:
		return find_peak_util(arr, (mid + 1), high, n)
def find_peak(arr, n):
	return find_peak_util(arr, 0, n - 1, n)


def decimal_to_Octal(deciNum):
    octalNum = 0
    countval = 1;
    dNo = deciNum;
    while (deciNum!= 0):
        remainder= deciNum % 8;
        octalNum+= remainder*countval;
        countval= countval*10;
        deciNum //= 8;
    return (octalNum)


def max_product(arr, n ):
	mpis =[0] * (n)
	for i in range(n):
		mpis[i] = arr[i]
	for i in range(1, n):
		for j in range(i):
			if (arr[i] > arr[j] and
					mpis[i] < (mpis[j] * arr[i])):
						mpis[i] = mpis[j] * arr[i]
	return max(mpis)


def max_profit(price, k):
    n = len(price)
    final_profit = [[None for x in range(n)] for y in range(k + 1)]
    for i in range(k + 1):
        for j in range(n):
            if i == 0 or j == 0:
                final_profit[i][j] = 0
            else:
                max_so_far = 0
                for x in range(j):
                    curr_price = price[j] - price[x] + final_profit[i-1][x]
                    if max_so_far < curr_price:
                        max_so_far = curr_price
                final_profit[i][j] = max(final_profit[i][j-1], max_so_far)
    return final_profit[k][n-1]


def add_pairwise(test_tup):
  res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))
  return (res)


def find_remainder(arr, lens, n):
    mul = 1
    for i in range(lens):
        mul = (mul * (arr[i] % n)) % n
    return mul % n


def check_Consecutive(l):
    return sorted(l) == list(range(min(l),max(l)+1))


def tuple_intersection(test_list1, test_list2):
  res = set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2])
  return (res)


def replace_char(str1,ch,newch):
 str2 = str1.replace(ch, newch)
 return str2


from collections import Counter
def sort_counter(dict1):
 x = Counter(dict1)
 sort_counter=x.most_common()
 return sort_counter


def big_sum(nums):
      sum= max(nums)+min(nums)
      return sum


def is_lower(string):
  return (string.lower())


import re
def remove_lowercase(str1):
 remove_lower = lambda text: re.sub('[a-z]', '', text)
 result =  remove_lower(str1)
 return result


def first_Digit(n) :
    while n >= 10:
        n = n / 10;
    return int(n)


def get_max_occuring_char(str1):
  ASCII_SIZE = 256
  ctr = [0] * ASCII_SIZE
  max = -1
  ch = ''
  for i in str1:
    ctr[ord(i)]+=1;
  for i in str1:
    if max < ctr[ord(i)]:
      max = ctr[ord(i)]
      ch = i
  return ch


def is_subset_sum(set, n, sum):
	if (sum == 0):
		return True
	if (n == 0):
		return False
	if (set[n - 1] > sum):
		return is_subset_sum(set, n - 1, sum)
	return is_subset_sum(set, n-1, sum) or is_subset_sum(set, n-1, sum-set[n-1])


import re
def match(text):
		pattern = '[A-Z]+[a-z]+$'
		if re.search(pattern, text):
				return('Yes')
		else:
				return('No')


def first_Factorial_Divisible_Number(x):
    i = 1;
    fact = 1;
    for i in range(1,x):
        fact = fact * i
        if (fact % x == 0):
            break
    return i


def remove_matching_tuple(test_list1, test_list2):
  res = [sub for sub in test_list1 if sub not in test_list2]
  return (res)


def is_palindrome(n) :
	divisor = 1
	while (n / divisor >= 10) :
		divisor *= 10
	while (n != 0) :
		leading = n // divisor
		trailing = n % 10
		if (leading != trailing) :
			return False
		n = (n % divisor) // 10
		divisor = divisor // 100
	return True
def largest_palindrome(A, n) :
	A.sort()
	for i in range(n - 1, -1, -1) :
		if (is_palindrome(A[i])) :
			return A[i]
	return -1


def nCr(n, r):
	if (r > n / 2):
		r = n - r
	answer = 1
	for i in range(1, r + 1):
		answer *= (n - r + i)
		answer /= i
	return answer
def binomial_probability(n, k, p):
	return (nCr(n, k) * pow(p, k) *	pow(1 - p, n - k))


def sort_tuple(tup):
	lst = len(tup)
	for i in range(0, lst):
		for j in range(0, lst-i-1):
			if (tup[j][-1] > tup[j + 1][-1]):
				temp = tup[j]
				tup[j]= tup[j + 1]
				tup[j + 1]= temp
	return tup


import math
def area_pentagon(a):
  area=(math.sqrt(5*(5+2*math.sqrt(5)))*pow(a,2))/4.0
  return area


def frequency_Of_Largest(n,arr):
    mn = arr[0]
    freq = 1
    for i in range(1,n):
        if (arr[i] >mn):
            mn = arr[i]
            freq = 1
        elif (arr[i] == mn):
            freq += 1
    return freq


def extract_symmetric(test_list):
  temp = set(test_list) & {(b, a) for a, b in test_list}
  res = {(a, b) for a, b in temp if a < b}
  return (res)


import math
def sum_gp(a,n,r):
 total = (a * (1 - math.pow(r, n ))) / (1- r)
 return total


def binary_search(item_list,item):
	first = 0
	last = len(item_list)-1
	found = False
	while( first<=last and not found):
		mid = (first + last)//2
		if item_list[mid] == item :
			found = True
		else:
			if item < item_list[mid]:
				last = mid - 1
			else:
				first = mid + 1
	return found


import math
def calculate_polygons(startx, starty, endx, endy, radius):
    sl = (2 * radius) * math.tan(math.pi / 6)
    p = sl * 0.5
    b = sl * math.cos(math.radians(30))
    w = b * 2
    h = 2 * sl
    startx = startx - w
    starty = starty - h
    endx = endx + w
    endy = endy + h
    origx = startx
    origy = starty
    xoffset = b
    yoffset = 3 * p
    polygons = []
    row = 1
    counter = 0
    while starty < endy:
        if row % 2 == 0:
            startx = origx + xoffset
        else:
            startx = origx
        while startx < endx:
            p1x = startx
            p1y = starty + p
            p2x = startx
            p2y = starty + (3 * p)
            p3x = startx + b
            p3y = starty + h
            p4x = startx + w
            p4y = starty + (3 * p)
            p5x = startx + w
            p5y = starty + p
            p6x = startx + b
            p6y = starty
            poly = [
                (p1x, p1y),
                (p2x, p2y),
                (p3x, p3y),
                (p4x, p4y),
                (p5x, p5y),
                (p6x, p6y),
                (p1x, p1y)]
            polygons.append(poly)
            counter += 1
            startx += w
        starty += yoffset
        row += 1
    return polygons


def binary_to_integer(test_tup):
  res = int("".join(str(ele) for ele in test_tup), 2)
  return (str(res))


import re
def remove_lowercase(str1):
  remove_lower = lambda text: re.sub('[a-z]', '', text)
  result =  remove_lower(str1)
  return (result)


import heapq as hq
def heap_queue_smallest(nums,n):
  smallest_nums = hq.nsmallest(n, nums)
  return smallest_nums


import math
def surfacearea_cone(r,h):
  l = math.sqrt(r * r + h * h)
  SA = math.pi * r * (r + l)
  return SA


def gcd(x, y):
    gcd = 1
    if x % y == 0:
        return y
    for k in range(int(y / 2), 0, -1):
        if x % k == 0 and y % k == 0:
            gcd = k
            break
    return gcd


def diameter_circle(r):
  diameter=2*r
  return diameter


def concatenate_elements(list):
  ans = ' '
  for i in list:
    ans = ans+ ' '+i
  return (ans)


def ngcd(x,y):
    i=1
    while(i<=x and i<=y):
        if(x%i==0 and y%i == 0):
            gcd=i;
        i+=1
    return gcd;
def num_comm_div(x,y):
  n = ngcd(x,y)
  result = 0
  z = int(n**0.5)
  i = 1
  while(i <= z):
    if(n % i == 0):
      result += 2
      if(i == n/i):
        result-=1
    i+=1
  return result


def find(n,m):
  r = n%m
  return (r)


def add_consecutive_nums(nums):
    result = [b+a for a, b in zip(nums[:-1], nums[1:])]
    return result


def sum_Of_Series(n):
    sum = 0
    for i in range(1,n + 1):
        sum += i * i*i
    return sum


def re_order(A):
    k = 0
    for i in A:
        if i:
            A[k] = i
            k = k + 1
    for i in range(k, len(A)):
        A[i] = 0
    return A


def permutation_coefficient(n, k):
	P = [[0 for i in range(k + 1)]
			for j in range(n + 1)]
	for i in range(n + 1):
		for j in range(min(i, k) + 1):
			if (j == 0):
				P[i][j] = 1
			else:
				P[i][j] = P[i - 1][j] + (
						j * P[i - 1][j - 1])
			if (j < k):
				P[i][j + 1] = 0
	return P[n][k]


def remove_words(list1, removewords):
    for word in list(list1):
        if word in removewords:
            list1.remove(word)
    return list1


def same_order(l1, l2):
    common_elements = set(l1) & set(l2)
    l1 = [e for e in l1 if e in common_elements]
    l2 = [e for e in l2 if e in common_elements]
    return l1 == l2


def average_Odd(n) :
    if (n%2==0) :
        return ("Invalid Input")
        return -1
    sm =0
    count =0
    while (n>=1) :
        count=count+1
        sm = sm + n
        n = n-2
    return sm//count


def no_of_subsequences(arr, k):
	n = len(arr)
	dp = [[0 for i in range(n + 1)]
			for j in range(k + 1)]
	for i in range(1, k + 1):
		for j in range(1, n + 1):
			dp[i][j] = dp[i][j - 1]
			if arr[j - 1] <= i and arr[j - 1] > 0:
				dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1
	return dp[k][n]


def find_Min_Sum(num):
    sum = 0
    i = 2
    while(i * i <= num):
        while(num % i == 0):
            sum += i
            num /= i
        i += 1
    sum += num
    return sum


def flatten(test_tuple):
	for tup in test_tuple:
		if isinstance(tup, tuple):
			yield from flatten(tup)
		else:
			yield tup
def count_element_freq(test_tuple):
  res = {}
  for ele in flatten(test_tuple):
    if ele not in res:
      res[ele] = 0
    res[ele] += 1
  return (res)


def add_str(test_tup, K):
  res = [ele for sub in test_tup for ele in (sub, K)]
  return (res)


def sum_elements(test_tup):
  res = sum(list(test_tup))
  return (res)


def modular_sum(arr, n, m):
	if (n > m):
		return True
	DP = [False for i in range(m)]
	for i in range(n):
		if (DP[0]):
			return True
		temp = [False for i in range(m)]
		for j in range(m):
			if (DP[j] == True):
				if (DP[(j + arr[i]) % m] == False):
					temp[(j + arr[i]) % m] = True
		for j in range(m):
			if (temp[j]):
				DP[j] = True
		DP[arr[i] % m] = True
	return DP[0]


def radix_sort(nums):
    RADIX = 10
    placement = 1
    max_digit = max(nums)

    while placement < max_digit:
      buckets = [list() for _ in range( RADIX )]
      for i in nums:
        tmp = int((i / placement) % RADIX)
        buckets[tmp].append(i)
      a = 0
      for b in range( RADIX ):
        buck = buckets[b]
        for i in buck:
          nums[a] = i
          a += 1
      placement *= RADIX
    return nums


def largest_pos(list1):
    max = list1[0]
    for x in list1:
        if x > max :
             max = x
    return max


import math
def sqrt_root(num):
 sqrt_root = math.pow(num, 0.5)
 return sqrt_root


import math
def volume_tetrahedron(num):
	volume = (num ** 3 / (6 * math.sqrt(2)))
	return round(volume, 2)


def find_lcm(num1, num2):
	if(num1>num2):
		num = num1
		den = num2
	else:
		num = num2
		den = num1
	rem = num % den
	while (rem != 0):
		num = den
		den = rem
		rem = num % den
	gcd = den
	lcm = int(int(num1 * num2)/int(gcd))
	return lcm
def get_lcm(l):
  num1 = l[0]
  num2 = l[1]
  lcm = find_lcm(num1, num2)
  for i in range(2, len(l)):
    lcm = find_lcm(lcm, l[i])
  return lcm


def check_isosceles(x,y,z):
  if x!=y & y!=z & z!=x:
	   return True
  else:
     return False


def lbs(arr):
	n = len(arr)
	lis = [1 for i in range(n+1)]
	for i in range(1 , n):
		for j in range(0 , i):
			if ((arr[i] > arr[j]) and (lis[i] < lis[j] +1)):
				lis[i] = lis[j] + 1
	lds = [1 for i in range(n+1)]
	for i in reversed(range(n-1)):
		for j in reversed(range(i-1 ,n)):
			if(arr[i] > arr[j] and lds[i] < lds[j] + 1):
				lds[i] = lds[j] + 1
	maximum = lis[0] + lds[0] - 1
	for i in range(1 , n):
		maximum = max((lis[i] + lds[i]-1), maximum)
	return maximum


def check_string(str1):
    messg = [
    lambda str1: any(x.isupper() for x in str1) or 'String must have 1 upper case character.',
    lambda str1: any(x.islower() for x in str1) or 'String must have 1 lower case character.',
    lambda str1: any(x.isdigit() for x in str1) or 'String must have 1 number.',
    lambda str1: len(str1) >= 7                 or 'String length should be atleast 8.',]
    result = [x for x in [i(str1) for i in messg] if x != True]
    if not result:
        result.append('Valid string.')
    return result


def max_sum_increasing_subsequence(arr, n):
	max = 0
	msis = [0 for x in range(n)]
	for i in range(n):
		msis[i] = arr[i]
	for i in range(1, n):
		for j in range(i):
			if (arr[i] > arr[j] and
				msis[i] < msis[j] + arr[i]):
				msis[i] = msis[j] + arr[i]
	for i in range(n):
		if max < msis[i]:
			max = msis[i]
	return max


def parallel_lines(line1, line2):
  return line1[0]/line1[1] == line2[0]/line2[1]


def capitalize_first_last_letters(str1):
     str1 = result = str1.title()
     result =  ""
     for word in str1.split():
        result += word[:-1] + word[-1].upper() + " "
     return result[:-1]


def get_pairs_count(arr, n, sum):
    count = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            if arr[i] + arr[j] == sum:
                count += 1
    return count


def min_length(list1):
   min_length = min(len(x) for x in  list1 )
   min_list = min((x) for x in   list1)
   return(min_length, min_list)


def jacobsthal_lucas(n):
	dp=[0] * (n + 1)
	dp[0] = 2
	dp[1] = 1
	for i in range(2, n+1):
		dp[i] = dp[i - 1] + 2 * dp[i - 2];
	return dp[n]


from array import array
def negative_count(nums):
    n = len(nums)
    n1 = 0
    for x in nums:
        if x < 0:
            n1 += 1
        else:
          None
    return round(n1/n,2)


import sys
def min_coins(coins, m, V):
    if (V == 0):
        return 0
    res = sys.maxsize
    for i in range(0, m):
        if (coins[i] <= V):
            sub_res = min_coins(coins, m, V-coins[i])
            if (sub_res != sys.maxsize and sub_res + 1 < res):
                res = sub_res + 1
    return res


def check_permutation(str1, str2):
  n1=len(str1)
  n2=len(str2)
  if(n1!=n2):
    return False
  a=sorted(str1)
  str1=" ".join(a)
  b=sorted(str2)
  str2=" ".join(b)
  for i in range(0, n1, 1):
    if(str1[i] != str2[i]):
      return False
  return True


def remove_datatype(test_tuple, data_type):
  res = []
  for ele in test_tuple:
    if not isinstance(ele, data_type):
      res.append(ele)
  return (res)


import re
def search_literal(pattern,text):
 match = re.search(pattern, text)
 s = match.start()
 e = match.end()
 return (s, e)


def topbottom_surfacearea(r):
  toporbottomarea=3.1415*r*r
  return toporbottomarea


def nth_items(list,n):
 return list[::n]


def first_repeated_word(str1):
  temp = set()
  for word in str1.split():
    if word in temp:
      return word;
    else:
      temp.add(word)
  return 'None'


def string_list_to_tuple(str1):
    result = tuple(x for x in str1 if not x.isspace())
    return result


def basesnum_coresspondingnum(bases_num,index):
  result = list(map(pow, bases_num, index))
  return result


def find_Diff(arr,n):
    arr.sort()
    count = 0; max_count = 0; min_count = n
    for i in range(0,(n-1)):
        if arr[i] == arr[i + 1]:
            count += 1
            continue
        else:
            max_count = max(max_count,count)
            min_count = min(min_count,count)
            count = 0
    return max_count - min_count


import math
def get_sum(n):
	sum = 0
	i = 1
	while i <= (math.sqrt(n)):
		if n%i == 0:
			if n/i == i :
				sum = sum + i
			else:
				sum = sum + i
				sum = sum + (n / i )
		i = i + 1
	sum = sum - n
	return sum
def check_abundant(n):
	if (get_sum(n) > n):
		return True
	else:
		return False


import re
def fill_spaces(text):
  return (re.sub("[ ,.]", ":", text))


def count_digits(num1,num2):
    number=num1+num2
    count = 0
    while(number > 0):
        number = number // 10
        count = count + 1
    return count


def flatten_tuple(test_list):
  res = ' '.join([idx for tup in test_list for idx in tup])
  return (res)


def take_L_and_F_set_bits(n) :
    n = n | n >> 1
    n = n | n >> 2
    n = n | n >> 4
    n = n | n >> 8
    n = n | n >> 16
    return ((n + 1) >> 1) + 1
def toggle_F_and_L_bits(n) :
    if (n == 1) :
        return 0
    return n ^ take_L_and_F_set_bits(n)


def last_occurence_char(string,char):
 flag = -1
 for i in range(len(string)):
     if(string[i] == char):
         flag = i
 if(flag == -1):
    return None
 else:
    return flag + 1


def Total_Hamming_Distance(n):
    i = 1
    sum = 0
    while (n // i > 0):
        sum = sum + n // i
        i = i * 2
    return sum


def longest_increasing_subsequence(arr):
	n = len(arr)
	longest_increasing_subsequence = [1]*n
	for i in range (1 , n):
		for j in range(0 , i):
			if arr[i] > arr[j] and longest_increasing_subsequence[i]< longest_increasing_subsequence[j] + 1 :
				longest_increasing_subsequence[i] = longest_increasing_subsequence[j]+1
	maximum = 0
	for i in range(n):
		maximum = max(maximum , longest_increasing_subsequence[i])
	return maximum


def odd_Num_Sum(n) :
    j = 0
    sm = 0
    for i in range(1,n+1) :
        j = (2*i-1)
        sm = sm + (j*j*j*j*j)
    return sm


def find_Max(arr,low,high):
    if (high < low):
        return arr[0]
    if (high == low):
        return arr[low]
    mid = low + (high - low) // 2
    if (mid < high and arr[mid + 1] < arr[mid]):
        return arr[mid]
    if (mid > low and arr[mid] < arr[mid - 1]):
        return arr[mid - 1]
    if (arr[low] > arr[mid]):
        return find_Max(arr,low,mid - 1)
    else:
        return find_Max(arr,mid + 1,high)


def extract_column(list1, n):
   result = [i.pop(n) for i in list1]
   return result


def Seq_Linear(seq_nums):
  seq_nums = [seq_nums[x] - seq_nums[x-1] for x in range(1, len(seq_nums))]
  if len(set(seq_nums)) == 1:
    return "Linear Sequence"
  else:
    return "Non Linear Sequence"


def tuple_to_float(test_tup):
  res = float('.'.join(str(ele) for ele in test_tup))
  return (res)


def Split(list):
    od_li = []
    for i in list:
        if (i % 2 != 0):
            od_li.append(i)
    return od_li


def difference(n) :
    S = (n*(n + 1))//2;
    res = S*(S-1);
    return res;


def find_Odd_Pair(A,N) :
    oddPair = 0
    for i in range(0,N) :
        for j in range(i+1,N) :
            if ((A[i] ^ A[j]) % 2 != 0):
                oddPair+=1
    return oddPair


def toggle_string(string):
 string1 = string.swapcase()
 return string1


def digit_distance_nums(n1, n2):
         return sum(map(int,str(abs(n1-n2))))


def max_sub_array_sum(a, size):
  max_so_far = 0
  max_ending_here = 0
  for i in range(0, size):
    max_ending_here = max_ending_here + a[i]
    if max_ending_here < 0:
      max_ending_here = 0
    elif (max_so_far < max_ending_here):
      max_so_far = max_ending_here
  return max_so_far


def union_elements(test_tup1, test_tup2):
  res = tuple(set(test_tup1 + test_tup2))
  return (res)


def assign_elements(test_list):
  res = dict()
  for key, val in test_list:
    res.setdefault(val, [])
    res.setdefault(key, []).append(val)
  return (res)


def Find_Max_Length(lst):
    maxLength = max(len(x) for x in lst )
    return maxLength


import re
def extract_values(text):
 return (re.findall(r'"(.*?)"', text))


def count_Pairs(arr,n):
    cnt = 0;
    for i in range(n):
        for j in range(i + 1,n):
            if (arr[i] != arr[j]):
                cnt += 1;
    return cnt;


def split(word):
    return [char for char in word]


def sum_digits(n):
  if n == 0:
    return 0
  else:
    return n % 10 + sum_digits(int(n / 10))