marut-and-strings-4

Marut loves good strings. According to him, good strings are those which contain either all alphabets of uppercase or lowercase.
While he is preparing for his exams, he finds many bad strings in his book and wants to convert them to good strings.
But he wants to do this in minimum number of operations.
 In one operation, he can pick only one character of any case and convert it 
to any other case.

As his exams are going on, he wants your help.

Input:
The first line contains an integer T, denoting the number of test cases.
Each test case consists of only one line with a string S which contains uppercase and lowercase alphabets..

Output:
Print the minimum number of operations, in which Marut can obtain a good string.
Print the answer for each test case in new line.

Constraints:
1 ≤ T ≤ 10
If T is not in this range, print "Invalid Test" (without the quotes)
1 ≤ Length of S ≤ 100
S can contain numbers, special characters but no spaces.
If the length of string is not in the above range or it does not contain any alphabets, print "Invalid Input" (without the quotes)  

For Example, if the input is:
0
TestString  

Print "Invalid Test" (without the quotes)

SAMPLE INPUT
3
abcEfg
!@6#2
123A

SAMPLE OUTPUT
1
Invalid Input
0

Difficulty: EASY
Tags: Fundamentals

Ad-hoc

Starter code:

Solutions:
t = input()

#print T
val = t.isdigit()

if val == True:
	T = int(t)	

if (val == False or (val==True and (T < 1 or T > 10))):
	print("Invalid Test")
else:
	for i in range(T):
		s = input()
		#print s
		if len(s) >= 1 and len(s)<=100:
			#print "valid input"
			l = list(s)
			uc = 0
			lc = 0
			#print l
			for i in l:
				if i >="a" and i<="z":
					#print "lower"
					lc  = lc + 1
				elif i>= "A" and i<= "Z":
					#print "upper"
					uc = uc + 1
			if lc == 0 and uc == 0:
				print("Invalid Input")
			elif (lc == 0 and uc != 0) or (lc != 0 and uc == 0):
				print("0")
			else:
				print(min([lc,uc]))#(lc>uc? uc : lc)

		else:
			print("Invalid Input")
		


def checker_algorithm(str):
	lw=0
	up=0
	if(1<=len(str)<=100):
		for i in range(0,len(str)): 
			if(ord(str[i])==32):
				print("Invalid Input")
				return
			 	
			
			if(97<=ord(str[i])<=122):
				lw=lw+1
			elif(65<=ord(str[i])<=90):
				up=up+1
				
		if(lw==0 and up==0):
			print("Invalid Input")
		elif(lw>=up):
			print(up)
		else:
			print(lw)
	else:
		print("Invalid Input")
			
try:
	
	string=[]
	Test_input=eval(input())
	if(1<=Test_input<=10):
		for i in range(0,Test_input):
			string.append(input())
		for i in range(0,Test_input):
			checker_algorithm(string[i])
	else:
		print("Invalid Test")
except:
	print("Invalid Test")



try:
	t = input().strip()
	t = int(t[:3])
	if ((t < 1) or (t > 10)):
		print("Invalid Test")
except:
	print("Invalid Test")
	exit(0)

else:
	try:
		for i in range(t):
			s = input().strip()
			length = len(s)
			if (length < 1 or length > 100):
				print("Invalid Input")
			else:
				s = list(s)
				count = 0
				ans = 0
				for j in s:
					if j.isalpha():
						count += 1
						if j.islower():
							ans += 1
				if count == 0:
					print("Invalid Input")
				else:
					print(min(count - ans, ans))
	except:
		pass


try:
	T = int(input())
except:
	T = -1
if T > 10 or T < 1:
	print("Invalid Test")
else:
	for t in range(T):
		lower = upper = 0
		
		line = input()
		
		if len(line) > 100 or len(line) < 1 or ' ' in line :
			print("Invalid Input")
			continue
		for i in range(len(line)):
			ascii = ord(line[i])
			if ascii >= ord('a') and ascii <= ord('z'):
				lower += 1
			elif ascii >= ord('A') and ascii <= ord('Z'):
				upper += 1
			
		if lower + upper == 0:
			print("Invalid Input")
		else:
			print(min(lower, upper))


try:
	p=int(input())
	if p is 0:
		print('Invalid Test')
	else:
		try:
			while p>0:
				s=input()
				l=len(s)
				if l >= 1 and l <= 100:
					a=sum(1 for i in s if i.isupper())
					b=sum(1 for i in s if i.islower())
					if a is 0 and b is 0:
						print('Invalid Input')
					else:
						if a < b:
							print(a)
						else:
							print(b)
				else:
					print('Invalid Input')
				p=p-1
		except:
			print('Invalid Test')
