problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximu...
3
def vk(S): ans = 0 for i in range(1, len(S)): if S[i-1] == 'V' and S[i] == 'K': ans += 1 return ans S = list(input()) cur = vk(S) for i in range(len(S)): tem = S[i] S[i] = 'V' cur = max(cur, vk(S)) S[i] = tem for i in range(len(S)): tem = S[i] S[i] =...
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes d...
3
N = int(input()) T = list(map(int, input().split())) M = int(input()) S = sum(T) for _ in range(M): P, X = map(int, input().split()) print(S-T[P-1]+X)
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β€” an excerpt from contest rules. A total of n participants took part in the contest (n β‰₯ k), and you already know their scores. Calculate how many ...
3
n = input().split() k = int(n[1]) t = [int(x) for x in input().split()] l = [x for x in t if x >= t[k-1] and x > 0] print(len(l))
The letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop. Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string s. There are m friends, the i-th of them is named t_i. Eac...
1
n=input() s=raw_input() m=input() l3=[[] for i in range(26)] for i in range(n): l3[ord(s[i])-97].append(i) for t in range(m): f=raw_input() ans=0 l=[0 for i in range(26)] for i in f: ans=max(ans,l3[ord(i)-97][l[ord(i)-97]]) l[ord(i)-97]+=1 print ans+1
There are two rival donut shops. The first shop sells donuts at retail: each donut costs a dollars. The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them ...
3
test = int(input()) for _ in range(test): a,b,c = map(int, input().split()) if a<c: print(1, end=' ') else: print(-1, end=' ') if a*b>c: print(b) else: print(-1)
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
3
n = int(input()) lis = sorted(map(int,input().split())) a=lis[-1] ans=0 for i in lis: ans+=(a-i) print(ans)
N friends of Takahashi has come to a theme park. To ride the most popular roller coaster in the park, you must be at least K centimeters tall. The i-th friend is h_i centimeters tall. How many of the Takahashi's friends can ride the roller coaster? Constraints * 1 \le N \le 10^5 * 1 \le K \le 500 * 1 \le h_i \le 5...
3
#!/usr/bin/env python3 n,k,*h=map(int,open(0).read().split()) print(sum(i>=k for i in h))
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should cont...
3
n,m = list(map(int, input().split() ) ) for i in range(m): k=input() if n%2==0: print('01'*(n//2)) else: print('01'*(n//2)+ '0')
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
n1=int(input()) arr=list(map(int,input().split())) print(sum(arr)/(n1))
Given are integers A, B, and N. Find the maximum possible value of floor(Ax/B) - A Γ— floor(x/B) for a non-negative integer x not greater than N. Here floor(t) denotes the greatest integer not greater than the real number t. Constraints * 1 ≀ A ≀ 10^{6} * 1 ≀ B ≀ 10^{12} * 1 ≀ N ≀ 10^{12} * All values in input are i...
1
A, B, N = map(int, raw_input().split()) def f(x): return int(A*x/float(B)) - A * int(x/float(B)) print f(min(N, B - 1))
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
3
n = int(input()) count = 0 assert n>=1 and n<=1000 problems= [] for i in range(n): problems.append(input().replace(" ","")) i = 0 for i in range(n): if int(problems[i][0])+int(problems[i][1])+int(problems[i][2])>=2: count+=1 print(count)
Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula: \begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n - 1) + fib(n - 2) & \\\ \end{array} \right. \end{equation*} Constraints ...
3
num = int(input()) arr = [0] * 45 arr[0] = 1 arr[1] = 1 for i in range(2,45): arr[i] = arr[i-1] + arr[i-2] print(arr[num])
Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to spli...
3
from math import * def main(): n=int(input()) if n%2!=0: print(0) else: ans=ceil((n/4)-1) print(ans) main()
You are given an array of n integers: a_1, a_2, …, a_n. Your task is to find some non-zero integer d (-10^3 ≀ d ≀ 10^3) such that, after each number in the array is divided by d, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least ⌈n/2βŒ‰). Not...
3
R = lambda: map(int, input().split()) n = int(input()) L = list(R()) p,ne = 0,0 for i in L: if i > 0: p += 1 elif i < 0: ne += 1 h = (n+1)//2 if p >= ne and p >= h: print(1) elif p < ne and ne >= h: print(-1) else: print(0)
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
3
def sint(): return (int(input())) def sints(): return (map(int, input().split())) def sara(): return (list(map(int,input().split()))) def sstr(): s = input() return (list(s[:len(s)])) def main(): n, x, y = sints() s = input() cnt = 0 for i in range(n-1, n-x-1, -1): ...
You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≀ x ≀ a) coins of value n and y (0 ≀ y ≀ b) coins of value 1, then the total value of taken coins will be S. You have to answer q independent test cases. Input The...
3
import random def get_many_ints(): return map(int, input().split()) def get_int(): return int(input()) def get_int_list(): return list(get_many_ints) def prog(): a, b, n, S = get_many_ints() a -= S // n b -= S % n b -= max(0, -a) * n print("NO" if b < 0 else "YES") q = get_int(...
Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known who was the winner β€” Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input The first line of the input contains a...
3
n = int(input()) s = input() anton = 0 danik = 0 for i in range(0, n): if s[i] == 'A': anton += 1 else: danik += 1 if anton > danik: print('Anton') elif danik > anton: print('Danik') else: print('Friendship')
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots...
3
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase import heapq MOD = 10 ** 5 + 1 def main(): n,k = map(int,input().split()) a = list(map(int,input().split())) target = max((sum(a) + (k - 1)) // k - 100,1) cost = [] currentSplit = [] currentCost = [] for elem in a: ...
You are given two n Γ— m matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly...
3
#import numpy as np def main(): n, m = list(map(int, input().split())) l1 = [[0] * m for index in range(n)] l2 = [[0] * m for index in range(n)] for i in range(0, n): l1[i] = list(map(int, input().split())) for i in range(0, n): l2[i] = list(map(int, input().split())) #print(l1, l2) for i in range(0, n): ...
Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any city can reach any other city traveling by these roads. Cities a...
3
import sys import math,bisect sys.setrecursionlimit(10 ** 5) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict I = lambda : int(sys.stdin.readline()) neo = lambda : map(int, sys.stdin.readline().split()) Neo = lambda : list(map(int, sys...
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches th...
3
def ut(s1, s2): for c1, c2 in zip(s1, s2): if c1 >= c2: return 'NO' return 'YES' n = int(input()) s = input() s1, s2 = sorted(s[:len(s) // 2]), sorted(s[len(s) // 2:]) print(ut(min(s1, s2), max(s1, s2)))
Let's call left cyclic shift of some string t_1 t_2 t_3 ... t_{n - 1} t_n as string t_2 t_3 ... t_{n - 1} t_n t_1. Analogically, let's call right cyclic shift of string t as string t_n t_1 t_2 t_3 ... t_{n - 1}. Let's say string t is good if its left cyclic shift is equal to its right cyclic shift. You are given str...
3
for tc in range(int(input())): S = input() ans = 0 for i in range(10): for j in range(10): c = str(i) l = 0 for k in S: if k == c: l += 1 c = str(i) if c == str(j) else str(j) if l & 1 and i != j: l -= 1 ans = max(ans, l) print (len(S) - ans)
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: * Operation ++ increases the value of variable x by 1. * Operation -- decreases the value of variable x by 1....
3
test_case = int( input() ) result = 0 for t in range( test_case ): string = input() if string == '++X' or string == 'X++': result += 1 # if the string is not '++' then it must be '--' else: result -= 1 print( result )
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy start...
3
#citim datele de intrare forwardStations = input() firstStations = input() lastStation = input() #functia care cauta in string daca o astfel de ordine a caracterelor exista def getDirection(stations): #adaca acest substring exista if firstStations in stations: #cautam indexul lui ...
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
n = int(input()) love = "I love " hate = "I hate " print(hate, end="") for i in range(1,n): print("that ", end="") print(love if i%2 else hate, end="") print("it")
There are n students in a school class, the rating of the i-th student on Codehorses is a_i. You have to form a team consisting of k students (1 ≀ k ≀ n) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then pri...
3
def main(): k, n = map(int, input().split()) arr = list(map(int, input().split())) dict = {} for i, v in enumerate(arr): dict[v] = i + 1 if len(dict.keys()) < n: print("NO") else: print("YES") print(*list(dict.values())[0:n]) if __name__ == "__main__": ma...
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≀ i ≀ N)...
3
n,m=map(int,input().split()) a=[int(i) for i in range(n)] def find(a, x): if a[x] != x: a[x] = find(a, a[x]) return a[x] def unite(a, x, y): x = find(a, x) y = find(a, y) if x != y: a[x] = min(x, y) a[y] = a[x] p=list(int(i)-1 for i in input().split()) pp=p ans=0 #007ζ˜ η”»γ€€4...
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
n=int(input()) Out=[] for i in range(n): s=input() ; a=len(s) if a<=10: Out.append(s) else: Out.append(s[0]+str(len(s)-2)+s[a-1]) for x in Out: print(x)
HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the value stored in the internal accumulator. Instructions "H" and "Q"...
3
str=input() l=0 for i in range(len(str)): if str[i]=='H' or str[i]=='Q' or str[i]=='9': print('YES') break else: l+=1 if l== len(str): print('NO')
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
n = int(input()) hulk_feelings = "" for i in range(1, n + 1): if i % 2 != 0: hulk_feelings += " I hate" else: hulk_feelings += " I love" hulk_feelings += " that" print(hulk_feelings[1:-5] + " it")
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
3
prev=0 count=0 for _ in range(int(input())): curr=int(input()) if prev!=curr: count+=1 prev=curr print(count)
It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, th...
3
n,t=map(int,input().split()) bus=[] x=[] for i in range(n): r=[int(i) for i in input().split()] x.append(r) for nn in range(n): s=int(x[nn][0]) d=int(x[nn][1]) if t<=s: bus.append(s) else: k=int((t-s)/d) if k<(t-s)/d: k+=1 temp=s+(k*d) bus.append(temp) bust=bus[::] bust.sort() # print(bus) # ...
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, l and r (1 ≀ l ≀ r ≀ n), and you should...
3
import copy n = int(input()) a = list(map(int,input().split())) asum = [0] for x in a: asum.append(asum[-1] + x) a.sort() lsum = [0] for x in a: lsum.append(lsum[-1] + x) m = int(input()) for _ in range(m): q,l,r = map(int,input().split()) print(asum[r] -asum[l-1] if q==1 else lsum[r]-lsum[l-1])
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy. Input The only line contains three integers n, a and ...
3
import sys sys.version n, a, b = input('').split() n = int(n) a = int(a) b = int(b) pos = (n-a) if(pos <= b): print (pos) else: print (b+1)
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10). Constraints * 2 ≀ N ≀ 10^5 * N is an integer. Input Input is given from Standard Input in the following format: N Outp...
3
n = sum(map(int, input())) print(10 if n == 1 else n)
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i. You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maxi...
3
# @author Nayara Souza # UFCG - Universidade Federal de Campina Grande # AA - Basico n = int(input()) l = list(map(int, input().split())) l.sort() j = 0 count = 0 for i in range(n): while abs(l[j] - l[i]) > 5: j += 1 count = max(count, i-j) print(count+1)
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
3
n = int(input()) l = list(map(int,input().split())) dic = dict() mini = 101 for e in l: if(e in dic): dic[e]+=1 else: dic[e]=1 print(max(dic.values()))
You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀...
3
import itertools from itertools import combinations def findsubsets(s, n): return list(itertools.combinations(s, n)) def find_indexes_from_elements(a, elements): answer = set() for element in elements: indx = a.index(element) if indx in answer: indx = a.index(element, indx ...
You have a list of numbers from 1 to n written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit). <image> When there are less than ...
3
t = int(input()) for a in range(0,t): x = input() a,b = x.split(" ") a = int(a) b = int(b) print(2*b)
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
3
def Main(): n = int(input()) stones = input() ans = 0 for i in range(n-1): if stones[i] == stones[i+1]: ans+=1 print(ans) if __name__ == "__main__": Main()
See Russian Translation After a long term relationship, Anandi and Jagdish decided to marry. Anandi being a studious girl decided to complete her studies first. What next, she comes to ABC Public School. Her classes haven't even started yet and Jagdish becomes restless, comes to her college and asks her to complete he...
1
import math for _ in range(int(raw_input())): x=int(raw_input()) y=math.sqrt(x)-1 if int(y)==y: print(int(2*y)+1) else: print(int(2*y)+2)
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
3
n=int(input()) xs=0 ys=0 zs=0 x=[0]*n for i in range(n): x[i]=list(map(int,input().split())) for i in range(n): xs=xs+x[i][0] ys=ys+x[i][1] zs=zs+x[i][2] if(xs==ys==zs==0): print("YES") else: print("NO")
Dr .: Peter, I've finally done it. Peter: What's wrong, Dr. David? Is it a silly invention again? Dr .: This table, this table. | Character | Sign --- | --- (Blank) | 101 '| 000000 , | 000011 -| 10010001 . | 010001 ? | 000001 A | 100101 B | 10011010 | Character | Sign --- | --- C | 0101 D | 0001 E | 110 F | 01001 G |...
1
encode = { ' ':'101', "'":'000000', ',':'000011', '-':'10010001', '.':'010001', '?':'000001', 'A':'100101', 'B':'10011010', 'C':'0101', 'D':'0001', 'E':'110', 'F':'01001', 'G':'10011011', 'H':'010000', 'I':'0111', 'J':'10011000', 'K':'0110', 'L':'00100', 'M':'10011001', 'N':'10011110', 'O':'00101', ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
3
n=input() ans="NO" i=0 for a in range(len(n)): if n[a]=="7": ans="YES" elif n[a]=="4": ans="YES" else: ans="NO" break n=int(n) l=[4,7,47,74,447,747,474,774] for a in l: if n%a==0: ans="YES" print (ans)
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the eve...
3
a,b=map(int,input().split()) print(a+(a-1)//(b-1))
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they...
3
n=int(input()) p=2*(n)-1 print(p,2) print(1,2)
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol). For example, as a result of typing the word "hello", the follo...
3
def check(pred, real): lp = len(pred) lr = len(real) ind_p = 0 ind_r = 0 count_p = 0 count_r = 0 char_p = None char_r = None while ind_p < lp: if pred[ind_p] != char_p: if char_p != char_r or count_p > count_r: return 'NO' count_p ...
There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure: * The crow sets ai initially 0. * The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi...
3
n=int(input()) L=[int(x) for x in input().split()] for i in range(1,n): print(L[i]+L[i-1],end=" ") print(L[-1])
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he ...
1
#!/usr/local/bin/python n,m = map(int,raw_input().split(" ")) ary = map(int,raw_input().split(" ")) ary.sort() sumn = 0 for i in xrange(m): if ary[i] <= 0: sumn += ary[i] print abs(sumn)
Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills...
3
def process(S): S1 = sum([int(c) for c in S]) if S1 % 3 != 0: return 'cyan' zeroes = 0 for c in S: if c=='0': zeroes+=1 if zeroes==0: return 'cyan' if zeroes > 1: return 'red' for c in S: if c in '2468': return 'red' return ...
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
3
n = int(input()) k=0 for i in range(n): s = input() s = s.replace(' ', '') if int(s)%100==11 or int(s)//10==11 or(int(s)//100==1 and int(s)%100==1): k+=1 print(k)
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, the second one allows you to convert c grams of lead into d grams of gold a...
1
def doIt(a,b,c,d,e,f): if d == 0 : return 0 if c==0 : return 1 if b==0 : return 0 if a==0 : return 1 if f==0 : return 0 if e==0 : return 1 return a*c*e<b*d*f def doIt2(a): print(a+1) #doIt2(input()) a,b,c,d,e,f=map(int,raw_input().spli...
Your company was appointed to lay new asphalt on the highway of length n. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing. Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are ...
3
import math q=int(input()) #q=1 for _ in range(q): n,g,b=map(int,input().split()) if n<=g: print(n) else: need_good=(math.ceil(n/2)) full_good=(need_good//g) good=full_good*g rem=need_good%g good+=rem #print(good) if rem>0: bad=(fu...
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
3
def send(x): print(x) return x def check(x,y): if x=='a' or x=='A' or x=='e' or x=='E' or x=='i' or x=='I' or \ x=='O' or x=='o' or x=='u' or x=='U' or x=='n' or x=='N': return('OK') else: if y=='a' or y=='A' or y=='e' or y=='E' or y=='i' or \ y=='I' or y=='O' or y=='o'...
This is the easy version of this problem. The only difference is the constraint on k β€” the number of gifts in the offer. In this version: k=2. Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky β€” today the offer "k of goods for the price of one" is held in store...
3
t=int(input()) for _ in range(t): n,p,k=map(int,input().split()) arr=sorted((map(int,input().split()))) a=[0]*(n+k+3) for i in range(n): a[i]=a[i-k]+arr[i] ans=-1 for i in range(n): if a[i]<=p: ans=i print(ans+1)
Theatre Square in the capital city of Berland has a rectangular shape with the size n Γ— m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a Γ— a. What is the least number of flagstones needed to pave the Square? It'...
3
import math l, w, s = map(int, input().split()) l/=s w/=s if l <=1: print(math.ceil(w)) elif w <=1: print(math.ceil(l)) else: print(math.ceil(l) * math.ceil(w))
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from ...
3
import math a,b,n = map(int,input().split()) while(1): k = math.gcd(a,n) if(n-k<0): print(1) exit() n-=k k=math.gcd(b,n) if(n-k<0): print(0) exit() n-=k
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown be...
1
a,b = tuple(map(int,raw_input().split())) print ("Malvika" if min(a,b) % 2 is 0 else "Akshat")
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order ...
3
n = int(input()) steps_len = [1, 2, 3, 4, 5] num_steps = 0 for i in steps_len[::-1]: if n >= i: num_steps += n // i n -= num_steps * i print(num_steps)
Manao has invented a new mathematical term β€” a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all poi...
1
input = map(int, raw_input().split()) n = input[0] m = input[1] minimum = min(n, m) print minimum + 1 for i in xrange(minimum + 1): print "%i %i" % (i, minimum - i)
Boboniu gives you * r red balls, * g green balls, * b blue balls, * w white balls. He allows you to do the following operation as many times as you want: * Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the b...
3
def tc(): r, g, b, w = map(int, input().split()) # all even or one odd is fine, but that's it odd, even = 0, 0 for c in (r, g, b, w): if c % 2: odd += 1 else: even += 1 if even >= 3: print('YES') elif odd >= 3 and all(c > 0 for c in (r, g, b)): ...
Find an n Γ— n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≀ n ≀ 49). Output Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main di...
1
import sys n = int(sys.stdin.readline()) evenIndex = 1 oddIndex = 1 center = (n-1)/2 for i in range(0, n): ret = '' for j in range(0, n): if abs(i-center)+abs(j-center)<=center: ret += str(2*oddIndex-1)+' ' oddIndex += 1 else: ret += str(2*evenIndex)+' ' ...
You have n gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of a_i candies and b_i oranges. During one move, you can choose some gift 1 ≀ i ≀ n and do one of the following operations: * eat exactly...
3
for _ in range(int(input())): n=int(input()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] x=min(a) y=min(b) count=0 for i in range(n): if a[i]==x: if b[i]==y: continue else: count+=b[i]-y elif b[i]==y: if a[i]==x: continue else: count+=a[i]-x else: ...
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
3
n = int(input()) l = [None] * n t = [None] * n for i in range(n): l[i], t[i] = map(int, input().split()) f = False for i in range(n): j = l[i] + t[i] if l.count(j) == 1 and t[l.index(j)] == -t[i]: f = True break if f == True: print('YES') else: print('NO')
You are given an integer N. Consider an infinite N-ary tree as shown below: <image> Figure: an infinite N-ary tree for the case N = 3 As shown in the figure, each vertex is indexed with a unique positive integer, and for every positive integer there is a vertex indexed with it. The root of the tree has the index 1. ...
3
import math N, Q = map(int, input().split()) queries = [] for i in range(Q): v, w = map(int, input().split()) queries.append([v, w]) if N == 1: for v, w in queries: print(min(v, w)) else: for v, w in queries: if 1 in [v, w]: print(1) else: # v < w にする ...
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each...
3
def swap(line,pos): return line[:pos-1]+"GB"+line[pos+1:] num = str(input()) num = [int(j) for j in num.split()] n = num[0] t = num[1] line = str(input()) for _ in range(t): line = line.replace("BG","GB",int(n/2)) print(line)
It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned ...
1
n = int(raw_input()) for _ in xrange(n): a,b = map(int,raw_input().split()) c = map(int,raw_input().split()) d = max(c[0],a-c[-1]+1) for i in xrange(1,b): d = max(d,int((c[i]-c[i-1])/2+1)) print d
We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}. Print the number of elements p_i (1 < i < n) that satisfy the following condition: * p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}. Constraints * All values in input are integers. * 3 \leq n \leq 20 * p...
3
a = int(input()) x = list(map(int,input().split())) s = 0 for i, j , k in zip(x,x[1:],x[2:]): if i < j < k or k < j < i:s+=1 print(s)
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β€” an integer from 1 to 109. At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. Aft...
3
n, k = map(int, input().split()) IDs = list(map(int, input().split())) ans = 0 for i in range(1, n+1) : if i < k : k -= i else : ans = IDs[k-1] break print(ans)
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. Constraints * 1 \leq N...
3
n = int(input()) a = list(map(int,input().split())) b = [bin(i) for i in a] print(min([len(i)-i.rfind("1")-1 for i in b]))
You're given an array a of n integers, such that a_1 + a_2 + β‹…β‹…β‹… + a_n = 0. In one operation, you can choose two different indices i and j (1 ≀ i, j ≀ n), decrement a_i by one and increment a_j by one. If i < j this operation is free, otherwise it costs one coin. How many coins do you have to spend in order to make a...
3
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) pos = 0 neg = 0 for i in range(1, n + 1): if a[-i] > 0: if neg == 0: pos += a[-i] elif neg >= a[-i]: neg -= a[-i] else: pos +...
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: * After the cutting each ribbon piece should have length a, b or c. * After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces ...
1
n,a,b,c = map(int,raw_input().split()) INF = -10**9 dp = [INF for _ in xrange(n+1)] dp[0] = 0 for i in xrange(n+1): for x in [a,b,c]: if i-x >= 0: dp[i] = max(dp[i],dp[i-x]+1) print dp[n]
Chef has a box full of infinite number of identical coins. One day while playing, he made N piles each containing equal number of coins. Chef suddenly remembered an important task and left the room for sometime. While he was away, his newly hired assistant came across the piles and mixed them up while playing. When Che...
1
import collections import sys f = sys.stdin n = int(f.readline().strip()) for i in range(n): m = int(f.readline().strip()) s = f.readline().strip().split(" ") d = collections.defaultdict(int) for j in range(len(s)): d[s[j]] += 1 r = m - max(d.values()) print r
You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0. You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≀ c, d ≀ r_i, and swap a_c and a_d. Calculate the number of indices k such that it is poss...
3
#------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class F...
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d...
3
n = int(input()) def f(n): i = n - 1 while i > 4: i = (i - 5) // 2 arr = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] return arr[i] print(f(n))
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
3
import sys input = sys.stdin.readline n, m = map(int, input().strip().split()) a = [] for _ in range(n): [a.append(char) for char in input().strip().split()] if 'C' in a or 'M' in a or 'Y' in a: print('#Color') else: print('#Black&White')
You are given a bracket sequence s of length n, where n is even (divisible by two). The string s consists of n/2 opening brackets '(' and n/2 closing brackets ')'. In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index i, remov...
3
t = int(input()) for _ in range(t): n = int(input()) S = list(input()) p = 0 i = 0 c = 0 while i < len(S): # print(S,end = " -> ") if S[i] == "(": p += 1 i += 1 else: p -= 1 if p < 0: del S[i] ...
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children. Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time? Constraints * 1 ≀ X ≀ 9 * X is an integer. Input Input is given from...
3
l=[3,5,7] print("YES" if int(input()) in l else "NO" )
You have n students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the i-th student skill is denoted by an integer a_i (different students can have the same skills). So, about the teams. Firstly, these two teams should have the s...
3
import collections t=int(input()) for _ in range(t): n=int(input()) l=list(map(int, input().split())) d=collections.Counter(l) un=0 ma=0 c1=0 for i in d.values(): un=un+1 if i==1: c1=c1+1 if i>ma: ma=i val1=min(un-1,ma) val2=min(un,ma-1...
Acacius is studying strings theory. Today he came with the following problem. You are given a string s of length n consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulti...
3
a="abacaba" def cal(s): c=0 for i in range(len(s)-6): if s[i:i+7]==a: c+=1 return c def mz(s): s=list(s) for i,x in enumerate(s): if x=='?': s[i]='z' return ''.join(s) def pos(s): s1=list(s) n=len(s) i=0 while i<n-7: j=0 while i+j<i+7: if s[i+j]==a[j]: continue elif s[i+j]=='?': s...
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi...
1
# -*- coding: utf-8 -*- from __future__ import print_function def read_int(): return int(raw_input()) def read_int_list(): return map(int, raw_input().split()) import string if __name__ == '__main__': n = read_int() words = [] lens = [] for i in xrange(n): w = raw_input().strip() ...
Bob is playing a game named "Walk on Matrix". In this game, player is given an n Γ— m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}. To reach the goal, position (n,m), player can move right or down, i.e. move from ...
3
k = int(input()) x = 2**17 print(2, 3) print(x^k, k, 0) print(x, x^k, k)
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits. Input The on...
3
print((2 * (2 ** int(input()) - 1)))
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
3
w=int(input()) if (w>=1 and w<=100): if (w==2 or w%2==1): print("NO") if (w!=2 and w%2==0): print("YES") if (w<1 or w>100): print("Please enter a valid number!")
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat. <image> There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ....
3
n=int(input()) menorP=200 total=0 for i in range(n): line=input().split(" ") a, p = int(line[0]), int(line[1]) if p<menorP: menorP=p total+=a*menorP print(total)
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
1
import sys lines = list(sys.stdin) n, k = map(int, lines[0].split()) lines = lines[1:] ans = n - 1 has = [] for line in lines: nums = map(int, line.split()) ans += nums[0] - 1 for i in range(1,nums[0]): if nums[i+1] - nums[i] == 1: has.append(nums[i]) has.sort() for i in range(len(has)): if has[i] == i+1: ...
For some binary string s (i.e. each character s_i is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length 2 were written. For each pair (substring of length 2), the number of '1' (ones) in it was calculated. You are given three numbers: * n_0 β€” th...
3
for _ in range(int(input())): n0, n1, n2 = map(int, input().split()) if not n1: if not n2: print("0" * (n0 + 1)) else: print("1" * (n2 + 1)) else: s0 = "0" * n0 s1 = "1" * n2 s10 = "10" * ((n1 + 1) // 2) + "1" * ((n1 + 1) % 2) ...
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if...
3
jadi = "hello" hasil = "NO" mulai = 0 a = input() for z in range (len(a)): if jadi[mulai] == a[z]: mulai = mulai + 1 if mulai == 5: hasil = "YES" break print(hasil)
Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scroll d pages forwards or backwards (but he cannot scroll outside the book). F...
3
T = int(input()) sol = list() for _ in range (T) : n, x, y, d = map(int, input().split()) ans = 1e18 if abs(y - x) % d == 0: ans = min(ans, abs(y - x) // d) if (n - y) % d == 0: ans = min(ans, abs(n - y) // d + (n - x + d - 1) // d) if (y - 1) % d == 0: ans = min(ans, (y - 1) // d + (x + d - 1) // d) sol....
Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weigh...
3
n = int(input()) lista = [] for i in range(n): coins = int(input()) for j in range(1, coins+1): lista.append(2**j) grupoA = 1 grupoB = somaB = 0 somaA = lista[coins-1] idc = 0 while grupoA < coins//2: somaA += lista[idc] grupoA += 1 idc += 1 while grupoB ...
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
3
n=int(input()) if (n)%2==0 and n!=2: print("yes") else: print("no")
Phoenix is playing with a new puzzle, which consists of n identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below. <image> A puzzle piece The goal of the puzzle is to create a square using the n pieces. He is allowed to rotate and move the pieces around, but none of them can overlap an...
3
import math t = int(input()) for i in range(t): n = int(input()) if n % 2 == 1: print("NO") else: n = n // 2 if n ** 0.5 == math.floor(n**0.5): print("YES") else: if n % 2 != 0: print("NO") else: n = n // 2 if n ** 0.5 == math.floor(n**0.5): pri...
Bob watches TV every day. He always sets the volume of his TV to b. However, today he is angry to find out someone has changed the volume to a. Of course, Bob has a remote control that can change the volume. There are six buttons (-5, -2, -1, +1, +2, +5) on the control, which in one press can either increase or decrea...
3
import sys input = sys.stdin.readline Q = int(input()) Query = [] for _ in range(Q): A, B = map(int, input().split()) Query.append((A, B)) for A, B in Query: delta = abs(B-A) ans = delta//5 am = delta%5 if am == 3 or am == 4: ans += 2 elif am == 1 or am == 2: ans += 1 ...
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x...
3
def solve(arr): arr = sorted(arr) a0 = arr[0] #case 1: arr[-1] = an an = arr[-1] minsub = 1000000000000 for i in range(1, len(arr)//2): minsub = min(arr[i+len(arr)//2-1] - arr[i], minsub) first_case = (an-a0)*minsub #case 2: arr[-1] = bn bn = arr[-1] an = arr[len(arr)/...
You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a...
3
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N = int(input()) P = [int(x) for x in input().split()] L = 2*N+100 A = [None] + [L*i for i in range(1,N+1)] B = [None] + [L*(N+1-i) for i in range(1,N+1)] for i,p in enumerate(P,1): A[p] += i print(' '.join(map(str,A[1:]))) print(' '.join(map...
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat. <image> There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ....
3
n = int(input()) minimo = 101 soma = 0 for i in range(n): a, p = map(int, input().split()) if minimo > p: minimo =p soma += minimo*a print(soma)
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
n = int(input()) lista = [] pomoc = '' tupla_help = () for x in range (0,n): word = input() if len(word)>10: tupla_help = (word) between = len(word) - 2 pomoc = tupla_help[0] + str(between)+ tupla_help[len(word)-1] lista.append(pomoc) else: lista.append(word) for y in...
You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts. Suppose you decided to sell packs with a cans in a pack with a discount and some customer wants to buy x cans of cat food. Then he follows a greedy str...
3
import bisect import math import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) de...
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
n = int(input()) parameter = 0 while n != parameter: if parameter % 2 == 0: print("I hate", end=" ") else: print("I love", end=" ") if parameter + 1 == n: print("it") else: print("that", end=" ") parameter += 1
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: * Tetrahedron. Tetrahedron has 4 triangular faces. * Cube. Cube has 6 square faces. * Octahedron. Octahedron has 8 triangular faces. * Dodecahedron. Dodecahedron has 12 pentagonal faces. *...
3
n=int(input()) i=t=0 while(i<n): s=str(input()) if(s=="Tetrahedron"): t+=4 elif (s == "Cube"): t +=6 elif (s == "Octahedron"): t +=8 elif (s == "Dodecahedron"): t +=12 else: t +=20 i+=1 print(t)