problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
3
str1 = input() str2 = input() str3 = input() str = str1+str2 if len(str) != len(str3): print("NO") exit() else: for c in str: if str.count(c) != str3.count(c): print("NO") exit() print("YES")
Arkady and his friends love playing checkers on an n × n field. The rows and the columns of the field are enumerated from 1 to n. The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an old parable (but not its moral), Arkady wants to give to his friends one set o...
3
'''1dl3''' n, m = map(int, input().split()) s = 0 for i in range(1, m+1): for j in range(1, m+1): if((i**2+j**2) % m == 0): s += ((n-i)//m+1)*((n-j)//m+1) print(s)
You are given a multiset (i. e. a set that can contain multiple equal integers) containing 2n integers. Determine if you can split it into exactly n pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by 2, the remainder is 1). Input The...
3
t = int(input()) for _ in range(t): n = int(input()) cnt = 0 for i in input().split(): if int(i) % 2 == 1: cnt += 1 if cnt == n: print('YES') else: print('NO')
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: 1. on this day the gym is closed and...
3
n = int(input()) info = list(map(int, input().split())) # return the minimum number of rest days starting from today # today = the index of the current day - when we have to make a decision # yActivity = what we actualy did yestarday: # 0 = rest # 1 = computer # 2 = sports # Memoization # 3 X 3 Matrix matrix = [[Fals...
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()) min_meat_cost = float("inf") ans = 0 for i in range(n): duff_meat, meat_cost = list(map(int, input().split())) min_meat_cost = min(min_meat_cost, meat_cost) ans += duff_meat * min_meat_cost print(ans)
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it. ...
3
import math for t in range(int(input())): n=int(input()) x=math.ceil(n/4) st="9"*(n-x)+"8"*x print(st)
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
3
ostanovok = int(input()) mas = [] for i in range(ostanovok): mas.append(input().split()) m_result = [] result = 0 for k in range(len(mas)): result -= int(mas[k][0]) result += int(mas[k][1]) m_result.append(result) m_result.sort() result = m_result[-1] print(result)
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
3
n,h=map(int,input().split()) count=0 l=list(map(int,input().split())) for i in range(n): if l[i]<=h: count+=1 else: count+=2 print(count)
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who in...
3
# -- Hello 2019 # B. Petr and a Combination Lock from sys import stdin n = int(stdin.readline()) xs = [] for _ in range(n): x = int(stdin.readline()) xs.append(x) # -- there are 2**n combinations # the binary for each n-bit integer gives a move sequence # (bit i 0 represents move dial CW by a[i] de...
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n. He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his se...
3
from sys import stdin, stdout def main(): t = int(stdin.readline()) for case in range(t): n = int(stdin.readline()) if n <= 2: stdout.write(str(1) + '\n') else: ans = (n-1)//2+1 stdout.write(str(ans) + '\n') return if __name__ == '__main__'...
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years. There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_1, t_2, t_3, …, t_{m}. ...
3
n, m = map(int, input().split()) s = input() s = s.split(' ') t = input() t = t.split(' ') q= int(input()) lista = [] while q: x = int(input()) lista.append(s[(x-1) % n] + t[(x-1) % m]) q -= 1 for i in lista: print(i)
You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option). For example, if a = [1, 1, ...
3
""" 616C """ """ 1152B """ import math # import sys def check(k,h,c): return ((((k+1)*h)+((k)*c))/((2*k)+1)) def main(): # n ,m= map(int,input().split()) # arr = list(map(int,input().split())) # b = list(map(int,input().split())) # n = int(input()) # string = str(input()) n = int(input()) a = list(map(int,inpu...
On the Planet AtCoder, there are four types of bases: `A`, `C`, `G` and `T`. `A` bonds with `T`, and `C` bonds with `G`. You are given a letter b as input, which is `A`, `C`, `G` or `T`. Write a program that prints the letter representing the base that bonds with the base b. Constraints * b is one of the letters `A`...
1
# A - Double Helix # https://atcoder.jp/contests/abc122/tasks/abc122_a bases_dict = {'A' : 'T', 'T' : 'A', 'C' : 'G', 'G' : 'C'} base = raw_input() print '{}'.format(bases_dict[base])
Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem: There are two arrays of integers a and b of length n. It turned out that array a contains only elements from the set \{-1, 0, 1\}. Anton can perform the following sequence of operations any number of ti...
3
T = int(input()) for case in range(T): i = int(input()) #s = input() #m,n = [int(x) for x in input().split()] ls1 = [int(x) for x in input().split()] ls2 = [int(x) for x in input().split()] base = [False] * 2 if ls1[0] != ls2[0]: print("NO") continue if ls1[0] == -1: base[0] = True elif ls1[0] == 1: ba...
You are given an array a consisting of n integers a_1, a_2, ... , a_n. In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array [2, 1, 4] you can obtain the following arrays: [3, 4],...
3
t=int(input()) for i in range(t): n=int(input()) a=input().split() a=[(int(x))%3 for x in a] m=0 f=0 l=0 for x in a: if x==0: m+=1 elif x==1: f+=1 else: l+=1 print(m+min(f,l)+int((max(f,l)-min(f,l))/3))
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimu...
3
x=int(input()) x=bin(x)[2:] print(x.count('1'))
You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new ones or rearra...
3
for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) chk = list(map(int,input().split())) val = [] for i in range(n): if not chk[i]: val.append(l[i]) val.sort(reverse=True) j = 0 for i in range(n): if not chk[i]: l[i] =...
You have final scores of an examination for n students. Calculate standard deviation of the scores s1, s2 ... sn. The variance α2 is defined by α2 = (∑ni=1(si - m)2)/n where m is an average of si. The standard deviation of the scores is the square root of their variance. Constraints * n ≤ 1000 * 0 ≤ si ≤ 100 Inpu...
3
import statistics while True: n = int(input()) if n == 0: break else: data_set = [int(i) for i in input().split()] print(statistics.pstdev(data_set))
Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were x persons who would upvote, y persons who would downvote, and there were also another z persons who would vote, but you don't know whether they woul...
3
''' CodeForces 1173A Nauuo and Votes Tags: Ad-hoc, Math ''' def sign(n): if n > 0: return 1 if n < 0: return -1 return 0 x, y, z = map(int, input().split()) up = sign(x - y + z) down = sign(x - y - z) if up * down > 0: print('+' if up > 0 else '-') elif up is 0 and down is 0: print('0') else: print('?...
A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets. The store does not sell single clothing items — instead, it sells suits of two types: * a suit of the first type consists of one tie and one jacket; * a suit of the second type ...
3
a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) f=int(input()) ans=0 if(f>e): m=min(b,c,d) ans+=m*f d-=m m=min(d,a) ans+=m*e else: m=min(d,a) ans+=m*e d-=m m=min(b,c,d) ans+=m*f print(ans)
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 for _ in range(n): number = list(map(int, input().split())) one_count = number.count(1) zero_count = number.count(0) if one_count > zero_count: count += 1 print(count)
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
3
s=input() count1=0 count2=0 for i in range(len(s)): if s[i] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": count1=count1+1 else: count2=count2+1 if(count1<=count2): print(s.lower()) else: print(s.upper())
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety...
1
a = raw_input() b = raw_input() c = [x for (i, x) in enumerate(a) if x != b[i]] print max(c.count('4'), c.count('7'))
You are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in such a way that: * No two students i and j such that |a_i - a_j| = 1 belong to the same team (i.e. skills of each pair of students in t...
3
q = int(input()) while q>0: n = int(input()) a = [int(x) for x in input().split()] flag = 0 amap = {} for x in a: amap[x] = 1 for x in a: if (x-1 in amap) or (x+1 in amap): flag = 1 if flag == 1: print(2) else: print(1) q -= 1
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforc...
1
def palindrome(s): l = len(s) count = 0 for t in range(l/2): if s[t] != s[l-t-1]: count += 1 if count == 1: print "Yes" elif count >1: print "No" elif l%2 ==1: print "Yes" else: print "No" if __name__ == "__main__": s = raw_input('') palindrome(s)
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfi...
3
S = list(input()) def check(x): #print(S[len(S)-x:x]) for y in S[len(S)-x:x]: if y != S[len(S)-x]: break else: return True return False def bisect(l,r): if r - l == 1: return l mid = (l+r) // 2 if check(mid) == False: return bisect(l,mid) else: return bi...
Recently Vasya found a golden ticket — a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. No...
3
def check(s,n): for j in range(len(s)): if sum([int(letter) for letter in s[:j+1]]) == n: if j == len(s)-1: return True else: return check(s[j+1:],n) elif sum([int(letter) for letter in s[:j+1]]) > n: return False def solve(x): ...
You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here <https://en.wikipedia.org/wiki/24-hour_clock>. Input The first line...
1
hh,mm=map(int,raw_input().split(":")) a=input() mm+=a k=mm/60 mm%=60 hh+=k hh%=24 s=str(hh) if hh<10: s="0"+s s2=str(mm) if mm<10: s2="0"+s2 print "%s:%s"%(s,s2)
You have n barrels lined up in a row, numbered from left to right from one. Initially, the i-th barrel contains a_i liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels x and y (the x-th barrel shouldn't be empty) and pour any possible amount of wa...
3
for _ in range(int(input())): N, K = map(int, input().split()) V =list(map(int, input().split())) V.sort() print(sum(V[-K-1:]))
Tanya has n candies numbered from 1 to n. The i-th candy has the weight a_i. She plans to eat exactly n-1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day. Your task is to find the number of such candies i (let's call these candies goo...
3
n = int(input()) a = list(map(int, input().split())) s = 0 o_g = 0 e_g = 0 for i in range(len(a)): if i % 2 == 1: o_g += a[i] else: e_g += a[i] o_c = 0 e_c = 0 for i in range(len(a)): if i % 2 == 1: o_g -= a[i] else: e_g -= a[i] if o_c + e_g == e_c + o_g: ...
Two players decided to play one interesting card game. There is a deck of n cards, with values from 1 to n. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has a...
3
t = int(input()) for _ in range(t): n,k,l = map(int,input().split()) a1 = list(map(int,input().split())) a2 = list(map(int, input().split())) p1 = max(a1) p2 = max(a2) if p1>p2: print("YES") else: print("NO")
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song wi...
1
R = lambda:map(int, raw_input().split()) (n, d) = R() tot = sum(R()) + (n - 1) * 10 print -1 if tot > d else (n - 1) * 2 + (d - tot) / 5
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$ Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes. Your task is calculate a_{K} for given a_{1} and K. Input The ...
3
for _ in [0]*int(input()): a, k = map(int,input().split()) for i in range(k-1): if '0' in str(a):break a += (max(list(map(int,str(a))))*min(list(map(int,str(a))))) print(a)
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his...
3
k=int(input())*2 l=[0]*10 for i in range(4): s=input() for j in s: if j!='.': l[int(j)]+=1 print('NO' if max(l)>k else 'YES')
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
3
# ---------------------------------------------------------------------------------------------------- # #! /usr/local/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # Copyright © 2017 pmxt <pmxt@Manjunathas-MacBook-Air.local> # ----------------------------------------------------------------------------------...
You are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in such a way that: * No two students i and j such that |a_i - a_j| = 1 belong to the same team (i.e. skills of each pair of students in t...
3
q = int(input()) for _ in range(q): n = int(input()) a = sorted(list(map(int, input().split()))) for i in range(n-1): if a[i] + 1 == a[i+1]: print(2) break else: print(1)
Santa Claus has n candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has. Input The only line contains positive integ...
3
n=int(input()) if n==1: print(1) print(1) elif n==2: print(1) print(2) else: t=[] i=1 while i<=n: n-=i t.append(i) i+=1 k=len(t) t[k-1]+=n print(k) for i in t: print(i,end=" ")
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be a...
3
X = int(input()) t=0 x=0 while(True): t += 1 x += t if x>=X:break print(t)
We start with a permutation a_1, a_2, …, a_n and with an empty array b. We apply the following operation k times. On the i-th iteration, we select an index t_i (1 ≤ t_i ≤ n-i+1), remove a_{t_i} from the array, and append one of the numbers a_{t_i-1} or a_{t_i+1} (if t_i-1 or t_i+1 are within the array bounds) to the r...
3
import sys input = sys.stdin.readline for _ in range (int(input())): n,m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ind = [-1]*(n) for i in range (n): ind[a[i]-1] = i fixed = [0]*(n) for i in range (m): fixe...
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
3
s1 = input() + input() s3 = input() l1 = sorted(s1) l2 = sorted(s3) if len(l2)==len(l1): for i in range(len(l1)): if l1[i]!=l2[i]: print("NO") break else:print("YES") else:print("NO")
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of...
3
n=int(input()) W=[] H=[] for _ in range(0,n): w,h = input().split() w=int(w) h=int(h) W.append(w) H.append(h) t = sum(W) H1=sorted(H) # print(H1) for i in range(n): if(H[i]==H1[n-1]): print((t-W[i])*H1[n-2], end=" ") else: print((t-W[i])*H1[n-1], end=" " )
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1. Constraints * 0 \leq N \...
3
n = int(input()) a = list(map(int,input().split())) dmax = [0]*(n+2) x = []*(n+1) i = n ne = 0 while i >= 0: dmax[i] = a[i] + dmax[i+1] i -= 1 hantei = True ans = 0 x.append(1) for i in range(n+1): if x[i] < a[i]: hantei = False break else: x.append(min((x[i]-a[i]) * 2,dmax[i+...
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
for j in range(int(input())): n=int(input()) a=list(map(int,input().split())) ans=[] for j in range(n): if a[j]%2==0: ans.append(j) break if len(ans)==0: if n>1: print(2) print(1,2) else: print(-1) else: ...
We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i. Takahashi loves the number 3. He is seeking a permutation p_1, p_2, \ldots , p_N of integers from 1 to N satisfying the following condition: * For every pair of vertices (i, j), if the distance betw...
3
import sys from collections import deque def solve(): input = sys.stdin.readline N = int(input()) Edge = [[] for _ in range(N)] Par = [0 for _ in range(N)] Son = [[] for _ in range(N)] for _ in range(N - 1): a, b = map(int, input().split()) Edge[a-1].append(b-1) Edge[b-1...
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
3
n = int(input()) coins = list(reversed(sorted([int(x) for x in input().split(' ')]))) totalValue = sum(coins) coinTaken = 0 takenValue = 0 for i in range(n): coinTaken += 1 takenValue += coins[i] if takenValue > totalValue - takenValue: break print(coinTaken)
Write a program which reads an integer n and prints the factorial of n. You can assume that n ≤ 20. Input An integer n (1 ≤ n ≤ 20) in a line. Output Print the factorial of n in a line. Example Input 5 Output 120
3
n = int(input()) def f(n): if n == 0 : return 1 else : return f(n - 1) * n print(f(n))
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a ce...
3
s=input() print(len([x for x,y in zip(s,'CODEFESTIVAL2016') if x!=y]))
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not. Print the number...
3
def Gen(x, number, bound): result = 1 if x == 0: if number * 2 <= bound: result += Gen(0, number * 2, bound) if number * 3 <= bound: result += Gen(1, number * 3, bound) return result l, r = map(int, input().split()) Left = 0 if l != 1: Left = Gen(0, 1, l - 1) Right = ...
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the n...
3
#解説参照 #毎日売り買いしてよい n=int(input()) *a,=map(int, input().split()) yen=1000 for i in range(n-1): if a[i]<a[i+1]: yen = (yen//a[i])*a[i+1]+yen%a[i] print(yen)
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible. The j-th key can be used to unlock the ...
3
_ = input() chests = list(map(int, input().split(" "))) keys = list(map(int, input().split(" "))) even_num_chests = len(list(filter(lambda x: x % 2 == 0, chests))) even_num_keys = len(list(filter(lambda x: x % 2 == 0, keys))) odd_num_chests = len(list(filter(lambda x: x % 2 == 1, chests))) odd_num_keys = len(list(filt...
Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C. There are n flights from A to B, they depart at time moments a_1, a_2, a_3, ..., a_n and arrive at B t_a moments later. There are m flights from B to C...
3
n, m, ta, tb, k = [int(t) for t in input().split(' ')] da = [int(t) for t in input().split(' ')] db = [int(t) for t in input().split(' ')] best = None i = 0 j = 0 while i <= k and k < n: arrive = da[i] + ta while j < m and db[j] < arrive: j += 1 b_cancel = (k - i) if j + b_cancel >= m: ...
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
3
x = input() s=0 c=0 t=0 for i in range (0,len(x)): if (x[i] == '0'): c=c+1 if (c == 7): s=s+1 else: c=0 if (x[i] == '1'): t=t+1 if (t == 7): s=s+1 else: t=0 if (s>0): print("YES") else: print("NO")
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
def solve(): n = int(input()) s = input() pattern = "abacaba" lst = [s[i:i+7] for i in range(0,len(s)-6)] if lst.count(pattern) == 1: ans = s.replace("?","z") return "YES", ans elif lst.count(pattern) > 1: return "NO" else: j = 0 for ss in lst: temp = "" for i in range(7): if(ss[i] == "?"):...
You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i. When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where...
3
N = int(input()) V = list(map(int,input().split())) V.sort() S = V[0] for i in range(N): S = (S + V[i])/2 print(S)
Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n. He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arb...
3
n = int(input()) s = input() c = 0 ans = '' for i in range(0, n-1, 2): ans+=s[i] if(s[i]==s[i+1]): c+=1 if(s[i]=='a'): ans+='b' else: ans+='a' else: ans+=s[i+1] print(c) print(ans)
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ Output Print the previ...
3
import itertools n = input(); a = tuple(map(int, input().split())) p = sorted(list(itertools.permutations(a))) i = p.index(a) if i > 0: print(*p[i-1]) print(*p[i]) if i < len(p)-1: print(*p[i+1])
Today at the lesson of mathematics, Petya learns about the digital root. The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-d...
3
q = int(input()) for case in range(q): k, x = map(int, input().strip().split()) print((k-1) * 9 + x)
Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering. Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and othe...
3
from math import hypot, atan2, cos, sin, sqrt, pi import sys mapInt = lambda:map(int,sys.stdin.buffer.readline().split()) N, Q = mapInt() # Get points from input points = {} for n in range(N) : x, y = mapInt() points[n+1] = [x,y] # Calculate COM (centroid) centroid = [0,0] A = 0 for n in range(1,N+1) : ...
There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i...
3
strori = input() strano = input() lori = {} case = {} for i in range(26): lori[strori[i]] = strano[i] string = input() ans = '' for i in range(len(string)): if string[i].isdigit(): ans+=string[i] else: low = string[i].lower() ans+=lori[low].upper() if string[i].isupper() else lori[lo...
This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row ...
1
from sys import stdin, stdout def main(): n = int(stdin.readline()) a = map(int, stdin.readline().split()) a.sort() if n < 3 or a[0] >= a[-2]: stdout.write('0\n') stdout.write(' '.join(map(str, a))) return lo, hi = 0, (n - 1) / 2 + 1 while lo + 1 < hi: mid = (lo +...
Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remainin...
3
turns, candies = map(int, input().split()) summ = 0 turn = 0 while candies != summ - (turns - turn): turn += 1 summ += turn print(turns - turn)
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: * Employee A is the immediate manag...
1
''' ---------------vishva-mitra---------------- ''' from collections import defaultdict import Queue class Graph : def __init__(self,N) : self.graph = dict([(u,list()) for u in xrange(1,N+1)]) def addEdge(self, u, v) : self.graph[u] += v, def maxDepth(self,source) : level = 1 ...
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
3
n=int(input()) a=[int(i) for i in input().split()] if len(a)!=1: if a[0]==a[1]: ans=0 else: ans=1 max1=max(a[0],a[1]) min1=min(a[0],a[1]) for i in range(2,n): if a[i]<min1: min1=a[i] ans=ans+1 if a[i]>max1: max1=a[i] ans=ans+1 print(ans) else: print(str(0))
Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. In this problem you should implement the similar functionality. You are given a string which only consists of: * uppercase and lowercase English...
3
n = int(input()) out,ins = 0,0 s = input() p = 0 w = 0 for i in s: if p==0: if i=='(': p=1 out = max(out,w) w = 0 elif i=='_': out = max(out,w) w = 0 else: w+=1 else: if i==')': p = 0 ...
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
3
first= [ord(c.lower()) for c in input()] second = [ord(c.lower()) for c in input()] output = [first[counter]-second[counter] for counter in range(len(first))] counter = 0 for i in output: counter += i if i > 0: print(1) break elif i < 0: print(-1) break if counter == 0: ...
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. <image> English alphabet You are given a...
3
string = input() dic = {"o": "o", "x": "x", "d": "b", "b": "d", "v": "v", "w": "w", "p": "q", "q": "p"} mid = len(string) // 2 + 1 is_p = True for i in range(1, mid): f, s = string[i - 1], string[i * -1] if (f == s and f in "AHIMOTUVWXY") or (f in dic and dic[f] == s): continue else: is_p = ...
Ilya lives in a beautiful city of Chordalsk. There are n houses on the street Ilya lives, they are numerated from 1 to n from left to right; the distance between every two neighboring houses is equal to 1 unit. The neighboring houses are 1 and 2, 2 and 3, ..., n-1 and n. The houses n and 1 are not neighboring. The ho...
3
n = int(input()) d = list(map(int, input().split())) x = d[0] for i, uv in enumerate(zip(reversed(d), d)): if uv[0] != x or uv[1] != x: print(n-1-i) break
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
print(sum([1 if (sum(list(map(int,input().split()))) > 1) else 0 for i in range(int(input()))]))
Ehab loves number theory, but for some reason he hates the number x. Given an array a, find the length of its longest subarray such that the sum of its elements isn't divisible by x, or determine that such subarray doesn't exist. An array a is a subarray of an array b if a can be obtained from b by deletion of several...
3
test = int(input()) while test > 0 : test -= 1 x,y = map(int,input().split()) l = [int(x) for x in input().split()] cnt = 0 for i in range(len(l)): if l[i] % y == 0 : cnt += 1 if cnt == x : print("-1") continue sum1 = sum(l) if sum1 % y != 0 : print(x) continue #print(sum1) i,j = 0,x-1 cnt1,c...
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple...
3
n=int(input()) a=list(map(int,input().split())) a.sort() d=a.count(max(a)) e=a.count(min(a)) c=0 if len(a)<3: c=0 else: c=n-d-e if c<0: c=0 print(c)
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to...
3
s = input().split(' ') a, b, c = int(s[0]), int(s[1]), int(s[2]) M, m = max(a, b, c), min(a, b, c) d = 300 for i in range(m, M + 1): dist = abs(a - i) + abs(b - i) + abs(c - i) if dist < d: d = dist print(d)
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
3
# Valera and X def calculate(n_dim, matrix): diag_equal= True rem_equal = True diag_elem = matrix[0][0] for i in range(n_dim): if diag_equal: for j in range(n_dim): if (i == j) or (i + j == n_dim - 1) : f = matrix[i][j] s = mat...
The only difference between easy and hard versions is the maximum value of n. You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n. The positive integer is called good if it can be represented as a sum of distinct powers of 3 (...
3
import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) t,=I() for _ in range(t): n,=I() k='';x=n while x: k+=str(x%3) x//=3 k=k[::-1] ix=0 if '2' not in k: print(n) else: p=k.find('2') if p==0 or '0' not in k: k='1'+'0'*len(k) else: f=n+1;l=p-1 while l>0: if ...
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s. We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen? Constraints * All values in input are integers. * 0 \leq A, B, C * 1 \leq K \l...
3
a,b,c,k=map(int,input().split()) if a+b>=k: print(min(a,k)) else: print(a-min(c,k-(a+b)))
Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) ∈ E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v, u) doesn't matter. The vertices are numbered from 1 to |V|. Construct a rela...
1
n,m=map(int,raw_input().split()) c=0 ans=[] from fractions import gcd for i in range(1,n+1): for j in range(i+1,n+1): #print c,i,j if gcd(i,j)==1: ans.append((i,j)) c=c+1 if c==m: break if c==m: break #print ans,m if m<n-1: print "Impossible" else: if c<m: print "Impossi...
You are given N items. The value of the i-th item (1 \leq i \leq N) is v_i. Your have to select at least A and at most B of these items. Under this condition, find the maximum possible arithmetic mean of the values of selected items. Additionally, find the number of ways to select items so that the mean of the values o...
3
n,a,b=map(int,input().split()) V=list(map(int,input().split())) V.sort(reverse=True) A=V[:a] B=V[:b] ave=sum(A)/a print(ave) C=[[0]*51 for _ in range(51)] C[0][0]=1 for i in range(50): C[i+1][0]=1 C[i+1][i+1]=1 for j in range(i): C[i+1][j+1]=C[i][j]+C[i][j+1] if A[0]==A[-1]: ans=0 x=V.count(...
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a. For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times. Given are N strings s_1, s_2, \ldots, s...
3
N = int(input()) Dic = {} ans = 0 for _ in range(N): st = input() st=''.join(sorted(st)) if st not in Dic: Dic[st]=0 else: Dic[st]+=1 ans+=Dic[st] print(ans)
This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt. To make a toast, each friend needs nl ...
1
n, k, l, c, d, p, nl, np = map(int,raw_input().split()) hay = k*l beb = hay/nl sal = p/np lim = c*d cadauno = min([beb,sal,lim])/n print cadauno
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
a = input() for i in range(len(a)): if a[i] == 'H' or a[i] == 'Q' or a[i] == '9': print('YES') exit() print('NO')
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved. The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav...
3
t = int(input()) for _ in range(t): n, m, x, y = map(int, input().split()) if 2 * x <= y: b = 0 for _ in range(n): a = input() for i in range(m): if a[i] == ".": b += x print(b) else: b = 0 for _ in range(n):...
One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have s...
1
data=raw_input() data=data.split() kolvo=int(data[0]) summa=int(data[1]) scores=[] k=kolvo i=0 for i in range (kolvo): scores.append(2) while sum(scores)<summa: if i<kolvo-1: pass else: i=0 scores[i]+=1 k-=1 i+=1 if k<0: print 0 else: print k
Masha has n types of tiles of size 2 × 2. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type. Masha decides to construct the square of size m × m consisting of the given tiles. This square also has to be a symmetric with respect to the main diagonal matrix, and each cell of ...
3
def makeSq(n,m,tiles): def isSym(tile): if tile[0][1]==tile[1][0]: return True return False if m%2==1: return "NO" for tile in tiles: if isSym(tile): return "YES" return "NO" t = int(input()) for i in range(t): n, m = map(int, input().split()) tiles = [] for i i...
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
3
n,h=map(int,input().split()) ar=list(map(int,input().split())) min_w=0 for i in range(n): if ar[i]>h: min_w+=2 else: min_w+=1 print(min_w)
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below. <image> The dimension of this tile is perfect for this kitchen, as h...
3
def int_list(): return [int(c) for c in input().split()] def int1(): return int(input()) def str_list(): return [c for c in input().split()] def str1(): return input() # start w, h = int_list() ex = w+h res = 1 for i in range(w+h): res = (res*2) % 998244353 print(res)
Let's denote a function <image> You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. Input The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a. The second line contains n integers a1, a2, ..., ...
1
N = int(input()) A = map(int, raw_input().strip().split(' ')) mp = {} ans = 0 s = 0 for i in xrange(N): ans += i * A[i] - s - mp.get(A[i] - 1, 0) + mp.get(A[i] + 1, 0) s += A[i] mp[A[i]] = mp.get(A[i], 0) + 1 print ans
You are given a string s consisting of n lowercase Latin letters. You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation. String s = s_1 s_2 ... s_n is lexicograp...
3
n=int(input()) tmp=input() pos=0 arr=[] for i in tmp: arr.append(i) f=0 for i in range(n-1): if(arr[i+1]<arr[i]): arr[i]=-1 f=1 break if(f): for i in arr: if(i!=-1): print(i,end="") else: for i in range(n-1): print(arr[i],end="")
There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke ca...
3
# coding: utf-8 import sys input = sys.stdin.readline N, Q = map(int, input().split()) S = input().strip() td_list = [input().split() for _ in range(Q)] dest = [-2] * (N+1) def sim(i): # i番目のゴーレムの最終結果を得る idx = i if dest[i] != -2: return dest[i] for td in td_list: if idx == -1: dest[i] = -1 ...
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
3
s1=input() s2=input() for i in range(len(s1)): if(s1[i]==s2[i]): print('0',end="") else: print('1',end="")
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
3
s = list(map(int,input().split('+'))) s = sorted(s) l = '' for i in s: l += str(i)+'+' print(l[:-1:])
You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa. ...
3
for i in range(int(input())): s, t = input(), input() f = 1 for j in set(s): if j in set(t): f = 0 break print(['YES', 'NO'][f])
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas? Input The first lin...
3
inputs = list(map(int, input().split(" "))) # price | money | bananas x = 0 for i in range(1, inputs[2] + 1): x = x + i # print(x, i) borrow = x * inputs[0] - inputs[1] if borrow < 0: print("0") else: print(borrow)
For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for? Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got ...
3
#! /usr/bin/python3 import os import sys from io import BytesIO, IOBase def main1(): for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(1, n): if a[i] < a[i - 1]: cnt += 1 if cnt == n - 1: ...
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of n people. Each soldier registered himse...
3
n, m, x, y = map(int,input().split()) people = list(map(int,input().split())) vests = list(map(int,input().split())) i = 0 j = 0 result = [] count = 0 while (i < n) and (j < m): if people[i] - x <= vests[j] and vests[j] <= people[i] + y: result.append((i+1,j+1)) i += 1 j += 1 cou...
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn. Nickolas adores permutations. He likes some permutations more than the o...
3
T_ON = 0 DEBUG_ON = 0 MOD = 998244353 def solve(): n = read_int() if n % 2 == 1: print(-1) return A = list(range(1, n + 1)) for i in range(0, n, 2): A[i], A[i+1] = A[i+1], A[i] print_nums(A) def main(): T = read_int() if T_ON else 1 for i in range(T): solv...
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
n, m = map(int,input().split()) arr = [] for i in range(n): arr.extend(list(map(str, input().split()))) if {'B', 'W', 'G'}.union(set(arr)) == {'B', 'W', 'G'}: print("#Black&White") else: print("#Color")
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()) polyhedrons = [ input() for i in range(n)] total = 0 plane = {"Tetrahedron": 4 , "Cube": 6 , "Octahedron": 8 , "Dodecahedron":12, "Icosahedron":20} for i in polyhedrons: total += plane[i] print(total)
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients stric...
3
p, k = map(int, input().split()) l = [0] r = [0] cp = [1] coef = [] for deg in range(1, 2333): l.append(l[-1]) r.append(r[-1]) if cp[-1] > 0: r[-1] += cp[-1] * (k-1) else : l[-1] += cp[-1] * (k-1) if p <= r[-1] and p >= l[-1]: coef = [0] * deg break cp.append(cp[-1] * (-k)) cv...
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan consider...
3
n = int(input().strip()) x, y = {}, {} total = 0 points = {} for i in range(n): xi, yi = map(int, input().strip().split()) if (xi, yi) in points: points[(xi, yi)] += 1 else: points[(xi, yi)] = 1 if xi not in x.keys(): x[xi] = 1 else: x[xi] += 1 if yi not in y.keys(): y[yi] = 1 else: y[yi] += 1 for x...
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
import sys w=int(input()) if w>2: if w%2==0: print('YES') else: print('NO') else: print('NO')
Problem Statement Write a program that accepts a number and outputs the same. Sample Input 123 Sample Output 123
1
num = int( raw_input( "" ) ) print num