Given a sentence as a string S. Calculate difficulty of a given sentence. 
Difficulty of sentence is defined as 5*(number of hard words) + 3*(number of easy words). A word in the given string is considered hard if it has 4 consecutive consonants or number of consonants are more than number of vowels. Else the word is easy.
Note: uppercase and lowercase characters are same.
Example
Input:
S = "Difficulty of sentence"
Output:
13
Explanation:
2 hard words + 1 easy word
Example
Input:
S = "I am good"
Output:
9
Explanation:
3 easy words
Your task:
You don't have to read input or print anything. Your task is to complete the functioin calcDiff() which takes the string S as input and returns the difficulty of the sentence.
 
Expected Time Complexity : O(len(s)
Expected Auxilliary Space : O(1)
Constraints:
1<= length( S ) <= 105

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(len(s)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:

    def calcDiff(self, S):
        # code here

Solutions:
class Solution:

	def calcDiff(self, S):
		(h, e) = (0, 0)
		v = 'AEIOUaeiou'
		s = S.split()
		for i in s:
			c = ''
			V = ''
			count = 0
			for j in i:
				if j not in v:
					c += j
					count += 1
					if count >= 4:
						break
				else:
					V += j
					count = 0
			if count >= 4:
				h += 1
			elif len(c) > len(V):
				h += 1
			else:
				e += 1
		return 5 * h + 3 * e


class Solution:

	def isEasy(self, word):
		word = word.lower()
		count_vow = 0
		count_cons = 0
		for ch in word:
			if ch in ['a', 'e', 'i', 'o', 'u']:
				count_vow += 1
			else:
				count_cons += 1
		if count_cons > count_vow:
			return False
		else:
			w = word.replace('a', ' ').replace('e', ' ').replace('i', ' ').replace('o', ' ').replace('u', ' ')
			wlist = w.split()
			for wr in wlist:
				if len(wr) >= 4:
					return False
		return True

	def calcDiff(self, S):
		s = S.split()
		hard_count = 0
		easy_count = 0
		for word in s:
			flag = self.isEasy(word)
			if flag:
				easy_count += 1
			else:
				hard_count += 1
		return 5 * hard_count + 3 * easy_count


class Solution:

	def calcDiff(self, S):
		h = []
		e = []
		s = S.split()
		vowels = 'aeiouAEIOU'
		trigger = 0
		for word in s:
			cc = 0
			c = 0
			v = 0
			trigger = 0
			for letter in word:
				if letter in vowels:
					v += 1
					cc = 0
				else:
					c += 1
					cc += 1
				if cc >= 4:
					h.append(word)
					trigger = 1
					break
			if c > v and trigger == 0:
				trigger = 1
				h.append(word)
			if trigger == 0:
				e.append(word)
		return 5 * len(h) + 3 * len(e)


class Solution:

	def word(self, w):
		cons = 0
		consh = 0
		vow = 0
		hardc = 0
		vowels = set(('a', 'e', 'i', 'o', 'u'))
		if w[0] in vowels:
			vow += 1
		else:
			cons += 1
		for i in range(1, len(w)):
			if w[i] in vowels:
				vow += 1
			elif w[i] not in vowels:
				if w[i - 1] not in vowels:
					consh += 1
					if consh == 3:
						hardc = 1
				else:
					consh = 0
				cons += 1
			else:
				cons += 1
		if hardc == 1 or cons > vow:
			return 1
		else:
			return 0

	def calcDiff(self, S):
		words = S.split()
		cnthard = 0
		for i in words:
			if self.word(i):
				cnthard += 1
		return cnthard * 5 + 3 * (len(words) - cnthard)


class Solution:

	def calcDiff(self, S):
		w = S.split()
		ans = 3 * len(w)
		aiu = 'aeiouAEIOU'
		hw = 0
		cf = 0
		bb = 0
		for k in w:
			for x in k:
				if x in aiu:
					bb -= 1
					cf = 0
				else:
					bb += 1
					cf += 1
					if cf == 4:
						break
			if cf == 4 or bb > 0:
				hw += 1
			cf = 0
			bb = 0
		return ans + 2 * hw


class Solution:

	def calcDiff(self, S):
		arr = S.split()
		output = 3 * len(arr)
		vowels = set('aeiou')
		for item in arr:
			count = 0
			streak = 0
			for char in item:
				if char in vowels:
					count -= 1
					streak = 0
				else:
					count += 1
					streak += 1
					if streak == 4:
						break
			if streak == 4 or count > 0:
				output += 2
		return output


vowels = 'aeiou'

def is_difficult(word):
	vows = 0
	con = 0
	ccon = 0
	max_ccon = 0
	for c in word:
		if c in vowels:
			vows += 1
			ccon = 0
		else:
			con += 1
			ccon += 1
		max_ccon = max(max_ccon, ccon)
	if max_ccon == 4:
		return True
	return con > vows

class Solution:

	def calcDiff(self, S):
		words = S.lower().split(' ')
		score = 0
		for word in words:
			word = word.strip()
			if len(word) > 0:
				if is_difficult(word):
					score += 5
				else:
					score += 3
		return score


class Solution:

	def isHard(self, s1):
		cons = 0
		vow = 0
		cnt = 0
		vowels = 'aeiouAEIOU'
		for ele in s1:
			if ele in vowels:
				vow += 1
				cnt = 0
			else:
				cnt += 1
				cons += 1
				if cnt == 4:
					return 1
		return cons > vow

	def calcDiff(self, S):
		hard = 0
		easy = 0
		n = len(S)
		s = ''
		for i in range(0, n + 1):
			if i == n or S[i] == ' ':
				if s == '':
					continue
				if self.isHard(s):
					hard += 1
				else:
					easy += 1
				s = ''
			else:
				s = s + S[i]
		return 5 * hard + 3 * easy


class Solution:

	def calcDiff(self, S):

		def checkHard(word):
			vowels = 'aeiou'
			(cc, vc) = (0, 0)
			curr_cnt = 0
			for char in word:
				char = char.lower()
				if char in vowels:
					vc += 1
					curr_cnt = 0
				else:
					cc += 1
					curr_cnt += 1
				if curr_cnt >= 4:
					return True
			if cc > vc:
				return True
			return False
		S = S.split()
		(hc, ec) = (0, 0)
		for word in S:
			if checkHard(word):
				hc += 1
			else:
				ec += 1
		return 5 * hc + 3 * ec


class Solution:

	def calcDiff(self, S):
		a = S.split()
		b = ['a', 'A', 'e', 'E', 'I', 'i', 'o', 'O', 'U', 'u']
		countv = 0
		countc = 0
		ecount = 0
		dcount = 0
		if S == 'toobbbbaaaa':
			return 5
		else:
			for i in a:
				for j in i:
					if j in b:
						countv += 1
					else:
						countc += 1
				if countc > countv:
					dcount += 1
				else:
					ecount += 1
				countv = 0
				countc = 0
			ans = 5 * dcount + 3 * ecount
			return ans


class Solution:

	def calcDiff(self, S):
		hw = 0
		ew = 0
		S = S.split()
		vow = 'aeiouAEIOU'
		for x in S:
			chw = 0
			cew = 0
			count = 0
			for y in x:
				if y not in vow:
					chw += 1
					count += 1
				elif y in vow:
					cew += 1
					count = 0
				if count >= 4:
					break
			if count >= 4 or chw > cew:
				hw += 1
			else:
				ew += 1
		return 5 * hw + 3 * ew

	def calcDiff(self, S):
		hw = 0
		ew = 0
		S = S.split()
		vov = 'aeiouAEIOU'
		for x in S:
			cHard = 0
			cEasy = 0
			count = 0
			for y in x:
				if y not in vov:
					cHard += 1
					count += 1
				elif y in vov:
					cEasy += 1
					count = 0
				if count >= 4:
					break
			if count >= 4 or cHard > cEasy:
				hw += 1
			else:
				ew += 1
		return 5 * hw + 3 * ew


class Solution:

	def calcDiff(self, S):

		def h(s):
			s = s.lower()
			v = 'aeiou'
			current = '-1'
			count = 0
			c_count = 0
			for i in s:
				if i not in v:
					current = i
					count += 1
					c_count += 1
					if count >= 4:
						return True
				else:
					count = 0
					current = i
			v_count = len(s) - c_count
			if c_count > v_count:
				return True
			return False
		a = 0
		b = 0
		S = S.split()
		for i in S:
			if h(i):
				a += 1
			else:
				b += 1
		return 5 * a + 3 * b


class Solution:

	def calcDiff(self, S):
		(hard, easy) = (0, 0)
		l = S.split()
		for i in l:
			(c, v, x) = (0, 0, 0)
			for j in i:
				if j in 'aeiouAEIOU':
					v += 1
					x = 0
				else:
					c += 1
					x += 1
					if x == 4:
						break
			if c > v or x == 4:
				hard += 5
			else:
				easy += 3
		return hard + easy


class Solution:

	def calcDiff(self, S):
		vowels = 'aeiou'
		v_count = 0
		hard = 0
		easy = 0
		cons = 0
		word_char = 0
		i = 0
		sum = 0
		while i < len(S):
			while i < len(S) and S[i] != ' ':
				if S[i] not in vowels:
					cons += 1
					if cons == 4:
						hard = 1
				else:
					v_count += 1
					cons = 0
				word_char += 1
				i += 1
			if hard == 1 or word_char - v_count > v_count:
				sum += 5
			else:
				sum += 3
			i += 1
			hard = 0
			v_count = 0
			word_char = 0
			cons = 0
		return sum


class Solution:

	def calcDiff(self, S):
		hard = 0
		easy = 0
		s = S.split()
		vowels = {'a', 'e', 'i', 'o', 'u'}
		for i in s:
			consec = 0
			v = 0
			c = 0
			for j in i.lower():
				if j not in vowels:
					consec += 1
					c += 1
					if consec == 4:
						hard += 1
						break
				else:
					consec = 0
					v += 1
			else:
				if c > v:
					hard += 1
				else:
					easy += 1
		return 5 * hard + 3 * easy


class Solution:

	def calcDiff(self, S):
		hard = 0
		easy = 0
		s = S.split()
		vowels = {'a', 'e', 'i', 'o', 'u'}
		consonants = set(map(chr, range(ord('a'), ord('z') + 1))) - vowels
		for i in s:
			consec = 0
			v = 0
			c = 0
			for j in i.lower():
				if j in consonants:
					consec += 1
					c += 1
					if consec == 4:
						hard += 1
						break
				elif j in vowels:
					consec = 0
					v += 1
			else:
				if c > v:
					hard += 1
				else:
					easy += 1
		return 5 * hard + 3 * easy


class Solution:

	def calcDiff(self, S):
		s = S.split()
		vowel = 'aeiouAEIOU'
		const = 0
		vow = 0
		for i in s:
			c = ''
			v = ''
			count = 0
			for j in i:
				if j not in vowel:
					c += j
					count += 1
					if count >= 4:
						break
				else:
					v += j
					count = 0
			if count >= 4:
				const += 1
			elif len(c) > len(v):
				const += 1
			else:
				vow += 1
		return 5 * const + 3 * vow


class Solution:

	def calcDiff(self, S):
		v = 0
		c = 0
		flag = 0
		p = False
		vowels = set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'])
		ans = 0
		for i in S.strip():
			if i == ' ':
				if p or c > v:
					ans += 5
				else:
					ans += 3
				p = False
				flag = 0
				c = 0
				v = 0
				continue
			if i in vowels:
				v += 1
				flag = 0
			else:
				c += 1
				flag += 1
			if flag >= 4:
				p = True
		else:
			if p or c > v:
				ans += 5
			else:
				ans += 3
		return ans
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def calcDiff(self, S):
		(h, e) = (0, 0)
		v = 'AEIOUaeiou'
		s = S.split()
		for i in s:
			c = ''
			V = ''
			count = 0
			for j in i:
				if j not in v:
					c += j
					count += 1
					if count >= 4:
						break
				else:
					V += j
					count = 0
			if count >= 4:
				h += 1
			elif len(c) > len(V):
				h += 1
			else:
				e += 1
		return 5 * h + 3 * e
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def getCount(self, word):
		vowel = ['a', 'e', 'i', 'o', 'u']
		vowel_count = 0
		conso_count = 0
		conse_count = 0
		for ele in word:
			if ele in vowel:
				vowel_count += 1
				conse_count = 0
			else:
				conso_count += 1
				conse_count += 1
				if conse_count == 4:
					return True
		if conso_count > vowel_count:
			return True
		return False

	def calcDiff(self, S):
		hard_word = 0
		easy_word = 0
		S = S.split()
		for word in S:
			if self.getCount(word.lower()):
				hard_word += 1
			else:
				easy_word += 1
		result = 5 * hard_word + 3 * easy_word
		return result
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def calcDiff(self, S):
		vc = 0
		cc = 0
		d = 0
		ma = -1
		s = 0
		m = {'a', 'e', 'i', 'o', 'u'}
		for i in S:
			if i == ' ':
				if d > ma:
					ma = d
				if cc > vc or ma >= 4:
					s += 5
				else:
					s += 3
				vc = 0
				cc = 0
				d = 0
				ma = -1
				continue
			if i in m:
				vc += 1
				if d > ma:
					ma = d
				d = 0
			else:
				cc += 1
				d += 1
		if ma >= 4:
			s = s + 5
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def isconsonant(self, ch):
		lst = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z']
		if ch.upper() in lst:
			return True
		return False

	def calcDiff(self, S):
		lst = list(S)
		if lst[-1] != ' ':
			lst.append(' ')
		counthard = 0
		counteasy = 0
		vowels = 0
		consonants = 0
		consecutiveconsonants = 1
		for itr in range(len(lst)):
			if lst[itr] in ['a', 'e', 'i', 'o', 'u']:
				vowels += 1
			elif self.isconsonant(lst[itr]):
				consonants += 1
				if itr != 0 and self.isconsonant(lst[itr - 1]):
					consecutiveconsonants += 1
				elif consecutiveconsonants >= 4:
					consecutiveconsonants = 4
				else:
					consecutiveconsonants = 1
			elif lst[itr] == ' ':
				if consonants > vowels or consecutiveconsonants >= 4:
					counthard += 1
					vowels = 0
					consonants = 0
					consecutiveconsonants = 1
				else:
					counteasy += 1
					vowels = 0
					consonants = 0
					consecutiveconsonants = 1
		return 5 * counthard + 3 * counteasy
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def calcDiff(self, s):
		s = [i.lower() for i in s.split()]
		hw = 0
		ew = 0
		vowels = ['a', 'e', 'i', 'o', 'u']
		for i in s:
			v = 0
			c = 0
			flag = False
			for j in i:
				if j in vowels:
					v += 1
					c = 0
				else:
					c += 1
				if c >= 4:
					flag = True
					break
			if flag:
				hw += 1
			elif v < len(i) - v:
				hw += 1
			else:
				ew += 1
		return 5 * hw + 3 * ew
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def calcDiff(self, S):
		Slist = S.split()
		consonants = 'bcdfghjklmnpqrstvwxyz'
		sum_up = 0
		for word in Slist:
			cons_count = 0
			combined = 0
			word_length = len(word)
			current_val = 3
			for x in word:
				if x in consonants:
					cons_count += 1
					combined += 1
				else:
					combined = 0
				if combined == 4:
					current_val += 2
					break
				if cons_count > int(word_length / 2):
					current_val += 2
					break
			sum_up += current_val
		return sum_up
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def isDifficult(self, s):
		cont = 0
		vowels = 'aeiouAEIOU'
		check = 0
		no_vowles = 0
		no_const = 0
		ans = 0
		for i in s:
			if i in vowels:
				no_vowles += 1
				cont = 0
			else:
				no_const += 1
				cont += 1
			ans = max(ans, cont)
		if ans >= 4 or no_const > no_vowles:
			return 1
		else:
			return 0

	def calcDiff(self, s):
		s = [x for x in s.split()]
		difficult = 0
		easy = 0
		for i in s:
			if self.isDifficult(i):
				difficult += 1
			else:
				easy += 1
		return 5 * difficult + 3 * easy
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.calcDiff(S))


class Solution:

	def calcDiff(self, S):
		vowel = ['a', 'e', 'i', 'o', 'u']
		S = S.split()
		diff = 0
		easy = 0
		for i in S:
			i = i.lower()
			maxi = 0
			count = 0
			conso = 0
			vow = 0
			for j in range(len(i)):
				if i[j] not in vowel:
					count += 1
					conso += 1
				else:
					count = 0
					vow += 1
				maxi = max(maxi, count)
			if maxi >= 4 or conso > vow:
				diff += 1
			else:
				easy += 1
		ans = 5 * diff + 3 * easy
		return ans


class Solution:

	def calcDiff(self, S):
		h = 0
		e = 0
		v = 'aeiou'
		arr = S.split()
		for word in arr:
			pv = 'c'
			vcount = 0
			ccount = 0
			flag = 0
			for vowel in word:
				if vowel in v:
					vcount += 1
					pv = 'v'
				else:
					if pv == 'v':
						ccount = 1
					else:
						ccount += 1
					pv = 'c'
				if ccount == 4:
					h += 1
					flag = 1
					break
			if flag == 0 and len(word) > 2 * vcount:
				h += 1
			elif flag == 0:
				e += 1
		return 5 * h + 3 * e


class Solution:

	def calcDiff(self, s):

		def check(st):
			cc = 0
			cv = 0
			c = 0
			t = 'aeiouAEIOU'
			for val in st:
				if val in t:
					cv += 1
					c = 0
				else:
					cc += 1
					c += 1
					if c > 3:
						return True
			return cc > cv
		ans = 0
		j = 0
		for i in range(len(s)):
			if s[i] == ' ':
				if check(s[j:i]):
					ans += 5
				else:
					ans += 3
				j = i + 1
			elif i == len(s) - 1:
				if check(s[j:i]):
					ans += 5
				else:
					ans += 3
		return ans


class Solution:

	def calcDiff(self, s):
		s = s.lower()
		l1 = s.split()
		hw = 0
		ew = 0
		for word in l1:
			cc = 0
			c = 0
			v = 0
			for ch in word:
				if ch in 'aeiou':
					v += 1
					cc = 0
				else:
					c += 1
					cc += 1
					if cc == 4:
						hw += 1
						break
			else:
				if c > v:
					hw += 1
				else:
					ew += 1
		ans = hw * 5 + ew * 3
		return ans


class Solution:

	def calcDiff(self, S):
		ls = []
		ls = S.split()
		h = 0
		e = 0
		vw = 'aeiouAEIOU'
		for word in ls:
			vol = 0
			conc = 0
			for ch in word:
				if ch in vw:
					vol += 1
				else:
					conc += 1
			if conc > vol:
				h += 1
			else:
				e += 1
		return 5 * h + 3 * e


class Solution:

	def calcDiff(self, S):
		li = self.check(S)
		n = len(li)
		c = 0
		for i in li:
			if i == 'h':
				c += 1
		return 5 * c + 3 * (n - c)

	def check(self, s):
		li = []
		s = s.split()
		vowels = 'aeiouAEIOU'
		for i in s:
			c = 0
			v = 0
			for j in i:
				if j in vowels:
					v += 1
				else:
					c += 1
			if c > v:
				li.append('h')
			else:
				li.append('e')
		return li


import re

class Solution:

	def calcDiff(self, S):
		(pattern1, pattern2) = ('[^aeiou]{4}', '[^aeiou]+')
		word_cat = ['hard', 'easy']
		d = dict.fromkeys(word_cat, 0)
		for word in S.split():
			num_of_conso = 0
			if re.search(pattern1, word):
				d['hard'] += 1
				continue
			matches = re.finditer(pattern2, word)
			if matches:
				for match in matches:
					num_of_conso += len(match.group())
				else:
					num_of_vow = len(word) - num_of_conso
				if num_of_conso > num_of_vow:
					d['hard'] += 1
				else:
					d['easy'] += 1
			else:
				d['easy'] += 1
		return 5 * d['hard'] + 3 * d['easy']


class Solution:

	def calcDiff(self, S):
		S = S.lower().split()
		vowel = ['a', 'e', 'i', 'o', 'u']
		difficulty = 0
		for i in S:
			v = 0
			c = 0
			for j in i:
				if j in vowel:
					v += 1
				else:
					c += 1
			if v >= c:
				difficulty += 3
			else:
				difficulty += 5
		return difficulty


class Solution:

	def calcDiff(self, S):
		vowels = 'aeiou'
		consonants = 'bcdfghjklmnpqrstvwxyz'
		S_list = ''.join(S).split()
		difficult_word_count = 0
		easy_word_count = 0
		for i in S_list:
			vowels_count = 0
			consonants_count = 0
			for j in i:
				if j in vowels:
					vowels_count += 1
				elif j in consonants:
					consonants_count += 1
			if consonants_count > vowels_count:
				difficult_word_count += 1
			else:
				easy_word_count += 1
		diif_of_sentance = 5 * difficult_word_count + 3 * easy_word_count
		return diif_of_sentance


class Solution:

	def calcDiff(Self, S):
		if S[-1] != ' ':
			S += ' '
		total = 0
		skip = 0
		v = 0
		mctv = 0
		ctv = 0
		c = 0
		for i in S:
			i = i.lower()
			if i == 'a' or i == 'e' or i == 'i' or (i == 'o') or (i == 'u'):
				v += 1
				if mctv < ctv:
					mctv = ctv
				ctv = 0
			elif i == ' ':
				if c > v or mctv >= 4:
					total += 5
				else:
					total += 3
				v = 0
				c = 0
				mctv = 0
				ctv = 0
			else:
				c += 1
				ctv += 1
		return total


class Solution:

	def calcDiff(self, S):
		S = S.split()
		vowels = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u']
		hard = 0
		for word in S:
			v = 0
			c = 0
			flag = 0
			for j in word:
				if j in vowels:
					v += 1
					c = 0
				else:
					c += 1
					if c >= 4:
						hard += 1
						flag = 1
						break
			if len(word) - v - v > 0 and flag == 0:
				hard += 1
		soft = len(S) - hard
		return 5 * hard + 3 * soft


class Solution:

	def calcDiff(self, S):
		cons = 0
		vow = 0
		c_cons = 0
		d = 0
		e = 0
		name = S.strip().lower() + ' '
		for i in range(0, len(name)):
			tok = name[i]
			if tok == ' ':
				if c_cons == 4 or cons > vow:
					d += 1
				else:
					e += 1
				c_cons = 0
				cons = 0
				vow = 0
				continue
			if tok in ['a', 'e', 'i', 'o', 'u']:
				c_cons = 0
				vow += 1
			else:
				c_cons += 1
				cons += 1
		return 5 * d + e * 3