Note: click on newest button on top select old
CLOTHING STORE
from collections import Countern=int(input())
l1=map(int,input().split())
l2=dict(Counter(l1))
l3=l2.values()
sum=0
for i in l3:
sum+=i//2
print(sum)
DISPLAY UNIQUE VALUES IN ARRAY
a=int(input())b=list(map(int,input().split()))
c=set(b)
count=0
for i in c:
if i not in b[b.index(i)+1:]:
print(i,end=' ')
count+=1
if(count==0):
print(-1)
predict the winner
n=int(input())a=list(map(int,input().split()))
s=0
s1=0
for i in range(len(a)):
if(i%2==0):
s=s+a[i]
else:
s1=s1+a[i]
b=abs(s-s1)
if(b%4==0):
print('X')
else:
print('Y')
Rotation
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]))
sum of odd and even digits
n=int(input())se=0
so=0
a=list(map(int,input().split()))
for i in range(len(a)):
if(i%2==0):
se=se+a[i]
if(i%2!=0):
so=so+a[i]
if(se-so==0):
print('YES')
else:
print('NO')
Sorting Frequency
from collections import defaultdictdef sort(a,n):
s=defaultdict(lambda:0)
for i in range(n):
s[a[i]]+=1
a.sort(key=lambda x:(-s[x],x))
return a
n=int(input())
a=list(map(int,input().split()))
s=sort(a,n)
for i in sorted(set(s),key=s.index):
print(i,end=' ')
unique maximum nuber
n=int(input())a=list(map(int,input().split()))
b=[]
c=0
for i in range(len(a)):
if(a.count(a[i])==1):
b.append(a[i])
c+=1
if(c!=0):
print(max(b))
else:
print('-1')
Greattest Number of Cadies
n=int(input())a=list(map(int,input().split()))
b=max(a)
m=int(input())
c=[]
for i in range(len(a)):
a[i]=a[i]+m
if(a[i]>=b):
c.append(True)
else:
c.append(False)
print(*c)
How many Numbers are smaller Than the Current Number
n=int(input())c=0
a=list(map(int,input().split()))
for i in range(len(a)):
c=0
for j in range(len(a)):
if(i!=j):
if(a[i]>a[j]):
c+=1
print(c,end=' ')
Decompress_Run-Length_Encoded_List
n=int(input())a=list(map(int,input().split()))
l=[]
for i in range(0,n,2):
k=a[i+1]
for j in range(a[i]):
l.append(k)
for i in l:
print(i,end=' ')
Find_Numbers_with_Even_Number_of_Digits
n=int(input())c=0
cc=0
a=list(map(int,input().split()))
for i in range(len(a)):
c=0
while(a[i]):
d=a[i]%10
c+=1
a[i]=a[i]//10
if(c%2==0):
cc+=1
print(cc)
Create_Target_Array_in_the_Given_Order
n=int(input())a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
ans=[None]
for i in range(n):
ans.insert(b[i],a[i])
for i in range(n):
print(ans[i],end=' ')
Squares_of_a_Sorted_Array
n=int(input())a=list(map(int,input().split()))
for i in range(len(a)):
a[i]=a[i]**2
a.sort()
print(*a)
MAJORITY ELEMENT
import statisticsa=int(input())
b=[int(i) for i in input().split()]
print(statistics.mode(b))
Move Zeroes
n=int(input())c=0
a=list(map(int,input().split()))
for i in range(len(a)):
if(a[i]!=0):
print(a[i],end=' ')
c+=1
for j in range(c,n):
print('0',end=' ')
MAX CONSECUTIVE ONES
l=int(input())a=''.join(input().split())
max=0
for i in range(1,l+1):
if a.find('1'*i)!=-1:
max=i
print(max)
Make_Two_Arrays_Equal_by_Reversing_Sub-arrays
n=int(input())a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
if n==m:
for i in range(0,n):
if a[i] not in b:
print('False')
break
else:
print('True')
else:
print('True')
Replace_Elements_with_Greatest_Element_on_Right_Side
n=int(input())a=list(map(int,input().split()))
for i in range(n-1):
maxi=0
for j in range(i+1,n):
if(maxi<a[j]):
maxi=a[j]
print(maxi,end=' ')
print(-1)
Maximum_Sum_Circular_Subarray
n=int(input())a=list(map(int,input().split()))
maxx=-1000
for p in range(n):
f=a[0]
a[0]=a[n-1]
for k in range(1,n):
temp=a[k]
a[k]=f
f=temp
for i in range(n):
s=0
for j in range(i,n):
s+=a[j]
if maxx<s:
maxx=s
print(maxx)
Search_in_Rotated_Sorted_Array
m=int(input())n=list(map(int,input().split()))
a=int(input())
c=0
for i in range(len(n)):
if(n[i]==a):
b=i
c+=1
if(c==0):
print('-1')
else:
print(b)
FIND FIRST AND LAST POSITION OF ELEMENTS IN SORTED ARRAY
a=int(input())b=''.join(input().split())
t=input()
n1=b.find(t)
n2=b.rfind(t)
print(n1,n2)
Best_Time_to_Buy_and_Sell_Stock
n=int(input())a=list(map(int,input().split()))
x=0
for i in range(n):
for j in range(i,n):
if x<a[j]-a[i]:
x=a[j]-a[i]
print(x)
Find the Duplicate NUmber
from collections import Countera=int(input())
l=list(map(int,input().split()))
d=dict(Counter(l))
for i in d:
if d.get(i)!=1:
print(i)
Monk_and_Welcome_Problem
t=int(input())a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(t):
c.append(a[i]+b[i])
print(*c)
Maximum_Subarray
def maxsubarr(a,size):s=a[0]
cm=a[0]
for i in range(1,size):
cm=max(a[i],cm+a[i])
s=max(s,cm)
return s
n=int(input())
a=list(map(int,input().split()))
print(maxsubarr(a,n))
Product_of_Array_Except_Self
def prod(a,n):if n==1:
print('0')
return
i=1
temp=1
p=[1 for i in range(n)]
for i in range(n):
p[i]=temp
temp*=a[i]
temp=1
for i in range(n-1,-1,-1):
p[i]*=temp
temp*=a[i]
for i in range(n):
print(p[i],end=' ')
n=int(input())
a=list(map(int,input().split()))
prod(a,n)
Third Maximmum Number
n=int(input())a=list(map(int,input().split()))
b=set(a)
b=sorted(b)
if(len(b)>=3):
print(b[-3])
else:
print(max(b))
SnackDown_Contest
x=int(input())for o in range(x):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
for i in range(1,len(a)):
if(a[i] not in l):
l.append(a[i])
for i in range(1,len(b)):
if b[i] not in l:
l.append(b[i])
if len(l)+1>n:
print('YES')
else:
print('NO')
Help_Jarvis!
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')
Excel_Sheet_Column_Title
a=int(input())
p="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s=""
while a>0:
r=a%26
if r==0:
s+='Z'
a=(a//26)-1
else:
s+=p[r-1]
a//=26
for i in range(len(s)-1,-1,-1):
print(s[i],end="")
R-r-riddikulus!_once_again
n,d = map(int,input().split())a = list(map(int,input().split()))
print(*(a[d:]+a[:d]))
2 Arrays
n=int(input())a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
s=0
s1=0
for i in a:
if i==-1:
c+=1
else:
s+=i
for i in b:
if i==-1:
c+=1
else:
s1+=i
if c==2:
print('Infinite')
else:
c1=0
for i in range(9999):
if i+s==s1:
c1+=1
print(c1)
Subarray_with_given_sum
def subarr(n,m,a):for i in range(n):
s=a[i]
for j in range(i+1,n+1):
if s==m:
print("%d %d"%(i+1,j))
return 1
if s>m or j==n:
break
s=s+a[j]
print('-1')
return 0
x=int(input())
for i in range(x):
n,m=map(int,input().split())
a=list(map(int,input().split()))
subarr(n,m,a)
Sum of matrix Elements
m=int(input())n=int(input())
a=[list(map(int,input().split())) for i in range(m)]
sum=0
for i in range(0,m):
for j in range(0,n):
sum=sum+a[i][j]
print(sum)
Missing_number_in_array
def Missing(a):n=len(a)
total = (n + 1)*(n + 2)/2
sumofa= sum(a)
return total-sumofa
n=int(input())
for i in range(n):
x=int(input())
a=list(map(int,input().split()))
print(int(Missing(a)))
Maximum_element_in_each_column
n,m=map(int,input().split())l=[]
k=[]
s=[]
p=[]
x=[]
for i in range(n):
a=list(map(int,input().split()))
l.append(a[0])
k.append(a[1])
if m>2:
s.append(a[2])
if m>3:
p.append(a[3])
if m>4:
x.append(a[4])
print(max(l))
if m>=2:
print(max(k))
if m>=3:
print(max(s))
if m>=4:
print(max(p))
if m>=5:
print(max(x))
Merge_Without_Extra_Space
x=int(input())for i in range(x):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
for k in range(n):
l.append(a[k])
for j in range(m):
l.append(b[j])
print(*sorted(l))
Rearrange_Array_Alternately.
def rearrange(arr, n):temp = n*[None]
small, large = 0, n-1
flag = True
for i in range(n):
if flag is True:
temp[i] = arr[large]
large -= 1
else:
temp[i] = arr[small]
small += 1
flag = bool(1-flag)
for i in range(n):
arr[i] = temp[i]
print(*arr)
x=int(input())
l=[]
for i in range(x):
n=int(input())
a=list(map(int,input().split()))
rearrange(a,n)
A_Very_Big_Sum
n = int(input())arr = list(map(int, input().split()))
print(sum(arr))
Temperatures
n=int(input())a=list(map(int,input().split()))
for i in range(n):
c=0
for j in range(i+1,n):
c+=1
if a[i]<a[j]:
print(c,end=' ')
break
else:
print('0',end=' ')
Record_Breaker
x=int(input())l=0
for i in range(x):
l+=1
n=int(input())
c=0
a=list(map(int,input().split()))
for j in range(n):
ans1=ans2=-1
if j==0:
if a[j]>a[j+1]:
c+=1
else:
for k in range(j):
if a[k]>a[j]:
ans1=1
break
elif a[k]<a[j]:
ans1=0
if j==(n-1):
if ans1==0:
c+=1
else:
if a[j]>a[j+1]:
ans2=1
if ans1==0 and ans2==1:
c+=1
print('Case #',end='')
print(l,end='')
print(':',end=' ')
print(c)
Count
n=int(input())ec=0
oc=0
a=list(map(int,input().split()))
for i in range(len(a)):
if(a[i]%2==0):
ec+=1
if(a[i]%2!=0):
oc+=1
print(ec,oc,end=' ')
Program_to_find_the_sum_of_perfect_square_elements_in_an_array
import mathn=int(input())
sum=0
a=list(map(int,input().split()))
for i in range(len(a)):
s=int(math.sqrt(a[i]))
if(s*s==a[i]):
sum=sum+a[i]
print(sum)
Remove_duplicates_from_an_array
n=int(input())for i in range(0,n+1):
a=list(map(int,input().split()))
print(*(set(a)))
Calculate_sums_of_diagonals_of_a_matrix
n=int(input())s1,s2=0,0
j=n-1
for i in range(n):
a=list(map(int,input().split()))
s1+=a[i]
s2+=a[j]
j-=1
print("Principal Diagonal:%d"%s1)
print("Secondary Diagonal:%d"%s2)
Half list
n=int(input())a=list(map(int,input().split()))
s=len(a)
for i in range(s-1,(s//2)-1,-1):
print(a[i],end=' ')
for i in range(0,s//2):
print(a[i],end=' ')
Roman__Number
def printRoman(number):num = [1, 4, 5, 9, 10, 40, 50, 90,100, 400, 500, 900, 1000]
sym = ["I", "IV", "V", "IX", "X", "XL","L", "XC", "C", "CD", "D", "CM", "M"]
i = 12
while number:
div = number // num[i]
number %= num[i]
while div:
print(sym[i], end = "")
div -= 1
i -= 1
if __name__ == "__main__":
number =int(input())
printRoman(number)
Airport Authority
t=int(input())b=[]
s=0
for i in range(t):
a=int(input())
b.append(a)
n=int(input())
for i in range(len(b)):
if(b[i]<=n):
s=s+1
else:
s=s+2
print(s)
Factor_sum
a=list(map(int,input().split(',')))p=0
for i in set(a):
s=0
flag=0
for j in range(1,i+1):
if i%j==0:
s+=j
for k in a:
if s==k:
flag=1
if flag==1:
print(i,end=' ')
p=1
if p==0:
print(-1)
Subarray_Sum_Equals_K
n,m=map(int,input().split())a=list(map(int,input().split()))
c=s=0
for i in range(n):
for j in range(i,n):
s=s+a[j]
if s==m:
c+=1
if s>m:
break
s=0
print(c)
Distinct_subarray
a=int(input())b=int(input())
c=0
for i in range(a,b+1):
x=0
for j in range(i,b+1):
x+=j
if x%2!=0:
c+=1
print(c)
Sort_an_Array_of_0s_and_1s
def zero(arr, n) :count=0
for i in range(0, n) :
if (arr[i] == 0) :
count = count + 1
for i in range(0, count) :
arr[i] = 0
for i in range(count, n) :
arr[i] = 1
def printarr(arr , n) :
for i in range(0, n) :
print(arr[i],end =' ')
n=int(input())
arr=list(map(int,input().split()))
zero(arr, n)
printarr(arr, n)