├── A Big Sale.py ├── A good set.py ├── ATM cdvta.py ├── ATM.py ├── ATM_Machine.py ├── ATcdvta.py ├── A_Balanced_contest.py ├── Ada King.py ├── Ada School.py ├── Ada and the Staircase.py ├── Akhil_and_coloredBalls.py ├── Alternating subarray prefix.py ├── Appy and contest.py ├── Archi and Comparsion.py ├── Area or perimeter.py ├── Array got some moves.py ├── Art of balance.py ├── Average Number.py ├── Bear and Candies 123.py ├── Bear_and_segment01.py ├── Bob and his strict mom.py ├── Brackets.py ├── Buggy calculator.py ├── Buying new tablet.py ├── Camp Or Not.py ├── Candy Love.py ├── Cats and Dogs.py ├── Chef And Coloring.py ├── Chef And His Characters.py ├── Chef And his Cake.py ├── Chef Judges a Competition.py ├── Chef and An Ideal Problem.py ├── Chef and Balls.py ├── Chef and Bored Games.py ├── Chef and Cook-Off Contests.py ├── Chef and Difficult Contests.py ├── Chef and Dolls.py ├── Chef and Eid.py ├── Chef and Friends.py ├── Chef and Fruits.py ├── Chef and Game with Sequence.py ├── Chef and Glove.py ├── Chef and His Apartment Dues.py ├── Chef and Inequality.py ├── Chef and Interactive Contests.py ├── Chef and Number Game.py ├── Chef and Polygon Cakes.py ├── Chef and Secret Ingredient.py ├── Chef and Sequence.py ├── Chef and Serves.py ├── Chef and SnackDown.py ├── Chef and String.py ├── Chef and Subarrays.py ├── Chef and Two Strings.py ├── Chef and Way.py ├── Chef and a Beautiful Digit.py ├── Chef and digits of a number.py ├── Chef and his Sequence.py ├── Chef and the Wildcard Matching.py ├── Chef got Recipes.py ├── Chef_Detective.py ├── Chef_and_his_dailyRoutine.py ├── Coder Life Matters.py ├── Coins And Triangle.py ├── Coinscdvta.py ├── Collisions.py ├── Cops and the Thief Devu.py ├── Count Subarrays.py ├── Coupon System.py ├── Cut the Board.py ├── D - Triangle Count.py ├── DEvu and an array.py ├── Dada Ques.py ├── Days in Month.py ├── Deputy Chef.py ├── Devu and Grapes.py ├── Devu and friendship testing.py ├── Digit Longest Increasing Subsequences 2.py ├── Download file.py ├── Encoding Message.py ├── Entrance Exam.py ├── Extreme Encoding.py ├── Farmer And His Plot.py ├── Fencing.py ├── Fibonacci String.py ├── Fit Squares in Triangle.py ├── Football Match.py ├── Forgotten Language.py ├── Friend or Girlfriend.py ├── GCD and LCM.py ├── Game of chef.py ├── Good Joke!.py ├── Good and Bad Persons.py ├── Grade The Steel.py ├── Greedy puppy.py ├── Gross Salary.py ├── Help Lost Robot!.py ├── IPL and RCB.py ├── Id and Ship.py ├── Is it a Cakewalk Problem.py ├── Is it a VOWEL or CONSONANT.py ├── Itercdvta.py ├── J - Reached Safely Or Not.py ├── Judging Delay.py ├── Jumping in the hills.py ├── K Fibonnaci.py ├── Kitchen Timetable.py ├── Lazy Jem.py ├── Life Limited.py ├── Lucky number game.py ├── Magic Set.py ├── Magician versus Chef.py ├── Mahasena.py ├── Malvika is peculiar about color of balloons.py ├── Maximise the Sum.py ├── Maximum Remaining.py ├── Minimum Deletions.py ├── Minimum Maximum.py ├── Movie Weekend.py ├── Naive Chef.py ├── NightsWatch.py ├── Ordering teams.py ├── PERMUTATION_OF_STRING.py ├── Palindromic substrings.py ├── Play Piano.py ├── Pogo Stick Competition.py ├── Print Pattern.py ├── Program Your Own CALCULATOR.py ├── Puppy and Sum.py ├── Quentin Tarantino.py ├── README.md ├── Random Pair.py ├── Rectangle.py ├── Rooks.py ├── Roots of a Quadratic Equation.py ├── Rupsa and the Game.py ├── Sebi and the highway.py ├── Secret Recipe.py ├── Simple Statistics.py ├── Smart Strategy.py ├── Split Stones.py ├── Sticks.py ├── Strange Operations.py ├── Strike or Spare.py ├── Studying Alphabet.py ├── Subsequence Equality.py ├── Subtree Removal.py ├── Sum OR Difference.py ├── Sums in a Triangle.py ├── Survive in ChocoLand.py ├── Tanu and Head-bob.py ├── Task for Alexey.py ├── Temple Land.py ├── Testing Robot.py ├── The Deadly Sin.py ├── The Great Run.py ├── The Smallest Pair.py ├── The Tricky Deal.py ├── Three Friends.py ├── Tickets.py ├── Total Expenses.py ├── Trace of Matrix.py ├── Train Partner.py ├── Turbo Sort.py ├── Tweedle-Dee and Tweedle-Dum.py ├── Two Numbers.py ├── Two vs Ten.py ├── Uniform Strings.py ├── Valid Stack Operations.py ├── Version Control System.py ├── Villages and Tribes.py ├── Whats in the name.py ├── Workers.py ├── XOR N-bonacci Sequence.py ├── Xor Again.py ├── Yet Again a Subarray Problem.py ├── ada_and_crayons.py ├── andrash and stipendiium.py ├── art of balance2.py ├── art of balance3.py ├── bear and ladder.py ├── bear_and_milky_cookies.py ├── cdvta_prac.py ├── chang_bitwiseOR.py ├── chef and chocolate.py ├── chef and cookoff.py ├── chef and his students.py ├── chef and majical jars.py ├── chef and party.py ├── chef and secret ingredients.py ├── chef and secret password.py ├── chef and table tennis.py ├── chef_and_employement test.py ├── chef_and_icecream.py ├── chef_and_movie.py ├── chef_and_text.py ├── common.py ├── decrement or invcrement.py ├── find the maximum value.py ├── from heaven to earth.py ├── gregorian calender.py ├── how many digits do i have.py ├── importantINPUT_TEST.py ├── little chef and sums.py ├── loop_test.py ├── mantison_and _pangrams.py ├── name1.png ├── nothing in common.py ├── oDD EVEN FIBO PRIME.py ├── one more wierd game.py ├── palindrom.py ├── palindroms _in_subsequence.py ├── piece_of_cake.py ├── plotlibfig.py ├── pr.py ├── practise1.py ├── practise2.py ├── practise3.py ├── scratch.py ├── scratch_1.py ├── similar dishes.py ├── sincosmatplotlib.py ├── snake procession.py ├── snake_mongoose_hijibiji.py ├── subsequence.py ├── tests_for_subsequence.py ├── who dares to be a millionare.py └── xenny_and_alternating_tasks.py /A Big Sale.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | loss=0 4 | for i in range(n): 5 | p,q,d=map(int,input().split()) 6 | sp=p+(p*d)/100 7 | sp-=(sp*d)/100 8 | if sp=0: 7 | y-=(0.5+x) 8 | y="{0:.2f}".format(y) 9 | print(y) 10 | -------------------------------------------------------------------------------- /ATM_Machine.py: -------------------------------------------------------------------------------- 1 | for j in range(int(input())): 2 | n, k = [int(x) for x in input().split()] 3 | a = [int(x) for x in input().split()] 4 | 5 | for i in range(n): 6 | if a[i] <= k: 7 | k-= a[i] 8 | a[i]= 1 9 | else: 10 | a[i]= 0 11 | for i in range(n): 12 | print(a[i], end="") 13 | print() 14 | 15 | 16 | -------------------------------------------------------------------------------- /ATcdvta.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | w=int(input()) 3 | h=int(input()) 4 | th=int(input()) 5 | fh=int(input()) 6 | thsnd=int(input()) 7 | 8 | fin,ini=0,0 9 | 10 | nthsnd = int(w/1000) 11 | nfh = int((w-nthsnd*1000)/500) 12 | nth = int((w-nthsnd*1000-nfh*500)/200) 13 | nh = int((w-nthsnd*1000-nfh*500-nth*200)/100) 14 | 'print(nthsnd+nfh+nth+nh,nthsnd,nfh,nth,nh)' 15 | 'i=0' 16 | if w>(h*100+th*200+fh*500+thsnd*1000): 17 | print(0) 18 | elif n<(nthsnd+nfh+nth+nh) or h0 and (nthsnd-1)+nfh+nth+(nh+10)<=n: 28 | nthsnd=nthsnd-1 29 | nh=nh+10 30 | while 5+nh<=h and nfh>0 and nthsnd+(nfh-1)+nth+(5+nh)<=n: 31 | nfh=nfh-1 32 | nh=nh+5 33 | while 2+nh<=h and nth>0 and nthsnd+nfh+nth-1+nh+2<=n: 34 | nth=nth-1 35 | nh=nh+2 36 | 'print("i=" + str(i), nthsnd, nfh, nth, nh)' 37 | 38 | while 5+nth<=th and nthsnd>0 and nthsnd-1+nfh+nth+5+nh<=n: 39 | nthsnd=nthsnd-1 40 | nth=nth+5 41 | while 2+nth<=th and 1+nh<=h and nfh>0 and nthsnd+nfh-1+nth+2+nh+1<=n: 42 | nfh=nfh-1 43 | nh=nh+1 44 | nth=nth+2 45 | 'print("i=" + str(i), nthsnd, nfh, nth, nh)' 46 | 47 | while 2+nfh<=fh and nthsnd>0 and nthsnd-1+nfh+2+nth+nh<=n: 48 | nthsnd=nthsnd-1 49 | nfh=nfh+2 50 | 51 | 'print("i="+str(i),nthsnd,nfh,nth,nh)' 52 | fin = nthsnd+nfh+nth+nh 53 | if fin==ini: 54 | break 55 | 56 | 57 | if fin<=n: 58 | print(fin) 59 | else: 60 | print(0) 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /A_Balanced_contest.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | p2=p10=0 3 | n,p=[int(x) for x in input().split()] 4 | a=[int(x) for x in input().split()] 5 | for i in a: 6 | if i>=(p//2): 7 | p2+=1 8 | elif i<=(p//10): 9 | p10+=1 10 | if p2==1 and p10==2: 11 | print("yes") 12 | else: 13 | print("no") 14 | #what the **** -------------------------------------------------------------------------------- /Ada King.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | r,c,k=map(int,input().split()) 3 | s=0 4 | 5 | one=k 6 | r1=r 7 | r1 -= 1 8 | while one>0 and r1>0: 9 | r1-=1 10 | if ((r1-r)**2)+((c-c)**2) <= 2: 11 | s+=1 12 | else: 13 | break 14 | one-=1 15 | 16 | print("s one: "+str(s)) 17 | s2=0 18 | 19 | two = k 20 | r1 = r 21 | r1 += 1 22 | while two > 0 and r1 < 9: 23 | r1 += 1 24 | if ((r1 - r) ** 2) + ((c - c) ** 2) <= 2: 25 | s += 1 26 | s2+=1 27 | else: 28 | break 29 | two-=1 30 | 31 | print("s two: " + str(s2)) 32 | s3=0 33 | 34 | three = k 35 | c1 = c 36 | c1 -= 1 37 | while three > 0 and c1 > 0: 38 | c1 -= 1 39 | if ((r - r) ** 2) + ((c1 - c) ** 2) <= 2: 40 | s += 1 41 | s3+=1 42 | else: 43 | break 44 | three-=1 45 | 46 | print("s three: " + str(s3)) 47 | s4=0 48 | 49 | four = k 50 | c1 = c 51 | c1 += 1 52 | while four > 0 and c1 < 9: 53 | c1 += 1 54 | if ((r - r) ** 2) + ((c1 - c) ** 2) <= 2: 55 | s += 1 56 | s4+=1 57 | else: 58 | break 59 | four-=1 60 | 61 | print("s four: " + str(s4)) 62 | s5=0 63 | 64 | five = k 65 | r1 = r 66 | c1=c 67 | r1 -= 1 68 | c1 -= 1 69 | while five > 0 and r1 > 0 and c1 >0: 70 | r1 -= 1 71 | c1-=1 72 | if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2: 73 | s += 1 74 | s5+=1 75 | else: 76 | break 77 | five-=1 78 | 79 | print("s five: " + str(s5)) 80 | s6=0 81 | 82 | six = k 83 | r1 = r 84 | c1=c 85 | r1 += 1 86 | c1 += 1 87 | while six > 0 and r1 < 9 and c1 < 9: 88 | r1 += 1 89 | c1+=1 90 | if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2: 91 | s += 1 92 | s6+=1 93 | else: 94 | break 95 | six-=1 96 | 97 | print("s six: " + str(s6)) 98 | s7=0 99 | 100 | seven = k 101 | r1 = r 102 | c1=c 103 | r1 -= 1 104 | c1 += 1 105 | while seven > 0 and r1 > 0 and c1 < 9: 106 | r1 -= 1 107 | c1+=1 108 | if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2: 109 | s += 1 110 | s7+=1 111 | else: 112 | break 113 | seven-=1 114 | 115 | print("s seven: " + str(s7)) 116 | s8=0 117 | 118 | eight = k 119 | r1 = r 120 | c1=c 121 | r1 += 1 122 | c1 -= 1 123 | while eight > 0 and r1 < 9 and c1 > 0: 124 | r1 += 1 125 | c1-=1 126 | if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2: 127 | s += 1 128 | s8+=1 129 | else: 130 | break 131 | eight-=1 132 | 133 | print("s eight: " + str(s8)) 134 | 135 | s+=1 136 | print(s) -------------------------------------------------------------------------------- /Ada School.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m=map(int,input().split()) 3 | if n==1 or m==1 or (m*n)%2!=0: 4 | print("NO") 5 | else: 6 | print("YES") -------------------------------------------------------------------------------- /Ada and the Staircase.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | h=[int(x) for x in input().split()] 4 | hf,c=0,0 5 | for i in h: 6 | if i-hf>k: 7 | c+=(i-hf-1)//k 8 | hf=i 9 | print(c) -------------------------------------------------------------------------------- /Akhil_and_coloredBalls.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | X=input().upper() 3 | Y=input().upper() 4 | Z="" 5 | for i in range(len(X)): 6 | if X[i]=='B' and Y[i]=='B': 7 | Z+='W' 8 | else: 9 | Z+='B' 10 | print(Z) -------------------------------------------------------------------------------- /Alternating subarray prefix.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[0 if int(x)<0 else 1 for x in input().split()] 4 | i,j,k=0,0,0 5 | while i <=(n-1): 6 | s=0 7 | j=i 8 | while j<=(n-1): 9 | if j=k: 9 | print("Win") 10 | else: 11 | print("Lose") 12 | -------------------------------------------------------------------------------- /Archi and Comparsion.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b,n=map(int,input().split()) 3 | if n%2==0: 4 | if abs(a)==abs(b): 5 | print(0) 6 | elif abs(a)>abs(b): 7 | print(1) 8 | else: 9 | print(2) 10 | else: 11 | if a==b: 12 | print(0) 13 | elif a>b: 14 | print(1) 15 | else: 16 | print(2) -------------------------------------------------------------------------------- /Area or perimeter.py: -------------------------------------------------------------------------------- 1 | '''l=float(input()) 2 | b=float(input()) 3 | p=2*(l+b) 4 | a=l*b 5 | if a>p: 6 | print("Area") 7 | print(int(a)) 8 | elif ab)+"Peri"*(b>a)+"Eq"*(b==a),a+(b>a)*(b-a),sep='\n') -------------------------------------------------------------------------------- /Array got some moves.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | s=(k*(k+1))/2 4 | s+=(n-k)*1 5 | print(int(s)) 6 | 7 | -------------------------------------------------------------------------------- /Art of balance.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | for _ in range(int(input())): 3 | st=input().upper() 4 | lst=len(st) 5 | s=set(st) 6 | c=[] 7 | min_avg=999999 8 | min_i=0 9 | min_c=0 10 | for i in s: 11 | c.append(st.count(i)) 12 | c.sort() 13 | c.reverse() 14 | l=len(c) 15 | #print(c) 16 | i=1 17 | f=[] 18 | #print(f) 19 | while i<=26 and i<=l: 20 | if lst%i==0: 21 | f.append(i) 22 | i+=1 23 | #print(f) 24 | for i in f: 25 | #print("for i="+str(i)) 26 | comp=lst//i 27 | #print("comp="+str(comp)) 28 | diff=0 29 | avg=0 30 | for j in range(i): 31 | #print("for j="+str(j),end=" ") 32 | diff+=abs(comp-c[j]) 33 | avg+=diff 34 | #print(diff) 35 | #avg=diff/i 36 | #print(avg) 37 | if avg b: 12 | print("Limak") -------------------------------------------------------------------------------- /Bear_and_segment01.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input().strip('0') 3 | if '1' in s: 4 | if '0' in s[s.index('1'):]: 5 | print("NO") 6 | else: 7 | print("YES") 8 | else: 9 | print("NO") 10 | 11 | -------------------------------------------------------------------------------- /Bob and his strict mom.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=list(input()) 4 | c=0 5 | nz,no=0,0 6 | 7 | for i in range(n): 8 | if s[i]=='0': 9 | nz+=1 10 | else: 11 | no+=1 12 | if nz>no: 13 | no+=1 14 | nz-=1 15 | c+=1 16 | print(c) 17 | -------------------------------------------------------------------------------- /Brackets.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a=input() 3 | balance = 0 4 | max_balance = 0 5 | for i in range(len(a)): 6 | if a[i] == '(' :balance+=1 7 | if a[i] == ')' :balance-=1 8 | max_balance = max(max_balance, balance) 9 | for i in range(max_balance): 10 | print("(",end='') 11 | for i in range(max_balance): 12 | print(")",end='') 13 | print() -------------------------------------------------------------------------------- /Buggy calculator.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b=map(int,input().split()) 3 | s1=0 4 | s=1 5 | while a>0 or b>0: 6 | q=a%10 7 | w=b%10 8 | s1=s1+(s*((q+w)%10)) 9 | s=s*10 10 | a=a//10 11 | b=b//10 12 | print(s1) 13 | 14 | -------------------------------------------------------------------------------- /Buying new tablet.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,b=map(int,input().split()) 3 | maxy=-1 4 | for i in range(n): 5 | w,h,p=map(int,input().split()) 6 | if p<=b: 7 | a=w*h 8 | if a>maxy: 9 | maxy=a 10 | if maxy==-1: 11 | print("no tablet") 12 | else: 13 | print(maxy) -------------------------------------------------------------------------------- /Camp Or Not.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | da=int(input()) 3 | d=[0]*40 4 | for i in range(da): 5 | x,z=map(int,input().split()) 6 | d[x]=z 7 | 8 | q=int(input()) 9 | for i in range(q): 10 | x, z = map(int, input().split()) 11 | if sum(d[0:x+1])>=z: 12 | print("Go Camp") 13 | else: 14 | print("Go Sleep") -------------------------------------------------------------------------------- /Candy Love.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=list(map(int,input().split())) 4 | s=sum(a) 5 | if s%2==0: 6 | print("NO") 7 | else: 8 | print("YES") -------------------------------------------------------------------------------- /Cats and Dogs.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | c,d,l=map(int,input().split()) 3 | if l%4==0 : 4 | ma=c*4+d*4 5 | if d*2>=c: 6 | mi=d*4 7 | else: 8 | mi=(c-(d*2))*4+d*4 9 | if l in range(mi,ma+1): 10 | print("yes") 11 | continue 12 | print("no") -------------------------------------------------------------------------------- /Chef And Coloring.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=input().upper() 4 | r = s.count('R') 5 | g = s.count('G') 6 | b = s.count('B') 7 | print(n-max(r,g,b)) -------------------------------------------------------------------------------- /Chef And His Characters.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | for i in s: 4 | if not i.isalpha(): 5 | s=s.replace(i,'',1) 6 | s.lower() 7 | cll=['chef', 'chfe', 'cehf', 'cefh', 'cfeh', 'cfhe', 'hcef', 'hcfe', 'hecf', 'hefc', 'hfec', 'hfce', 'ehcf', 'ehfc', 'echf', 'ecfh', 'efch', 'efhc', 'fhec', 'fhce', 'fehc', 'fech', 'fceh', 'fche'] 8 | c=0 9 | for i in range(len(s)-3): 10 | if s[i:i+4] in cll: 11 | c+=1 12 | if c: 13 | print("lovely",c) 14 | else: 15 | print("normal") -------------------------------------------------------------------------------- /Chef And his Cake.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m=map(int,input().split()) 3 | red,green=0,0 4 | for i in range(n): 5 | s=input() 6 | if i%2==0: 7 | for l in range(m): 8 | if l%2==0 and s[l]=='R': 9 | green+=5 10 | elif l%2!=0 and s[l]=='G': 11 | green+=3 12 | 13 | if l%2==0 and s[l]=='G': 14 | red+=3 15 | elif l%2!=0 and s[l]=='R': 16 | red+=5 17 | elif i%2!=0: 18 | for l in range(m): 19 | if l%2==0 and s[l]=='G': 20 | green+=3 21 | elif l%2!=0 and s[l]=='R': 22 | green+=5 23 | 24 | if l%2==0 and s[l]=='R': 25 | red+=5 26 | elif l%2!=0 and s[l]=='G': 27 | red+=3 28 | 29 | if red2: 5 | for i in a: 6 | #print(a," i:"+str(i)) 7 | temp=a.copy() 8 | temp.remove(i) 9 | for j in temp: 10 | 11 | if (i+j)%2==0: 12 | #print(i,j,i+j) 13 | a.append(i+j) 14 | a.remove(i) 15 | a.remove(j) 16 | break 17 | #print("a:"+str(a)) 18 | if len(a)==2 and (a[0]+a[1])%2!=0: 19 | print(2) 20 | else: 21 | print(1) -------------------------------------------------------------------------------- /Chef and Glove.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | l=list(map(int,input().split())) 4 | g=list(map(int,input().split())) 5 | front,back=True,True 6 | for i in range(n): 7 | if l[i]>g[i]: 8 | front=False 9 | break 10 | g.reverse() 11 | for i in range(n): 12 | if l[i]>g[i]: 13 | back=False 14 | break 15 | if front and back: 16 | print("both") 17 | elif front: 18 | print("front") 19 | elif back: 20 | print("back") 21 | else: 22 | print("none") -------------------------------------------------------------------------------- /Chef and His Apartment Dues.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | if 0 in a: 5 | print(1000*(a.count(0))+100*(n-a.index(0))) 6 | else: 7 | print(0) -------------------------------------------------------------------------------- /Chef and Inequality.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b,c,d=map(int,input().split()) 3 | count=0 4 | if b0 else 0 for x in input().split()] 4 | #print(*a) 5 | pos,neg=a.count(1),a.count(0) 6 | if pos==0: 7 | print(neg,neg) 8 | elif neg==0: 9 | print(pos,pos) 10 | elif pos>neg: 11 | print(pos,neg) 12 | else: 13 | print(neg,pos) 14 | -------------------------------------------------------------------------------- /Chef and Polygon Cakes.py: -------------------------------------------------------------------------------- 1 | import math 2 | for _ in range(int(input())): 3 | n,a,k=map(int,input().split()) 4 | num=(360*(n-2))-((2*a)*n) 5 | d=(n*(n-1)) 6 | num=a*d+(k-1)*num 7 | print(int(num/math.gcd(num,d)),int(d/math.gcd(num,d))) 8 | -------------------------------------------------------------------------------- /Chef and Secret Ingredient.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,x=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | if any(i>=x for i in a ): 5 | print("YES") 6 | else: 7 | print("NO") -------------------------------------------------------------------------------- /Chef and Sequence.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | c=0 5 | for i in a: 6 | if i>1: 7 | c+=1 8 | if c<=k: 9 | print("YES") 10 | else: 11 | print("NO") -------------------------------------------------------------------------------- /Chef and Serves.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | p1,p2,k=map(int,input().split()) 3 | if ((p1+p2)//k)%2==0: 4 | print("CHEF") 5 | else: 6 | print("COOK") -------------------------------------------------------------------------------- /Chef and SnackDown.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | d=[2010,2015,2016,2017,2019] 4 | if n in d: 5 | print("HOSTED") 6 | else: 7 | print("NOT HOSTED") -------------------------------------------------------------------------------- /Chef and String.py: -------------------------------------------------------------------------------- 1 | """s=input().upper() 2 | cont=0 3 | if 'C' in s: 4 | c=s.index('C') 5 | while c0: 34 | if c>h:h+=1 35 | if i=='e' and h>0: 36 | if h>e:e+=1 37 | if i=='f' and e>0: 38 | if e>f:f+=1 39 | print(min(c,h,e,f)) -------------------------------------------------------------------------------- /Chef and Subarrays.py: -------------------------------------------------------------------------------- 1 | import numpy as PKMKB 2 | for _ in range(int(input())): 3 | n=int(input()) 4 | c=0 5 | a=[int(x) for x in input().split()] 6 | for i in range(n): 7 | for j in range(i+1,n+1): 8 | if sum(a[i:j])==PKMKB.prod(a[i:j]): 9 | #print(a[i:j]) 10 | c+=1 11 | print(c) 12 | -------------------------------------------------------------------------------- /Chef and Two Strings.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s1,s2=input(),input() 3 | mind,minx=0,0 4 | for i in range(len(s1)): 5 | if s1[i]!='?' and s2[i]!='?': 6 | if s1[i]!=s2[i]: 7 | mind+=1 8 | for i in range(len(s1)): 9 | if s1[i]=='?' or s2[i]=='?': 10 | minx+=1 11 | print(mind,minx+mind) -------------------------------------------------------------------------------- /Chef and Way.py: -------------------------------------------------------------------------------- 1 | n,k=map(int,input().split()) 2 | a=[int(c) for c in input().split()] 3 | p,mul,visited,ans=[],[],[],[] 4 | mod=1000000007 5 | for _ in range(n-1): 6 | p.append([]) 7 | mul.append([]) 8 | 9 | for i in range(1,n): 10 | if a[i]-a[0]<=k: 11 | p[0].append(i) 12 | mul[0].append(a[0]*a[i]) 13 | else: 14 | break 15 | #print(p) 16 | #print(mul) 17 | 18 | for i in range(n-1): 19 | j=0 20 | #print("p[i] " + str(p[i])) 21 | while jd: 10 | n=operation(n,len(n)-1,d) 11 | while i>0: 12 | if n[i]d: 15 | n = operation(n,i,d) 16 | else: 17 | i-=1 18 | print(n) -------------------------------------------------------------------------------- /Chef and digits of a number.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=input() 3 | if n.count('1')==1 or n.count('0')==1: 4 | print("Yes") 5 | else: 6 | print("No") -------------------------------------------------------------------------------- /Chef and his Sequence.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=set([int(x) for x in input().split()]) 4 | m=int(input()) 5 | f=set([int(x) for x in input().split()]) 6 | print("Yes" if len(s.intersection(f))==len(f) else "No") -------------------------------------------------------------------------------- /Chef and the Wildcard Matching.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | x,y=input(),input() 3 | flag=1 4 | for i in range(len(x)): 5 | if x[i]!='?' and y[i]!='?': 6 | if x[i]!=y[i]: 7 | print("No") 8 | flag=0 9 | break 10 | if flag: 11 | print("Yes") 12 | 13 | -------------------------------------------------------------------------------- /Chef got Recipes.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 4 | #subc=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 5 | cou=0 6 | vow={'a','e','i','o','u'} 7 | l=[{'a'}, {'a', 'e'}, {'i', 'a', 'e'}, {'i', 'a', 'e', 'o'}, {'i', 'a', 'e', 'u'}, {'a', 'e', 'o'}, 8 | {'a', 'e', 'o', 'u'}, {'a', 'e', 'u'}, {'i', 'a'}, {'i', 'a', 'o'}, {'i', 'a', 'o', 'u'}, {'i', 'a', 'u'}, 9 | {'a', 'o'}, {'a', 'o', 'u'}, {'a', 'u'}, {'e'}, {'i', 'e'}, {'i', 'e', 'o'}, {'i', 'e', 'o', 'u'}, {'i', 'e', 'u'}, 10 | {'e', 'o'}, {'e', 'o', 'u'}, {'e', 'u'}, {'i'}, {'i', 'o'}, {'i', 'o', 'u'}, {'i', 'u'}, {'o'}, {'o', 'u'}, {'u'}, 11 | {'i', 'o', 'e', 'u', 'a'},{}] 12 | for i in range(n): 13 | s=set(input()) 14 | #print(s,vow-s) 15 | c[l.index(s)]+=1 16 | #print(c) 17 | 18 | """for i in range(len(l)-1): 19 | for j in range(len(l)): 20 | if l[j]!=l[i] and l[i].issubset(l[j]): 21 | subc[l.index(l[i])]+=c[l.index(l[j])]""" 22 | 23 | for i in range(len(l)): 24 | if c[i]!=0: 25 | if l[i]==vow: 26 | cou+=((n*c[i])-((c[i]*(c[i]+1))//2)) 27 | else: 28 | #print("for " + str(l[i])) 29 | cou+=(c[l.index(vow-l[i])]*c[i]) 30 | #print("core:"+str(c[l.index(vow-l[i])]*c[i])) 31 | for j in range(len(l)-2): 32 | if (vow-l[i]).issubset(l[j]) and (vow-l[i])!=l[j]: 33 | cou+=(c[l.index(l[j])]*c[i]) 34 | #print("subset wala:" + str(c[l.index(l[j])]*c[i])) 35 | #print(str(cou)) 36 | c[i]=0 37 | #print(c) 38 | 39 | print(cou) -------------------------------------------------------------------------------- /Chef_Detective.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | r=[int(x) for x in input().split()] 3 | r=set(r) 4 | for i in range(n): 5 | if (i+1) not in r: 6 | print(i+1,end=" ") -------------------------------------------------------------------------------- /Chef_and_his_dailyRoutine.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | st=input().upper() 3 | strin=sorted(st) 4 | print(strin) 5 | c=e=s=1 6 | tot=0 7 | for i in st: 8 | if i=='C' and c==1: 9 | tot+=c 10 | if i=='E' and e==1: 11 | c=0 12 | tot+=e 13 | if i=='S' and s==1: 14 | e=0 15 | c=0 16 | tot+=s 17 | if tot==len(st): 18 | print("yes") 19 | else: 20 | print("no") -------------------------------------------------------------------------------- /Coder Life Matters.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a=[int(x) for x in input().split()] 3 | c,flag=0,1 4 | for i in a: 5 | if i==1: 6 | c+=1 7 | if c>5: 8 | flag=0 9 | break 10 | else: 11 | c=0 12 | if flag: 13 | print("#allcodersarefun") 14 | else:print("#coderlifematters") -------------------------------------------------------------------------------- /Coins And Triangle.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | c=0 4 | for i in range(1,n+1): 5 | if (i*(i+1))//2<=n: 6 | c=i 7 | else: 8 | break 9 | print(c) -------------------------------------------------------------------------------- /Coinscdvta.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | dict={5:0,2:0,1:0} 3 | x=1 4 | r,t=0,0 5 | while x<=n: 6 | r=5 * dict[5] + 2 * dict[2] + 1 * dict[1] 7 | if r>=x: 8 | x+=1 9 | continue 10 | else: 11 | d=[] 12 | for i in [1,2,5]: 13 | if i<=x: 14 | d.append(i) 15 | mr=0 16 | for i in d: 17 | if (i+r)>mr and i+r<=n: 18 | mr= i+r 19 | t=i 20 | dict[t]+=1 21 | x+=1 22 | print(sum(dict.values()),dict[5],dict[2],dict[1]) -------------------------------------------------------------------------------- /Collisions.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | for _ in range(int(input())): 3 | n,m=[int(x) for x in input().split()] 4 | a=[] 5 | c=0 6 | for _ in range(n): 7 | a.append([int(i) for i in input()]) 8 | for i in range(m): 9 | for j in range(n): 10 | if a[j][i]==1: 11 | for k in range(j+1,n): 12 | if a[k][i]==1: 13 | c+=1 14 | print(c) 15 | 16 | -------------------------------------------------------------------------------- /Cops and the Thief Devu.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | m,x,y=map(int,input().split()) 3 | t=x*y 4 | a=[int(x) for x in input().split()] 5 | a.sort() 6 | strt,s=1,0 7 | for i in range(m): 8 | if a[i]>strt: 9 | r=a[i]-strt 10 | if r>=t: 11 | s+=r-t 12 | strt=a[i]+t+1 13 | if strt>100: 14 | break 15 | if strt<=100: 16 | s+=100-strt+1 17 | print(s) 18 | -------------------------------------------------------------------------------- /Count Subarrays.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | a.append(-1) 5 | s=0 6 | i,j,c=0,1,0 7 | while jdi1: 10 | di1=x 11 | ci1=c 12 | elif x==di1: 13 | if cdi2: 17 | di2=x 18 | ci2=c 19 | elif x==di2: 20 | if cdi3: 24 | di3=x 25 | ci3=c 26 | elif x==di3: 27 | if cl: 5 | print("Case "+str(z+1)+": 0") 6 | elif k==l: 7 | print("Case "+str(z+1)+": 1") 8 | else: 9 | if l<=4: 10 | n=1 11 | else: 12 | n=(l-4)+1 13 | for i in range(n+1,0,-1): 14 | if i-k>0: 15 | s+=i-k 16 | else: 17 | break 18 | #print(s) 19 | 20 | print("Case "+str(z+1)+": "+str(s+3)) 21 | 22 | 23 | """for z in range(int(input())): 24 | l,k=map(int,input().split()) 25 | s=0 26 | for i in range(l+1,0,-1): 27 | if i-k>0: 28 | s+=i-k 29 | else: 30 | break 31 | print("Case "+str(z+1)+": "+str(s)) 32 | """ 33 | 34 | -------------------------------------------------------------------------------- /DEvu and an array.py: -------------------------------------------------------------------------------- 1 | n,q=[int(x) for x in input().split()] 2 | a=sorted([int(x) for x in input().split()]) 3 | for _ in range(q): 4 | qu=int(input()) 5 | if qu in range(a[0],a[-1]+1): 6 | print("Yes") 7 | else: 8 | print("No") -------------------------------------------------------------------------------- /Dada Ques.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b,c,d=map(int,input().split()) 3 | flag=0 4 | if a==c and b==d: 5 | print("Yes") 6 | continue 7 | elif a>c and b>d: 8 | print("No") 9 | continue 10 | else: 11 | while True: 12 | if d-c>0: 13 | d-=c 14 | else: 15 | c-=d 16 | if c==a and d==b: 17 | flag=1 18 | break 19 | if ca[1]+a[-1]: 9 | if d[i]>s: 10 | s=d[i] 11 | elif i==n-1: 12 | if d[i]>a[0]+a[-2]: 13 | if d[i]>s: 14 | s=d[i] 15 | elif d[i]>a[i-1]+a[i+1]: 16 | if d[i] > s: 17 | s = d[i] 18 | print(s) -------------------------------------------------------------------------------- /Devu and Grapes.py: -------------------------------------------------------------------------------- 1 | for x in range(int(input())): 2 | n,m=map(int,input().split()) 3 | b=[int(x) for x in input().split()] 4 | usm=0 5 | """for i in b: 6 | d=i//m 7 | usm+=min(abs(i-(d*m)),abs(i-((d+1)*m))) 8 | print(usm) 9 | usm=0""" 10 | for i in b: 11 | if i % m!= 0: 12 | d = i // m 13 | usm += min(abs(i - (d * m)), abs(i - ((d + 1) * m))) 14 | print(usm) 15 | """usm=0 16 | for i in b: 17 | if i % m != 0: 18 | d = i % m 19 | if i > m: 20 | usm += min(d, m - d) 21 | else: 22 | usm += m - d 23 | print(usm)""" -------------------------------------------------------------------------------- /Devu and friendship testing.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | d=[int(x) for x in input().split()] 4 | print(n-(len(d)-len(set(d)))) -------------------------------------------------------------------------------- /Digit Longest Increasing Subsequences 2.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | lis=[int(x) for x in input().split()] 4 | print(*lis,sep='') -------------------------------------------------------------------------------- /Download file.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | su=0 4 | for i in range(n): 5 | t,d=map(int,input().split()) 6 | if k>t: 7 | k-=t 8 | else: 9 | t-=k 10 | k-=k 11 | if not k: 12 | su+=t*d 13 | print(su) -------------------------------------------------------------------------------- /Encoding Message.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=list(input()) 4 | LOL=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] 5 | i=0 6 | while i+1>16) 8 | print("Case "+str(j+1)+":") 9 | print(*a) 10 | print(*b) 11 | 12 | 13 | 14 | 15 | 16 | """x,n=map(int,input().split()) 17 | n=n<<(1<<(1<<(1<<1))) 18 | x=x|n 19 | print(n) 20 | print(x) 21 | x1=x-n 22 | n=(((((n>>11)>>1)>>1)>>1)>>1)>>1 #just made trial error until it giving the same lol ;) 23 | print(x1,n)""" -------------------------------------------------------------------------------- /Farmer And His Plot.py: -------------------------------------------------------------------------------- 1 | import math as ma 2 | for _ in range(int(input())): 3 | n,m=map(int,input().split()) 4 | print(int((m*n)//ma.pow(ma.gcd(n,m),2))) 5 | -------------------------------------------------------------------------------- /Fencing.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m,ck=map(int,input().split()) 3 | a=[[]] 4 | pl=[] 5 | r1,rprev=-2,0 6 | fu=ck*4 7 | for _ in range(ck): 8 | pl.append(list(map(int,input().split()))) 9 | pl.sort() 10 | for i in pl: 11 | r,c=i[0],i[1] 12 | if r!=r1: 13 | a.append([]) 14 | rprev=r1 15 | r1=r 16 | a[-1].append(c) 17 | if c-1 in a[-1]: 18 | fu-=2 19 | if (c in a[-2]) and r-rprev==1: 20 | fu-=2 21 | print(fu) 22 | 23 | #"Those who break the rules are scum, that's true, but those who abandon their friends are worse than scum." -------------------------------------------------------------------------------- /Fibonacci String.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | c=list(set(s)) 4 | l=[] 5 | for i in c: 6 | l.append(s.count(i)) 7 | noty=0 8 | l.sort() 9 | #print(l) 10 | if len(l)<3: 11 | print("Dynamic") 12 | else: 13 | for i in range(2,len(l)): 14 | if i==3: 15 | if not l[3]==l[2]+l[1] and not l[3]==l[2]+l[0]: 16 | noty=1 17 | break 18 | elif l[i-1]+l[i-2]!=l[i]: 19 | noty=1 20 | break 21 | if noty: 22 | print("Not") 23 | else: 24 | print("Dynamic") 25 | -------------------------------------------------------------------------------- /Fit Squares in Triangle.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | b=int(input()) 3 | if b==1: 4 | print(0) 5 | else: 6 | c=(b//2)-1 7 | tot=(c*(c+1))/2 8 | print(int(tot)) -------------------------------------------------------------------------------- /Football Match.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | lo=[] 4 | for _ in range(n): 5 | lo.append(input()) 6 | s = list(set(lo)) 7 | if n==0: 8 | print("Draw") 9 | elif len(s)==1: 10 | print(s[0]) 11 | else: 12 | t1=lo.count(s[0]) 13 | t2=lo.count(s[1]) 14 | if t1>t2: 15 | print(s[0]) 16 | elif t2>t1: 17 | print(s[1]) 18 | else: 19 | print("Draw") -------------------------------------------------------------------------------- /Forgotten Language.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | mydik={} 4 | for x in input().split(): 5 | mydik.setdefault(x, 0) 6 | #print(mydik) 7 | for _ in range(k): 8 | s=input() 9 | for i in mydik: 10 | if i in s: 11 | mydik[i]+=1 12 | #print(mydik) 13 | for i in mydik: 14 | print("YES"*bool(mydik[i]>0)+"NO"*bool(mydik[i]==0),end=' ') 15 | print() -------------------------------------------------------------------------------- /Friend or Girlfriend.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s,x=input().split() 4 | c=0 5 | ind=[-1] 6 | for i in range(n): 7 | if s[i]==x: 8 | ind.append(i) 9 | for i in range(1,len(ind)): 10 | st=ind[i]-ind[i-1] 11 | f=n-ind[i] 12 | c+=(st*f) 13 | print(c) 14 | 15 | 16 | #"A Shinobi's life is not measured by how they lived but rather what they managed to accomplish before their death." - The Jiraiya <3 17 | -------------------------------------------------------------------------------- /GCD and LCM.py: -------------------------------------------------------------------------------- 1 | from math import gcd 2 | for _ in range(int(input())): 3 | a,b=map(int,input().split()) 4 | print(gcd(a,b),int((a*b)/gcd(a,b))) -------------------------------------------------------------------------------- /Game of chef.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | su,m=0,0 5 | for i in range(n): 6 | for j in range(i,n+1): 7 | su=sum(a[i:j]) 8 | if su>m: 9 | m=su 10 | print(m) 11 | -------------------------------------------------------------------------------- /Good Joke!.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | for _ in range(int(input())): 3 | n=int(input()) 4 | a=[] 5 | for i in range(n): 6 | a.append([int(c) for c in input().split()]) 7 | p=a.copy() 8 | #print(p) 9 | mi=9999 10 | x=1 11 | start,temp=a[0],[] 12 | #print("start="+str(start)) 13 | #print("pos of start in p= " + str(p.index(start) + 1)) 14 | #print(str(a[0])+" removed") 15 | a.remove(a[0]) 16 | for _ in range(n-1): 17 | l = len(a) 18 | #print(*a) 19 | #print("len(a)= "+str(l)) 20 | for i in range(l): 21 | if min(abs(start[0]-a[i][0]),abs(start[1]-a[i][1]))k: 11 | print("chef") 12 | elif l<=k and u>k: 13 | print("brother") 14 | elif u<=k and l<=k: 15 | print("both") 16 | else: 17 | print("none") 18 | -------------------------------------------------------------------------------- /Grade The Steel.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | h,c,t=map(float,input().split()) 3 | if h>50 and c<0.7 and t>5600: 4 | print(10) 5 | elif h>50 and c<0.7: 6 | print(9) 7 | elif c<0.7 and t>5600: 8 | print(8) 9 | elif h>50 and t>5600: 10 | print(7) 11 | elif h>50 or c<0.7 or t>5600: 12 | print(6) 13 | elif not h>50 and not c<0.7 and not t>5600: 14 | print(5) -------------------------------------------------------------------------------- /Greedy puppy.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | maxc=0 4 | for i in range(1,k+1): 5 | if n%i>maxc: 6 | maxc=n%i 7 | print(maxc) 8 | -------------------------------------------------------------------------------- /Gross Salary.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | sal=float(input()) 3 | hra,da=0.0,0.0 4 | if sal<1500: 5 | hra=0.1*sal 6 | da=0.9*sal 7 | elif sal>=1500: 8 | hra=500 9 | da=0.98*sal 10 | print(sal+hra+da) 11 | -------------------------------------------------------------------------------- /Help Lost Robot!.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | x1,y1,x2,y2=map(int,input().split()) 3 | if x1==x2: 4 | print("up"*bool(y2>y1)+"down"*bool(y2x1)+"left"*bool(x20: 5 | print(p) 6 | else:print(0) -------------------------------------------------------------------------------- /Id and Ship.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | c=input() 3 | print("BattleShip"*bool(c=='B' or c=='b')+"Cruiser"*bool(c=='C' or c=='c')+"Destroyer"*bool(c=='D' or c=='d')+"Frigate"*bool(c=='F' or c=='f')) -------------------------------------------------------------------------------- /Is it a Cakewalk Problem.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,t=[],0 3 | for i in range(10): 4 | a.append([int(x) for x in input().split()]) 5 | for i in range(10): 6 | for j in range(10): 7 | if a[i][j]<=30: 8 | t+=1 9 | if t>=60: 10 | print("yes") 11 | else: 12 | print('no') -------------------------------------------------------------------------------- /Is it a VOWEL or CONSONANT.py: -------------------------------------------------------------------------------- 1 | c=input().upper() 2 | print("Vowel"*bool(c in "AEIOU")+"Consonant"*bool(c not in "AEIOU")) -------------------------------------------------------------------------------- /Itercdvta.py: -------------------------------------------------------------------------------- 1 | dict={'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'I': 18, 'J': 19, 'K': 20, 'L': 21, 'M': 22, 'N': 23, 'O': 24, 'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T': 29, 'U': 30, 'V': 31, 'W': 32, 'X': 33, 'Y': 34, 'Z': 35} 2 | s=input() 3 | ini,fin=0,0 4 | x=0 5 | t=[] 6 | for i in s: 7 | t.append(dict[i]) 8 | maxy=max(t) 9 | base=maxy+1 10 | te=len(t)-1 11 | 'print(t,maxy,base,te)' 12 | for i in t: 13 | fin += i * (base ** te) 14 | te = te - 1 15 | 16 | 17 | 'print(fin)' 18 | 19 | while True: 20 | """x+=1 21 | print() 22 | print(x)""" 23 | 24 | ini=fin 25 | t1=list(str(fin)) 26 | fin = 0 27 | 28 | maxy = int(max(t1)) 29 | base = maxy + 1 30 | te = len(t1) - 1 31 | 32 | 'print(t1,maxy,base,te)' 33 | 34 | for i in t1: 35 | fin += int(i) * (base ** te) 36 | te = te - 1 37 | 'print(fin)' 38 | 39 | 'print(fin)' 40 | if fin==ini: 41 | break 42 | print(fin) 43 | 44 | -------------------------------------------------------------------------------- /J - Reached Safely Or Not.py: -------------------------------------------------------------------------------- 1 | for j in range(int(input())): 2 | m,n=map(int,input().split()) 3 | rx, ry = map(int, input().split()) 4 | l=int(input()) 5 | s=input() 6 | x,y=0,0 7 | for i in s: 8 | if i=='U': 9 | y+=1 10 | if i=='D': 11 | y-=1 12 | if i=='R': 13 | x+=1 14 | if i=='L': 15 | x-=1 16 | if (x<0 or y<0) or (x>m or y>n): 17 | print("Case "+str(j+1)+": DANGER") 18 | elif x==rx and y==ry: #'or' karke rakha tha bhaaagwaaaan :( 19 | #bhagwaan: "kuch na ho payga re tera aagar isme bhi WA aya toh -_-" 20 | #bhagwaan: "aur kitna insult karwayega re khudka!!!!!" 21 | #me: "i never give up -_0" 22 | print("Case "+str(j+1)+": REACHED") 23 | else: 24 | print("Case "+str(j+1)+": SOMEWHERE") -------------------------------------------------------------------------------- /Judging Delay.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | c=0 4 | for _ in range(n): 5 | s,j=map(int,input().split()) 6 | if j-s>5: 7 | c+=1 8 | print(c) -------------------------------------------------------------------------------- /Jumping in the hills.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,u,d=map(int,input().split()) 3 | h=[int(x) for x in input().split()] 4 | para,i=0,0 5 | while i=h[i]: 15 | if h[i+1]-h[i]<=u: 16 | i+=1 17 | else: 18 | break 19 | 20 | print(i+1) -------------------------------------------------------------------------------- /K Fibonnaci.py: -------------------------------------------------------------------------------- 1 | def series(n1,k1): 2 | s=0 3 | if n1<=k1: 4 | return 1 5 | else: 6 | for i in range(1,k1+1): 7 | s+=series(n1-i,k1) 8 | return s 9 | 10 | n,k=map(int,input().split()) 11 | ans=series(n,k) 12 | print(ans%1000000007) -------------------------------------------------------------------------------- /Kitchen Timetable.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | b=[int(x) for x in input().split()] 5 | d,s=0,0 6 | a.insert(0,d) 7 | for i in range(1,n+1): 8 | if a[i]-a[i-1]>=b[i-1]: 9 | s+=1 10 | print(s) -------------------------------------------------------------------------------- /Lazy Jem.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,b,m=map(int,input().split()) 3 | su=0 4 | while n!=0: 5 | p=int((n/2)*(n%2==0)+((n+1)/2)*(n%2!=0)) 6 | su+=p*m+b*(n//2!=0) 7 | m*=2 8 | n-=p 9 | print(su) -------------------------------------------------------------------------------- /Life Limited.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,f=[],0 3 | for _ in range(3): 4 | a.append(list(input())) 5 | for i in range(2): 6 | if not f: 7 | for j in range(2): 8 | if a[i][j]=='l' and a[i+1][j]=='l' and a[i+1][j+1]=='l': 9 | print('yes') 10 | f=1 11 | break 12 | if f!=1: 13 | print('no') -------------------------------------------------------------------------------- /Lucky number game.py: -------------------------------------------------------------------------------- 1 | t=int(input()) 2 | 3 | 4 | for q in range(t): 5 | A = [] 6 | bob = alice = True 7 | inputs=list(map(int,input().strip().split())) 8 | n=inputs[0] 9 | a=inputs[1] 10 | b=inputs[2] 11 | 12 | for x in range(n): 13 | A.append(int(input())) 14 | 15 | while bob and alice: 16 | c=0 17 | bob=False 18 | alice=False 19 | for i in A: 20 | if i%a==0: 21 | A.remove(i) 22 | bob=True 23 | c+=1 24 | 25 | if bob: 26 | for x in range(c): 27 | for i in A: 28 | if i%b==0: 29 | A.remove(i) 30 | alice=True 31 | break 32 | if not alice: 33 | break 34 | #if not alice: 35 | # print("BOB") 36 | # break 37 | #else: 38 | # print("ALICE") 39 | # break 40 | 41 | if not bob: 42 | print("ALICE") 43 | else: 44 | print("BOB") 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Magic Set.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | c=0 5 | for i in a: 6 | if i%m==0: 7 | c+=1 8 | print(2**c-1) -------------------------------------------------------------------------------- /Magician versus Chef.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,x,s=map(int,input().split()) 3 | kidnap=x 4 | for i in range(s): 5 | a,b=map(int,input().split()) 6 | if kidnap==a: 7 | kidnap=b 8 | elif kidnap==b: 9 | kidnap=a 10 | print(kidnap) -------------------------------------------------------------------------------- /Mahasena.py: -------------------------------------------------------------------------------- 1 | _=int(input()) 2 | a=[0 if int(x)%2==0 else 1 for x in input().split()] 3 | print("READY FOR BATTLE"*bool(a.count(0)>a.count(1))+"NOT READY"*bool(a.count(0)<=a.count(1))) -------------------------------------------------------------------------------- /Malvika is peculiar about color of balloons.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | if 'a' and 'b' in s: 4 | if s.count('a')>s.count('b'): 5 | print(s.count('b')) 6 | else: 7 | print(s.count('a')) 8 | else: 9 | print(0) -------------------------------------------------------------------------------- /Maximise the Sum.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | a.sort() 5 | su=0 6 | for i in range(n//2): 7 | su+=abs(a[n-(i+1)]-a[i]) 8 | print(su) -------------------------------------------------------------------------------- /Maximum Remaining.py: -------------------------------------------------------------------------------- 1 | _=int(input()) 2 | naruto=list(set([int(jiraiya) for jiraiya in input().split()])) 3 | naruto.remove(max(naruto)) 4 | if len(naruto)==0: 5 | print(0) 6 | else: 7 | print(max(naruto)) 8 | 9 | #please watch NARUTO ...plssssss ;_; 10 | #"When a man learns to love, he must bear the risk of hatred." - the greatest Uchiha of all times -------------------------------------------------------------------------------- /Minimum Deletions.py: -------------------------------------------------------------------------------- 1 | 2 | from functools import reduce 3 | from math import gcd as gandu 4 | for _ in range(int(input())): 5 | n=int(input()) 6 | a=[int(x) for x in input().split()] 7 | if 1 in a or reduce(gandu,a)==1: 8 | print(0) 9 | else: 10 | print(-1) 11 | -------------------------------------------------------------------------------- /Minimum Maximum.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | print(min(*a)*(n-1)) 5 | -------------------------------------------------------------------------------- /Movie Weekend.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | l=[int(x) for x in input().split()] 4 | r = [int(x) for x in input().split()] 5 | maxmul=-1 6 | maxr=-1 7 | for i in range(n): 8 | if l[i]*r[i]>maxmul: 9 | maxmul=l[i]*r[i] 10 | for i in range(n): 11 | if l[i]*r[i]==maxmul: 12 | if r[i]>maxr: 13 | maxr=r[i] 14 | 15 | print(r.index(maxr)+1) 16 | -------------------------------------------------------------------------------- /Naive Chef.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,a,b=map(int,input().split()) 3 | x=[int(x) for x in input().split()] 4 | ca,cb=x.count(a),x.count(b) 5 | print("{:.10f}".format((ca*cb)/n**2)) 6 | -------------------------------------------------------------------------------- /NightsWatch.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | l=input() 4 | s=list(l) 5 | c=0 6 | if '1' in l: 7 | i=0 8 | while i<(n-1): 9 | if s[i]=='0' and s[i+1]=='0' and s[i+2]=='0': 10 | c+=1 11 | s[i+1]='1' 12 | elif s[i] == '0' and s[i + 1] == '0' and s[i + 2] == '1': 13 | c+=1 14 | s[i]='1' 15 | elif s[i] == '1' and s[i + 1] == '0': 16 | if i+2k[q]: 15 | c+=1 16 | elif j[q]==k[q] and eq<2: 17 | c+=1 18 | eq+=1 19 | eq=0 20 | if c==len(temp1)*3: 21 | p.remove(j) 22 | gd+=1 23 | break 24 | if gd==2: 25 | print("yes") 26 | else: 27 | print("no") -------------------------------------------------------------------------------- /PERMUTATION_OF_STRING.py: -------------------------------------------------------------------------------- 1 | cll=[] 2 | def tostring(lista): 3 | return ''.join(lista) 4 | 5 | 6 | def permute(a, l, r): 7 | if l==r: 8 | cll.append(tostring(a)) 9 | else: 10 | for i in range(l,r+1): 11 | a[l], a[i] = a[i], a[l] 12 | permute(a, l+1, r) 13 | a[l], a[i] = a[i], a[l] # backtrack 14 | 15 | 16 | string = "chef" 17 | n = len(string) 18 | a = list(string) 19 | permute(a, 0, n-1) 20 | 21 | print(cll) 22 | # Function to print permutations of string 23 | # This function takes three parameters: 24 | # 1. String 25 | # 2. Starting index of the string 26 | # 3. Ending index of the string. 27 | -------------------------------------------------------------------------------- /Palindromic substrings.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a=input() 3 | b=input() 4 | pal=False 5 | for i in a: 6 | if i in b: 7 | print("Yes") 8 | pal=True 9 | break 10 | if not pal: 11 | print("No") -------------------------------------------------------------------------------- /Play Piano.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | n=len(s) 4 | g=['AB','BA'] 5 | if n%2==0 and all(s[i:i+2] in g for i in range(0,len(s)-1,2)): 6 | print("yes") 7 | else: 8 | print("no") -------------------------------------------------------------------------------- /Pogo Stick Competition.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | s,maxy=0,[] 5 | for i in range(n): 6 | for j in range(i,n,k): 7 | s+=a[j] 8 | maxy.append(s) 9 | s=0 10 | print(max(maxy)) -------------------------------------------------------------------------------- /Print Pattern.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | for _ in range(int(input())): 3 | n=int(input()) 4 | x=np.zeros((n,n)) 5 | i,j,c=0,0,0 6 | while i<=n-1 and j<=n-1: 7 | tempi = i 8 | tempj = j 9 | while tempi<=j: 10 | c+=1 11 | x[tempi][tempj]=int(c) 12 | tempj-=1 13 | tempi+=1 14 | if j!=n-1: 15 | i=0 16 | j+=1 17 | else: 18 | i+=1 19 | j=n-1 20 | 21 | for i in range(n): 22 | print(*list(map(int,x[i]))) -------------------------------------------------------------------------------- /Program Your Own CALCULATOR.py: -------------------------------------------------------------------------------- 1 | a=float(input()) 2 | b=float(input()) 3 | o=input() 4 | if o=="+": 5 | print(int(a+b)) 6 | elif o=="-": 7 | print(int(a-b)) 8 | elif o=="/": 9 | print(a/b) 10 | else: 11 | print(int(a*b)) -------------------------------------------------------------------------------- /Puppy and Sum.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | d,n=map(int,input().split()) 3 | for _ in range(d): 4 | n=sum(range(1,n+1)) 5 | print(n) -------------------------------------------------------------------------------- /Quentin Tarantino.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | ch=[int(x) for x in input().split()] 4 | nch=ch.copy() 5 | ch.sort() 6 | if len(set(ch)) (Link provided above ^) 3 | 4 | These are my works from past 4-5 months... when i was in 2nd Yr. of Grad. 5 | 6 | Yesterday i learned to use Git and GitHub... uploaded the codes with a hope, it would help a lot of beginners in python. 7 | Recently i have switched back to Java. 8 | Java is love ;) 9 | -------------------------------------------------------------------------------- /Random Pair.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=list(map(int,input().split())) 4 | lsa=list(set(a)) 5 | lsa.sort() 6 | maxc,max2c=a.count(lsa[-1]),0 7 | if len(lsa)!=1: 8 | max2c=a.count(lsa[-2]) 9 | if maxc==1: 10 | print("{:.8f}".format(max2c/((n*(n-1))/2))) 11 | else: 12 | print("{:.8f}".format(((maxc * (maxc - 1)) / 2) / ((n * (n - 1)) / 2))) -------------------------------------------------------------------------------- /Rectangle.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a=[int(x) for x in input().split()] 3 | s=list(set(a)) 4 | if (len(s)==2 and a.count(s[0])==2 and a.count(s[1])==2) or (len(s)==1):print("YES") 5 | else:print("NO") 6 | -------------------------------------------------------------------------------- /Rooks.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=[int(x) for x in input().split()] 3 | r=[] 4 | c=[] 5 | for i in range(k): 6 | s=list(input().split()) 7 | r.append(int(s[0])) 8 | c.append(int(s[1])) 9 | for i in range(n): 10 | if i+1 not in r: 11 | r.append(i+1) 12 | for j in range(n): 13 | if j+1 not in c: 14 | c.append(j+1) 15 | break 16 | print(len(r)-k,end=" ") 17 | for i in range(k,len(r)): 18 | print(r[i],end=" ") 19 | print(c[i],end=" ") 20 | print() -------------------------------------------------------------------------------- /Roots of a Quadratic Equation.py: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | a,b,c =int(input()),int(input()),int(input()) 3 | x1=(-b+sqrt(pow(b,2)-(4*a*c)))/(2*a) 4 | x2=(-b-sqrt(pow(b,2)-(4*a*c)))/(2*a) 5 | print(x1) 6 | print(x2) -------------------------------------------------------------------------------- /Rupsa and the Game.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | mul,mod=[a[0]],1000000007 5 | #for i in range(1,n): 6 | #mul.append(a[i]*(2**(i-1))) 7 | #print(mul) 8 | sumy,temp=0,a[0] 9 | pr1=1 10 | for i in range(1,n+1): 11 | pr=(a[i]*temp) 12 | sumy=2*sumy+pr 13 | temp += (a[i] * pr1) 14 | pr1=(pr1*2)%mod 15 | print((sumy*2)%mod) 16 | 17 | # prev submission with n+1 -_- -------------------------------------------------------------------------------- /Sebi and the highway.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s,sg,fg,d,t=map(int,input().split()) 3 | kph=(d*50*18)/(t*5) 4 | print(kph) 5 | print((18/5)*((d*50)/t)) 6 | stot=s+kph 7 | sebidiff=abs(sg-stot) 8 | fatherdiff=abs(fg-stot) 9 | if fatherdiff=a and y>=b: 5 | if c==(x-a)+(y-b): 6 | possible=1 7 | elif x>=b and y>=a: 8 | if c==(x-b)+(y-a): 9 | possible=1 10 | elif x>=a and y>=c: 11 | if b==(x-a)+(y-c): 12 | possible=1 13 | elif x>=c and y>=a: 14 | if b==(x-c)+(y-a): 15 | possible=1 16 | elif x>=b and y>=c: 17 | if a==(x-b)+(y-c): 18 | possible=1 19 | elif x>=c and y>=b: 20 | if a==(x-c)+(y-b): 21 | possible=1 22 | 23 | if possible: 24 | print("YES") 25 | else: 26 | print("NO") 27 | -------------------------------------------------------------------------------- /Sticks.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | s=list(set(a)) 5 | s.sort() 6 | s.reverse() 7 | cont=0 8 | ar=1 9 | for i in s: 10 | if a.count(i)>1 and cont<2: 11 | ar*=i 12 | cont+=1 13 | if a.count(i)>3 and cont<2: 14 | ar*=i 15 | cont+=1 16 | if cont==2: 17 | print(ar) 18 | break 19 | if cont<2:print(-1) 20 | -------------------------------------------------------------------------------- /Strange Operations.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | s=(2*sum(a))+1 5 | if (((k-1)*s)+2)%2==0:print("even") 6 | else:print("odd") -------------------------------------------------------------------------------- /Strike or Spare.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | print(1,n**(2**(n-1)-(n-1))) 4 | -------------------------------------------------------------------------------- /Studying Alphabet.py: -------------------------------------------------------------------------------- 1 | s=input() 2 | n=int(input()) 3 | 4 | for _ in range(n): 5 | flag = 0 6 | w=set(input()) 7 | for i in w: 8 | if i not in s: 9 | print("No") 10 | flag=1 11 | break 12 | if not flag:print("Yes") -------------------------------------------------------------------------------- /Subsequence Equality.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | flag=0 4 | for i in range(len(s)-2): 5 | if s.count(s[i])>=2: 6 | print("yes") 7 | flag=1 8 | break 9 | if not flag: 10 | print("no") -------------------------------------------------------------------------------- /Subtree Removal.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | l,su=[],0 5 | forbidden=[0]*n 6 | for _ in range(n-1): 7 | t=list(map(int,input().split())) 8 | l.append(t) 9 | l.sort() 10 | c=0 11 | pos=[0]*(n+1) 12 | pos[0]=1 13 | for i in l[-1::-1]: 14 | a[i[0]-1]+=a[i[1]-1] 15 | ans=a[0] 16 | 17 | for i in l: 18 | if i[0]==1 or pos[i[0]-1]==1: 19 | pos[i[1]-1]=i[0] 20 | else: 21 | pos[i[1]-1]=pos[i[0]-1] 22 | #print(pos) 23 | 24 | ns=[] 25 | for _ in range(l[(pos.count(1)-1)-1][1]): 26 | ns.append([]) 27 | for i in range(1,n): 28 | ns[pos[i]-1].append(a[i]) 29 | #print(ns) 30 | 31 | p1=0 32 | if ans-ans-k>=ans: 33 | p1=ans-ans-k 34 | 35 | for i in range(1,len(ns)): 36 | m=min(ns[i]) 37 | #print(m) 38 | m=min(m,ns[0][i-1]) 39 | #print(m,ns[0][i-1]) 40 | if m<0 and abs(m)-k>0: 41 | ans=ans+(abs(m)-k) 42 | print(max(p1,ans)) 43 | 44 | """for i in l: 45 | if forbidden[i[0]-1]!=1: 46 | if a[i[1]-1]<0 and abs(a[i[1]-1])-k>0: 47 | forbidden[i[1]-1]=1 48 | ans+=abs(a[i[1]-1]) 49 | c+=1 50 | else: 51 | forbidden[i[1]-1]=1 52 | 53 | 54 | print(ans-(k*c))""" -------------------------------------------------------------------------------- /Sum OR Difference.py: -------------------------------------------------------------------------------- 1 | n1,n2=int(input()),int(input()) 2 | print((n1-n2)*(n1>n2)+(n1+n2)*(n1<=n2)) -------------------------------------------------------------------------------- /Sums in a Triangle.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | r=int(input()) 3 | a=[] 4 | for _ in range(r): 5 | a.append([int(x) for x in input().split()]) 6 | st=a[0] 7 | temp=[] 8 | for i in range(1,r): 9 | k=0 10 | for j in st: 11 | if k>0: 12 | if j+a[i][k]>temp[k]: 13 | temp[k]=j+a[i][k] 14 | else: 15 | temp.append(j+a[i][k]) 16 | temp.append(j+a[i][k+1]) 17 | k+=1 18 | st=temp.copy() 19 | temp=[] 20 | #print(st) 21 | print(max(st)) 22 | -------------------------------------------------------------------------------- /Survive in ChocoLand.py: -------------------------------------------------------------------------------- 1 | import math as ma 2 | for _ in range(int(input())): 3 | n,k,s=map(int,input().split()) 4 | d=s-(s//7) 5 | req=k*s 6 | got=n*d 7 | daysononebox=n/k 8 | if got>=req: 9 | print(int(ma.ceil(s/daysononebox))) 10 | else: 11 | print(-1) -------------------------------------------------------------------------------- /Tanu and Head-bob.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=input().upper() 4 | i=s.count('I') 5 | no=s.count('N') 6 | y=s.count('Y') 7 | if no==len(s) or (i!=0 and y!=0): 8 | print("NOT SURE") 9 | elif i==0 and y>0: 10 | print("NOT INDIAN") 11 | elif y==0 and i>0: 12 | print("INDIAN") -------------------------------------------------------------------------------- /Task for Alexey.py: -------------------------------------------------------------------------------- 1 | import math as aaa 2 | import sys 3 | for _ in range(int(input())): 4 | n=int(input()) 5 | a=[int(x) for x in input().split()] 6 | a.sort() 7 | mini=sys.maxsize 8 | for i in range(n-1): 9 | for j in range(i+1,n): 10 | if (a[i]*a[j])//aaa.gcd(a[i],a[j])maxi: 7 | maxi=sum(a[i:i+k]) 8 | print(maxi) -------------------------------------------------------------------------------- /The Smallest Pair.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | a.sort() 5 | print(a[0]+a[1]) -------------------------------------------------------------------------------- /The Tricky Deal.py: -------------------------------------------------------------------------------- 1 | from math import pow 2 | for _ in range(int(input())): 3 | a=int(input()) 4 | i,s,chs,pr=1,0,0,0 5 | d1,d2=0,0 6 | while True: 7 | s+=a 8 | ch=pow(2,i-1) 9 | chs+=ch 10 | if chs>s: 11 | break 12 | else: 13 | d1=i 14 | if a-ch>0: 15 | d2=i 16 | i+=1 17 | print(d1,d2) 18 | 19 | 20 | -------------------------------------------------------------------------------- /Three Friends.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | x,y,z=map(int,input().split()) 3 | sets=[[-x,y,z],[x,-y,z],[x,y,-z]] 4 | c=0 5 | for i in sets: 6 | if abs(i[0]+i[1])==abs(i[2]) and abs(i[1]+i[2])==abs(i[0]) and abs(i[0]+i[2])==abs(i[1]): 7 | c+=1 8 | break 9 | if c: 10 | print("yes") 11 | else: 12 | print("no") -------------------------------------------------------------------------------- /Tickets.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | """s=input().upper() 3 | if s[0]!=s[1]: 4 | if (s.count(s[0]+s[1]))*2<=len(s): 5 | print("YES") 6 | continue 7 | print("NO")""" 8 | s=set(input()) 9 | if len(s)==2: 10 | print("YES") 11 | else: 12 | print("NO") 13 | #WRONG QUESTION/TEST CASES BRO.. LOL.. ABBABA SHOULD GIVE "NO" BUT 100pts FOR "YES" LMAO -------------------------------------------------------------------------------- /Total Expenses.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | q,p=map(float,input().split()) 3 | if q>1000: 4 | p=0.9*p 5 | print("%.6f"%(q*p)) -------------------------------------------------------------------------------- /Trace of Matrix.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[] 4 | maxy=[] 5 | 6 | for i in range(n): 7 | a.append(list(map(int,input().split()))) 8 | 9 | for i in range(n): 10 | sumy=0 11 | i1=i 12 | for j in range(n-i): 13 | sumy+=a[j][i1] 14 | i1+=1 15 | maxy.append(sumy) 16 | #print(maxy) 17 | for i in range(1,n): 18 | sumy=0 19 | i1=i 20 | for j in range(n-i): 21 | sumy+=a[i1][j] 22 | i1+=1 23 | maxy.append(sumy) 24 | #print(maxy) 25 | print(max(maxy)) -------------------------------------------------------------------------------- /Train Partner.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | dic = {3: "UB", 2: "MB", 1: "LB", 7: "SU", 6: "UB", 5: "MB", 4: "LB", 0: "SL"} 4 | dik = {3: 6, 2: 5, 1: 4, 7: 8, 6: 3, 5: 2, 4: 1, 0: -1} 5 | print(8*(n//8)+dik[n%8],dic[n%8],sep='') -------------------------------------------------------------------------------- /Turbo Sort.py: -------------------------------------------------------------------------------- 1 | t=int(input()) 2 | a=[] 3 | for _ in range(t): 4 | a.append(int(input())) 5 | a.sort() 6 | print(*a,sep="\n") -------------------------------------------------------------------------------- /Tweedle-Dee and Tweedle-Dum.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n1,p=input().split() 3 | n=int(n1) 4 | a=[int(x) for x in input().split()] 5 | if a[0]%2==0 and n==1 and p=='Dee': 6 | print("Dee") 7 | else: 8 | print("Dum") -------------------------------------------------------------------------------- /Two Numbers.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b,n=map(int,input().split()) 3 | print((max(a,b)//min(a,b))*bool(n%2==0)+(max(2*a,b)//min(2*a,b))*bool(n%2!=0)) -------------------------------------------------------------------------------- /Two vs Ten.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | x=int(input()) 3 | if x%10==0: 4 | print(0) 5 | elif x%5==0: 6 | print(1) 7 | else: 8 | print(-1) -------------------------------------------------------------------------------- /Uniform Strings.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | if s.count('01')+s.count('10')+int(s[0]!=s[len(s)-1])<=2: 4 | print("uniform") 5 | else: 6 | print("non-uniform") -------------------------------------------------------------------------------- /Valid Stack Operations.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | _=int(input()) 3 | a=[int(x) for x in input().split()] 4 | s=0 5 | for i in a: 6 | if i==1: 7 | s+=1 8 | else: 9 | s-=1 10 | if s<0: 11 | break 12 | if s<0: 13 | print("Invalid") 14 | else: 15 | print("Valid") -------------------------------------------------------------------------------- /Version Control System.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m,k=map(int,input().split()) 3 | ig=set([int(x) for x in input().split()]) 4 | tc=set([int(x) for x in input().split()]) 5 | print(len(ig.intersection(tc)),n-len(ig.union(tc))) -------------------------------------------------------------------------------- /Villages and Tribes.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | fa,fb,ca,cb=None,None,0,0 4 | for i in range(len(s)): 5 | if s[i]=='A': 6 | if fa is not None: 7 | ca+=i-fa 8 | else: 9 | ca+=1 10 | fa = i 11 | fb=None 12 | if s[i] == 'B': 13 | if fb is not None: 14 | cb += i - fb 15 | else: 16 | cb += 1 17 | fb = i 18 | fa = None 19 | 20 | print(ca,cb) -------------------------------------------------------------------------------- /Whats in the name.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=list(input().lower().split(' ')) 3 | st="" 4 | for i in range(len(s)-1): 5 | st+=s[i][0].upper()+". " 6 | print(st+s[len(s)-1].capitalize()) -------------------------------------------------------------------------------- /Workers.py: -------------------------------------------------------------------------------- 1 | import sys 2 | n=int(input()) 3 | c=[int(x) for x in input().split()] 4 | t=[int(x) for x in input().split()] 5 | min1,min2,min3=sys.maxsize,sys.maxsize,sys.maxsize 6 | for i in range(n): 7 | if t[i]==1: 8 | if c[i]=4.0:print("Yes") 7 | else:print("No") 8 | else:print("No") 9 | -------------------------------------------------------------------------------- /art of balance2.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | from math import sqrt 3 | for _ in range(int(input())): 4 | st=input().upper() 5 | lst=len(st) 6 | prime=True 7 | if lst < 2: 8 | prime=False 9 | else: 10 | for i in range(2, int(sqrt(lst)) + 1): 11 | if lst % i == 0: 12 | prime=False 13 | break 14 | s=set(st) 15 | c=[] 16 | min_avg=999999 17 | min_i=0 18 | min_c=0 19 | comp=0 20 | for i in s: 21 | c.append(st.count(i)) 22 | c.sort() 23 | c.reverse() 24 | l=len(c) 25 | print(c) 26 | i=1 27 | f=[] 28 | print(f) 29 | while i<=26: 30 | if prime and i<=lst: 31 | if lst%i==0: 32 | f.append(i) 33 | elif i<=l: 34 | if lst%i==0: 35 | f.append(i) 36 | i+=1 37 | print(f) 38 | for i in f: 39 | print("for i="+str(i)) 40 | comp=lst/i 41 | print("comp="+str(comp)) 42 | diff=0 43 | if i>l: 44 | i=l 45 | for j in range(i): 46 | print("for j="+str(j),end=" ") 47 | diff+=abs(comp-c[j]) 48 | print(diff) 49 | avg=diff/i 50 | print(avg) 51 | if avgb[i]: 8 | d.append(a[i]-b[i]) 9 | c.append(i) 10 | else: 11 | d.append(b[i]-a[i]) 12 | c.append(i) 13 | print(d) 14 | print(c) 15 | 16 | for i in range(n-1): 17 | for j in range(i+1,n): 18 | if d[i]0: 20 | A=list(map(int , stdin.readline().split())) 21 | s=sum(A) 22 | print(s) 23 | print(mydict[s]) 24 | t=t-1 25 | -------------------------------------------------------------------------------- /chef and his students.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | print(s.count("<>")) -------------------------------------------------------------------------------- /chef and majical jars.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x)-1 for x in input().split()] 4 | print(sum(a)+1) -------------------------------------------------------------------------------- /chef and party.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | a.sort() 5 | sumy=0 6 | joined=0 7 | for i in range(n): 8 | if sumy>=a[i]: 9 | sumy+=1 10 | joined+=1 11 | print(joined) -------------------------------------------------------------------------------- /chef and secret ingredients.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | l=[] 4 | for _ in range(n): 5 | l.append(set(input())) 6 | print(len(set.intersection(*l))) -------------------------------------------------------------------------------- /chef and secret password.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=input() 4 | """lmax=-1 5 | cmax=s.count(s[0]) 6 | ctot=1 7 | ltot=len(s) 8 | pas="" 9 | for i in range(n//2+1): 10 | c=s.count(s[:i+1]) 11 | l=len(s[:i+1]) 12 | if cmax==c: 13 | if l>lmax: 14 | pas=s[:i+1] 15 | lmax=l 16 | cmax=c 17 | if ctot==cmax: 18 | if ltot>lmax: 19 | pas=s 20 | 21 | print(pas)""" 22 | st=s 23 | pas="" 24 | p=s[:len(s)//2] 25 | #print(p) 26 | cmax=0 27 | count=1 28 | lmax=-1 29 | while len(p)>=1: 30 | #print("s "+s) 31 | #print("p "+p) 32 | #print("s[len(s)//2+1:] "+s[len(s)//2:]) 33 | if p in s[len(s)//2:]: 34 | count=count*2 35 | l=len(p) 36 | if count>cmax: 37 | lmax=len(p) 38 | cmax=count 39 | pas=p 40 | elif count==cmax: 41 | if l>lmax: 42 | lmax=l 43 | pas=p 44 | #print("lmax "+str(lmax)) 45 | #print("cmax "+str(cmax)) 46 | s=p 47 | p = s[:len(s) // 2] 48 | else: 49 | p=p[:-1] 50 | #print(p) 51 | if cmax==0: 52 | print(st) 53 | else: 54 | print(pas) -------------------------------------------------------------------------------- /chef and table tennis.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | ls=0 4 | wn=0 5 | c=True 6 | for i in range(len(s)): 7 | if not int(s[i]): 8 | ls+=1 9 | if int(s[i]): 10 | wn+=1 11 | if ls == wn == 10: 12 | c=False 13 | for j in range(i+1,len(s)): 14 | if not int(s[j]): 15 | ls+=1 16 | if int(s[j]): 17 | wn+=1 18 | if (ls-wn)==2: 19 | print("LOSE") 20 | elif (wn-ls)==2: 21 | print("WIN") 22 | 23 | if (ls==11 or wn==11) and c: 24 | print("LOSE"*bool(ls==11)+"WIN"*bool(wn==11)) 25 | break 26 | -------------------------------------------------------------------------------- /chef_and_employement test.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=[int(x) for x in input().split()] 3 | a=[int(x) for x in input().split()] 4 | a.sort() 5 | print(a[abs((n+k)//2)]) -------------------------------------------------------------------------------- /chef_and_icecream.py: -------------------------------------------------------------------------------- 1 | b=[0,1,3] 2 | 3 | def count(a): 4 | if a=97 and c<=109 or c>=65 and c<=77: 10 | s[i]=chr(c+13) 11 | 12 | elif c>=110 and c<=122 or c>=78 and c<=90: 13 | s[i]=chr(c-13) 14 | 15 | elif c>=48 and c<=52: 16 | s[i]=chr(c+5) 17 | 18 | elif c>=53 and c<=57: 19 | s[i]=chr(c-5) 20 | 21 | elif s[i]==' ': 22 | s[i]=' ' 23 | for i in s: 24 | print(i,end="") 25 | print() 26 | -------------------------------------------------------------------------------- /common.py: -------------------------------------------------------------------------------- 1 | """a=[int(x) for x in input().split()] 2 | b=[int(x) for x in input().split()] 3 | 4 | for i in a: 5 | if i in b: 6 | print(i)""" 7 | 8 | temp=[] 9 | for i in range(9999): 10 | temp = str(i) 11 | s=0 12 | for t in temp: 13 | s+=int(t)**(len(temp)) 14 | """print(s)""" 15 | if s==i: 16 | print(i) -------------------------------------------------------------------------------- /decrement or invcrement.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | print((n+1)*(n%4==0)+(n-1)*(n%4!=0)) 3 | 4 | -------------------------------------------------------------------------------- /find the maximum value.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a=[int(x) for x in input().split()] 3 | a.remove(len(a)-1) 4 | print(max(a)) -------------------------------------------------------------------------------- /from heaven to earth.py: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | for _ in range(int(input())): 3 | n,v1,v2=map(int,input().split()) 4 | ans=["Stairs","Elevator"] 5 | print(ans[0]*bool(((sqrt(2)*n)/v1)<2*(n/v2))+ans[1]*bool(((sqrt(2)*n)/v1)>=2*(n/v2))) -------------------------------------------------------------------------------- /gregorian calender.py: -------------------------------------------------------------------------------- 1 | import calendar as cal 2 | for _ in range(int(input())): 3 | n=int(input()) 4 | dic={0: "monday", 1: "tuesday", 2: "wednesday", 3: "thursday", 4: "friday", 5: "saturday", 6: "sunday"} 5 | print(dic[cal.weekday(n,1,1)]) -------------------------------------------------------------------------------- /how many digits do i have.py: -------------------------------------------------------------------------------- 1 | l=["1","2","3","More than 3 digits"] 2 | n=input() 3 | if len(n)<4:print(l[len(n)-1]) 4 | else:print(l[3]) -------------------------------------------------------------------------------- /importantINPUT_TEST.py: -------------------------------------------------------------------------------- 1 | x=input("enter vales: ").strip().split(',') 2 | for i in x: 3 | if i ==' ': 4 | print("**") 5 | else: 6 | print(i) 7 | 8 | print("<<<<<................>>>>") 9 | 10 | print(x[0]) 11 | 12 | #print(x[2]) 13 | 14 | #print(x[3]) 15 | 16 | print(x[1]) 17 | 18 | -------------------------------------------------------------------------------- /little chef and sums.py: -------------------------------------------------------------------------------- 1 | import sys 2 | for _ in range(int(input())): 3 | n=int(input()) 4 | a=[int(x) for x in input().split()] 5 | minu = sys.maxsize 6 | minx=0 7 | for i in range(n): 8 | sumu=sum(a[0:i+1])+sum(a[-(n-i):]) 9 | if sumu>>>>>>>") -------------------------------------------------------------------------------- /mantison_and _pangrams.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | tot=0 3 | n=[int(x) for x in input().split()] 4 | st=sorted(set(input().lower())) 5 | for i in range(len(st)): 6 | st[i]=ord(st[i]) 7 | for i in range(97,123): 8 | if i not in st: 9 | tot+=n[i-97] 10 | print(tot) -------------------------------------------------------------------------------- /name1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S-C-U-B-E/CodeChef-Practise-Beginner-Python/78a02303b3cdd7eb7b0c45be59a1c282234f8719/name1.png -------------------------------------------------------------------------------- /nothing in common.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m=[int(x) for x in input().split()] 3 | a=[int(x) for x in input().split()] 4 | b=[int(x) for x in input().split()] 5 | print(len(set(a).intersection(set(b)))) -------------------------------------------------------------------------------- /oDD EVEN FIBO PRIME.py: -------------------------------------------------------------------------------- 1 | n = int(input()) #JOTO GULO PLACE OBDHI ARRAY BHORBI 2 | 3 | result_array=[] #ARRAY INITIALIZE 4 | 5 | FIBO_0TH=0 6 | FIBO_1ST=1 7 | 8 | PRIME_SURU=1 # JODIO EKHANE 1 ACHE.. WHILE LOOP E DHUKE AAGE +1 HOBE 9 | # THEN 2 THEKE 1ST CHECK SURU 10 | 11 | for i in range(n): #LOOP BEGINS 12 | if i%2==0: 13 | if i == 0: 14 | result_array.append(FIBO_0TH) # PROTHOM 2 BAR KONO CALCULATION NEI. 15 | elif i == 2: 16 | result_array.append(FIBO_1ST) 17 | else: 18 | result_array.append(result_array[i-2]+result_array[i-4]) # PREVIOUS DUTO EVEN PLACE -2 AND -4TH 19 | # POSITION E THAKBE 20 | 21 | print("FIBO:i="+str(i)+" VALUE:"+str(result_array[-1])) #EI KETH WALA PRINT TA IGNORE MAAR 22 | 23 | else: 24 | prime_noe = 0 # DHORENILAM NUMBER TA PRIME 25 | 26 | while True: 27 | 28 | PRIME_SURU += 1 # EKBAR PRIME NO. NA PAWA OBDHI ETA BARTE THAKBE 29 | 30 | for j in range(2,PRIME_SURU): # NORMAL PRIME NO. CHECK KORCHI (2 THEKE SURU KORE .. NUMBER_TA-1 OBDHI CHOLBE) 31 | if PRIME_SURU%j == 0: # JODI ONNO KONO NO. DIYE DIVIDE HOE JAE 32 | prime_noe = 1 # THEN OTA SOTTI E PRIME NOE 33 | break 34 | if prime_noe: 35 | prime_noe = 0 #PRIME NA HOLE.. EI VARIABLE TA ABAR 0 36 | else: 37 | result_array.append(PRIME_SURU) # PEYE GELE .... ARRAY TE DHOKABE 38 | break # INFINITE LOOP SESH 39 | 40 | 41 | #CAUTION : TCS E BHUL INFINTE LOOP CHOLLE PROBLEM HOBE ... MONE ACHE TOH ???????? 42 | 43 | print("PRIME:i=" + str(i) + " VALUE:" + str(result_array[-1])) # EI KETH WALA PRINT TA IGNORE MAAR 44 | 45 | print(result_array) 46 | 47 | #ANY PROBLEM DEER <3 ?.. FEEL FREE TO CALL ME AT 7908653345. -------------------------------------------------------------------------------- /one more wierd game.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m=map(int,input().split()) 3 | print(n*(m-1)+m*(n-1)) -------------------------------------------------------------------------------- /palindrom.py: -------------------------------------------------------------------------------- 1 | s="SORES" 2 | 3 | def pal(st): 4 | l=len(st) 5 | for i in range(int(l/2)): 6 | print(st[i]) 7 | print(st[-(i+1)]) 8 | if st[i]!=st[-(i+1)]: 9 | return 0 10 | return 1 11 | """for _ in range(int(input("ENTER N: "))): 12 | s=[] 13 | print("ENTER 9 STRINGS : ") 14 | for _ in range(9): 15 | s.append(input()) 16 | for v in range(9): 17 | print("SENT: "+str(s[v]),end="......") 18 | t=pal(s[v]) 19 | if t: 20 | print("PALINDROM") 21 | else: 22 | print("NON_PALINDROM")""" 23 | 24 | t=pal(s) 25 | if t: 26 | print("PALINDROM") 27 | else: 28 | print("NON_PALINDROM") -------------------------------------------------------------------------------- /palindroms _in_subsequence.py: -------------------------------------------------------------------------------- 1 | s="SHANKHASHUBHRASAN" 2 | l=len(s) 3 | index=[] 4 | sub_seq=[] 5 | pals=[] 6 | 7 | def pal(st): 8 | l=len(st) 9 | for i in range(int(l/2)): 10 | #print(st[i]) 11 | #print(st[-(i+1)]) 12 | if st[i]!=st[-(i+1)]: 13 | return 0 14 | return 1 15 | 16 | def formation(s_val ,val_ind): 17 | for j in range(val_ind+1,l): 18 | if [j]>index: 19 | st=s_val+s[j] 20 | index.append(j) 21 | if st in sub_seq or st==s: 22 | return 23 | else: 24 | sub_seq.append(st) 25 | if pal(st): 26 | pals.append(st) 27 | formation(st,j) 28 | 29 | for i in range(l): 30 | index.clear() 31 | index.append(i) 32 | sub_seq.append(s[i]) 33 | formation(s[i],i) 34 | 35 | sub_seq.append(s) 36 | 37 | """for v in range(len(sub_seq)): 38 | print("SENT: " + str(sub_seq[v]), end="......") 39 | t = pal(str(sub_seq[v])) 40 | if t: 41 | pals.append(sub_seq[v]) 42 | print("PALINDROM") 43 | else: 44 | print("NON_PALINDROM")""" 45 | 46 | print("\n\n<<<<<<<>>>>>>>") 47 | for i in pals: 48 | print(i,end=" ") -------------------------------------------------------------------------------- /piece_of_cake.py: -------------------------------------------------------------------------------- 1 | """for _ in range(int(input())): 2 | st=input() 3 | s=set(st) 4 | #print(s) 5 | c=[] 6 | sum=0 7 | for i in s: 8 | c.append(st.count(i)) 9 | c.sort() 10 | for i in range(len(c)-1): 11 | sum+=c[i] 12 | if sum==c[len(c)-1]: 13 | print("YES") 14 | else: 15 | print("NO")""" 16 | try: 17 | import collections 18 | m=int(input()) 19 | while m: 20 | x=input() 21 | l=list(x) 22 | v=len(l) 23 | c=collections.Counter(l) 24 | k=list(c.values()) 25 | u=max(k) 26 | print(u,v) 27 | if u == (v-u): 28 | print("YES") 29 | else: 30 | print("NO") 31 | m-=1 32 | except: 33 | pass 34 | -------------------------------------------------------------------------------- /plotlibfig.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plit 2 | import numpy as np 3 | import seaborn as sns 4 | 5 | x= np.linspace(2,5,11) 6 | y=x**2 7 | 8 | 9 | 10 | fig = plit.figure() 11 | 12 | axes = fig.add_axes([0.1,0.1,0.8,0.8]) 13 | axes.plot(x ,y ,'r--') 14 | axes.set_xlabel('lala') 15 | axes.set_ylabel('haha') 16 | axes.set_title('Title') 17 | 18 | 19 | 20 | fig.savefig("name1.png",dpi = 1000) 21 | 22 | fig,axes = plit.subplots(nrows=1,ncols=4) 23 | 24 | for ax in axes: 25 | ax.plot(x,y,'b') 26 | ax.set_xlabel('X') 27 | ax.set_ylabel('Y') 28 | ax.set_title('Fig') 29 | print(fig) 30 | 31 | plit.show(block=True) 32 | -------------------------------------------------------------------------------- /pr.py: -------------------------------------------------------------------------------- 1 | #e=2.71828 2 | """print("--------- ") 3 | print("| | | /\\ |\\ | | / | | /\\") 4 | print("| | | / \\ | \\ | | / | | / \\") 5 | print("| | | / \\ | \\ | | / | | / \\") 6 | print("--------- |___________| / \\ | \\ | | / |__________| / \\") 7 | print(" | | | /________\\ | \\ | |/ | | /________\\") 8 | print(" | | | / \\ | \\ | | \\ | | / \\") 9 | print(" | | | / \\ | \\ | | \\ | | / \\") 10 | print("--------- | | / \\ | \\| | \\ | | / \\") 11 | 12 | print("\n\n") 13 | 14 | print(2%1) 15 | print(4%1) 16 | print(6%1) 17 | u=8 18 | f=[] 19 | for _ in range(u): 20 | f.append([]) 21 | f[1].append(4) 22 | print(f) 23 | for i in range(1,5): 24 | f[i-1].append(i) 25 | print(f)""" 26 | 27 | x=40 28 | y=35 29 | z=20 30 | w=10 31 | 32 | #BODMAS RULE: 33 | 34 | print("y/z: "+str(y/z)) # AAGE DIVISION 35 | print("x*y/z: "+str(x*y/z)) #THEN MULTIPLICATION 36 | print("x*y/z-w: "+str(x*y/z-w)) # LAST SUBSTRACTION 37 | print("RESULT: "+str(x*y/z-w)) # RESULT 38 | 39 | print() 40 | 41 | print("z-w: "+str(z-w)) # AAGE BRACKET 42 | print("y/(z-w): "+str(y/(z-w))) #THEN DIVIDE 43 | print("x*y/(z-w): "+str(x*y/(z-w))) #THEN MULTI. 44 | print("RESULT: "+str(x*y/(z-w))) #RESULT 45 | 46 | print("DIFFERENCE: "+str( (x*y/(z-w) - (x*y/z-w) ))) -------------------------------------------------------------------------------- /practise1.py: -------------------------------------------------------------------------------- 1 | x=0 2 | t=int(input()) 3 | while t!=0: 4 | s=input() 5 | s+=" " 6 | st = "" 7 | c=0 8 | for i in s: 9 | if i!=' ': 10 | st+=i 11 | else: 12 | if st=="not": 13 | print("Real Fancy") 14 | c+=1 15 | break 16 | st="" 17 | if c==0: 18 | print("regularly fancy") 19 | t-=1 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /practise2.py: -------------------------------------------------------------------------------- 1 | t=int(input()) 2 | while t!=0: 3 | c=0 4 | x=input().strip().split() 5 | for i in x: 6 | if i=="not": 7 | print("Real Fancy") 8 | c+=1 9 | break 10 | if c==0: 11 | print("regularly fancy") 12 | t-=1 -------------------------------------------------------------------------------- /practise3.py: -------------------------------------------------------------------------------- 1 | t=list(map(int,input().strip().split())) 2 | while t[0]!=0: 3 | x=input().strip().split() 4 | if "not" in x: 5 | print("Real Fancy") 6 | else: 7 | print("regularly fancy") 8 | t[0]-=1 -------------------------------------------------------------------------------- /scratch.py: -------------------------------------------------------------------------------- 1 | a="12345678" 2 | b=[] 3 | st="" 4 | l=len(a) 5 | lim=-1 6 | print(l) 7 | for i in range(l): 8 | lim=i 9 | print("\n\n"+str(i+1)+"\n") 10 | print(str(a[i])) 11 | if a[i] not in b: 12 | b.append(str(a[i])) 13 | while lim>>>>>>>>") 31 | else: 32 | print("<<<<<<<>>>>>>>>") -------------------------------------------------------------------------------- /scratch_1.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | first = pd.Series([1,2,3,4,5]) 3 | sse -------------------------------------------------------------------------------- /similar dishes.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s1=[x for x in input().split()] 3 | s2=[x for x in input().split()] 4 | if len(set.intersection(set(s1),set(s2)))>=2: 5 | print("similar") 6 | else: 7 | print("dissimilar") -------------------------------------------------------------------------------- /sincosmatplotlib.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | 4 | x=np.arange(0,4*np.pi,0.1) 5 | y=np.sin(x) 6 | z=np.cos(x) 7 | 8 | fig = plt.figure() 9 | 10 | axes = fig.add_axes([0.5,0.5,0.1,0.1]) 11 | 12 | axes.plot(x,y,'r') 13 | axes.plot(x,z,'b') 14 | axes.set_xlabel('x') 15 | axes.set_ylabel('y') 16 | axes.set_title('fig1') 17 | """axes.legend(['sin(x)','cos(x)'])""" 18 | 19 | plt.show(block=True) -------------------------------------------------------------------------------- /snake procession.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | l=int(input()) 3 | s=input().upper() 4 | s=s.replace('.','') 5 | print("Valid"*bool(2*s.count("HT")==len(s))+"Invalid"*bool(2*s.count("HT")!=len(s))) 6 | -------------------------------------------------------------------------------- /snake_mongoose_hijibiji.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s =input() 3 | s+=" " 4 | s=list(s) 5 | sc=mc=0 6 | for i in range(len(s)): 7 | if s[i]=='s': 8 | if s[i+1]!='m': 9 | sc+=1 10 | else: 11 | mc+=1 12 | s[i+1]='*' 13 | if s[i]=='m': 14 | mc+=1 15 | if s[i+1]=='s': 16 | s[i+1]='*' 17 | if mc==sc: 18 | print("tie") 19 | elif mc>sc: 20 | print("mongooses") 21 | else: 22 | print("snakes")#hissss 23 | 24 | -------------------------------------------------------------------------------- /subsequence.py: -------------------------------------------------------------------------------- 1 | import time 2 | start=time.time() 3 | s="1073741824" 4 | l=len(s) 5 | index=[] 6 | sub_seq=[] 7 | 8 | def pal(st): 9 | le=len(st) 10 | for j in range(int(le/2)): 11 | #print(st[j]) 12 | #print(st[-(j+1)]) 13 | if st[j]!=st[-(j+1)]: 14 | return 0 15 | return 1 16 | 17 | 18 | 19 | def formation(s_val ,val_ind): 20 | for j in range(val_ind+1,l): 21 | if [j]>index: 22 | st=s_val+s[j] 23 | index.append(j) 24 | if st in sub_seq or st==s: 25 | return 26 | else: 27 | sub_seq.append(st) 28 | formation(st,j) 29 | 30 | 31 | for i in range(l): 32 | index.clear() 33 | index.append(i) 34 | sub_seq.append(s[i]) 35 | formation(s[i],i) 36 | 37 | sub_seq.append(s) 38 | print(sub_seq) 39 | 40 | print("\n<<<>>>") 41 | for i in sub_seq: 42 | t=pal(i) 43 | if t: 44 | print(i) 45 | end=time.time() 46 | print(end-start) -------------------------------------------------------------------------------- /tests_for_subsequence.py: -------------------------------------------------------------------------------- 1 | a=[1,2,3,5,4] 2 | """b=[1,2,3,4,5] 3 | 4 | print([0]>b) 5 | print(a) 6 | a.clear() 7 | print(a) 8 | 9 | print([0]>a) 10 | 11 | b.pop() 12 | b.pop(1) 13 | b.pop(0) 14 | print(b)""" 15 | 16 | for j in range(90,len(a)): 17 | print("HAHA>>.") 18 | print("<>") -------------------------------------------------------------------------------- /who dares to be a millionare.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s1=list(input().upper()) 4 | s2=list(input().upper()) 5 | w=[int(x) for x in input().split()] 6 | c=0 7 | uc=0 8 | for i in range(n): 9 | if s1[i]==s2[i]: 10 | c+=1 11 | if c==0 or len(set(w))==1: 12 | print(w[0]) 13 | continue 14 | elif c==n: 15 | print(w[n]) 16 | continue 17 | else: 18 | print(max(w[:c+1])) -------------------------------------------------------------------------------- /xenny_and_alternating_tasks.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | min1=min2=0 4 | X = list(map(int, input().split())) 5 | Y = list(map(int, input().split())) 6 | for i in range(n): 7 | if i%2==0: 8 | min1+=X[i] 9 | min2+=Y[i] 10 | else: 11 | min1+=Y[i] 12 | min2+=X[i] 13 | if min1<=min2: 14 | print(str(min1)) 15 | else: 16 | print(str(min2)) 17 | --------------------------------------------------------------------------------