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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,678,730,177 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 2,764,800 | import math
import sys
N = 100001
a = [0] * (N)
vis = [False] * (N)
n = int(input())
for i in range(n):
a[i] = int(input())
vis = [False] * (N*5)
a.sort()
k = n-1
m = 0
for i in range(k-1, -1, -1):
if a[k] >= a[i] * 2:
m += 1
k -= 1
if n % 2:
if m > n//2:
print((n//2)+1)
else:
print(n-m)... | Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
import math
import sys
N = 100001
a = [0] * (N)
vis = [False] * (N)
n = int(input())
for i in range(n):
a[i] = int(input())
vis = [False] * (N*5)
a.sort()
k = n-1
m = 0
for i in range(k-1, -1, -1):
if a[k] >= a[i] * 2:
m += 1
k -= 1
if n % 2:
if m > n//2:
print((n//2)+1)
else:
... | 0 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,672,415,226 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
from collections import defaultdict, Counter
def IA(): return list(map(int, inp().split()))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): return float(in... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
from collections import defaultdict, Counter
def IA(): return list(map(int, inp().split()))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): retur... | 0 | |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot... | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**... | 1,638,534,544 | 2,147,483,647 | Python 3 | OK | TESTS | 12 | 46 | 0 | n = int(input())
for i in range(1, n + 1, 2):
print("*" * ((n - i) // 2) + "D" * i + "*" * ((n - i) // 2))
for i in range(n - 2, -1, -2):
print("*" * ((n - i) // 2) + "D" * i + "*" * ((n - i) // 2))
| Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You ... | ```python
n = int(input())
for i in range(1, n + 1, 2):
print("*" * ((n - i) // 2) + "D" * i + "*" * ((n - i) // 2))
for i in range(n - 2, -1, -2):
print("*" * ((n - i) // 2) + "D" * i + "*" * ((n - i) // 2))
``` | 3 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,657,822,729 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 1,638,400 | def appleman_and_card_game(): # inefficient af but im lazy
alphabet = {"A": 0, "B": 0, "C": 0, "D": 0, "E": 0, "F": 0,
"G": 0, "H": 0, "I": 0, "J": 0, "K": 0, "L": 0,
"M": 0, "N": 0, "O": 0, "P": 0, "Q": 0, "R": 0,
"S": 0, "T": 0, "U": 0, "V": 0, "W": 0, "X": 0, ... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
def appleman_and_card_game(): # inefficient af but im lazy
alphabet = {"A": 0, "B": 0, "C": 0, "D": 0, "E": 0, "F": 0,
"G": 0, "H": 0, "I": 0, "J": 0, "K": 0, "L": 0,
"M": 0, "N": 0, "O": 0, "P": 0, "Q": 0, "R": 0,
"S": 0, "T": 0, "U": 0, "V": 0, "W": 0... | 3 | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,557,239,019 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 420 | 2,867,200 | s, t = input(), input()
a1, a2 = list(s), list(t)
r1, r2 = 0, 0
for i in range(ord('a'), ord('z') + 1, 1):
l1 = a1.count(chr(i))
l2 = a2.count(chr(i))
u1 = a1.count(chr(i+ord('A') - ord('a')))
u2 = a2.count(chr(i+ord('A') - ord('a')))
c = min(l1, l2) + min(u1, u2)
r1 += c
r2 += min... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
s, t = input(), input()
a1, a2 = list(s), list(t)
r1, r2 = 0, 0
for i in range(ord('a'), ord('z') + 1, 1):
l1 = a1.count(chr(i))
l2 = a2.count(chr(i))
u1 = a1.count(chr(i+ord('A') - ord('a')))
u2 = a2.count(chr(i+ord('A') - ord('a')))
c = min(l1, l2) + min(u1, u2)
r1 += c
... | 3 | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,674,671,352 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | t=int(input())
for i in range(1,t+1):
print(i,end=' ') | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
t=int(input())
for i in range(1,t+1):
print(i,end=' ')
``` | 0 | |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,499,724,628 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 77 | 5,529,600 | s = input()
print(max( (s[:i] + c + s[i+1:]).count('VK') for i in range(len(s)) for c in ['V', 'K'] )) | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
s = input()
print(max( (s[:i] + c + s[i+1:]).count('VK') for i in range(len(s)) for c in ['V', 'K'] ))
``` | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,693,400,573 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | import math
num = int(input())
maxx = -math.inf
allpas = 0
for i in range(num):
x,y = input().split()
allpas = (allpas + int(y)) - int(x)
if allpas > maxx:
maxx = allpas
print(maxx) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
import math
num = int(input())
maxx = -math.inf
allpas = 0
for i in range(num):
x,y = input().split()
allpas = (allpas + int(y)) - int(x)
if allpas > maxx:
maxx = allpas
print(maxx)
``` | 3 | |
45 | A | Codecraft III | PROGRAMMING | 900 | [
"implementation"
] | A. Codecraft III | 2 | 256 | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa... | The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III. | Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December. | [
"November\n3\n",
"May\n24\n"
] | [
"February\n",
"May\n"
] | none | 0 | [
{
"input": "November\n3",
"output": "February"
},
{
"input": "May\n24",
"output": "May"
},
{
"input": "April\n0",
"output": "April"
},
{
"input": "September\n0",
"output": "September"
},
{
"input": "August\n0",
"output": "August"
},
{
"input": "June\n1... | 1,592,060,962 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 15 | 186 | 0 | ip=input()
n=int(input())
month=['January','February','March','April','May','June','July','August','September','October','November','December']
i=month.index(ip)
if(i+n>12):
print(month[(n-(12-i))%12])
else:
print(month[i+n]) | Title: Codecraft III
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *... | ```python
ip=input()
n=int(input())
month=['January','February','March','April','May','June','July','August','September','October','November','December']
i=month.index(ip)
if(i+n>12):
print(month[(n-(12-i))%12])
else:
print(month[i+n])
``` | -1 |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,580,729,075 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 842 | 1,638,400 | # maa chudaaye duniya
from math import sqrt, ceil
def findnumber(arr, z, lo, hi):
while hi >= lo:
mid = lo + ((hi-lo)//2)
if arr[mid] == z:
return True
elif z > arr[mid]:
lo = mid + 1
else:
hi = mid - 1
return False
... | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
# maa chudaaye duniya
from math import sqrt, ceil
def findnumber(arr, z, lo, hi):
while hi >= lo:
mid = lo + ((hi-lo)//2)
if arr[mid] == z:
return True
elif z > arr[mid]:
lo = mid + 1
else:
hi = mid - 1
return False
... | 3 | |
22 | B | Bargaining Table | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | B. Bargaining Table | 2 | 256 | Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, t... | The first line contains 2 space-separated numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=25) — the office room dimensions. Then there follow *n* lines with *m* characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in ... | Output one number — the maximum possible perimeter of a bargaining table for Bob's office room. | [
"3 3\n000\n010\n000\n",
"5 4\n1100\n0000\n0000\n0000\n0000\n"
] | [
"8\n",
"16\n"
] | none | 0 | [
{
"input": "3 3\n000\n010\n000",
"output": "8"
},
{
"input": "5 4\n1100\n0000\n0000\n0000\n0000",
"output": "16"
},
{
"input": "3 3\n000\n110\n000",
"output": "8"
},
{
"input": "4 2\n00\n10\n11\n00",
"output": "6"
},
{
"input": "3 5\n00001\n00000\n10100",
"out... | 1,633,255,170 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 102,400 | from collections import deque
def st_md(n, adj_list):
visited = [False for _ in range(n + 1)]
longest = adj_list.index(max(adj_list, key=lambda x: len(x))) # Picks the vertex with the most edges
visited[longest] = True
q = deque()
q.append(longest) # It is queued so as to start a BFS
... | Title: Bargaining Table
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either ... | ```python
from collections import deque
def st_md(n, adj_list):
visited = [False for _ in range(n + 1)]
longest = adj_list.index(max(adj_list, key=lambda x: len(x))) # Picks the vertex with the most edges
visited[longest] = True
q = deque()
q.append(longest) # It is queued so as to start... | -1 |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,588,056,546 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 156 | 0 | n, m = [int(i) for i in input().split()]
a1 = min([int(i) for i in input().split()])
a2 = min([int(i) for i in input().split()])
if (a1 == a2):
print(a1)
else:
print(str(min(a1, a2))+str(max(a1, a2))) | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the sm... | ```python
n, m = [int(i) for i in input().split()]
a1 = min([int(i) for i in input().split()])
a2 = min([int(i) for i in input().split()])
if (a1 == a2):
print(a1)
else:
print(str(min(a1, a2))+str(max(a1, a2)))
``` | 0 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,698,948,655 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | def find_groups(arr):
n = len(arr)
group_count = [0] * n
for i in range(n):
if arr[i] == -1:
continue
group_count[arr[i] - 1] += 1
max_group = max(group_count)
return max_group + 1
n = int(input())
managers = []
for i in range(n):
manager = int(input())
manager... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
def find_groups(arr):
n = len(arr)
group_count = [0] * n
for i in range(n):
if arr[i] == -1:
continue
group_count[arr[i] - 1] += 1
max_group = max(group_count)
return max_group + 1
n = int(input())
managers = []
for i in range(n):
manager = int(input())
... | 0 | |
190 | D | Non-Secret Cypher | PROGRAMMING | 1,900 | [
"two pointers"
] | null | null | Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the informati... | The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array... | Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 2\n1 2 1 2\n",
"5 3\n1 2 1 1 3\n",
"3 1\n1 1 1\n"
] | [
"3",
"2",
"6"
] | In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), ... | 2,000 | [
{
"input": "4 2\n1 2 1 2",
"output": "3"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10",
"output": "131"
},
{
"input": "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3... | 1,688,580,168 | 2,147,483,647 | Python 3 | OK | TESTS | 120 | 778 | 51,404,800 | def count_subarrays(n, k, arr):
count = 0
freq = {}
left = 0
for right in range(n):
freq[arr[right]] = freq.get(arr[right], 0) + 1
while left <= right and freq[arr[right]] >= k:
count += n - right
freq[arr[left]] -= 1
left += 1
return count
n, k... | Title: Non-Secret Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunat... | ```python
def count_subarrays(n, k, arr):
count = 0
freq = {}
left = 0
for right in range(n):
freq[arr[right]] = freq.get(arr[right], 0) + 1
while left <= right and freq[arr[right]] >= k:
count += n - right
freq[arr[left]] -= 1
left += 1
return c... | 3 | |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,534,682,597 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 358 | 14,028,800 | n=int(input())
b=list(map(int,input().split()))
a=[]
for i in range(n-1):
a.append(b[i]+b[i+1])
a.append(b[len(b)-1])
print(*a)
| Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
n=int(input())
b=list(map(int,input().split()))
a=[]
for i in range(n-1):
a.append(b[i]+b[i+1])
a.append(b[len(b)-1])
print(*a)
``` | 3 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,612,700,467 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 8 | 154 | 67,072,000 | def reverse(s):
if len(s) == 0:
return s
else:
return reverse(s[1:]) + s[0]
def index(string, test):
for i in range(0, len(string)):
if string[i:i + len(test)] == test:
return i + len(test)
order = input()
reverseOrder = reverse(order)
first = input()
... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
def reverse(s):
if len(s) == 0:
return s
else:
return reverse(s[1:]) + s[0]
def index(string, test):
for i in range(0, len(string)):
if string[i:i + len(test)] == test:
return i + len(test)
order = input()
reverseOrder = reverse(order)
first ... | 0 |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,606,456,326 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 93 | 307,200 | n=int(input())
l=list(map(int,input().split()))
ans1=[]
ans2=[]
for i in range(n-1):
ans1.append(abs(l[i]-l[i+1]))
#print(ans1)
for i in range(n-2):
ans2.append(abs(l[i]-l[i+2]))
#print(ans2)
print(max(max(ans1),min(ans2))) | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n=int(input())
l=list(map(int,input().split()))
ans1=[]
ans2=[]
for i in range(n-1):
ans1.append(abs(l[i]-l[i+1]))
#print(ans1)
for i in range(n-2):
ans2.append(abs(l[i]-l[i+2]))
#print(ans2)
print(max(max(ans1),min(ans2)))
``` | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,591,369,349 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 280 | 0 |
n, k = [int(i) for i in input().split()]
l = [x for x in input().split()]
for i in l:
soma = i.count('4')+i.count('7')
if (soma>k):
n -= 1
print(n)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
n, k = [int(i) for i in input().split()]
l = [x for x in input().split()]
for i in l:
soma = i.count('4')+i.count('7')
if (soma>k):
n -= 1
print(n)
``` | 3 | |
241 | E | Flights | PROGRAMMING | 2,600 | [
"graphs",
"shortest paths"
] | null | null | LiLand is a country, consisting of *n* cities. The cities are numbered from 1 to *n*. The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel between the cities, but the flights are arranged in a way that once you leave a city you wil... | First line of the input contains two integer numbers *n* and *m* (2<=≤<=*n*<=≤<=1000; 1<=≤<=*m*<=≤<=5000) specifying the number of cities and the number of flights.
Each of the next *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) specifying a one-directional flight from city *a**... | If it is impossible for Lily to do her task, print "No" (without quotes) on the only line of the output.
Otherwise print "Yes" (without quotes) on the first line of output, then print an integer *ans**i* (1<=≤<=*ans**i*<=≤<=2) to each of the next *m* lines being the duration of flights in new transportation system. Y... | [
"3 3\n1 2\n2 3\n1 3\n",
"4 4\n1 2\n2 3\n3 4\n1 4\n",
"5 6\n1 2\n2 3\n3 5\n1 4\n4 5\n1 3\n"
] | [
"Yes\n1\n1\n2\n",
"No\n",
"Yes\n1\n1\n1\n2\n1\n2\n"
] | none | 0 | [
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "Yes\n1\n1\n2"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n1 4",
"output": "No"
},
{
"input": "5 6\n1 2\n2 3\n3 5\n1 4\n4 5\n1 3",
"output": "Yes\n1\n1\n1\n2\n1\n2"
}
] | 1,605,331,401 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 64 | 2,000 | 1,126,400 | #Flights
from queue import Queue
def BFS(node ,mk,G):
q = Queue()
q.put(node)
mk[node] = True
while not q.empty():
top = q.get()
for ady in G[top]:
if not mk[ady]:
mk[ady] = True
q.put(ady)
def InitValue(n,m):
G1 = [[]f... | Title: Flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
LiLand is a country, consisting of *n* cities. The cities are numbered from 1 to *n*. The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel... | ```python
#Flights
from queue import Queue
def BFS(node ,mk,G):
q = Queue()
q.put(node)
mk[node] = True
while not q.empty():
top = q.get()
for ady in G[top]:
if not mk[ady]:
mk[ady] = True
q.put(ady)
def InitValue(n,m):
... | 0 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,489,515,033 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 4,608,000 | a = [int(i) for i in input().split()]
if a[0]-a[1]>=-1 and a[0]-a[1]<=1 and a[0]>0 and a[1] >0:
print("YES")
else:
print("NO")
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
a = [int(i) for i in input().split()]
if a[0]-a[1]>=-1 and a[0]-a[1]<=1 and a[0]>0 and a[1] >0:
print("YES")
else:
print("NO")
``` | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,680,275,799 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def almost_prime(num):
ans=0
for n in range(1,num+1):
temp=set()
d=2
while d * d <= n:
while n % d == 0:
temp.add(d)
n //= d
d += 1
if n > 1:
temp.add(n)
if len(temp)==2:
ans+=1
... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
def almost_prime(num):
ans=0
for n in range(1,num+1):
temp=set()
d=2
while d * d <= n:
while n % d == 0:
temp.add(d)
n //= d
d += 1
if n > 1:
temp.add(n)
if len(temp)==2:
... | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Kleofáš is participating in an *n*-thlon - a tournament consisting of *n* different competitions in *n* different disciplines (numbered 1 through *n*). There are *m* participants in the *n*-thlon and each of them participates in all competitions.
In each of these *n* competitions, the participants are given ranks from... | The first line of the input contains two space-separated integers *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=1000) — the number of competitions and the number of participants respectively.
Then, *n* lines follow. The *i*-th of them contains one integer *x**i* (1<=≤<=*x**i*<=≤<=*m*) — the rank of Kleofáš in the *i*... | Output a single real number – the expected overall rank of Kleofáš. Your answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"4 10\n2\n1\n2\n1\n",
"5 5\n1\n2\n3\n4\n5\n",
"3 6\n2\n4\n2\n"
] | [
"1.0000000000000000\n",
"2.7500000000000000\n",
"1.6799999999999999\n"
] | In the first sample, Kleofáš has overall score 6. Nobody else can have overall score less than 6 (but it's possible for one other person to have overall score 6 as well), so his overall rank must be 1. | 0 | [] | 1,689,596,964 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689596964.8779435")# 1689596964.8779626 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kleofáš is participating in an *n*-thlon - a tournament consisting of *n* different competitions in *n* different disciplines (numbered 1 through *n*). There are *m* participants in the *n*-thlon and each of them participates in a... | ```python
print("_RANDOM_GUESS_1689596964.8779435")# 1689596964.8779626
``` | 0 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,587,155,539 | 2,147,483,647 | Python 3 | OK | TESTS | 104 | 296 | 1,433,600 | def compS(s):
t = len(s)
if t%2 == 1:
return s
t//=2
a = compS(s[0:t])
b = compS(s[t::])
return a+b if a<b else b+a
a,b = input(),input()
print("YES" if compS(a) == compS(b) else "NO")
| Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def compS(s):
t = len(s)
if t%2 == 1:
return s
t//=2
a = compS(s[0:t])
b = compS(s[t::])
return a+b if a<b else b+a
a,b = input(),input()
print("YES" if compS(a) == compS(b) else "NO")
``` | 3 | |
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes th... | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose bal... | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
... | 1,694,465,574 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | n=int(input())
arr=list(set(list(map(int,input().split()))))
arr.sort()
flag=0
for i in range(0,len(arr)-3):
if arr[i]+2==arr[i+2]:
if arr[i+1]==arr[i]+1:
flag=1
break
if flag==1:
print("YES")
else:
print("NO") | Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri... | ```python
n=int(input())
arr=list(set(list(map(int,input().split()))))
arr.sort()
flag=0
for i in range(0,len(arr)-3):
if arr[i]+2==arr[i+2]:
if arr[i+1]==arr[i]+1:
flag=1
break
if flag==1:
print("YES")
else:
print("NO")
``` | 0 | |
61 | E | Enemy is weak | PROGRAMMING | 1,900 | [
"data structures",
"trees"
] | E. Enemy is weak | 5 | 256 | The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | The first line of input contains a single number *n* (3<=≤<=*n*<=≤<=106) — the number of men in Roman army. Next line contains *n* different positive integers *a**i* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*a**i*<=≤<=109) — powers of men in the Roman army. | A single integer number, the weakness of the Roman army.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"3\n3 2 1\n",
"3\n2 3 1\n",
"4\n10 8 3 1\n",
"4\n1 5 4 3\n"
] | [
"1\n",
"0\n",
"4\n",
"1\n"
] | none | 2,500 | [
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "0"
},
{
"input": "4\n10 8 3 1",
"output": "4"
},
{
"input": "4\n1 5 4 3",
"output": "1"
},
{
"input": "9\n10 9 5 6 8 3 4 7 11",
"output": "20"
},
{
"input": "7\n11 3 8 4 2 9 6",
... | 1,687,510,043 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 70 | 2,340 | 213,606,400 | def getSum(BiTree, i, n):
sum = 0
while i > 0:
sum += BiTree[i]
i -= i & (-i)
return sum
from sys import stdin, stdout
def update(BiTree, i, n, val):
while i <n:
BiTree[i] += val
i += i & (-i)
def construct(a, BiTree, a2, a3, n):
lcount = [0 for i in range(n... | Title: Enemy is weak
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roma... | ```python
def getSum(BiTree, i, n):
sum = 0
while i > 0:
sum += BiTree[i]
i -= i & (-i)
return sum
from sys import stdin, stdout
def update(BiTree, i, n, val):
while i <n:
BiTree[i] += val
i += i & (-i)
def construct(a, BiTree, a2, a3, n):
lcount = [0 for i ... | 3.368127 |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,696,921,006 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 186 | 0 | n = int(input())
coins = [int(i) for i in input().split()]
fq = 101*[0] #skip index 0
nSum = 0
for i in range(n):
nSum += coins[i]
fq[int(coins[i])] += 1
avg = nSum//2
n_coin = 0
value_n_coin = 0
stop_value = 0
for value in range(100,0,-1):
if fq[value]==0: continue
if fq[value]*value + val... | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n = int(input())
coins = [int(i) for i in input().split()]
fq = 101*[0] #skip index 0
nSum = 0
for i in range(n):
nSum += coins[i]
fq[int(coins[i])] += 1
avg = nSum//2
n_coin = 0
value_n_coin = 0
stop_value = 0
for value in range(100,0,-1):
if fq[value]==0: continue
if fq[value]*v... | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,642,519,099 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 154 | 307,200 | from collections import defaultdict
def solve():
n = int(input())
cnt = defaultdict(int)
for i in range(n):
s = input()
cnt[s] += 1
ans = ""
cnt[ans] = 0
for i in cnt:
if (cnt[i] > cnt[ans]):
ans = i
print(ans)
t = 1
#t = int(input())
fo... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
from collections import defaultdict
def solve():
n = int(input())
cnt = defaultdict(int)
for i in range(n):
s = input()
cnt[s] += 1
ans = ""
cnt[ans] = 0
for i in cnt:
if (cnt[i] > cnt[ans]):
ans = i
print(ans)
t = 1
#t = int(in... | 3.960928 |
520 | B | Two Buttons | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"greedy",
"implementation",
"math",
"shortest paths"
] | null | null | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . | Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. | [
"4 6\n",
"10 1\n"
] | [
"2\n",
"9\n"
] | In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | 1,000 | [
{
"input": "4 6",
"output": "2"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "2 10",
"outpu... | 1,699,675,530 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | m,n=map(int,input().split())
res1=n-m if n>=m else float('inf')
res=0
while n>m:
res+=1+(n&1)
n>>=1
print(min(res+m-n,res1)) | Title: Two Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by t... | ```python
m,n=map(int,input().split())
res1=n-m if n>=m else float('inf')
res=0
while n>m:
res+=1+(n&1)
n>>=1
print(min(res+m-n,res1))
``` | 0 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,623,642,030 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 233 | 1,843,200 | # 1 2 4
# 1 2 6
# 1 3 6
n = int(input())
arr = list(map(int, input().split()))
from collections import Counter
c = Counter(arr)
if 5 in arr or 7 in arr or arr.count(1) != n//3 or arr.count(2)+arr.count(3) != n//3 or (3 in arr and arr.count(3) > arr.count(6)):
print(-1)
else:
for i in range(n//3):
pr... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
# 1 2 4
# 1 2 6
# 1 3 6
n = int(input())
arr = list(map(int, input().split()))
from collections import Counter
c = Counter(arr)
if 5 in arr or 7 in arr or arr.count(1) != n//3 or arr.count(2)+arr.count(3) != n//3 or (3 in arr and arr.count(3) > arr.count(6)):
print(-1)
else:
for i in range(n//3):
... | 3 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,693,932,660 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | def cAPS_lOCK(string):
if len(string) == 1 :
return string.capitalize()
if string[0] == string[1]:
return string.lower()
elif string[1:].isupper():
return string.capitalize()
elif string.isupper():
return string.capitalize()
else :
return string
i... | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
def cAPS_lOCK(string):
if len(string) == 1 :
return string.capitalize()
if string[0] == string[1]:
return string.lower()
elif string[1:].isupper():
return string.capitalize()
elif string.isupper():
return string.capitalize()
else :
return s... | 0 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,657,561,769 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 0 | n=int(input())
a=[]
a=input().split(maxsplit=n)
a=[int(item) for item in a]
k1=0
k2=0
k3=0
b=[]
c=[[],[],[]]
for i in range (n):
if a[i]==1:
k1=k1+1
c[0].append(i)
elif a[i]==2:
k2=k2+1
c[1].append(i)
else:
k3=k3+1
c[2].append(i)
b.append(k1... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n=int(input())
a=[]
a=input().split(maxsplit=n)
a=[int(item) for item in a]
k1=0
k2=0
k3=0
b=[]
c=[[],[],[]]
for i in range (n):
if a[i]==1:
k1=k1+1
c[0].append(i)
elif a[i]==2:
k2=k2+1
c[1].append(i)
else:
k3=k3+1
c[2].append(i)
b... | 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,697,050,849 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 |
n = int(input())
x = 0
for i in range(n):
s = input()
if s[-1] == '+' or s[0] == '+':
x+=1
else:
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 = int(input())
x = 0
for i in range(n):
s = input()
if s[-1] == '+' or s[0] == '+':
x+=1
else:
x-=1
print(x)
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,612,518,985 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 154 | 0 | a,b,c,d=sorted(map(int,input().split()))
if(a+b>c or b+c>d):
print("TRIANGLE")
elif(a+b==c or b+c==d):
print("SEGMENT")
else:
print("IMPOSSIBLE") | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
a,b,c,d=sorted(map(int,input().split()))
if(a+b>c or b+c>d):
print("TRIANGLE")
elif(a+b==c or b+c==d):
print("SEGMENT")
else:
print("IMPOSSIBLE")
``` | 3.9615 |
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,610,815,275 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 108 | 1,433,600 | inp = input()
inp = inp.split(' ')
children = 0
packs = 0
children = int(inp[0])
packs = int(inp[1])
distressed = 0
for i in range(children):
s = input()
s = s.split(' ')
if s[0] == '+':
packs += int(s[1])
else:
if packs < int(s[1]):
distressed += 1
e... | 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
inp = input()
inp = inp.split(' ')
children = 0
packs = 0
children = int(inp[0])
packs = int(inp[1])
distressed = 0
for i in range(children):
s = input()
s = s.split(' ')
if s[0] == '+':
packs += int(s[1])
else:
if packs < int(s[1]):
distressed += 1
... | 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,689,769,877 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
l={'Tetrahedron':4,'Cube':6, 'Octahedron':8,'Dodecahedron':12,'Icosahedron':20}
m = 0
for i in range(n):
s = input()
for key, value in l.items():
if s == value:
m += key
print(m) | 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
n=int(input())
l={'Tetrahedron':4,'Cube':6, 'Octahedron':8,'Dodecahedron':12,'Icosahedron':20}
m = 0
for i in range(n):
s = input()
for key, value in l.items():
if s == value:
m += key
print(m)
``` | 0 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,486,310,601 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | input1 = input("Enter the bigger number:\n")
input2 = input("Enter the smaller number:\n")
try:
input1>0
input2>0
except:
print("Please enter a postive number")
if input1-input2 == 0:
print("No")
else:
print("Yes") | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
input1 = input("Enter the bigger number:\n")
input2 = input("Enter the smaller number:\n")
try:
input1>0
input2>0
except:
print("Please enter a postive number")
if input1-input2 == 0:
print("No")
else:
print("Yes")
``` | -1 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,540,936,736 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | s = input().split()
a = s[0]
b = s[1]
n = int(s[2])
for i in range(len(b)):
for j in '0123456789':
c = a + j
if int(c) % int(b) == 0:
a = c
break
if a != c:
a = -1
break
if int(a) != -1:
a = a + '0' * (n - len(b))
print(a) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
s = input().split()
a = s[0]
b = s[1]
n = int(s[2])
for i in range(len(b)):
for j in '0123456789':
c = a + j
if int(c) % int(b) == 0:
a = c
break
if a != c:
a = -1
break
if int(a) != -1:
a = a + '0' * (n - len(b))
print(a)
``` | 0 | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,620,677,755 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 124 | 6,758,400 | a = open('input.txt', 'r')
b = open('output.txt', 'w')
x, y = map(int, a.readline().split())
if x >= y:
b.write('BG' * y + 'B' * (x-y))
else:
b.write('GB' * x + 'G' * (y-x))
| Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
a = open('input.txt', 'r')
b = open('output.txt', 'w')
x, y = map(int, a.readline().split())
if x >= y:
b.write('BG' * y + 'B' * (x-y))
else:
b.write('GB' * x + 'G' * (y-x))
``` | 3 | |
272 | D | Dima and Two Sequences | PROGRAMMING | 1,600 | [
"combinatorics",
"math",
"sortings"
] | null | null | Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109). The numbers in the lines are separated by spaces.
The last line contains integer *m* ... | In the single line print the remainder after dividing the answer to the problem by number *m*. | [
"1\n1\n2\n7\n",
"2\n1 2\n2 3\n11\n"
] | [
"1\n",
"2\n"
] | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | 2,000 | [
{
"input": "1\n1\n2\n7",
"output": "1"
},
{
"input": "2\n1 2\n2 3\n11",
"output": "2"
},
{
"input": "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5... | 1,649,934,371 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 16,588,800 | import collections
import math
import sys
def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = collections.defaultdict(int)
div = 1
for x, y in zip(a, b):
d[x] += 1
d[y] += 1
if x == y:
div *= ... | Title: Dima and Two Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the ... | ```python
import collections
import math
import sys
def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = collections.defaultdict(int)
div = 1
for x, y in zip(a, b):
d[x] += 1
d[y] += 1
if x == y:
... | 0 | |
174 | A | Problem About Equation | PROGRAMMING | 1,100 | [
"math"
] | null | null | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the... | The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the ... | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus ... | [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
] | [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
] | none | 500 | [
{
"input": "5 50\n1 2 3 4 5",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000"
},
{
"input": "2 2\n1 100",
"output": "-1"
},
{
"input": "2 2\n1 1",
"output": "1.000000\n1.000000"
},
{
"input": "3 2\n1 2 1",
"output": "1.000000\n0.000000\n1.000000"
},
{
... | 1,573,480,800 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | n, m = map(int, input().split())
arr = list(map(int, input().split()))
check = 0
for i in range(n - 1):
if check > m:
print(-1)
exit()
check += max(arr[i + 1], arr[i]) - min(arr[i + 1], arr[i])
need = (m + sum(arr)) / n
for i in range(n):
answ = need - arr[i]
print("{:.6f}... | Title: Problem About Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In... | ```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
check = 0
for i in range(n - 1):
if check > m:
print(-1)
exit()
check += max(arr[i + 1], arr[i]) - min(arr[i + 1], arr[i])
need = (m + sum(arr)) / n
for i in range(n):
answ = need - arr[i]
pri... | 0 | |
985 | D | Sand Fortress | PROGRAMMING | 2,100 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand o... | The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively. | Print the minimum number of spots you can occupy so the all the castle building conditions hold. | [
"5 2\n",
"6 8\n"
] | [
"3\n",
"3\n"
] | Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are ... | 0 | [
{
"input": "5 2",
"output": "3"
},
{
"input": "6 8",
"output": "3"
},
{
"input": "20 4",
"output": "7"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1414213562"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 10000000000000000... | 1,586,182,912 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 307,200 | n, h = map(int, input().split())
d = h * (h + 1) // 2
if n >= d:
ok = 10 ** 20
ng = 0
while (ok - ng > 1):
mid = (ok + ng) // 2
if (h + mid) * (mid - h + 1) // 2 + mid * (mid + 1) // 2 >= n:
ok = mid
else:
ng = mid
print(ok+ok-h+1)
else:
... | Title: Sand Fortress
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars... | ```python
n, h = map(int, input().split())
d = h * (h + 1) // 2
if n >= d:
ok = 10 ** 20
ng = 0
while (ok - ng > 1):
mid = (ok + ng) // 2
if (h + mid) * (mid - h + 1) // 2 + mid * (mid + 1) // 2 >= n:
ok = mid
else:
ng = mid
print(ok+ok-h+1)
... | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,687,952,928 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | friends_number = int(input())
index_gave_to_arr = list(map(int, input().split()))
new_arr = ''
for i in range(1, friends_number + 1):
new_arr += str(index_gave_to_arr.index(i) + 1) + ' '
print(new_arr) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
friends_number = int(input())
index_gave_to_arr = list(map(int, input().split()))
new_arr = ''
for i in range(1, friends_number + 1):
new_arr += str(index_gave_to_arr.index(i) + 1) + ' '
print(new_arr)
``` | 3 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,699,633,195 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 409,600 | def main():
n = int(input())
s = input()
count = 0
while s.count('10') + s.count ('01') > 0:
count = count + s.count('10')
s = s.replace("10", "")
count = count + s.count('01')
s = s.replace("01", "")
print(n - count * 2)
main() | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
def main():
n = int(input())
s = input()
count = 0
while s.count('10') + s.count ('01') > 0:
count = count + s.count('10')
s = s.replace("10", "")
count = count + s.count('01')
s = s.replace("01", "")
print(n - count * 2)
main()
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,663,069,410 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | a,b=[int(x) for x in input().split()]
x= a*b
print(int(x/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
a,b=[int(x) for x in input().split()]
x= a*b
print(int(x/2))
``` | 3.977 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,661,440,128 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | l = input()
m = input()
z = l[::-1]
if z == m:
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
l = input()
m = input()
z = l[::-1]
if z == m:
print("YES")
else:
print("NO")
``` | 3.977 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,657,031,999 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | inp = input()
print(['YES', 'NO'][any(map(lambda x: x in inp, ['2','3', '444', '5', '6', '7', '8', '9', '0']))]) | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
inp = input()
print(['YES', 'NO'][any(map(lambda x: x in inp, ['2','3', '444', '5', '6', '7', '8', '9', '0']))])
``` | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,622,809,621 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 312 | 0 | n=input()
l=input()
if n==l[::-1]:
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
n=input()
l=input()
if n==l[::-1]:
print("YES")
else:
print("NO")
``` | 3.922 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,679,563,098 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | s = input()
s = s.split()
print(int(s[0]) * int(s[1]) // 2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
s = input()
s = s.split()
print(int(s[0]) * int(s[1]) // 2)
``` | 3.977 |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,652,521,916 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | def solve (n ,m):
if n < m:
return n
return solve(n//m,m) + n + n%m
n, m = input().split()
n = int(n)
m = int(m)
print(solve(n, m))
| Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
def solve (n ,m):
if n < m:
return n
return solve(n//m,m) + n + n%m
n, m = input().split()
n = int(n)
m = int(m)
print(solve(n, m))
``` | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,579,583,583 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 186 | 2,150,400 | n=input()
n=int(n)
a=input().split()
for i in range(n-1):
if len(a)==1:
break
a.remove(max(a))
a.remove(min(a))
print(" ".join(a))
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n=input()
n=int(n)
a=input().split()
for i in range(n-1):
if len(a)==1:
break
a.remove(max(a))
a.remove(min(a))
print(" ".join(a))
``` | -1 | |
721 | C | Journey | PROGRAMMING | 1,800 | [
"dp",
"graphs"
] | null | null | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially I... | The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them cont... | Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in t... | [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n"
] | [
"3\n1 2 4 \n",
"4\n1 2 4 6 \n",
"3\n1 3 5 \n"
] | none | 1,500 | [
{
"input": "4 3 13\n1 2 5\n2 3 7\n2 4 8",
"output": "3\n1 2 4 "
},
{
"input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1",
"output": "4\n1 2 4 6 "
},
{
"input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2",
"output": "3\n1 3 5 "
},
{
"input": "10 10 100\n1 4 1\n6 4 1\n9 3... | 1,586,098,223 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 7 | 295 | 8,601,600 | def dfs(graph,i,n,timeLeft):
if i == n and timeLeft>=0:
return [n]
if timeLeft<=0:
return []
maxCitiesAfter = 0
maxCitiesTravelled = []
for vertice,time in graph[i]:
citiesTravelled = dfs(graph,vertice,n,timeLeft-time)
if len(citiesTravelled)>maxCitiesAfter:
... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlato... | ```python
def dfs(graph,i,n,timeLeft):
if i == n and timeLeft>=0:
return [n]
if timeLeft<=0:
return []
maxCitiesAfter = 0
maxCitiesTravelled = []
for vertice,time in graph[i]:
citiesTravelled = dfs(graph,vertice,n,timeLeft-time)
if len(citiesTravelled)>maxCit... | -1 | |
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,629,234,083 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 6,963,200 | inp = []
for i in range(int(input())):
T_inp = input()
T_inp = T_inp.split(' ')
inp.append(T_inp)
print(inp)
for i in range(3):
sum = 0
for x in range(len(inp)):
sum += int(inp[x][i])
if sum == 0 and i == 2:
print("YES")
elif sum == 0:
continue... | 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
inp = []
for i in range(int(input())):
T_inp = input()
T_inp = T_inp.split(' ')
inp.append(T_inp)
print(inp)
for i in range(3):
sum = 0
for x in range(len(inp)):
sum += int(inp[x][i])
if sum == 0 and i == 2:
print("YES")
elif sum == 0:
... | 0 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,692,537,063 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n=map(int,input().split())
ans=(m*n)//2
print(ans) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n=map(int,input().split())
ans=(m*n)//2
print(ans)
``` | 3.977 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,618,510,473 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | c = input()
c = c.split(sep=" ")
m = int(c[0])
n = int(c[1])
a = m*n/2
b = str(a)
b = b.split(sep = ".")
print(b)
if b[1] == '0':
a = b[0]
print(a)
if type(a) == float:
a -= 0.5
print(a) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
c = input()
c = c.split(sep=" ")
m = int(c[0])
n = int(c[1])
a = m*n/2
b = str(a)
b = b.split(sep = ".")
print(b)
if b[1] == '0':
a = b[0]
print(a)
if type(a) == float:
a -= 0.5
print(a)
``` | 0 |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,692,452,492 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 124 | 0 | t=input()
m=["H","Q","9"]
for j in m:
if j in t:
print("YES")
break
else:print("NO") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
t=input()
m=["H","Q","9"]
for j in m:
if j in t:
print("YES")
break
else:print("NO")
``` | 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,683,455,461 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n=int(input())
x=list(map(int,input().split()))
c=0
cnt=0
i=1
d=0
while i<n:
if x[i]==x[i-1]:
cnt=0
elif x[i]>x[i-1] and cnt!=1:
c+=1
cnt=1
elif x[i]<x[i-1] and cnt!=-1:
d+=1
cnt=-1
i+=1
print(c) | 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())
x=list(map(int,input().split()))
c=0
cnt=0
i=1
d=0
while i<n:
if x[i]==x[i-1]:
cnt=0
elif x[i]>x[i-1] and cnt!=1:
c+=1
cnt=1
elif x[i]<x[i-1] and cnt!=-1:
d+=1
cnt=-1
i+=1
print(c)
``` | 0 | |
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
... | 1,663,949,069 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 61 | 409,600 |
import math
import sys
from collections import deque,OrderedDict,defaultdict
import heapq,re
from collections import Counter
def inp(): return sys.stdin.readline().rstrip()
def mpp(): return map(int,inp().split())
def lis(): return list(mpp())
def yn(n):
if n:
return "YES"
else:
re... | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems,... | ```python
import math
import sys
from collections import deque,OrderedDict,defaultdict
import heapq,re
from collections import Counter
def inp(): return sys.stdin.readline().rstrip()
def mpp(): return map(int,inp().split())
def lis(): return list(mpp())
def yn(n):
if n:
return "YES"
else:
... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,659,528,847 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | M = int(input())
N = int(input())
x = M * N
print(x // 2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M = int(input())
N = int(input())
x = M * N
print(x // 2)
``` | -1 |
626 | B | Cards | PROGRAMMING | 1,300 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adja... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. | Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. | [
"2\nRB\n",
"3\nGRG\n",
"5\nBBBBB\n"
] | [
"G\n",
"BR\n",
"B\n"
] | In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue car... | 750 | [
{
"input": "2\nRB",
"output": "G"
},
{
"input": "3\nGRG",
"output": "BR"
},
{
"input": "5\nBBBBB",
"output": "B"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBB... | 1,697,163,841 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | memo = {}
def solve(c, r, g, b):
if any([r < 0, g < 0, b < 0]):
return 0
if c == "R" and r == 1 and g == b == 0:
return 1
if c == "G" and g == 1 and r == b == 0:
return 1
if c == "B" and b == 1 and r == g == 0:
return 1
memo[(c, r, g, b)] = any(
... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors... | ```python
memo = {}
def solve(c, r, g, b):
if any([r < 0, g < 0, b < 0]):
return 0
if c == "R" and r == 1 and g == b == 0:
return 1
if c == "G" and g == 1 and r == b == 0:
return 1
if c == "B" and b == 1 and r == g == 0:
return 1
memo[(c, r, g, b)] = any... | 0 | |
873 | E | Awards For Contestants | PROGRAMMING | 2,300 | [
"brute force",
"data structures",
"dp"
] | null | null | Alexey recently held a programming contest for students from Berland. *n* students participated in a contest, *i*-th of them solved *a**i* problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree... | The first line contains one integer number *n* (3<=≤<=*n*<=≤<=3000).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5000). | Output *n* numbers. *i*-th number must be equal to the degree of diploma *i*-th contestant will receive (or <=-<=1 if he doesn't receive any diploma).
If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists. | [
"4\n1 2 3 4\n",
"6\n1 4 3 1 1 2\n"
] | [
"3 3 2 1 \n",
"-1 1 2 -1 -1 3 \n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "3 3 2 1 "
},
{
"input": "6\n1 4 3 1 1 2",
"output": "-1 1 2 -1 -1 3 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,586,683,621 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 140 | 0 | n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
dip = {}
first_value = 0
first_index = 2
for i in range(first_index, n):
if b[i] - b[i-1] >= first_value:
first_value = b[i] - b[i-1]
first_index = i
second_value = 0
second_index = 1
for i in range(second_index... | Title: Awards For Contestants
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alexey recently held a programming contest for students from Berland. *n* students participated in a contest, *i*-th of them solved *a**i* problems. Now he wants to award some contestants. Alexey can award the st... | ```python
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
dip = {}
first_value = 0
first_index = 2
for i in range(first_index, n):
if b[i] - b[i-1] >= first_value:
first_value = b[i] - b[i-1]
first_index = i
second_value = 0
second_index = 1
for i in range(se... | 0 | |
145 | C | Lucky Subsequence | PROGRAMMING | 2,100 | [
"combinatorics",
"dp",
"math"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has sequence *a* consisting of *n* integers.
The subsequence of the sequence *a* is such su... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the sequence *a*. | On the single line print the single number — the answer to the problem modulo prime number 1000000007 (109<=+<=7). | [
"3 2\n10 10 10\n",
"4 2\n4 4 7 7\n"
] | [
"3\n",
"4\n"
] | In the first sample all 3 subsequences of the needed length are considered lucky.
In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}. | 1,500 | [
{
"input": "3 2\n10 10 10",
"output": "3"
},
{
"input": "4 2\n4 4 7 7",
"output": "4"
},
{
"input": "7 4\n1 2 3 4 5 6 7",
"output": "35"
},
{
"input": "7 4\n7 7 7 7 7 7 7",
"output": "0"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"... | 1,673,930,557 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 |
from math import comb
#import operator
# t = int(input())
# for _ in range(t):
#n = int(input())
#cost = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
# print(b)
# print(b)
# print(a)
n=a[0]
k=a[1]
def isLucky(val):
string=str... | Title: Lucky Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are n... | ```python
from math import comb
#import operator
# t = int(input())
# for _ in range(t):
#n = int(input())
#cost = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
# print(b)
# print(b)
# print(a)
n=a[0]
k=a[1]
def isLucky(val):
... | 0 | |
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,699,934,790 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 217 | 102,400 | n=int(input())
b=0
for i in range(n):
a=input()
if a=="Icosahedron":
b=b+20
if a=="Cube":
b=b+6
if a=="Tetrahedron":
b=b+4
if a=="Dodecahedron":
b=b+12
if a=="Octahedron":
b=b+8
print(b)
| 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
n=int(input())
b=0
for i in range(n):
a=input()
if a=="Icosahedron":
b=b+20
if a=="Cube":
b=b+6
if a=="Tetrahedron":
b=b+4
if a=="Dodecahedron":
b=b+12
if a=="Octahedron":
b=b+8
print(b)
``` | 3 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,683,995,029 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,m = [int(i) for i in input().split()]
vals = [int(i) for i in input().split()]
def qSort(listt):
n = len(listt)
if n <= 1:
return listt
x = listt[n//2]
b1 = [b for b in listt if b < x]
bx = [b for b in listt if b == x]
b2 = [b for b in listt if b > x]
return qSort(b1) +... | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m = [int(i) for i in input().split()]
vals = [int(i) for i in input().split()]
def qSort(listt):
n = len(listt)
if n <= 1:
return listt
x = listt[n//2]
b1 = [b for b in listt if b < x]
bx = [b for b in listt if b == x]
b2 = [b for b in listt if b > x]
return q... | 0 | |
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
}... | 1,669,999,889 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 38 | 278 | 6,451,200 | # LUOGU_RID: 96348952
import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
ans1=ans2=q1=i=q2=0
f=1
j=n-1
while i<=j:
if f:
if q1<=q2:
q1+=a[i]
i+=1
ans1+=1
else:
if q1>=q2:
q2+=a[j]
j-=1
... | Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo... | ```python
# LUOGU_RID: 96348952
import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
ans1=ans2=q1=i=q2=0
f=1
j=n-1
while i<=j:
if f:
if q1<=q2:
q1+=a[i]
i+=1
ans1+=1
else:
if q1>=q2:
q2+=a[j]
... | 0 |
278 | A | Circle Line | PROGRAMMING | 800 | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) —... | Print a single number — the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of st... | 500 | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"inpu... | 1,586,344,888 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 186 | 307,200 | n=int(input())
l=list(map(int,input().split()))
s,t=map(int,input().split())
a=0
b=0
i=s-1
while(1):
if i==t-1:
break
a=a+l[i]
i=(i+1)%n
i=t-1
while(1):
if i==(s-1):
break
b=b+l[i]
i=(i+1)%n
if a>0 and b>0:
print(min(a,b))
elif a>0 and b==0:
prin... | Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd... | ```python
n=int(input())
l=list(map(int,input().split()))
s,t=map(int,input().split())
a=0
b=0
i=s-1
while(1):
if i==t-1:
break
a=a+l[i]
i=(i+1)%n
i=t-1
while(1):
if i==(s-1):
break
b=b+l[i]
i=(i+1)%n
if a>0 and b>0:
print(min(a,b))
elif a>0 and b==0:... | 3 | |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,624,953,182 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 77 | 0 | n,m = map(int,input().split(" "))
topper_per_sub = {}
marks_per_student = {}
for i in range(1,n+1):
a = input()
marks_per_student[i] = a
for j in range(0,len(a)):
marks_in_this_sub = int(a[j])
if j+1 not in topper_per_sub.keys():
topper_per_sub[j+1] = [i]
else:
if marks_in_this_sub > int... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
n,m = map(int,input().split(" "))
topper_per_sub = {}
marks_per_student = {}
for i in range(1,n+1):
a = input()
marks_per_student[i] = a
for j in range(0,len(a)):
marks_in_this_sub = int(a[j])
if j+1 not in topper_per_sub.keys():
topper_per_sub[j+1] = [i]
else:
if marks_in_this... | 3 | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,697,111,860 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 936 | 22,323,200 | import math
# 预处理数组
N = int(1e6+1)
is_prime = [True] * N
is_prime[0], is_prime[1] = False, False
for i in range(2, int(math.sqrt(N))+1):
if is_prime[i]:
for j in range(i*i, N, i):
is_prime[j] = False
def is_t_prime(num):
# 判断一个数是否为T-prime
# T-prime的特点是有且仅有三个正因子,即平方根也是质数
... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
import math
# 预处理数组
N = int(1e6+1)
is_prime = [True] * N
is_prime[0], is_prime[1] = False, False
for i in range(2, int(math.sqrt(N))+1):
if is_prime[i]:
for j in range(i*i, N, i):
is_prime[j] = False
def is_t_prime(num):
# 判断一个数是否为T-prime
# T-prime的特点是有且仅有三个正因子,即... | 3 | |
378 | B | Semifinals | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Two semifinals have just been in the running tournament. Each semifinal had *n* participants. There are *n* participants advancing to the finals, they are chosen as follows: from each semifinal, we choose *k* people (0<=≤<=2*k*<=≤<=*n*) who showed the best result in their semifinals and all other places in the finals g... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of participants in each semifinal.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=109) — the results of the *i*-th participant (the number of milliseconds he needs to cover the semifinals distan... | Print two strings consisting of *n* characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The *i*-th character in the *j*-th line should equal "1" if the *i*-th participant of... | [
"4\n9840 9920\n9860 9980\n9930 10020\n10040 10090\n",
"4\n9900 9850\n9940 9930\n10000 10020\n10060 10110\n"
] | [
"1110\n1100\n",
"1100\n1100\n"
] | Consider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090.
- If *k* = 0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. - If... | 1,000 | [
{
"input": "4\n9840 9920\n9860 9980\n9930 10020\n10040 10090",
"output": "1110\n1100"
},
{
"input": "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110",
"output": "1100\n1100"
},
{
"input": "1\n1 2",
"output": "1\n0"
},
{
"input": "1\n2 1",
"output": "0\n1"
},
{
"... | 1,633,116,116 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 38,707,200 | i=int(input())
t=[]
for x in range(i):
a,b=map(int,input().split())
t.append([a,1])
t.append([b,2])
t.sort()
al=bl=0
for x in t[:i]:
if x[1]==1: al+=1
else: bl+=1
al=max(i//2,al);bl=max(bl,i//2)
print('1'*al+'0'*(i-al))
print('1'*bl+'0'*(i-bl)) | Title: Semifinals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two semifinals have just been in the running tournament. Each semifinal had *n* participants. There are *n* participants advancing to the finals, they are chosen as follows: from each semifinal, we choose *k* people (0<=≤<=2... | ```python
i=int(input())
t=[]
for x in range(i):
a,b=map(int,input().split())
t.append([a,1])
t.append([b,2])
t.sort()
al=bl=0
for x in t[:i]:
if x[1]==1: al+=1
else: bl+=1
al=max(i//2,al);bl=max(bl,i//2)
print('1'*al+'0'*(i-al))
print('1'*bl+'0'*(i-bl))
``` | 0 | |
108 | B | Datatypes | PROGRAMMING | 1,400 | [
"math",
"sortings"
] | B. Datatypes | 2 | 256 | Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of *n* integers (1<=≤<=*a**i*<=≤<=109) — sizes of datatypes in bits. Some datatypes may have equal sizes. | Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise. | [
"3\n64 16 32\n",
"4\n4 2 1 3\n"
] | [
"NO\n",
"YES\n"
] | In the second example, *x* = 7 (111<sub class="lower-index">2</sub>) fits in 3 bits, but *x*<sup class="upper-index">2</sup> = 49 (110001<sub class="lower-index">2</sub>) does not fit in 4 bits. | 1,000 | [
{
"input": "3\n64 16 32",
"output": "NO"
},
{
"input": "4\n4 2 1 3",
"output": "YES"
},
{
"input": "5\n1 5 3 3 2",
"output": "YES"
},
{
"input": "52\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 ... | 1,578,052,746 | 2,147,483,647 | PyPy 3 | OK | TESTS | 65 | 466 | 10,854,400 | n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(1, len(a)):
f, s = a[i-1], a[i]
if f == s:
continue
if f != 1:
f *= 2
if f > s:
print("YES")
exit()
print("NO")
| Title: Datatypes
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to wr... | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(1, len(a)):
f, s = a[i-1], a[i]
if f == s:
continue
if f != 1:
f *= 2
if f > s:
print("YES")
exit()
print("NO")
``` | 3.863282 |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,590,012,615 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | # coding: utf-8
# Your code here!
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
if(s%2!=0):
for i in range(1,n):
if((s-l[-i])%2==0):
print(s-l[-i])
break
else:
print(s)
| Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
# coding: utf-8
# Your code here!
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
if(s%2!=0):
for i in range(1,n):
if((s-l[-i])%2==0):
print(s-l[-i])
break
else:
print(s)
``` | 0 | |
400 | A | Inna and Choose Options | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The ... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line b... | [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n"
] | [
"3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n"
] | none | 500 | [
{
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"
},
{
"input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX",
"output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1"
},
{
"input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n... | 1,566,543,073 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 124 | 102,400 | fact = [2,3,4,6]
n = int(input())
l1 = []
for i in range(n):
t = input()
l2 = []
if t.count("X"):
l2.append("1x12")
for j in fact:
for k in range(12//j):
flag = 0
# print(j)
for l in range(k,12,12//j):
# print(k,j,l)
if t[l] == "X":
pass
else:
flag ... | Title: Inna and Choose Options
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game.... | ```python
fact = [2,3,4,6]
n = int(input())
l1 = []
for i in range(n):
t = input()
l2 = []
if t.count("X"):
l2.append("1x12")
for j in fact:
for k in range(12//j):
flag = 0
# print(j)
for l in range(k,12,12//j):
# print(k,j,l)
if t[l] == "X":
pass
else:
... | 3 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,585,436,547 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 124 | 0 | """
Nome: Stefano Lopes Chiavegatto
RA: 1777224
"""
num_tam = input()
baldes = input()
lista_num_tam = num_tam.split(" ")
tam = int(lista_num_tam[1])
lista_baldes = baldes.split(" ")
tam_baldes = [tam/int(i) for i in lista_baldes if (tam%int(i) == 0)]
print(int(min(tam_baldes)))
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
"""
Nome: Stefano Lopes Chiavegatto
RA: 1777224
"""
num_tam = input()
baldes = input()
lista_num_tam = num_tam.split(" ")
tam = int(lista_num_tam[1])
lista_baldes = baldes.split(" ")
tam_baldes = [tam/int(i) for i in lista_baldes if (tam%int(i) == 0)]
print(int(min(tam_baldes)))
... | 3 | |
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle... | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"in... | 1,483,361,618 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 62 | 4,608,000 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def gcd(x, y):
return x//y + gcd(y, x%y) if y else 0
a = list(map(int, input().split(' ')))
print(gcd(a[0], a[1]))
| Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a squ... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def gcd(x, y):
return x//y + gcd(y, x%y) if y else 0
a = list(map(int, input().split(' ')))
print(gcd(a[0], a[1]))
``` | 3 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,489,485,446 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 |
n = input().strip()
n = int(n)
socks = list(map(int, input().strip().split(' ')))
table =[]
max_table = 0
idx = 0
x=0
while x!=n and idx < len(socks)-2:
if(socks[idx]==socks[idx+1]):
x = x+1
idx = idx+2
else:
if(table.count(socks[idx])==1):
table.remove(socks... | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n = input().strip()
n = int(n)
socks = list(map(int, input().strip().split(' ')))
table =[]
max_table = 0
idx = 0
x=0
while x!=n and idx < len(socks)-2:
if(socks[idx]==socks[idx+1]):
x = x+1
idx = idx+2
else:
if(table.count(socks[idx])==1):
table.re... | 0 | |
18 | A | Triangle | PROGRAMMING | 1,500 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t... | The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero. | If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER. | [
"0 0 2 0 0 1\n",
"2 3 4 5 6 6\n",
"-1 0 2 0 0 1\n"
] | [
"RIGHT\n",
"NEITHER\n",
"ALMOST\n"
] | none | 0 | [
{
"input": "0 0 2 0 0 1",
"output": "RIGHT"
},
{
"input": "2 3 4 5 6 6",
"output": "NEITHER"
},
{
"input": "-1 0 2 0 0 1",
"output": "ALMOST"
},
{
"input": "27 74 85 23 100 99",
"output": "NEITHER"
},
{
"input": "-97 -19 17 62 30 -76",
"output": "NEITHER"
},... | 1,542,286,070 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 27 | 248 | 0 | def l(vx ,vy):
return (vx*vx+vy*vy)
x1,y1,x2,y2,x3,y3 = [int (i) for i in input().split()]
ax = x2-x1
ay = y2-y1
bx = x3-x2
by = y3-y2
cx = x1-x3
cy = y1-y3
la = l(ax,ay)
lb = l(bx,by)
lc = l(cx,cy)
b,c = max(lb,lc),min(lb,lc)
a,b = max(la,lb),min(la,lb)
if a == b+c :
print ('RIGHT')
e... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer co... | ```python
def l(vx ,vy):
return (vx*vx+vy*vy)
x1,y1,x2,y2,x3,y3 = [int (i) for i in input().split()]
ax = x2-x1
ay = y2-y1
bx = x3-x2
by = y3-y2
cx = x1-x3
cy = y1-y3
la = l(ax,ay)
lb = l(bx,by)
lc = l(cx,cy)
b,c = max(lb,lc),min(lb,lc)
a,b = max(la,lb),min(la,lb)
if a == b+c :
print ('... | 0 |
989 | B | A Tide of Riverscape | PROGRAMMING | 1,200 | [
"constructive algorithms",
"strings"
] | null | null | "Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks a... | The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' c... | Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). | [
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] | [
"1000100010\n",
"1001101000\n",
"No\n"
] | In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the onl... | 1,000 | [
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"i... | 1,528,725,234 | 1,134 | Python 3 | CHALLENGED | CHALLENGES | 8 | 77 | 204,800 | n,m = [int(i) for i in input().split()]
a = list(input())
l = len(a)
f = False
for i in range(l - m):
if a[i] != a[i + m]:
f = True
if a[i] == ".":
if a[i + m] == "1":
a[i] = "0"
else:
a[i] = "1"
if a[i + m] == ".":
if a[i] == "0":
a[i + m] = "1"
else:
a[i + m] = "0"
if f == F... | Title: A Tide of Riverscape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its... | ```python
n,m = [int(i) for i in input().split()]
a = list(input())
l = len(a)
f = False
for i in range(l - m):
if a[i] != a[i + m]:
f = True
if a[i] == ".":
if a[i + m] == "1":
a[i] = "0"
else:
a[i] = "1"
if a[i + m] == ".":
if a[i] == "0":
a[i + m] = "1"
else:
a[i + m] = "0"
... | -1 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,621,707,335 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
string = input()
string = [char for char in string]
key = []
room = []
for i in range(len(string)):
if i % 2 == 0:
key.append(string[i])
else:
room.append(string[i])
# print(key,room)
count = 0
for j,k in zip(key,room):
if j == k.lower():
continue
... | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
n = int(input())
string = input()
string = [char for char in string]
key = []
room = []
for i in range(len(string)):
if i % 2 == 0:
key.append(string[i])
else:
room.append(string[i])
# print(key,room)
count = 0
for j,k in zip(key,room):
if j == k.lower():
co... | 0 | |
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,690,023,624 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | number = int(input())
l = list(map(int,input().split(" ")))
maximum = l[0]
minimum = l[0]
c = 0
for i in l :
if i > maximum:
c+=1
maximum = i
elif i < minimum:
c+=1
minimum = i
else :
continue
print(c)
| 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
number = int(input())
l = list(map(int,input().split(" ")))
maximum = l[0]
minimum = l[0]
c = 0
for i in l :
if i > maximum:
c+=1
maximum = i
elif i < minimum:
c+=1
minimum = i
else :
continue
print(c)
``` | 3 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,694,099,884 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a=input()
if a<=5:
print('1')
else:
m=a//5
if a%5==0:
print(m)
else:
print(m+1) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
a=input()
if a<=5:
print('1')
else:
m=a//5
if a%5==0:
print(m)
else:
print(m+1)
``` | -1 | |
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,698,156,821 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n=int(input())
x=0
for i in range(n):
gg=input()
if gg=='++X'or gg=='X++':
x+=1
else:
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=int(input())
x=0
for i in range(n):
gg=input()
if gg=='++X'or gg=='X++':
x+=1
else:
x-=1
print(x)
``` | 3 | |
985 | C | Liebig's Barrels | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
... | The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*. | [
"4 2 1\n2 2 1 2 3 2 2 3\n",
"2 1 0\n10 10\n",
"1 2 1\n5 2\n",
"3 2 1\n1 2 3 4 5 6\n"
] | [
"7\n",
"20\n",
"2\n",
"0\n"
] | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so... | 0 | [
{
"input": "4 2 1\n2 2 1 2 3 2 2 3",
"output": "7"
},
{
"input": "2 1 0\n10 10",
"output": "20"
},
{
"input": "1 2 1\n5 2",
"output": "2"
},
{
"input": "3 2 1\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194... | 1,528,013,770 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 217 | 15,360,000 | n, k, l = [int(x) for x in input().split()]
staves = [int(x) for x in input().split()]
staves = sorted(staves)
volume = 0
curr = 0
for i in range(n*k-1, -1, -1):
curr += 1
if staves[i] - staves[0] <= l and curr >= k:
volume += staves[i]
curr -= k
print([volume, 0][curr > 0]) | Title: Liebig's Barrels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to ex... | ```python
n, k, l = [int(x) for x in input().split()]
staves = [int(x) for x in input().split()]
staves = sorted(staves)
volume = 0
curr = 0
for i in range(n*k-1, -1, -1):
curr += 1
if staves[i] - staves[0] <= l and curr >= k:
volume += staves[i]
curr -= k
print([volume, 0][curr > 0... | 3 | |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh... | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759... | 1,699,202,955 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | n = int(input())
camels = {}
for _ in range(n):
a, b = map(int, input().split())
camels[a] = a + b
for c, t in camels.items():
if t in camels and camels[t] == c:
print("YES")
exit(0)
print("NO")
| Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
n = int(input())
camels = {}
for _ in range(n):
a, b = map(int, input().split())
camels[a] = a + b
for c, t in camels.items():
if t in camels and camels[t] == c:
print("YES")
exit(0)
print("NO")
``` | 3.969 |
440 | A | Forgotten Episode | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watch... | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | 500 | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
... | 1,649,261,465 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 30 | 0 | b=int(input(""))
c=[int(a) for a in input("").split(" ")]
c=sorted(c)
r=c[0]
for i in range(b):
if(r==c[i]):
r=r+1
else:
break
print(r)
| Title: Forgotten Episode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episo... | ```python
b=int(input(""))
c=[int(a) for a in input("").split(" ")]
c=sorted(c)
r=c[0]
for i in range(b):
if(r==c[i]):
r=r+1
else:
break
print(r)
``` | -1 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,690,966,961 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n = int(input())
s =[]
for i in range(n):
s.append(input())
output_string = ''
for i in (s):
if len(i) < 10:
output_string += i + "\n"
else:
output_string += i[0] + str(len(i) - 2) + i[-1] + "\n"
print(output_string)
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input())
s =[]
for i in range(n):
s.append(input())
output_string = ''
for i in (s):
if len(i) < 10:
output_string += i + "\n"
else:
output_string += i[0] + str(len(i) - 2) + i[-1] + "\n"
print(output_string)
``` | 0 |
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,619,551,520 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 77 | 409,600 | n=int(input())
l=list(map(int,input().split()))
from collections import Counter
dic=Counter(l)
print(max(dic.values())) | 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())
l=list(map(int,input().split()))
from collections import Counter
dic=Counter(l)
print(max(dic.values()))
``` | 3 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,694,610,373 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | r, c = map(int, input().split())
grid = []
def notincolumn(j):
for i in range(r):
if grid[i][j] == "S":
return False
return True
for _ in range(r):
grid.append(input())
count = 0
for i in range(r):
for j in range(c):
if grid[i][j] == "." and ("." not i... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
r, c = map(int, input().split())
grid = []
def notincolumn(j):
for i in range(r):
if grid[i][j] == "S":
return False
return True
for _ in range(r):
grid.append(input())
count = 0
for i in range(r):
for j in range(c):
if grid[i][j] == "." and ... | 0 | |
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. | Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1... | 1,525,156,658 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 499 | 7,065,600 | z = int(input(""))
n = p = 0
for i in range(z):
x = int(input("").split(" ")[0])
if x >= 0:
p += 1
else:
n += 1
if (p >= 1 and n == 0) or (p == 0 and n > 0) or n == 1 or p == 1:
print("YES")
else:
print("NO")
| Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first li... | ```python
z = int(input(""))
n = p = 0
for i in range(z):
x = int(input("").split(" ")[0])
if x >= 0:
p += 1
else:
n += 1
if (p >= 1 and n == 0) or (p == 0 and n > 0) or n == 1 or p == 1:
print("YES")
else:
print("NO")
``` | 3 | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,508,747,181 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 500 | 5,529,600 | t = int(input())
pos = int(input())
s = [False,False,False]
s[pos] = True
#print (s[pos-1])
for i in range(t) :
p = t - i
if ( p % 2 == 0) :
if(s[1] == 1 or s[2] == 1):
s[1] = not(s[1])
s[2] = not(s[2])
else :
if (s[0] == 1 or s[1] == 1) :
s[0] = not(s[0])
... | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
t = int(input())
pos = int(input())
s = [False,False,False]
s[pos] = True
#print (s[pos-1])
for i in range(t) :
p = t - i
if ( p % 2 == 0) :
if(s[1] == 1 or s[2] == 1):
s[1] = not(s[1])
s[2] = not(s[2])
else :
if (s[0] == 1 or s[1] == 1) :
s[0] = not(s[... | 0 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,679,736,098 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 187 | 0 | n=int(input())
s=list(map(int,input().split()))
m=min(s.count(1),s.count(2),s.count(3))
print(m)
for ___ in range(m):
t1=s.index(1)
t2=s.index(2)
t3=s.index(3)
print(t1+1,t2+1,t3+1)
s[t1]=0
s[t2]=0
s[t3]=0
| Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n=int(input())
s=list(map(int,input().split()))
m=min(s.count(1),s.count(2),s.count(3))
print(m)
for ___ in range(m):
t1=s.index(1)
t2=s.index(2)
t3=s.index(3)
print(t1+1,t2+1,t3+1)
s[t1]=0
s[t2]=0
s[t3]=0
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,658,421,031 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | #!/usr/bin/env python
# coding: utf-8
# In[44]:
m, n=map(int, input().split())
k=0
if m<2 and n<0:
print(0)
elif m==1 or n==1:
m,n=0,0
else:
if m>=n:
k=int(m/2)+n
else:
k=int(n/2)+m
print(int(k))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
#!/usr/bin/env python
# coding: utf-8
# In[44]:
m, n=map(int, input().split())
k=0
if m<2 and n<0:
print(0)
elif m==1 or n==1:
m,n=0,0
else:
if m>=n:
k=int(m/2)+n
else:
k=int(n/2)+m
print(int(k))
``` | 0 |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,671,106,644 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 93 | 1,331,200 | n,v = list(map(int,input().split()))
ans = []
for i in range(1,n+1):
row = list(map(int,input().split()))
k = row[0]
items = sorted(row[1:])
if items[0] < v:
ans.append(i)
print(len(ans))
print(*ans) | Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
n,v = list(map(int,input().split()))
ans = []
for i in range(1,n+1):
row = list(map(int,input().split()))
k = row[0]
items = sorted(row[1:])
if items[0] < v:
ans.append(i)
print(len(ans))
print(*ans)
``` | 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,580,248,421 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 248 | 0 | no_vectors = int(input())
vector_count = 0
for i in range(no_vectors):
vector = input()
for i in range(len(vector.split())):
vector_count = vector_count + int(vector.split()[i])
if vector_count == 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
no_vectors = int(input())
vector_count = 0
for i in range(no_vectors):
vector = input()
for i in range(len(vector.split())):
vector_count = vector_count + int(vector.split()[i])
if vector_count == 0:
print('YES')
else:
print('NO')
``` | 0 |
638 | A | Home Numbers | PROGRAMMING | 1,100 | [
"*special",
"constructive algorithms",
"math"
] | null | null | The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the pictur... | The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even. | Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*. | [
"4 2\n",
"8 5\n"
] | [
"2\n",
"3\n"
] | In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left. | 500 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "100000 100000",... | 1,458,506,764 | 31,564 | Python 3 | OK | TESTS | 69 | 61 | 5,120,000 | n, a = input().split()
n = int(n)
a = int(a)
if a==1:
print(1)
elif (a % 2 != 0):
print (int(((a / 2)+1)))
else:
print(int(((n-a) / 2)+1))
| Title: Home Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are nu... | ```python
n, a = input().split()
n = int(n)
a = int(a)
if a==1:
print(1)
elif (a % 2 != 0):
print (int(((a / 2)+1)))
else:
print(int(((n-a) / 2)+1))
``` | 3 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,616,039,940 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 77 | 0 | d1,d2,d3=map(int,input().split())
# if(d1<=d2<d3):
# print(2*(d1+d2))
# elif(d1>=d2>=d3):
# print(d1+d2+d3)
# elif(d1>d2 and d1>3):
# print(2*(d1+d2))
print(min(d1+d2+d3,2*(d1+d2),2*(d3+d2),2*(d1+d3))) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3=map(int,input().split())
# if(d1<=d2<d3):
# print(2*(d1+d2))
# elif(d1>=d2>=d3):
# print(d1+d2+d3)
# elif(d1>d2 and d1>3):
# print(2*(d1+d2))
print(min(d1+d2+d3,2*(d1+d2),2*(d3+d2),2*(d1+d3)))
``` | 3 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,556,526,946 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 109 | 0 | n = int(input())
if n%2 != 0:
print(0)
elif n%4 != 0:
print(n//4)
else:
print(n//4 -1) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
n = int(input())
if n%2 != 0:
print(0)
elif n%4 != 0:
print(n//4)
else:
print(n//4 -1)
``` | 3 | |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,685,016,044 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 159 | 77 | 0 | n=int(input())
parsa=list(map(int,input().split()))
for i in range(0,n,1):
if i==0:
min=parsa[i]
max=parsa[i]
mn=i
mx=i
if min>parsa[i]:
min=parsa[i]
mn=i
if max<parsa[i]:
max=parsa[i]
mx=i
if mx>mn:
if mx==n-1 and mn==0:
... | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
n=int(input())
parsa=list(map(int,input().split()))
for i in range(0,n,1):
if i==0:
min=parsa[i]
max=parsa[i]
mn=i
mx=i
if min>parsa[i]:
min=parsa[i]
mn=i
if max<parsa[i]:
max=parsa[i]
mx=i
if mx>mn:
if mx==n-1 and ... | 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,695,562,368 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | k,n,w=list(map(int,input().split()))
o=1
while w>0:
b=o*k
n=n-b
w=w-1
o=o+1
print(abs(n))
| 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()))
o=1
while w>0:
b=o*k
n=n-b
w=w-1
o=o+1
print(abs(n))
``` | 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,634,120,508 | 2,147,483,647 | PyPy 3 | OK | TESTS | 127 | 170 | 30,003,200 | n=int(input())
x=list(map(int,input().split()))
x.sort()
s=1
for i in x:
if i>=s:
s+=1
print(s)
| 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())
x=list(map(int,input().split()))
x.sort()
s=1
for i in x:
if i>=s:
s+=1
print(s)
``` | 3 | |
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,493,929,117 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | s=input()
x=0
y=0
z=len(s)
t=0
for i in s:
if i=="b":
y+=1
else:break
for i in range(1,len(s)+1):
if s[-i]=="a":
z-=1
else:break
s=s[y:z]
for i in range(1,len(s)+1):
if s[-i]=="a":
t+=x
t%=1000000009
x*=2
x%=1000000009
else:
x+=1
print(t) | Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr... | ```python
s=input()
x=0
y=0
z=len(s)
t=0
for i in s:
if i=="b":
y+=1
else:break
for i in range(1,len(s)+1):
if s[-i]=="a":
z-=1
else:break
s=s[y:z]
for i in range(1,len(s)+1):
if s[-i]=="a":
t+=x
t%=1000000009
x*=2
x%=1000000009
else:
x+=1
print(t)
``` | 0 | |
891 | A | Pride | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"math",
"number theory"
] | null | null | You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the mi... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array.
The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. | [
"5\n2 2 3 4 6\n",
"4\n2 4 6 8\n",
"3\n2 6 9\n"
] | [
"5\n",
"-1\n",
"4\n"
] | In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves. | 500 | [
{
"input": "5\n2 2 3 4 6",
"output": "5"
},
{
"input": "4\n2 4 6 8",
"output": "-1"
},
{
"input": "3\n2 6 9",
"output": "4"
},
{
"input": "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21",
"output": "15"
},
{
"input": "12\n10 10 14 14 14 14 14 14 14 14 21 21",
... | 1,667,989,669 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # LUOGU_RID: 93383212
#include<stdio.h>
int n,a[2006];
int one,g,mn=1e9;
int gcd(int a, int b){
return b ? gcd(b, a % b) : a;
}
int main()
{
scanf("%d", &n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
g=gcd(g,a[i]);
if(a[i]==1) one++;
}
if(one!=0){
printf("%d\n",n-one);
return 0;
}
if(g!=... | Title: Pride
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [great... | ```python
# LUOGU_RID: 93383212
#include<stdio.h>
int n,a[2006];
int one,g,mn=1e9;
int gcd(int a, int b){
return b ? gcd(b, a % b) : a;
}
int main()
{
scanf("%d", &n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
g=gcd(g,a[i]);
if(a[i]==1) one++;
}
if(one!=0){
printf("%d\n",n-one);
return 0;
... | -1 |
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.