problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 β₯ w_2. In this game, exactly one ship is used... | 3 | w1, h1, w2, h2 = list(map(int, input().split()))
x, y = h1 + h2, max(w1, w2)
print(2 * x + 2 * y + 4) |
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are chosen.
Constraints
* All values i... | 3 | a,b=[list(map(int,input().split())) for i in range(2)]
print((a[0]-b[0])*(a[1]-b[1])) |
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.
He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (iβ j), he has to pay the cost separately for transforming each of them (See ... | 3 | N = int(input())
A = sorted(list(map(int,input().split())))
z = 10**6
for i in range(A[0],A[-1]+1):
z = min(z,sum([(a-i)**2 for a in A]))
print(z) |
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each... | 3 |
n, t = map(int, input().split())
s = list(map(str, input()))
while(t):
i = 0
while(i < n-1):
if(s[i] == 'B' and s[i+1] == 'G'):
s[i], s[i+1] = s[i+1], s[i]
i += 2
else:
i += 1
t -= 1
print(''.join(s)) |
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and pl... | 1 | A,B,C,D=map(int,raw_input().split())
L=A+B
R=C+D
if L>R:
print "Left"
elif L==R:
print "Balanced"
else:
print "Right"
|
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N... | 3 | M,*li = [list(map(int,i.split())) for i in open(0)]
M = M[0]
row = [[x-y,x+y] for x,y in li]
row.sort(key = lambda x:x[1])
ans = 0
s = -1*float('inf')
for rs,rt in row:
if s <= rs:
ans += 1
s = rt
print(ans) |
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline ... | 3 | import math
n,k=map(int,input().split())
ans=0
arr=[]
for ii in range(n):
x,y=map(int,input().split())
arr.append([x,y])
for i in range(n-1):
xx=arr[i][0]-arr[i+1][0]
yy=arr[i][1]-arr[i+1][1]
temp=(xx**2)+(yy**2)
ans+=(temp**0.5)
print(k*ans/50) |
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | 3 | n, x, Decode = int(input()), input(), ''
if n % 2 == 0:
for i in range(n):
Decode = (Decode + x[i] if i % 2 != 0 else x[i] + Decode)
else:
for i in range(n):
Decode = (Decode + x[i] if i % 2 == 0 else x[i] + Decode)
print(Decode)
|
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a de... | 3 | def op(a,b):
return(a[0]*b[1]- a[1]*b[0])
def vec(a,b):
return(b[0]-a[0],b[1]- a[1])
while True:
try:
xa,ya,xb,yb,xc,yc,xd,yd = list(map(float,input().strip().split(',')))
a = (xa,ya)
b = (xb,yb)
c = (xc,yc)
d = (xd,yd)
p1 = op(vec(a,b), vec(b,c))
p2... |
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | 3 | s = input()
t=list(s)
t.reverse()
print(s,end="")
for i in t:
print(i,end="")
print() |
This problem is interactive.
We have hidden an array a of n pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.
This device can answer queries of the following form: in response to the positions of k diffe... | 3 | n, k = list(map(int, input().split()))
values = []
for i in range(1, k + 2):
x = list(range(1, i)) + list(range(i + 1, k + 2))
print('?', *x)
position, a = map(int, input().split())
values.append(a)
small = min(values)
large = max(values)
m = len([a for a in values if a == large])
print('!', m)
|
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n ... | 3 | for _ in range(int(input())):
n = int(input())
lis = list(map(int,input().split()))
ans = [0]*n
dec = 0
for i in range(n-1,-1,-1):
dec = max(dec,lis[i])
if dec>0:
dec -= 1
ans[i]=1
print(*ans) |
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input
The first line contains a nu... | 3 | codes = {"." : 0, "-." : 1, "--" : 2}
msg = input()
i = 0
while(i < len(msg)):
if msg[i] == ".":
print(0,end = "")
else:
if msg[i+1] == ".":
print(1,end = "")
else:
print(2,end = "")
i += 1
i += 1 |
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, ... | 3 | import math
def simply(a, b):
g = math.gcd(a, b)
a = a // g
b = b // g
return (a, b)
def mul(a, b, c, d):
return simply(a * c, b * d)
def add(a, b, c, d):
return simply(a * d + b * c, b * d)
def main():
n = int(input())
nxt = 0
depth = 0
node = 1
total_node = 1
p = 0
q = 1
while (n % 2 == 0):
de... |
Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the boa... | 3 | from math import *
from itertools import *
from functools import *
def ceilInt(a, b):
return a if b == 1 else (a + b - 1) // b
def scanLine(dtype):
return list(map(dtype, input().split()))
b = scanLine(int)[0]
def factorize(b, p):
k = 0
while b % p == 0:
b /= p
k += 1
return b, ... |
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | 1 | groups=0
prev=""
for i in range(int(raw_input())):
bla=raw_input()
if bla != prev:
groups+=1
prev=bla
print groups
|
You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once.
A contiguous substring of string s is a string that can be obtained from s by removing some (possibly zero) character... | 3 | def solve(s):
# count = {'1': 0, '2': 0, '3': 0}
count = [0,0,0]
l = 0
r = 0
res = 0
while r < len(s):
while min(count) == 0:
count[int(s[r])-1] += 1
r += 1
if r == len(s):
break
if min(count) == 0:
retu... |
You are given four integers n, c_0, c_1 and h and a binary string s of length n.
A binary string is a string consisting of characters 0 and 1.
You can change any character of the string s (the string should be still binary after the change). You should pay h coins for each change.
After some changes (possibly zero) ... | 3 | t = int(input())
for i in range(t):
n, c0, c1, h = map(int, input().split())
s = str(input())
Mi = min(c0, c1)
Ma = max(c0, c1)
if Mi + h < Ma:
if Mi == c0:
print(s.count('0')*c0 + s.count('1')*(c0+h) )
else:
print(s.count('0')*(c1 + h) + s.count('1')*c1 )
... |
Given an integer n, find the maximum value of integer k such that the following condition holds:
n & (n-1) & (n-2) & (n-3) & ... (k) = 0 where & denotes the [bitwise AND operation.](https://en.wikipedia.org/wiki/Bitwise_operation#AND)
Input
The first line contains a single integer t (1 β€ t β€ 3 β
10^4). Then t test... | 3 | from math import log
from math import floor
t = int(input())
for i in range(t):
n = int(input())
#print(n)
k = 2**(floor(log(n,2)))-1
print(k)
|
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regar... | 1 | from collections import deque
N=input()
a=map(int, raw_input().split())
b=map(int, raw_input().split())
S=[]
def bfs(n,start,end):
c=[set() for i in range(51)]
for i in range(51):
for j in range(1,n+1):
c[i].add(i%j)
for i in range(51):
c[i].add(i)
for i in range(51):
for j in S:
c[i].add(i%j)
V... |
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting e... | 3 | a = int(input())
b = int(input())
c = int(input())
if (a*b*c >= (a+b)*c and a*b*c >= a*(b+c)):
print(a*b*c)
elif (a+b)*c >= a*(b+c) and (a+b)*c >= a+b+c:
print((a+b)*c)
elif a*(b+c) >= (a+b)*c and a*(b+c) >= a+b+c:
print(a*(b+c))
else:
print(a+b+c) |
You're given an array a of n integers, such that a_1 + a_2 + β
β
β
+ a_n = 0.
In one operation, you can choose two different indices i and j (1 β€ i, j β€ n), decrement a_i by one and increment a_j by one. If i < j this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make a... | 3 | import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readlin... |
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
Constraints
* 0 \leq N_1, N_2, N_3, N_4 \leq 9
* N_1, N_2, N_3 and N_4 are integers.
Input
Input is given from Standard Input in the following format:
N_1 N_2 N_3 N_4
Output
If N_1, N_2, N_3 ... | 3 | n = set(map(int, input().split()))
if n == {1, 4, 7, 9}:
print('YES')
else:
print('NO') |
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain posi... | 3 | def count(n):
c = 0
while n > 0:
c += n % 10
n = n // 10
return c
n = int(input())
k = 0
R= []
for i in range(90):
if n - i > 0:
if count(n - i) == i:
k += 1
R.append(n - i)
R = R[::-1]
print(k)
for i in R:
print(i)
|
You have a given integer n. Find the number of ways to fill all 3 Γ n tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap.
<image> This picture describes when n = 4. The left one is the shape and the right one is 3 Γ n tiles.
Input
The only line cont... | 3 | n=int(input())
if n&1:
print(0)
else:
power = n//2
print(pow(2,power))
|
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":
* "A" corresponds to an angry... | 3 | for i in range(int(input())):
p=int(input())
s=list(input().split('A'))
if len(s)>0:
t=[]
for k in range(len(s)):
if 'P' in s[k]:
if k>0:
t.append(len(s[k]))
if len(t)>0:
print(max(t))
else:
print(0)
... |
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^5) β the number of test cases.
The next t lines... | 3 | t=int(input())
while(t>0):
t-=1
n,k=map(int,input().split())
if(k*k<=n and n%2==k%2):
print("YES")
else:
print("NO") |
During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of n high school students numbered from 1 to n. Initially, each student i is on position i. Each student i is characterized by two numbers β a_i and b_i. Dissatisfaction of the person i equals the product of a_i b... | 3 | n = int(input())
d = []
total = 0
for i in range(n):
a, b = [int(x) for x in input().split()]
total += (b * (n-1))
d.append(a-b)
d.sort(reverse=True)
for i in range(n):
total += (d[i] * i)
print(total) |
You have n students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the i-th student skill is denoted by an integer a_i (different students can have the same skills).
So, about the teams. Firstly, these two teams should have the s... | 3 | import math
T = int(input())
for t in range(T):
N = int(input())
A = list(map(int, input().split()))
numbers = {}
for a in A:
if a in numbers.keys():
numbers[a] += 1
else:
numbers[a] = 1
sol = math.floor(N/2)
firstT = max(numbers.values())
secondT = le... |
2N players are running a competitive table tennis training on N tables numbered from 1 to N.
The training consists of rounds. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.
The winner of the... | 3 | n,a,b = map(int,input().split())
if(( b-a ) % 2 == 0):
print(((b-a)//2))
exit()
print((min(a-1,n-b)+1+(b-a-1)//2)) |
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
* if the last digit of the number is non-zero, she decreases the number by one;
* if the last digit of the number is ze... | 3 | a,b=[int(i) for i in input().split()]
while(b):
b-=1
if(a%10==0):
a=a//10
else:
a-=1
print(a) |
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direc... | 3 | inp = input().split(" ")
largestnum = int(inp[0])
trash = int(inp[1])
if trash == 1:
print(largestnum)
else:
res = largestnum
k = 0
while 2 ** k <= largestnum:
k = k + 1
print(2 ** k - 1)
|
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | 3 | # Medium
year = input()
def has_distinct_digits(year):
for i in range(len(year)):
for j in range(len(year)):
if j > i and year[i] == year[j]:
return False
return True
next_year = str(int(year) + 1)
while not has_distinct_digits(next_year):
next_year = str(int(next_yea... |
Polycarp is sad β New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them ... | 3 | for i in range(int(input())):
garland = list(map(int,input().split()))
f = max(garland)
garland.remove(f)
if f-sum(garland)<=1:
print("Yes")
else:
print("No")
|
<image>
You have one chip and one chance to play roulette. Are you feeling lucky?
Output
Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). | 3 | def main():
print("Red")
if __name__ == "__main__":
main()
|
Screen resolution of Polycarp's monitor is a Γ b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 β€ x < a, 0 β€ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β from 0 to b-1.
Polycarp wants to open a rectangular window of maximal size, which ... | 1 | #!/usr/bin/env python
from sys import stdin, stderr
def solve(a, b, x, y):
return max( x * b, (a - x - 1) * b, a * y, a * (b - y - 1) )
def main():
TC = int(stdin.readline())
for tc in xrange(TC):
a, b, x, y = map(int, stdin.readline().split())
res = solve(a, b, x, y)
print(res)
return... |
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | 3 | r = int(input())
string = [] * r
for i in range(r):
m = input()
string.append(m)
for i in range(r):
n = string[i]
t = ''
k = len(n)
if len(n) > 10:
t = n[0] + str(k-2) + n[k-1]
print(t)
else:
print(string[i])
|
X and A are integers between 0 and 9 (inclusive).
If X is less than A, print 0; if X is not less than A, print 10.
Constraints
* 0 \leq X, A \leq 9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X A
Output
If X is less than A, print 0; if X is not less th... | 3 | s=input();print("100"[s[0]<s[2]::2]) |
There are n people who want to participate in a boat competition. The weight of the i-th participant is w_i. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.
So, if there are k teams (a_1, b_1), (a_2, b_2)... | 3 | if __name__ == "__main__":
t = int(input())
for _ in range(t):
n = int(input())
w = list(map(int, input().split()))
range_start, range_end = 2, 2* n + 1
team_count = 0
for team_weight in range(range_start, range_end):
team_count_fortarget = 0
tea... |
You are given a permutation p_1, p_2, ..., p_n. Recall that sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.
Find three indices i, j and k such that:
* 1 β€ i < j < k β€ n;
* p_i < p_j and p_j > p_k.
Or say that there are no such indices.
Input
The first lin... | 3 | for i in range(int(input())):
n = int(input())
l = list(map(int, input().rstrip().split(" ")))
r = []
for i in range(1, n-1):
if l[i-1]< l[i] and l[i]> l[i+1]:
r = [i , i+1, i+2]
break
if r:
print("YES")
print(*r)
else:
print("NO") |
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contes... | 1 | inp = raw_input().split(' ')
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])
x = max(a * 3 / 10, a - a * c / 250)
y = max(b * 3 / 10, b - b * d / 250)
if x > y:
print 'Misha'
elif x == y:
print 'Tie'
else:
print 'Vasya' |
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | 3 | import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
ddc = 0
f = 1
ans = set()
for x in a:
if f:
ddc = x%k
o = 0
o = x%k
if not f:
ddc = math.gcd(ddc, o)
if o == 1:
print(k)
print(*range(k))
exit()
f = 0
'''
if k%2 != o%2 and math.gcd(k, o)==1:
print(k)
print(*rang... |
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 = list(map(int, (input()).split()))
m = list(map(int, (input()).split()))
max_distance = 0.0
m.sort()
if m[0] > (n[1] - m[n[0] - 1]) :
max_distance = m[0]
else:
max_distance = (n[1] - m[n[0] - 1])
for i in range(n[0] -1):
if (m[i + 1] - m[i])/2 > max_distance:
max_distance = (m[i + 1] - m[i])/2
p... |
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The fi... | 3 | for _ in range(int(input())):
n = int(input())
t = 0
tw = 0
while(n>0):
if(n%3 == 0):
t+=1
n = n//3
else:
break
while(n>0):
if(n%2 == 0):
tw+=1
n = n//2
else:
break
if(tw<=t and n==1):
... |
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the eve... | 3 | a,b=map(int,input().split())
r=a
s=a
while(s>=b):
r=r+s//b
s=(s//b)+(s%b)
print(r) |
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly th... | 3 | n=int(input())
for i in range(n):
x=int(input())
k=x
f=0
while(x>0):
if((x%3==0)or(x%7==0)):
print("YES")
f=1
break
else:
x-=3
x=k
if(f==1):
continue
while(x>0):
if((x%3==0)or(x%7==0)):
print("YES")
... |
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 | a = int(input())
#a = [int(i) for i in input().split()]
if (a % 2 == 0 and a!= 2):
print('YES')
else:
print ('NO')
|
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their h... | 3 | n = int(input())
heights = [int(x) for x in input().split()]
def swap(i, j):
heights[i], heights[j] = heights[j], heights[i]
time = 0
max_idx = 0
for i in range(1, n):
if heights[i] > heights[max_idx]:
max_idx = i
while max_idx > 0:
swap(max_idx - 1, max_idx)
max_idx -= 1
time += 1
... |
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 |
n,k = map(int, input().split())
bank = 1
count = 0
j = 1
n -= 1
while n>0:
if bank <= k:
j += 1
bank += j
n -= 1
else:
while bank > k:
n -= 1
bank -= 1
count += 1
print(count) |
Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x = 0. Mezo starts sending n commands to Zoma. There are two possible commands:
* 'L' (Left) sets the position x: =x - 1;
* 'R' (Right) sets the position x: =x + 1.
Unfortunately, Mezo's controller malfunctions sometimes. ... | 3 | l,r=0,0
x=(int(input()))
arr=[ch for ch in input()]
for i in arr:
if(i=="L"):
l+=1
else:
r+=1
print(l+r+1) |
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on it.
Constraints
* 2 \leq N \leq 50
* 0 \leq x_i \leq 1000
* 0 \leq y_i \leq 1000
* The given N points are all different.
* The values in input are all integers.
Input
Input is giv... | 1 | #
# Bad python template TM
#
# Zeyu, 2019
#
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
flush = stdout.flush
# setrecursionlimit(1000000)
############################################################
OUT = []
def write(item, sep=""):
if type(item) is int or type(item) is lo... |
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | 1 | from collections import Counter
t = Counter(map(int, raw_input().split()))
max_sum = 0
for value, count in t.items():
if count > 1:
new_sum = value * min(count, 3)
if not max_sum:
max_sum = new_sum
elif max_sum < new_sum:
max_sum = new_sum
print sum(k * v for k, v... |
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 | combine = list(input() + input())
combine.sort()
disorder = list(input())
disorder.sort()
if combine == disorder :
print('YES')
else:
print('NO')
|
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 | n1=input().lower()
n2=input().lower()
if (n1)<n2:
print("-1")
elif n1>n2:
print("1")
else:
print("0")
|
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | 3 | str=input()
n=int(str)
if n>=0:
print(n)
else:
a=(-n)%10
b=((-n)%100)//10
if a>=b:
print(-((-n)//10))
elif (-n)%10==0 and (-n)//10<10:
print('0')
else:
print(-((-n)//100)*10-a) |
You are given two arrays a and b both consisting of n positive (greater than zero) integers. You are also given an integer k.
In one move, you can choose two indices i and j (1 β€ i, j β€ n) and swap a_i and b_j (i.e. a_i becomes b_j and vice versa). Note that i and j can be equal or different (in particular, swap a_2 w... | 3 | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
for _ in range(k):
b,bi = -1,-1
s,si = float('inf'),-1
for i in range(n):
if A[i]<s:
... |
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please d... | 1 | n,x,y = map(int,raw_input().split())
if y < n: print -1;
elif (n-1) + (y - n + 1)**2 < x: print -1;
else:
print "1 "*(n-1) + str(y - n + 1) |
The game of Berland poker is played with a deck of n cards, m of which are jokers. k players play this game (n is divisible by k).
At the beginning of the game, each player takes n/k cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he... | 3 | import math
from sys import stdin
input = stdin.readline
for t in range(int(input())):
n, m, k = map(int, input().split())
cards = int(n / k)
if cards >= m:
print(m)
else:
if cards == max(1, int((m - cards) / k - 1)):
print(0)
else:
print(cards - max(1, m... |
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=input()
s2=input()
print('YES' if s1[::-1]==s2 else 'NO') |
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
* a1 = p, where p is some integer;
* ai = ai - 1 + ( - 1)i + 1Β·q (i > 1), where q is som... | 3 | n=int(input())
b=list(map(int,input().split()))
dp=[[1]*n for i in range(n)]
d={}
k=0
for i in range(n):
if b[i] not in d:
d[b[i]]=k
k+=1
b[i]=d[b[i]]
for i in range(n):
for j in range(i):
dp[i][b[j]]=max(dp[j][b[i]]+1,dp[i][b[j]])
ans=0
for l in dp:
ans=max(ans,max(l))
print(ans) |
A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily 7 days!
In detail, she can choose any integer k which satisfies 1 β€ k β€ r, and set k days as the number of days in a week.
Alice is going to paint some n... | 3 | for i in range(int(input())):
a,b=map(int,input().split())
c=0
if a>b:
if b%2==0:
c=(b*((b)//2))+b//2
else:
c=b*(b//2+1)
print(int(c))
else:
if (a-1)%2==0:
c=((a-1)*(a-1)//2)+(a-1)//2
else:
c=(a-1)*(((a-1)//2)+1)
... |
You are given n triangles.
You are required to find how many triangles are unique out of given triangles.
For each triangle you are given three integers a,b,c , the sides of a
triangle.
A triangle is said to be unique if there is no other triangle with same set of sides.
Note : It is always possible to form triangl... | 1 | from collections import Counter
c = Counter()
for _ in range(int(raw_input())):
c[tuple(sorted(map(int, raw_input().split())))] += 1
print c.values().count(1) |
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are roun... | 3 | t = int(input())
while(t>0):
n = int(input())
a = []
if(n%(10**(len(str(n))-1))==0):
print(1)
print(n)
else:
while(len(str(n))>0):
i = len(str(n))
if(n==0): break
a.append((n//(10**(i-1)))*(10**(i-1)))
if(i == 1): break
... |
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the followin... | 1 | from __future__ import division
import math
n, k = map(long, raw_input().split())
mid = int(math.ceil(n / 2))
if k < mid + 1:
print ((2 * (k - 1)) + 1)
else:
print 2*(k-mid) |
Alice guesses the strings that Bob made for her.
At first, Bob came up with the secret string a consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers Alice the string b so that she can guess the string a.
Bob builds b from a... | 3 | t=int(input())
for z in range(t):
s=input()
r=''
if(len(s)==2):
print(s)
else:
r=r+s[0]
for i in range(len(s)):
if(i%2==1):
r=r+s[i]
print(r) |
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.
Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from t... | 3 | N,A,B= map(int,input().split())
S = input()
for s in S:
if s == 'a' and A+B > 0:
if A != 0:
A -= 1
else:
B -= 1
print('Yes')
elif s == 'b' and B > 0:
B -= 1
print('Yes')
else:
print('No')
|
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 | sumi = 0
maxi = 0
for _ in range(int(input())):
depart, arrival = map(int, input().split())
if sumi >= depart:
sumi -= depart
sumi += arrival
if sumi > maxi:
maxi = sumi
print(maxi)
|
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 | from functools import reduce
n = int(input())
p = [int(i) for i in input().split()]
print(reduce(lambda x,y: x+y, p) / n) |
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the... | 3 | o = list(input())
e = input()
for i in range(len(e)):
o.insert(i*2+1, e[i])
print(''.join(o))
|
Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 Γ 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.
The morning has ... | 3 | n = int(input())
x = set()
y = set()
for i in range(n):
a, b = map(int, input().split())
x.add(a)
y.add(b)
print(min(len(x), len(y)))
|
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" β three distinct two-grams.
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ... | 3 | l1 = int(input())
l2 = list(input())
lul = []
obj = {}
for i in range(l1-1):
x = l2[i] + l2[i+1]
if x in obj:
obj[x] += +1
else:
obj[x] = 1
max_key = max(obj, key=obj.get)
print(max_key)
|
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | 1 | n = input()
k = -1 if n < 0 else 1
print max(n, abs(n) / 10 * k, (abs(n) / 100 * 10 + abs(n) % 10) * k) |
You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map.
<image>
Figure B-1: A marine area map
You can walk from a square land area to another if they are horizontally, vertically, or diagonally adjacent to each other on the map. Two ar... | 3 | import sys
sys.setrecursionlimit(2500)
w,h = map(int,input().split())
while not(w==h==0):
m = [[0]*(w+2)]
m += [[0]+list(map(int,input().split()))+[0] for i in range(h)]
m += [[0]*(w+2)]
g = [[] for i in range(w*h)]
for i in range(1,h+1):
for j in range(1,w+1):
if m[i][j]==1:
... |
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
* a < b < c;
* a divides b, b divides c.
Naturally, Xenia wants... | 1 | def solver():
n = input()
num = map(int, raw_input().split())
count1 = num.count(1)
count2 = num.count(2)
count3 = num.count(3)
count4 = num.count(4)
count6 = num.count(6)
count_other = len(num) - count1 - count2 -count3 -count4 -count6
if count1 == 0 or count_other != 0:
pri... |
There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty.
In the beginning, Snuke stands on Square A, and Fnuke stand... | 3 | n,a,b,c,d = [int(x) for x in input().split()]
s = input()
if s[a-1:c].count("##") > 0 or s[a-1:d].count("##") > 0:
print("No")
elif d < c:
if s[b-2:d+1].count("..."):
print("Yes")
else:
print("No")
else:
print("Yes") |
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b d... | 3 | p,n=map(int,input().split())
l=[]
for i in range(n):
x=int(input())
d=x%p
if(d not in l):
l.append(d)
else:
print(i+1)
exit()
else:
print(-1) |
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | 3 | n=int(input())
for j in range(n):
word=input()
k=len(word)
if(k<11):
print(word)
else:
l=str(k-2)
print(word[0]+l+word[k-1]) |
You are given two integers a and b. You may perform any number of operations on them (possibly zero).
During each operation you should choose any positive integer x and set a := a - x, b := b - 2x or a := a - 2x, b := b - x. Note that you may choose different values of x in different operations.
Is it possible to mak... | 3 | from collections import Counter,deque,defaultdict,OrderedDict,namedtuple
from bisect import bisect_left,bisect_right,insort
from math import sqrt,ceil,floor,factorial,gcd
mod=10**9+7
from sys import stdin
t=int(stdin.readline())
while t:
a,b=map(int,stdin.readline().split())
k='NO'
if a==1 and b==1:
... |
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted ... | 3 | n = int(input().strip())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
s1 = set(a+b)
c = 0
for i in range(n):
for j in range(n):
if a[i]^b[j] in s1:
c += 1
print(['Karen', 'Koyomi'][c%2]) |
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in th... | 3 | import heapq
t=int(input())
while t:
n=int(input())
l=list(map(int,input().split()))
h=[]
for i in range(n):
heapq.heappush(h,(-l[i],i))
lol=0
prev1=-1
prev2=-1
lel=0
while h:
if(lol==0):
val,ind=heapq.heappop(h)
val=-val
if(ind==pr... |
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 | def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a,b):
return (a*b) / gcd(a,b)
n=int(input())
for i in range(n):
l,r=list(map(int,input().split()))
if(lcm(l,r)==r):
print(l,r,sep=' ')
elif(r-l<l):
print(-1,-1,sep=' ')
else:
print(l,2*l, ... |
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest comm... | 1 | import time
def comp(code, number):
newcode = ''
for i in range(len(code)):
if code[i] == number[i]:
newcode += code[i]
else:
break
return newcode
n = int(raw_input())
adress = [raw_input() for i in range(n)]
code = adress[0]
for i in range(1, n):
code = comp(code, adress[i])
print len(code)
|
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions:
* Question 1: Are you subscribing to Newspaper X?
* Question 2: Are you subscribing to Newspaper Y?
As the result, A respondents answered "yes" to Question 1, and B respondents answer... | 3 | N, A, B = list(map(int, input().split()))
print(min(A, B), max(- N + A + B, 0))
|
You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 Γ 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures.
Yo... | 3 | t=int(input())
for l in range(t):
n=int(input())
e=0
o=0
c=0
a=input().split()
for i in a:
if int(i)%2==0:
e+=1
if o>0:
print("NO")
c=1
break
else:
o+=1
if e>0:
print("... |
Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x = 0. Mezo starts sending n commands to Zoma. There are two possible commands:
* 'L' (Left) sets the position x: =x - 1;
* 'R' (Right) sets the position x: =x + 1.
Unfortunately, Mezo's controller malfunctions sometimes. ... | 3 | n=int(input())
s=input()
print(abs(s.count('L')*-1-1*s.count('R'))+1) |
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm... | 3 | print(int(''.join(bin('><+-.,[]'.index(i)+8)[2:]for i in input()),2)%1000003) |
Little Ashish got a lot of strings as his birthday gift. He does not mind getting so many strings for free; in fact, he loves them. But, on noticing all the strings he received as a gift, Little Ashish, who's also a snob and a bit OCD kind of a guy, realizes that he does not like the way in which the strings are arrang... | 1 | from collections import Counter
def SortedString():
T = int(raw_input())
for t in range(T):
instr = raw_input()
charcount = Counter(instr)
outlist = []
append = outlist.append
for char,count in charcount.most_common():
append((char,count))
outlist.sort(key = lambda tup:(tup[1],tup[0]))
finalstr = ''
... |
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths... | 3 | n = int(input())
l = list(map(int,input().split()))
print('Yes' if (sum(l)-max(l)) > max(l) else 'No') |
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'... | 1 | import sys
lines = sys.stdin.readline()
s=lines.split()
if int(s[0])%int(s[2])==0:
x=int(s[0])/int(s[2])
else:
x=int(s[0])/int(s[2])+1
if int(s[1])%int(s[2])==0:
y=int(s[1])/int(s[2])
else:
y=int(s[1])/int(s[2])+1
print x*y
|
Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant is described by a string of length n which contains characters ... | 3 | import sys
def input():
return sys.stdin.readline().rstrip()
def input_split():
return [int(i) for i in input().split()]
t = int(input())
for tests in range(t):
n,k = input_split()
s = input()
safe = [True for i in range(n)]
ind = 0
while (ind < n):
if s[ind] == '1':
j = 0
while (ind < n and j <= k):
... |
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 β€ x β€ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (w... | 3 | def make_int(num):
return int(num)
def check_x(x):
if x >= 1 and x <= int(1e9):
return x
else:
return -1
if __name__ == "__main__":
num = input().split()
k = make_int(num[1])
num = make_int(num[0])
arr = []
arr = input().split()
arr = list(map(make_int, ... |
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | 1 | '''input
119 119 119 119 119
0 0 0 0 0
10 0
'''
X = [500, 1000, 1500, 2000, 2500]
M = map(int, raw_input().split())
W = map(int, raw_input().split())
H = map(int, raw_input().split())
ans = 0
for i in xrange(len(M)):
# print W[i], (1 - M[i]/250.0), (1- M[i]/250) * X[i]
ans += max(0.3 * X[i], (1 - M[i]/250.0) * X[i] ... |
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at lea... | 3 | t = int(input())
import math
while t>0:
n = int(input())
r, p, s = map(int, input().split())
st = input()
reach = math.ceil(n/2)
count = 0
output = ""
for i in st:
if i == 'R':
if p>0:
p -= 1
output += "P"
co... |
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 β€ si β€ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu... | 1 | n = int(raw_input())
s=map (int,raw_input().split())
count=[0,0,0,0,0]
taxi=0
for _ in s:
count[_]+=1
#print count
taxi+=count[4]
count[4]=0
#print count
#print taxi
taxi+=count[3]
count[1]-=count[3]
count[3]=0
#print count
#print taxi
taxi+=count[2]/2
if count[2]%2>0:
taxi+=1
count[1]-=2
if count... |
Theatre Square in the capital city of Berland has a rectangular shape with the size n Γ m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a Γ a.
What is the least number of flagstones needed to pave the Square? It'... | 3 | import math
n,m,a=map(int,input().split())
s=int(math.ceil(m/a))*int(math.ceil(n/a))
print(s) |
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round elemen... | 1 | N=input()
s,a=raw_input().split(),[0]*2*N
for i in range(0,2*N):a[i]=int(s[i].split('.')[1])
x,t,ans=a.count(0),sum(a),2e9
for i in range(max(N-x,0),min(2*N-x,N)+1):ans=min(ans,abs(t-i*1000))
print '%.3f'%(ans/1000.0)
|
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | 3 | import sys
chk = [0] * 200001
prm = []
fact = {1: [1]}
for i in range(2, 200001):
if chk[i] == 0:
prm.append(i)
j = 1
while True:
if i * j > 200000:
break
if i * j not in fact:
fact[i * j] = [i]
else:
fact[i... |
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).
The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
Note
θ§£θͺ¬
Input
In the first line, the number of cards n (n β€ 52) is given.
In the following n line... | 1 | S =[i+1 for i in xrange(13)]
H =[i+1 for i in xrange(13)]
C =[i+1 for i in xrange(13)]
D =[i+1 for i in xrange(13)]
#[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
n = input()
for i in xrange(n):
c, a = raw_input().split()
if c == "S":
for j in xrange(len(S)):
if S[j-1] == int(a):
... |
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
... | 3 | n=int(input())
a=[int(i)for i in input().split()]
print(((n-1)*max(a))-(sum(a)-max(a))) |
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()))
a = list(map(int,input().split()))
w = 0
for i in a :
w += 1 if i<= h else 2
print( w )
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.