problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
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=list(range(1,int(input())+1))
s=""
for i in range(len(n)):
if n[i]%2!=0:
s+="I hate "
else:
s+="I love "
if i<len(n)-1:
s+="that "
else:
s+="it"
print(s) |
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, ... | 3 | k = int(input())
s = list(input())
s.sort()
ch=''
count=0
l = len(s)
for i in range(len(s)):
if i%k==0:
ch=s[i]
if s[i]==ch:
count+=1
if l==count and count%k==0:
for i in range(k):
for l in range(0,len(s),k):
print(s[l],end='')
else:
print(-1) |
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ... | 3 | n=int(input())
a=list(map(int,input().split()))
dict={}
for i in a:
if i in dict:
dict[i]+=1
else:
dict[i]=1
ans=max(dict.values())
print(ans) |
Artist Shinagawa was asked to exhibit n works. Therefore, I decided to exhibit the six sides of the cube colored with paint as a work. The work uses all six colors, Red, Yellow, Blue, Magenta, Green, and Cyan, and each side is filled with one color. Shinagawa changed the arrangement of colors even for cubic works with ... | 3 | import copy
class Dice:
def __init__(self, a, b, c, d, e, f):
self.top = a
self.front = b
self.right = c
self.left = d
self.behind = e
self.bottom = f
def S(self):
self.top, self.front, self.behind, self.bottom = self.behind, self.top, self.bottom, self... |
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
<image>
You should count, how many there are pai... | 3 | ans = 0
n, m = map(int, input().split())
for i in range(1010) :
for j in range(1010) :
if (i * i + j == n and i + j * j == m) :
ans += 1
print(ans) |
We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i.
There is one cursor. The cursor's location β is denoted by an integer in \{0, β¦, |s|\}, with the following meaning:
* If β = 0, then the cursor... | 3 | import sys
mod=10**9+7
t=int(sys.stdin.readline())
for _ in range(t):
x=int(sys.stdin.readline())
z=1
s=[i for i in sys.stdin.readline()][:-1]
length=len(s)
for i in range(1,x+1):
#print(length,'length')
#print(s,'s')
if len(s)>=x:
#print(int(s[i-1]))
... |
A tetromino is a figure formed by joining four squares edge to edge. We will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:
a60bcb8e9e8f22e3af51049eda063392.png
Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession... | 3 | A=list(map(int,input().split()))
ans=A[1]
I,J,L=A[0],A[3],A[4]
odd_cnt=I%2+J%2+L%2
if odd_cnt==0 or odd_cnt==3:
ans+=I+J+L
elif odd_cnt==1:
ans+=I+J+L-1
else:
if I*J*L:
ans+=I+J+L-1
else:
ans+=I+J+L-2
print(ans) |
Bob has a string s consisting of lowercase English letters. He defines s' to be the string after removing all "a" characters from s (keeping all other characters in the same order). He then generates a new string t by concatenating s and s'. In other words, t=s+s' (look at notes for an example).
You are given a string... | 3 | original = input()
replaced = original.replace("a","")
n = len(replaced)
if not n:
print(original)
elif(replaced[:n//2]==original[-n//2:]):
print(original[:-n//2])
else:
print(":(") |
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls M... | 3 | t = int(input())
lst = []
for i in range (t):
a = int(input())
lst.append(a//7 + 1)
for i in lst:
print(i) |
DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I M... | 3 | n = int(input())
A = [int(x) for x in input().split()]
print(A[-1]^max(A))
|
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day cons... | 3 | #2 3 20
#2 4 6 8 10 12 14 16 18 20
#3 6 9 12 15 18
f=1
C=0
n,m,z=map(int,input().split())
while m*f<=z:
if m*f%n==0:
C+=1
f+=1
print(C)
"""
s1={n}
s2={m}
f=2
while n*f<=z:
s1.add(n*f)
f+=1
f=2
while m*f<=z:
s2.add(m*f)
f+=1
print(len(s1.intersection(s2)))
"""
|
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 | word = input()
word = word.lower()
res = []
for char in word:
if char in {'a', 'o', 'y', 'e', 'u', 'i'}:
continue
else:
res.extend(['.', char])
print(''.join(res))
|
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... | 1 | n, h = map(int, raw_input().split())
heights = [int(i) for i in raw_input().split()[:n]]
width =0
for height in heights:
if height > h:
width += 2
else:
width+= 1
print width
|
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 1 | tc = int(raw_input())
cnt=0
for i in xrange(tc):
a,b,c = map(int,raw_input().split(' '))
if( (a+b+c) >= 2):
cnt+=1
print cnt
|
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
<image>
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the ... | 1 | y=raw_input()
y=y[:1]+y[2:]
n=len(y)
b=y.index('e')
a=int(y[b+1:])
y=y[:b]
if a==0:
if y[len(y)-1]=='0':
print y[0]
else:
print y[0]+'.'+y[1:]
else:
if a+1==len(y):
print y[:a+1]
elif a+1>len(y):
print y+'0'*(a+1-len(y))
else:
print y[:a+1]+'.'+y[a+1:]
|
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 | n=int(input())
x =list(map(int,input().strip().split()))
y=list(map(int,input().strip().split()))
s=0
for i in range (1,n+1):
p=x[1:]+y[1:]
if i in p:
s+=1
if s==n:
print("I become the guy.")
else:
print("Oh, my keyboard!") |
You will be given an integer a and a string s consisting of lowercase English letters as input.
Write a program that prints s if a is not less than 3200 and prints `red` if a is less than 3200.
Constraints
* 2800 \leq a < 5000
* s is a string of length between 1 and 10 (inclusive).
* Each character of s is a lowerca... | 3 | a = int(input())
s = input()
print((s, 'red')[a < 3200])
|
The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows:
* employee ::= name. | name:employee1,employee2, ... ,employeek.
* name ::= name of an employee
That is, the description of each employee consists of his name,... | 1 | s = filter(lambda x: x!=',',raw_input())
l,r = [],0
while s:
b = s.find('.')
if b<0: b=len(s)
if b: l.extend(s[:b].split(':'))
s = s[b+1:]
r+=l.count(l.pop())
print r |
Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges.
For each edge (u, v) find the minimal possible weight of the spanning tree that contains the edge (u, v).
The weight of the spanning tree is the sum of weights of all edges included in spanning t... | 1 | from sys import stdin, stdout
from operator import itemgetter
from itertools import repeat
def main():
n, m = map(int, stdin.readline().split())
dat = map(int, stdin.read().split(), repeat(10, 3 * m))
d = []
ev = [set() for _ in xrange(n + 1)]
ans = [0] * m
for i in xrange(m):
u, v, w = ... |
After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa... | 3 | n=int(input())
s=input()
if s.count('1')!=s.count('0'):
print(1)
print(s)
else:
for i in range(1,n):
if s[:i].count('1')!=s[:i].count('0') and s[i:].count('1')!=s[i:].count('0'):
print(2)
print(s[:i],s[i:])
break |
You are given an array a of length n, which initially is a permutation of numbers from 1 to n. In one operation, you can choose an index i (1 β€ i < n) such that a_i < a_{i + 1}, and remove either a_i or a_{i + 1} from the array (after the removal, the remaining parts are concatenated).
For example, if you have the ar... | 3 | for _ in range(int(input())):
a=int(input())
L=list(map(int,input().split()))
n=len(L)
if L[n-1]>L[0]:
print("YES")
else:
print("NO") |
Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... | 3 | n = int(input())
total_cube = 0
i = 0
while(True):
i += 1
total_cube += i
if (total_cube > n):
break
n -= total_cube
print(i - 1)
|
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Bi... | 3 | n = int(input())
b = False
for i in range(1, n):
if i % 2 == 0 and (n - i) % 2 == 0:
# print(i, n - i, "is even")
b = True
break
if b:
print("YES")
else:
print("NO")
|
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 β€ i β€ n.
He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his se... | 3 | n=int(input())
for i in range (n):
x=int(input())
if x%2==0:
y=int(x/2)-1
else:
y=int(x/2)
print(y+1)
|
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 β€ m β€ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o... | 3 | def discard():
n, m, k = map(int, input().rstrip().split())
special = list(map(int, input().rstrip().split()))
index = 0
last_in_page = k
total = 0
p = special[0]
while index < m:
if p > last_in_page:
last_in_page = p + (last_in_page - p) % k
drops = 0
whi... |
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players tak... | 3 | #!/usr/bin/python3
# http://codeforces.com/contest/832/problem/A
n, k = [int(x) for x in input().split()]
res = n // k
if res % 2 == 0:
print("NO")
else:
print("YES")
|
HQ9+ is a joke programming language which has only four one-character instructions:
* "H" prints "Hello, World!",
* "Q" prints the source code of the program itself,
* "9" prints the lyrics of "99 Bottles of Beer" song,
* "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q"... | 1 | if set(['H', 'Q', '9']) & set(raw_input()):
print 'YES'
else:
print 'NO' |
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 β€ i β€ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is it... | 1 | a=input()
b=raw_input()
read=b.split(' ')
c=[]
ans=1
for i in range(len(read)):
c.append(int(read[i]))
r=1
for i in range(1,len(c)):
if c[i]>=c[i-1]:
r+=1
if r>ans:
ans=r
else:
r=1
print ans
|
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | 3 | a = input()
q = int(a.count('Danil')) + int(a.count('Ann')) + int (a.count('Olya')) + int(a.count('Slava')) + int(a.count('Nikita'))
if q != 1 :
print ('NO')
else :
print ('YES')
|
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T
T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
Constraints
* The length of W β€ 10
* W consists of lower cas... | 3 | import sys
w=input().upper()
print(sys.stdin.read().upper().split().count(w)) |
Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and re... | 3 | """
Code of Ayush Tiwari
Codechef: ayush572000
Codeforces: servermonk
"""
# import sys
# input = sys.stdin.buffer.readline
def solution():
# This is the main code
n, k = map(int, input().split())
s = "".join(sorted(input()))
if s[0] != s[k-1] or k == n:
print(s[k-1])
elif s[k] == s[-1... |
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
* Tetrahedron. Tetrahedron has 4 triangular faces.
* Cube. Cube has 6 square faces.
* Octahedron. Octahedron has 8 triangular faces.
* Dodecahedron. Dodecahedron has 12 pentagonal faces.
*... | 3 | V = {
"Tetrahedron": 4,
"Cube": 6,
"Octahedron": 8,
"Dodecahedron": 12,
"Icosahedron": 20
}
n = int(input())
res = 0
for i in range(n):
p = input()
res += V[p]
print(res) |
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 | T = int(input())
for t in range(T):
word = input()
if len(word) <= 10:
print(word)
else:
print(f'{word[0]}{len(word)-2}{word[-1]}')
|
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 Γ 3 grid (one player always draws crosses, the other β noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the g... | 3 |
a = input() + input() + input()
cx, c0 = a.count('X'), a.count('0')
w = [a[i] for i, j, k in (
(0,1,2), (3,4,5), (6,7,8),
(0,3,6), (1,4,7), (2,5,8),
(0,4,8), (2,4,6)
) if a[i] == a[j] and a[j] == a[k]]
if not c0 in (cx - 1, cx) or 'X' in w and '0' in w:
print("illegal")
elif 'X' in w:
print(... |
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 | T=int(input())
while T:
R,G,B=map(int,input().split())
val=max(R,G,B)
if val==R:
if val-G-B-1>0:
print("No")
else:
print("Yes")
elif val==B:
if val-R-G-1>0:
print("No")
else:
print("Yes")
elif val==G:
if val-R-B-... |
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 | t = int(input())
for i in range(t) :
n = int(input())
s = input().split()
for j in range(n):
s[j] = int(s[j])
s.sort()
# print(s)
u = 1
w = 0
l = 1
for j in range(n-1):
if s[j] != s[j+1] :
u = u + 1
# print(l)
if l > w :
... |
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction <image> as a sum of three distinct positive fractions in form <image>.
Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that <image... | 3 | n = int(input())
if n == 1:
print(-1)
else:
# 2 / n = 1 / n + 1 / n
# represent 1 / n as sum of 2 fractions
x = n
y = n + 1
z = x * y
if z > int(1e9):
print(-1)
else:
print(f'{x} {y} {z}')
|
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" a... | 3 | s = input()
n = len(s)
for i in range(n + 1):
new_s = s[:i] + s[-i-(i<=n//2)] + s[i:]
if new_s == new_s[::-1]:
print(new_s)
break
else:
print('NA') |
Every year Santa Claus gives gifts to all children. However, each country has its own traditions, and this process takes place in different ways. For example, in Berland you need to solve the New Year's puzzle.
Polycarp got the following problem: given a grid strip of size 2 Γ n, some cells of it are blocked. You need... | 3 | # Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
def main():
for _ in range(int(input())):
input()
n,m=map(int,input().split())
a=defaultdict(list)
for i in range(m):
x,... |
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ... | 3 | n=int(input())
v=list(map(int,input().split()))
dict1={}
for i in v:
dict1[i]=dict1.get(i,0)+1
print(max(dict1.values())) |
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which ... | 3 | from collections import defaultdict, deque, Counter, OrderedDict
from bisect import insort, bisect_right, bisect_left
import threading, sys
def main():
n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
adj[a... |
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... | 3 | _=input()
print("YNEOS"[len(set(input().lower()))!=26::2]) |
The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...
What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now n cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone... | 3 | n, m = list(map(int, input().split()))
if(m == 0) :
print(1)
exit(0)
print(min(m, n - m)) |
Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c.
You h... | 3 | a,b,c,d=input().split(' ')
x = [int(a),int(b),int(c),int(d)]
x.remove(max(x))
print((x[0]+x[1]-x[2])//2, (x[1]+x[2]-x[0])//2, (x[2]+x[0]-x[1])//2)
|
Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!
A password is an array a of n positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them ... | 3 | t=int(input())
c=[]
for i in range(t):
n=int(input())
a=[int(y) for y in input().split()]
j=0
p=0
while j<n-1:
if a[j]!=a[j+1]:
p=1
break
j+=1
if p==0:
c.append(n)
else:
c.append(1)
for k in c:
print(k) |
You are given four integers a, b, x and y. Initially, a β₯ x and b β₯ y. You can do the following operation no more than n times:
* Choose either a or b and decrease it by one. However, as a result of this operation, value of a cannot become less than x, and value of b cannot become less than y.
Your task is to fi... | 3 | t = int(input())
for i in range(t):
a, b, x, y, n = [int(j) for j in input().split()]
a2=a
b2=b
n2=n
#if a-x>=b-y:
if a-x<=n:
n-=a-x
a-=a-x
if n>0:
if b-y<=n:
n-=b-y
b-=b-y
else:
b-=n
... |
You are given a board of size n Γ n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure.
In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move... | 3 | for _ in range(0,int(input())):
n = int(int(input())/2)
print(int(8*(n*(n+1)*(n-1)/3+n*(n+1)/2))) |
Β«One dragon. Two dragon. Three dragonΒ», β the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | 3 | q = int(input())
w = int(input())
e = int(input())
r = int(input())
t = int(input())
c = 0
for i in range(1,t+1):
if (i%q==0 or i%w==0 or i%e==0 or i%r==0):
c+=1
print(c) |
Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | 1 | n=input()
A=sorted(map(int,raw_input().split()))
for i in range(1,n+2):
if i not in A:
print i
exit()
|
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
Constraints
* The number of characters in the sentence < 1200
Input
A sentence in English is given in several lines.
Output
Prints the number of alphabetical letters in the following format:
a : The n... | 3 | a = "abcdefghijklmnopqrstuvwxyz"
b = ''
while 1:
try:
b += input().lower()
except:
break
for i in range(26):
print(a[i],':',b.count(a[i]))
|
You are given an array a_1, a_2, ..., a_n where all a_i are integers and greater than 0.
In one operation, you can choose two different indices i and j (1 β€ i, j β€ n). If gcd(a_i, a_j) is equal to the minimum element of the whole array a, you can swap a_i and a_j. gcd(x, y) denotes the [greatest common divisor (GCD)](... | 3 | # mere_array.py
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
b = []
b = a.copy()
b.sort()
min_ = b[0]
ok = True
for i in range(n):
if a[i]!=b[i] and a[i]%min_>0:
ok = False
break
# print(a[i],b[i])
if ok... |
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or bl... | 3 | n,m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n-m+1):
for j in range(n-m+1):
a1 = [a[k][j:j+m] for k in range(i,i+m)]
if a1 == b:
print('Yes')
exit()
print('No')
|
This is an easier version of the problem. In this version n β€ 1000
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company ... | 3 | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
M = 0
ans = [-1]*n
for i in range(n):
b = a[:]
for j in range(i-1, -1, -1):
b[j] = min(b[j], b[j+1])
for j in range(i+1, n):
b[j] = min(b[j], b[j-1])
S = sum(b)
if S>M:
... |
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 | # -*- coding: utf-8 -*-
"""
Created on Sat Nov 2 20:16:44 2019
@author: 86138
"""
#266B Queue at the School
n,t = [int(x) for x in input().split()]
q = input()
for i in range(t):
q = q.replace('BG','GB')
print(q)
|
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.
There are ex... | 3 | n = int(input())
s = input().split()
s.reverse()
x = s.index("0")
y = s.index("1")
x = n - x
y = n - y
print(min(x, y))
|
You are given two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 100). Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided by 2).
In other words, find a_1, a_2, β¦, a_k such that all a_i>0, n = a_1 + a_2 + β¦ + a_k and either all a_i are even or all a_i ar... | 3 | testcases = int(input())
while(testcases>0):
testcases = testcases - 1
n,k = map(int,input().split())
if(n<k):
print("NO")
continue
else:
if(n==k):
string = '1'*n
print("YES")
string = ""
for i in range(0,k):
string = string + " " + '1'
print(string[1:])
continue
else:
n1 = n - k + ... |
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers.
LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6.
O... | 3 | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode... |
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | 3 |
def solution():
n = int(input())
database = {}
for _ in range(n):
name = input()
try:
database[name] += 1
print(f"{name}{database[name]}")
except KeyError:
database[name] = 0
print("OK")
solution()
|
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | 3 | n = int(input())
cities = [char for char in input()]
if cities[0] == 'S' and cities[-1] == 'F':
print('YES')
else:
print('NO')
|
Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value ai β the maximum number of messages which the i-th student is agree to send per day. ... | 3 | # -*- coding: utf-8 -*-
n = int(input())
l = list(map(int, input().split(' ')))
a = l
sms_n = list(range(1, n, 1))
sms_y = [0]
r = []
c = 0
if l[0] == 0:
print(-1)
else:
while len(sms_y) < n and sum(a) > 0:
i = 0
for x in range(1, n):
if (a[x] >= a[i]) and (x in sms_y): i = x
... |
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 β€ r ... | 3 | #732A
a, b = map(int, input().split())
for i in range(1, 11):
if (a * i % 10 == 0) or (a * i % 10 == b):
print(i)
break |
Two players play a game.
Initially there are n integers a_1, a_2, β¦, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate t... | 3 | n = int(input())
number_list = sorted(map(int, input().split()))
last = number_list[n//2 - (n % 2 == 0)]
print(last) |
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if h... | 1 | from random import random
import math
import re
import fractions
# N = input()
N, P, K = map(int, raw_input().split(" "))
l = K-1
r = N-K
P -= N
def test(x):
return x * x <= P + max(0,x-l-1)*(x-l)/2 + max(0,x-r-1)*(x-r)/2
c = 0
il = -1
ir = P+1
while il < ir - 1:
mid = (il + ir)/2
if test(mid):
i... |
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 | a=input()
b=input()
c=int(len(a))
a=a.lower()
b=b.lower()
a=[ord(m) for m in a]
b=[ord(m) for m in b]
i=int(0)
t=int(0)
while i<c:
if a[i]==b[i]:
t+=1
i+=1
continue
elif a[i]>b[i]:
print("1")
break
else:
print("-1")
break
if t==c:
print("0") |
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety... | 3 | a, b = input(), input()
f = list(zip(a, b)).count(('4', '7'))
s = list(zip(a, b)).count(('7', '4'))
print(f + s - min(f, s))
|
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location... | 3 | t=int(input())
ans=[]
for i in range(t):
n,s,k=input().split()
n=int(n)
s=int(s)
k=int(k)
cl=[int(i) for i in input().split()]
if s not in cl:
ans.append(0)
else:
for j in range(1,n):
if s+j not in cl and s+j<=n:
ans.append(j)
break... |
For a finite set of integers X, let f(X)=\max X - \min X.
Given are N integers A_1,...,A_N.
We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) ove... | 3 | n, k = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
total = 0
def cmb(n, r, mod):
if (r<0 or r>n):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**5
g1 = [1,1]
g2 = [1,1]
inverse = [0,1]
for i in range(2, N + 1):
g1.append((g1[-1]... |
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following:
1. Add the integer xi to the first ai elements of the sequence.
2. Append an integer ki to the end of the sequenc... | 3 | def main():
l, base, res, le, tot = [0] * 200001, [0] * 200001, [], 1, 0
for _ in range(int(input())):
s = input()
c = s[0]
if c == '1':
a, x = map(int, s[2:].split())
base[a] += x
tot += a * x
elif c == '2':
l[le] = x = int(s[2:])
... |
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... | 1 | n = input()
print sum(list(map(int, raw_input().split()))) * 1.0 / n
|
You are given an array a consisting of n integers.
Your task is to determine if a has some subsequence of length at least 3 that is a palindrome.
Recall that an array b is called a subsequence of the array a if b can be obtained by removing some (possibly, zero) elements from a (not necessarily consecutive) without c... | 3 | import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa ... |
You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
You know that you ... | 3 | import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
... |
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya... | 1 | N, D = raw_input().split(' ')
N, D = int(N), int(D)
Max = 0
Current = 0
for i in xrange(D):
Flag = False
Str = raw_input().strip()
for j in xrange(N):
if Str[j] == '0':
Flag = True
break
if Flag == True:
Current += 1
Max = max(Max, Current)
else... |
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the e... | 3 | x,y,a,b=map(int,input().split())
if (a<b and (x-a)<=(b-a)) or (a==b and x<y):
print(0)
else:
c=0
for i in range(a,x+1):
for j in range(b,y+1):
if i>j:
c=c+1
print(c)
for i in range(a,x+1):
for j in range(b,y+1):
if i>j:
print(i,... |
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(1,t+1):
n=input()
if n[1]=='+':
count=count+1
else:
count=count-1
print(count)
|
A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi... | 3 | import sys,math,string,bisect
input=sys.stdin.readline
from collections import deque
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
a,b=M()
print(min(a,b,(a+b)//3))
|
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.
* Operation 1: Pour 100A grams of water into the beaker.
* Operation 2: Pour 100B grams of water into the beaker.... | 3 | a,b,c,d,e,f=map(int,input().split())
res=-1
ans=[0,0]
s1=set()
s2=set()
for x in range(0,f+1,100*a):
for y in range(0,f+1-x,100*b):
s1.add(x+y)
for x in range(0,f+1,c):
for y in range(0,f+1-x,d):
s2.add(x+y)
for x in s1:
for y in s2:
if x*e/100>=y and 0<x+y<=f:
tmp=y/(x+y)
if tmp>res:
... |
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 | input()
s = input()
n = len(s)
for i in range(2, n + 1):
if n % i == 0:
s = s[:i][::-1] + s[i:]
print(s)
|
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm Γ b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting t... | 1 | a, b = map(int, raw_input().split())
x, r = divmod(a, b)
ans = x
while r:
a, b = b, r
x, r = divmod(a, b)
ans += x
print ans |
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | 1 | input()
a = map(int, raw_input().split())
mx = max(a)
mn = min(a)
print sum(i!=mx and i!=mn for i in a) |
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequenc... | 1 | n = input()
c = 1
ans = n
t = n - 1
for i in range(n-1):
ans += t*c
c+=1
t-=1
print ans
|
You are given an integer n and an integer k.
In one step you can do one of the following moves:
* decrease n by 1;
* divide n by k if n is divisible by k.
For example, if n = 27 and k = 3 you can do the following steps: 27 β 26 β 25 β 24 β 8 β 7 β 6 β 2 β 1 β 0.
You are asked to calculate the minimum numbe... | 3 | t=int(input())
for i in range(t):
n,k=map(int,input().split())
v=0
while n>=k:
v=v+n%k+1
n=n//k
if n>0:
v=v+n
print(v)
|
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exa... | 1 | def g(n, a):
for i in range(1, 100):
if a**i > n:
return a**(i-1)
return -1
dp = {}
def solve(n):
if n < 6:
return n
if not n in dp:
a = g(n, 6)
b = g(n, 9)
dp[n] = min(solve(n-a)+1, solve(n-b)+1)
return dp[n]
# assert solve(127) == 4
# assert so... |
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps,... | 1 | qtdd = int(raw_input())
stairs = map(int, raw_input().split())
cont = 0
ans = []
for i in xrange(qtdd):
if stairs[i] == 1:
cont += 1
if i != 0:
ans.append(stairs[i - 1])
if cont > 0:
ans.append(stairs[qtdd - 1])
print cont
for j in xrange(len(ans)):
print ans[j], |
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l β€ a β€ b β€ r). Your task is to find the maximum value among all considered ones.
Expression <image> means applying bitwise excl... | 1 | r = map(int, raw_input().split())
a, b = r[0], r[1]
def p(a, b):
if (a == b):
return 0
c = bin(a)[2:]
d = bin(b)[2:]
if len(c) < len(d):
k = ''
for i in range(0, len(d)-len(c)):
k += '0'
c = k + c
e = 0
for i in range(0, len(c)):
if (c[:i] ==... |
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | 1 | n = input()
s = map(int, list(raw_input()))
st = set(s)
if any(x in st for x in [1,2,3,5,6,8,9,0]):
print 'NO'
else:
if sum(s) == sum(s[:(n+1)/2])*2: print 'YES'
else: print 'NO' |
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 | string = input()
string = string.lower()
notvowl = ".".join([c for c in string if not c in "aiueoy"])
print ("." + notvowl)
|
Tomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.
While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and d... | 3 | def solve():
a, b, c, d, k = map(int, input().split())
x = (a + c - 1) // c
y = (b + d - 1) // d
if x + y > k:
print(-1)
else:
print(x, y)
def main():
t = int(input())
for _ in range(t):
solve()
main()
|
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i... | 3 | n = input()
n = n.split()
m = int(n[1])
n = int(n[0])
k = input()
k = k.split()
for i in range(m):
k[i] = int(k[i])
steps = 0
current = 1
for i in range(m):
if(current<=k[i]):
q=k[i]-current
elif(current>k[i]):
q = n - (current-k[i])
#print(current,k[i],q)
current = k[i]
steps+=q
print(steps)
|
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the mi... | 3 | arr = [0 for i in range(7)]
for i in range(int(input())) :
temp = input()
for i in range(7) :
arr[i] += int(temp[i])
print(max(arr))
|
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far A... | 1 | n = int(raw_input())
daysM = [0]*400
daysF = [0]*400
store = []
for _ in range(n):
q = raw_input().split()
if q[0] == 'M':
daysM[int(q[1])]+=1
daysM[int(q[2])+1]-=1
else:
daysF[int(q[1])]+=1
daysF[int(q[2])+1]-=1
ans = 0
M = 0
F = 0
for _ in range(367):
... |
Write a program which reads two integers a and b, and calculates the following values:
* a Γ· b: d (in integer)
* remainder of a Γ· b: r (in integer)
* a Γ· b: f (in real number)
Constraints
* 1 β€ a, b β€ 109
Input
Two integers a and b are given in a line.
Output
Print d, r and f separated by a space in a line. For ... | 3 | a,b = map(int,input().split())
print('{0} {1} {2:.8f}'.format(a//b,a%b,a/b))
|
Given are N positive integers A_1,...,A_N.
Consider positive integers B_1, ..., B_N that satisfy the following condition.
Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.
Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.
Since the answer can be enormous, print t... | 3 | from fractions import gcd
from functools import reduce
n = int(input())
A = list(map(int,input().split()))
mod = 10 ** 9 + 7
lcm = reduce(lambda x,y: x*y//gcd(x,y), A)
# print(lcm)
ans = sum(lcm//x for x in A)
ans %= mod
print(ans) |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 3 | import collections
a=int(input())
c=0
for i in range(a):
a=list(map(int,input().split()))
if(sum(a)>1):
c+=1
print(c) |
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 | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode... |
You are given two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 100). Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided by 2).
In other words, find a_1, a_2, β¦, a_k such that all a_i>0, n = a_1 + a_2 + β¦ + a_k and either all a_i are even or all a_i ar... | 3 | for _ in range(int(input())):
n, k = map(int, input().split())
li = []
if(n % 2 == 0):
if(k % 2 == 0):
li.extend([1 for i in range(k-1)])
val = n - (k-1)
if(val < 1):
# print("aaaaa")
print("NO")
else:
... |
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight... | 3 | a, b = map(int, input().split())
if a <= b:
year = 0
while a <= b:
a *= 3
b *= 2
year += 1
print(year)
|
Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
Input
The first... | 3 | #!/usr/bin/python3
def main():
N = int(input())
c = 0
h = N // 100
c += h
N -= h * 100
h = N // 20
c += h
N -= h * 20
h = N // 10
c += h
N -= h * 10
h = N // 5
c += h
N -= h * 5
c += N
print(c)
if __name__ == '__main__':
main()
|
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second a and then the next word at second b, then if b - a β€ c, just the new word is appended to other words on the screen. If b - a > c, then ever... | 3 | n,c=map(int,input().split())
s=list(map(int,input().split()))
ans=1
for i in range(1, len(s)):
a = s[i-1]
b = s[i]
if b-a>c:
ans=1
else:
ans += 1
print(ans)
|
For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ in $S$ (0 or 1).
* delete($x$): Delete $x$ from $S$.
Constraints
... | 3 | def resolve():
import sys
input = sys.stdin.readline
n = int(input())
ans = set()
for _ in range(n):
q, x = [int(i) for i in input().split()]
if q == 0:
ans.add(x)
print(len(ans))
elif q == 1:
if x in ans:
print(1)
... |
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Bi... | 3 | a=int(input())
if(a<=2):
print('NO')
elif(a%2 == 0):
print('YES')
else:
print('NO')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.