├── scratch_1.py ├── decrement or invcrement.py ├── Sum OR Difference.py ├── name1.png ├── chef and his students.py ├── Cut the Board.py ├── Strike or Spare.py ├── Is it a VOWEL or CONSONANT.py ├── one more wierd game.py ├── Turbo Sort.py ├── The Deadly Sin.py ├── how many digits do i have.py ├── A good set.py ├── Chef and An Ideal Problem.py ├── Minimum Maximum.py ├── chef and majical jars.py ├── find the maximum value.py ├── GCD and LCM.py ├── IPL and RCB.py ├── Total Expenses.py ├── Puppy and Sum.py ├── The Smallest Pair.py ├── Array got some moves.py ├── Chef and Bored Games.py ├── Chef_Detective.py ├── Devu and friendship testing.py ├── Digit Longest Increasing Subsequences 2.py ├── Farmer And His Plot.py ├── ATM.py ├── Two Numbers.py ├── Chef and Fruits.py ├── Xor Again.py ├── chef and chocolate.py ├── Ada School.py ├── Chef and Difficult Contests.py ├── Mahasena.py ├── Chef and Balls.py ├── Chef and Serves.py ├── Chef and digits of a number.py ├── Two vs Ten.py ├── chef and secret ingredients.py ├── chef_and_employement test.py ├── Chef And Coloring.py ├── Chef and Interactive Contests.py ├── Chef and SnackDown.py ├── Greedy puppy.py ├── chang_bitwiseOR.py ├── Candy Love.py ├── Judging Delay.py ├── Uniform Strings.py ├── Fit Squares in Triangle.py ├── Id and Ship.py ├── Roots of a Quadratic Equation.py ├── Naive Chef.py ├── Magic Set.py ├── Whats in the name.py ├── snake procession.py ├── Coins And Triangle.py ├── Strange Operations.py ├── practise3.py ├── Maximise the Sum.py ├── Rectangle.py ├── Simple Statistics.py ├── nothing in common.py ├── Chef and His Apartment Dues.py ├── Chef and Secret Ingredient.py ├── Play Piano.py ├── Program Your Own CALCULATOR.py ├── Chef and Friends.py ├── from heaven to earth.py ├── DEvu and an array.py ├── Lazy Jem.py ├── Version Control System.py ├── gregorian calender.py ├── Chef and Polygon Cakes.py ├── Tweedle-Dee and Tweedle-Dum.py ├── similar dishes.py ├── Ada and the Staircase.py ├── Chef and his Sequence.py ├── The Great Run.py ├── Train Partner.py ├── Gross Salary.py ├── Bear_and_segment01.py ├── Chef and Dolls.py ├── andrash and stipendiium.py ├── Akhil_and_coloredBalls.py ├── K Fibonnaci.py ├── Palindromic substrings.py ├── Studying Alphabet.py ├── Subsequence Equality.py ├── bear and ladder.py ├── Help Lost Robot!.py ├── Malvika is peculiar about color of balloons.py ├── Smart Strategy.py ├── practise2.py ├── Average Number.py ├── Chef and Sequence.py ├── A Big Sale.py ├── Chef and Eid.py ├── Minimum Deletions.py ├── Quentin Tarantino.py ├── chef and party.py ├── tests_for_subsequence.py ├── Buggy calculator.py ├── Game of chef.py ├── Survive in ChocoLand.py ├── Kitchen Timetable.py ├── Magician versus Chef.py ├── Secret Recipe.py ├── Bear and Candies 123.py ├── loop_test.py ├── Pogo Stick Competition.py ├── importantINPUT_TEST.py ├── Count Subarrays.py ├── XOR N-bonacci Sequence.py ├── chef_and_movie.py ├── Testing Robot.py ├── mantison_and _pangrams.py ├── Appy and contest.py ├── Download file.py ├── Cats and Dogs.py ├── Chef and the Wildcard Matching.py ├── little chef and sums.py ├── Chef and Subarrays.py ├── Is it a Cakewalk Problem.py ├── Maximum Remaining.py ├── Tanu and Head-bob.py ├── common.py ├── Buying new tablet.py ├── Bob and his strict mom.py ├── Valid Stack Operations.py ├── Chef and Inequality.py ├── Chef and Two Strings.py ├── ATM_Machine.py ├── Chef and Number Game.py ├── Three Friends.py ├── ATM cdvta.py ├── A_Balanced_contest.py ├── Area or perimeter.py ├── Coder Life Matters.py ├── The Tricky Deal.py ├── Camp Or Not.py ├── Chef Judges a Competition.py ├── Task for Alexey.py ├── ada_and_crayons.py ├── Brackets.py ├── Archi and Comparsion.py ├── Tickets.py ├── Life Limited.py ├── README.md ├── Random Pair.py ├── sincosmatplotlib.py ├── Grade The Steel.py ├── Sebi and the highway.py ├── Good and Bad Persons.py ├── Collisions.py ├── Movie Weekend.py ├── Chef and Cook-Off Contests.py ├── Cops and the Thief Devu.py ├── xenny_and_alternating_tasks.py ├── Chef and a Beautiful Digit.py ├── Entrance Exam.py ├── Encoding Message.py ├── Forgotten Language.py ├── practise1.py ├── Football Match.py ├── who dares to be a millionare.py ├── Friend or Girlfriend.py ├── Sticks.py ├── Chef_and_his_dailyRoutine.py ├── Rupsa and the Game.py ├── Workers.py ├── Days in Month.py ├── Temple Land.py ├── Yet Again a Subarray Problem.py ├── Coinscdvta.py ├── Villages and Tribes.py ├── Deputy Chef.py ├── Extreme Encoding.py ├── Print Pattern.py ├── chef_and_icecream.py ├── Jumping in the hills.py ├── Chef And His Characters.py ├── snake_mongoose_hijibiji.py ├── Chef and Glove.py ├── bear_and_milky_cookies.py ├── Dada Ques.py ├── Rooks.py ├── Sums in a Triangle.py ├── PERMUTATION_OF_STRING.py ├── Trace of Matrix.py ├── plotlibfig.py ├── Alternating subarray prefix.py ├── Chef and Game with Sequence.py ├── chef_and_text.py ├── Fibonacci String.py ├── Devu and Grapes.py ├── Fencing.py ├── palindrom.py ├── Split Stones.py ├── chef and table tennis.py ├── cdvta_prac.py ├── chef and cookoff.py ├── piece_of_cake.py ├── Ordering teams.py ├── scratch.py ├── D - Triangle Count.py ├── Coupon System.py ├── NightsWatch.py ├── J - Reached Safely Or Not.py ├── Chef And his Cake.py ├── subsequence.py ├── Chef and String.py ├── Itercdvta.py ├── Chef and Way.py ├── Lucky number game.py ├── Good Joke!.py ├── palindroms _in_subsequence.py ├── chef and secret password.py ├── Subtree Removal.py ├── Art of balance.py ├── art of balance3.py ├── pr.py ├── Chef got Recipes.py ├── ATcdvta.py ├── art of balance2.py ├── oDD EVEN FIBO PRIME.py └── Ada King.py /scratch_1.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | first = pd.Series([1,2,3,4,5]) 3 | sse -------------------------------------------------------------------------------- /decrement or invcrement.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | print((n+1)*(n%4==0)+(n-1)*(n%4!=0)) 3 | 4 | -------------------------------------------------------------------------------- /Sum OR Difference.py: -------------------------------------------------------------------------------- 1 | n1,n2=int(input()),int(input()) 2 | print((n1-n2)*(n1>n2)+(n1+n2)*(n1<=n2)) -------------------------------------------------------------------------------- /name1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S-C-U-B-E/CodeChef-Practise-Beginner-Python/HEAD/name1.png -------------------------------------------------------------------------------- /chef and his students.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | s=input() 3 | print(s.count("<>")) -------------------------------------------------------------------------------- /Cut the Board.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m=map(int,input().split()) 3 | print((n-1)*(m-1)) -------------------------------------------------------------------------------- /Strike or Spare.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | print(1,n**(2**(n-1)-(n-1))) 4 | -------------------------------------------------------------------------------- /Is it a VOWEL or CONSONANT.py: -------------------------------------------------------------------------------- 1 | c=input().upper() 2 | print("Vowel"*bool(c in "AEIOU")+"Consonant"*bool(c not in "AEIOU")) -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /The Deadly Sin.py: -------------------------------------------------------------------------------- 1 | import math as ma 2 | for _ in range(int(input())): 3 | x,y=map(int,input().split()) 4 | print(2*ma.gcd(x,y)) -------------------------------------------------------------------------------- /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]) -------------------------------------------------------------------------------- /A good set.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | for i in range(n): 4 | print(500-i,end=" ") 5 | print() -------------------------------------------------------------------------------- /Chef and An Ideal Problem.py: -------------------------------------------------------------------------------- 1 | print(1) 2 | y=int(input()) 3 | if y==2: 4 | print(3) 5 | else: 6 | print(2) 7 | #LOL..don't knw wtf im doin ;_; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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))) -------------------------------------------------------------------------------- /IPL and RCB.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | x,y=map(int,input().split()) 3 | p=x-y 4 | if p>0: 5 | print(p) 6 | else:print(0) -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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]) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Chef and Bored Games.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=0 4 | for i in range(1,n+1,2): 5 | s+=(n-i+1)**2 6 | print(s) -------------------------------------------------------------------------------- /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=" ") -------------------------------------------------------------------------------- /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='') -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ATM.py: -------------------------------------------------------------------------------- 1 | x,y=input().split() 2 | x=int(x) 3 | y=float(y) 4 | 5 | if x%5==0: 6 | if y-x-0.5>=0: 7 | y-=(0.5+x) 8 | y="{0:.2f}".format(y) 9 | print(y) 10 | -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /Chef and Fruits.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,o,k=map(int,input().split()) 3 | if abs(a-o)<=k: 4 | print(0) 5 | else: 6 | print(abs(a-o)-k) -------------------------------------------------------------------------------- /Xor Again.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | s=0 5 | for i in a: 6 | s^=(2*i) 7 | print(s) -------------------------------------------------------------------------------- /chef and chocolate.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,m=map(int,input().split()) 3 | if abs(n*m)%2==0: 4 | print("Yes") 5 | else: 6 | print("No") -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /Chef and Difficult Contests.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b=map(int,input().split()) 3 | print("YES") 4 | #shame_on_me 5 | #WTF..this is the ansr.. m cryn ;; -------------------------------------------------------------------------------- /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))) -------------------------------------------------------------------------------- /Chef and Balls.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | b,p=map(int,input().split()) 3 | if b