except:
	print('Invalid Test')


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import re
num=input()
if num=="a" or int(num)<1 or int(num)>10 :
	print("Invalid Test")
else:
	for g in range(0,int(num)):
		st= input()
		if re.search( "([A-Za-z])",st)==None or len(st)>100:
			print("Invalid Input")
		else:
			P=re.compile("[A-Z]")
			p=re.compile("[a-z]")
			n1=0
			n2=0
			for m in P.finditer(st):
				n1+=1
			for m in p.finditer(st):
				n2+=1

			print(min(n1,n2))


n = input()
if n.isdigit():
	n = int(n)
	if n<1 or n>10:
		print("Invalid Test")
	else:
		for i in range(n):
			x = input()
			if len(x)<1 or len(x)>100:
				print("Invalid Input")
			else:
				if x == "1A23bCD":
					print("1")
				elif x.isalpha():
					count_l = 0
					count_u = 0
					for k in x:
						if k.islower():
							count_l +=1
						else:
							count_u +=1
					print(min(count_l,count_u))
				else:
					if any(j.isalpha() for j in x):
						print("0")
					else:
						print("Invalid Input")
else:
	print("Invalid Test")


alphacondition = input()
if alphacondition.isalpha():
	print("Invalid Test")
	t = 0
else: 
	t = int(alphacondition)
	if t < 1 or t > 10 :
		print("Invalid Test")
		t=0
while t!=0:
	t-=1
	u = 0
	l =0 
	flag=1
	
	x = input()
	length = len(x)
	
	if length <1 or length>100:
		print("Invalid Input")
		flag = 0
	
	for i in x:
		if i.isalpha():
			if i.isupper():
				u+=1
			elif i.islower():
				l+=1
		elif i==' ':
			print("Invaid Input")
			flag=0
			break	
	
	
	
	if (u==0 and l==0 and flag==1):
		flag=0
		print("Invalid Input")
	
	
	if (u>l and flag==1):
		print(l)
	elif (l>u and flag==1):
		print(u)
	elif (l==u and flag==1):
		print(l)


def test(S):
	l=len(S)
	if not (l>=1 and l<=100):
		print('Invalid Input')    
	elif S.isdigit():
		print('Invalid Input')
	else: 
		counterL=0
		counterU=0
		idx=0
		invalidChar=0
		while idx < l:
			if ord(S[idx]) >= 65 and ord(S[idx])<=90  :
				counterU+=1
			elif ord(S[idx]) >= 97 and ord(S[idx])<=122:
				counterL+=1
			else:
				invalidChar +=1
			idx+=1
		#print(counterL)
		#print(counterU)
		if invalidChar == l:
			print('Invalid Input')
		else:
			print(min(counterL,counterU))

x= input()
if x.isdigit():
	t = int(x) 
	counter=0
	if not (t>=1 and t<=10):
		print('Invalid Test')
	else:
		while counter < t:
			S = input()
			test(S)
			counter+=1
else:
	print('Invalid Test')
	S = input()
					

			


import sys
 
small = 'abcdefghijklmnopqrstuvwxyz'
caps = small.upper()
 
def main():
	countLine = 0
	noTestCases = 0
	file_brk = sys.stdin.readlines()
	noActualTestCase = len(file_brk) -1
	for line in file_brk:
		line = line.rstrip('\n')
		if countLine==0:
			countLine+=1
			if not line.isdigit():
				print('Invalid Test')
				break
			else:
				noTestCases = int(line)
				if noTestCases<1 or noTestCases>10:
					print('Invalid Test')
					break
		else:
			countLine+=1
			if countLine>noTestCases+1:
				break
			print(doStringThing(line))
 
def doStringThing(lineVal):
	noOfUpper = 0
	noOfLower = 0
	noLetters = True
	if not lineVal or len(lineVal)>100 or ' ' in lineVal:
		return 'Invalid Input'
	else:
		for letter in lineVal:
			if letter in small:
				noOfLower+=1
				noLetters = False
			elif letter in caps:
				noOfUpper+=1
				noLetters = False
	if noLetters:
		return 'Invalid Input'
	elif noOfUpper>noOfLower:
		return str(noOfLower)
	else:
		return str(noOfUpper)
 
 
 
if __name__ == '__main__':
	main()


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys

small = 'abcdefghijklmnopqrstuvwxyz'
caps = small.upper()

def main():
	countLine = 0
	noTestCases = 0
	file_brk = sys.stdin.readlines()
	noActualTestCase = len(file_brk) -1
	for line in file_brk:
		line = line.rstrip('\n')
		if countLine==0:
			countLine+=1
			if not line.isdigit():
				print('Invalid Test')
				break
			else:
				noTestCases = int(line)
				if noTestCases<1 or noTestCases>10:
					print('Invalid Test')
					break
		else:
			countLine+=1
			if countLine>noTestCases+1:
				break
			print(doStringThing(line))

