problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought n integers, now it's time to distribute them between his friends rationally... Lee has n integers a_1, a_2, …, a_n in his backpack and he has k friends. Lee would like to distribute all integers in his backpack betwe...
3
T = int(input()) for _ in range(T): N, K = map(int, input().split(' ')) a = [int(x) for x in input().split(' ')] w = [int(x) for x in input().split(' ')] a.sort() w.sort(reverse=True) ans = 0 while w and w[-1] == 1: ans += 2*a.pop() w.pop() i = 0 for x in w: a...
Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation exactly once: * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation. Constraints * 2 \leq N \leq 200000...
3
from collections import deque N, K = map(int, input().split()) a = list(map(int, input().split())) ans = 1 c = 0 d = 0 q = deque() p = deque() for i in range(K): if len(q) == 0: q.append(i) else: while len(q) > 0: if a[q[len(q)-1]] > a[i]: q.pop() else: ...
There is a building consisting of 10~000 apartments numbered from 1 to 10~000, inclusive. Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are 11, 2, 777, 9999 and so on. Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone...
3
l = [1,3,6,10] for _ in range(int(input())): i = input() ans = ((int(i[0]) - 1)*10) + l[len(i) - 1] print(ans)
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis...
3
s, v1, v2, t1, t2 = [int(i) for i in input().split()] res = 2*t1 + v1*s - (2*t2 + v2*s) if res == 0: print ("Friendship") elif res < 0: print("First") else: print("Second")
You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero. An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i (0 ≤ i ≤ n - 1) the equality i mod 2 = a[i] m...
3
def solution(a): z=[] b=[] for i in range(len(a)): z.append(i%2) b.append(a[i]%2) c=0 for i in range(len(a)): if z[i]!=b[i]: c+=1 if c%2!=0 or sorted(z)!=sorted(b): print(-1) else: print(c//2) for i in range(int(input())): n=int(...
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0. On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2...
3
for i in range(int(input())): n = int(input()) matrix = [] for j in range(n): l1 = list(input()) matrix.append(l1) if n == 1: print('YES') else: ans = 'YES' for j in range(n - 1): for k in range(n - 1): if matrix[j][k] == '1': ...
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
n = int(input()) print((sum(list(map(lambda x: x/100, map(int, input().split()))))/n)*100)
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers....
3
n, k = map(int, input().split()) nums = list(map(str, input().split())) total = 0 for n in nums: lucky = n.count('4') + n.count('7') if lucky <= k: total += 1 print(total)
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: * the Power Gem of purple color, * the Time Gem of green color, * the Space Gem of blue color, * the Soul Gem of orange color, * the Reality Gem of red color, * the Mind Gem of yellow color. ...
3
n = int(input()) gems = { 'purple': 'Power', 'green':'Time', 'blue':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind' } count = 6 missing = [ 'Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'] for _ in range(n): s = input() missing.remove(gems[s]) count -= 1 print(count) for _ in missing: pri...
Let's say string s has period k if s_i = s_{i + k} for all i from 1 to |s| - k (|s| means length of string s) and k is the minimum positive integer with this property. Some examples of a period: for s="0101" the period is k=2, for s="0000" the period is k=1, for s="010" the period is k=2, for s="0011" the period is k=...
3
import sys input = sys.stdin.readline t=int(input()) for tests in range(t): S=input().strip() if len(set(S))==1: print(S) else: print("01"*len(S))
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
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) count = 0 els = set() for ai in a: if ai not in els: els.add(ai) count += 1 print(count)
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1. You are given a positive integer x. Your task is to count the number of cells in a table that contain number x. Input T...
3
n, x = list(map(int, input().split())) c = 0 for i in range(1, n+1): if x % i == 0 and x // i < (n+1): c += 1 print(c)
Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the ...
3
n,l=input().split(' ') n=int(n) l=int(l) arr=list(map(int,input().rstrip().split())) arr.sort() best=0 Min=arr[0]-0 Max=l-arr[len(arr)-1] for i in range(len(arr)-1): ss=arr[i+1]-arr[i] if ss>best: best=ss dd=best/2 a=[Min,Max,dd] print(round(max(a),9))
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ...
1
N,cnt=input(),0 a=map(int,raw_input().split()) b=sorted(a) for i in xrange(N): cnt+=a[i]!=b[i] print"YNEOS"[cnt!=2 and cnt!=0::2]
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
n = int(input()) x = 0 for _ in range(n): op = input() if '++' in op: x = x + 1 else: x = x - 1 print(x)
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list. For ex...
1
def get_all_divisors(num): res = [] for i in range(1, num +1): if num % i == 0: res.append(i) return res n = int(raw_input()) divisors = sorted(map(int, raw_input().split())) value1 = divisors[-1] D = get_all_divisors(value1) i = len(D) - 1 j = len(divisors) - 1 while i > 0 and j > 0: ...
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
3
if __name__ == "__main__": n = int(input()) numbers = list(map(int,input().split())) uno = numbers.count(1) dos = numbers.count(2) tres = numbers.count(3) if uno >= dos and uno >= tres: print(dos+tres) elif dos >= uno and dos >= tres: print(uno + tres) elif tres >= dos a...
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. Constraints * 1 \leq N \leq 10^{12} * 1 \leq P \leq 10^{12} Input Input is...
3
from collections import Counter N, P = map(int, input().split()) ans = 1 prime_dict = Counter() i = 2 while i**2 <= P: if P % i == 0: P //= i prime_dict[i] += 1 continue i += 1 prime_dict[P] += 1 for k, v in prime_dict.items(): ans *= k ** (v // N) print(ans)
Initially, you have the array a consisting of one element 1 (a = [1]). In one move, you can do one of the following things: * Increase some (single) element of a by 1 (choose some i from 1 to the current length of a and increase a_i by one); * Append the copy of some (single) element of a to the end of the array...
3
import math t = int(input()) while t!=0: n = int(input()) if n==1: print(0) else: p = math.ceil(math.sqrt(n)) ans = 0 ans+=(p) ans+= math.ceil(n/p) print(ans-2) t-=1
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
k,n,w=map(int,input().split()) #k=cost of 1st banana #n=number of dollars he has #w=no.of bananas cost=0 w=w*(w+1)/2; cost=k*w-n; if(cost<=0): print(0) else: print(int(cost))
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
''' Created on 01/08/2020 @author: Gon ''' import math n, m, a = map(int, input().split()) print(math.ceil(n / a) * math.ceil(m / a))
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
3
n=int(input()) print("YES" if (str(n).count("4")+str(n).count("7"))==4 or (str(n).count("4")+str(n).count("7"))==7 else "NO")
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order. Constraints * The ...
3
a= input() b=input() print("Yes" if sorted(a)<sorted(b, reverse=True) else "No")
Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller? Constraints * 1 \leq a \leq 9 * 1 \leq b \leq 9 * a and b are integers. Input Input is given from Stan...
3
x = input().split() n = x[0] m = x[1] print(min(n*int(m), m*int(n)))
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. Input The first line contai...
3
n = int(input()) m = int(input()) usb = [] for _ in range(n): tmp = int(input()) usb.append(tmp) usb.sort(reverse=True) ans = 0 tot = 0 for i in usb: if tot >= m: break else: tot += i ans += 1 print(ans)
Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out. Bob travelled around the world and collected clues of the treasure location at n obelisks. These clues were in an ancient language, and he has only decrypted them at hom...
3
n = int(input()) x = [] a = [] cnt_x = 0 cnt_y = 0 for i in range(n*2): x, y = map(int,input().split()) cnt_x += x cnt_y += y print(cnt_x//n, cnt_y//n)
There are n candies in a row, they are numbered from left to right from 1 to n. The size of the i-th candy is a_i. Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten. The process consists o...
3
import collections def solve(n, arr): totalMoves, a, b = 0, 0, 0 def go(left, right, alexTurn, prev): nonlocal totalMoves, a, b if left > right: return if alexTurn: currSum = 0 while left < n and left <= right and currSum <= prev: ...
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard. If at least one of these n people has answered that th...
3
n=int(input()) true=False k = input() j = k.split(' ') for i in j: if i == '1': print('Hard') true = True break if true == False: print('Easy')
There are n athletes in front of you. Athletes are numbered from 1 to n from left to right. You know the strength of each athlete — the athlete number i has the strength s_i. You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team. You want...
3
for i in range(int(input())): n=int(input()) l=sorted(map(int,input().split())) s=50000000 for j in range(len(l)-1): a=l[j+1]-l[j] if a<s: s=a print(s)
There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. T...
3
n,m=map(int,input().split()) s=[list(map(int,input().split())) for _ in range(n)] m=[list(map(int,input().split())) for _ in range(m)] for i in s: a,b=i[0],i[1] md=[abs(c[0]-a)+abs(c[1]-b) for c in m] print(md.index(min(md))+1)
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
3
t=int(input()) for _ in range (t): s=input() a=0 while(len(s)>0): if '01' in s: a+=s.count('01') s=s.replace('01','') continue if '10' in s: a+=s.count('10') s=s.replace('10','') continue else: ...
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes. Some examples of beautiful numbers: * 12 (110); * 1102 (610); * 11110002 (12010); * 111110...
3
n=int(input()) k=1 if n%6==0: k=6 if n%28==0: k=28 if n%120==0: k=120 if n%496==0: k=496 if n%2016==0: k=2016 if n%8128==0: k=8128 if n%32640==0: k=32640 print(k)
There are n robots driving along an OX axis. There are also two walls: one is at coordinate 0 and one is at coordinate m. The i-th robot starts at an integer coordinate x_i~(0 < x_i < m) and moves either left (towards the 0) or right with the speed of 1 unit per second. No two robots start at the same coordinate. Whe...
3
##pyrival template for fast IO import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode ...
You are given 4n sticks, the length of the i-th stick is a_i. You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only...
3
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) a.sort() if len({x * y for (x, y) in zip(a, a[::-1])}) == 1 and a[::2] == a[1::2]: print("YES") else: print("NO")
You are given two integers x and y. You can perform two types of operations: 1. Pay a dollars and increase or decrease any of these integers by 1. For example, if x = 0 and y = 7 there are four possible outcomes after this operation: * x = 0, y = 6; * x = 0, y = 8; * x = -1, y = 7; * x = 1, y = ...
3
for _ in range(int(input())): first = input().split(" ") dollars = input().split(" ") first = list(map(int, first)) dollars = list(map(int, dollars)) if dollars[1]//dollars[0] >=2: print((first[0]+first[1])*dollars[0]) else: sum=0 if first[0]<first[1]: sum+=...
Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select...
3
def main(): import sys input = sys.stdin.readline q = int(input()) for _ in range(q): a, b = map(int, input().split()) S = input().rstrip('\n') S += '!' win = 1 cnt = 0 flg = 0 num = 0 for s in S: if s == '.': ...
Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vert...
3
import sys input=sys.stdin.readline import collections from collections import defaultdict n=int(input()) par=[ int(i) for i in input().split() if i!='\n'] suma=[int(i) for i in input().split() if i!='\n'] graph=defaultdict(list) for i in range(n-1): graph[i+2].append(par[i]) graph[par[i]].append(i+2) #print(gr...
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of...
3
#!/usr/bin/env python3 def tricky_sum(n): total = (n*(n+1))//2 other = 1 while other <= n: total -= 2*other other *= 2 return total if __name__ == '__main__': t = int(input()) for _ in range(t): print(tricky_sum(int(input())))
There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S. Adjacent slimes with the same color will fuse into one larger slime withou...
3
input() s=input() t,a=s[0],1 for c in s: if c!=t: a+=1; t=c print(a)
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
3
print((lambda word = input(): word.swapcase() if (len(word) == 1 or word[1:].isupper()) else word)())
Vasya likes to solve equations. Today he wants to solve (x~div~k) ⋅ (x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solu...
3
n,k = map(int, input().strip().split(' ')) #p = list(map(int, input().strip().split(' '))) f=0 if k>n: i=n else: i=k-1 while(i>=1): if n%i==0: x=i+((n//i) * k ) f=1 print(x) break else: i-=1 if f==0: print(0)
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to <image>. In one step you can mov...
3
n = int(input()) ls = list(map(int, input().split())) ls.sort() sum1 = 0 sum2 = 0 temp = 0 for i in range(1, n+1, 2): sum1 += (abs(ls[temp] - i)) temp += 1 temp = 0 for i in range(2, n+1, 2): sum2 += (abs(ls[temp] - i)) temp += 1 print(min(sum1, sum2))
Shubham has an array a of size n, and wants to select exactly x elements from it, such that their sum is odd. These elements do not have to be consecutive. The elements of the array are not guaranteed to be distinct. Tell him whether he can do so. Input The first line of the input contains a single integer t (1≤ t ≤...
3
for _ in range(int(input())): n,x=[*map(int,input().split())] a=[*map(int,input().split())] se=0 so=0 if x==n: if sum(a)%2==1: print("Yes") else: print("No") else: for i in a: if i%2==0: se+=1 else: ...
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 = input() n = len(s) if n%2 == 0: a = n//2 - 1 b = n//2 c = 2 d = s[a] if s[b] != d: print(n//2) quit() else: a = n//2 b = n//2 c = 1 d = s[a] while a-1 >= 0 and s[a-1] == d and s[b+1] == d: a -= 1 b += 1 c += 2 print(n-(n-c)//2)
Ziota found a video game called "Monster Invaders". Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns. For the sake of simplicity, we only consider two different types of monsters and three different types of guns. Namely, the two types of monsters are: *...
3
N, R1, R2, R3, D = map(int, input().split()) A = list(map(int, input().split())) # print(N, R1, R2, R3, D, A) dp = [[0, 0] for _ in A] dp[0][0] = R1 * A[0] + R3 dp[0][1] = min(R2, R1 * A[0] + R1) for i, a in enumerate(A[1:-1], 1): dp[i][0] = min(dp[i - 1][0] + D + R1 * A[i] + R3, dp[i - 1][1] + D ...
Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = 2, b = 3 changes the value of a to 5 (the value of b does not change). In a prototype progr...
1
x = int(raw_input()) for i in range(x): a,b,n = map(int, raw_input().split()) soma = a + b aux_a = a aux_b = b cont = 0 while (soma < n+1): if (aux_a <= aux_b): aux_a += aux_b soma = aux_a + aux_b cont += 1 else: aux_b += aux_a soma = aux_b + aux_a cont += 1 ...
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integers. * The array contains two elements x and y (these elements are known for you) such that x < y. * If you sort the arr...
3
""" pppppppppppppppppppp ppppp ppppppppppppppppppp ppppppp ppppppppppppppppppppp pppppppp pppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppp...
There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Co...
3
n = int(input()) v = list(map(int, input().split())) c = list(map(int, input().split())) print(sum(vi - ci for vi, ci in zip(v, c) if vi > ci))
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surfac...
3
x = list (map (int, input ().split (' '))) print ((x [1] ** 2 - x [0] ** 2) / (2 * x [0]))
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
t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) a1,b1=[],[] x=min(a) y=min(b) for i in range(n): a1.append(a[i]-x) b1.append(b[i]-y) s=0 for i in range(n): s=s+max(a1[i],b1[i]) print(s)
You are given an integer n and an integer k. In one step you can do one of the following moves: * decrease n by 1; * divide n by k if n is divisible by k. For example, if n = 27 and k = 3 you can do the following steps: 27 → 26 → 25 → 24 → 8 → 7 → 6 → 2 → 1 → 0. You are asked to calculate the minimum numbe...
3
n=int(input()) for i in range(0,n): p=input().rstrip().split(' ') n=int(p[0]) k=int(p[1]) GG=0; if(1): while(n!=0): if(n%k==0): n=n//k; GG+=1; else: G=n//k; A=G*k; GG+=(n-A); ...
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
3
t=int(input()) count=0 for _ in range(t): n,m = map(int,input().split()) if (abs(n-m))>=2: count=count+1 print(count)
Daruma Otoshi You are playing a variant of a game called "Daruma Otoshi (Dharma Block Striking)". At the start of a game, several wooden blocks of the same size but with varying weights are stacked on top of each other, forming a tower. Another block symbolizing Dharma is placed atop. You have a wooden hammer with it...
3
def solve(n,lst): #i行j列はjから連続したi個のうち落とせる個数の最大値 dp=[[0]*n for _ in range(n+1)] #initialize for j in range(n-1): if abs(lst[j]-lst[j+1])<=1 : dp[2][j]=2 #真ん中2*i個が抜けて上下を落とせる場合と2*(i+1)個を複数の部分に分けて落とせる場合の2通りが考えられる for i in range(3,n+1): for j in range(n-i+1): mx=0 ...
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
n,k=map(int,input().split()) l=list(map(int,input().split())) s=set(l) l1=[] l2=[] if len(s) >= k: print("YES") for i in s: for j in range(len(l)): if i == l[j]: l1.append(j+1) break l1.sort() for i in range(k): l2.append(l1[i]) print(*l2) else: print("NO")
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, the...
3
n = int(input()) posl = list(map(int , input().split())) posl.sort() # print(posl) first_pos = 0 for i in range(len(posl)): if posl[first_pos] <0: first_pos += 1 else: break cs = sum(posl[:first_pos]) bs = sum(posl[first_pos:]) print(bs - cs)
You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria. According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is...
3
n = int(input());l = list(map(int, input().split()));ans = "APPROVED" for i in (l): if(i%2 ==0 and (i%3 !=0 and i%5!=0)): ans = "DENIED" print(ans)
Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. She would like to r...
3
from sys import stdin input=stdin.readline n=int(input()) a=list(map(int,input().split())) mask=2**30 while mask and len([ai for ai in a if ai&mask])!=1: mask//=2 if mask: i=next((i for i in range(n) if a[i]&mask)) a[i],a[0]=a[0],a[i] print(*a)
Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can m...
3
T = int(input()) for t_itr in range(T): A, B = map(int, input().rstrip().split()) a_bin = bin(A) b_bin = bin(B) if len(a_bin) > len(b_bin): b_bin, a_bin = a_bin, b_bin can_replace = True for i in range(len(a_bin)): if b_bin[i] != a_bin[i]: can_replace = False ...
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
3
s1=str(input()) s2=str(input()) t=s1[::-1] if s2==t: print("YES") else: print("NO")
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
1
n, d = map(int, raw_input().split()) log = [] ans = set() for i in range(n): A, B, t = raw_input().split() t = int(t) for e in log: if e[0] == B and e[1] == A and 0 < t - e[2] <= d: ans.add(tuple(sorted([A, B]))) log.append([A, B, t]) print len(ans) for a in ans: print a[0], a[1]...
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo...
3
#n = int(input().strip()) #x = int(input().strip()) n,m = list(map(int, input().strip().split(" "))) a = list(map(int, input().strip().split(" "))) total = 0 prev = 0 out = [] for i in range(n): total += a[i] curr = int(total / m) out.append(str(curr-prev)) prev = curr print(" ".join(out))
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: * deletes all the vowels, * inserts a character "." before each consonant, * repl...
3
i=0 output=str() line = input().lower() L=len(line) while i<L: p="" p=str(line[i]) if p in "aeiouy": i=i+1 else: output = str(output) + str(".")+ str(p) i=i+1 print( str(output))
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() u=0 l=0 for i in range(0,len(s)): if(65<=ord(s[i])<=91): u+=1 else: l+=1 if(u>l): print(s.upper()) else: print(s.lower())
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of...
3
for _ in range(int(input())): N=int(input()) Sum=N*(N+1)//2 i=0 while 2**i<=N: Sum-=(2**(i+1)) i+=1 print(Sum)
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are give...
3
y=1 while True: x=int(input()) if x==0: break else: print('Case %d: %d'%(y,x)) y+=1
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on fo...
3
l, d, v, g, r = map(int, input ().split ()) s = (d / v) % (g + r) print(l / v + (s >= g) * (g + r - s)) # Made By Mostafa_Khaled
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
3
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) if n==1: print("0") else: l=l[::-1] i=1 while i<n and l[i]>=l[i-1]: i+=1 while i<n and l[i]<=l[i-1]: i+=1 print(n-i)
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decim...
3
a=[min(c, str(9-int(c)))for c in input()];print((a[0]if a[0]>'0'else'9')+''.join(a[1:]))
Orac is studying number theory, and he is interested in the properties of divisors. For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that a⋅ c=b. For n ≥ 2, we will denote as f(n) the smallest positive divisor of n, except 1. For example, f(7)=7,f(10)=2,f(35)=5. ...
3
t=int(input()) def add(a): for i in range(2,int(a**0.5)+1): if a%i==0: a+=i return a return 2*a for i in range(t): n,k=map(int,input().split()) n=add(n) print(n+2*(k-1))
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input A single line contains a non-empty word. This word consists of lowercase and uppercase English letters....
3
S = str(input()) x = S[0].upper() + S[1:] print(str(x))
There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ...
3
for i in range(int(input())): flag = 0 arr = [] for j in range(int(input())): x, y = map(int, input().split()) arr.append([x, y]) arr.sort() X, Y = 0, 0 path = "" for k in arr: if(k[0]<X or k[1]<Y): flag = 1 break path += "R" * (k[0]-X)...
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sur...
3
n = int(input()) if n <= 2: print('1\n1') elif n == 3: print('2\n1 3') else: w = '' for r in range(2,n+1,2): w = w + str(r) + ' ' for r in range(1,n+1,2): w = w + str(r) + ' ' print(n) print(w)
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
r =0 for i in [0]*int(input()): s = input() if s.count("1") > 1: r +=1 print(r)
You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of mult...
3
testCases = int(input()) for i1 in range(testCases): length = int(input()) if length == 1: print("-1") else: result = "2" + ("3"*(length-1)) print(result)
We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right). Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where th...
3
I = lambda : list(map(int,input().split())) h,w,m=I() x={};y={} l=[];dic={} for i in range(m): a,b=I() l.append([a,b]) dic[(a,b)]=1 x[a]=x.get(a,0)+1 y[b]=y.get(b,0)+1 p,q=max(x.values()),max(y.values()) a,b=[i for i in x if x[i]==p],[i for i in y if y[i]==q] an=p+q;fl=0 for i in a: for j in b: if dic.g...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
3
import math n, I = map(int, input().split()) a = list(map(int,input().split())) a.sort() vals = 2**((I*8)//n) K = len(a) if K>vals: d = {} for i in a: d[i] = d.get(i, 0) + 1 d = list(d.items()) s = sum([val for key, val in d[:vals]]) maxs = s for i in range(vals, len(d)): s = s -...
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
3
a=list(input().split('WUB')) if a[0]==' ': print(a[1],end=' ') for i in range(2,len(a)): print(a[i],end=' ') else: for i in range(len(a)): print(a[i],end=' ')
Nezzar's favorite digit among 1,…,9 is d. He calls a positive integer lucky if d occurs at least once in its decimal representation. Given q integers a_1,a_2,…,a_q, for each 1 ≤ i ≤ q Nezzar would like to know if a_i can be equal to a sum of several (one or more) lucky numbers. Input The first line contains a singl...
3
import sys, collections, math, itertools, random, bisect INF = sys.maxsize def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() mod = 10**9 + 7 for _ in range(int(input())): ...
Alice is playing with some stones. Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones. Each time she can do one of two operations: 1. take one stone from the first heap and two stones from the second heap (...
3
t = int(input()) for p in range(t): a, b, c = [int(s) for s in input().split()] if c%2: c -= 1 if 2*a + c//2 <= b: ans = 3*(a + c//2) print(ans) continue if c//2 <= b: y = c//2 x = min(a, (b-y)//2) ans = 3*(x+y) print(ans) continue ...
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections. The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Ob...
3
import math a = int(input()) cur = math.factorial(a) // math.factorial(a - 5) cnk = math.factorial(a) // math.factorial(5) // math.factorial(a - 5) print(cur * cnk)
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water...
3
#!/usr/bin/env python3 """ Codeforces 149 A. Business trip @author yamaton @date 2015-08-04 """ def solve(xs, k): if sum(xs) < k: return -1 if k == 0: return 0 ys = sorted(xs, reverse=True) centimeter = 0 month = 0 for y in ys: centimeter += y month += 1 ...
You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties: * Have positive area. * With vertices at integer points. * All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0, 0), (w, 0), (w, h), (0,...
1
n,m = map(int,raw_input().split()) res = 0 for a in range (2,n+1,2): for b in range (2,m+1,2): res = res + (m-b+1)*(n-a+1) print res
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and...
3
n=int(input()) a=list(map(int,input().split())) cnt=[0 for i in range(100001)] dp=[0 for i in range(100001)] for i in a: cnt[i]+=1 dp[0]=0 dp[1]=cnt[1] for i in range(2,100001): dp[i]=max(dp[i-1],dp[i-2]+(i*cnt[i])) print(dp[100000])
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...
3
n,t = map(int, input().split()) a = list(map(int, input().split())) z = t - (sum(a) + (n-1)*10) if z>=0: out = z//5 + (n-1)*2 else: out = -1 print(out)
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....
1
__author__ = 'lonnelan' n = int(raw_input()) x = 0 for i in range(0, n, 1): str = raw_input() if str == "++X" or str == "X++": x += 1 elif str == "--X" or str == "X--": x -= 1 print x
Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18. You are given two integers l and r. Find two integers x and y such that l ≤ x < y ≤ r and l ≤ LCM(x, y) ≤ r. Input The first line contains one integer t (1 ≤ t ≤ 10000) — the number of tes...
3
t=int(input()) while(t>0): t-=1 l,r=map(int,input().split()) if(l*2>r): print("-1 -1") else: print(l,l*2)
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length ...
3
#599A lst=list(map(int, input().split())) a=lst[0] b=lst[1] c=lst[2] route1=2*min(a+b,b+c,c+a) route2=a+b+c print(min(route1,route2))
The only difference between easy and hard versions is the constraints. Polycarp has to write a coursework. The coursework consists of m pages. Polycarp also has n cups of coffee. The coffee in the i-th cup Polycarp has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can dri...
3
n, m = map(int, input().split()) A = list(map(int, input().split())) A.sort() A.reverse() def func(i): ans = 0 for j in range(0, n): ans += max(A[j] - j // i, 0) return ans >= m l = 1 r = n while (r - l) > 1: s = (l + r) >> 1 if func(s) == 1: r = s else: l = s if func(l) ...
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long...
1
def solve(n): if len(str(n)) == 1: return 1 start = int(str(n)[0]) + 1 for i in xrange(len(str(n)) - 1): start *= 10 return start - n print solve(input())
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() f = False for i in a: if i == 'H': f = True if i == 'Q': f = True if i == '9': f = True if f == True: print('YES') else: print('NO')
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k. You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-mu...
1
s=raw_input().split() n=int(s[0]) k=int(s[1]) x=raw_input().split() for i in range(0,n): x[i]=int(x[i]) x.sort() p=set() ans=0 for i in x: if i in p: continue else: ans+=1 p.add(i*k) print ans
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visi...
3
from itertools import permutations INF = 10 ** 8 N, M, R = map(int,input().split()) r = list(map(lambda x: int(x)-1 ,input().split())) MAP = [[INF for i in range(N)] for j in range(N)] for i in range(M): A, B, C = map(int,input().split()) MAP[A-1][B-1] = C MAP[B-1][A-1] = C for k in range(N): for i in r...
You are given a binary string s consisting of n zeros and ones. Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string belongs to exactly one subsequence and each subsequence looks like "010101 ..." or "101010 ..." (i.e. the subsequence should no...
3
from collections import defaultdict def main(): for _ in range(int(input())): n=int(input()) s=input() ans=[0]*n count=0 d=defaultdict(list) for i in range(n): if s[i]=='0': if not d[1]: count+=1 d[0]...
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
1
n, k = map(int, raw_input().split()) f, t = map(int, raw_input().split()) if t > k: result = f - t + k else: result = f for i in range(1, n): f, t = map(int, raw_input().split()) if t > k: joy = f - t + k else: joy = f if joy > result: result = joy print result
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... In...
3
# --------------------------------# #-----------<HajLorenzo>----------- #Most Important Thing About Life #Is Loving What You Do... # --------------------------------# _="heidi" n=input() DFX=0 for i in range(len(n)): if(n[i]=="heidi"[DFX]): DFX+=1 if(DFX==5): print("YES") exi...
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
if __name__ == "__main__": n = int(input()) if(2<=n<=1000): a=0 c=0 d=[] for i in range(n): b = list(map(int,input().split())) if((i==0 and b[0]>0) or (i!=0 and b[0]>d[i-1])): a='n' break if(i==0...
You have two integers l and r. Find an integer x which satisfies the conditions below: * l ≤ x ≤ r. * All digits of x are different. If there are multiple answers, print any of them. Input The first line contains two integers l and r (1 ≤ l ≤ r ≤ 10^{5}). Output If an answer exists, print any of them. Oth...
3
l, r = map(int, input().split()) f = 1 for i in range(l, r+1): if(len(set(str(i))) == len(str(i))): print(i) f = 0 break if(f): print(-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...
1
import sys f = sys.stdin #f = open("input.txt") line = f.readline().strip(); l = len(line) x = int(line, 2) y = int(f.readline(), 2) x ^= y print ("{0:0>" + str(len(line)) + "}").format(bin(x)[2:])
Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first...
3
n=int(input()) c=0 c+=n//100 n%=100 c+=n//20 n%=20 c+=n//10 n%=10 c+=n//5 n%=5 c+=n//1 print(c)
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 = list(map(int,input().split())) tall = list(map(int,input().split())) r = 0 for i in range(n): if tall[i] <= h: r+=1 else: r+=2 print(r)