contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,624,879,266 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l = list(map(int,input().split()))
a = l[0]
b = l[1]
n = l[2]
while:
if math.gcd(a,n) >= n:
n -= math.gcd(a,n)
else:
print(0)
exit()
if math.gcd(b,n) >= n:
n -= math.gcd(b,n)
else:
print(1)
exit()
... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
l = list(map(int,input().split()))
a = l[0]
b = l[1]
n = l[2]
while:
if math.gcd(a,n) >= n:
n -= math.gcd(a,n)
else:
print(0)
exit()
if math.gcd(b,n) >= n:
n -= math.gcd(b,n)
else:
print(1)
exit()
... | -1 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,673,244,117 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | a = list(map(int, input().split()))
print(max(a)-min(a))
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
a = list(map(int, input().split()))
print(max(a)-min(a))
``` | 3 | |
245 | C | Game with Coins | PROGRAMMING | 1,700 | [
"greedy"
] | null | null | Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins.
Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer *x* (2·*x... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of chests with coins. The second line contains a sequence of space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the number of coins in the chest number *i* at the beginning of the game. | Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. | [
"1\n1\n",
"3\n1 2 3\n"
] | [
"-1\n",
"3\n"
] | In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests.
In the second sample there is only one possible move *x* = 1. This move should be repeated at least 3 times to empty the third chest. | 0 | [
{
"input": "1\n1",
"output": "-1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "100\n269 608 534 956 993 409 297 735 258 451 468 422 125 407 580 769 857 383 419 67 377 230 842 113 169 427 287 75 372 133 456 450 644 303 638 40 217 445 427 730 168 341 371 633 237 951 142 596 528 5... | 1,595,242,585 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 278 | 20,172,800 | n=int(input())
if n==1:
print(-1)
exit(0)
a=list(map(int,input().split(' ')))
a=[0]+a
# print(a)
ans=0
for i in range(1,n+1):
if 2*i+1>n:
continue
if a[i]==0 or a[2*i]==0 or a[2*i+1]==0 :
continue
mina=min([a[i],a[2*i],a[2*i+1]])
a[i],a[2*i],a[2*i+1]=a[i]-mina,a[2*i... | Title: Game with Coins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins.
Polycarpus and Vasily move in tu... | ```python
n=int(input())
if n==1:
print(-1)
exit(0)
a=list(map(int,input().split(' ')))
a=[0]+a
# print(a)
ans=0
for i in range(1,n+1):
if 2*i+1>n:
continue
if a[i]==0 or a[2*i]==0 or a[2*i+1]==0 :
continue
mina=min([a[i],a[2*i],a[2*i+1]])
a[i],a[2*i],a[2*i+1]=a[i]-... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | 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... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,592,142,233 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s = input()
n = len(s)
lower = 0
upper = 0
for i in s:
if i.islower():
lower+=1
elif i.isupper():
upper+=1
if lower >= upper:
s = s.lower()
else:
s= s.upper()
print(s) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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 ei... | ```python
s = input()
n = len(s)
lower = 0
upper = 0
for i in s:
if i.islower():
lower+=1
elif i.isupper():
upper+=1
if lower >= upper:
s = s.lower()
else:
s= s.upper()
print(s)
``` | 3.9455 |
137 | A | Postcards and photos | PROGRAMMING | 900 | [
"implementation"
] | null | null | Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not ... | The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if ... | Print the only number — the minimum number of times Polycarpus has to visit the closet. | [
"CPCPCPC\n",
"CCCCCCPPPPPP\n",
"CCCCCCPPCPPPPPPPPPP\n",
"CCCCCCCCCC\n"
] | [
"7\n",
"4\n",
"6\n",
"2\n"
] | In the first sample Polycarpus needs to take one item to the closet 7 times.
In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.
In the third sample Polycarpus can visit the closet twice, both time... | 500 | [
{
"input": "CPCPCPC",
"output": "7"
},
{
"input": "CCCCCCPPPPPP",
"output": "4"
},
{
"input": "CCCCCCPPCPPPPPPPPPP",
"output": "6"
},
{
"input": "CCCCCCCCCC",
"output": "2"
},
{
"input": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC... | 1,586,246,234 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 16 | 218 | 307,200 | # -*- coding: utf-8 -*-
"""
Created on Tue Apr 7 02:29:32 2020
@author: alexi
"""
#https://codeforces.com/problemset/problem/137/A --- Alexis Galvan
def post_cards():
string = input()
dic = {'C':0,'P':0}
output = 0
aux = string[0]
for i in range(len(string))... | Title: Postcards and photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the r... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 7 02:29:32 2020
@author: alexi
"""
#https://codeforces.com/problemset/problem/137/A --- Alexis Galvan
def post_cards():
string = input()
dic = {'C':0,'P':0}
output = 0
aux = string[0]
for i in range(le... | 0 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,685,201,879 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 | n=int(input())
s=str(n)
res=''
for i in range(len(s)):
if s[i]>=5 & s[i]<9:
res+=str(9-int(s[i]))
else:
res+=s[i]
print(res) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
n=int(input())
s=str(n)
res=''
for i in range(len(s)):
if s[i]>=5 & s[i]<9:
res+=str(9-int(s[i]))
else:
res+=s[i]
print(res)
``` | -1 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,663,699,693 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n, k = map(int, input().split())
count = 0
for i in range(n):
test = input()
Mistaken = False
for j in range(k+1):
if test.find(str(j)) == -1:
Mistaken = True
break
for l in range(k+1, 10):
if test.find(str(l)) != -1:
Mistaken = True
... | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n, k = map(int, input().split())
count = 0
for i in range(n):
test = input()
Mistaken = False
for j in range(k+1):
if test.find(str(j)) == -1:
Mistaken = True
break
for l in range(k+1, 10):
if test.find(str(l)) != -1:
Mistaken = Tr... | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,669,053,157 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 140 | 7,065,600 | # -*- coding: utf-8 -*-
"""
Created on Tue Nov 22 01:12:17 2022
@author: thinkpad
"""
n = int(input())
a = [int(i) for i in input().split()]
s = [0]*100002
for i in a:
s[i]+=i
res,b=0,0
for d in s:
res,b = max(res,b),res+d
print(res) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 22 01:12:17 2022
@author: thinkpad
"""
n = int(input())
a = [int(i) for i in input().split()]
s = [0]*100002
for i in a:
s[i]+=i
res,b=0,0
for d in s:
res,b = max(res,b),res+d
print(res)
``` | 3 | |
637 | A | Voting for Photos | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms",
"implementation"
] | null | null | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. | Print the identifier of the photo which won the elections. | [
"5\n1 3 2 2 1\n",
"9\n100 200 300 200 100 300 300 100 200\n"
] | [
"2\n",
"300\n"
] | In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3; - as many likes as the photo with id 1, but t... | 500 | [
{
"input": "5\n1 3 2 2 1",
"output": "2"
},
{
"input": "9\n100 200 300 200 100 300 300 100 200",
"output": "300"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "5\n1 3 4 2 2",
"output": "2"
},
{
"input... | 1,457,897,193 | 26,793 | Python 3 | OK | TESTS | 65 | 77 | 819,200 | # -*- coding: utf-8 -*-
"""
Created on Sun Mar 13 19:40:03 2016
@author: Kostya S.
"""
from functools import cmp_to_key
n = int(input())
d = {}
a = [int(i) for i in input().split()]
for i,e in enumerate(a):
d[e] = (i+1,1,e) if d.get(e) == None else (i+1,d[e][1] + 1,e)
t1 = sorted(list(d.values()),key =... | Title: Voting for Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rule... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 13 19:40:03 2016
@author: Kostya S.
"""
from functools import cmp_to_key
n = int(input())
d = {}
a = [int(i) for i in input().split()]
for i,e in enumerate(a):
d[e] = (i+1,1,e) if d.get(e) == None else (i+1,d[e][1] + 1,e)
t1 = sorted(list(d.value... | 3 | |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,657,973,911 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import time
t=int(input())
while t:
rec=input()
s=input().split()
nb,ns,nc=map(int,s)
s=input().split()
pb,ps,pc=map(int,s)
r=int(input())
c={'B':0,'S':0,'C':0}
for i in rec:
c[i]+=1
ans=0
low,high=0,r+100
while low<=high:
... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
import time
t=int(input())
while t:
rec=input()
s=input().split()
nb,ns,nc=map(int,s)
s=input().split()
pb,ps,pc=map(int,s)
r=int(input())
c={'B':0,'S':0,'C':0}
for i in rec:
c[i]+=1
ans=0
low,high=0,r+100
while low<=h... | -1 | |
437 | C | The Child and Toy | PROGRAMMING | 1,400 | [
"graphs",
"greedy",
"sortings"
] | null | null | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts.... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**... | Output the minimum total energy the child should spend to remove all *n* parts of the toy. | [
"4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n"
] | [
"40\n",
"400\n",
"160\n"
] | One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 +... | 1,500 | [
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3",
"output": "40"
},
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4",
"output": "400"
},
{
"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4",
"output": "160"
},
{
"input": "1 0\n23333",
... | 1,406,647,274 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 62 | 0 | import sys
lines = sys.stdin.readlines()
nm = lines[0].strip().split(" ")
n = int(nm[0])
m = int(nm[1])
energies = lines[1].strip().split(" ")
energydict = {}
neighbours = {}
for i in range(1, len(energies)+1):
energydict[i] = int(energies[i-1])
for line in lines[2:]:
parts = line.strip().split(" "... | Title: The Child and Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but ev... | ```python
import sys
lines = sys.stdin.readlines()
nm = lines[0].strip().split(" ")
n = int(nm[0])
m = int(nm[1])
energies = lines[1].strip().split(" ")
energydict = {}
neighbours = {}
for i in range(1, len(energies)+1):
energydict[i] = int(energies[i-1])
for line in lines[2:]:
parts = line.strip()... | -1 | |
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time p... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a... | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"... | 1,652,528,551 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | word1 = input().split()
maxnum = int(word1[1])
word2 = input().split()
word2 = [ int(x) for x in word2 ]
sum1 = sum(word2)
#sum1 = abs(sum1)
final = 0
flst = []
for elm in range(min(word2),maxnum+1):
if sum1 != 0 and elm !=0:
count = 0
while sum1 !=0:
if sum1 %elm == 0:... | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each... | ```python
word1 = input().split()
maxnum = int(word1[1])
word2 = input().split()
word2 = [ int(x) for x in word2 ]
sum1 = sum(word2)
#sum1 = abs(sum1)
final = 0
flst = []
for elm in range(min(word2),maxnum+1):
if sum1 != 0 and elm !=0:
count = 0
while sum1 !=0:
if sum1 ... | 0 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,599,229,810 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | from sys import stdin, stdout
def need_to_check(card, vowels=['a','e','i','o','u']):
return (ord(card) >= ord('0') and ord(card) <= ord('9') and int(card) % 2 == 1) or (card in vowels)
def number_of_reveals(cards):
count = 0
for card in cards:
count = count+1 if need_to_check(card) else count
... | Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
from sys import stdin, stdout
def need_to_check(card, vowels=['a','e','i','o','u']):
return (ord(card) >= ord('0') and ord(card) <= ord('9') and int(card) % 2 == 1) or (card in vowels)
def number_of_reveals(cards):
count = 0
for card in cards:
count = count+1 if need_to_check(card) else ... | 3 | |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | 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.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,585,398,173 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | def func(numero, soma, digitos, n, results):
total4 = soma+4
total7 = soma+7
novo = numero+4*pow(10, digitos)
if n > total4:
func(novo, total4, digitos+1, n, results)
elif n < total4:
return
else:
results.append(novo)
novo = numero+7*pow(10, digitos)
if n > tota... | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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.
... | ```python
def func(numero, soma, digitos, n, results):
total4 = soma+4
total7 = soma+7
novo = numero+4*pow(10, digitos)
if n > total4:
func(novo, total4, digitos+1, n, results)
elif n < total4:
return
else:
results.append(novo)
novo = numero+7*pow(10, digitos)
i... | 0 |
606 | A | Magic Spheres | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible,... | The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number o... | If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". | [
"4 4 0\n2 1 2\n",
"5 6 1\n2 7 2\n",
"3 3 3\n2 2 2\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what... | 500 | [
{
"input": "4 4 0\n2 1 2",
"output": "Yes"
},
{
"input": "5 6 1\n2 7 2",
"output": "No"
},
{
"input": "3 3 3\n2 2 2",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 0",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 1",
"output": "No"
},
{
"input": "0 1 0\n0 0 0... | 1,484,674,766 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 4,608,000 | a,b,c = map(int, input().split())
x, y, z = map(int, input().split())
if a >= x and b >= y and c >= z:
print("YES")
else:
extra = 0
if a >= x:
extra += (a - x) / 2
if b >= y:
extra += (b - x) / 2
if c >= z:
extra += (c - z) / 2
if a < x and (a + extra) >= x:
extra -= (x - a)
... | Title: Magic Spheres
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been see... | ```python
a,b,c = map(int, input().split())
x, y, z = map(int, input().split())
if a >= x and b >= y and c >= z:
print("YES")
else:
extra = 0
if a >= x:
extra += (a - x) / 2
if b >= y:
extra += (b - x) / 2
if c >= z:
extra += (c - z) / 2
if a < x and (a + extra) >= x:
extra -=... | 0 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,461,667,736 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 4,608,000 | n = int(input())
print ((n + 3) // 3) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
n = int(input())
print ((n + 3) // 3)
``` | 0 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | 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... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,694,057,583 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 46 | 0 | n=int(input())
li1=list(map(int,input().split()))
li2=list(map(int,input().split()))
li3=li1+li2
s=set(li3)
sumt=(n*(n+1))/2
li=list(s)
if sum(li)==sumt:
print("I become the guy.")
else:
print("Oh, my keyboard!")
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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 g... | ```python
n=int(input())
li1=list(map(int,input().split()))
li2=list(map(int,input().split()))
li3=li1+li2
s=set(li3)
sumt=(n*(n+1))/2
li=list(s)
if sum(li)==sumt:
print("I become the guy.")
else:
print("Oh, my keyboard!")
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,602,371,164 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | n=int(input())
a=[int(x) for x in input().split()]
b=[]
for i in range(n):
b.append(a[i]%2)
if b.count(1)>b.count(0):
c=[1]*n
else:
c=[0]*n
for i in range(n):
if b[i]-c[i]!=0:
print(i+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
a=[int(x) for x in input().split()]
b=[]
for i in range(n):
b.append(a[i]%2)
if b.count(1)>b.count(0):
c=[1]*n
else:
c=[0]*n
for i in range(n):
if b[i]-c[i]!=0:
print(i+1)
``` | 3.9455 |
625 | B | War of the Corporations | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine... | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | [
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] | [
"1",
"0",
"2"
] | In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | 750 | [
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",... | 1,498,085,255 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 140 | 5,632,000 | # Description of the problem can be found at http://codeforces.com/problemset/problem/625/B
x = input()
s = input()
print(x.count(s)) | Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Last... | ```python
# Description of the problem can be found at http://codeforces.com/problemset/problem/625/B
x = input()
s = input()
print(x.count(s))
``` | 3 | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,593,521,808 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 202 | 3,276,800 | n,m= input().split()
print(n,m)
num = int(input())
for i in range(num):
a,b=input().split()
if(a==n):
print(b,m)
n=b
else:
print(b,n)
m=b
| Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
n,m= input().split()
print(n,m)
num = int(input())
for i in range(num):
a,b=input().split()
if(a==n):
print(b,m)
n=b
else:
print(b,n)
m=b
``` | 3 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | 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. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,679,367,714 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 265 | 0 | s = {"Tetrahedron": 4,
"Cube": 6,
"Octahedron": 8,
"Dodecahedron": 12,
"Icosahedron": 20}
t = int(input())
add = 0
for i in range(t):
add += s[input()]
print(add)
| Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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. - Octahe... | ```python
s = {"Tetrahedron": 4,
"Cube": 6,
"Octahedron": 8,
"Dodecahedron": 12,
"Icosahedron": 20}
t = int(input())
add = 0
for i in range(t):
add += s[input()]
print(add)
``` | 3 | |
849 | B | Tell Your World | PROGRAMMING | 1,600 | [
"brute force",
"geometry"
] | null | null | Connect the countless points with lines, till we reach the faraway yonder.
There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of the... | The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=1<=000) — the number of points.
The second line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (<=-<=109<=≤<=*y**i*<=≤<=109) — the vertical coordinates of each point. | Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
"5\n7 5 8 6 9\n",
"5\n-1 -2 0 0 -5\n",
"5\n5 4 3 2 1\n",
"5\n1000000000 0 0 0 0\n"
] | [
"Yes\n",
"No\n",
"No\n",
"Yes\n"
] | In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, ... | 1,000 | [
{
"input": "5\n7 5 8 6 9",
"output": "Yes"
},
{
"input": "5\n-1 -2 0 0 -5",
"output": "No"
},
{
"input": "5\n5 4 3 2 1",
"output": "No"
},
{
"input": "5\n1000000000 0 0 0 0",
"output": "Yes"
},
{
"input": "5\n1000000000 1 0 -999999999 -1000000000",
"output": "... | 1,553,843,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n=int(input())
l=[int(i) for i in input().split()]
diff=[l[i]-l[i-1] for i in range(1,n)]
if len(set(diff))<=2:
print('Yes')
else:
print('No') | Title: Tell Your World
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Connect the countless points with lines, till we reach the faraway yonder.
There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*).
Determine whether it's possible to draw two parallel and... | ```python
n=int(input())
l=[int(i) for i in input().split()]
diff=[l[i]-l[i-1] for i in range(1,n)]
if len(set(diff))<=2:
print('Yes')
else:
print('No')
``` | 0 | |
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**... | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti... | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
... | 1,620,188,062 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 18 | 904 | 3,584,000 | import sys
input = sys.stdin.readline
n,m = map(int,input().split())
adj=[[] for j in range(n+1)]
for i in range(m):
a,b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
ans=9999
for i in range(1,n+1):
f=[i]
for j in range(1,n+1):
if j!=i:
... | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br... | ```python
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
adj=[[] for j in range(n+1)]
for i in range(m):
a,b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
ans=9999
for i in range(1,n+1):
f=[i]
for j in range(1,n+1):
if j!=i:
... | 0 | |
227 | A | Where do I Turn? | PROGRAMMING | 1,300 | [
"geometry"
] | null | null | Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight... | The first input line contains two space-separated integers *x**a*,<=*y**a* (|*x**a*|,<=|*y**a*|<=≤<=109) — the coordinates of point *A*. The second line contains the coordinates of point *B* in the same form, the third line contains the coordinates of point *C*.
It is guaranteed that all points are pairwise different.... | Print a single line. If a hero must turn left, print "LEFT" (without the quotes); If he must go straight ahead, print "TOWARDS" (without the quotes); if he should turn right, print "RIGHT" (without the quotes). | [
"0 0\n0 1\n1 1\n",
"-1 -1\n-3 -3\n-4 -4\n",
"-4 -6\n-3 -7\n-2 -6\n"
] | [
"RIGHT\n",
"TOWARDS\n",
"LEFT\n"
] | The picture to the first sample:
The red color shows points A, B and C. The blue arrow shows the hero's direction. The green color shows the hero's trajectory.
The picture to the second sample: | 500 | [
{
"input": "0 0\n0 1\n1 1",
"output": "RIGHT"
},
{
"input": "-1 -1\n-3 -3\n-4 -4",
"output": "TOWARDS"
},
{
"input": "-4 -6\n-3 -7\n-2 -6",
"output": "LEFT"
},
{
"input": "-44 57\n-118 -41\n-216 33",
"output": "RIGHT"
},
{
"input": "39 100\n90 85\n105 136",
"o... | 1,630,951,047 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 124 | 6,963,200 | xa,ya = input().split()
xa = int(xa)
ya = int(ya)
xb,yb = input().split()
xb = int(xb)
yb = int(yb)
xc,yc = input().split()
xc = int(xc)
yc = int(yc)
vab_x = xb-xa
vab_y = yb-ya
vbc_x = xc - xb
vbc_y = yc - yb
produto_vetorial = (vab_x * vbc_y) - (vab_y * vbc_x)
if(produto_vetorial == 0):
... | Title: Where do I Turn?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the... | ```python
xa,ya = input().split()
xa = int(xa)
ya = int(ya)
xb,yb = input().split()
xb = int(xb)
yb = int(yb)
xc,yc = input().split()
xc = int(xc)
yc = int(yc)
vab_x = xb-xa
vab_y = yb-ya
vbc_x = xc - xb
vbc_y = yc - yb
produto_vetorial = (vab_x * vbc_y) - (vab_y * vbc_x)
if(produto_vetorial =... | 3 | |
220 | A | Little Elephant and Problem | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers. | In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. | [
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we ... | 500 | [
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000... | 1,682,313,650 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n=int(input())
l=list(map(int,input().split()))
if len(l)<=3:
print('YES')
else:
c=0
l1=sorted(l)
for i,j in zip(l,l1):
if i!=j:
c+=1
if c==2:
print('YES')
else:
print('NO') | Title: Little Elephant and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to c... | ```python
n=int(input())
l=list(map(int,input().split()))
if len(l)<=3:
print('YES')
else:
c=0
l1=sorted(l)
for i,j in zip(l,l1):
if i!=j:
c+=1
if c==2:
print('YES')
else:
print('NO')
``` | 0 | |
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"... | 1,559,129,705 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n = int(input())
a = list(map(int , input().split()))
a.sort()
c = 1
for i in range(n):
if c < n:
c+=1
print(c) | Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small... | ```python
n = int(input())
a = list(map(int , input().split()))
a.sort()
c = 1
for i in range(n):
if c < n:
c+=1
print(c)
``` | 0 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,509,113,739 | 639 | Python 3 | OK | TESTS | 16 | 61 | 0 | a=input().split(' ')
n=int(a[0])
t=int(a[1])
a=input().split(' ')
a=[int(i) for i in a]
for i in range(n):
if t<=0:
print(i)
break
t=t-(86400-a[i])
else:
print(n)
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
a=input().split(' ')
n=int(a[0])
t=int(a[1])
a=input().split(' ')
a=[int(i) for i in a]
for i in range(n):
if t<=0:
print(i)
break
t=t-(86400-a[i])
else:
print(n)
``` | 3 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,692,610,152 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | #all those moments will be lost in time , like tears in rain "D
a=[]
n=int(input())
for _ in range(n):
b=input()
if b in a:
print('YES')
else:
print('NO')
a.append(b); | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
#all those moments will be lost in time , like tears in rain "D
a=[]
n=int(input())
for _ in range(n):
b=input()
if b in a:
print('YES')
else:
print('NO')
a.append(b);
``` | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,618,250,609 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 6,348,800 | n,a,b=map(int,input().split())
l=list(map(int,input().split()))
l1=l[1:]
l1.sort()
while (a*l[0])/(sum(l1)+l[0])<b :
l1.pop()
print(n-len(l1)-1) | Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
n,a,b=map(int,input().split())
l=list(map(int,input().split()))
l1=l[1:]
l1.sort()
while (a*l[0])/(sum(l1)+l[0])<b :
l1.pop()
print(n-len(l1)-1)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with *n* rows and *m* columns. Each cell originally contains the number 0.
One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.
... | The first line of input contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of rows and the number of columns in the grid, respectively.
The next *n* lines each contain *m* integers. In particular, the *j*-th integer in the *i*-th of these rows contains *g**i*,<=*j* (0<=≤<=*g**i*,<=*j*<=≤<=500). | If there is an error and it is actually not possible to beat the level, output a single integer -1.
Otherwise, on the first line, output a single integer *k*, the minimum number of moves necessary to beat the level.
The next *k* lines should each contain one of the following, describing the moves in the order they mu... | [
"3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1\n",
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"3 3\n1 1 1\n1 1 1\n1 1 1\n"
] | [
"4\nrow 1\nrow 1\ncol 4\nrow 3\n",
"-1\n",
"3\nrow 1\nrow 2\nrow 3\n"
] | In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:
In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required... | 0 | [
{
"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1",
"output": "4\nrow 1\nrow 1\ncol 4\nrow 3"
},
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "-1"
},
{
"input": "3 3\n1 1 1\n1 1 1\n1 1 1",
"output": "3\nrow 1\nrow 2\nrow 3"
},
{
"input": "3 5\n2 4 2 2 3\n0 2 0 0 1\n1 3 1 1... | 1,530,962,458 | 2,147,483,647 | Python 3 | OK | TESTS | 177 | 374 | 819,200 | n,m=map(int,input().split())
a=[];row=[];col=[]
for i in range(n):
a.append(list(map(int,input().split())))
if m>n:
for i in range(n):
row.append(min(a[i]))
for i in range(m):
col.append(a[0][i]-row[0])
else:
for i in range(m):
r=1000
for j in range(n):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with *n* rows and *m* columns. Each cell originally contains the number 0.
One move consis... | ```python
n,m=map(int,input().split())
a=[];row=[];col=[]
for i in range(n):
a.append(list(map(int,input().split())))
if m>n:
for i in range(n):
row.append(min(a[i]))
for i in range(m):
col.append(a[0][i]-row[0])
else:
for i in range(m):
r=1000
for j in range(... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,673,238,311 | 431 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | import sys
vector = [0, 0, 0]
counter = 0
for line in sys.stdin:
if not counter:
continue
nums = [int(i) for i in line.split(' ')]
for i in range(3):
vector[i] += nums[i]
counter += 1
if vector[0] == 0 and vector[1] == 0 and vector[2] == 0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
import sys
vector = [0, 0, 0]
counter = 0
for line in sys.stdin:
if not counter:
continue
nums = [int(i) for i in line.split(' ')]
for i in range(3):
vector[i] += nums[i]
counter += 1
if vector[0] == 0 and vector[1] == 0 and vector[2] == 0:
print('YES')
else:
print('NO')
``` | 0 |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times... | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {... | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",... | 1,597,955,869 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 24 | 109 | 0 | l,r=map(int,input().split())
x,y=(r//2)-(l//2),(r//3)-(l//3)
if x>=y:
print('2')
else:
print('3') | Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the... | ```python
l,r=map(int,input().split())
x,y=(r//2)-(l//2),(r//3)-(l//3)
if x>=y:
print('2')
else:
print('3')
``` | 0 | |
16 | C | Monitor | PROGRAMMING | 1,800 | [
"binary search",
"number theory"
] | C. Monitor | 0 | 64 | Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999... | The first line of the input contains 4 integers — *a*, *b*, *x* and *y* (1<=≤<=*a*,<=*b*,<=*x*,<=*y*<=≤<=2·109). | If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise. | [
"800 600 4 3\n",
"1920 1200 16 9\n",
"1 1 1 2\n"
] | [
"800 600\n",
"1920 1080\n",
"0 0\n"
] | none | 0 | [
{
"input": "800 600 4 3",
"output": "800 600"
},
{
"input": "1920 1200 16 9",
"output": "1920 1080"
},
{
"input": "1 1 1 2",
"output": "0 0"
},
{
"input": "1002105126 227379125 179460772 1295256518",
"output": "0 0"
},
{
"input": "625166755 843062051 1463070160 19... | 1,653,665,743 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 102,400 | """16С 1800 баллов"""
from datetime import datetime
"""#print("Размер до ")
a = float(input())
b = float(input())
#print("Размер после ")
x= int(input())
y= int(input())"""
a, b, x, y = map(int, input().split())
s = datetime.now()
#if a>x and b>y:
if a % x == 0 and b % y == 0:
print(int(a), int(b))
... | Title: Monitor
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *... | ```python
"""16С 1800 баллов"""
from datetime import datetime
"""#print("Размер до ")
a = float(input())
b = float(input())
#print("Размер после ")
x= int(input())
y= int(input())"""
a, b, x, y = map(int, input().split())
s = datetime.now()
#if a>x and b>y:
if a % x == 0 and b % y == 0:
print(int(a)... | 0 |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | 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 ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,691,351,899 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | w = int(input("w"))
if (w/2=0):
ptint("Yes")
else:
print("No") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
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, dyin... | ```python
w = int(input("w"))
if (w/2=0):
ptint("Yes")
else:
print("No")
``` | -1 |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,697,189,638 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 | line1 = input()
line2 = input()
n=int(line1[0])
d=int(line1[2])
city = set(map(int, line2.split()))
d1 = {i+d for i in city}
d2 = {i-d for i in city}
ncity = city | d1 | d2
ncity = sorted(ncity)
min = [ncity[i+1] - ncity[i] for i in range(len(ncity)-1)]
c=0
for i in min:
if i>=d:
c += 1
print(... | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
line1 = input()
line2 = input()
n=int(line1[0])
d=int(line1[2])
city = set(map(int, line2.split()))
d1 = {i+d for i in city}
d2 = {i-d for i in city}
ncity = city | d1 | d2
ncity = sorted(ncity)
min = [ncity[i+1] - ncity[i] for i in range(len(ncity)-1)]
c=0
for i in min:
if i>=d:
c +=... | -1 | |
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,638,315,578 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 62 | 0 | string=input().lower()
consonants=['b','c','d','f','g','h','j','k','l','m','p','q','r','s','t','v','w','x','y','z']
vowels=['a','e','i','o','u']
ber='YES'
for n in range(len(string)-1):
if string[n] in consonants:
if string[n+1] not in vowels:
ber='NO'
if string[-1] in consonants:
ber='NO'
print... | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
string=input().lower()
consonants=['b','c','d','f','g','h','j','k','l','m','p','q','r','s','t','v','w','x','y','z']
vowels=['a','e','i','o','u']
ber='YES'
for n in range(len(string)-1):
if string[n] in consonants:
if string[n+1] not in vowels:
ber='NO'
if string[-1] in consonants:
ber='... | 3 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | 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... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,699,879,770 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | #n is number of statement in the program
x=0
n=int(input())
for i in range(n):
stmt=input().lower()
if stmt=='++x' or stmt=='x++':
x+=1
elif stmt=='--x' or stmt=='x--':
x+=-1
print(x) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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 ++ incre... | ```python
#n is number of statement in the program
x=0
n=int(input())
for i in range(n):
stmt=input().lower()
if stmt=='++x' or stmt=='x++':
x+=1
elif stmt=='--x' or stmt=='x--':
x+=-1
print(x)
``` | 3 | |
340 | C | Tourist Problem | PROGRAMMING | 1,600 | [
"combinatorics",
"implementation",
"math"
] | null | null | Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a*... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107). | Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible. | [
"3\n2 3 5\n"
] | [
"22 3"
] | Consider 6 possible routes:
- [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; - [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; - [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; - [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; - [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; - [5, 3, 2]: |5 – 0| + |3 – 5|... | 2,000 | [
{
"input": "3\n2 3 5",
"output": "22 3"
},
{
"input": "4\n1 5 77 2",
"output": "547 4"
},
{
"input": "5\n3 3842 288 199 334",
"output": "35918 5"
},
{
"input": "7\n1 2 3 40 52 33 86",
"output": "255 1"
},
{
"input": "7\n1 10 100 1000 10000 1000000 10000000",
"... | 1,591,173,432 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 528 | 7,577,600 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 3 11:57:46 2020
@author: shailesh
"""
from math import gcd
def reduce_fraction(x,y):
d = gcd(x,y)
x = x//d
y = y//d
return x,y
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
d0 = A[0]
sum_val = 0
for i in r... | Title: Tourist Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* d... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 3 11:57:46 2020
@author: shailesh
"""
from math import gcd
def reduce_fraction(x,y):
d = gcd(x,y)
x = x//d
y = y//d
return x,y
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
d0 = A[0]
sum_val = 0
... | 3 | |
190 | A | Vasya and the Bus | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..."
The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers cou... | The input file consists of a single line containing two space-separated numbers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=105) — the number of the grown-ups and the number of the children in the bus, correspondingly. | If *n* grown-ups and *m* children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly.
Otherwise, print "Impossible" (without the quotes). | [
"1 2\n",
"0 5\n",
"2 2\n"
] | [
"2 2",
"Impossible",
"2 3"
] | In the first sample a grown-up rides with two children and pays two rubles.
In the second sample there are only children in the bus, so the situation is impossible.
In the third sample there are two cases: - Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passen... | 500 | [
{
"input": "1 2",
"output": "2 2"
},
{
"input": "0 5",
"output": "Impossible"
},
{
"input": "2 2",
"output": "2 3"
},
{
"input": "2 7",
"output": "7 8"
},
{
"input": "4 10",
"output": "10 13"
},
{
"input": "6 0",
"output": "6 6"
},
{
"input... | 1,648,888,039 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | a,c=map(int,input().split())
if a==0:
print('IMPOSSIBLE')
else:
print(a+(c-a)*int(c>a),a+(c-1)*int(c>1)) | Title: Vasya and the Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..."
The latter events happen to be of no importance to us. Vasya is an accountant... | ```python
a,c=map(int,input().split())
if a==0:
print('IMPOSSIBLE')
else:
print(a+(c-a)*int(c>a),a+(c-1)*int(c>1))
``` | 0 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,671,476,320 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 93 | 1,536,000 | a = input()
n = len(a)
c = 0
for i in range(n):
if a[i] == 'Q':
for j in range(i + 1, n):
if a[j] == 'A':
for k in range(j + 1, n):
if a[k] == 'Q':
c += 1
print(c) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
a = input()
n = len(a)
c = 0
for i in range(n):
if a[i] == 'Q':
for j in range(i + 1, n):
if a[j] == 'A':
for k in range(j + 1, n):
if a[k] == 'Q':
c += 1
print(c)
``` | 3 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,657,193,572 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | a=input()
if a[len(a)-2]=="A" or a[len(a)-2]=="a" or a[len(a)-2]=="E" or a[len(a)-2]=="e" or a[len(a)-2]=="Y" or a[len(a)-2]=="y" or a[len(a)-2]=="U" or a[len(a)-2]=="u" or a[len(a)-2]=="I" or a[len(a)-2]=="i" or a[len(a)-2]=="O" or a[len(a)-2]=="o":
print('YES')
else:
print('NO')
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
a=input()
if a[len(a)-2]=="A" or a[len(a)-2]=="a" or a[len(a)-2]=="E" or a[len(a)-2]=="e" or a[len(a)-2]=="Y" or a[len(a)-2]=="y" or a[len(a)-2]=="U" or a[len(a)-2]=="u" or a[len(a)-2]=="I" or a[len(a)-2]=="i" or a[len(a)-2]=="O" or a[len(a)-2]=="o":
print('YES')
else:
print('NO')
``` | 0 |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,463,814,130 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | type
point = record
x, y: int64;
p: boolean;
end;
var
a, b, c, p, i, j: int64;
ar: array [1..300000] of point;
procedure qsort(a, b: int64);
var
d, e: int64;
c, x: point;
begin
if a < b then begin
d := a;
e := b;
x := ar[random(b - a) + a];
while d <= e... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
type
point = record
x, y: int64;
p: boolean;
end;
var
a, b, c, p, i, j: int64;
ar: array [1..300000] of point;
procedure qsort(a, b: int64);
var
d, e: int64;
c, x: point;
begin
if a < b then begin
d := a;
e := b;
x := ar[random(b - a) + a];
wh... | -1 | |
625 | C | K-special Tables | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you f... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500,<=1<=≤<=*k*<=≤<=*n*) — the size of the table Alice is looking for and the column that should have maximum possible sum. | First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you ar... | [
"4 1\n",
"5 3\n"
] | [
"28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n",
"85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n"
] | none | 1,000 | [
{
"input": "4 1",
"output": "28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16"
},
{
"input": "5 3",
"output": "85\n1 2 11 12 13\n3 4 14 15 16\n5 6 17 18 19\n7 8 20 21 22\n9 10 23 24 25"
},
{
"input": "1 1",
"output": "1\n1"
},
{
"input": "2 1",
"output": "4\n1 2\n3 4"
},
... | 1,657,818,548 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 52 | 93 | 4,608,000 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
d = [[0]*n for _ in range(n)]
x = (k-1)*n + 1
c = 1
if k > 1:
for i in range(n):
for j in range(k-1):
d[i][j] = c
c += 1
for i in range(n):
for j in range(k-1, n):
d[i][j] = c
... | Title: K-special Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
d = [[0]*n for _ in range(n)]
x = (k-1)*n + 1
c = 1
if k > 1:
for i in range(n):
for j in range(k-1):
d[i][j] = c
c += 1
for i in range(n):
for j in range(k-1, n):
d[i][j] = ... | 3 | |
1,006 | A | Adjacent Replacements | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occu... | The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array. | Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array. | [
"5\n1 2 4 5 10\n",
"10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n"
] | [
"1 1 3 5 9\n",
"9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "5\n1 2 4 5 10",
"output": "1 1 3 5 9"
},
{
"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000",
"output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"
},
{
"input": "1\n999999999",
"output": "999999999"
},
{
"input": "1\n1000000000",... | 1,598,864,624 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 93 | 6,963,200 | n = int(input())
a = [int(s) for s in input().split(' ')]
b = [str(c - ((c + 1) % 2)) for c in a]
print(' '.join(b))
| Title: Adjacent Replacements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjace... | ```python
n = int(input())
a = [int(s) for s in input().split(' ')]
b = [str(c - ((c + 1) % 2)) for c in a]
print(' '.join(b))
``` | 3 | |
21 | A | Jabber ID | PROGRAMMING | 1,900 | [
"implementation",
"strings"
] | A. Jabber ID | 0 | 256 | Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. - <hostname> — is... | The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive. | Print YES or NO. | [
"[email protected]\n",
"[email protected]/contest.icpc/12\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "mike@codeforces.com",
"output": "YES"
},
{
"input": "john.smith@codeforces.ru/contest.icpc/12",
"output": "NO"
},
{
"input": "test@test.ri/abacaba",
"output": "YES"
},
{
"input": "@ops",
"output": "NO"
},
{
"input": "this-is-the-test",
"output": "N... | 1,510,646,181 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | def norm(str):
for i in range(len(str)):
if (33<= ord(str[i])<= 127) or (ord('0')<= ord(str[i])<= ord('9')) or str[i]== '_':
pass
else:
return False
if not (0 <len(str[i])< 17): return False
return True
def fin():
print('NO')
quit()
j= inp... | Title: Jabber ID
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «... | ```python
def norm(str):
for i in range(len(str)):
if (33<= ord(str[i])<= 127) or (ord('0')<= ord(str[i])<= ord('9')) or str[i]== '_':
pass
else:
return False
if not (0 <len(str[i])< 17): return False
return True
def fin():
print('NO')
quit()
... | 0 |
797 | A | k-Factorization | PROGRAMMING | 1,100 | [
"implementation",
"math",
"number theory"
] | null | null | Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). | If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. | [
"100000 2\n",
"100000 20\n",
"1024 5\n"
] | [
"2 50000 \n",
"-1\n",
"2 64 2 2 2 \n"
] | none | 0 | [
{
"input": "100000 2",
"output": "2 50000 "
},
{
"input": "100000 20",
"output": "-1"
},
{
"input": "1024 5",
"output": "2 64 2 2 2 "
},
{
"input": "100000 10",
"output": "2 2 2 2 2 5 5 5 5 5 "
},
{
"input": "99999 3",
"output": "3 813 41 "
},
{
"input... | 1,674,129,309 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,k=map(int,input().split())
i=2
l=[]
cnt=0
while(i*i<=n):
if(n%i==0):
while(n%i==0):
n=n//i
l.append(i)
i+=1
if(n>1):
l.append(n)
if(len(l)==k):
print(l)
elif(len(l)<k):
print(-1)
else:
ans=1
l1=l[k-1:... | Title: k-Factorization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
Input Specification:
The first line contains two int... | ```python
n,k=map(int,input().split())
i=2
l=[]
cnt=0
while(i*i<=n):
if(n%i==0):
while(n%i==0):
n=n//i
l.append(i)
i+=1
if(n>1):
l.append(n)
if(len(l)==k):
print(l)
elif(len(l)<k):
print(-1)
else:
ans=1
... | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,692,772,851 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 93 | 0 | a = input()
p=[]
for i in a:
if(i.isalpha()==True):
p.append(i)
s=list(set(p))
print(len(s)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a = input()
p=[]
for i in a:
if(i.isalpha()==True):
p.append(i)
s=list(set(p))
print(len(s))
``` | 3 | |
985 | B | Switches and Lamps | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps.
The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise.
It is guar... | Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. | [
"4 5\n10101\n01000\n00111\n10000\n",
"4 5\n10100\n01000\n00110\n00101\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "4 5\n10101\n01000\n00111\n10000",
"output": "YES"
},
{
"input": "4 5\n10100\n01000\n00110\n00101",
"output": "NO"
},
{
"input": "1 5\n11111",
"output": "NO"
},
{
"input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1",
"output": "YES"
},
{
"input": "1 1\n1",
... | 1,527,318,977 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 2,355 | 4,710,400 | n,m = [int(i) for i in input().split()]
l = []
for i in range(n):
l.append(input())
cnt = m*[0]
for i in range(m):
for j in range(n):
cnt[i]+=int(l[j][i])
ans = 'NO'
#print(*cnt)
t = 0
for i in range(m):
if cnt[i]>=2:
t+=1
if t >= 2:
ans = 'YES'
print(ans)
| Title: Switches and Lamps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th... | ```python
n,m = [int(i) for i in input().split()]
l = []
for i in range(n):
l.append(input())
cnt = m*[0]
for i in range(m):
for j in range(n):
cnt[i]+=int(l[j][i])
ans = 'NO'
#print(*cnt)
t = 0
for i in range(m):
if cnt[i]>=2:
t+=1
if t >= 2:
ans = 'YES'
print(ans)
``` | 0 | |
220 | B | Little Elephant and Array | PROGRAMMING | 1,800 | [
"constructive algorithms",
"data structures"
] | null | null | The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. T... | In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query. | [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
] | [
"3\n1\n"
] | none | 1,000 | [
{
"input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4",
"output": "3\n1"
},
{
"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6",
"output": "1\n0\n2\n1\n1\n3"
},
{
"input": "1 2\n1\n1 1\n1 1",
"output": "1\n1"
},
{
"input": "1 1\n1000000000\n1 1",
"output": "0"
}
] | 1,467,244,980 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 204,800 | def add(elem, count):
count[elem] += 1
if count[elem] == elem:
global answer
answer += 1
def remove(elem, count):
count[elem] -= 1
# case our count gets below the element count
if count[elem] == elem-1:
global answer
answer -= 1
def process_queries(queries, array):... | Title: Little Elephant and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant... | ```python
def add(elem, count):
count[elem] += 1
if count[elem] == elem:
global answer
answer += 1
def remove(elem, count):
count[elem] -= 1
# case our count gets below the element count
if count[elem] == elem-1:
global answer
answer -= 1
def process_queries(querie... | -1 | |
11 | D | A Simple Task | PROGRAMMING | 2,200 | [
"bitmasks",
"dp",
"graphs"
] | D. A Simple Task | 2 | 256 | Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges. | The first line of input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=19, 0<=≤<=*m*) – respectively the number of vertices and edges of the graph. Each of the subsequent *m* lines contains two integers *a* and *b*, (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*) indicating that vertices *a* and *b* are connected by an undire... | Output the number of cycles in the given graph. | [
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n"
] | [
"7\n"
] | The example graph is a clique and contains four cycles of length 3 and three cycles of length 4. | 0 | [
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "7"
},
{
"input": "10 3\n4 8\n9 4\n8 9",
"output": "1"
},
{
"input": "8 28\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8",
"output":... | 1,678,339,999 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
def dfs(vertex, visited, path):
visited[vertex] = True
path.append(vertex)
count = 0
for neighbor in graph[vertex]:
... | Title: A Simple Task
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.
Input Specification:
The first line of input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=19, ... | ```python
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
def dfs(vertex, visited, path):
visited[vertex] = True
path.append(vertex)
count = 0
for neighbor in graph[v... | 0 |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,602,629,518 | 418 | Python 3 | OK | TESTS | 42 | 108 | 409,600 | n = int(input())
s = 'bbaa' * (n // 4 + 1)
s = s[:n]
print(s) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
s = 'bbaa' * (n // 4 + 1)
s = s[:n]
print(s)
``` | 3 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,585,860,422 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 1,902 | 16,076,800 | n=int(input())
L=[]
aG=0;
mini = 1000000000
maxi = -1000000000;
for i in range(0,n):
a=input().rstrip().split(' ')
L.append(a)
if int(a[0])<=mini and int(a[1])>=maxi:
G=int(a[0]);
H=int(a[1]);
S=i;
mini = int(a[0])
maxi = int(a[1])
#print(S,mini,maxi)
f... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
n=int(input())
L=[]
aG=0;
mini = 1000000000
maxi = -1000000000;
for i in range(0,n):
a=input().rstrip().split(' ')
L.append(a)
if int(a[0])<=mini and int(a[1])>=maxi:
G=int(a[0]);
H=int(a[1]);
S=i;
mini = int(a[0])
maxi = int(a[1])
#print(S,min... | 3 | |
920 | A | Water The Garden | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *... | The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200).
Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively.
Next line contains *k* intege... | For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered. | [
"3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n"
] | [
"3\n1\n4\n"
] | The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is ... | 0 | [
{
"input": "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1",
"output": "3\n1\n4"
},
{
"input": "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4... | 1,517,584,887 | 2,787 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 5,632,000 | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
s = 1
t = [False] * n
for i in arr:
t[i-1] = True
while set(t) != {True}:
q = list(t)
s += 1
for j in range(n):
if j+1 < n:
if q[j+1] == True:
t[j] = True
if j-1 < n: ... | Title: Water The Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the ... | ```python
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
s = 1
t = [False] * n
for i in arr:
t[i-1] = True
while set(t) != {True}:
q = list(t)
s += 1
for j in range(n):
if j+1 < n:
if q[j+1] == True:
t[j] = True
if... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,645,417,899 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | n=int(input())
lst=[int(i) for i in input().split()]
diff_lst=[]
for i in range(len(lst)-1):
diff_lst.append(lst[i]-lst[i+1])
diff_prop=0
for i in set(diff_lst):
if i!=max(set(diff_lst)) and i!=min(set(diff_lst)):
diff_prop=i
break
ans=0
for i in range(len(diff_lst)):
if diff_lst... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
lst=[int(i) for i in input().split()]
diff_lst=[]
for i in range(len(lst)-1):
diff_lst.append(lst[i]-lst[i+1])
diff_prop=0
for i in set(diff_lst):
if i!=max(set(diff_lst)) and i!=min(set(diff_lst)):
diff_prop=i
break
ans=0
for i in range(len(diff_lst)):
i... | 0 |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,580,799,944 | 2,147,483,647 | Python 3 | OK | TESTS | 72 | 109 | 0 | n = int(input())
b, c = 0, 0
for i in map(int, input().split()):
if i < 0:
c += i
else:
b += i
print(b - c)
| Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n = int(input())
b, c = 0, 0
for i in map(int, input().split()):
if i < 0:
c += i
else:
b += i
print(b - c)
``` | 3 | |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T... | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2,... | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr... | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
... | 1,525,889,026 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 17,203,200 | n,q=map(int,input().split())
a,cd,cc=list(map(int,input().split())),0,0
for k in input().split():
k=int(k)
while k:
if a[cc]<=k+cd:
cd-=a[cc]
if cd<0:
cd,k=0,k+cd
cc+=1
else:
cd,k=k+cd,0
if cc>=n:
br... | Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line ... | ```python
n,q=map(int,input().split())
a,cd,cc=list(map(int,input().split())),0,0
for k in input().split():
k=int(k)
while k:
if a[cc]<=k+cd:
cd-=a[cc]
if cd<0:
cd,k=0,k+cd
cc+=1
else:
cd,k=k+cd,0
if cc>=n:
... | 0 | |
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and brin... | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to th... | 1,474,470,618 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | l=[]
maxx=0
while True:
try:
l.append(input())
except EOFError:
break
for x in l:
if len(x)>maxx:
maxx=len(x)
print("*"*(maxx+2))
for i in l:
print("*"+i.center(maxx," ")+"*")
print("*" * (maxx + 2))
| Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You ... | ```python
l=[]
maxx=0
while True:
try:
l.append(input())
except EOFError:
break
for x in l:
if len(x)>maxx:
maxx=len(x)
print("*"*(maxx+2))
for i in l:
print("*"+i.center(maxx," ")+"*")
print("*" * (maxx + 2))
``` | 0 |
602 | B | Approximating a Constant Range | PROGRAMMING | 1,400 | [
"dp",
"implementation",
"two pointers"
] | null | null | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). | Print a single number — the maximum length of an almost constant range of the given sequence. | [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] | [
"4\n",
"5\n"
] | In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10]. | 1,000 | [
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 ... | 1,691,855,211 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | //my
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000005];
int main()
{
int n1,ans = 2,x;
scanf("%d",&n1);
for(int i = 1; i <= n1; i++)
{
scanf("%d",&x);
a[x] = i;
if(a[x-1] > a[x+1])
ans = max(ans,i-max(a[x+1],a[x-2]));
else
ans = max(ans,i-max(a[x+2],a[x-1]));
}
pr... | Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo... | ```python
//my
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000005];
int main()
{
int n1,ans = 2,x;
scanf("%d",&n1);
for(int i = 1; i <= n1; i++)
{
scanf("%d",&x);
a[x] = i;
if(a[x-1] > a[x+1])
ans = max(ans,i-max(a[x+1],a[x-2]));
else
ans = max(ans,i-max(a[x+2],a[x-... | -1 | |
842 | C | Ilya And The Tree | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs",
"math",
"number theory",
"trees"
] | null | null | Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex *i* is equal to *a**i*.
Ilya believes that the beauty of the vertex *x* is the greatest co... | First line contains one integer number *n* — the number of vertices in tree (1<=≤<=*n*<=≤<=2·105).
Next line contains *n* integer numbers *a**i* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=2·105).
Each of next *n*<=-<=1 lines contains two integer numbers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*), which means that t... | Output *n* numbers separated by spaces, where *i*-th number equals to maximum possible beauty of vertex *i*. | [
"2\n6 2\n1 2\n",
"3\n6 2 3\n1 2\n1 3\n",
"1\n10\n"
] | [
"6 6 \n",
"6 6 6 \n",
"10 \n"
] | none | 1,500 | [
{
"input": "2\n6 2\n1 2",
"output": "6 6 "
},
{
"input": "3\n6 2 3\n1 2\n1 3",
"output": "6 6 6 "
},
{
"input": "1\n10",
"output": "10 "
},
{
"input": "10\n2 3 4 5 6 7 8 9 10 11\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n4 8\n8 9\n9 10",
"output": "2 3 2 1 1 1 1 1 1 1 "
},
{
... | 1,504,025,965 | 6,865 | PyPy 3 | WRONG_ANSWER | PRETESTS | 3 | 233 | 149,401,600 | """
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout, setrecursionlimit
import threading
from fractions import gcd
def dfs(u, g1, g2):
global a, g, ans
x1 = gcd(g1, 0)
x2 = gcd(g2, a[u])
ans[u] = max(x1, x2)
g1... | Title: Ilya And The Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number writte... | ```python
"""
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout, setrecursionlimit
import threading
from fractions import gcd
def dfs(u, g1, g2):
global a, g, ans
x1 = gcd(g1, 0)
x2 = gcd(g2, a[u])
ans[u] = max(x1, x2)... | 0 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,633,725,431 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 62 | 6,758,400 | def main():
s = input()
heidi = "heidi"
j = 0
hasHeidi = 0
for i in s:
if(i == heidi[j]):
if(j < 4):
j += 1
else:
hasHeidi = 1
if(hasHeidi == 0):
print("NO")
else:
print("YES")
if __name__ == '__main__':
... | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
def main():
s = input()
heidi = "heidi"
j = 0
hasHeidi = 0
for i in s:
if(i == heidi[j]):
if(j < 4):
j += 1
else:
hasHeidi = 1
if(hasHeidi == 0):
print("NO")
else:
print("YES")
if __name__ == '__ma... | 3 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,669,298,895 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 0 | n=int(input())
a=[int(i) for i in input().split()]
s=1
s1=[]
for i in range(1,n):
if a[i]>a[i-1]:
s+=1
s1.append(s)
else:
s1.append(s)
s=1
print(max(s1)) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n=int(input())
a=[int(i) for i in input().split()]
s=1
s1=[]
for i in range(1,n):
if a[i]>a[i-1]:
s+=1
s1.append(s)
else:
s1.append(s)
s=1
print(max(s1))
``` | -1 | |
278 | B | New Problem | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Yo... | The first line contains integer *n* (1<=≤<=*n*<=≤<=30) — the number of titles you've got to consider. Then follow *n* problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive. | Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title. | [
"5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n",
"4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n"
] | [
"j\n",
"ab\n"
] | In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | 1,000 | [
{
"input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear",
"output": "j"
},
{
"input": "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc",
"output": "ab"
},
{
"input": "1\na",
"output": "b"
},
{
"input": "1\nb",
"output": "a"
},
{
"input": "1\nz",
"o... | 1,571,597,995 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 248 | 0 | # from dust i have come, dust i will be
n = int(input())
a = []
for i in range(n):
x = input()
a.append(x)
arr = []
for i in range(26):
arr.append(chr(i + ord('a')))
for i in range(26):
for j in range(26):
arr.append(arr[i] + chr(j + ord('a')))
for i in range(len(arr)):
... | Title: New Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You'... | ```python
# from dust i have come, dust i will be
n = int(input())
a = []
for i in range(n):
x = input()
a.append(x)
arr = []
for i in range(26):
arr.append(chr(i + ord('a')))
for i in range(26):
for j in range(26):
arr.append(arr[i] + chr(j + ord('a')))
for i in range(len(... | 3 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,578,040,754 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 21 | 1,356 | 27,545,600 | # -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/3/20
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
N = int(input())
A = []
for i in range(N):
row = [int(x) for x in input().split()]
A.append(row)
def count(val, div):
c = 0
... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/3/20
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
N = int(input())
A = []
for i in range(N):
row = [int(x) for x in input().split()]
A.append(row)
def count(val, div):
... | -1 |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,596,355,058 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 155 | 21,196,800 | n = int(input())
thingo=["a","a","b","b"]
print(int(n/4)*"aabb" + "".join(thingo[:n%4])) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
thingo=["a","a","b","b"]
print(int(n/4)*"aabb" + "".join(thingo[:n%4]))
``` | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,656,272,331 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 92 | 4,505,600 | n = int(input())
a = [int(i) for i in input().split()]
x = sum(a)
counter = 0
for i in range(len(a)):
difference = x - a[i]
if difference % 2 == 0:
counter = counter + 1
print(counter) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n = int(input())
a = [int(i) for i in input().split()]
x = sum(a)
counter = 0
for i in range(len(a)):
difference = x - a[i]
if difference % 2 == 0:
counter = counter + 1
print(counter)
``` | 3 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,700,313,373 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | Q, min = input().split()
QsolvinTime = 0
count = 0
qmin = 5
for i in range(int(Q)):
QsolvinTime += qmin
if 240 - int(min) >= QsolvinTime:
qmin += 5
count += 1
else:
break
print(count) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
Q, min = input().split()
QsolvinTime = 0
count = 0
qmin = 5
for i in range(int(Q)):
QsolvinTime += qmin
if 240 - int(min) >= QsolvinTime:
qmin += 5
count += 1
else:
break
print(count)
``` | 3 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,625,758,791 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 62 | 0 | n,k=map(int,input().split())
l=list(map(int,input().split()))
s=set()
for i in range(len(l)):
s.add(l[i])
l1=[i for i in s]
l2=[]
if len(s)>=k:
print("YES")
for i in range(k):
if(l1[i] in l):
l2.append(l.index(l1[i])+1)
l2.sort()
for i in range(len(l2)):
pri... | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
s=set()
for i in range(len(l)):
s.add(l[i])
l1=[i for i in s]
l2=[]
if len(s)>=k:
print("YES")
for i in range(k):
if(l1[i] in l):
l2.append(l.index(l1[i])+1)
l2.sort()
for i in range(len(l2)):
... | 3 | |
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ... | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, yo... | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input... | 1,676,717,806 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | # LUOGU_RID: 102443681
n = int(input())
if n < 3:
print(-1)
else:
print(*range(n, 0, -1)) | Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*... | ```python
# LUOGU_RID: 102443681
n = int(input())
if n < 3:
print(-1)
else:
print(*range(n, 0, -1))
``` | 3 | |
544 | B | Sea and Islands | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. | If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is t... | [
"5 2\n",
"5 25\n"
] | [
"YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n",
"NO\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS"
},
{
"input": "5 25",
"output": "NO"
},
{
"input": "82 6047",
"output": "NO"
},
{
"input": "6 5",
"output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS"
},
{
"input": "10 80",
"outpu... | 1,574,799,916 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 307,200 | import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
def solve():
n, k = read_tuple(int)
grid = [['S' for _ in range(n)] for _ in range(n)]
flag = True
for i in range(n):
for j in range(n):
if k and flag:
grid[i... | Title: Sea and Islands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on... | ```python
import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
def solve():
n, k = read_tuple(int)
grid = [['S' for _ in range(n)] for _ in range(n)]
flag = True
for i in range(n):
for j in range(n):
if k and flag:
... | 3 | |
690 | F1 | Tree of Life (easy) | PROGRAMMING | 1,300 | [] | null | null | Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of *n* points... | The first line of the input contains a single integer *n* – the number of vertices in the tree (1<=≤<=*n*<=≤<=10000). The vertices are labeled with the numbers from 1 to *n*. Then *n*<=-<=1 lines follow, each describing one edge using two space-separated numbers *a* *b* – the labels of the vertices connected by the edg... | Print one integer – the number of lifelines in the tree. | [
"4\n1 2\n1 3\n1 4\n",
"5\n1 2\n2 3\n3 4\n3 5\n"
] | [
"3",
"4"
] | In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5. | 0 | [
{
"input": "4\n1 2\n1 3\n1 4",
"output": "3"
},
{
"input": "5\n1 2\n2 3\n3 4\n3 5",
"output": "4"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "3\n2 1\n3 2",
"output": "1"
},
{
"input": "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "11"
... | 1,490,269,770 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 93 | 4,812,800 | n = int(input())
t = [0] * n
out = 0
for _ in range(n-1):
a, b = input().split(' ')
a, b = [int(a), int(b)]
t[a-1] += 1
t[b-1] += 1
for x in t:
out += x * (x-1) / 2
print(int(out))
| Title: Tree of Life (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a r... | ```python
n = int(input())
t = [0] * n
out = 0
for _ in range(n-1):
a, b = input().split(' ')
a, b = [int(a), int(b)]
t[a-1] += 1
t[b-1] += 1
for x in t:
out += x * (x-1) / 2
print(int(out))
``` | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,676,105,198 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 102,400 | from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
def main():
t = 1
# t = int(input())
for _ in range(t):
run_test_case()
def run_test_case():
n = int(input())
l = list(map(int, input().split()))
sereja = dima = 0
left, ri... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
def main():
t = 1
# t = int(input())
for _ in range(t):
run_test_case()
def run_test_case():
n = int(input())
l = list(map(int, input().split()))
sereja = dima = 0
... | 3 | |
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,612,078,280 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 421 | 204,800 | t=int(input())
television1=[]
television2=[]
start,end=map(int,input().split())
television1=[start,end]
start,end=map(int,input().split())
television2=[start,end]
count=2
for i in range(t-2):
start,end=map(int,input().split())
if start>television1[0]:
television1=[start,end]
count+=1
elif st... | Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
t=int(input())
television1=[]
television2=[]
start,end=map(int,input().split())
television1=[start,end]
start,end=map(int,input().split())
television2=[start,end]
count=2
for i in range(t-2):
start,end=map(int,input().split())
if start>television1[0]:
television1=[start,end]
count+=1
... | 0 | |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,611,815,204 | 2,147,483,647 | PyPy 3 | OK | TESTS | 88 | 202 | 10,956,800 | import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=a[0]%k;t=0
for i in range(1,n):
if a[i]%k!=r:
print(-1)
break
else:
t+=(a[i]-a[0])//k
else:
print(t)
| Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=a[0]%k;t=0
for i in range(1,n):
if a[i]%k!=r:
print(-1)
break
else:
t+=(a[i]-a[0])//k
else:
print(t)
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,677,513,194 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | input1=list(input())
instructions=list(input())
ans=1
counter1=0
counter2=0
for i in range(len(instructions)):
if instructions[counter1]==input1[counter2]:
ans+=1
counter2+=1
counter1+=1
print(ans) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
input1=list(input())
instructions=list(input())
ans=1
counter1=0
counter2=0
for i in range(len(instructions)):
if instructions[counter1]==input1[counter2]:
ans+=1
counter2+=1
counter1+=1
print(ans)
``` | 3 | |
218 | A | Mountain Scenery | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting th... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the gi... | Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. | [
"3 2\n0 5 3 5 1 5 2\n",
"1 1\n0 2 0\n"
] | [
"0 5 3 4 1 4 2 \n",
"0 1 0 \n"
] | none | 500 | [
{
"input": "3 2\n0 5 3 5 1 5 2",
"output": "0 5 3 4 1 4 2 "
},
{
"input": "1 1\n0 2 0",
"output": "0 1 0 "
},
{
"input": "1 1\n1 100 0",
"output": "1 99 0 "
},
{
"input": "3 1\n0 1 0 1 0 2 0",
"output": "0 1 0 1 0 1 0 "
},
{
"input": "3 1\n0 1 0 2 0 1 0",
"out... | 1,593,606,878 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 |
n,k = map(int,input().split())
t = list(map(int,input().split()))
u=0
for i in range(len(t)):
if u<k:
if t[i]>0:
if i==0:
if t[i]-1!=t[i+1]:
u+=1
t[i]-=1
if u==k:
print(*t... | Title: Mountain Scenery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordi... | ```python
n,k = map(int,input().split())
t = list(map(int,input().split()))
u=0
for i in range(len(t)):
if u<k:
if t[i]>0:
if i==0:
if t[i]-1!=t[i+1]:
u+=1
t[i]-=1
if u==k:
... | 0 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,628,327,562 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 14,131,200 | a, b, d = [int(i) for i in input().split()]
n = 0
res = 0
s = [int(i) for i in input().split()]
for i in range(a):
if s[i] < b:
n += s[i]
if n > d:
n = 0
res += 1
print(res) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
a, b, d = [int(i) for i in input().split()]
n = 0
res = 0
s = [int(i) for i in input().split()]
for i in range(a):
if s[i] < b:
n += s[i]
if n > d:
n = 0
res += 1
print(res)
``` | 0 | |
552 | A | Vanya and Table | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of rectangles.
Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=100, 1<=≤<=*y*1<=≤<=*y*2<=≤<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *... | In a single line print the sum of all values in the cells of the table. | [
"2\n1 1 2 3\n2 2 3 3\n",
"2\n1 1 3 3\n1 1 3 3\n"
] | [
"10\n",
"18\n"
] | Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110
So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will ... | 500 | [
{
"input": "2\n1 1 2 3\n2 2 3 3",
"output": "10"
},
{
"input": "2\n1 1 3 3\n1 1 3 3",
"output": "18"
},
{
"input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13",
"output": "510"
},
{
"input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11",
"o... | 1,695,059,582 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 77 | 0 | def solve(x1, y1, x2, y2):
return sum((x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) for i in range(len(x1)))
def main():
n = int(input())
x1 = []
y1 = []
x2 = []
y2 = []
for _ in range(n):
x1_i, y1_i, x2_i, y2_i = map(int, input().split())
x1.append(x1_i)
... | Title: Vanya and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vany... | ```python
def solve(x1, y1, x2, y2):
return sum((x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) for i in range(len(x1)))
def main():
n = int(input())
x1 = []
y1 = []
x2 = []
y2 = []
for _ in range(n):
x1_i, y1_i, x2_i, y2_i = map(int, input().split())
x1.append(x1... | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,684,257,177 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n = int(input())
m = list(map(int, input().split()))
hitler = 0
maxx = m[0]
minn = m[0]
for i in range(1, n):
if m[i] > maxx:
maxx = m[i]
hitler += 1
elif m[i] < minn:
minn = m[i]
hitler += 1
print(hitler)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
m = list(map(int, input().split()))
hitler = 0
maxx = m[0]
minn = m[0]
for i in range(1, n):
if m[i] > maxx:
maxx = m[i]
hitler += 1
elif m[i] < minn:
minn = m[i]
hitler += 1
print(hitler)
``` | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,687,599,843 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 31 | 0 | a, b = input().split()
a, b = int(a), int(b)
print(f"{min(a, b)} {abs(a-b)//2}") | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a, b = input().split()
a, b = int(a), int(b)
print(f"{min(a, b)} {abs(a-b)//2}")
``` | 3 | |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,519,504,403 | 17,903 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 5,632,000 | import sys
counter = 0
checker = 0 | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
import sys
counter = 0
checker = 0
``` | 0 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,622,905,654 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 466 | 2,252,800 | from sys import *
import sys
from math import *
from collections import *
import string
import re
from bisect import *
from functools import reduce
from itertools import permutations, combinations
# import numpy as np
# def arr(): return np.random.randint(1,50,5)
t=stdin.readline
R=range
p=stdout.write
... | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
from sys import *
import sys
from math import *
from collections import *
import string
import re
from bisect import *
from functools import reduce
from itertools import permutations, combinations
# import numpy as np
# def arr(): return np.random.randint(1,50,5)
t=stdin.readline
R=range
p=std... | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,696,262,388 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | k, n, w = list(map(int, input().split()))
ans = [3 for i in range(w + 1)]
for i in range(1, w + 1):
ans[i] = ans[i] * i
print(sum(ans) - n - ans[0])
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k, n, w = list(map(int, input().split()))
ans = [3 for i in range(w + 1)]
for i in range(1, w + 1):
ans[i] = ans[i] * i
print(sum(ans) - n - ans[0])
``` | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,697,625,577 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | def vasyahisper(a, b):
p = min(a, b)
s = ((a - p) // 2) + ((b - p) // 2)
print(f'{p} {s}')
vasyahisper(int(input()), int(input()))
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
def vasyahisper(a, b):
p = min(a, b)
s = ((a - p) // 2) + ((b - p) // 2)
print(f'{p} {s}')
vasyahisper(int(input()), int(input()))
``` | -1 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,695,137,693 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | s = str(input())
s1 = s.split('+')
print('+'.join(sorted(s1))) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
s = str(input())
s1 = s.split('+')
print('+'.join(sorted(s1)))
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | 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.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,995,058 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | #!/usr/bin/python3
n = int(input())
votes = []
for i in range(n):
a, b, c = [int(char) for char in input().split(" ")]
if sum([a, b, c]) >= 2:
votes.append(1)
print(len(votes))
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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 decid... | ```python
#!/usr/bin/python3
n = int(input())
votes = []
for i in range(n):
a, b, c = [int(char) for char in input().split(" ")]
if sum([a, b, c]) >= 2:
votes.append(1)
print(len(votes))
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,675,424,104 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | x = list(map(int, input().split()))
s = 0
for i in range(x[0]):
y = list(map(str, input().split()))
y[1] = int(y[1])
if y[0] == '+':
x[1] = x[1] + y[1]
elif y[0] == '-':
if x[1] >= y[1]:
x[1] = x[1] - y[1]
else:
s = s+1
m = [str(x[1]),str... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
x = list(map(int, input().split()))
s = 0
for i in range(x[0]):
y = list(map(str, input().split()))
y[1] = int(y[1])
if y[0] == '+':
x[1] = x[1] + y[1]
elif y[0] == '-':
if x[1] >= y[1]:
x[1] = x[1] - y[1]
else:
s = s+1
m = [str... | 3 | |
332 | A | Down the Hatch! | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to pl... | The first line contains a single integer *n* (4<=≤<=*n*<=≤<=2000) — the number of participants in the game. The second line describes the actual game: the *i*-th character of this line equals 'a', if the participant who moved *i*-th pointed at the next person with his elbow, and 'b', if the participant pointed with a n... | Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well. | [
"4\nabbba\n",
"4\nabbab\n"
] | [
"1\n",
"0\n"
] | In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the mov... | 500 | [
{
"input": "4\nabbba",
"output": "1"
},
{
"input": "4\nabbab",
"output": "0"
},
{
"input": "4\naaa",
"output": "0"
},
{
"input": "4\naab",
"output": "0"
},
{
"input": "4\naabaabbba",
"output": "1"
},
{
"input": "6\naaaaaaaaaaaaaaaa",
"output": "2"
... | 1,689,603,446 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1689603446.3714156")# 1689603446.371438 | Title: Down the Hatch!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and th... | ```python
print("_RANDOM_GUESS_1689603446.3714156")# 1689603446.371438
``` | 0 | |
622 | F | The Sum of the k-th Powers | PROGRAMMING | 2,600 | [
"math"
] | null | null | There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees.
Find the value of the sum modulo 109<=+<=7 (so you should find the remainder after dividing the answer by the value 109<=+<=7). | The only line contains two integers *n*,<=*k* (1<=≤<=*n*<=≤<=109,<=0<=≤<=*k*<=≤<=106). | Print the only integer *a* — the remainder after dividing the value of the sum by the value 109<=+<=7. | [
"4 1\n",
"4 2\n",
"4 3\n",
"4 0\n"
] | [
"10\n",
"30\n",
"100\n",
"4\n"
] | none | 0 | [
{
"input": "4 1",
"output": "10"
},
{
"input": "4 2",
"output": "30"
},
{
"input": "4 3",
"output": "100"
},
{
"input": "4 0",
"output": "4"
},
{
"input": "10 0",
"output": "10"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 0",
"o... | 1,675,458,104 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 171,929,600 | def lagrange_interpolation(n, y, T, mod):
# f(i)=y_i (i=0,1,...,n) となる f について f(T) を O(n) で求める
finv = [0]*(n+1)
fac = 1
for i in range(1, n+1):
fac = fac*i % mod
finv[n] = pow(fac, mod-2, mod)
for i in range(n-1, -1, -1):
finv[i] = finv[i+1]*(i+1) % mod
T %= mod
L = [1... | Title: The Sum of the k-th Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees.
Find the value of the sum modulo 109<=+<=7 (so you should find the remainder after dividing the answer by ... | ```python
def lagrange_interpolation(n, y, T, mod):
# f(i)=y_i (i=0,1,...,n) となる f について f(T) を O(n) で求める
finv = [0]*(n+1)
fac = 1
for i in range(1, n+1):
fac = fac*i % mod
finv[n] = pow(fac, mod-2, mod)
for i in range(n-1, -1, -1):
finv[i] = finv[i+1]*(i+1) % mod
T %= mod
... | 0 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,559,803,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 |
n = int(input())
arr = list(map(int, input().split(' ')))
last = 0
end = False
for i in arr:
if i - last > 15:
print(last + 15)
end = True
last = i
if not end:
print(last) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
n = int(input())
arr = list(map(int, input().split(' ')))
last = 0
end = False
for i in arr:
if i - last > 15:
print(last + 15)
end = True
last = i
if not end:
print(last)
``` | 0 | |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,600,822,233 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 140 | 0 |
n = input()
a = int(input())
if len(n)%a!=0:
print('NO')
else:
g = len(n)//a
p=0
if g%2==0:
for k in range(0,len(n),g):
u= n[k:k+g]
if u[:g//2]!=u[g//2:][::-1]:
print('NO')
p+=1
... | Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
n = input()
a = int(input())
if len(n)%a!=0:
print('NO')
else:
g = len(n)//a
p=0
if g%2==0:
for k in range(0,len(n),g):
u= n[k:k+g]
if u[:g//2]!=u[g//2:][::-1]:
print('NO')
p+=1
... | 3 | |
400 | B | Inna and New Matrix of Candies | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"schedules"
] | null | null | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a can... | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n"
] | [
"2\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3 4\n*G*S\nG**S\n*G*S",
"output": "2"
},
{
"input": "1 3\nS*G",
"output": "-1"
},
{
"input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S",
"output": "9"
},
{
"input": "5 10\nG***S**... | 1,545,236,944 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n,m=map(int,input().split())
s=-1
l=[]
for i in range(n):
k=list(input())
for j in range(m):
if k[j]=="G":
for a in range(j+1,m):
if k[a]=="S":
s=abs(j-a)
l.append(s)
print(min(l))
| Title: Inna and New Matrix of Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of th... | ```python
n,m=map(int,input().split())
s=-1
l=[]
for i in range(n):
k=list(input())
for j in range(m):
if k[j]=="G":
for a in range(j+1,m):
if k[a]=="S":
s=abs(j-a)
l.append(s)
print(min(l))
``` | 0 | |
356 | A | Knight Tournament | PROGRAMMING | 1,500 | [
"data structures",
"dsu"
] | null | null | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname... | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th f... | Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0. | [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n"
] | [
"3 1 4 0 ",
"0 8 4 6 4 8 6 1 "
] | Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won. | 500 | [
{
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 "
},
{
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1",
"output": "0 8 4 6 4 8 6 1 "
},
{
"input": "2 1\n1 2 1",
"output": "0 1 "
},
{
"input": "2 1\n1 2 2",
"output": "2 0 "
},
{
"input": "3 1\n1 3 1",
"out... | 1,660,393,703 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | # 4 3
# k = [1, 2, 3, 4]
# 1 2 1
# [1, 2], 1
# ans = [0, 1, 0, 0]
# [1, 3, 4]
# 1 3 3
# [1, 3], 3
# ans = [3, 1, 0, 0]
# [3, 4]
# 1 4 4
# [3, 4], 4
# ans = [3, 1, 4, 0]
# [4]
# 8 4
# k = {1, 2, 3, 4, 5, 6, 7, 8}
# 3 5 4
# [3, 4, 5], 4
# ans = [0, 0, 4, 0, 4, 0, 0, 0]
# [1, 2, 4, 6, 7, 8]
# 3 7 6
# [4, 6, 7], 6
#... | Title: Knight Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're j... | ```python
# 4 3
# k = [1, 2, 3, 4]
# 1 2 1
# [1, 2], 1
# ans = [0, 1, 0, 0]
# [1, 3, 4]
# 1 3 3
# [1, 3], 3
# ans = [3, 1, 0, 0]
# [3, 4]
# 1 4 4
# [3, 4], 4
# ans = [3, 1, 4, 0]
# [4]
# 8 4
# k = {1, 2, 3, 4, 5, 6, 7, 8}
# 3 5 4
# [3, 4, 5], 4
# ans = [0, 0, 4, 0, 4, 0, 0, 0]
# [1, 2, 4, 6, 7, 8]
# 3 7 6
# [4, ... | 0 | |
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d... | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black co... | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBW... | 1,664,383,513 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 92 | 0 | ans = 'YES'
for _ in range(8):
line = input()
for i in range(7):
if line[i] == line[i+1]:
ans = 'NO'
break
print(ans) | Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, e... | ```python
ans = 'YES'
for _ in range(8):
line = input()
for i in range(7):
if line[i] == line[i+1]:
ans = 'NO'
break
print(ans)
``` | 3 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | 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 i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,646,440,758 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | n = int(input())
a = list(map(int, input().split()))
dp = [a.count(i + 1) for i in range(n)]
print(max(dp)) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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 Po... | ```python
n = int(input())
a = list(map(int, input().split()))
dp = [a.count(i + 1) for i in range(n)]
print(max(dp))
``` | 0 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,506,868,091 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 124 | 204,800 | import math
n = int(input())
bags = int(math.pow(n,2))
#candies = math.factorial(bags)
n_bags = []
for j in range (n):
n_bags.append("")
for i in range(int(n/2)):
n_bags[j] += str((i*n)+j+1)
n_bags[j] += " "
n_bags[j] += str(bags-(j+(i*n)))
n_bags[j] += " "
#n_bags[j].append((i*n)+j+1)
#n_bags[j].appen... | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
import math
n = int(input())
bags = int(math.pow(n,2))
#candies = math.factorial(bags)
n_bags = []
for j in range (n):
n_bags.append("")
for i in range(int(n/2)):
n_bags[j] += str((i*n)+j+1)
n_bags[j] += " "
n_bags[j] += str(bags-(j+(i*n)))
n_bags[j] += " "
#n_bags[j].append((i*n)+j+1)
#n_bag... | 3 | |
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"in... | 1,697,995,328 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
x = int(input())
prev_faces = [7 - x] # Initialize the previous top face as the opposite of x
for _ in range(n):
a, b = map(int, input().split())
if a == prev_faces[-1] or b == prev_faces[-1] or a + b == 7:
print("NO")
break
prev_faces.append(b)
e... | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other... | ```python
n = int(input())
x = int(input())
prev_faces = [7 - x] # Initialize the previous top face as the opposite of x
for _ in range(n):
a, b = map(int, input().split())
if a == prev_faces[-1] or b == prev_faces[-1] or a + b == 7:
print("NO")
break
prev_faces.appe... | 0 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,697,557,211 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 307,200 | from collections import defaultdict
di = [(0, 1), (1, 0), (1, 1), (0, 0)]
n, m, k = map(int, input().split())
plan = defaultdict(lambda: float('inf'))
for i in range(k):
plan[tuple(map(int, input().split()))] = min(plan[tuple(map(int, input().split()))], i)
for x, y in plan.keys():
if all((x + dx, y ... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
from collections import defaultdict
di = [(0, 1), (1, 0), (1, 1), (0, 0)]
n, m, k = map(int, input().split())
plan = defaultdict(lambda: float('inf'))
for i in range(k):
plan[tuple(map(int, input().split()))] = min(plan[tuple(map(int, input().split()))], i)
for x, y in plan.keys():
if all((... | -1 | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,561,187,507 | 2,147,483,647 | PyPy 3 | OK | TESTS | 67 | 202 | 14,540,800 | n = int(input())
l = list(map(int,input().split()))
k = l.count(1)
h = l.count(2)
if k>h:
print(h+(k-h)//3)
else:
print(k) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n = int(input())
l = list(map(int,input().split()))
k = l.count(1)
h = l.count(2)
if k>h:
print(h+(k-h)//3)
else:
print(k)
``` | 3 | |
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and brin... | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to th... | 1,609,235,095 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 614,400 | import fileinput
m = []
l = []
for line in fileinput.input():
m.append(line[:-1])
l.append(len(line) - 1)
r = max(l)
print('*' * (r + 2))
for i in range(0, len(m) - 1):
s1 = ' ' * ((r - l[i]) // 2)
s2 = ' ' * (r - len(s1) - l[i])
print('*' + s1 + m[i] + s2 + '*')
print('*' * (r + 2)) | Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You ... | ```python
import fileinput
m = []
l = []
for line in fileinput.input():
m.append(line[:-1])
l.append(len(line) - 1)
r = max(l)
print('*' * (r + 2))
for i in range(0, len(m) - 1):
s1 = ' ' * ((r - l[i]) // 2)
s2 = ' ' * (r - len(s1) - l[i])
print('*' + s1 + m[i] + s2 + '*')
print('*' * ... | 0 |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,658,897,538 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | # -*- coding=utf-8 -*-
if __name__ == "__main__":
N = int(input())
if N == 2:
print(1)
print(2)
exit()
counter = 2
dp = [2]
dp_set = set([2])
has_finish = False
for n in range(N - 2):
if n == 0:
dp.append(1)
... | Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
# -*- coding=utf-8 -*-
if __name__ == "__main__":
N = int(input())
if N == 2:
print(1)
print(2)
exit()
counter = 2
dp = [2]
dp_set = set([2])
has_finish = False
for n in range(N - 2):
if n == 0:
dp.append(1)
... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.