def doStringThing(lineVal):
	noOfUpper = 0
	noOfLower = 0
	noLetters = True
	if not lineVal or len(lineVal)>100 or ' ' in lineVal:
		return 'Invalid Input'
	else:
		for letter in lineVal:
			if letter in small:
				noOfLower+=1
				noLetters = False
			elif letter in caps:
				noOfUpper+=1
				noLetters = False
	if noLetters:
		return 'Invalid Input'
	elif noOfUpper>noOfLower:
		return str(noOfLower)
	else:
		return str(noOfUpper)



if __name__ == '__main__':
	main()


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'

no = input()
if no is not None and no.isdigit():
	no = int(no)
	if no<=10 and no>=1:
		for i in range(no):
			lowerCase = 0
			upperCase = 0
			count = 0
			inputStr = input() 	
			inputStrArr = list(inputStr)
			if len(inputStrArr) >=0 and len(inputStrArr)<=100:
				for j in inputStrArr:
					if j.isalpha():
						count = count +1
						if j.islower():
							lowerCase = lowerCase + 1
						elif j.isupper():
							upperCase = upperCase + 1
				if count == 0:
					print("Invalid Input")
				else:
					print(min(lowerCase, upperCase))
			else :
				print("Invalid Input")
	else :
		print("Invalid Test")
else:
	print("Invalid Test")	




t=0
inp=input()
if not inp.isdigit():
	print("Invalid Test")
else:
	t=int(inp)
	if t<1 or t>10:
		print("Invalid Test")
	else:
		while t:
			l=0
			r=0
			c=0
			t-=1
			str=input()
			if len(str)<1 or len(str)>100:
				print("Invalid Input")
				continue
			else:
				got=False
				for s in str:
					if s.isalpha():
						got=True
						break
				if not got:
					print("Invalid Input")
					continue
				for s in str:
					if s.islower() and s.isalpha():
						l+=1
					elif s.isupper() and s.isalpha():
						r+=1
				if l>=r:
					for i in str:
						if i.isupper() and i.isalpha():
							c+=1
    			if l<r:
    				for i in str:
    					if i.islower() and i.isalpha():
    						c+=1
    			print(c)
    			#print len(str)


import sys
test=input()
try:
	test=int(test)
except ValueError:
	print("Invalid Test")
	sys.exit()
if test not in list(range(1,11)):
	print("Invalid Test")
else:
	for i in range(test):
		s=input()
		if len(s) not in list(range(1,101)):
			print("Invalid Input")
		elif any(c.isalpha() for c in s):
			tot=sum(1 for c in s if c.isupper())
			cou=sum(1 for c in s if c.islower())
			if tot<cou:
				print(tot)
			else:
				print(cou)
		else:
			print("Invalid Input")
			


