problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
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... | 3 | k = list(input())
n = int("".join(k))
m = len(k)-1
i = 0
ans = 0
if n%(10**m) == 0:
print(10**m)
else:
while n // 10 != 0:
if n%10 == 0:
n //= 10
else:
ans += (10**i) * (10 - (n%10) )
n //=10
n+=1
## print("n", n)
## print("ans", an... |
In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. Team BowWow has arrived at the station at the time s and it is trying to co... | 3 | s = input()
ans = (len(s) - 1) // 2
add = False
for i in range(1, len(s)):
if s[i] == '1':
add = True
if add or len(s) % 2 == 0:
ans += 1
print(ans)
|
Recently Vova found n candy wrappers. He remembers that he bought x candies during the first day, 2x candies during the second day, 4x candies during the third day, ..., 2^{k-1} x candies during the k-th day. But there is an issue: Vova remembers neither x nor k but he is sure that x and k are positive integers and k >... | 3 | for _ in range(int(input())):
n=int(input())
if n==1:
print(1)
else:
for i in range(2,31):
d=(pow(2,i)-1)
if n%d==0:
print(n//d)
break |
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | 3 | n = int(input())
s = input()
months1 = "31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31"
months2 = "31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31"
months3 = "31 28 31 30 31 30 31 31 30 31 30 31 31 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 | t = int(input())
count = 0
for i in range(t):
y = (input())
if y=='++X':
count+=1
elif y=='X++':
count+=1
else:
count-=1
print(count)
|
Maxim wants to buy some games at the local game shop. There are n games in the shop, the i-th game costs c_i.
Maxim has a wallet which can be represented as an array of integers. His wallet contains m bills, the j-th bill has value a_j.
Games in the shop are ordered from left to right, Maxim tries to buy every game i... | 3 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split())) + [-1]
ans = 0
curr = 0
for i in range(n):
if (b[curr] >= a[i]):
ans += 1
curr += 1
print(ans) |
This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.
To make a toast, each friend needs nl ... | 3 | n, k, l, c, d, p, nl, np = map(int,input().split())
drink = (k*l)//nl
print(int(min(drink,c*d,p//np)/n)) |
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handk... | 3 | n = int(input())
s = n
for i in range(n + 1):
print(s * ' ', end='')
s -= 1
if i > 0:
for g in range(i + 1):
print(str(g) + ' ', end='')
for g in range(i - 1):
print(str(i - 1 - g) + ' ', end='')
print(0)
s = 1
for i in range(n):
print(s * ' ', end='')
s... |
Alice and Bob are decorating a Christmas Tree.
Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have y yellow ornaments, b blue ornaments and r red ornaments.
In Bob's opinion, a Christmas Tree will be beautiful if:
* the number of blue ornaments used is greater b... | 3 | #send help plz
from math import inf
def main():
arr=input().split()
maxi=min((int(arr[0]),int(arr[1])-1,int(arr[2])-2))
print(maxi*3+3)
main()
|
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 |
import sys
def write_to_stdout(d):
sys.stdout.write('%f\n' % (d))
def read_input():
n, l = input().rstrip().split()
coordinates = input().rstrip().split()
return int(n), int(l), [int(i) for i in coordinates]
def find_d(coordinates, l, n):
max_dist = max(coordinates[0], l - coordinates[-1])
... |
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutio... | 3 | n, m, k = map(int, input().split())
if 2*n*m % k:
print('NO')
else:
print('YES')
print(0, 0)
print(n, 1)
print(n * ((2 * m + k - 1) // k) - 2 * n * m // k, (2 * m + k - 1) // k)
|
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
<image>
The park consists of 2n + 1 - 1 squares connected by roads... | 1 | def main():
n = int(raw_input())
N = 2 ** n
a = [0, 0] + map(int, raw_input().split())
s = [0] * (N * 2)
mx = max
for i in xrange(N + N):
s[i] = a[i]
ans = 0
for i in xrange(N - 1, 0, -1):
x, y = s[i*2], s[i*2+1]
if x < y:
x, y = y, x
s[i] += x... |
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N).
For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.
We say a set of choices to put a ball or not in the boxes is good when the following con... | 3 | n=int(input())
a=[0] + list(map(int,input().split()))
boxes=[0]*(n+1)
m=0
b=[]
for i in reversed(range(1,n+1)):
if sum(boxes[i::i])%2 != a[i]:
boxes[i]=1
m+=1
b.append(i)
print(m)
print(*b)
|
You are given a string s, consisting only of characters '0' or '1'. Let |s| be the length of s.
You are asked to choose some integer k (k > 0) and find a sequence a of length k such that:
* 1 ≤ a_1 < a_2 < ... < a_k ≤ |s|;
* a_{i-1} + 1 < a_i for all i from 2 to k.
The characters at positions a_1, a_2, ...,... | 3 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ... |
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):
n,k=map(int,input().split())
if (n>=k*k) and (n%2==k%2):
print("YES")
else:
print("NO")
t-=1 |
While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid.
A 1-st order rhombus is just a square 1 × 1 (i.e just a cell).
A n-th order rhombus for all n ≥ 2 one obtains from a n-1-th order rhombus adding all cells which have a common side with it to it (look ... | 3 | a = [ 1 ]
for i in range(2, 101):
a.append(a[-1]+4*(i-1))
print( a[ int(input()) - 1 ] )
|
An n × n table a is defined as follows:
* The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for all i = 1, 2, ..., n.
* Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defin... | 3 | inp=input
li=list
iinp=lambda : int(inp())
ent=lambda : map(int,inp().split())
lient=lambda : [int(i) for i in inp().split()]
li0= lambda x: [0 for i in range(x)]
n=iinp()
if n<=2: print(n)
else:
mat=[[1 for i in range(n)]]
for i in range(1,n):
mat.append([1]+[0 for i in range(1,n)])
for i in range... |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contain... | 3 | from sys import stdin,stdout
import sys
from bisect import bisect_left,bisect_right
import heapq
# stdin = open("input.txt", "r");
# stdout = open("output.txt", "w");
n,k=stdin.readline().strip().split(' ')
n,k=int(n),int(k)
ctr=0
c=1
arr=[]
while c<=n:
if c&n!=0:
arr.append(-1*c)
c=c*2
def disp(arr):
for i in ... |
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course.
You decided to rob a town's blacksmith and you take a follower with you. You can carry at most p units and your follower — at most f units.
... | 3 | from sys import stdin, stdout
import heapq as hp
def findBest(C,N1,N2,W1,W2):
if W1>W2: return findBest(C,N2,N1,W2,W1)
A=min(N1,C//W1)
B=min(N2,(C-A*W1)//W2)
return A+B
def find(C1,C2,N1,N2,W1,W2):
M=0
for i in range(min(N1,C1//W1)+1):
A=i
B=min(N2,(C1-i*W1)//W2)
M=max(... |
Reziba has many magic gems. Each magic gem can be split into M normal gems. The amount of space each magic (and normal) gem takes is 1 unit. A normal gem cannot be split.
Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is N units. If a magic g... | 3 | import sys
from math import trunc
# How to multiply matrices in 32 bit python?
# Solution: Use doubles with homemade mult and mod.
# This should be around 6-10 times faster than using int
# and close to the speed you'd get in 64 bit python.
MOD = 10**9 + 7
MODF = float(MOD)
MODF_inv = 1.0/MODF
FLOAT_PREC = float(2**52... |
Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from the string and the remaining parts of the string get concatenated.... | 3 | t=int(input())
for i in range(t):
s=input()
n=len(s)
l=[]
for i in range(n):
l.append(s[i])
i=0
d=[]
for i in range(n):
if len(d)==0:
d.append(l[i])
else:
if d[-1]=='A' and l[i]=='B':
d.pop()
elif d[-1]=='B' and l[i]... |
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift ... | 3 | n,k=map(int,input().split())
l=list(map(int,input().split()))
ls=[0]*(100)
a=0
y=0
h=0
c=0
d=0
for i in range(n):
ls[l[i]%k]+=1
#print(ls)
if(k!=2):
for i in range(1,k//2+1):
if(i!=k-i):
d=min(ls[i],ls[k-i])
else:
break
if(d!=0):
a=a+d
if(k%2==0):
... |
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employ... | 3 | k=int(input())
c=0
for i in range(1,(k//2)+1):
if((k-i)%i==0):
c=c+1
print(c) |
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 | def waterMaleon(w):
if(w%2 == 1 or w<4):
print("NO")
return
# Now weight is Not None
# if watermaleon weight is less than 4 then also not possible
else:
print("YES")
w=int(input())
waterMaleon(w) |
Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is n.
There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains 2 apartments, every other floor contains x apartments each. Apartments are numbered starting from one, from... | 3 | import math
t=eval(input())
for i in range(t):
n,x=map(int,input().split())
if(n<=2):print(1)
else:
print(1+math.ceil((n-2)/x)) |
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'... | 3 | a = list(map(int,input().split()))
z=[]
for i in range(a[1]):
z+=[tuple(map(int,input().split()))]
z.sort()
q=True
while len(z)!=0:
if z[0][0]>= a[0]:
print("NO")
exit()
a[0]+=z[0][1]
z=z[1:]
print("YES")
|
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 = (map(int,input()))
k = set(map(int,input().split()))
if 1 in k:
print("hard")
else:
print ("easy") |
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing o... | 1 | n = int(raw_input())
for i in range(n):
print 10000000 - n + i,
|
You are given an integer sequence 1, 2, ..., n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A) - sum(B)| is minimum possible.
The value |x| is the absolute value of x and sum(S) is the sum of elements of the set S.
Input
The first line of the input ... | 3 | n=int(input())
rem=n%4
if rem==1 or rem==2:
print(1)
else:
print(0) |
n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner.
For each of the p... | 3 | firstInput = input().split()
n = int(firstInput[0])
k = int(firstInput[1])
players = list(map(int, input().rstrip().split()))
numOfWins = 0
temporaryArray = []
currentPlayerWinner = players[0]
if n == 2:
if players[0] > players[1]:
print(players[0])
else:
print(players[1])
elif k > n**2:
... |
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one.
At least how many operations are necessary to satisfy the following conditions?
* For every i (1≤i≤n), the sum of the terms from the 1-st through i-... | 3 | n = int(input())
a = [int(i) for i in input().split()]
b = a[::]
ans1 = ans2 = 0
sign = 1
total = 0
for i in range(n):
total += a[i]
if total * sign <= 0:
k = abs(total - sign)
ans1 += k
total = sign
sign *= -1
sign = -1
total = 0
for i in range(n):
total += b[i]
if total * ... |
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers... | 3 | n = int(input())
n = 2 * n
x = round(n ** (1/2))
if n ==x * (x + 1) or n == x * (x - 1):
print("YES")
else:
print("NO") |
You are given n strings s_1, s_2, …, s_n consisting of lowercase Latin letters.
In one operation you can remove a character from a string s_i and insert it to an arbitrary position in a string s_j (j may be equal to i). You may perform this operation any number of times. Is it possible to make all n strings equal?
In... | 3 | from collections import defaultdict
for _ in range(int(input())):
n = int(input())
d = defaultdict(int)
for i in range(n):
s = input()
for j in s:
d[j] += 1
for i in d.values():
if i % n != 0:
print("NO")
break
else:
print("YES") |
For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:
* Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.
* Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \time... | 3 | n = int(input())
l = sorted(list(map(int,input().split())),reverse=True)
mod = 10**9+7
ans = 0
for i in range(n-1,-1,-1):
ans += ((2+i)*l[i])
b = pow(2,2*n-2,mod)
print(ans*b%mod) |
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maxi... | 3 |
# -*- coding: utf-8 -*-
# @Date : 2019-03-07 21:05:32
# @Author : raj lath (oorja.halt@gmail.com)
# @Link : link
# @Version : 1.0.0
import sys
sys.setrecursionlimit(10**5+1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambd... |
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 | #https://codeforces.com/problemset/problem/118/A
s = input().lower()
s1 = ''
for i in range(len(s)):
if s[i] in 'aieyou':
continue
s1 += '.' + s[i]
print(s1) |
Alice has a lovely piece of cloth. It has the shape of a square with a side of length a centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length b centimeters (where b < a). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to ... | 3 | def is_prime(n):
'''check if integer n is a prime'''
# make sure n is a positive integer
n = abs(int(n))
# 0 and 1 are not primes
if n < 2:
return False
# 2 is the only even prime number
if n == 2:
return True
# all other even numbers are not primes
if not n & 1:... |
You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42.
Your task is to remove the minimum number of elements to make this array good.
An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15... | 3 | if __name__ == '__main__':
n = 0
Arr = []
n = int(input())
Arr = list(map(int,input().split()))
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t5 = 0
t6 = 0
# 4 8 15 16 42 23
for i in range(n):
if Arr[i] == 4:
t1 += 1
if Arr[i] == 8:
if t2 < t1:
... |
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perfor... | 3 | n, k = map(int, input().split())
a = sorted(map(int, input().split()))
i = 1
while True:
ans = a[-i] - a[i - 1]
if (a[i] - a[i - 1]) * i >= k:
ans -= k // i
break
ans = a[-i] - a[i]
k += a[i - 1] * i
k -= a[i] * i
if (a[-i] - a[-i - 1]) * i >= k:
ans -= k // i
bre... |
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
n,m,a=map(int,sys.stdin.readline().split())
w=m/a
x=(float(m)/a)%1!=0
y=n/a
z=(float(n)/a)%1!=0
print (w+x)*(y+z)
# no_of_flagstones = ( m/a + (float(m)/a)%1!=0 ) * ( n/a + (float(n)/a)%1!=0 )
# print no_of_flagstones |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ... | 3 | import math
def main_function():
n, d = [int(i) for i in input().split(" ")]
l = [int(i) for i in input().split(" ")]
count = 0
for i in range(len(l) - 1):
for j in range(i + 1, len(l)):
if abs(l[i] - l[j]) <= d:
count += 2
return str(count)
print(main_functio... |
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 | def is_dividable(num):
return 'YES' if (num > 3 and not num & 1) else 'NO'
weight = int(input())
print(is_dividable(weight))
|
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... | 1 | e = int(raw_input())
if (e <= 2):
print "NO"
elif (e % 2 == 0):
print "YES"
else:
print "NO"
|
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 | t = int(input())
for _ in range(t):
n = int(input())
p = []
for __ in range(n):
p.append(list(map(int,input().split(' '))))
p.sort()
# print(p)
a,b = 0,0
ans = ''
f = 1
for point in p:
x,y = point
if x >= a and y >= b:
ans += 'R' * (x-a)
... |
"Not every love story has a happy ending!"- Little Jhool was certainly a con man, fooling people by telling them about their future, [The first problem!] but he loved his girl - truly! But, Big Jhool, his girlfriend, was shocked and had broken up with him after getting to know that Little Jhool was a con man. Now, our ... | 1 | r = input()
pat = map(int, raw_input().split())
s = sum(pat)
spat = [s-i for i in pat if (s-i)%2]
if s%2:
print s
elif spat:
print max(spat)
else:
print ':(' |
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct str... | 3 | '''a=int(input())
l=[]
for ddfdf in range(a):
n=int(input())
s1=input()
t1=input()
s=[];t=[]
for i in s1:
s.append(i)
for i in t1:
t.append(i)
f=0
for i in range(n):
for j in range(n):
s[i],t[j]=t[j],s[i]
#print('s=',end=' ');... |
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... | 1 | #!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys, math, random, operator
from string import ascii_lowercase, ascii_uppercase
from fractions import Fraction, gcd
#from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from Queue import Queue, PriorityQueue
from collectio... |
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 | import sys
def solution():
result = 0
s1 = input()
s2 = input()
for i in range(len(s1)):
result = ord(s1[i].lower()) - ord(s2[i].lower())
if result > 0:
result = 1
break
elif result < 0:
result = -1
break
else:
... |
Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers x, y are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the number... | 1 | X, Y, M = map(int, raw_input().split())
if X > Y:
X, Y = Y, X
ans = 0
while Y < M:
Z = X + Y
if Z <= X:
ans = -1
break
else:
ans += (Y - X) / Y + 1
X, Y = Y, ((Y - X) / Y + 1) * Y + X
print ans
|
Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422.
Help him to count the sum of goodness of all integers from L to R, inclusive. Since the answer can be too lar... | 1 | tests = int(raw_input())
for _ in xrange(tests):
l,r = [int(num) for num in raw_input().split()]
x = l
res = 0
while x <= r:
digits = len(str(x))
maxVal = (10**digits) - 1
minVal = min(maxVal,r)
res = res + digits * (minVal + x)*(minVal - x + 1) / 2
x = int(minVal... |
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())
for _ in range(0,T):
n=int(input())
a,b=map(int,input().split())
s=input()
s=[int(x) for x in input().split()]
for i in range(0,len(s)):
a,b=map(int,input().split())"""
T=int(input())
for _ in range(0,T):
n=int(input())
L=[]
while(n>0):
N=str(n)
... |
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... | 3 | x,y=input().split(' ')
s=0
if int(x)%2==0:
if int(y)<=int(x)/2:
s=1+(int(y)-1)*2
else:
s=(int(y)-int((int(x)/2)))*2
else:
if int(y)<=(int(x)+1)/2:
s=1+(int(y)-1)*2
else:
s=(int(y)-int((int(x)/2))-1)*2
print(s) |
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... | 3 | x = int(input())
lst = list(map(int, input().split()))
lst1=[]
lst2=[]
lst3=[]
lst4=[]
for i in lst:
if i==4:
lst4.append(i)
if i==3:
lst3.append(i)
if i==2:
lst2.append(i)
if i==1:
lst1.append(i)
taxis=0
sum2 = len(lst2)*2
length1 = len(lst1)
length3 = len(lst3)
oneLeft ... |
problem
At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen.
Given the price of pasta and juice for a ... | 3 | p1, p2, p3, j1, j2=[int(input()) for _ in range(5)]
print(min(p1, p2, p3)+min(j1, j2)-50)
|
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that... | 3 | a = list(map(int, input().split()))
s = sum(a)
if s % 5 != 0 or s == 0:
print(-1)
else:
print(s // 5)
|
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... | 1 | s = raw_input()
print '.'+'.'.join([c for c in s.lower() if c not in 'aeiouy']) |
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each c... | 3 | t=int(input())
for q in range(t):
r={'a':'b','b':'c','c':'a'}
s=list(input())
n=len(s)
c=0
flag=0
for i in range(0,n):
if s[i]!='?':
if i>=1 and s[i]==s[i-1]:
flag=1
break
elif s[i]=='?':
if i==0:
s[i]='a'
else:
s[i]=r[s[i-1]]
if i<n-1:
if s[i]==s[i+1]:
s[i]=r[s[i]]
if fl... |
Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.
These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now sh... | 3 | import statistics
t=int(input())
for i in range(t):
a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
z=c
y=c
x=b
print(x,y,z)
|
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 | num_of_statements = input()
x = 0
for i in xrange(num_of_statements):
operation = raw_input()
if operation == "++X" or operation =="X++":
x = x+1
else:
x = x-1
print x |
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()
c=0
for i in s:
if(ord(i)<91):
c+=1
else:
c-=1
if(c>0):
print(s.upper())
else:
print(s.lower()) |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the ... | 1 | temp = raw_input()
n, m, q = temp.split(' ')
n = int(n)
q = int(q)
mat = []
for i in xrange(n):
temp = raw_input()
mat.append(temp.split(' '))
maxinrow = []
for i in xrange(n):
temp = mat[i]
temp = ''.join(temp)
temp = temp.split('0')
maxlen = len(max(temp))
maxinrow.append(maxlen)
for x in xrange(q):
temp ... |
You have a large electronic screen which can display up to 998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 7 segments which can be turned on and off to compose different digits. The following picture describes how you can dis... | 3 | """
Oh, Grantors of Dark Disgrace,
Do Not Wake Me Again.
"""
# import stackprinter
# stackprinter.set_excepthook(style='color')
# import pysnooper
# @pysnooper.snoop()
def solve():
for _ in range(ii()):
n = ii()
if n%2 == 0:
print(int("1"*(n//2)))
elif n == 3:
pri... |
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | 3 | t=int(input())
k=False
a=[4,7,44,47,74,77,444,447,477,744,747,777]
for i in a:
if t==i:
k=True
elif t%i==0:
k=True
if k==True:
print('YES')
else:
print('NO')
|
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds.
Note that a+b=15 and a\times b=15 do not hold at the same time.
Constraints
* 1 \leq a,b \leq 15
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b
Output
If a+b=15,... | 3 | stra, strb = input().split()
a = int(stra)
b = int(strb)
if a+b == 15:
print('+')
elif a*b == 15:
print('*')
else:
print('x')
|
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them ... | 3 | t = int(input())
for _ in range(t):
a, b, c = map(int, input().split())
if a >= c:
print("-1", end=" ")
else:
print("1", end=" ")
if a*b <= c:
print("-1")
else:
print(b) |
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you... | 3 | a, n = map(int, input().split())
x =list(map(int, input().split()))
y = list(map(int, input().split()))
dist1 = []
dist2 = []
for i in range(1, a):
dist1.append(x[i] - x[i - 1])
dist2.append(y[i] - y[i - 1])
dist1.append(n - sum(dist1))
dist2.append(n - sum(dist2))
for start in range(len(dist1)):
bool = Tr... |
Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.
Polycarp decided to store the hash of the password, generated by the following algorithm:
1. take the password p, consisting of lowercase Latin letters, and shuffle the l... | 3 | import string
def check(password, hashpassword):
passwordDict = dict.fromkeys(string.ascii_lowercase, 0)
hashDict = dict.fromkeys(string.ascii_lowercase, 0)
for j in password:
passwordDict[j]+=1
for k in hashpassword:
hashDict[k]+=1
temp= list(passwordDict.keys())
for i i... |
You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squa... | 3 | l = list(map(int,input().split()))
print(l[0]*l[1]//2)
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if... | 1 | s = raw_input()
try:
a = s.index('h')
b = s.index('e',a+1)
c = s.index('l',b+1)
d = s.index('l',c+1)
e = s.index('o',d+1)
if a<b<c<d<e:
print 'YES'
else:
print 'NO'
except:
print 'NO' |
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ... | 3 | n, k = map(int, input().split())
list = input().split()
cutoff = list[k - 1]
ans = 0
abc = int
for i in range(len(list[::-1])):
if abc(list[::-1][i]) >= abc(cutoff) and int(list[::-1][i]) > 0:
ans = n - i
break
print(ans) |
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 | n = int(input())
for i in range(n):
x, y = map(int, input().split())
a, b = map(int, input().split())
print(a * abs(x - y) + min(2 * a, b) * min(x, y))
|
There is a trampoline park with n trampolines in a line. The i-th of which has strength S_i.
Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice.
If at the moment Pekora jumps on trampoline i, the trampoline will launch her to position i + S_i, and S_i wi... | 3 | #######################################################################################################################
# Author: BlackFyre
# Language: PyPy 3.7
#######################################################################################################################
from sys import stdin, stdo... |
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka ... | 3 | #winners never quit, quiters never win
from collections import deque as de
import math
from collections import Counter as cnt
class My_stack():
def __init__(self):
self.data = []
def my_push(self, x):
return (self.data.append(x))
def my_pop(self):
return (self.data.pop())
def my_... |
Two players A and B have a list of n integers each. They both want to maximize the subtraction between their score and their opponent's score.
In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an elem... | 3 | from functools import*
n=int(input())
[a,b]=(list(map(int, input().split())) for _ in range(2))
v=list(sum(i) for i in [a,b])
a+=b;
a.sort(reverse=True)
for i in range(2*n):
#print("tod ",v[0]," ",v[1])
#print(a[i])
v[i&1]+=a[i]
#print(len(v))
print((v[0]-v[1])//2)
|
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 | mx = 0
s = 0
for i in range(int(input())):
a, b = map(int, input().split())
s += b - a
if s > mx: mx = s
print(mx)
|
Bawris, are wells or ponds in which the water may be reached by descending a set of steps. They may be covered and protected and are often of architectural significance.
Rajasthan has a history of maintaining bawris, but now they are of architectural significance hence ASI is interested to save a historic bawris from... | 1 | for i in xrange(input()):
a,b,c,d=map(int,raw_input().split())
if(a>=c and b>=d) or(a>=d and b>=c):
print "Possible"
else:
print "Not Possible" |
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists.
You have to answer t independent test cases.
Recall that the substring s[l ... | 3 | t = int(input())
for q in range(t):
n, a, b = map(int, input().split())
g = ""
for i in range(b):
g += chr(ord('a') + i)
for j in range(a - b):
g += 'a'
for i in range(n):
print (g[i % a], end = '')
print()
|
A string s of length n can be encrypted by the following algorithm:
* iterate over all divisors of n in decreasing order (i.e. from n to 1),
* for each divisor d, reverse the substring s[1 ... d] (i.e. the substring which starts at position 1 and ends at position d).
For example, the above algorithm applied t... | 3 | n=int(input())
x=list(input())
asdf=[]
for i in range(1,n+1):
if n%i==0: asdf.append(i)
for i in asdf:
xcxc=x[i-1::-1]
for j in range(i):
x[j]=xcxc[j]
print(''.join(x)) |
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 | import math
n1=int(input())
for x in range(n1):
a=int(input())
b=input()
d=b.split(" ")
arr=[]
for y in range(a):
arr.append(int(d[y]))
test="NO"
for y in range(1,a-1):
if(arr[y]>arr[y-1] and arr[y]>arr[y+1]):
print("YES")
print(y,y+1,y+2,end=" ")
... |
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"
Igor just c... | 1 | a=[]
for i in range(input()):
a+=raw_input()
print["WIN","FAIL"][sorted(a)==list(" 1122334455")] |
Lunar New Year is approaching, and you bought a matrix with lots of "crosses".
This matrix M of size n × n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≤ i, j ≤ n. We define a cross appearing in the i-th row and the j-th column (1 < i... | 3 | n=int(input())
list=[list(input()) for y in range(n)]
#print(list)
cnt=0
for i in range(1,n-1):
for j in range(1,n-1):
if list[i][j]=='X' and list[i+1][j+1]=='X' and list[i-1][j-1]=='X' and list[i+1][j-1]=='X' and list[i-1][j+1]=='X':
cnt+=1
print(cnt) |
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | 3 |
vowels = ['a', 'e', 'i', 'o', 'u']
a = input()
b = input()
c = input()
a = len([vowel for vowel in a if vowel in vowels])
b = len([vowel for vowel in b if vowel in vowels])
c = len([vowel for vowel in c if vowel in vowels])
if a == c == 5 and b == 7:
print("YES")
else:
print("NO")
|
Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example,
* f(599) = 6: 599 + 1 = 600 → 60 → 6;
* f(7) = 8: 7 + 1 = 8;
* f(9) = 1: 9 + 1 = 10 → 1;
* f(10099) = 101: 10099 + 1 = 10100 → 1010 → 101.
... | 3 | n = int(input())
d = set()
i = 0
while i < 100000:
d.add(n)
n += 1
while n % 10 == 0:
n //= 10
i += 1
print(len(d))
|
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t... | 3 | n=int(input())
s=input()
cn=0
cz=0
for i in s:
if i == 'z':
cz += 1
elif i=='n':
cn += 1
a=[]
for i in range(cn):
a.append(1)
for i in range(cz):
a.append(0)
print(" ".join(map(str,a))) |
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=map(int, input().split())
S=input()
if S.find("##", A, B)<0 and S.find("##", C, D)<0:
if C<D:
print("Yes")
else:
if S.find("...", B-2, D+1)>=0:
print("Yes")
else:
print("No")
else:
print("No") |
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where ... | 3 | n = int(input())
h = int(input())
w = int(input())
height = n - h + 1
width = n - w + 1
print(str(height*width))
|
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | 1 | from string import *
n=input()
s=raw_input()
s=s.lower()
l=list(ascii_lowercase)
flag=True
for i in l:
if i not in s:
flag=False
break
if flag:
print 'YES'
else:
print 'NO'
|
There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass ... | 3 | def arr_to_int(arr):
for i in range(len(arr)):
arr[i] = int(arr[i])
return arr
n = int(input()) # levels
little_x = input().split()[1:]
little_y = input().split()[1:]
levels = dict()
result = "I become the guy."
arr_to_int(little_x)
arr_to_int(little_y)
for i in little_x:
if not i in levels:
... |
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco... | 3 | n = int(input())
feeling = ["hate","love"]
cnt = 0
for i in range(n-1):
print("I "+feeling[cnt]+" that",end=" ")
cnt = (cnt+1)%2
print("I "+feeling[cnt]+" it") |
<image>
Input
The input contains a single integer a (0 ≤ a ≤ 15).
Output
Output a single integer.
Example
Input
3
Output
13 | 3 | line = int(input())
arr = [15, 14, 12, 13, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7]
#
#
#
#
#
#
print(arr[line])
|
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | 3 | string=input()
counter=0
v=[]
for x in string:
counter+=1
if x=='A' or x=='E' or x=='I' or x=='O' or x=='U' or x=='Y':
v.append(counter)
counter=0
v.append(counter+1)
print(max(v))
|
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz).
The picture showing the correct sudoku solution:
<image>
Blocks are bordered with bold black color.
Your task is to change at most 9 elements of this field (i.e. choose s... | 3 | def main():
for _ in range(int(input())):
matrix = []
for i in range(9):
s = input()
row = []
for j in range(len(s)):
row.append(ord(s[j])-ord('0'))
matrix.append(row)
for i in range(0,9):
for j in range(0,9,):
if matrix[i][j] == 1:
matrix[i][j]=2
# print()
for i in range(9):
f... |
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... | 1 | w = int(raw_input())
if w <= 2 or w > 100 or w % 2 != 0:
print('NO')
else:
print('YES') |
A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.
The store does not sell single clothing items — instead, it sells suits of two types:
* a suit of the first type consists of one tie and one jacket;
* a suit of the second type ... | 3 | a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = int(input())
if e > f:
cnt = min(a, d)
print(cnt * e + min(d - cnt, c, b) * f)
else:
cnt = min(d, b, c)
print(cnt * f + min(d - cnt, a) * e) |
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows:
... | 3 | t = int(input())
while t != 0:
t -= 1
n = int(input())
count = 0
for i in range(30000, 0, -1):
s = int(i*(3*i+1)/2)
while s<=n:
count +=1
n -=s
print(count)
|
There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | 3 | t=int(input())
a=list(map(int,input().split()))
for i in range(t):
if a[i]%4==0 or a[i]%2==0:
print(a[i]*4+1)
elif a[i]%4==3:
print(a[i]+1)
else:
print(a[i]*2+1) |
You are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in such a way that:
* No two students i and j such that |a_i - a_j| = 1 belong to the same team (i.e. skills of each pair of students in t... | 3 | q=int(input())
while q:
n=int(input())
ans=1
a=list(map(int,input().split()))
a.sort()
for i in range(len(a)-1):
if(a[i+1]-a[i]==1):
ans=2
break
print(ans)
q-=1 |
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | 3 | m,n=map(int,input().split())
dec=[]
for i in range(n):
a,b=map(str,input().split())
alen=len(a)
blen=len(b)
temp=[]
temp.append(a)
temp.append(b)
if alen<=blen:
temp.append(a)
else:
temp.append(b)
dec.append(temp)
word=""
stat=list(map(str,input().split()))
for i in s... |
This problem is same as the next one, but has smaller constraints.
Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time.
For each of the n days since the day Shiro moved to the n... | 3 | from collections import Counter
n = int(input())
l = list(map(int, input().split()))
res = 0
m = 0
MAX = 10**5+1
colors = 0
c_colors = [0]*MAX
c_counts = [0]*MAX
for i, val in enumerate(l):
c_colors[val] += 1
c_counts[c_colors[val]-1] -= 1
c_counts[c_colors[val]] += 1
m = max(m, c_colors[val])
if c_counts[1] =... |
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ... | 3 | playerCount = input()
scoreList = input()
playerCount = playerCount.split()
scoreList = scoreList.split()
kthPlacePlayer = int(playerCount[1]) - 1
totalNumOfPlayers = 0
for score in scoreList:
if int(score) < 1:
continue
elif int(score) >= int(scoreList[kthPlacePlayer]):
totalNumOfPlayers +=... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.