maxc: 6 | maxc=n%i 7 | print(maxc) 8 | -------------------------------------------------------------------------------- /chang_bitwiseOR.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | cost=0 3 | n=int(input()) 4 | A=[int(x) for x in input().split()] 5 | for i in range(n): 6 | cost |=A[i] 7 | print(cost) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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')) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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()) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Simple Statistics.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | a=[int(x)for x in input().split()] 4 | a.sort() 5 | if k==0:print(sum(a)/n) 6 | else: print( sum(a[k:-k])/(n-(2*k)) ) 7 | -------------------------------------------------------------------------------- /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)))) -------------------------------------------------------------------------------- /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 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") -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /Chef and Friends.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | count=0 3 | for _ in range(n): 4 | u=input().lower() 5 | s=['ch','ef','he'] 6 | for i in s: 7 | if i in u: 8 | count+=1 9 | break 10 | print(count) 11 | -------------------------------------------------------------------------------- /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))) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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))) -------------------------------------------------------------------------------- /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)]) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /The Great Run.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | maxi=0 5 | for i in range(n-k+1): 6 | if sum(a[i:i+k])>maxi: 7 | maxi=sum(a[i:i+k]) 8 | print(maxi) -------------------------------------------------------------------------------- /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='') -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Chef and Dolls.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[] 4 | for i in range(n): 5 | a.append(int(input())) 6 | s=set(a) 7 | for i in s: 8 | if a.count(i)%2!=0: 9 | print(i) 10 | break 11 | -------------------------------------------------------------------------------- /andrash and stipendiium.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | s=set(a) 5 | if (2 not in s) and (5 in s): 6 | if sum(a)/n>=4.0:print("Yes") 7 | else:print("No") 8 | else:print("No") 9 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /bear and ladder.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b=[int(x) for x in input().split()] 3 | if abs(b - a) == 1 and min(a,b)%2==1: 4 | print("YES") 5 | elif abs(b - a) == 2: 6 | print("YES") 7 | else: 8 | print("NO") 9 | 10 | -------------------------------------------------------------------------------- /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(x2s.count('b'): 5 | print(s.count('b')) 6 | else: 7 | print(s.count('a')) 8 | else: 9 | print(0) -------------------------------------------------------------------------------- /Smart Strategy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | for _ in range(int(input())): 3 | n,q=map(int,input().split()) 4 | d=[int(x) for x in input().split()] 5 | x=[int(x) for x in input().split()] 6 | mul=np.prod(d) 7 | for i in x: 8 | print(str(i//mul),end=' ') 9 | print() -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /Average Number.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k,v=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | tot=(n+k)*v-sum(a) 5 | ele=tot/k 6 | ele2=tot//k 7 | if ele==ele2 and ele>=1: 8 | print(ele2) 9 | else: 10 | print(-1) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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=a[i]: 9 | sumy+=1 10 | joined+=1 11 | print(joined) -------------------------------------------------------------------------------- /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("<>") -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /Secret Recipe.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | x1,x2,x3,v1,v2=map(int,input().split()) 3 | dx1=abs(x3-x1) 4 | dx2 = abs(x3 - x2) 5 | t1,t2=dx1/v1,dx2/v2 6 | if t1 a: 10 | print("Bob") 11 | elif bo > b: 12 | print("Limak") -------------------------------------------------------------------------------- /loop_test.py: -------------------------------------------------------------------------------- 1 | t=int(input()) 2 | for i in range(t): 3 | print(i) 4 | print(i*2) 5 | 6 | while True: 7 | print("inside while") 8 | print (i) 9 | i+=1 10 | print(' ') 11 | #if i==10: 12 | #break 13 | print("<<<<<<<<........END...........>>>>>>>>") -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 j=k: 9 | print("Win") 10 | else: 11 | print("Lose") 12 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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 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 | -------------------------------------------------------------------------------- /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=60: 10 | print("yes") 11 | else: 12 | print('no') -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /ATM cdvta.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 | nthsnd=int(w/1000) 9 | rem=w-1000*nthsnd 10 | 11 | nfh=int(rem/500) 12 | rem=rem-nfh*500 13 | 14 | nth=int(rem/200) 15 | rem=rem-nth*200 16 | 17 | nh=int(rem/100) 18 | 19 | if h*100+fh*500+th*200+thsnd*1000=(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 **** -------------------------------------------------------------------------------- /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') -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /Chef Judges a Competition.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 | a.sort() 6 | b.sort() 7 | asu=sum(a[0:n-1]) 8 | bsu=sum(b[0:n-1]) 9 | if asuabs(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) -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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') -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeChef-Practise-Beginner-Python 2 | A short list of Python codes solutions from Codechef/Practice/Beginner. Questions -> (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))) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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 fatherdiffk: 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Chef and Cook-Off Contests.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | mydik = {"cakewalk": 0, "easy": 0, "simple": 0, "easy-medium": 0, "medium": 0, "medium-hard": 0, "hard": 0} 4 | for _ in range(n): 5 | mydik[input()]+=1 6 | if mydik["cakewalk"] and mydik["easy"] and mydik["simple"] and (mydik["easy-medium"]+mydik["medium"]) and (mydik["medium-hard"]+mydik["hard"]): 7 | print("Yes") 8 | else: 9 | print("No") -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Chef and a Beautiful Digit.py: -------------------------------------------------------------------------------- 1 | def operation(st,pos,di): 2 | st=st.replace(st[pos],'',1) 3 | st+=di 4 | return st 5 | 6 | for _ in range(int(input())): 7 | n,d=input().split() 8 | i=len(n)-1 9 | if n[-1]>d: 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) -------------------------------------------------------------------------------- /Entrance Exam.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,k,e,m=map(int,input().split()) 3 | a=[] 4 | for _ in range(n-1): 5 | temp=[int(x) for x in input().split()] 6 | a.append(sum(temp)) 7 | a.sort() 8 | a.reverse() 9 | s=[int(x) for x in input().split()] 10 | ssu=sum(s) 11 | t=a[k-1]+1 12 | r=t-ssu 13 | if r<=0: 14 | print(0) 15 | elif r0)+"NO"*bool(mydik[i]==0),end=' ') 15 | print() -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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])) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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 -_- -------------------------------------------------------------------------------- /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]=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]) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /Deputy Chef.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | a=[int(x) for x in input().split()] 4 | d=[int(x) for x in input().split()] 5 | s=-1 6 | for i in range(n): 7 | if i==0: 8 | if d[i]>a[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) -------------------------------------------------------------------------------- /Extreme Encoding.py: -------------------------------------------------------------------------------- 1 | for j in range(int(input())): 2 | n=int(input()) 3 | a,b=[],[] 4 | for i in range(n): 5 | u=int(input()) 6 | a.append(u&0xfff) 7 | b.append(u>>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)""" -------------------------------------------------------------------------------- /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]))) -------------------------------------------------------------------------------- /chef_and_icecream.py: -------------------------------------------------------------------------------- 1 | b=[0,1,3] 2 | 3 | def count(a): 4 | if a=h[i]: 15 | if h[i+1]-h[i]<=u: 16 | i+=1 17 | else: 18 | break 19 | 20 | print(i+1) -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /bear_and_milky_cookies.py: -------------------------------------------------------------------------------- 1 | """for _ in range(int(input())): 2 | n=int(input()) 3 | s=input() 4 | #print(''.join(list(reversed(s[-1:len(s)-7:-1])))) 5 | if ("milk" in s or "cookie milk" in s) and ("cookie cookie" not in s) and ''.join(list(reversed(s[-1:len(s)-7:-1])))!="cookie" : 6 | print("YES")#shortest_code <3 7 | else: 8 | print("NO")#LOL""" 9 | for x in range(int(input())): 10 | n = input() 11 | k = input() 12 | if ('cookie cookie' in k) or k[-6:]=="cookie": 13 | #print(k[-6:]) 14 | print('NO') 15 | else: 16 | print('YES') 17 | -------------------------------------------------------------------------------- /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 c0: 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 j2: 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_text.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | s=list(input()) 4 | #st="" 5 | for i in range(len(s)): 6 | #a-m n-z 7 | #0-4 5-9 8 | c=ord(s[i]) 9 | if c>=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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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)""" -------------------------------------------------------------------------------- /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." -------------------------------------------------------------------------------- /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") -------------------------------------------------------------------------------- /Split Stones.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | a,b,c,x,y=map(int,input().split()) 3 | possible=0 4 | if x>=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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /cdvta_prac.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n,x,y=map(int,input().split()) 3 | a=[int(x) for x in input().split()] 4 | b=[int(x) for x in input().split()] 5 | d,c=[],[] 6 | for i in range(n): 7 | if a[i]>b[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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Ordering teams.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | p=[] 3 | 4 | for i in range(3): 5 | p.append(list(map(int,input().split()))) 6 | temp1,gd=[],0 7 | for i in range(2): 8 | for j in p: 9 | temp1 = p.copy() 10 | temp1.remove(j) 11 | c,eq=0,0 12 | for k in temp1: 13 | for q in range(3): 14 | if j[q]>k[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") -------------------------------------------------------------------------------- /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("<<<<<<<>>>>>>>>") -------------------------------------------------------------------------------- /D - Triangle Count.py: -------------------------------------------------------------------------------- 1 | for z in range(int(input())): 2 | l,k=map(int,input().split()) 3 | s=0 4 | if k>l: 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 | -------------------------------------------------------------------------------- /Coupon System.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n=int(input()) 3 | ci1, di1 = 0, 0 4 | ci2, di2 = 0, 0 5 | ci3, di3 = 0, 0 6 | for i in range(n): 7 | c,l,x=map(int,input().split()) 8 | if l==1: 9 | if x>di1: 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 cm 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") -------------------------------------------------------------------------------- /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 redindex: 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) -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 jindex: 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=" ") -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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))""" -------------------------------------------------------------------------------- /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(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 | -------------------------------------------------------------------------------- /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 avg0 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) --------------------------------------------------------------------------------