Repository: parasjain-12/HackerEarth-Solution
Branch: master
Commit: e2156145ab71
Files: 153
Total size: 64.6 KB
Directory structure:
gitextract_2juf35yw/
├── 2 arrays.py
├── @K R-r-riddikulus! once again.py
├── A Special Number.py
├── A beauty factor.py
├── Achhe Din.py
├── Add Alternate Elements of 2-Dimensional Array.py
├── Alien language.py
├── All Vowels.py
├── AltF4 and the beetles.py
├── Anagrams.py
├── Anshul, Usama And Punishment - A.py
├── Anti-palindrome strings.py
├── Arjit and Apex.py
├── Array operations.py
├── ArrayGame.py
├── Bag Of Numbers.py
├── Best Index.py
├── Biased Chandan.py
├── Binary Queries.py
├── Breakup App.py
├── Bricks Game.py
├── CAn you solve it?.py
├── Chandu and Consecutive Letters.py
├── Char Sum.py
├── Charged Up Array.py
├── Cost of balloons.py
├── Count Divisors.py
├── Counting Triangles.py
├── Crazy Kangaroo.py
├── Dedication Level = Infinity.py
├── Determining numbers.py
├── Difficult Characters.py
├── Digital Sequence.py
├── Distribute chocolates.py
├── Divisibility.py
├── Divisible.py
├── Does it Divide?.py
├── Duration.py
├── EEDC Lab.py
├── Easy Sum Set Problem.py
├── Easy one.py
├── Equal elements
├── Equalize strings.py
├── Erasing an array.py
├── Exchanging money.py
├── Factorial!.py
├── Find Product.py
├── Find the String.py
├── Finding the Subarrays.py
├── Finding vaccines.py
├── Fredo and Large Numbers.py
├── Frequency of Students.py
├── Going to office.py
├── Grid and phrase.py
├── Hackers with Bits.py
├── Hamiltonian and Lagrangian.py
├── Hello.py
├── Help Jarvis!.py
├── Honey Bees.py
├── ICPC Team Management.py
├── James and the menus.py
├── LAL Evaluation.py
├── Length of Valley
├── Life, the Universe, and Everything.py
├── Lift queries.py
├── Little Monk and Balanced Parentheses.py
├── Little_Jhool_psychic_powers.py
├── Long ATM Queue.py
├── Lunch boxes.py
├── MYSTERY.py
├── Manna's First Name.py
├── Mark The Answer.py
├── Mathematically beautiful numbers.py
├── Maximize the Earning.py
├── Maximize the modulo function.py
├── Maximum Of K- size subarrays (Deque).py
├── Maximum Sum.py
├── Maximum goodness.py
├── Maximum occurrence.py
├── Maze Problem.py
├── Memorise Me!.py
├── Micro and Array Update.py
├── Min-Max.py
├── Mind Palaces.py
├── Minimum Add to Make Parentheses Valid.py
├── Minimum moves.py
├── Modify Sequence.py
├── Modulo Strength.py
├── Monk And the operations.py
├── Monk Takes a Walk.py
├── Monk Teaches Palindrome.py
├── Monk and Inversions.py
├── Monk and Lucky Minimum.py
├── Monk and Power of Time.py
├── Monk and Rotation.py
├── Monk and Welcome Problem.py
├── Most Frequent.py
├── Multiple occurrences.py
├── N - Co Ordinates (Pair Practice).py
├── Neutralisation of charges.py
├── Not in Range.py
├── Number of cycles.py
├── Number of steps.py
├── Pair Sum.py
├── Pairs.py
├── Palindromic String.py
├── Passing the Parcel.py
├── Pepper and Contiguous Even Subarray.py
├── Perfect Subarray.py
├── Permute the Array.py
├── Polygon Possibility
├── Prasun the detective.py
├── Prime Number.py
├── Priority Interview.py
├── README.md
├── Rain Sound.py
├── Rectangles to squares.py
├── Reversed Linked List.py
├── Robotic moves.py
├── Roy and Profile Picture.py
├── Roy and Symmetric Logos.py
├── Saul Goodman's Problem Statement.py
├── Save Mrinal.py
├── Seating Arrangement.py
├── Seven-Segment Display.py
├── Simon cannot sleep.py
├── Simple Search.py
├── SnackDown Contest.py
├── Speed.py
├── Split Houses.py
├── Stack and Queue <Nissan>.py
├── Statistics.py
├── Strange Game.py
├── String.py
├── Sumita and equal array.py
├── Takeoff.py
├── Terrible Chandu.py
├── The Amazing Race.py
├── The Monk and Kundan.py
├── The best Internet Browser.py
├── Thief and Warehouses.py
├── Toggle String.py
├── Two Strings.py
├── VC pairs.py
├── Vada Pav List.py
├── Weighing the Stones.py
├── Wet Clothes.py
├── Word Queries.py
├── balanced brackets.py
├── e-maze-in.py
├── square sub matrix.py
├── super reduced strings.py
└── zoos.py
================================================
FILE CONTENTS
================================================
================================================
FILE: 2 arrays.py
================================================
n = int(input())
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))
aneg = 0
bneg = 0
asum = 0
bsum = 0
for i in range(n):
if arr[i]== -1:
aneg +=1
else:
asum +=arr[i]
if brr[i] == -1:
bneg +=1
else:
bsum +=brr[i]
d = abs(asum - bsum)
if aneg ==bneg:
print("Infinite")
if (bsum-asum)>0 and aneg != bneg:
if aneg == 0:
print(0)
if aneg==1:
print(1)
elif aneg>1:
print(d+1)
if (asum-bsum)>0 and aneg!=bneg:
if bneg == 0:
print(0)
if bneg==1:
print(1)
elif bneg>1:
print(d+1)
================================================
FILE: @K R-r-riddikulus! once again.py
================================================
n,d = map(int,input().split())
a = list(map(int,input().split()))
print(*(a[d:]+a[:d]))
#print(*(a[d:]+a[:d]))
================================================
FILE: A Special Number.py
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
def getSum(n):
su = 0
while n!=0:
rem = n%10
su += rem
n = n//10
return su
n = int(input())
li = []
for i in range(n):
x = int(input())
for i in range(x,10000000000):
su = getSum(i)
if su%4 == 0:
print(i)
break
================================================
FILE: A beauty factor.py
================================================
# Simple Brute Force implementation
#First we check that whether the length (k) is 9 or not because if k ==9 then we can have only 1 number that is 123456789 becz number must be distinct and greater than zero.
# Step 2 : If start with the smallest number and remove all zero and indentical number (1231 here 1 is repeated two times which should not be as each number must be distinct) and
# check there beautyFactor . if they match print it else increment the number and recursivly check it len of the number is equal to k.
def checkBeautyFactor(n):
su = 0
for i in str(n):
su+= int(i)
if len(str(su))>1:
su = checkBeautyFactor(str(su))
return su
b,k = map(int,input().split())
if k == 9:
if b==9:
print(123456789)
else:
print(-1)
else:
n = "1" + "0"*(k-1)
while True:
if "0" in str(n):
n = int(n)
n+=1
continue
n = str(n)
if len(set(n)) != len(n):
n = int(n)
n+=1
continue
beautyFactor = checkBeautyFactor(str(n))
if beautyFactor == b:
print(n)
break
n = int(n)
n+=1
if len(str(n))>k:
print(-1)
break
================================================
FILE: Achhe Din.py
================================================
testCase = int(input())
from collections import Counter
for _ in range(testCase):
n = int(input())
ide = Counter(list(map(int,input().split())))
print(list(ide.keys())[list(ide.values()).index(1)])
================================================
FILE: Add Alternate Elements of 2-Dimensional Array.py
================================================
a,b,c,d,e,f,g,h,i = map(int,input().split())
print(a+c+e+g+i)
print(b+d+f+h)
================================================
FILE: Alien language.py
================================================
n = int(input())
for i in range(n):
first_word = input()
second_word = input()
for i in second_word:
if i in first_word:
print("YES")
break
else:
print("NO")
================================================
FILE: All Vowels.py
================================================
n = int(input())
s = input()
a = 0
e=0
i=0
o=0
u=0
for j in range(n):
if s[j]=='a':
a+=1
if s[j]=='e':
e+=1
if s[j]=='i':
i+=1
if s[j]=='o':
o+=1
if s[j]=='u':
u+=1
if a>0 and e>0 and i>0 and o>0 and u>0:
print("YES")
else:
print("NO")
================================================
FILE: AltF4 and the beetles.py
================================================
for _ in range(int(input())):
n,a,b,c = map(int,input().split())
#store the beetles with 0 or 1
#0 means start time
# 1 means end time
beetles = []
for i in range(n):
x,y = map(int,input().split())
beetles.append((x,0))
beetles.append((y,1))
# sort the array with my giving start time pripority and taking the consideration that endtime is less than the
#previous once
beetles.sort(key = lambda b: b[0]*2+ b[1])
total = n*a
# since we have added a in starting , now we are adding b and substracting a
ba = b-a
cb = c-b
max_ = total
#checking whether the its the start time or end time
# If it is start time we are adding ba
#if end time we are adding cb
for b in beetles:
if b[1]==0:
total += ba
else:
total += cb
max_ = max(max_,total)
print(max_)
================================================
FILE: Anagrams.py
================================================
from collections import Counter
# Write your code here
def cc(a,b):
p = Counter(a)
q = Counter(b)
print(sum((q-p).values())+sum((p-q).values()))
n = int(input())
for _ in range(n):
a = input()
b = input()
cc(a,b)
================================================
FILE: Anshul, Usama And Punishment - A.py
================================================
n = int(input())
l = [20,30,40,90,80]
if n>len(l):
for i in range(5,n+1):
if i%2==0:
l.append(2*l[i-2])
else:
l.append(3*l[i-2])
y=0
for i in range(n):
for j in range(i+1,n):
ma = abs(l[i]+l[j])+abs(l[i]-l[j])
y = max(y,ma)
print(y)
================================================
FILE: Anti-palindrome strings.py
================================================
# Simple Solution First sort the string if sorted string is palindrome then print (-1) else print the sorted string. Because if the sorted string is palindrome then
# the string will be something like this aaaaaa,bbbbb,ccccc,etc
# Write your code here
t = int(input())
for _ in range(t):
inp = input()
s = ''.join(sorted(inp))
if s == s[::-1]:
print(-1)
else:
print(s)
================================================
FILE: Arjit and Apex.py
================================================
t = int(input())
for _ in range(t):
m,n = map(int,input().split())
d = dict()
new = dict()
for i in range(m):
p,q = map(int,input().split())
d[i] = (p,q)
for i in range(n):
p,q = map(int,input().split())
new[i] = (p,q)
g,h = map(int,input().split())
g_c = 0
h_c=0
i = 0
j = 0
while i<len(d):
while j<len(new):
if new[j][0]==d[i][0]:
g_c+=1
if new[j][1]==d[i][1]:
h_c+=1
i+=1
j+=1
break
#print(h_c,g_c)
if h_c == h:
print("Great")
elif g_c == g:
print("Good")
else:
print(":(")
================================================
FILE: Array operations.py
================================================
# Knowledge of Kadane algorithm
#To understand the below algorithm I highly recommend you to visit https://www.geeksforgeeks.org/maximum-subarray-sum-possible-after-removing-at-most-one-subarray/
def kadaneSum(arr,n):
new_arr = [0]*n
curr_sum = s = 0
for i in range(n):
if curr_sum<0:
curr_sum = 0
if curr_sum + arr[i] >s:
s = curr_sum + arr[i]
curr_sum = curr_sum + arr[i]
new_arr[i] = s
return new_arr
t = int(input())
for _ in range(t):
n = int(input())
li = list(map(int,input().split()))
pre_sum = kadaneSum(li,n)
post_sum = kadaneSum(li[::-1],n)
post_sum = post_sum[::-1]
ans = 0
for i in range(n-1):
ans = max(ans,pre_sum[i]+post_sum[i+1])
print(ans)
================================================
FILE: ArrayGame.py
================================================
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
p=0
if n>m:
for i in range(m):
if a[i]<b[i]:
p+=b[i]-a[i]
else:
break
else:
for i in range(n):
if a[i]<b[i]:
p+=b[i]-a[i]
else:
break
print(p)
================================================
FILE: Bag Of Numbers.py
================================================
n=input().split()
if (len(n)<4):
n[0]="output"
else:
n[0]="output:"
print(*n)
================================================
FILE: Best Index.py
================================================
## Explaination :
'''
Step 1 : First we will find out till what index the zeroth index can go for example consider the array [1,3,1,2,5] here the zeroth index can go till index 2 and
k = 2 k = partition that is 1,2,3. This k will tell us the much indeed information to solve the question this tells us that how many elements are picked .So
If for index zeroth the k value is 2 we can't have k >2 for any other index.(TRY with example ).
The above step is done from line 20 to 30.
Step 2: Now we will start a loop from index 1 as we have already cover the case for index 0.
2.a : We will first substract the previous value as we have added that in the step 1 and we don't need that now(because we have increase the index).
2.b : Then we will check whether the index 0 has reach the end or not: if index 0 has reach the end then the next index won't have same k value.
Therefore we will decrese the k and subtract those value from the initialSum.
If the index 0 has not reach the end :: Only one element is added.(Try to analyze with example )
'''
# Write your code here
n = int(input())
a = list(map(int,input().split()))
start = 1
k = 2
while start<=n:
start += k
k+=1
start -= k-1
k-=2
initialSum = sum(a[:start])
ma = initialSum
for i in range(1,n):
initialSum -= a[i-1]
if start<n:
initialSum += a[start]
start+=1
else:
k-=1
initialSum -= sum(a[n-k:n])
start -= k
if initialSum > ma:
ma =initialSum
print(ma)
================================================
FILE: Biased Chandan.py
================================================
n = int(input())
x=[]
for i in range(n):
inq = int(input())
if inq == 0:
if len(x)>0:
x.pop()
else:
x.append(inq)
print(sum(x))
================================================
FILE: Binary Queries.py
================================================
n,q = map(int,input().split())
l =list(map(int,input().split()))
q2 = [[ None for _ in range(3)] for _ in range(q)]
for i in range(q):
q2[i] = list(map(int,input().split()))
if q2[i][0] ==1:
if l[q2[i][1]-1] ==0:
l[q2[i][1]-1]=1
else:
l[q2[i][1]-1]=0
else:
if l[q2[i][2]-1]==0:
print('EVEN')
else:
print('ODD')
================================================
FILE: Breakup App.py
================================================
n = int(input())
result = {}
msg = []
for _ in range(n):
msg.append(list(input().split()))
for i in range(n):
for j in range(len(msg[i])):
if msg[i][j].isdigit():
if msg[i][j] not in result:
result[msg[i][j]]=0
if msg[i][0] == 'G:':
result[msg[i][j]]+=2
else:
result[msg[i][j]]+=1
if len(result) == 0:
print('No Date')
else:
Keymax = max(result, key= lambda x: result[x])
if Keymax == '19' or Keymax == '20':
print('Date')
else:
print('No Date')
================================================
FILE: Bricks Game.py
================================================
n = int(input())
temp = n
for i in range(temp):
n = n - i
if n<=0 :
print("Patlu")
break
n = n - i*2
if n<=0:
print("Motu")
break
================================================
FILE: CAn you solve it?.py
================================================
testCase = int(input())
for _ in range(testCase):
n = int(input())
l = list(map(int,input().split()))
mi = []
ma = []
for i in range(n):
ma.append(l[i]+i)
mi.append(l[i]-i)
print(max((max(mi)-min(mi)),(max(ma)-min(ma))))
================================================
FILE: Chandu and Consecutive Letters.py
================================================
n = int(input())
for i in range(n):
s = input()
st = []
for i in range(len(s)):
if len(st)==0:
st.append(s[i])
elif st[-1]==s[i]:
pass
else:
st.append(s[i])
print(''.join(st))
================================================
FILE: Char Sum.py
================================================
d = {}
n = input()
s = 'abcdefghijklmnopqrstuvwxyz'
for i,j in enumerate(s):
d[j] = i+1
cost = 0
for i in n:
cost += d[i]
print(cost)
================================================
FILE: Charged Up Array.py
================================================
T = int(input())
m = pow(10,9)+7
for _ in range(T):
N = int(input())
A = list(map(int, input().split()))
s=0
ch= int(pow(2,N)//2)
for i in range(N):
if A[i]>=ch:
s+=A[i]
print(s%m)
================================================
FILE: Cost of balloons.py
================================================
test_cases = int(input())
for i in range(test_cases):
p,g = map(int, input().split())
n = int(input())
cost = 0
lower = min(p,g)
maximum = max(p,g)
p1_total = 0
p2_total = 0
for i in range(n):
p1,p2 = map(int, input().split())
p1_total += p1
p2_total += p2
if p1_total >= p2_total:
cost += p1_total*lower
cost += p2_total*maximum
else:
cost += p2_total*lower
cost += p1_total*maximum
print(cost)
================================================
FILE: Count Divisors.py
================================================
l,r,k = map(int,input().split())
c=0
for i in range(l,r+1):
if i%k==0:
#print(i)
c+=1
print(c)
================================================
FILE: Counting Triangles.py
================================================
n = int(input())
l = []
for _ in range(n):
a = tuple(map(int,input().split()))
a = sorted(a)
l.append(tuple(a))
from collections import Counter
d = Counter(l)
ans = 0
for k,v in d.items():
if v ==1 :
ans+=1
print(ans)
================================================
FILE: Crazy Kangaroo.py
================================================
t = int(input())
for _ in range(t):
a,b,m = map(int,input().split())
ans =0
for i in range(a,b+1):
if i%m == 0 :
ans +=1
print(ans)
================================================
FILE: Dedication Level = Infinity.py
================================================
n= int(input())
l = [[0 for i in range(2)]for i in range(n)]
for i in range(n):
l[i] = list(input().split())
for i in range(n):
l[i][1] = int(l[i][1])
l.sort(key = lambda x:x[1],reverse = True)
for i in range(3):
print(l[i][0])
================================================
FILE: Determining numbers.py
================================================
# Write your code here
from collections import Counter
n = int(input())
arr = list(map(int,input().split()))
a = Counter(arr)
ans = []
for k,v in a.items():
if v==1:
ans.append(k)
ans.sort()
print(*ans)
================================================
FILE: Difficult Characters.py
================================================
n = int(input())
for _ in range(n):
s = input()
from collections import Counter
s2 = 'abcdefghijklmnopqrstuwvxyz'
d = Counter(s2)
for i in range(len(s)):
if s[i] in s2:
if d[s[i]]:
d[s[i]]+=1
else:
d[s[i]]=1
#print(d[s[i]])
else:
d[s[i]]=0
ans = sorted(d.items(), key = lambda x : (x[1],-ord(x[0])))
for i in range(len(ans)):
print(ans[i][0],end = ' ')
print('\n')
================================================
FILE: Digital Sequence.py
================================================
a=int(input())
b=list(input().split())
max=0
for i in range(10):
i=str(i)
count=0
for j in b:
if(i in j):
count=count+1
if(count>max):
max=count
print(max)
================================================
FILE: Distribute chocolates.py
================================================
#Logic : Since there are n students and each student will recienve atleast one chocalate and the next student will receive k+1(Assuming k is the no.of chocolate given to first student)
# then next student will get k+2,k+3.... so on
# Minimum no.of chocolate n student will get will be n*(n+1)//2 where n = no.of student
#Step 2: Calculate the chocalte left that is : c - ( Minimum no.of chocolate)
# Step3 : Ans = chocalte left % n
#Let us understand via example : c = 20 n = 3
# Since there are 3 student they are bound to recieve 6 chocolate
#chocolateLeft = 20 -6 = 14
# If we divide 14 //3 we get 4
# therefore we can give each student 4 more chocolate that 5,6,7 = 18
#Therefore ans = 20 - 18
#Below is a shortcut way to calculate the above
t = int(input())
for _ in range(t):
c,n = map(int,input().split())
minimumChocolates = (n*(n+1))//2
if minimumChocolates >= c:
print(c)
else:
c = c - minimumChocolates
ans = c%n
print(ans)
================================================
FILE: Divisibility.py
================================================
#If the last element contions zero then only we can divide the number formed by taking the last number by 10
# Therefore we only need to check that whether the last element of the last number is zero or not.
N = int(input())
arr = list(map(int,input().split()))
ele = arr[N-1]
if ele % 10 == 0:
print("Yes")
else:
print("No")
================================================
FILE: Divisible.py
================================================
n = int(input())
s = list(input().split())
half = n/2
x = []
for i in range(n):
if i < half:
x.append(s[i][0])
else:
x.append(s[i][-1:])
temp = ''.join(x)
if (int(temp) % 11 == 0):
print("OUI")
else:
print("NON")
================================================
FILE: Does it Divide?.py
================================================
def prime(n) :
# Corner cases
if (n <= 1) :
return 0
if (n <= 3) :
return 1
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return 0
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return 0
i = i + 6
return 1
t = int(input())
for _ in range(t):
n = int(input())
x = prime(n)
if n==2:
print('NO')
elif n==1:
print('YES')
elif x==1:
print('YES')
elif x==0:
y = prime(n+1)
if y==1:
print('NO')
else:
print('YES')
================================================
FILE: Duration.py
================================================
t = int(input())
for _ in range(t):
sh,sm,eh,em = list(map(int,input().split()))
starting_min = sh*60 + sm
ending_min = eh*60 + em
temp = ending_min - starting_min
if temp>=60:
hr = int(temp/60)
mi = temp - hr*60
else:
hr = 0
mi = temp
print(hr,mi)
================================================
FILE: EEDC Lab.py
================================================
n = int(input())
a = list(map(int,input().split()))
tmp_sum = sum(a)
lucky = []
if n == 1:
lucky.append(1)
else:
for i in range(n):
if i == 0:
lucky.append(0)
else:
lucky.append(lucky[i-1])
#print(lucky)
if (tmp_sum - a[i])%3 == 0:
if i == 0:
if a[n-1] == 0:
lucky[i]+=1
elif i == n-1:
if a[n-2] == 0:
lucky[i]+=1
else:
if (a[i-1]+a[n-1])%10 == 0:
lucky[i]+=1
lucky.insert(0,0)
q = int(input())
for _ in range(q):
l,r = map(int,input().split())
print(lucky[r] - lucky[l-1])
================================================
FILE: Easy Sum Set Problem.py
================================================
n = int(input())
a = list(map(int,input().split()))
m = int(input())
c = list(map(int,input().split()))
l=[]
for i in range(n):
for j in range(m):
x = c[j]-a[i]
l.append(x)
from collections import Counter
l = Counter(l)
ans = []
for k,v in l.items():
if v==n:
ans.append(k)
ans =sorted(ans)
print(' '.join(map(str, ans)))
================================================
FILE: Easy one.py
================================================
from collections import Counter,defaultdict
t = int(input())
for _ in range(t):
n,q = map(int,input().split())
arr = list(map(int,input().split()))
d = defaultdict(int)
d = Counter(arr)
for _ in range(q):
temp = int(input())
print(d[temp])
================================================
FILE: Equal elements
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
t = int(input())
def find(arr,ele,n):
ans = 0
for i in range(n):
temp = abs(ele-arr[i])
if temp == 1 or temp%2 !=0:
ans += 1
return ans
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
l = []
for i in range(n):
if arr[i]%2 == 0:
l.append(2)
else:
l.append(1)
x = n + 1
for k in range(1,3):
x2 = find(arr,k,n)
x = min(x,x2)
print(x)
================================================
FILE: Equalize strings.py
================================================
n = int(input())
x = input()
y = input()
c = 0
l = 0
for i in range(n):
if x[i] != y[i]:
c+=1
else:
if c > 0:
l += 1
c =0
if c >0:
l+=1
print(l)
================================================
FILE: Erasing an array.py
================================================
#When we encounter 1,0 sequence we have inversion and we can't erase the solution
#Therefore the simple solution here is to just count the number of inversion that is the sequence of 1 follwed by 0.
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
c = 1
for i in range(n-1):
if arr[i] == 1 and arr[i+1]==0:
c+=1
print(c)
================================================
FILE: Exchanging money.py
================================================
import math
n,q = map(int,input().split())
arr = list(map(int,input().split()))
g= arr[0]
for i in range(n):
g = math.gcd(g,arr[i])
for i in range(q):
q1 = int(input())
if q1%g==0:
print("YES")
else:
print("NO")
================================================
FILE: Factorial!.py
================================================
import math
n = int(input())
print(math.factorial(n))
================================================
FILE: Find Product.py
================================================
x = pow(10,9)+7
n = int(input())
l = list(map(int,input().split()))
ans =1
for i in range(n):
ans = (ans*l[i])%x
print(ans)
================================================
FILE: Find the String.py
================================================
t = int(input())
from collections import Counter
for _ in range(t):
n,m = map(int,input().split())
matrix = {}
for i in range(n):
a = list(input())
matrix[i] = Counter(a)
s = input()
l = len(s)
c = 0
c = 0
for i in range(len(s)):
#print("fdefd",s[i],i)
if i<n:
if s[i] in matrix[i] and matrix[i][s[i]]>0:
matrix[i][s[i]] -=1
#print(matrix[i],s[i])
c+=1
else:
j = i%n
if s[i] in matrix[j] and matrix[j][s[i]]>0:
matrix[j][s[i]] -=1
#print("Else",matrix[j])
c+=1
if c==l:
print("Yes")
else:
print("No")
================================================
FILE: Finding the Subarrays.py
================================================
n = int(input())
l1 = list(map(int,input().split()))
ma = pow(10,7)
ind1= [0]*(ma)
ind2 = [0]*(ma)
temp=0
for i in range(n):
r = sum(l1)
l = 0
for j in range(i,n):
l+= l1[j]
r = r - l1[j]
if(n== j-i+1 or l/(j-i+1)>r/(n-j+i-1)):
#print(r)
ind1[temp] = i+1
ind2[temp] = j+1
#print(ind1[temp],ind2[temp])
temp+=1
print(temp)
for i,j in zip(ind1,ind2):
if i>0 or j>0:
print(i,j)
================================================
FILE: Finding vaccines.py
================================================
# Simple Brute force
# Since the interaction are between "C" and "G" RNA we calculate the number of "C" and "G" molecule in virus and in vaccine and then calculate the score
# Write your code here
noOfVaccine = int(input())
lenOfVirus = int(input())
virus = input()
v = [0]*2
for i in virus:
if i == 'C':
v[0] += 1
elif i == 'G':
v[1] += 1
ans = 0
number = 0
for j in range(noOfVaccine):
le = int(input())
vacc = input()
temp = [0]*2 #A temp array used to keep the count of "C" and "G" molecule
for i in vacc:
if i == 'C':
temp[0]+=1
elif i =='G':
temp[1]+=1
score = v[0]*temp[1] + v[1]*temp[0]
if score > ans:
ans = score
number = j+1
print(number)
================================================
FILE: Fredo and Large Numbers.py
================================================
import sys
def index(t,f,ma,p,q,s,d):
if f>ma:
return 0
if t==0:
for k,v in d.items():
if v >= f:
return k
else:
if f not in s:
return 0
else:
return p[q.index(f)]
from collections import OrderedDict
n = sys.stdin.readline()
array = list(map(int, sys.stdin.readline().split()))
d = OrderedDict()
for i in array:
#print(i)
if i in d:
d[i] +=1
else:
d[i] = 1
#print(d)
ma= max(d.values())
k = list(d.keys())
v = list(d.values())
s = set(v)
for i in range(int(sys.stdin.readline())):
t,f = map(int, sys.stdin.readline().split())
print(index(t,f,ma,k,v,s,d))
================================================
FILE: Frequency of Students.py
================================================
# Write your code here
n = int(input())
d = {}
for _ in range(n):
x = input()
if x in d:
d[x]+=1
else:
d[x]=1
for k,v in sorted(d.items()):
print(k, v)
================================================
FILE: Going to office.py
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
d = int(input())
oc,of,od = map(int,input().split())
cs,cb,cm,cd = map(int,input().split())
temp = d- of
if temp > 0:
costOnline = oc+ temp*od
else:
costOnline = oc
time = d//cs
costOffline = cb + cm*time + cd*d
if costOnline<=costOffline:
print("Online Taxi")
else:
print("Classic Taxi")
================================================
FILE: Grid and phrase.py
================================================
n,m = map(int,input().split())
matrix = []
for i in range(n):
a= list(input())
matrix.append(a)
c=0
#horizontal
for i in range(n):
for j in range(m):
if m-j>=4:
#print(m,j,i)
if matrix[i][j]=='s' and matrix[i][j+1]=='a' and matrix[i][j+2]=='b' and matrix[i][j+3]=='a':
#print("yes")
c+=1
#Vertical
for j in range(m):
#ro
for i in range(n):
if n-i>=4:
if matrix[i][j]=='s' and matrix[i+1][j]=='a' and matrix[i+2][j]=='b' and matrix[i+3][j]=='a':
c+=1
for i in range(n):
for j in range(m):
if n-i>=4 and m-j>=4:
#print(i,j)
#print(matrix[i][j], matrix[i+1][j+1], matrix[i+2][j+2], matrix[i+3][j+3])
if matrix[i][j]=='s' and matrix[i+1][j+1]=='a' and matrix[i+2][j+2]=='b' and matrix[i+3][j+3]=='a':
#print("yes")
c+=1
for i in range(n-1,0,-1):
for j in range(m):
if i+1 >= 4 and m-j>=4:
if matrix[i][j]=='s' and matrix[i-1][j+1]=='a' and matrix[i-2][j+2]=='b' and matrix[i-3][j+3]=='a':
#print("ds")
c+=1
print(c)
================================================
FILE: Hackers with Bits.py
================================================
n = int(input())
l = input()
s1 = l.count('1')
s2 = l.count('0')
s= l.split('0')
m = 0
for i in range(len(s)-1):
z=s[i].count("1")+s[i+1].count("1")
if(z>m):
m=z
if(s2==0):
print(s1)
elif(s1==0):
print(0)
elif(s1>m):
print(m+1)
else:
print(m)
================================================
FILE: Hamiltonian and Lagrangian.py
================================================
n = int(input())
l = list(map(int,input().split()))[::-1]
pq = []
pq.append(l[0])
m = l[0]
for i in range(1,n):
if l[i]>=m:
pq.append(l[i])
m=l[i]
print(*pq[::-1])
================================================
FILE: Hello.py
================================================
print('Hello Kirti')
================================================
FILE: Help Jarvis!.py
================================================
t = int(input())
for i in range(t):
l = input()
li = []
for i in l:
li.append(int(i))
mi = min(li)
m = max(li)
c=0
arr = []
for i in range(mi,m+1):
arr.append(i)
if sorted(li)==sorted(arr):
print('YES')
else:
print('NO')
================================================
FILE: Honey Bees.py
================================================
for _ in range(int(input())):
n, m = map(int, input().split())
M = [list(map(int, input().split())) for __ in range(n)]
for k in range(int(input())):
t, x, y = map(int,input().split())
s = 0
if t == 1:
if y % 2 == 0:
if x-1 >= 0:
s += M[x-1][y]
if x+1 < n:
s += M[x+1][y]
if y-1 >= 0:
s += M[x][y-1]
if y+1 < m:
s += M[x][y+1]
if x-1 >= 0 and y-1 >= 0:
s += M[x-1][y-1]
if x-1 >= 0 and y+1 < m:
s += M[x-1][y+1]
print(s)
else:
if x-1 >= 0:
s += M[x-1][y]
if y-1 >= 0:
s += M[x][y-1]
if y+1 < m:
s += M[x][y+1]
if x+1 < n and y-1 >= 0:
s += M[x+1][y-1]
if x+1 < n:
s += M[x+1][y]
if x+1 < n and y+1 < m:
s += M[x+1][y+1]
print(s)
else:
if y % 2 == 0:
if x-2 >= 0 and y-1 >= 0:
s += M[x-2][y-1]
if x-2 >= 0:
s += M[x-2][y]
if x-2 >= 0 and y+1 < m:
s += M[x-2][y+1]
if x-1 >= 0 and y-2 >= 0:
s += M[x-1][y-2]
if y-2 >= 0:
s += M[x][y-2]
if x+1 < n and y-2 >= 0:
s += M[x+1][y-2]
if x+1 < n and y-1 >= 0:
s += M[x+1][y-1]
if x+2 < n:
s += M[x+2][y]
if x+1 < n and y+1 < m:
s += M[x+1][y+1]
if y+2 < m:
s += M[x][y+2]
if x+1 < n and y+2 < m:
s += M[x+1][y+2]
if x-1 >= 0 and y+2 < m:
s += M[x-1][y+2]
print(s)
else:
if x-1 >= 0 and y-1 >= 0:
s += M[x-1][y-1]
if x-2 >= 0:
s += M[x-2][y]
if x-1 >= 0 and y+1 < m:
s += M[x-1][y+1]
if x-1 >= 0 and y-2 >= 0:
s += M[x-1][y-2]
if y-2 >= 0:
s += M[x][y-2]
if x+1 < n and y-2 >= 0:
s += M[x+1][y-2]
if x+2 < n and y-1 >= 0:
s += M[x+2][y-1]
if x+2 < n:
s += M[x+2][y]
if x+2 < n and y+1 < m:
s += M[x+2][y+1]
if x+1 < n and y+2 < m:
s += M[x+1][y+2]
if y+2 < m:
s += M[x][y+2]
if x-1 >= 0 and y+2 < m:
s += M[x-1][y+2]
print(s)
================================================
FILE: ICPC Team Management.py
================================================
t = int(input())
for _ in range(t):
n,k = map(int,input().split())
from collections import Counter
d = Counter()
s = 0
for i in range(n):
temp = input()
d[len(temp)] +=1
c=0
for x,v in d.items():
#print(v)
if v%k==0:
c+=1
if c==len(d):
print("Possible")
else:
print("Not possible")
================================================
FILE: James and the menus.py
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
n,m = map(int,input().split())
lis = []
for i in range(n):
temp = list(map(int,input().split()))
lis.append(temp)
mx = [0]*m
su = [0]*n
for i in range(n):
for j in range(m):
mx[j] = max(mx[j],lis[i][j])
su[i] += lis[i][j]
cn = [0]*n
goodNumber = 0
for i in range(n):
for j in range(m):
if mx[j] == lis[i][j]:
cn[i]+=1
goodNumber = max(goodNumber,cn[i])
index = []
for i in range(len(cn)):
if goodNumber == cn[i]:
index.append(i)
ansSum = 0
ansIndex = 0
if len(index)>1:
for i in range(len(index)):
temp = su[index[i]]/4
if temp>ansSum:
ansSum = temp
ansIndex = index[i]
print(ansIndex+1)
else:
print(index[0]+1)
================================================
FILE: LAL Evaluation.py
================================================
n,m = map(int,input().split())
arr = list(map(int,input().split()))
d = dict()
c= 0
for i in range(n):
temp = m-arr[i]
if d.get(temp):
#print(arr[i],temp)
c+= d[temp]
if d.get(arr[i]):
d[arr[i]] +=1
else:
d[arr[i]] =1
print(c)
================================================
FILE: Length of Valley
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
def area(arr,n):
stack = []
right_index = [0]*n
index = 0
while index<n:
if len(stack)==0 or arr[stack[-1]]<arr[index]:
stack.append(index)
index += 1
else:
while len(stack)>0:
x = stack.pop()
right_index[x]= index
while len(stack)>0:
x = stack.pop()
right_index[x]= index
return right_index
def l_area(arr,n):
stack = []
left_index = [0]*n
index = 0
while index<n:
if len(stack)==0 or arr[stack[-1]]<arr[index]:
stack.append(index)
index += 1
else:
while len(stack)>0:
x = stack.pop()
left_index[x]= index
while len(stack)>0:
x = stack.pop()
left_index[x]= index
return left_index
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
left_index = l_area(arr[::-1],n)
left_index = left_index[::-1]
for i in range(n):
left_index[i] = n - left_index[i] + 1
right_index = area(arr,n)
ans = [0]*n
for i in range(n):
ans[i] = right_index[i] - left_index[i] + 1
print(*ans,sep =' ')
================================================
FILE: Life, the Universe, and Everything.py
================================================
while True:
n = int(input())
if n == 42:
break
else:
print(n)
================================================
FILE: Lift queries.py
================================================
test_case = int(input())
a = 0
b = 7
for i in range(test_case):
f = int(input())
temp = abs(f-a)
temp2 = abs(f-b)
if temp <= temp2:
a = f
print('A')
else:
b = f
print('B')
================================================
FILE: Little Monk and Balanced Parentheses.py
================================================
n = int(input())
a = list(map(int,input().split()))
s = []
ans = 0
for i in range(0,n):
if a[i] > 0:
s.append(i)
elif a[i] < 0:
if s and a[i] == -a[s[-1]]:
s.pop()
if not s:
temp = -1
else:
temp = s[-1]
ans = max(ans,i - temp)
else:
s.append(i)
print(ans)
================================================
FILE: Little_Jhool_psychic_powers.py
================================================
#Basics of Implementation
#hackerearth
#Little Jhool Psychic Powers
#Solution
n = input()
if '111111' in n:
print("Sorry, sorry!")
elif "000000" in n:
print("Sorry, sorry!")
else:
print("Good luck!" )
================================================
FILE: Long ATM Queue.py
================================================
# Write your code here
n = int(input())
l = list(map(int,input().split()))
c=1
for i in range(n-1):
if l[i+1]<l[i]:
c+=1
print(c)
================================================
FILE: Lunch boxes.py
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
t = int(input())
for _ in range(t):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
su = 0
for i in range(len(a)):
if a[i]+su <= n:
su+=a[i]
count+=1
print(count)
================================================
FILE: MYSTERY.py
================================================
while True:
try:
n = int(input())
s = bin(n)
print(s.count('1'))
except:
break
================================================
FILE: Manna's First Name.py
================================================
t = int(input())
word = 'SUVO'
word1 = 'SUVOJIT'
for _ in range(t):
s = input()
c = s.count(word)
c2 = s.count(word1)
print('SUVO = {}, SUVOJIT = {}'.format(c-c2,c2))
================================================
FILE: Mark The Answer.py
================================================
n,k = map(int,input().split())
l = list(map(int,input().split()))
c=0
skip=0
for i in range(n):
if l[i]<=k and skip<2:
#print(l[i])
c+=1
else:
skip+=1
print(c)
================================================
FILE: Mathematically beautiful numbers.py
================================================
#Step 1 : We first find out the powers of numbes smaller than or equal to x.Eg x = 91 ,k = 3 so we first find out [1,3,9,27,81]
#Step 2 : We start a loop and subtract the largest number one by one from x and simulatensly check whether they are equal or not.
#Step 3 : If they are equal print - YES else NO
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
t = int(input())
for _ in range(t):
x,k = map(int,input().split())
options = [1]
val = k
count = 1
while val<=x:
count+=1
options.append(val)
val = k**count
total = options.pop()
while total <= x:
dif = x - total
options = [i for i in options if i<= dif]
try:
total += options.pop()
except:
break
if total == x:
print("YES")
else:
print("NO")
================================================
FILE: Maximize the Earning.py
================================================
s=int(input())
for i in range(s):
n,r = map(int,input().split())
l = list(map(int,input().split()))
c=0
ma = 0.5
for i in range(len(l)):
if l[i]>ma:
ma = l[i]
c+=1
print(c*r)
================================================
FILE: Maximize the modulo function.py
================================================
'''
This code uses two formula to solve that is :
if c = a + b then
c mod(n) = [ a mod(n) + b mod(n)] mod(n)
example: c = 15
a = 7
b = 8
n = 2
15mod(2) = 1
7mod(2) = 1
8mod(2) = 0
[1+0]mod(2) = 1
2nd formula:
ab mod(n) = [(a mod(n))(b mod(n))]mod(n)
'''
# Write your code here
def solve(k, n,m):
pre = [0]
for c in n:
pre += [(pre[-1] * 10 + int(c))%k]
ans = pre[-1]%k
suf = 0
cur_pow = 1
for i in range(m - 1, -1, -1):
ans = max(ans, (pre[i] * cur_pow%k + suf) % k)
suf += cur_pow * int(n[i])
suf = suf%k
cur_pow = cur_pow * 10%k
return ans
if __name__ == "__main__":
T = int(input().strip())
for problem in range(1, T + 1):
n,k = map(int, input().split())
A = input()
print(solve(k, A,n))
================================================
FILE: Maximum Of K- size subarrays (Deque).py
================================================
n,m= map(int,input().split())
l = list(map(int,input().split()))
x=[]
for i in range(0,n):
if len(l[i:m+i])==m:
x.append(max(l[i:m+i]))
print(*x)
================================================
FILE: Maximum Sum.py
================================================
n = int(input())
arr= list(map(int,input().split()))
s = 0
c = 0
for i in range(len(arr)):
if arr[i]>=0:
s += arr[i]
c +=1
if s==0 and c==0:
s = max(arr)
c = 1
print(s,c)
================================================
FILE: Maximum goodness.py
================================================
n = int(input())
l = list(map(int,input().split()))
ans = [1]
le = [1]
#d = {}
#d[1] =1
for i in range(1,n):
if l[i]==1:
if ans[i-1]+ 1 >=1:
ans.append(ans[i-1]+1)
#d[ans[i-1]+1] = i+1
le.append(le[-1]+1)
#print(i+1,d[ans[i-1]+1])
else:
#d[1] = 1
le.append(1)
ans.append(1)
else:
ans.append(ans[i-1]-1)
le.append(le[-1]+1)
x= []
ma = max(ans)
for i in range(len(ans)):
if ans[i]==ma:
x.append(i)
final_ans= []
for i in range(len(x)):
final_ans.append(le[x[i]])
print(max(final_ans))
================================================
FILE: Maximum occurrence.py
================================================
l = list(input())
from collections import Counter
d = Counter(l)
temp = max(d.values())
li = []
for k,v in d.items():
if v==temp:
li.append(k)
li.sort(key= lambda x: ord(x))
print(li[0],d[li[0]])
================================================
FILE: Maze Problem.py
================================================
def issafe(p,q,arr):
#print(type(p),type(n))
if p<n and p>=0 and q<n and q>=0 and arr[p][q]==1:
#print("Sdsdsd")
return True
return False
def solve(arr,i,j,sol):
#print(n)
if i==n-1 and j==n-1:
sol[i][j]=1
return True
#print(i,j)
if issafe(i,j,arr)==True:
sol[i][j]=1
#print(sol)
if solve(arr,i,j+1,sol)==True:
return True
if solve(arr,i+1,j,sol)==True:
return True
sol[i][j]=0
return False
t = int(input())
for _ in range(t):
n = int(input())
arr =[]
sol = [[ 0 for i in range(n) ] for i in range(n)]
for i in range(n):
x = list(map(int,input().split()))
arr.append(x)
if solve(arr,0,0,sol) ==True:
print("POSSIBLE")
else:
print("NOT POSSIBLE")
================================================
FILE: Memorise Me!.py
================================================
from collections import Counter
n= int(input())
a = list(map(int,input().split()))
m = int(input())
p = Counter(a)
for i in range(m):
x = int(input())
if p[x]:
print(p[x])
else:
print('NOT PRESENT')
================================================
FILE: Micro and Array Update.py
================================================
n= int(input())
for _ in range(n):
le,k = map(int,input().split())
array = list(map(int,input().split()))
x = k-min(array)
if x>0:
print(x)
else:
print(0)
================================================
FILE: Min-Max.py
================================================
n = int(input())
arr = list(map(int,input().split()))
ma = max(arr)
mi = min(arr)
s = sum(arr)
a1_max = s-mi
a2_min = s-ma
print(a2_min,a1_max)
================================================
FILE: Mind Palaces.py
================================================
def binar(arr,l,r,x):
if r >=l:
mid = int(l+ (r-l)/2)
if arr[mid]==x:
return mid
elif arr[mid]>x:
return binar(arr,l,mid-1,x)
else:
return binar(arr,mid+1,r,x)
else:
return -1
n,m = map(int,input().split())
array = []
for i in range(n):
temp = list(map(int,input().split()))
array.append(temp)
q = int(input())
for _ in range(q):
x = int(input())
f =0
for i in range(n):
t = binar(array[i],0,len(array[i])-1,x)
if t!= -1:
f=1
break
if f==1:
print(i,t)
else:
print("-1 -1")
================================================
FILE: Minimum Add to Make Parentheses Valid.py
================================================
s = input()
op = '('
cl = ')'
st = [s[0]]
for i in range(1,len(s)):
#print(st)
if st:
temp =s[i]
if temp == cl:
if op == st[-1]:
st.pop()
else:
st.append(s[i])
else:
st.append(s[i])
else:
st.append(s[i])
print(len(st))
================================================
FILE: Minimum moves.py
================================================
n = int(input())
for _ in range(n):
x,y = map(int,input().split())
if x<0 or y<0 or y>x:
print(-1)
else:
print(max(x,y))
================================================
FILE: Modify Sequence.py
================================================
n = int(input())
l = list(map(int,input().split()))
for i in range(n-1):
if l[i]<=l[i+1]:
l[i+1] = l[i+1]-l[i]
else:
print('NO')
break
else:
if l[n-1]==0:
print('YES')
else:
print('NO')
================================================
FILE: Modulo Strength.py
================================================
#NOTE array b is used to store the count of number of student that have same strength
# Write your code here
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*k
for i in range(n):
b[a[i]%k] += 1
ans = 0
for i in range(k):
ans += b[i]*(b[i]-1)
print(ans)
================================================
FILE: Monk And the operations.py
================================================
def abs_sum(row):
s =0
for i in range(len(row)):
s += abs(row[i])
return s
def abs_add(row,v1):
l = len(row)
for i in range(l):
row[i] += v1
x = abs_sum(row)
return x
n,m= map(int,input().split())
#input Matrix
matrix = []
for i in range(n):
a = list(map(int,input().split()))
matrix.append(a)
v1,v2,v3,v4 = map(int,input().split())
#convert n rows into n column
col =[]
for i in range(m):
a = []
for j in range(n):
a.append(matrix[j][i])
col.append(a)
#row sum and update check
f_sum1=0
for i in range(n):
sum1=abs_sum(matrix[i])
x=0
temp = abs_add(matrix[i],v1)
temp_2 = abs(len(matrix[i])*v2)
if temp< temp_2:
x = temp_2
else:
x = temp
if x>sum1:
sum1 = x
#print(sum1,i)
f_sum1 += sum1
c_sum1=0
for i in range(m):
sum1=abs_sum(col[i])
x12 = 0
temp = abs_add(col[i],v3)
temp_1 = abs(len(col[i])*v4)
if temp< temp_1:
x12= temp_1
else:
x12 = temp
if x12>sum1:
sum1 =x12
#print(sum1,i)
c_sum1 += sum1
if c_sum1>f_sum1:
print(c_sum1)
else:
print(f_sum1)
================================================
FILE: Monk Takes a Walk.py
================================================
t = int(input())
for _ in range(t):
s = input()
s = s.lower()
c=0
for i in range(len(s)):
if s[i] =='a' or s[i] =='e' or s[i] =='i' or s[i] =='o' or s[i] =='u':
c+=1
print(c)
================================================
FILE: Monk Teaches Palindrome.py
================================================
t = int(input())
for _ in range(t):
s = input()
n = len(s)
if s == s[::-1]:
if n%2==0:
print("YES EVEN")
else:
print("YES ODD")
else:
print("NO")
================================================
FILE: Monk and Inversions.py
================================================
t = int(input())
for _ in range(t):
n= int(input())
matrix = []
for i in range(n):
a = list(map(int,input().split()))
matrix.append(a)
#print(matrix)
c=0
for i in range(n):
for j in range(n):
for p in range(n):
for q in range(n):
if i<=p and j<=q:
if matrix[i][j]>matrix[p][q]:
c+=1
print(c)
================================================
FILE: Monk and Lucky Minimum.py
================================================
testCase = int(input())
from collections import Counter
for _ in range(testCase):
n = int(input())
l = list(map(int,input().split()))
p = Counter(l)
x = min(l)
if p[x]%2==0:
print('Unlucky')
else:
print("Lucky")
================================================
FILE: Monk and Power of Time.py
================================================
n = int(input())
call = list(map(int,input().split()))
ideal = list(map(int,input().split()))
def check(a,b):
if a[0] == b[0]:
return True
return False
c=0
while len(call)>0:
if check(call,ideal)==True:
call = call[1:]
ideal = ideal[1:]
c+=1
else:
call = call[1:n]+call[:1]
#print(call)
c+=1
print(c)
================================================
FILE: Monk and Rotation.py
================================================
testCase = int(input())
for _ in range(testCase):
n,k = map(int,input().split())
l = list(map(int,input().split()))
x = k%n
print(*(l[n-x:]+l[:n-x]))
================================================
FILE: Monk and Welcome Problem.py
================================================
n= int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*n
for i in range(n):
c[i] = a[i]+b[i]
print(*c)
================================================
FILE: Most Frequent.py
================================================
from collections import Counter
n =int(input())
l = Counter(list(map(int,input().split())))
x = 100000
for k,v in l.items():
if v==max(l.values()):
x = min(x,k)
print(x)
================================================
FILE: Multiple occurrences.py
================================================
# Simple Brute force implementation
# Only thing to note here is that in the dictonary/HaspMap we are storing key and list of values
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
d= {}
for i in range(len(a)):
try:
if d[a[i]]:
d[a[i]].append(i+1)
except:
d[a[i]] = [i+1]
ans = 0
for k,v in d.items():
if len(v)>=2:
ans += v[-1] - v[0]
print(ans)
================================================
FILE: N - Co Ordinates (Pair Practice).py
================================================
from collections import Counter
n = int(input())
d = Counter()
for i in range(n):
x = tuple(map(int,input().split()))
d[x]+=1
for k,v in sorted(d.items()):
print(*k,v)
================================================
FILE: Neutralisation of charges.py
================================================
n = int(input())
s =input()
l = list(s)
stack = []
stack.append(l[0])
for i in range(1,len(l)):
stack.append(l[i])
try:
if stack[-1] and stack[-2]:
if stack[-1]==stack[-2]:
stack.pop()
stack.pop()
except:
pass
print(len(stack))
print(''.join(stack))
================================================
FILE: Not in Range.py
================================================
k = sum([i for i in range(1,1000001)])
t = int(input())
l = []
for _ in range(t):
x,y = map(int,input().split())
l.append([x,y])
l = sorted(l)
for i in range(len(l)-1):
#print(i)
if(l[i+1][0]<=l[i][1]):
l[i+1][0] = l[i][1]+1
for i in range(len(l)):
if(l[i][0]>l[i][1]):
l[i] = 0
for i in range(len(l)):
if(l[i]!=0):
e = (l[i][1]*(l[i][1]+1))//2
o = (l[i][0]*(l[i][0]+1))//2
p = e-o+l[i][0]
k-=p
print(k)
================================================
FILE: Number of cycles.py
================================================
#Simple Cycles - No.of closed figure .
#Hint - See Pattern
# Write your code here
t = int(input())
for _ in range(t):
n = int(input())
ans = 1
ans += (n-1)*n
print(ans)
================================================
FILE: Number of steps.py
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
mi = min(a)
i = 0
while i <n:
if a[i]>=b[i]:
while a[i]>mi:
a[i] -= b[i]
count+=1
if a[i] < mi:
mi = a[i]
i = 0
if a[i] != mi:
count = -1
break
i+=1
print(count)
#A rare test case :
# n=2
# a = [3,2]
# b = [2,1]
# then all a's element should be 1
================================================
FILE: Pair Sum.py
================================================
n,m= map(int,input().split())
from collections import Counter
arr = list(map(int,input().split()))
d = Counter(arr)
flag = 0
for i in range(n):
temp = m - arr[i]
if d[temp]:
if arr[i]==temp and d[temp]==1:
continue
print("YES")
flag = 1
break
if flag==0:
print("NO")
================================================
FILE: Pairs.py
================================================
def isPrime(n) :
# Corner cases
allprime = [True for i in range(ma+1)]
p=2
x = [0]*(n+1)
while (p*p<=n):
if allprime[p]==True:
for i in range(p*p,n+1,p):
allprime[i] = False
p+=1
for i in range(2,len(allprime)):
if allprime[i]:
x[i] = x[i-1]+1
else:
x[i] = x[i-1]
return x
ma = 100005
x = isPrime(ma)
t = int(input())
for _ in range(t):
m,n = list(map(int,input().split()))
if m==1:
m =2
#print("ALl Prime lsit",allprime)
no_of_prime = x[n]-x[m-1]
print(no_of_prime*(n-m-no_of_prime+1))
================================================
FILE: Palindromic String.py
================================================
n = input()
if n== n[::-1]:
print('YES')
else:
print('NO')
================================================
FILE: Passing the Parcel.py
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
n = int(input())
st = [True]*n
song = input()
ne = len(song)
c = 0
j=0
i=0
while c<n-1:
#print(i)
if i>=ne:
i = i%ne
if j>=n:
j = j%n
if song[i] =='a':
if st[j] != False:
i+=1
#st[j] == True
j+=1
else:
j+=1
elif song[i] == 'b':
#print("sdsds")
if st[j] != False:
c+=1
i+=1
st[j] = False
j+=1
else:
j+=1
for i in range(len(st)):
if st[i] == True:
print(i+1)
break
================================================
FILE: Pepper and Contiguous Even Subarray.py
================================================
t= int(input())
for _ in range(t):
n = int(input())
l = list(map(int,input().split()))
c=0
x=[-1]
for i in range(n):
if l[i]%2==0:
c+=1
x.append(c)
else:
c=0
print(max(x))
================================================
FILE: Perfect Subarray.py
================================================
n = int(input())
l = list(map(int,input().split()))
import math
def checkperfect(n):
i = int(math.sqrt(n))
if n==i*i:
return True
else:
return False
c=0
for i in range(n):
s= 0
for j in range(i,n):
s+=l[j]
if checkperfect(s):
c+=1
print(c)
================================================
FILE: Permute the Array.py
================================================
t = int(input())
from collections import Counter
for _ in range(t):
n,k = map(int,input().split())
arr = list(map(int,input().split()))
count = int(n/k)
a= Counter(arr)
l2 = 0
for p12,v in a.items():
if v==count:
l2+=1
#print(l1)
elif v>count:
temp = int((v/count))
l2+=temp
#print(temp)
if l2 ==k:
print("YES")
else:
print("NO")
================================================
FILE: Polygon Possibility
================================================
t= int(input())
for _ in range(t):
n = int(input())
l = list(map(int,input().split()))
s = sum(l)
for i in range(len(l)):
if l[i]>=s-l[i]:
print('No')
break
else:
print('Yes')
================================================
FILE: Prasun the detective.py
================================================
p = input().lower()
q = input().lower()
p =p.replace(" ","")
q = q.replace(" ","")
import re
p = re.sub('[^a-z0-9]','',p)
q= re.sub('[^a-z0-9]','',q)
if sorted(p)==sorted(q):
print('YES')
else:
print('NO')
================================================
FILE: Prime Number.py
================================================
# Write your code here
def prime(x):
l = [True for i in range(x+1)]
p=2
while (p*p <= x):
if l[p]==True:
for i in range(2*p,x+1,p):
l[i] = False
p+=1
for i in range(2,x+1):
if l[i]:
print(i,end=' ')
n = int(input())
prime(n)
================================================
FILE: Priority Interview.py
================================================
n = int(input())
x_y = []
for i in range(n):
a,b = map(int,input().split())
x_y.append([a,b])
x_y.sort(key = lambda x : x[1],reverse = True)
x_y.sort(key = lambda x : x[0])
for i in range(len(x_y)):
print(x_y[i][1],end = ' ')
================================================
FILE: README.md
================================================
# HackerEarth Solutions
Contains hackerearth solutions in python3
================================================
FILE: Rain Sound.py
================================================
t = int(input())
for _ in range(t):
l,r,s = map(int,input().split())
if s > r:
print(-1,-1)
else:
mi = int(((l-1)/s) + 1)
ma = r//s
if mi>ma:
print(-1,-1)
else:
print(mi,ma)
================================================
FILE: Rectangles to squares.py
================================================
# Write your code here
import math
m,n = map(int,input().split())
x = math.gcd(m,n)
if x>1:
print("Yes")
else:
print("No")
================================================
FILE: Reversed Linked List.py
================================================
class node:
def __init__(self,data):
self.data = data
self.next = None
class linkedList:
def __init__(self):
self.head = None
def printl(self):
t =self.head
while t:
print(t.data,end = ' ')
t = t.next
def atLast(self,new_data):
new_node = node(new_data)
if self.head is None:
self.head = new_node
return
temp = self.head
while temp.next:
temp = temp.next
temp.next = new_node
new_node.next = None
def addElement(self,lis):
lis = lis[::-1]
for i in range(len(lis)):
nl.atLast(lis[i])
def reverse(self):
temp = self.head
lis = []
while temp:
#print(temp.data)
if int(temp.data)%2==0:
lis.append(temp.data)
temp = temp.next
else:
if len(lis)>0:
nl.addElement(lis)
lis = []
nl.atLast(temp.data)
temp = temp.next
if len(lis)>0:
nl.addElement(lis)
l = linkedList()
nl = linkedList()
t = int(input())
arr = list(map(int,input().split()))
for i in range(len(arr)):
l.atLast(arr[i])
l.reverse()
nl.printl()
================================================
FILE: Robotic moves.py
================================================
# We only need to calculate for x axis since y axis part will be zero.
#For any more query feel free to mail me.
t = int(input())
for i in range(t):
n = int(input())
print(n*(n+1))
================================================
FILE: Roy and Profile Picture.py
================================================
l = int(input())
t = int(input())
for _ in range(t):
m,n = map(int,input().split())
if m < l or n<l:
print("UPLOAD ANOTHER")
elif m==n:
print("ACCEPTED")
else:
print("CROP IT")
================================================
FILE: Roy and Symmetric Logos.py
================================================
def symmetric(matrix,n):
for i in range(n):
for j in range(n):
if int(matrix[i][0][j]) != int(matrix[n-1-i][0][j]):
return 'NO'
if int(matrix[i][0][j]) != int(matrix[i][0][n-1-j]):
return 'NO'
return 'YES'
t = int(input())
for _ in range(t):
n = int(input())
matrix = []
for i in range(n):
temp = list((input().split()))
matrix.append(temp)
print(symmetric(matrix,n))
================================================
FILE: Saul Goodman's Problem Statement.py
================================================
from collections import defaultdict
t = int(input())
for _ in range(t):
n = int(input())
ans=0
d1=defaultdict(int)
d2=defaultdict(int)
for i in range(n):
a,b=map(int,input().split())
ans+=d1[a+b]
ans+=d2[a-b]
#print("sdsd",ans)
d1[a+b]+=1
d2[a-b]+=1
#print(d1,d2)
print(ans)
================================================
FILE: Save Mrinal.py
================================================
n = int(input())
l = list(map(int,input().split()))
m = int(input())
i=0
temp = []
while i!=m:
qq=[int(x) for x in input().split()]
temp.extend(qq)
if len(temp)>=2:
p= temp.pop(0)
q = temp.pop(0)
new_array = l[p-1:q]
print(len(set(new_array)))
i+=1
else:
pass
================================================
FILE: Seating Arrangement.py
================================================
def find(a):
ch = a%12
if ch==1:
print(a+11,'WS')
elif ch==0:
print(a-11,'WS')
elif ch==6:
print(a+1,'WS')
elif ch==7:
print(a-1,'WS')
elif ch==2:
print(a+9,'MS')
elif ch==3:
print(a+7,'AS')
elif ch==4:
print(a+5,'AS')
elif ch==5:
print(a+3,'MS')
elif ch==8:
print(a-3,'MS')
elif ch==9:
print(a-5,'AS')
elif ch==10:
print(a-7,'AS')
else:
print(a-9,'MS')
n = int(input())
for i in range(n):
a = int(input())
find(a)
================================================
FILE: Seven-Segment Display.py
================================================
# Write your code here
d = {'0': 6,
'1': 2,
'2': 5,
'3': 5,
'4':4,
'5':5,
'6':6,
'7':3,
'8':7,
'9':6}
t = int(input())
for _ in range(t):
n = input()
no_of_matchstick = 0
for i in n:
no_of_matchstick += d[i]
#Case 1 Max number when the no_of Matchstick is even
if no_of_matchstick%2 == 0:
x = int(no_of_matchstick/2)
number = ''
for i in range(x):
number = number + '1'
else:
x = int((no_of_matchstick-3)/2)
number = '7'
for i in range(x):
number = number + '1'
print(number)
================================================
FILE: Simon cannot sleep.py
================================================
import math
h,m = map(int,input().split(":"))
temp = h*60*60 + m*60
a = 0
d = 3927.272727272727
ans = temp/d + 1
print(math.floor(ans))
================================================
FILE: Simple Search.py
================================================
n= int(input())
l = list(map(int,input().split()))
k = int(input())
for i in range(n):
if l[i]==k:
print(i)
================================================
FILE: SnackDown Contest.py
================================================
t = int(input())
for _ in range(t):
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
p= p[1:]
q = q[1:]
z = p+q
z1 = list(set(z))
if len(z1)==n:
print('YES')
else:
print('NO')
================================================
FILE: Speed.py
================================================
testCase = int(input())
for _ in range(testCase):
n = int(input())
l = list(map(int,input().split()))
c=1
ma = l[0]
for i in range(1,n):
if l[i]<=ma:
#print(l[i])
c+=1
ma = l[i]
print(c)
================================================
FILE: Split Houses.py
================================================
n = int(input())
s = input()
consecutive_house = []
temp = 0
arr = ['']*n
for i,j in enumerate(s):
if j == 'H':
arr[i] = 'H'
temp += 1
if i == n-1:
consecutive_house.append(temp)
else:
arr[i] = 'B'
if temp > 0:
consecutive_house.append(temp)
temp = 0
if len(consecutive_house) == 0 or max(consecutive_house) == 1:
print('YES')
print(''.join(arr))
else:
print('NO')
================================================
FILE: Stack and Queue <Nissan>.py
================================================
n , k = map(int,input().split())
l = list(map(int,input().split()))
s = 0
for i in range(k):
s += l[i]
m = s
#print(m)
for i in range(k-1):
#print("sds",i)
s = s - l[k-i-1] + l[n-1-i]
if s>=m:
m=s
print(m)
================================================
FILE: Statistics.py
================================================
# Write your code here
n = int(input())
arr = []
for i in range(n):
l = input().split()
arr.append(l)
from collections import Counter,OrderedDict
d = Counter(OrderedDict())
for i in range(len(arr)):
x = str(arr[i][1])
#print(x,type(x))
if d[x]:
d[x]+=1
else:
d[x]=1
temp = max(d.values())
for k,v in d.items():
if v==temp:
print(k)
break
print(d['football'])
================================================
FILE: Strange Game.py
================================================
testcase = int(input())
for _ in range(testcase):
le,k = map(int,input().split())
alice = list(map(int,input().split()))
bob=list(map(int,input().split()))
x = max(bob)+1
t=0
for i in range(le):
if x-alice[i]>0:
t += (x-alice[i])*k
print(t)
================================================
FILE: String.py
================================================
from collections import Counter
n = int(input())
st = input()
p = Counter(st)
print(n - max(p.values()))
================================================
FILE: Sumita and equal array.py
================================================
t = int(input())
for _ in range(t):
n,x,y,z = map(int,input().split())
l = list(map(int,input().split()))
for i in range(n):
while l[i]%x==0:
l[i] = l[i]/x
while l[i]%y==0:
l[i] = l[i]/y
while l[i]%z==0:
l[i] = l[i]/z
for i in range(1,n):
if l[i]!=l[i-1]:
print("She can't")
break
else:
print('She can')
================================================
FILE: Takeoff.py
================================================
t = int(input())
for i in range(t):
n,p,q,r = map(int,input().split())
c=0
for i in range(1,n+1):
if (i%p==0)and (i%q!=0)and (i%r!=0):
c+=1
if (i%p!=0)and (i%q==0)and (i%r!=0):
c+=1
if (i%p!=0)and (i%q!=0)and (i%r==0):
c+=1
print(c)
================================================
FILE: Terrible Chandu.py
================================================
n = int(input())
for i in range(n):
a = input()
print(a[::-1])
================================================
FILE: The Amazing Race.py
================================================
# Write your code here
# To understand the question go to link : https://www.geeksforgeeks.org/largest-rectangle-under-histogram/
t = int(input())
for _ in range(t):
n= int(input())
ar = list(map(int,input().split()))
flist = [0]*n
stack = list()
i=0
while i<n:
if not stack or ar[stack[-1]]>=ar[i]:
stack.append(i)
#print(stack)
i+=1
else:
top = stack.pop()
if not stack:
flist[top] = top
#print("flidggfd",flist[top])
else:
#print("top",top)
flist[top] = top-stack[-1]
#print("flist",flist[i])
while stack:
top = stack.pop()
if not stack:
flist[top] = top
#print("sdfdf",flist[top])
else:
#print("top",top)
flist[top] = top-stack[-1]
#print("flist",flist[i])
blist = [0]*n
br = ar[::-1]
#print(br)
stack1 = list()
i=0
while i<n:
if not stack1 or br[stack1[-1]]>=br[i]:
stack1.append(i)
#print(stack1)
i+=1
else:
top = stack1.pop()
if not stack1:
blist[top] = top
#print("flidggfd",blist[top])
else:
#print("top",top)
blist[top] = top-stack1[-1]
#print("flist",flist[i])
while stack1:
top = stack1.pop()
if not stack1:
blist[top] = top
#print("sdfdf",blist[top])
else:
#print("top",top)
blist[top] = top-stack1[-1]
#print("flist",flist[i])
backlist = blist[::-1]
res_list = []
for i in range(0, len(backlist)):
res_list.append(backlist[i] + flist[i])
sight = []
for i in range(1,len(res_list)+1):
sight.append((i*res_list[i-1])%1000000007)
temp = sight.index(max(sight))+1
print(temp)
================================================
FILE: The Monk and Kundan.py
================================================
def index(ref,x):
for i in range(len(ref)):
if ref[i]==x:
return i
ref = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ref = list(ref)
n = int(input())
for i in range(n):
l = list(input().split())
s=0
for i in range(len(l)):
for j in range(len(l[i])):
t= index(ref,l[i][j])
s+=j+ t
print(s*len(l))
================================================
FILE: The best Internet Browser.py
================================================
from fractions import Fraction
t = int(input())
for _ in range(t):
s = input()
n = len(s)
c=0
for j in range(4,n-4):
#print(s[i])
if (s[j] != 'a') and (s[j] != 'e') and (s[j]!= 'i') and (s[j] != 'o') and (s[j] !='u') :
c+=1
print(c+4,end ='')
print('/',end = '')
print(n)
================================================
FILE: Thief and Warehouses.py
================================================
def solve (array, n):
stack = []
i=0
max_a=0
area = 0
while i<len(array):
if not stack or (array[stack[-1]]<=array[i]):
stack.append(i)
i+=1
#print(stack)
else:
top = stack.pop()
if stack:
area = array[top]*(i-1-stack[-1])
else:
area = array[top]*(i)
max_a = max(max_a,area)
while stack:
top = stack.pop()
if stack:
area = array[top]*(i-1-stack[-1])
else:
area = array[top]*(i)
max_a = max(max_a,area)
return max_a
# Write your code here
T = int(input())
for _ in range(T):
n = int(input())
Ar = list(map(int, input().split()))
out_ = solve(Ar, n)
print (out_)
================================================
FILE: Toggle String.py
================================================
n = input()
print(n.swapcase())
================================================
FILE: Two Strings.py
================================================
from collections import Counter
def check(a,b):
p = Counter(a)
q = Counter(b)
if sum((p-q).values())==0:
print('YES')
else:
print('NO')
n = int(input())
for _ in range(n):
a,b = input().split()
check(a,b)
================================================
FILE: VC pairs.py
================================================
test_cases = int(input())
for _ in range(test_cases):
n = int(input())
s = input()
count = 0
for i in range(n-1):
if s[i] != 'a' and s[i] != 'e' and s[i] != 'i' and s[i] != 'o' and s[i] != 'u' :
if s[i+1] == 'a' or s[i+1] == 'e' or s[i+1] == 'i' or s[i+1] == 'o' or s[i+1] == 'u' :
count += 1
print(count)
================================================
FILE: Vada Pav List.py
================================================
n = int(input())
l = []
for i in range(n):
x = input()
l.append(x)
l = list(set(l))
l.sort()
print(len(l))
for i in l:
print(i)
================================================
FILE: Weighing the Stones.py
================================================
from collections import Counter
testCase = int(input())
for _ in range(testCase):
n = int(input())
rupam = list(map(int,input().split()))
ankit = list(map(int,input().split()))
r =Counter(rupam)
a = Counter(ankit)
mr_k= 0
mr_v=0
for k,v in r.items():
#print(k,v)
if v>=mr_v:
if v>mr_v:
mr_v = v
mr_k = k
else:
if k>mr_k:
mr_k = k
mr_v = v
mr = max(r.keys())
if r[mr]>=mr_v:
mr_k = mr
ma_k= 0
ma_v=0
for k,v in a.items():
#print(k,v)
if v>=ma_v:
if v>ma_v:
ma_v = v
ma_k = k
elif v==ma_v:
if k>ma_k:
ma_k = k
ma_v = v
#print(ma_k)
ma = max(a.keys())
if a[ma]>=ma_v:
ma_k = ma
if mr_k>ma_k:
print('Rupam')
elif mr_k<ma_k:
print('Ankit')
else:
print("Tie")
================================================
FILE: Wet Clothes.py
================================================
n,m,g = input().split()
t = list(map(int,input().split()))
a = list(map(int,input().split()))
gap =[]
for i in range(len(t)-1):
x = t[i+1]-t[i]
gap.append(x)
m = max(gap)
c=0
for i in range(len(a)):
if a[i]<=m:
c+=1
print(c)
================================================
FILE: Word Queries.py
================================================
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
class TrieNode:
def __init__(self):
self.EndofWord =False
self.children = [None]*26
self.word_count = 0
class Trie:
def __init__(self):
self.root = self.getNode()
def getNode(self):
return TrieNode()
def charToint(self,char):
return ord(char) -ord('a')
def insert(self,key):
temp = self.root
l = len(key)
for i in range(l):
#print(i)
x = self.charToint(key[i])
#print("This is x",x)
if not temp.children[x]:
temp.children[x] = self.getNode()
temp = temp.children[x]
temp.word_count +=1
temp.EndofWord = True
def get_prefix(self,key):
temp =self.root
for i in range(len(key)):
x = self.charToint(key[i])
if not temp.children[x]:
return None
temp = temp.children[x]
return temp
def find(self,key):
node = self.get_prefix(key)
#print(node)
return node.word_count if node else 0
t = Trie()
n,q = map(int,input().split())
for i in range(n):
t.insert(input())
for i in range(q):
x = t.find(input())
print(x)
================================================
FILE: balanced brackets.py
================================================
n = int(input())
for _ in range(n):
s = list(input())
op = ["{","[","("]
cl = ["}","]",")"]
st = [s[0]]
for i in range(1,len(s)):
if st:
temp =s[i]
if temp in op:
st.append(temp)
else:
ind = cl.index(s[i])
if st[-1]==op[ind]:
st.pop()
else:
st.append(s[i])
if len(st)>0:
print("NO")
else:
print("YES")
================================================
FILE: e-maze-in.py
================================================
n = input()
x,y = 0,0
for i in n:
if i == 'L':
x -= 1
elif i == 'R':
x += 1
elif i == 'U':
y += 1
elif i == 'D':
y -= 1
print(x,y)
================================================
FILE: square sub matrix.py
================================================
t = int(input())
for _ in range(t):
n,m = map(int,input().split())
matrix = []
for i in range(n):
x = list(map(int,input().split()))
matrix.append(x)
m2 = [[0 for _ in range(m)] for _ in range(n)]
ma= 0
for i in range(n):
for j in range(m):
if i==0 or j==0:
#print(i,j)
m2[i][j] = matrix[i][j]
if ma<m2[i][j]:
ma = m2[i][j]
elif matrix[i][j]==0:
m2[i][j] =0
else:
m2[i][j] = matrix[i][j] + min(m2[i-1][j],m2[i-1][j-1],m2[i][j-1])
if m2[i][j] >ma:
ma = m2[i][j]
print(ma*ma)
================================================
FILE: super reduced strings.py
================================================
s = input()
stack = [s[0]]
for i in range(1,len(s)):
if stack:
if stack[-1]== s[i]:
#print("ssds",stack)
stack.pop()
else:
stack.append(s[i])
else:
stack.append(s[i])
#stack.append(s[i])
if len(stack)>0:
print(''.join(stack))
else:
print('Empty String')
================================================
FILE: zoos.py
================================================
# Write your code here
s = input()
from collections import Counter
d = Counter(s)
if d['z']*2 == d['o']:
print("Yes")
else:
print("No")
gitextract_2juf35yw/ ├── 2 arrays.py ├── @K R-r-riddikulus! once again.py ├── A Special Number.py ├── A beauty factor.py ├── Achhe Din.py ├── Add Alternate Elements of 2-Dimensional Array.py ├── Alien language.py ├── All Vowels.py ├── AltF4 and the beetles.py ├── Anagrams.py ├── Anshul, Usama And Punishment - A.py ├── Anti-palindrome strings.py ├── Arjit and Apex.py ├── Array operations.py ├── ArrayGame.py ├── Bag Of Numbers.py ├── Best Index.py ├── Biased Chandan.py ├── Binary Queries.py ├── Breakup App.py ├── Bricks Game.py ├── CAn you solve it?.py ├── Chandu and Consecutive Letters.py ├── Char Sum.py ├── Charged Up Array.py ├── Cost of balloons.py ├── Count Divisors.py ├── Counting Triangles.py ├── Crazy Kangaroo.py ├── Dedication Level = Infinity.py ├── Determining numbers.py ├── Difficult Characters.py ├── Digital Sequence.py ├── Distribute chocolates.py ├── Divisibility.py ├── Divisible.py ├── Does it Divide?.py ├── Duration.py ├── EEDC Lab.py ├── Easy Sum Set Problem.py ├── Easy one.py ├── Equal elements ├── Equalize strings.py ├── Erasing an array.py ├── Exchanging money.py ├── Factorial!.py ├── Find Product.py ├── Find the String.py ├── Finding the Subarrays.py ├── Finding vaccines.py ├── Fredo and Large Numbers.py ├── Frequency of Students.py ├── Going to office.py ├── Grid and phrase.py ├── Hackers with Bits.py ├── Hamiltonian and Lagrangian.py ├── Hello.py ├── Help Jarvis!.py ├── Honey Bees.py ├── ICPC Team Management.py ├── James and the menus.py ├── LAL Evaluation.py ├── Length of Valley ├── Life, the Universe, and Everything.py ├── Lift queries.py ├── Little Monk and Balanced Parentheses.py ├── Little_Jhool_psychic_powers.py ├── Long ATM Queue.py ├── Lunch boxes.py ├── MYSTERY.py ├── Manna's First Name.py ├── Mark The Answer.py ├── Mathematically beautiful numbers.py ├── Maximize the Earning.py ├── Maximize the modulo function.py ├── Maximum Of K- size subarrays (Deque).py ├── Maximum Sum.py ├── Maximum goodness.py ├── Maximum occurrence.py ├── Maze Problem.py ├── Memorise Me!.py ├── Micro and Array Update.py ├── Min-Max.py ├── Mind Palaces.py ├── Minimum Add to Make Parentheses Valid.py ├── Minimum moves.py ├── Modify Sequence.py ├── Modulo Strength.py ├── Monk And the operations.py ├── Monk Takes a Walk.py ├── Monk Teaches Palindrome.py ├── Monk and Inversions.py ├── Monk and Lucky Minimum.py ├── Monk and Power of Time.py ├── Monk and Rotation.py ├── Monk and Welcome Problem.py ├── Most Frequent.py ├── Multiple occurrences.py ├── N - Co Ordinates (Pair Practice).py ├── Neutralisation of charges.py ├── Not in Range.py ├── Number of cycles.py ├── Number of steps.py ├── Pair Sum.py ├── Pairs.py ├── Palindromic String.py ├── Passing the Parcel.py ├── Pepper and Contiguous Even Subarray.py ├── Perfect Subarray.py ├── Permute the Array.py ├── Polygon Possibility ├── Prasun the detective.py ├── Prime Number.py ├── Priority Interview.py ├── README.md ├── Rain Sound.py ├── Rectangles to squares.py ├── Reversed Linked List.py ├── Robotic moves.py ├── Roy and Profile Picture.py ├── Roy and Symmetric Logos.py ├── Saul Goodman's Problem Statement.py ├── Save Mrinal.py ├── Seating Arrangement.py ├── Seven-Segment Display.py ├── Simon cannot sleep.py ├── Simple Search.py ├── SnackDown Contest.py ├── Speed.py ├── Split Houses.py ├── Stack and Queue <Nissan>.py ├── Statistics.py ├── Strange Game.py ├── String.py ├── Sumita and equal array.py ├── Takeoff.py ├── Terrible Chandu.py ├── The Amazing Race.py ├── The Monk and Kundan.py ├── The best Internet Browser.py ├── Thief and Warehouses.py ├── Toggle String.py ├── Two Strings.py ├── VC pairs.py ├── Vada Pav List.py ├── Weighing the Stones.py ├── Wet Clothes.py ├── Word Queries.py ├── balanced brackets.py ├── e-maze-in.py ├── square sub matrix.py ├── super reduced strings.py └── zoos.py
SYMBOL INDEX (38 symbols across 21 files)
FILE: A Special Number.py
function getSum (line 11) | def getSum(n):
FILE: A beauty factor.py
function checkBeautyFactor (line 7) | def checkBeautyFactor(n):
FILE: Anagrams.py
function cc (line 3) | def cc(a,b):
FILE: Array operations.py
function kadaneSum (line 5) | def kadaneSum(arr,n):
FILE: Does it Divide?.py
function prime (line 2) | def prime(n) :
FILE: Fredo and Large Numbers.py
function index (line 3) | def index(t,f,ma,p,q,s,d):
FILE: Maximize the modulo function.py
function solve (line 20) | def solve(k, n,m):
FILE: Maze Problem.py
function issafe (line 1) | def issafe(p,q,arr):
function solve (line 8) | def solve(arr,i,j,sol):
FILE: Mind Palaces.py
function binar (line 1) | def binar(arr,l,r,x):
FILE: Monk And the operations.py
function abs_sum (line 1) | def abs_sum(row):
function abs_add (line 7) | def abs_add(row,v1):
FILE: Monk and Power of Time.py
function check (line 5) | def check(a,b):
FILE: Pairs.py
function isPrime (line 1) | def isPrime(n) :
FILE: Perfect Subarray.py
function checkperfect (line 5) | def checkperfect(n):
FILE: Prime Number.py
function prime (line 2) | def prime(x):
FILE: Reversed Linked List.py
class node (line 1) | class node:
method __init__ (line 2) | def __init__(self,data):
class linkedList (line 6) | class linkedList:
method __init__ (line 8) | def __init__(self):
method printl (line 13) | def printl(self):
method atLast (line 20) | def atLast(self,new_data):
method addElement (line 36) | def addElement(self,lis):
method reverse (line 44) | def reverse(self):
FILE: Roy and Symmetric Logos.py
function symmetric (line 1) | def symmetric(matrix,n):
FILE: Seating Arrangement.py
function find (line 1) | def find(a):
FILE: The Monk and Kundan.py
function index (line 1) | def index(ref,x):
FILE: Thief and Warehouses.py
function solve (line 1) | def solve (array, n):
FILE: Two Strings.py
function check (line 2) | def check(a,b):
FILE: Word Queries.py
class TrieNode (line 11) | class TrieNode:
method __init__ (line 12) | def __init__(self):
class Trie (line 17) | class Trie:
method __init__ (line 18) | def __init__(self):
method getNode (line 21) | def getNode(self):
method charToint (line 24) | def charToint(self,char):
method insert (line 27) | def insert(self,key):
method get_prefix (line 42) | def get_prefix(self,key):
method find (line 52) | def find(self,key):
Condensed preview — 153 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (77K chars).
[
{
"path": "2 arrays.py",
"chars": 646,
"preview": "n = int(input())\narr = list(map(int,input().split()))\nbrr = list(map(int,input().split()))\naneg = 0\nbneg = 0\nasum = 0\nbs"
},
{
"path": "@K R-r-riddikulus! once again.py",
"chars": 111,
"preview": "n,d = map(int,input().split())\na = list(map(int,input().split()))\nprint(*(a[d:]+a[:d]))\n#print(*(a[d:]+a[:d]))\n"
},
{
"path": "A Special Number.py",
"chars": 582,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "A beauty factor.py",
"chars": 1310,
"preview": "# Simple Brute Force implementation \n#First we check that whether the length (k) is 9 or not because if k ==9 then we c"
},
{
"path": "Achhe Din.py",
"chars": 210,
"preview": "testCase = int(input())\nfrom collections import Counter\nfor _ in range(testCase):\n n = int(input())\n ide = Counter"
},
{
"path": "Add Alternate Elements of 2-Dimensional Array.py",
"chars": 78,
"preview": "a,b,c,d,e,f,g,h,i = map(int,input().split())\n\nprint(a+c+e+g+i)\nprint(b+d+f+h)\n"
},
{
"path": "Alien language.py",
"chars": 214,
"preview": "n = int(input())\nfor i in range(n):\n first_word = input()\n second_word = input()\n for i in second_word:\n "
},
{
"path": "All Vowels.py",
"chars": 322,
"preview": "n = int(input())\ns = input()\na = 0\ne=0\ni=0\no=0\nu=0\nfor j in range(n):\n if s[j]=='a':\n a+=1\n if s[j]=='e':\n "
},
{
"path": "AltF4 and the beetles.py",
"chars": 928,
"preview": "\nfor _ in range(int(input())):\n n,a,b,c = map(int,input().split())\n \n #store the beetles with 0 or 1 \n #0 me"
},
{
"path": "Anagrams.py",
"chars": 241,
"preview": "from collections import Counter\n# Write your code here\ndef cc(a,b):\n p = Counter(a)\n q = Counter(b)\n print(sum("
},
{
"path": "Anshul, Usama And Punishment - A.py",
"chars": 298,
"preview": "n = int(input())\nl = [20,30,40,90,80]\nif n>len(l):\n for i in range(5,n+1):\n if i%2==0:\n l.append(2*"
},
{
"path": "Anti-palindrome strings.py",
"chars": 403,
"preview": "# Simple Solution First sort the string if sorted string is palindrome then print (-1) else print the sorted string. Bec"
},
{
"path": "Arjit and Apex.py",
"chars": 723,
"preview": "t = int(input())\nfor _ in range(t):\n m,n = map(int,input().split())\n d = dict()\n new = dict()\n for i in rang"
},
{
"path": "Array operations.py",
"chars": 776,
"preview": "# Knowledge of Kadane algorithm \n#To understand the below algorithm I highly recommend you to visit https://www.geeksfor"
},
{
"path": "ArrayGame.py",
"chars": 357,
"preview": "n,m=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\na.sort()\nb.sort(reverse=T"
},
{
"path": "Bag Of Numbers.py",
"chars": 86,
"preview": "n=input().split()\nif (len(n)<4):\n n[0]=\"output\"\nelse:\n n[0]=\"output:\"\nprint(*n)\n"
},
{
"path": "Best Index.py",
"chars": 1538,
"preview": "\n## Explaination : \n'''\nStep 1 : First we will find out till what index the zeroth index can go for example consider the"
},
{
"path": "Biased Chandan.py",
"chars": 168,
"preview": "n = int(input())\nx=[]\nfor i in range(n):\n inq = int(input())\n if inq == 0:\n if len(x)>0:\n x.pop("
},
{
"path": "Binary Queries.py",
"chars": 419,
"preview": "n,q = map(int,input().split())\nl =list(map(int,input().split()))\nq2 = [[ None for _ in range(3)] for _ in range(q)] \nfor"
},
{
"path": "Breakup App.py",
"chars": 579,
"preview": "n = int(input())\nresult = {}\nmsg = []\nfor _ in range(n):\n msg.append(list(input().split()))\nfor i in range(n):\n fo"
},
{
"path": "Bricks Game.py",
"chars": 185,
"preview": "n = int(input())\ntemp = n\nfor i in range(temp):\n n = n - i \n if n<=0 :\n print(\"Patlu\")\n break\n \n"
},
{
"path": "CAn you solve it?.py",
"chars": 261,
"preview": "testCase = int(input())\nfor _ in range(testCase):\n n = int(input())\n l = list(map(int,input().split()))\n mi = ["
},
{
"path": "Chandu and Consecutive Letters.py",
"chars": 257,
"preview": "n = int(input())\nfor i in range(n):\n s = input()\n st = []\n for i in range(len(s)):\n if len(st)==0:\n "
},
{
"path": "Char Sum.py",
"chars": 143,
"preview": "d = {}\nn = input()\ns = 'abcdefghijklmnopqrstuvwxyz'\nfor i,j in enumerate(s):\n d[j] = i+1\ncost = 0\nfor i in n:\n cos"
},
{
"path": "Charged Up Array.py",
"chars": 226,
"preview": "\nT = int(input())\nm = pow(10,9)+7\nfor _ in range(T):\n N = int(input())\n A = list(map(int, input().split()))\n s="
},
{
"path": "Cost of balloons.py",
"chars": 498,
"preview": "test_cases = int(input())\nfor i in range(test_cases):\n p,g = map(int, input().split())\n n = int(input())\n\n cost"
},
{
"path": "Count Divisors.py",
"chars": 115,
"preview": "l,r,k = map(int,input().split())\nc=0\nfor i in range(l,r+1):\n if i%k==0:\n #print(i)\n c+=1\nprint(c)\n"
},
{
"path": "Counting Triangles.py",
"chars": 258,
"preview": "n = int(input())\nl = []\nfor _ in range(n):\n a = tuple(map(int,input().split()))\n a = sorted(a)\n \n l.append(t"
},
{
"path": "Crazy Kangaroo.py",
"chars": 169,
"preview": "t = int(input())\nfor _ in range(t):\n a,b,m = map(int,input().split())\n ans =0 \n for i in range(a,b+1):\n "
},
{
"path": "Dedication Level = Infinity.py",
"chars": 241,
"preview": "n= int(input())\nl = [[0 for i in range(2)]for i in range(n)]\nfor i in range(n):\n l[i] = list(input().split())\nfor i i"
},
{
"path": "Determining numbers.py",
"chars": 234,
"preview": "# Write your code here\nfrom collections import Counter\n\nn = int(input())\narr = list(map(int,input().split()))\na = Counte"
},
{
"path": "Difficult Characters.py",
"chars": 524,
"preview": "n = int(input())\nfor _ in range(n):\n s = input()\n from collections import Counter\n s2 = 'abcdefghijklmnopqrstuw"
},
{
"path": "Digital Sequence.py",
"chars": 200,
"preview": "a=int(input())\nb=list(input().split())\nmax=0\nfor i in range(10):\n i=str(i)\n count=0\n for j in b:\n if(i i"
},
{
"path": "Distribute chocolates.py",
"chars": 989,
"preview": "#Logic : Since there are n students and each student will recienve atleast one chocalate and the next student will recei"
},
{
"path": "Divisibility.py",
"chars": 335,
"preview": "#If the last element contions zero then only we can divide the number formed by taking the last number by 10\n# Therefore"
},
{
"path": "Divisible.py",
"chars": 248,
"preview": "n = int(input())\ns = list(input().split())\n\nhalf = n/2\nx = []\nfor i in range(n):\n if i < half:\n x.append(s[i]["
},
{
"path": "Does it Divide?.py",
"chars": 710,
"preview": "\ndef prime(n) : \n \n # Corner cases \n if (n <= 1) : \n return 0\n if (n <= 3) : \n return 1\n \n #"
},
{
"path": "Duration.py",
"chars": 310,
"preview": "t = int(input())\nfor _ in range(t):\n sh,sm,eh,em = list(map(int,input().split()))\n starting_min = sh*60 + sm\n e"
},
{
"path": "EEDC Lab.py",
"chars": 694,
"preview": "n = int(input())\na = list(map(int,input().split()))\n\ntmp_sum = sum(a)\nlucky = []\nif n == 1:\n lucky.append(1)\nelse:\n "
},
{
"path": "Easy Sum Set Problem.py",
"chars": 361,
"preview": "n = int(input())\na = list(map(int,input().split()))\nm = int(input())\nc = list(map(int,input().split()))\nl=[]\nfor i in ra"
},
{
"path": "Easy one.py",
"chars": 276,
"preview": "from collections import Counter,defaultdict\nt = int(input())\nfor _ in range(t):\n n,q = map(int,input().split())\n a"
},
{
"path": "Equal elements",
"chars": 758,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "Equalize strings.py",
"chars": 202,
"preview": "n = int(input())\nx = input()\ny = input()\nc = 0\nl = 0\nfor i in range(n):\n if x[i] != y[i]:\n c+=1\n else:\n "
},
{
"path": "Erasing an array.py",
"chars": 405,
"preview": "#When we encounter 1,0 sequence we have inversion and we can't erase the solution \n#Therefore the simple solution here i"
},
{
"path": "Exchanging money.py",
"chars": 251,
"preview": "import math\n\nn,q = map(int,input().split())\narr = list(map(int,input().split()))\n\ng= arr[0]\nfor i in range(n):\n g = m"
},
{
"path": "Factorial!.py",
"chars": 54,
"preview": "import math\nn = int(input())\nprint(math.factorial(n))\n"
},
{
"path": "Find Product.py",
"chars": 129,
"preview": "x = pow(10,9)+7\nn = int(input())\nl = list(map(int,input().split()))\nans =1\nfor i in range(n):\n ans = (ans*l[i])%x\npr"
},
{
"path": "Find the String.py",
"chars": 729,
"preview": "t = int(input())\nfrom collections import Counter\nfor _ in range(t):\n n,m = map(int,input().split())\n matrix = {}\n "
},
{
"path": "Finding the Subarrays.py",
"chars": 485,
"preview": "n = int(input())\nl1 = list(map(int,input().split()))\nma = pow(10,7)\nind1= [0]*(ma)\nind2 = [0]*(ma)\ntemp=0 \n\nfor i in ran"
},
{
"path": "Finding vaccines.py",
"chars": 766,
"preview": "# Simple Brute force \n# Since the interaction are between \"C\" and \"G\" RNA we calculate the number of \"C\" and \"G\" molecul"
},
{
"path": "Fredo and Large Numbers.py",
"chars": 711,
"preview": "import sys\n \ndef index(t,f,ma,p,q,s,d):\n if f>ma:\n return 0 \n if t==0:\n for k,v in d.items():\n "
},
{
"path": "Frequency of Students.py",
"chars": 184,
"preview": "# Write your code here\nn = int(input())\nd = {}\nfor _ in range(n):\n x = input()\n if x in d:\n d[x]+=1\n els"
},
{
"path": "Going to office.py",
"chars": 585,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "Grid and phrase.py",
"chars": 1313,
"preview": "n,m = map(int,input().split())\nmatrix = []\nfor i in range(n):\n a= list(input())\n matrix.append(a)\nc=0\n#horizontal\n"
},
{
"path": "Hackers with Bits.py",
"chars": 278,
"preview": "n = int(input())\nl = input()\n\ns1 = l.count('1')\ns2 = l.count('0')\ns= l.split('0')\n\nm = 0\nfor i in range(len(s)-1):\n "
},
{
"path": "Hamiltonian and Lagrangian.py",
"chars": 185,
"preview": "n = int(input())\nl = list(map(int,input().split()))[::-1]\npq = []\npq.append(l[0])\nm = l[0]\nfor i in range(1,n):\n if "
},
{
"path": "Hello.py",
"chars": 21,
"preview": "print('Hello Kirti')\n"
},
{
"path": "Help Jarvis!.py",
"chars": 298,
"preview": "t = int(input())\nfor i in range(t):\n \n l = input()\n li = []\n for i in l:\n li.append(int(i))\n mi = "
},
{
"path": "Honey Bees.py",
"chars": 3023,
"preview": "for _ in range(int(input())):\n n, m = map(int, input().split())\n M = [list(map(int, input().split())) for __ in ra"
},
{
"path": "ICPC Team Management.py",
"chars": 417,
"preview": "t = int(input())\n\nfor _ in range(t):\n n,k = map(int,input().split())\n \n from collections import Counter\n d ="
},
{
"path": "James and the menus.py",
"chars": 1021,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "LAL Evaluation.py",
"chars": 280,
"preview": "n,m = map(int,input().split())\narr = list(map(int,input().split()))\n\nd = dict()\nc= 0\nfor i in range(n):\n temp = m-arr"
},
{
"path": "Length of Valley",
"chars": 1533,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "Life, the Universe, and Everything.py",
"chars": 90,
"preview": "while True:\n n = int(input())\n if n == 42:\n break\n else:\n print(n)\n"
},
{
"path": "Lift queries.py",
"chars": 224,
"preview": "test_case = int(input())\na = 0\nb = 7\nfor i in range(test_case):\n f = int(input())\n temp = abs(f-a)\n temp2 = abs"
},
{
"path": "Little Monk and Balanced Parentheses.py",
"chars": 385,
"preview": "n = int(input())\na = list(map(int,input().split()))\ns = []\nans = 0\n \nfor i in range(0,n):\n if a[i] > 0:\n s.app"
},
{
"path": "Little_Jhool_psychic_powers.py",
"chars": 220,
"preview": "#Basics of Implementation\n#hackerearth\n#Little Jhool Psychic Powers\n#Solution\n\nn = input()\nif '111111' in n:\n print(\""
},
{
"path": "Long ATM Queue.py",
"chars": 142,
"preview": "# Write your code here\nn = int(input())\nl = list(map(int,input().split()))\nc=1\nfor i in range(n-1):\n if l[i+1]<l[i]:\n"
},
{
"path": "Lunch boxes.py",
"chars": 540,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "MYSTERY.py",
"chars": 119,
"preview": "while True:\n try:\n n = int(input())\n s = bin(n)\n print(s.count('1'))\n except:\n break\n"
},
{
"path": "Manna's First Name.py",
"chars": 184,
"preview": "t = int(input())\nword = 'SUVO'\nword1 = 'SUVOJIT'\nfor _ in range(t):\n s = input()\n c = s.count(word)\n c2 = s.co"
},
{
"path": "Mark The Answer.py",
"chars": 192,
"preview": "n,k = map(int,input().split())\nl = list(map(int,input().split()))\nc=0\nskip=0\nfor i in range(n):\n if l[i]<=k and skip<"
},
{
"path": "Mathematically beautiful numbers.py",
"chars": 1083,
"preview": "#Step 1 : We first find out the powers of numbes smaller than or equal to x.Eg x = 91 ,k = 3 so we first find out [1,3,9"
},
{
"path": "Maximize the Earning.py",
"chars": 236,
"preview": "s=int(input())\nfor i in range(s):\n n,r = map(int,input().split())\n l = list(map(int,input().split()))\n \n c=0"
},
{
"path": "Maximize the modulo function.py",
"chars": 822,
"preview": "'''\nThis code uses two formula to solve that is :\nif c = a + b then \nc mod(n) = [ a mod(n) + b mod(n)] mod(n)\nexample: c"
},
{
"path": "Maximum Of K- size subarrays (Deque).py",
"chars": 158,
"preview": "n,m= map(int,input().split())\nl = list(map(int,input().split()))\nx=[]\nfor i in range(0,n):\n if len(l[i:m+i])==m:\n "
},
{
"path": "Maximum Sum.py",
"chars": 209,
"preview": "n = int(input())\narr= list(map(int,input().split()))\ns = 0\nc = 0\nfor i in range(len(arr)):\n if arr[i]>=0:\n s "
},
{
"path": "Maximum goodness.py",
"chars": 656,
"preview": "n = int(input())\nl = list(map(int,input().split()))\n\nans = [1]\nle = [1]\n#d = {}\n#d[1] =1\nfor i in range(1,n):\n \n i"
},
{
"path": "Maximum occurrence.py",
"chars": 217,
"preview": "l = list(input())\nfrom collections import Counter\nd = Counter(l)\ntemp = max(d.values())\nli = []\nfor k,v in d.items():\n "
},
{
"path": "Maze Problem.py",
"chars": 876,
"preview": "def issafe(p,q,arr):\n #print(type(p),type(n))\n if p<n and p>=0 and q<n and q>=0 and arr[p][q]==1:\n #print(\""
},
{
"path": "Memorise Me!.py",
"chars": 227,
"preview": "from collections import Counter\nn= int(input())\na = list(map(int,input().split()))\nm = int(input())\np = Counter(a)\nfor i"
},
{
"path": "Micro and Array Update.py",
"chars": 192,
"preview": "n= int(input())\nfor _ in range(n):\n le,k = map(int,input().split())\n array = list(map(int,input().split()))\n x"
},
{
"path": "Min-Max.py",
"chars": 146,
"preview": "n = int(input())\narr = list(map(int,input().split()))\nma = max(arr)\nmi = min(arr)\n\ns = sum(arr)\n\na1_max = s-mi\na2_min = "
},
{
"path": "Mind Palaces.py",
"chars": 665,
"preview": "def binar(arr,l,r,x):\n if r >=l:\n mid = int(l+ (r-l)/2)\n if arr[mid]==x:\n return mid\n "
},
{
"path": "Minimum Add to Make Parentheses Valid.py",
"chars": 363,
"preview": "s = input()\n\nop = '('\ncl = ')'\nst = [s[0]]\nfor i in range(1,len(s)):\n #print(st)\n if st:\n temp =s[i]\n "
},
{
"path": "Minimum moves.py",
"chars": 149,
"preview": "n = int(input())\nfor _ in range(n):\n x,y = map(int,input().split())\n if x<0 or y<0 or y>x:\n print(-1)\n e"
},
{
"path": "Modify Sequence.py",
"chars": 245,
"preview": "n = int(input())\nl = list(map(int,input().split()))\n\n\n\nfor i in range(n-1):\n if l[i]<=l[i+1]:\n l[i+1] = l[i+1]"
},
{
"path": "Modulo Strength.py",
"chars": 288,
"preview": "#NOTE array b is used to store the count of number of student that have same strength\n\n# Write your code here\nn,k = map("
},
{
"path": "Monk And the operations.py",
"chars": 1198,
"preview": "def abs_sum(row):\n s =0\n for i in range(len(row)):\n s += abs(row[i])\n return s\n \ndef abs_add(row,v1):"
},
{
"path": "Monk Takes a Walk.py",
"chars": 224,
"preview": "t = int(input())\nfor _ in range(t):\n s = input()\n s = s.lower()\n c=0\n for i in range(len(s)):\n \n "
},
{
"path": "Monk Teaches Palindrome.py",
"chars": 210,
"preview": "t = int(input())\nfor _ in range(t):\n s = input()\n n = len(s)\n if s == s[::-1]:\n if n%2==0:\n p"
},
{
"path": "Monk and Inversions.py",
"chars": 448,
"preview": "t = int(input())\nfor _ in range(t):\n n= int(input())\n matrix = []\n for i in range(n):\n a = list(map(int,"
},
{
"path": "Monk and Lucky Minimum.py",
"chars": 254,
"preview": "testCase = int(input())\nfrom collections import Counter\nfor _ in range(testCase):\n n = int(input())\n l = list(map"
},
{
"path": "Monk and Power of Time.py",
"chars": 376,
"preview": "n = int(input())\ncall = list(map(int,input().split()))\nideal = list(map(int,input().split()))\n\ndef check(a,b):\n if a["
},
{
"path": "Monk and Rotation.py",
"chars": 176,
"preview": "testCase = int(input())\nfor _ in range(testCase):\n n,k = map(int,input().split())\n l = list(map(int,input().split"
},
{
"path": "Monk and Welcome Problem.py",
"chars": 146,
"preview": "n= int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nc = [0]*n\nfor i in range(n):\n c"
},
{
"path": "Most Frequent.py",
"chars": 182,
"preview": "from collections import Counter\nn =int(input())\nl = Counter(list(map(int,input().split())))\nx = 100000\nfor k,v in l.item"
},
{
"path": "Multiple occurrences.py",
"chars": 498,
"preview": "# Simple Brute force implementation\n# Only thing to note here is that in the dictonary/HaspMap we are storing key and li"
},
{
"path": "N - Co Ordinates (Pair Practice).py",
"chars": 192,
"preview": "from collections import Counter\nn = int(input())\nd = Counter()\nfor i in range(n):\n x = tuple(map(int,input().split())"
},
{
"path": "Neutralisation of charges.py",
"chars": 325,
"preview": "n = int(input())\ns =input()\n\n\nl = list(s)\nstack = []\nstack.append(l[0])\nfor i in range(1,len(l)):\n stack.append(l[i])"
},
{
"path": "Not in Range.py",
"chars": 482,
"preview": "k = sum([i for i in range(1,1000001)])\nt = int(input())\nl = []\nfor _ in range(t):\n x,y = map(int,input().split())\n "
},
{
"path": "Number of cycles.py",
"chars": 187,
"preview": "#Simple Cycles - No.of closed figure . \n#Hint - See Pattern\n\n# Write your code here\nt = int(input())\nfor _ in range(t):\n"
},
{
"path": "Number of steps.py",
"chars": 734,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "Pair Sum.py",
"chars": 330,
"preview": "n,m= map(int,input().split())\nfrom collections import Counter\narr = list(map(int,input().split()))\nd = Counter(arr)\n\n\nfl"
},
{
"path": "Pairs.py",
"chars": 646,
"preview": "def isPrime(n) : \n \n # Corner cases\n allprime = [True for i in range(ma+1)]\n\n p=2\n x = [0]*(n+1)\n while "
},
{
"path": "Palindromic String.py",
"chars": 68,
"preview": "n = input()\nif n== n[::-1]:\n print('YES')\nelse:\n print('NO')\n"
},
{
"path": "Passing the Parcel.py",
"chars": 846,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "Pepper and Contiguous Even Subarray.py",
"chars": 248,
"preview": "t= int(input())\nfor _ in range(t):\n n = int(input())\n l = list(map(int,input().split()))\n c=0\n x=[-1]\n fo"
},
{
"path": "Perfect Subarray.py",
"chars": 307,
"preview": "n = int(input())\nl = list(map(int,input().split()))\n\nimport math\ndef checkperfect(n):\n i = int(math.sqrt(n))\n if n"
},
{
"path": "Permute the Array.py",
"chars": 454,
"preview": "t = int(input())\nfrom collections import Counter\nfor _ in range(t):\n n,k = map(int,input().split())\n arr = list(ma"
},
{
"path": "Polygon Possibility",
"chars": 236,
"preview": "t= int(input())\nfor _ in range(t):\n n = int(input())\n l = list(map(int,input().split()))\n s = sum(l)\n for i "
},
{
"path": "Prasun the detective.py",
"chars": 217,
"preview": "p = input().lower()\nq = input().lower()\n\np =p.replace(\" \",\"\")\n\nq = q.replace(\" \",\"\")\n\nimport re\np = re.sub('[^a-z0-9]','"
},
{
"path": "Prime Number.py",
"chars": 319,
"preview": "# Write your code here\ndef prime(x):\n l = [True for i in range(x+1)]\n p=2\n while (p*p <= x):\n if l[p]==T"
},
{
"path": "Priority Interview.py",
"chars": 240,
"preview": "n = int(input())\n\nx_y = []\nfor i in range(n):\n a,b = map(int,input().split())\n x_y.append([a,b])\nx_y.sort(key = la"
},
{
"path": "README.md",
"chars": 66,
"preview": "# HackerEarth Solutions\nContains hackerearth solutions in python3\n"
},
{
"path": "Rain Sound.py",
"chars": 250,
"preview": "t = int(input())\nfor _ in range(t):\n l,r,s = map(int,input().split())\n if s > r:\n print(-1,-1)\n else:\n "
},
{
"path": "Rectangles to squares.py",
"chars": 131,
"preview": "# Write your code here\nimport math\nm,n = map(int,input().split())\nx = math.gcd(m,n)\nif x>1:\n print(\"Yes\")\nelse:\n p"
},
{
"path": "Reversed Linked List.py",
"chars": 1522,
"preview": "class node:\n def __init__(self,data):\n self.data = data\n self.next = None\n\nclass linkedList:\n \n d"
},
{
"path": "Robotic moves.py",
"chars": 190,
"preview": "# We only need to calculate for x axis since y axis part will be zero.\n#For any more query feel free to mail me.\n\nt = in"
},
{
"path": "Roy and Profile Picture.py",
"chars": 219,
"preview": "l = int(input())\nt = int(input())\nfor _ in range(t):\n m,n = map(int,input().split())\n if m < l or n<l:\n p"
},
{
"path": "Roy and Symmetric Logos.py",
"chars": 472,
"preview": "def symmetric(matrix,n):\n for i in range(n):\n for j in range(n):\n if int(matrix[i][0][j]) != int(ma"
},
{
"path": "Saul Goodman's Problem Statement.py",
"chars": 382,
"preview": "from collections import defaultdict \n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n ans=0\n d1=defaultd"
},
{
"path": "Save Mrinal.py",
"chars": 337,
"preview": "n = int(input())\nl = list(map(int,input().split()))\nm = int(input())\ni=0\ntemp = []\nwhile i!=m:\n qq=[int(x) for x in i"
},
{
"path": "Seating Arrangement.py",
"chars": 583,
"preview": "def find(a):\n ch = a%12\n if ch==1:\n print(a+11,'WS')\n elif ch==0:\n print(a-11,'WS')\n elif ch=="
},
{
"path": "Seven-Segment Display.py",
"chars": 628,
"preview": "# Write your code here\nd = {'0': 6,\n '1': 2,\n '2': 5,\n '3': 5,\n '4':4,\n '5':5,\n '6':6,\n '7':3,\n"
},
{
"path": "Simon cannot sleep.py",
"chars": 137,
"preview": "import math\nh,m = map(int,input().split(\":\"))\ntemp = h*60*60 + m*60\na = 0\nd = 3927.272727272727\n\nans = temp/d + 1\nprint("
},
{
"path": "Simple Search.py",
"chars": 121,
"preview": "n= int(input())\nl = list(map(int,input().split()))\nk = int(input())\nfor i in range(n):\n if l[i]==k:\n print(i)"
},
{
"path": "SnackDown Contest.py",
"chars": 276,
"preview": "t = int(input())\nfor _ in range(t):\n n = int(input())\n p = list(map(int,input().split()))\n q = list(map(int,inp"
},
{
"path": "Speed.py",
"chars": 261,
"preview": "testCase = int(input())\nfor _ in range(testCase):\n n = int(input())\n l = list(map(int,input().split()))\n c=1\n "
},
{
"path": "Split Houses.py",
"chars": 475,
"preview": "n = int(input())\ns = input()\nconsecutive_house = []\ntemp = 0\narr = ['']*n\nfor i,j in enumerate(s):\n if j == 'H':\n "
},
{
"path": "Stack and Queue <Nissan>.py",
"chars": 236,
"preview": "n , k = map(int,input().split())\nl = list(map(int,input().split()))\n\ns = 0\nfor i in range(k):\n s += l[i]\n \nm = s\n#"
},
{
"path": "Statistics.py",
"chars": 437,
"preview": "# Write your code here\nn = int(input())\narr = []\nfor i in range(n):\n l = input().split()\n arr.append(l)\n \nfrom "
},
{
"path": "Strange Game.py",
"chars": 289,
"preview": "testcase = int(input())\nfor _ in range(testcase):\n le,k = map(int,input().split())\n alice = list(map(int,input().s"
},
{
"path": "String.py",
"chars": 105,
"preview": "from collections import Counter\nn = int(input())\nst = input()\np = Counter(st)\nprint(n - max(p.values()))\n"
},
{
"path": "Sumita and equal array.py",
"chars": 424,
"preview": "t = int(input())\nfor _ in range(t):\n n,x,y,z = map(int,input().split())\n l = list(map(int,input().split()))\n fo"
},
{
"path": "Takeoff.py",
"chars": 309,
"preview": "t = int(input())\nfor i in range(t):\n n,p,q,r = map(int,input().split())\n c=0\n for i in range(1,n+1):\n if"
},
{
"path": "Terrible Chandu.py",
"chars": 71,
"preview": "n = int(input())\nfor i in range(n):\n a = input()\n print(a[::-1])\n"
},
{
"path": "The Amazing Race.py",
"chars": 2019,
"preview": "\n\n# Write your code here\n# To understand the question go to link : https://www.geeksforgeeks.org/largest-rectangle-under"
},
{
"path": "The Monk and Kundan.py",
"chars": 414,
"preview": "def index(ref,x):\n for i in range(len(ref)):\n if ref[i]==x:\n return i\n \nref = 'abcdefghi"
},
{
"path": "The best Internet Browser.py",
"chars": 330,
"preview": "from fractions import Fraction\nt = int(input())\nfor _ in range(t):\n s = input()\n n = len(s)\n c=0\n for j in r"
},
{
"path": "Thief and Warehouses.py",
"chars": 815,
"preview": "def solve (array, n):\n stack = []\n i=0\n max_a=0\n area = 0\n while i<len(array):\n if not stack or ("
},
{
"path": "Toggle String.py",
"chars": 32,
"preview": "n = input()\nprint(n.swapcase())\n"
},
{
"path": "Two Strings.py",
"chars": 247,
"preview": "from collections import Counter\ndef check(a,b):\n p = Counter(a)\n q = Counter(b)\n if sum((p-q).values())==0:\n "
},
{
"path": "VC pairs.py",
"chars": 364,
"preview": "test_cases = int(input())\nfor _ in range(test_cases):\n n = int(input())\n s = input()\n count = 0\n\n for i in r"
},
{
"path": "Vada Pav List.py",
"chars": 141,
"preview": "n = int(input())\nl = []\nfor i in range(n):\n x = input()\n l.append(x)\n\nl = list(set(l))\nl.sort()\nprint(len(l))\nfor "
},
{
"path": "Weighing the Stones.py",
"chars": 1135,
"preview": "from collections import Counter\ntestCase = int(input())\nfor _ in range(testCase):\n n = int(input())\n rupam = list("
},
{
"path": "Wet Clothes.py",
"chars": 250,
"preview": "n,m,g = input().split()\nt = list(map(int,input().split()))\na = list(map(int,input().split()))\ngap =[]\nfor i in range(len"
},
{
"path": "Word Queries.py",
"chars": 1568,
"preview": "'''\n# Sample code to perform I/O:\n\nname = input() # Reading input from STDIN\nprint('Hi, %s.' % name) "
},
{
"path": "balanced brackets.py",
"chars": 483,
"preview": "n = int(input())\nfor _ in range(n):\n s = list(input())\n op = [\"{\",\"[\",\"(\"]\n cl = [\"}\",\"]\",\")\"]\n \n st = [s"
},
{
"path": "e-maze-in.py",
"chars": 179,
"preview": "n = input()\nx,y = 0,0\nfor i in n:\n if i == 'L':\n x -= 1\n elif i == 'R':\n x += 1\n elif i == 'U':\n "
},
{
"path": "square sub matrix.py",
"chars": 701,
"preview": "t = int(input())\nfor _ in range(t):\n n,m = map(int,input().split())\n matrix = []\n for i in range(n):\n x "
},
{
"path": "super reduced strings.py",
"chars": 344,
"preview": "s = input()\nstack = [s[0]]\nfor i in range(1,len(s)):\n if stack:\n \n if stack[-1]== s[i]:\n #pr"
},
{
"path": "zoos.py",
"chars": 145,
"preview": "# Write your code here\ns = input()\n\nfrom collections import Counter\nd = Counter(s)\nif d['z']*2 == d['o']:\n print(\"Yes"
}
]
About this extraction
This page contains the full source code of the parasjain-12/HackerEarth-Solution GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 153 files (64.6 KB), approximately 22.9k tokens, and a symbol index with 38 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.