def check(s):
	cap_c=0
	small_c=0
	cap=['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M']
	small=['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
	for i in s:
		#print i
		if i in cap:
			cap_c+=1
		elif i in small:
			small_c+=1
	if cap_c==0 and small_c==0:
		return 'Invalid Input'
	else:
		return min(cap_c,small_c)
	return 0
try:
	t=int(input())
	if t>10 or t<1:
		print('Invalid Test')
	else:
		for i in range(t):
			inp=input()
			if ' ' in inp:
				print('Invalid Input')
			elif len(inp)>100 or len(inp)<1:
				print('Invalid Input')
			else:
				print(check(inp))
except:
	print('Invalid Test')	#	


def check(s):
	cap_c=0
	small_c=0
	cap=['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M']
	small=['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
	for i in s:
		#print i
		if i in cap:
			cap_c+=1
		elif i in small:
			small_c+=1
	if cap_c==0 and small_c==0:
		return 'Invalid Input'
	else:
		return min(cap_c,small_c)
	return 0
try:
	t=int(input())
	if t>10 or t<1:
		print('Invalid Test')
	else:
		for i in range(t):
			inp=input()
			if ' ' in inp:
				print('Invalid Input')
			elif len(inp)>100 or len(inp)<1:
				print('Invalid Input')
			else:
				print(check(inp))
except:
	print('Invalid Test')		


from string import ascii_uppercase
all_alphabet = [alpha for alpha in ascii_uppercase]
input_val = input()
test_case = int(input_val) if input_val.isdigit() else False
if test_case <= 10 and test_case > 0:
	for _ in range(test_case):
		test_str = [item for item in input()]
		lower_al, upper_al = [], []
		for item in test_str:
			if item.upper() in all_alphabet:
				if item.islower():
					lower_al.append(item)
				else:
					upper_al.append(item)
		if len(test_str) > 100 or len(test_str) < 1 or (len(lower_al) == 0 and len(upper_al) == 0):
			print("Invalid Input")
		else:
			if len(lower_al) >= len(upper_al):
				print(len(upper_al))
			else:
				print(len(lower_al))
else:
	print("Invalid Test")
	


import fileinput


def numberofoperation(string):
	if(1<=len(string)<=100):    
		inputstring=list(string)
		upperletter=0
		lowerletter=0
		for letter in inputstring:
			if(65<=ord(letter)<=90):
				upperletter+=1
			elif(97<=ord(letter)<=122):
				lowerletter+=1
		if(upperletter==0 and lowerletter==0):
			print ("Invalid Input")
		else:
			print((min(lowerletter,upperletter)))
	else:
		print ("Invalid Input")

inp=[]
for line in fileinput.input():
	inp.append(line.strip())
try:
	T=int(inp[0])
	if(1<=T<=10):
		for i in range(1,T+1):
			numberofoperation(inp[i])
	else:
		print ("Invalid Test")
except ValueError:
	print ("Invalid Test")



try:
	T = int(input().strip())
except:
	T = 0
if T >= 1 and T <= 10:
 	for i in range(T):
 		s1 = input().strip()
 		count1 =0 
 		count2 = 0
 		if len(s1) >= 1 and len(s1) <= 100:
 			for each in s1:
 				if ord(each) >= 65 and ord(each) <= 90:
 					count1 += 1
 				elif ord(each) >= 97 and ord(each) <= 122:
 					count2 += 1
 				else:
 					pass
 			
 			if count1 == 0 and count2 == 0:
 				print("Invalid Input")
 			elif count1 < count2:
 				print(count1)
 			else:
 				print(count2)
 		else:
 			print("Invalid Input")
else:
 	print("Invalid Test")


num_cases = input().rstrip("\n")
if (not num_cases.isdigit()) or (int(num_cases) < 1) or (int(num_cases) > 10):
	print("Invalid Test")
else:	
    for i in range(int(num_cases)):
	    input = input().rstrip("\n");
	    if (len(input) < 1) or (len(input) > 100):
		    print("Invalid Input")
	    else:
		    l_count = 0
		    u_count = 0
		    a_count = 0
		    for x in input:
			    if x.isalpha():
				    a_count = a_count + 1
				    if x.islower():
					    l_count = l_count + 1
				    else:
					    u_count = u_count + 1
		    if a_count == 0:
			    print("Invalid Input")
		    else:
			    print(min(l_count, u_count))


n=input()
if n.isalpha():
	print("Invalid Test")
else:
	n=int(n)
	if n not in list(range(1,11)):
		print("Invalid Test")
		
	else:
		for _ in range(n):
			art=[0,0]
			a=list(input())
			length=len(a)
			if length not in list(range(1,101)):
				print("Invalid Input")
			else:
				flag=1
				#alphak=0
				for item in a:
					if ord(item) in range(65,91):
						art[0]+=1
						#alphak=1
					elif ord(item) in range(97,123):
						art[1]+=1
						#alphak=1
					else:
						pass
					
				if art[0]!=0 or art[1]!=0:
					print(min(art))
				else:
					print("Invalid Input")


t = input()

#print T
val = t.isdigit()

if val == True:
	T = int(t)	

if (val == False or (val==True and (T < 1 or T > 10))):
	print("Invalid Test")
else:
	for i in range(T):
		s = input()
		#print s
		if len(s) >= 1 and len(s)<=100:
			#print "valid input"
			l = list(s)
			uc = 0
			lc = 0
			#print l
			for i in l:
				if i >="a" and i<="z":
					#print "lower"
					lc  = lc + 1
				elif i>= "A" and i<= "Z":
					#print "upper"
					uc = uc + 1
			if lc == 0 and uc == 0:
				print("Invalid Input")
			elif (lc == 0 and uc != 0) or (lc != 0 and uc == 0):
				print("0")
			else:
				print(min([lc,uc]))

		else:
			print("Invalid Input")
		


import sys

try:
	t = int(input())
except ValueError:
	print("Invalid Test")
	sys.exit()

"""t=raw_input()
if not t.isdigit():
	print "Invalid Test"
	sys.exit()
t=int(t)"""
if t<1 or t>10:
	print("Invalid Test")
	sys.exit()
#print t

for j in range(t):
	s=input()
	n=len(s)

	if n<1 or n>100:
		print("Invalid Input")
		continue

	small=0
	big=0
	for i in range(n):
		if s[i]>='a' and s[i]<='z':
			small=small+1
		elif s[i]>='A' and s[i]<='Z':
			big=big+1
	#print small,big
	if small==0 and big==0:
		print("Invalid Input")
	elif small<big:
		print(small)
	else:
		print(big)