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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,678,635,413 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 670 | 9,318,400 | t = int(input())
c = 0
for el in range(t):
a , b = list(map(int , input().split()))
if(a != b):
c += 1
if(c > 0):
print('Happy Alex')
else:
print('Poor Alex') | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
t = int(input())
c = 0
for el in range(t):
a , b = list(map(int , input().split()))
if(a != b):
c += 1
if(c > 0):
print('Happy Alex')
else:
print('Poor Alex')
``` | 3 | |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,656,151,628 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 77 | 614,400 | '''
╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬ ▓▓█████▓▓ ╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
###########################
// •︿• \\
/\\ //\
/\\ //\
/\\//\
###########################
'''
i... | Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
'''
╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬ ▓▓█████▓▓ ╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬ ▓▓ ▓▓ ╬╬
╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
###########################
// •︿• \\
/\\ //\
/\\ //\
/\\//\
#########################... | 3 | |
576 | A | Vasya and Petya's Game | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | null | null | Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can a... | A single line contains number *n* (1<=≤<=*n*<=≤<=103). | Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. | [
"4\n",
"6\n"
] | [
"3\n2 4 3 \n",
"4\n2 4 3 5 \n"
] | The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Th... | 500 | [
{
"input": "4",
"output": "3\n2 4 3 "
},
{
"input": "6",
"output": "4\n2 4 3 5 "
},
{
"input": "1",
"output": "0"
},
{
"input": "15",
"output": "9\n2 4 8 3 9 5 7 11 13 "
},
{
"input": "19",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "2... | 1,652,054,208 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | def isPrime(n):
if (n <= 1):
return False
if (n <= 3):
return True
for i in range(n, 3):
if n // i == 0:
return False
else:
return True
import sys
n = int(sys.stdin.readline())
ans = []
for i in range(1, n + 1):
if isPrime(i):
... | Title: Vasya and Petya's Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The... | ```python
def isPrime(n):
if (n <= 1):
return False
if (n <= 3):
return True
for i in range(n, 3):
if n // i == 0:
return False
else:
return True
import sys
n = int(sys.stdin.readline())
ans = []
for i in range(1, n + 1):
if isP... | 0 | |
567 | B | Berland National Library | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of records in the system log. Next follow *n* events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ *r**i*" or "- *r**i*", where *r**i* is an integer from 1 to 106, the r... | Print a single integer — the minimum possible capacity of the reading room. | [
"6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7\n",
"2\n- 1\n- 2\n",
"2\n+ 1\n- 1\n"
] | [
"3",
"2",
"1"
] | In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3. | 1,000 | [
{
"input": "6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7",
"output": "3"
},
{
"input": "2\n- 1\n- 2",
"output": "2"
},
{
"input": "2\n+ 1\n- 1",
"output": "1"
},
{
"input": "5\n+ 1\n- 1\n+ 2\n+ 3\n- 4",
"output": "3"
},
{
"input": "3\n- 1\n- 2\n- 3",
"output": "... | 1,601,542,221 | 1,821 | Python 3 | WRONG_ANSWER | TESTS | 5 | 78 | 0 | n, visitors = int(input()), []
mn = 0
for i in range(n):
inp = input().split()
if inp[0] == '+':
visitors.append(inp[2:])
if len(visitors) >= mn:
mn += 1
elif inp[0] == '-':
try:
visitors.remove(inp[2:])
except:
mn += 1
print... | Title: Berland National Library
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the... | ```python
n, visitors = int(input()), []
mn = 0
for i in range(n):
inp = input().split()
if inp[0] == '+':
visitors.append(inp[2:])
if len(visitors) >= mn:
mn += 1
elif inp[0] == '-':
try:
visitors.remove(inp[2:])
except:
mn += ... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,596,624,907 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 248 | 6,963,200 |
length = int(input())
numbers = input().split()
new_arr = []
even_arr = []
odd_arr = []
for num in numbers:
new_arr.append(int(num))
for item in new_arr:
if item % 2 == 0:
even_arr.append(item)
else:
odd_arr.append(item)
if len(even_arr) == 1:
print(new... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
length = int(input())
numbers = input().split()
new_arr = []
even_arr = []
odd_arr = []
for num in numbers:
new_arr.append(int(num))
for item in new_arr:
if item % 2 == 0:
even_arr.append(item)
else:
odd_arr.append(item)
if len(even_arr) == 1:
... | 3.92503 |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,699,314,152 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 |
def scores():
list=[]
participants, place= input().split()
score= input().split()
counter=0
for personal_score in score:
if int(personal_score) > int(place) and int(personal_score)>0:
list.append(personal_score)
... | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
def scores():
list=[]
participants, place= input().split()
score= input().split()
counter=0
for personal_score in score:
if int(personal_score) > int(place) and int(personal_score)>0:
list.append(personal_score)
... | 0 | |
999 | E | Reachability from the Capital | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way. | The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_... | Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0. | [
"9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n",
"5 4 5\n1 2\n2 3\n3 4\n4 1\n"
] | [
"3\n",
"1\n"
] | The first example is illustrated by the following:
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following:
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the ci... | 0 | [
{
"input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1",
"output": "3"
},
{
"input": "5 4 5\n1 2\n2 3\n3 4\n4 1",
"output": "1"
},
{
"input": "5000 0 2956",
"output": "4999"
},
{
"input": "2 0 2",
"output": "1"
},
{
"input": "2 1 1\n1 2",
"output": "0"... | 1,694,329,348 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 140 | 9,318,400 | def dfs(v):
global used, g
for to in g[v]:
if used[to] == -1:
used[to] = 1
dfs(to)
def dfs2(v):
global used, g, lst
count = 1
used[v] = 2
for to in g[v]:
if used[to] == -1:
count += dfs2(to)
return count
n, m, s = list(map(int... | Title: Reachability from the Capital
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities r... | ```python
def dfs(v):
global used, g
for to in g[v]:
if used[to] == -1:
used[to] = 1
dfs(to)
def dfs2(v):
global used, g, lst
count = 1
used[v] = 2
for to in g[v]:
if used[to] == -1:
count += dfs2(to)
return count
n, m, s = li... | 0 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,643,549,396 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 109 | 2,252,800 | N, X = map(int, input().split())
c = 0
for m in range(1, N+1) :
if X%m==0 and X//m<=N :
c += 1
print(c)
| Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
N, X = map(int, input().split())
c = 0
for m in range(1, N+1) :
if X%m==0 and X//m<=N :
c += 1
print(c)
``` | 3 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,698,593,934 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 2,000 | 23,859,200 | a = int(input())
arr = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
for i in arr:
if arr.count(i) != arr1.count(i):
print(i)
break
for i in arr1:
if arr1.count(i) != arr2.count(i):
print(i)
break | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
a = int(input())
arr = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
for i in arr:
if arr.count(i) != arr1.count(i):
print(i)
break
for i in arr1:
if arr1.count(i) != arr2.count(i):
print(i)
brea... | 0 | |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,628,452,239 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 93 | 20,172,800 | original = input()
s = original
res = 1
while original != s[-1] + s[:-1]:
res += 1
s = s[-1] + s[:-1]
print(res)
| Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
original = input()
s = original
res = 1
while original != s[-1] + s[:-1]:
res += 1
s = s[-1] + s[:-1]
print(res)
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,691,335,390 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s=input()
l=[]
c=0
d=0
for i in s:
l.append(i)
l.sort()
print(l)
for i in l:
if i=='0':
c+=1
else:
d+=1
print(c)
print(d)
if c>=7 or d>=7:
print("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
s=input()
l=[]
c=0
d=0
for i in s:
l.append(i)
l.sort()
print(l)
for i in l:
if i=='0':
c+=1
else:
d+=1
print(c)
print(d)
if c>=7 or d>=7:
print("YES")
else:
print("NO")
``` | 0 |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input":... | 1,515,085,312 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 5,529,600 | n,s=map(int,input().split())
def nod(n):
res=0
while n>0:
res+=1
n//=10
return res
def sod(n):
res=0
while n>0:
res+=n%10
n//=10
return res
def maxsod(n):
if n+1==10**nod(n): return sod(n)
else: return 9*(nod(n)-1)
num=n-s
for i in range(s+1,min(s+maxsod(n),n)+1):
if i-sod(i)<s:
nu... | Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its... | ```python
n,s=map(int,input().split())
def nod(n):
res=0
while n>0:
res+=1
n//=10
return res
def sod(n):
res=0
while n>0:
res+=n%10
n//=10
return res
def maxsod(n):
if n+1==10**nod(n): return sod(n)
else: return 9*(nod(n)-1)
num=n-s
for i in range(s+1,min(s+maxsod(n),n)+1):
if i-sod(i... | 0 | |
616 | C | The Labyrinth | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.
Let's call a connected component any non-extendible set of cells such ... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the field.
Each of the next *n* lines contains *m* symbols: "." for empty cells, "*" for impassable cells. | Print the answer as a matrix as described above. See the examples to precise the format of the output. | [
"3 3\n*.*\n.*.\n*.*\n",
"4 5\n**..*\n..***\n.*.*.\n*.*.*\n"
] | [
"3.3\n.5.\n3.3\n",
"46..3\n..732\n.6.4.\n5.4.3\n"
] | In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner cell will be empty then it will be included to component of size 3 (corner). | 0 | [
{
"input": "3 3\n*.*\n.*.\n*.*",
"output": "3.3\n.5.\n3.3"
},
{
"input": "4 5\n**..*\n..***\n.*.*.\n*.*.*",
"output": "46..3\n..732\n.6.4.\n5.4.3"
},
{
"input": "1 1\n*",
"output": "1"
},
{
"input": "1 1\n.",
"output": "."
},
{
"input": "1 10\n**********",
"ou... | 1,642,674,659 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 66,764,800 | from collections import Counter
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
grid = [[j for j in input()] for i in range(n)]
d = Counter()
def dfs(x, y, g):
grid[x][y] = g
stk, cnt = [(x, y)], 0
while stk:
x, y = stk.pop()
cnt += 1
for dx, dy... | Title: The Labyrinth
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adj... | ```python
from collections import Counter
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
grid = [[j for j in input()] for i in range(n)]
d = Counter()
def dfs(x, y, g):
grid[x][y] = g
stk, cnt = [(x, y)], 0
while stk:
x, y = stk.pop()
cnt += 1
... | 0 | |
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,611,666,342 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 154 | 409,600 | from collections import Counter, OrderedDict
import operator
lines = int(input())
goals = []
for k in range(lines):
goals.append(input())
dict1 = (Counter(goals))
sorted_tuples = sorted(dict1.items(), key=operator.itemgetter(1), reverse=True)
sorted_dict = OrderedDict()
for k, v in sorted_tuples:
sorted_dict[k]... | 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 Counter, OrderedDict
import operator
lines = int(input())
goals = []
for k in range(lines):
goals.append(input())
dict1 = (Counter(goals))
sorted_tuples = sorted(dict1.items(), key=operator.itemgetter(1), reverse=True)
sorted_dict = OrderedDict()
for k, v in sorted_tuples:
sort... | 3.960737 |
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"... | 1,659,399,056 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 186 | 15,667,200 |
import sys
input = sys.stdin.readline
s = input()[:-1]
d = []
for i in s:
if d and i == d[-1]:
d.pop()
else:
d.append(i)
print(''.join(d)) | Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed... | ```python
import sys
input = sys.stdin.readline
s = input()[:-1]
d = []
for i in s:
if d and i == d[-1]:
d.pop()
else:
d.append(i)
print(''.join(d))
``` | 3.877818 |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,688,670,661 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 78 | 4,096,000 | a,b=map(int,input().split())
c=0
for i in range(a):
for j in range(b):
if i%2==0:
print("#",end="")
else:
if i % 4 == 1 and j == b - 1:
print("#", end="")
elif i % 4 == 3 and j == 0:
print("#", end="")
... | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
a,b=map(int,input().split())
c=0
for i in range(a):
for j in range(b):
if i%2==0:
print("#",end="")
else:
if i % 4 == 1 and j == b - 1:
print("#", end="")
elif i % 4 == 3 and j == 0:
print("#", end="")
... | 3 | |
639 | A | Bear and Displayed Friends | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*.
Spring is starting and the Wint... | The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) ... | For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. | [
"4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n",
"6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n"
] | [
"NO\nYES\nNO\nYES\nYES\n",
"NO\nYES\nNO\nYES\n"
] | In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We shou... | 500 | [
{
"input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3",
"output": "NO\nYES\nNO\nYES\nYES"
},
{
"input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3",
"output": "NO\nYES\nNO\nYES"
},
{
"input": "6 3 10\n62417580 78150524 410053501 582708235 ... | 1,459,183,765 | 865 | PyPy 3 | RUNTIME_ERROR | PRETESTS | 0 | 93 | 23,040,000 | n, k, q = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
S = set()
for i in range(q):
t, _id = [int(x) for x in input().split()]
if t == 1:
m = min(S, default = 0)
if len(S) == k:
if m < T[_id-1]:
S.remove(m)
S.add(T[_id-1])
... | Title: Bear and Displayed Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this val... | ```python
n, k, q = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
S = set()
for i in range(q):
t, _id = [int(x) for x in input().split()]
if t == 1:
m = min(S, default = 0)
if len(S) == k:
if m < T[_id-1]:
S.remove(m)
S.add(T[... | -1 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,694,013,192 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input()) # Number of cards
cards = list(map(int, input().split())) # List of card values
# Initialize Sereja's and Dima's scores
sereja_score = 0
dima_score = 0
# Initialize pointers for the leftmost and rightmost cards
left = 0
right = n - 1
# Initialize a variable to keep track of the current ... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input()) # Number of cards
cards = list(map(int, input().split())) # List of card values
# Initialize Sereja's and Dima's scores
sereja_score = 0
dima_score = 0
# Initialize pointers for the leftmost and rightmost cards
left = 0
right = n - 1
# Initialize a variable to keep track of th... | 3 | |
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,681,166,725 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | n = int(input())
w = str(input()).split()
dummy = [print(w[i][0], len(w[i])-2, w[i][-1]) if len(w[i])>10 else print(w[i]) for i in range(n)] | 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())
w = str(input()).split()
dummy = [print(w[i][0], len(w[i])-2, w[i][-1]) if len(w[i])>10 else print(w[i]) for i in range(n)]
``` | -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,697,225,345 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | #fff
n=int(input())
for i in range(n):
word=input()
l=len(word)
l1=len(word[1:l-1])
if(l>10):
word=word[0]+str(l1)+word[0]
print(word)
else:
print(word)
| 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
#fff
n=int(input())
for i in range(n):
word=input()
l=len(word)
l1=len(word[1:l-1])
if(l>10):
word=word[0]+str(l1)+word[0]
print(word)
else:
print(word)
``` | 0 |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,685,815,802 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,048,000 | def solve():
n, a, b = map(int, input().split())
if a == b:
print(f'1/{n}')
return
div = (a // math.gcd(a, b)) * b
res = min(a - 1, b - 1) # can't use these numbers as both players would be stuck in the beginning itself
res += (n // div) * min(a, b) # min steps you again... | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
def solve():
n, a, b = map(int, input().split())
if a == b:
print(f'1/{n}')
return
div = (a // math.gcd(a, b)) * b
res = min(a - 1, b - 1) # can't use these numbers as both players would be stuck in the beginning itself
res += (n // div) * min(a, b) # min steps... | -1 | |
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,691,706,077 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | word = input()
print(word)
new = ''
for i in range(len(word)) :
if ord(word[i]) >= 97 :
new += chr(ord(word[i]) - 32)
else :
new += chr(ord(word[i]) + 32)
print(new)
| 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
word = input()
print(word)
new = ''
for i in range(len(word)) :
if ord(word[i]) >= 97 :
new += chr(ord(word[i]) - 32)
else :
new += chr(ord(word[i]) + 32)
print(new)
``` | 0 | |
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ... | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "... | 1,689,245,612 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | x = input()
for _ in range(100):
x = x.replace("//", "/")
print(x)
| Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n... | ```python
x = input()
for _ in range(100):
x = x.replace("//", "/")
print(x)
``` | 0 |
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,571,070,656 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 0 | n = int(input())
j = 1
while n > j:
n -= j
j += 1
print(n)
| Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
n = int(input())
j = 1
while n > j:
n -= j
j += 1
print(n)
``` | 0 | |
552 | C | Vanya and Scales | PROGRAMMING | 1,900 | [
"brute force",
"dp",
"greedy",
"math",
"meet-in-the-middle",
"number theory"
] | null | null | Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass *m* using the given weights, if the weights can be put on both pans of the scale... | The first line contains two integers *w*,<=*m* (2<=≤<=*w*<=≤<=109, 1<=≤<=*m*<=≤<=109) — the number defining the masses of the weights and the mass of the item. | Print word 'YES' if the item can be weighted and 'NO' if it cannot. | [
"3 7\n",
"100 99\n",
"100 50\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can ha... | 1,500 | [
{
"input": "3 7",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "100 50",
"output": "NO"
},
{
"input": "1000000000 1",
"output": "YES"
},
{
"input": "100 10002",
"output": "NO"
},
{
"input": "4 7",
"output": "NO"
},
{
... | 1,542,199,710 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | import sys
w,m = input().split()
w = int(w)
m = int(m)
a = []
b = []
k2 = 10000
k = 10000
if w == 4:
print('NO')
sys.exit()
if w<= 3:
print('YES')
sys.exit()
while m!= 0:
if (m % w != (w - 1)) and (m % w != 0) and (m % w != 1):
m = (m+1)/w
print('NO')
sys.exit()
... | Title: Vanya and Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can wei... | ```python
import sys
w,m = input().split()
w = int(w)
m = int(m)
a = []
b = []
k2 = 10000
k = 10000
if w == 4:
print('NO')
sys.exit()
if w<= 3:
print('YES')
sys.exit()
while m!= 0:
if (m % w != (w - 1)) and (m % w != 0) and (m % w != 1):
m = (m+1)/w
print('NO')
sys.exit()
... | 0 | |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "37546069... | 1,576,819,638 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 156 | 0 | x=int(input())
print( 0 if x==0 else (x+1)//2 if (x+1)%2==0 else x+1 )
# My code says who am i
# red is love
# love is not in logic
| Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthd... | ```python
x=int(input())
print( 0 if x==0 else (x+1)//2 if (x+1)%2==0 else x+1 )
# My code says who am i
# red is love
# love is not in logic
``` | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,671,833,216 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
temp = []
ans = []
s = n
p = ''
for i in range(n):
if a[i] >= s:
ans.append(str(a[i])+' ' + p)
s = max(temp)-1 if len(temp) != 0 else s-1
p = ''
if len(temp) >0:
temp.clear()
else:
ans.append... | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n = int(input())
a = list(map(int, input().split()))
temp = []
ans = []
s = n
p = ''
for i in range(n):
if a[i] >= s:
ans.append(str(a[i])+' ' + p)
s = max(temp)-1 if len(temp) != 0 else s-1
p = ''
if len(temp) >0:
temp.clear()
else:
... | 0 | |
681 | C | Heap Operations | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"greedy"
] | null | null | Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the heap; - extract the minimum element from the heap;
Thus, at any moment of time the heap contains se... | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of the records left in Petya's journal.
Each of the following *n* lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers... | The first line of the output should contain a single integer *m* — the minimum possible number of records in the modified sequence of operations.
Next *m* lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applie... | [
"2\ninsert 3\ngetMin 4\n",
"4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2\n"
] | [
"4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4\n",
"6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2\n"
] | In the first sample, after number 3 is inserted into the heap, the minimum number is 3. To make the result of the first getMin equal to 4 one should firstly remove number 3 from the heap and then add number 4 into the heap.
In the second sample case number 1 is inserted two times, so should be similarly removed twice. | 1,500 | [
{
"input": "2\ninsert 3\ngetMin 4",
"output": "4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4"
},
{
"input": "4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2",
"output": "6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2"
},
{
"input": "1\ninsert 1",
"output": "1\ninsert 1"
},... | 1,623,416,735 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 109 | 409,600 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ... | Title: Heap Operations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the ... | ```python
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # #... | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,667,106,041 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 358 | 10,240,000 | n=int(input())
if n==1:
a=map(int,input().split())
print(1)
if n>1:
s=[]
b=0
for i in range(n):
a=list(map(int,input().split()))
s.append(a)
for i in range(1,len(s)-1):
if s[i][0]-s[i-1][0]>s[i][1]:
b+=1
elif s[i+1][0]-s[i][0]>s[i][1]:
... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
n=int(input())
if n==1:
a=map(int,input().split())
print(1)
if n>1:
s=[]
b=0
for i in range(n):
a=list(map(int,input().split()))
s.append(a)
for i in range(1,len(s)-1):
if s[i][0]-s[i-1][0]>s[i][1]:
b+=1
elif s[i+1][0]-s[i][0]>s[... | 3 | |
284 | B | Cows and Poker Game | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any be... | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED". | The first line should contain a single integer denoting the number of players that can currently show their hands. | [
"6\nAFFAAA\n",
"3\nAFI\n"
] | [
"4\n",
"1\n"
] | In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | 1,000 | [
{
"input": "6\nAFFAAA",
"output": "4"
},
{
"input": "3\nAFI",
"output": "1"
},
{
"input": "3\nFFF",
"output": "0"
},
{
"input": "3\nFIF",
"output": "1"
},
{
"input": "3\nAAA",
"output": "3"
},
{
"input": "3\nIII",
"output": "0"
},
{
"input"... | 1,517,748,921 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 218 | 6,144,000 |
a = int(input())
s = input()
b = {'A':0, 'I':0, 'F':0}
for i in s:
b[i] += 1
if b['I'] > 1:
print(0)
elif b['I'] == 1:
print(1)
else:
print(b['A'])
| Title: Cows and Poker Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player who... | ```python
a = int(input())
s = input()
b = {'A':0, 'I':0, 'F':0}
for i in s:
b[i] += 1
if b['I'] > 1:
print(0)
elif b['I'] == 1:
print(1)
else:
print(b['A'])
``` | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,592,964,461 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 20,172,800 | n = int(input())
ara = list(int(i) for i in input().split())
a = None
var = []
for i in range(n):
if i == 0:
a = ara[i]
var.append(ara[i])
else:
if a < ara[i]:
print()
var.append(ara[i])
a = ara[i]
else:
for j in ran... | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n = int(input())
ara = list(int(i) for i in input().split())
a = None
var = []
for i in range(n):
if i == 0:
a = ara[i]
var.append(ara[i])
else:
if a < ara[i]:
print()
var.append(ara[i])
a = ara[i]
else:
fo... | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,662,528,539 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | li=list(map(int,input().split()))
print(min(li),(abs(li[0]-li[1]))//2)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
li=list(map(int,input().split()))
print(min(li),(abs(li[0]-li[1]))//2)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,618,514,760 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 0 | n = list(input())
m = list(input())
N = []
M = []
for i in n:
N.append(int(i))
for i in m:
M.append(int(i))
#print(M,N)
res = []
for i in range(len(n)):
if N[i]==0 and M[i] == 0 :
res.append(0)
elif N[i]==1 and M[i] == 1 :
res.append(0)
else:
res.append(1)
fi... | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n = list(input())
m = list(input())
N = []
M = []
for i in n:
N.append(int(i))
for i in m:
M.append(int(i))
#print(M,N)
res = []
for i in range(len(n)):
if N[i]==0 and M[i] == 0 :
res.append(0)
elif N[i]==1 and M[i] == 1 :
res.append(0)
else:
res.app... | 3.98075 |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,645,695,504 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,m=map(int,input().split())
a = [list(map(int,input().split())) for x in range(n)]
s = 0
for row in a:
o,z=0,0
for i in row:
if i==0:
z+=1
else:
o+=1
s+=2**z-1
s+=2**o-1
print(s) | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
n,m=map(int,input().split())
a = [list(map(int,input().split())) for x in range(n)]
s = 0
for row in a:
o,z=0,0
for i in row:
if i==0:
z+=1
else:
o+=1
s+=2**z-1
s+=2**o-1
print(s)
``` | 0 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,551,568,106 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 374 | 1,024,000 | ens=set()
n=int(ch)
tab=list(map(int,input().split()))
ens=set(tab)
liste=list(ens)
if (len(ens)==1) :
printf("NO")
else:
liste.sort()
print(liste[1]) | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
ens=set()
n=int(ch)
tab=list(map(int,input().split()))
ens=set(tab)
liste=list(ens)
if (len(ens)==1) :
printf("NO")
else:
liste.sort()
print(liste[1])
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | From beginning till end, this message has been waiting to be conveyed.
For a given unordered multiset of *n* lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation *n*<=-<=1 times:
- Remove any two elements *s... | The first and only line of input contains a non-negative integer *k* (0<=≤<=*k*<=≤<=100<=000) — the required minimum cost. | Output a non-empty string of no more than 100<=000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.
Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters. | [
"12\n",
"3\n"
] | [
"abababab\n",
"codeforces\n"
] | For the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:
- {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0; - {"aba", "b", "a", "b", "a", "b"}, with a cost of 1; - {"abab", "a", "b", "a", "b"}, with a cost of 1; - {"abab", "ab", "a", "b"}, with a cost... | 0 | [
{
"input": "12",
"output": "abababab"
},
{
"input": "3",
"output": "codeforces"
},
{
"input": "0",
"output": "o"
},
{
"input": "2",
"output": "aabb"
},
{
"input": "5",
"output": "aaabbcc"
},
{
"input": "10",
"output": "aaaaa"
},
{
"input": ... | 1,504,279,691 | 6,791 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | from sys import stdin
from math import sqrt
n = int(stdin.readline().rstrip())
N = n * 2
charset = 'abcdefghijklmnopqrstuvwxyz'
sqr = int(sqrt(N)) // 2 + 1
for i in range(1, sqr + 1):
for j in range(1, i + 1):
for k in range(1, 26 + 1):
N_ = N - k * i * (i + 1)
if N_ % (j... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
From beginning till end, this message has been waiting to be conveyed.
For a given unordered multiset of *n* lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of le... | ```python
from sys import stdin
from math import sqrt
n = int(stdin.readline().rstrip())
N = n * 2
charset = 'abcdefghijklmnopqrstuvwxyz'
sqr = int(sqrt(N)) // 2 + 1
for i in range(1, sqr + 1):
for j in range(1, i + 1):
for k in range(1, 26 + 1):
N_ = N - k * i * (i + 1)
... | 0 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,691,403,369 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 9,830,400 | import sys
input = sys.stdin.readline
t = 1
# t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if (a[0] != 25):
print("NO")
else:
flag = 0
d = {25 : 0, 50 : 0}
for i in a:
if (i == 25):
d[25] += 1
... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
import sys
input = sys.stdin.readline
t = 1
# t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if (a[0] != 25):
print("NO")
else:
flag = 0
d = {25 : 0, 50 : 0}
for i in a:
if (i == 25):
d[25] +... | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,690,404,294 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 92 | 0 | n = int(input())
def isLuckyNumber(number):
while number > 0:
rest = number % 10
if rest != 4 and rest != 7: return False
number //= 10
return True
if isLuckyNumber(n): print('YES')
else:
if n % 4 == 0 or n % 7 == 0: print('YES')
else: print('NO') | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
def isLuckyNumber(number):
while number > 0:
rest = number % 10
if rest != 4 and rest != 7: return False
number //= 10
return True
if isLuckyNumber(n): print('YES')
else:
if n % 4 == 0 or n % 7 == 0: print('YES')
else: print('NO')
``` | 0 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,651,937,540 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | t=int(input())
h={}
count=0
for _ in range(t):
a=input()
if(a not in h):
h[a]=1
count=count+1
else:
pass
print(count)
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
t=int(input())
h={}
count=0
for _ in range(t):
a=input()
if(a not in h):
h[a]=1
count=count+1
else:
pass
print(count)
``` | 3.977 |
12 | B | Correct Solution? | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | B. Correct Solution? | 2 | 256 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe... | The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes. | Print OK if Bob's answer is correct and WRONG_ANSWER otherwise. | [
"3310\n1033\n",
"4\n5\n"
] | [
"OK\n",
"WRONG_ANSWER\n"
] | none | 0 | [
{
"input": "3310\n1033",
"output": "OK"
},
{
"input": "4\n5",
"output": "WRONG_ANSWER"
},
{
"input": "40\n04",
"output": "WRONG_ANSWER"
},
{
"input": "12\n12",
"output": "OK"
},
{
"input": "432\n234",
"output": "OK"
},
{
"input": "17109\n01179",
"o... | 1,658,812,265 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | def cout(n):
return print(n)
def cin():
return int(input())
def lcin():
return list(map(int,input().split()))
def scin():
return input()
n = scin()
m = cin()
n1 = (n.count('1'))*'1';n2 = (n.count('2'))*'2';n3 = (n.count('3'))*'3'
n4 = (n.count('4'))*'4';n5 = (n.count('5'))*'5';n6 = (n.count('... | Title: Correct Solution?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuf... | ```python
def cout(n):
return print(n)
def cin():
return int(input())
def lcin():
return list(map(int,input().split()))
def scin():
return input()
n = scin()
m = cin()
n1 = (n.count('1'))*'1';n2 = (n.count('2'))*'2';n3 = (n.count('3'))*'3'
n4 = (n.count('4'))*'4';n5 = (n.count('5'))*'5';n6 = ... | 0 |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,694,723,258 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 186 | 14,438,400 | import math
from collections import Counter
import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# for _ in range(int(input())):
n = input()
n = int(n)
arr = list(map(int, input().split()))
m = arr.index(min(arr))
arr.sort()
if n == 1:
arr.append(10000000)
if arr[0] == arr... | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
import math
from collections import Counter
import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# for _ in range(int(input())):
n = input()
n = int(n)
arr = list(map(int, input().split()))
m = arr.index(min(arr))
arr.sort()
if n == 1:
arr.append(10000000)
if arr... | 3 | |
416 | A | Guess a number! | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"two pointers"
] | null | null | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that *y* is st... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10000) — the number of questions (and answers). Next *n* lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries), - "<" (for the se... | Print any of such integers *y*, that the answers to all the queries are correct. The printed number *y* must meet the inequation <=-<=2·109<=≤<=*y*<=≤<=2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | [
"4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N\n",
"2\n> 100 Y\n< -100 Y\n"
] | [
"17\n",
"Impossible\n"
] | none | 500 | [
{
"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N",
"output": "17"
},
{
"input": "2\n> 100 Y\n< -100 Y",
"output": "Impossible"
},
{
"input": "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N",
"output": "1"
},
{
"input": "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y",
"output": "1"
},
{
"input": ... | 1,553,709,305 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n = int(input())
simbolo = []
num = []
yn = []
for j in range(n):
s,x,y = input().split()
simbolo.append(s)
num.append(int(x))
yn.append(y)
maximo = float('inf')
minimo = -float('inf')
for i in range(n):
ismax = False
if simbolo[i] == '<' or simbolo[i] == '<=': # se x < y => y é max
i... | Title: Guess a number!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by aski... | ```python
n = int(input())
simbolo = []
num = []
yn = []
for j in range(n):
s,x,y = input().split()
simbolo.append(s)
num.append(int(x))
yn.append(y)
maximo = float('inf')
minimo = -float('inf')
for i in range(n):
ismax = False
if simbolo[i] == '<' or simbolo[i] == '<=': # se x < y => y é max... | 0 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,673,644,278 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n = int(input())
mishka = 0
chris = 0
for i in range(n):
mish, chri = map(int,input().split())
if mish > chri:
mishka = mishka + 1
elif chri > mish:
chris = chris + 1
if chris == mishka:
print("Friendship is magic!^^")
else:
if chris > mishka:
print... | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n = int(input())
mishka = 0
chris = 0
for i in range(n):
mish, chri = map(int,input().split())
if mish > chri:
mishka = mishka + 1
elif chri > mish:
chris = chris + 1
if chris == mishka:
print("Friendship is magic!^^")
else:
if chris > mishka:
... | 3 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,620,998,577 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 7,065,600 | n = int(input())
l = []
for i in range(n):
x, y = map(int, input().split())
l.append(x*60+y)
l.sort()
mx = 1
for i in l:
mx = max(mx, l.count(i))
print(mx)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
l = []
for i in range(n):
x, y = map(int, input().split())
l.append(x*60+y)
l.sort()
mx = 1
for i in l:
mx = max(mx, l.count(i))
print(mx)
``` | 0 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,641,754,383 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 93 | 0 | import math
def main():
r, x, y, a, b = [int(x) for x in input().split()]
d = ((a - x) ** 2 + (b - y) ** 2)**0.5
t = r << 1
ans = math.floor(d) // t
d = d - ans * t
if d > 0:
ans += 1
print(ans)
if __name__ == '__main__':
main() | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import math
def main():
r, x, y, a, b = [int(x) for x in input().split()]
d = ((a - x) ** 2 + (b - y) ** 2)**0.5
t = r << 1
ans = math.floor(d) // t
d = d - ans * t
if d > 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
``` | 3 | |
989 | C | A Mist of Florescence | PROGRAMMING | 1,800 | [
"constructive algorithms",
"graphs"
] | null | null | "I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.
The wood can be represented by a ... | The first and only line of input contains four space-separated integers $a$, $b$, $c$ and $d$ ($1 \leq a, b, c, d \leq 100$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively. | In the first line, output two space-separated integers $n$ and $m$ ($1 \leq n, m \leq 50$) — the number of rows and the number of columns in the grid respectively.
Then output $n$ lines each consisting of $m$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and '... | [
"5 3 2 1\n",
"50 50 1 1\n",
"1 6 4 5\n"
] | [
"4 7\nDDDDDDD\nDABACAD\nDBABACD\nDDDDDDD",
"4 50\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nABABABABABABABABABABABABABABABABABABABABABABABABAB\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
"7 7\nDDDDDDD\nDDDBDBD\nDDCDCDD\nDBDADBD\nDDCDCDD\nDB... | In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one. | 1,500 | [
{
"input": "5 3 2 1",
"output": "5 13\nAABABBBBCDDAD\nABAABBBBCDADD\nAAAABBBBCDDAD\nAAAABCBBCDADD\nAAAABBBBCDDDD"
},
{
"input": "50 50 1 1",
"output": "10 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABAB... | 1,528,812,213 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 108 | 0 | abcd = input().split(' ')
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
out = []
h = int(50 / 4)
for letter in 'D C B A'.split(' '):
for i in range(h):
out.append([letter for j in range(50)])
y = 0
for counts in [a - 1,b - 1,c - 1,d - 1]:
counter = 0
shift = 1
... | Title: A Mist of Florescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds... | ```python
abcd = input().split(' ')
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
out = []
h = int(50 / 4)
for letter in 'D C B A'.split(' '):
for i in range(h):
out.append([letter for j in range(50)])
y = 0
for counts in [a - 1,b - 1,c - 1,d - 1]:
counter = 0
... | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,698,055,745 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | s = input();a = s[0];b = s[1:]
print(a.upper(),b,sep='') | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
s = input();a = s[0];b = s[1:]
print(a.upper(),b,sep='')
``` | 3 | |
677 | E | Vanya and Balloons | PROGRAMMING | 2,300 | [
"binary search",
"brute force",
"dp",
"implementation"
] | null | null | Vanya plays a game of balloons on the field of size *n*<=×<=*n*, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons in the cross is maximum possible. There are two types of crosses: normal and rotated. For example:
or
... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows and columns in the table with balloons.
The each of the following *n* lines contains *n* characters '0', '1', '2' or '3' — the description of the values in balloons. | Print the maximum possible product modulo 109<=+<=7. Note, that you are not asked to maximize the remainder modulo 109<=+<=7, but to find the maximum value and print it this modulo. | [
"4\n1233\n0213\n2020\n0303\n",
"5\n00300\n00300\n33333\n00300\n00300\n",
"5\n00003\n02030\n00300\n03020\n30000\n",
"5\n21312\n10003\n10002\n10003\n23231\n",
"5\n12131\n12111\n12112\n21311\n21212\n"
] | [
"108\n",
"19683\n",
"108\n",
"3\n",
"24\n"
] | In the first sample, the maximum product is achieved for a rotated cross with a center in the cell (3, 3) and radius 1: 2·2·3·3·3 = 108. | 2,250 | [] | 1,692,524,195 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1692524194.9703364")# 1692524194.9703534 | Title: Vanya and Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya plays a game of balloons on the field of size *n*<=×<=*n*, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons... | ```python
print("_RANDOM_GUESS_1692524194.9703364")# 1692524194.9703534
``` | 0 | |
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000... | 1,677,070,574 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | m,s=map(int,input().split())
low=[0]*m
hie=[0]*m
x=s
if s>0:
low[0]=1
x-=1
i=m-1
while x>0 and i>0:
temp=min(9,x)
low[i]+=temp
x-=temp
i-=1
xx=s
i=0
while xx>0 and i<m:
temp=min(9,xx)
hie[i]=temp
xx-=temp
i+=1
if (low == [0]*len(low) and hie == [0]*len(hie) )o... | Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ... | ```python
m,s=map(int,input().split())
low=[0]*m
hie=[0]*m
x=s
if s>0:
low[0]=1
x-=1
i=m-1
while x>0 and i>0:
temp=min(9,x)
low[i]+=temp
x-=temp
i-=1
xx=s
i=0
while xx>0 and i<m:
temp=min(9,xx)
hie[i]=temp
xx-=temp
i+=1
if (low == [0]*len(low) and hie == [0]*l... | 0 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,693,930,881 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | x,y,z=map(int,input().split(' '))
distance =[abs(x-y),abs(x-z),abs(z-y)]
min_distance=max(distance)
print(min_distance) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
x,y,z=map(int,input().split(' '))
distance =[abs(x-y),abs(x-z),abs(z-y)]
min_distance=max(distance)
print(min_distance)
``` | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,690,226,558 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | s=list(input())
count=0
for i in range (len(s)):
if s[i]!=',' and s[i]!=' ' and s[i]!='{' and s[i]!='}' and s[i]!=-1:
count+=1
for j in range (i+1,len(s)):
if s[i]==s[j]:
s[j]=-1
print(s)
print(count)
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s=list(input())
count=0
for i in range (len(s)):
if s[i]!=',' and s[i]!=' ' and s[i]!='{' and s[i]!='}' and s[i]!=-1:
count+=1
for j in range (i+1,len(s)):
if s[i]==s[j]:
s[j]=-1
print(s)
print(count)
``` | 0 | |
421 | A | Pasha and Hamsters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams... | The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line... | Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. | [
"4 2 3\n1 2\n2 3 4\n",
"5 5 2\n3 4 1 2 5\n2 3\n"
] | [
"1 1 2 2\n",
"1 1 1 1 1\n"
] | none | 500 | [
{
"input": "4 2 3\n1 2\n2 3 4",
"output": "1 1 2 2"
},
{
"input": "5 5 2\n3 4 1 2 5\n2 3",
"output": "1 1 1 1 1"
},
{
"input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7... | 1,650,167,496 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 15 | 0 | n = int(input()[0])
a = set(map(int, input().split()))
b = set(map(int, input().split())) - a
for i in range(1, n+1):
print(1 if i in a else 2, end=' ')
| Title: Pasha and Hamsters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between... | ```python
n = int(input()[0])
a = set(map(int, input().split()))
b = set(map(int, input().split())) - a
for i in range(1, n+1):
print(1 if i in a else 2, end=' ')
``` | 0 | |
390 | A | Inna and Alarm Clock | PROGRAMMING | 0 | [
"implementation"
] | null | null | Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square.
The mornin... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100).
Note that a single point in the room can conta... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | [
"4\n0 0\n0 1\n0 2\n1 0\n",
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n1 1\n1 2\n2 3\n3 3\n"
] | [
"2\n",
"2\n",
"3\n"
] | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | 500 | [
{
"input": "4\n0 0\n0 1\n0 2\n1 0",
"output": "2"
},
{
"input": "4\n0 0\n0 1\n1 0\n1 1",
"output": "2"
},
{
"input": "4\n1 1\n1 2\n2 3\n3 3",
"output": "3"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 ... | 1,654,092,978 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 171 | 0 | h=set()
v=set()
for i in range(int(input())):
k = input().split()
v.add(k[0])
h.add(k[1])
print(min(len(v),len(h)))
| Title: Inna and Alarm Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner a... | ```python
h=set()
v=set()
for i in range(int(input())):
k = input().split()
v.add(k[0])
h.add(k[1])
print(min(len(v),len(h)))
``` | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,688,069,933 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
A,B,C = map(int,input().split())
ans = A//3+B//3+C//3
A%=3
B%=3
C%=3
print(ans+min... | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
A,B,C = map(int,input().split())
ans = A//3+B//3+C//3
A%=3
B%=3
C%=3
pri... | 0 | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,633,290,004 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 77 | 6,758,400 | a, b, c, d = map(int, input().split())
e = max(3*a/10, a-a*c/250)
f = max(3*b/10, b-b*d/250)
if e>f:
print("Misha")
elif e<f :
print("Vasya")
else:
print("Tie") | Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
a, b, c, d = map(int, input().split())
e = max(3*a/10, a-a*c/250)
f = max(3*b/10, b-b*d/250)
if e>f:
print("Misha")
elif e<f :
print("Vasya")
else:
print("Tie")
``` | 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,635,664,399 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 4,300,800 | a = map(int, input().split())
data = list(a)
print (int(data[0] * data[1] / 2)) if (data[0] % 2 == 0 or data[1] % 2 == 0) \
else print (int((data[0] * data[1] - 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
a = map(int, input().split())
data = list(a)
print (int(data[0] * data[1] / 2)) if (data[0] % 2 == 0 or data[1] % 2 == 0) \
else print (int((data[0] * data[1] - 1) / 2))
``` | 3.968989 |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,698,343,429 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 61 | 0 | t = int(input())
arr = []
for i in range(t):
p,q = map(int,input().split())
arr.append([p,q])
arr.sort()
arr = [[1, 2], [2, 1]]
found = False
for i in range(len(arr)):
for j in range(len(arr)):
if arr[i][0] < arr[j][0] and arr[i][1] > arr[j][1]:
print("Happy Alex")
... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
t = int(input())
arr = []
for i in range(t):
p,q = map(int,input().split())
arr.append([p,q])
arr.sort()
arr = [[1, 2], [2, 1]]
found = False
for i in range(len(arr)):
for j in range(len(arr)):
if arr[i][0] < arr[j][0] and arr[i][1] > arr[j][1]:
print("Happy Alex... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,610,904,008 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 154 | 0 | n = int(input())
l = list(map(int,input().split()))
e1 = []
o1 = []
for i in range(n) :
if l[i]%2==0:
e1.append(i)
else:
o1.append(i)
if len(e1)==1:
print(e1[0]+1)
else:
print(o1[0]+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
l = list(map(int,input().split()))
e1 = []
o1 = []
for i in range(n) :
if l[i]%2==0:
e1.append(i)
else:
o1.append(i)
if len(e1)==1:
print(e1[0]+1)
else:
print(o1[0]+1)
``` | 3.9615 |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,696,762,359 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | i = 1
for _ in range(5):
r = input().split()
if "1" in r:
j = r.index("1")+1
print((abs(3-j)+abs(3-i)))
break
i += 1 | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
i = 1
for _ in range(5):
r = input().split()
if "1" in r:
j = r.index("1")+1
print((abs(3-j)+abs(3-i)))
break
i += 1
``` | 3 | |
830 | B | Cards Sorting | PROGRAMMING | 1,600 | [
"data structures",
"implementation",
"sortings"
] | null | null | Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cards in the deck.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), where *a**i* is the number written on the *i*-th from top card in the deck. | Print the total number of times Vasily takes the top card from the deck. | [
"4\n6 3 1 2\n",
"1\n1000\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"7\n",
"1\n",
"7\n"
] | In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards ... | 1,000 | [
{
"input": "4\n6 3 1 2",
"output": "7"
},
{
"input": "1\n1000",
"output": "1"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "7"
},
{
"input": "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256... | 1,669,363,437 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
s = sorted(enumerate(w), key=lambda x:x[1])
c = 0
q = n
a, b = 0, 0
for i in range(n):
if s[i][0] >= a:
b += 1
else:
c += q
q -= b
b = 1
a = s[i][0]
c += q
print(c) | Title: Cards Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them.
Vasily decid... | ```python
import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
s = sorted(enumerate(w), key=lambda x:x[1])
c = 0
q = n
a, b = 0, 0
for i in range(n):
if s[i][0] >= a:
b += 1
else:
c += q
q -= b
b = 1
a = s[i][0]
c += q
... | 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,616,292,313 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 124 | 307,200 | def swap(num1,num2):
arr = [num2,num1]
return arr
num = int(input())
distance = list(map(int, input() .split()))
cities = list(map(int, input() .split()))
answer = 0
sum1 = 0
sum2 = 0
if cities[0] == cities[1]:
answer = 0
if (cities[0] > cities[1]):
cities = swap(cities[0], cities[1])
i = citie... | 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
def swap(num1,num2):
arr = [num2,num1]
return arr
num = int(input())
distance = list(map(int, input() .split()))
cities = list(map(int, input() .split()))
answer = 0
sum1 = 0
sum2 = 0
if cities[0] == cities[1]:
answer = 0
if (cities[0] > cities[1]):
cities = swap(cities[0], cities[1])
... | 3 | |
793 | B | Igor and his way to work | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"implementation",
"shortest paths"
] | null | null | Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid.
Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell; - "*" — a cell with road ... | In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise. | [
"5 5\n..S..\n****.\nT....\n****.\n.....\n",
"5 5\nS....\n****.\n.....\n.****\n..T..\n"
] | [
"YES",
"NO"
] | The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture: | 1,000 | [
{
"input": "5 5\nS....\n****.\n.....\n.****\n..T..",
"output": "NO"
},
{
"input": "1 2\nST",
"output": "YES"
},
{
"input": "3 1\nS\n*\nT",
"output": "NO"
},
{
"input": "3 3\n*..\n...\nTS.",
"output": "YES"
},
{
"input": "3 3\nT.*\n*.*\n*S*",
"output": "YES"
... | 1,501,906,587 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 4,915,200 | turns = {}
score_dict = {}
def has_turn(from_cell, direction):
return not turns[from_cell] & direction
def move(matrix, from_cell, to_cell, direction):
# print('from_cell, to_cell, direction ', from_cell, to_cell, direction)
can_move = False
if not to_cell in turns:
turns[to_cell] ... | Title: Igor and his way to work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, th... | ```python
turns = {}
score_dict = {}
def has_turn(from_cell, direction):
return not turns[from_cell] & direction
def move(matrix, from_cell, to_cell, direction):
# print('from_cell, to_cell, direction ', from_cell, to_cell, direction)
can_move = False
if not to_cell in turns:
turns... | 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,678,601,945 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 124 | 0 | m,n = (input().split())
area = int(m)*int(n)
print(int(area/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,n = (input().split())
area = int(m)*int(n)
print(int(area/2))
``` | 3.969 |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,668,086,699 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n,m,k=map(int,input().split())
x=[[0]*(m+2) for i in range(n+2)]
def check(i,j):
if mx[i][j+1] and mx[i+1][j] and mx[i+1][j+1]:
return True
if mx[i][j-1] and mx[i+1][j-1] and mx[i+1][j]:
return True
if mx[i-1][j] and mx[i-1][j+1] and mx[i][j+1]:
return True
if mx[i-1][j-... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
n,m,k=map(int,input().split())
x=[[0]*(m+2) for i in range(n+2)]
def check(i,j):
if mx[i][j+1] and mx[i+1][j] and mx[i+1][j+1]:
return True
if mx[i][j-1] and mx[i+1][j-1] and mx[i+1][j]:
return True
if mx[i-1][j] and mx[i-1][j+1] and mx[i][j+1]:
return True
if ... | -1 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,691,085,404 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | a,b=map(int,input().split())
s=0
d=0
if a>b:
d+=b
a-=b
if a %2 == 0:
s+=int(a/2)
else:
s+=int((a-1)/2)
else:
d+=a
b-=a
if b % 2 ==0:
s+=int(b/2)
else:
s+=int((b-1)/2)
print(d,s) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b=map(int,input().split())
s=0
d=0
if a>b:
d+=b
a-=b
if a %2 == 0:
s+=int(a/2)
else:
s+=int((a-1)/2)
else:
d+=a
b-=a
if b % 2 ==0:
s+=int(b/2)
else:
s+=int((b-1)/2)
print(d,s)
``` | 3 | |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,423,330,051 | 1,651 | Python 3 | OK | TESTS | 20 | 62 | 0 | n1, n2, k1, k2=map(int, input().split())
if(n1>n2):
print("First")
if(n1<=n2):
print("Second")
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
n1, n2, k1, k2=map(int, input().split())
if(n1>n2):
print("First")
if(n1<=n2):
print("Second")
``` | 3 | |
977 | C | Less or Equal | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
Note that the sequence can contain equal elements.
If there is no suc... | The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself. | Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$.
If there is no such $x$, print "-1" (without quotes). | [
"7 4\n3 7 5 1 10 3 20\n",
"7 2\n3 7 5 1 10 3 20\n"
] | [
"6",
"-1\n"
] | In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$.
In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ el... | 0 | [
{
"input": "7 4\n3 7 5 1 10 3 20",
"output": "5"
},
{
"input": "7 2\n3 7 5 1 10 3 20",
"output": "-1"
},
{
"input": "1 0\n1",
"output": "-1"
},
{
"input": "1 0\n2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "3 ... | 1,697,752,615 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def solve():
n,k = input().split()
nums = list(map(int,input().split()))
nums.sort()
n,k = int(n),int(k)
id = k-1
person = nums[id]
l = 0
r = len(nums)-1
while l < r:
m = l+(r-l)//2
if nums[m] > person:
r = m
else:
l = m+1... | Title: Less or Equal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are... | ```python
def solve():
n,k = input().split()
nums = list(map(int,input().split()))
nums.sort()
n,k = int(n),int(k)
id = k-1
person = nums[id]
l = 0
r = len(nums)-1
while l < r:
m = l+(r-l)//2
if nums[m] > person:
r = m
else:
... | 0 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,632,430,269 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 6,963,200 | k = int(input())
s = input()
ns = set(s)
if len(ns) > k:
print(-1)
else:
if len(s) % len(ns) == 0:
count = 0
for i in ns:
count += (s.count(i) / k)
if count == (len(s) / k):
temp = " "
for i in ns:
temp += ((s.count(i) //... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k = int(input())
s = input()
ns = set(s)
if len(ns) > k:
print(-1)
else:
if len(s) % len(ns) == 0:
count = 0
for i in ns:
count += (s.count(i) / k)
if count == (len(s) / k):
temp = " "
for i in ns:
temp += ((s.c... | 0 | |
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,667,018,085 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | d_list = []
d = input().split()
for u in range(len(d)):
d[u] = int(d[u])
d_list.append(d[u])
if d[0] + d[1] > d[2]:
print(d[2]*2)
elif d[0] + d[1] < d[2]:
print((d[0] + d[1])*2)
else:
print(d[2]*2)
| 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
d_list = []
d = input().split()
for u in range(len(d)):
d[u] = int(d[u])
d_list.append(d[u])
if d[0] + d[1] > d[2]:
print(d[2]*2)
elif d[0] + d[1] < d[2]:
print((d[0] + d[1])*2)
else:
print(d[2]*2)
``` | 0 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,673,427,213 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a, k = map(int,input().split())
count = 0
k_list = [str(i) for i in range(1,k)]
k_list.append(str(k))
k_list.append(str(0))
l = len(k_list)
n_l ="".join(k_list)
for x in range(a):
list_a = [(x) for x in input()]
str_a = "".join(list_a)
if n_l in str_a:
count += 1
print(count)
| Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
a, k = map(int,input().split())
count = 0
k_list = [str(i) for i in range(1,k)]
k_list.append(str(k))
k_list.append(str(0))
l = len(k_list)
n_l ="".join(k_list)
for x in range(a):
list_a = [(x) for x in input()]
str_a = "".join(list_a)
if n_l in str_a:
count += 1
print... | 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,693,733,584 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n = map(int,input().split())
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,n = map(int,input().split())
x = m*n
print(x//2)
``` | 3.977 |
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ... | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, yo... | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input... | 1,623,499,939 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 108 | 0 | def main_function():
a = int(input())
if a > 2:
return " ".join([str(a - i) for i in range(a)])
return -1
print(main_function())
| Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*... | ```python
def main_function():
a = int(input())
if a > 2:
return " ".join([str(a - i) for i in range(a)])
return -1
print(main_function())
``` | 3 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,695,979,397 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 11,161,600 | n=int(input())
magnets=[]
for i in range(n):
magnet=input()
magnets.append(magnet)
group=1
for i in range(len(magnets)-1):
if magnets[i]!=magnets[i+1]:
group+=1
print(group)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n=int(input())
magnets=[]
for i in range(n):
magnet=input()
magnets.append(magnet)
group=1
for i in range(len(magnets)-1):
if magnets[i]!=magnets[i+1]:
group+=1
print(group)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 0 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,587,101,463 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 27 | 3,000 | 41,062,400 | import math
def nCr(n,r):
f = math.factorial
return f(n) // f(r) // f(n-r)
n = int(input())
l = []
for i in range(n):
l.append(list(map(int,input().split())))
xd = {}
yd = {}
dup = {}
for [x,y] in l:
if x not in xd.keys():
xd[x] = 1
else:
xd[x] += 1
if... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need ... | ```python
import math
def nCr(n,r):
f = math.factorial
return f(n) // f(r) // f(n-r)
n = int(input())
l = []
for i in range(n):
l.append(list(map(int,input().split())))
xd = {}
yd = {}
dup = {}
for [x,y] in l:
if x not in xd.keys():
xd[x] = 1
else:
xd[x] += 1
... | 0 | |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,671,875,638 | 2,038 | PyPy 3-64 | OK | TESTS | 20 | 124 | 0 | n = int(input())
s = input()
ans=""
if(n%2==0):
for i in range(0,n,2):
if(i<n-2):
ans = ans + s[i:i+2]+"-"
if(i==n-2):
ans = ans + s[i:i+2]
else :
j = n-3
k = 0
while (k<j):
ans = ans + s[k:k+2]+"-"
k+=2
ans = ans+s[j:]
print(ans)
... | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
n = int(input())
s = input()
ans=""
if(n%2==0):
for i in range(0,n,2):
if(i<n-2):
ans = ans + s[i:i+2]+"-"
if(i==n-2):
ans = ans + s[i:i+2]
else :
j = n-3
k = 0
while (k<j):
ans = ans + s[k:k+2]+"-"
k+=2
ans = ans+s[j:]
print(ans... | 3.969 |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,690,039,718 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 |
inp=input()
pos=inp.index("|")
world1=inp[:pos]
world2=inp[pos+1:]
rest=input()
len3=len(rest)
ans=False
if len(world1)<=len(world2) and pos!=0:
ans=True
rec=len(world2)-len(world1)
len3-=rec
if len3<0 or len3%2==1:
print("Impossible")
exit(0)
world1+=rest[:... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
inp=input()
pos=inp.index("|")
world1=inp[:pos]
world2=inp[pos+1:]
rest=input()
len3=len(rest)
ans=False
if len(world1)<=len(world2) and pos!=0:
ans=True
rec=len(world2)-len(world1)
len3-=rec
if len3<0 or len3%2==1:
print("Impossible")
exit(0)
worl... | 0 | |
596 | A | Wilbur and Swimming Pool | PROGRAMMING | 1,100 | [
"geometry",
"implementation"
] | null | null | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are... | Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. | [
"2\n0 0\n1 1\n",
"1\n1 1\n"
] | [
"1\n",
"-1\n"
] | In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | 500 | [
{
"input": "2\n0 0\n1 1",
"output": "1"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n-188 17",
"output": "-1"
},
{
"input": "1\n71 -740",
"output": "-1"
},
{
"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174",
"output": "570456"
},
{
"inp... | 1,649,230,194 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 121 | 62 | 0 | import math
def rl():
return map(int,input().split())
def ri():
return int(input())
n=ri()
x=[]
y=[]
while n:
a,b=rl()
x.append(a)
y.append(b)
n-=1
s=(max(x)-min(x))*(max(y)-min(y))
if s==0:
print(-1)
else:
print(s) | Title: Wilbur and Swimming Pool
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parall... | ```python
import math
def rl():
return map(int,input().split())
def ri():
return int(input())
n=ri()
x=[]
y=[]
while n:
a,b=rl()
x.append(a)
y.append(b)
n-=1
s=(max(x)-min(x))*(max(y)-min(y))
if s==0:
print(-1)
else:
print(s)
``` | 3 | |
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,691,772,486 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 93 | 17,510,400 | n = int(input())
L = set(map(int, input().split())) # Use a set for O(1) membership check
missing = set(range(1, n+1)) - L # Calculate the missing elements
print(min(missing)) # Print the smallest missing element
| 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
n = int(input())
L = set(map(int, input().split())) # Use a set for O(1) membership check
missing = set(range(1, n+1)) - L # Calculate the missing elements
print(min(missing)) # Print the smallest missing element
``` | 3 | |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,614,776,144 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 307,200 | try:
s=input()
p=s
p='M'+p
def io(x):
x='M'+x
while '()' in x:
x=x.replace('()','')
if len(x)==1:
return True
else:
return False
while '()' in p or '{}' in p or '<>' in p or '[]' in p:
if '()' in p:
... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
try:
s=input()
p=s
p='M'+p
def io(x):
x='M'+x
while '()' in x:
x=x.replace('()','')
if len(x)==1:
return True
else:
return False
while '()' in p or '{}' in p or '<>' in p or '[]' in p:
if '()' in p:
... | 0 | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,608,817,462 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n = int(input())
s = str(input())
res, p = '', 0
while p < n:
if p + 1 < n:
if s[p] == '0' and s[p + 1] == '0':
res += '0'
p += 2
continue
if s[p] == '1':
count = 1
p += 1
while p < n:
if s[p] == '1':
p... | Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
n = int(input())
s = str(input())
res, p = '', 0
while p < n:
if p + 1 < n:
if s[p] == '0' and s[p + 1] == '0':
res += '0'
p += 2
continue
if s[p] == '1':
count = 1
p += 1
while p < n:
if s[p] == '1':
... | 0 | |
600 | F | Edge coloring of bipartite graph | PROGRAMMING | 2,800 | [
"graphs"
] | null | null | You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour. | The first line contains three integers *a*,<=*b*,<=*m* (1<=≤<=*a*,<=*b*<=≤<=1000, 0<=≤<=*m*<=≤<=105), *a* is the size of the first part, *b* is the size of the second part, *m* is the number of edges in the graph.
Each of the next *m* lines contains two integers *x*,<=*y* (1<=≤<=*x*<=≤<=*a*,<=1<=≤<=*y*<=≤<=*b*), where... | In the first line print integer *c* — the minimal number of colours. The second line should contain *m* integers from 1 to *c* — the colours of the edges (in the order they appear in the input).
If there are several solutions, you can print any one of them. | [
"4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3\n"
] | [
"3\n1 2 3 1 2\n"
] | none | 0 | [
{
"input": "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3",
"output": "3\n1 2 3 1 2"
},
{
"input": "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3",
"output": "3\n1 2 3 1 2"
},
{
"input": "4 3 0",
"output": "0"
},
{
"input": "10 10 67\n1 1\n1 2\n1 3\n1 7\n1 9\n1 10\n2 1\n2 2\n2 3\n2 6\n2 8\n2 10\n3 2\n3 3\... | 1,657,806,830 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 889 | 52,326,400 | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wr... | Title: Edge coloring of bipartite graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour.
Input Specifica... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self... | 3 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,591,128,093 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 310 | 102,400 | # Author : debugster
# Email : [email protected]
# Date : 2020-06-03 01:51:41
import sys
import os
def get_int():
return map(int, input().split())
def get_array():
return list(map(int, input().split()))
if os.environ.get("DEBUGSTER_PYTHON"):
sys.stdin = open('in.txt', 'r')
sys.stdout ... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
# Author : debugster
# Email : [email protected]
# Date : 2020-06-03 01:51:41
import sys
import os
def get_int():
return map(int, input().split())
def get_array():
return list(map(int, input().split()))
if os.environ.get("DEBUGSTER_PYTHON"):
sys.stdin = open('in.txt', 'r')
s... | 3.922309 |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,685,122,319 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | a, b = list(map(int, input().split()))
lista = []
lista.append(b)
flag = False
while a <= b:
# print("~~", a, b)
if a == b:
flag = True
break
elif b % 2 == 0:
b = b // 2
lista.append(b)
elif b % 10 == 1:
b = (b - 1) // 10
lista.append(b)
else:
... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app... | ```python
a, b = list(map(int, input().split()))
lista = []
lista.append(b)
flag = False
while a <= b:
# print("~~", a, b)
if a == b:
flag = True
break
elif b % 2 == 0:
b = b // 2
lista.append(b)
elif b % 10 == 1:
b = (b - 1) // 10
lista.append(b)
el... | 3 | |
979 | B | Treasure Hunt | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the lengt... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Th... | 1,000 | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{... | 1,530,262,308 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n = int(input())
scores = []
for _ in range(3):
letters = {}
word = input()
if n >= len(word) - 1:
print("Draw")
exit(0)
for c in word:
if c in letters:
letters[c] += 1
else:
letters[c] = 0
scores.append(max(letters.values()))
... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friend... | ```python
n = int(input())
scores = []
for _ in range(3):
letters = {}
word = input()
if n >= len(word) - 1:
print("Draw")
exit(0)
for c in word:
if c in letters:
letters[c] += 1
else:
letters[c] = 0
scores.append(max(letters.val... | 0 | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,563,392,089 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 124 | 0 | s=input()
m=1
l=0
d={'A','E','I','O','U','Y'}
for i in range(len(s)):
if s[i] in d:
l=max(l,m)
m=1
else:
m+=1
l=max(l,m)
if l==0:
print(len(s)+1)
else:
print(l) | Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
s=input()
m=1
l=0
d={'A','E','I','O','U','Y'}
for i in range(len(s)):
if s[i] in d:
l=max(l,m)
m=1
else:
m+=1
l=max(l,m)
if l==0:
print(len(s)+1)
else:
print(l)
``` | 3 | |
161 | A | Dress'em in Vests! | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"greedy",
"two pointers"
] | null | null | The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.
The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered him... | The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i... | In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests.
In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are ... | [
"5 3 0 0\n1 2 3 3 4\n1 3 5\n",
"3 3 2 2\n1 5 9\n3 5 7\n"
] | [
"2\n1 1\n3 2\n",
"3\n1 1\n2 2\n3 3\n"
] | In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one.
In the second sample the vest size can differ... | 1,000 | [
{
"input": "5 3 0 0\n1 2 3 3 4\n1 3 5",
"output": "2\n1 1\n3 2"
},
{
"input": "3 3 2 2\n1 5 9\n3 5 7",
"output": "3\n1 1\n2 2\n3 3"
},
{
"input": "1 1 0 0\n1\n1",
"output": "1\n1 1"
},
{
"input": "1 1 0 0\n1\n2",
"output": "0"
},
{
"input": "2 3 1 4\n1 5\n1 2 2",
... | 1,637,251,075 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 124 | 512,000 | from sys import stdin
input = stdin.readline
def answer():
ans = []
j = 0
for i in range(m):
if((a[j] - x) > b[i]):continue
while(j < n and (a[j] + y) < b[i]):
j += 1
if(j == n):break
ans.append([i + 1 , j + 1])
j += 1
print(len(ans))
for v ... | Title: Dress'em in Vests!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the s... | ```python
from sys import stdin
input = stdin.readline
def answer():
ans = []
j = 0
for i in range(m):
if((a[j] - x) > b[i]):continue
while(j < n and (a[j] + y) < b[i]):
j += 1
if(j == n):break
ans.append([i + 1 , j + 1])
j += 1
print(len(ans))
... | 0 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,686,714,385 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n=int(input())
x=list(map(int,input().split()))
def solve(i,p=0):
if i==n:
return i+1
if x[i]==1 and p!=1:
return solve(i+1,1)
elif x[i]==2 and p!=2:
return solve(i+1,2)
elif x[i]==3:
if p:
return solve(i+1,[2,1][p-1])
else:
ret... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n=int(input())
x=list(map(int,input().split()))
def solve(i,p=0):
if i==n:
return i+1
if x[i]==1 and p!=1:
return solve(i+1,1)
elif x[i]==2 and p!=2:
return solve(i+1,2)
elif x[i]==3:
if p:
return solve(i+1,[2,1][p-1])
else:
... | 0 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,616,594,111 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 3,788,800 | n, cases = map(int, input().split())
arr = list(map(int, input().split()))
while cases:
cases -= 1
a, b = map(int, input().split())
minus = 0
plus = 0
for n in arr:
if n > 0:
plus += 1
else:
minus += 1
if (b-a+1) % 2 != 0:
print(... | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
n, cases = map(int, input().split())
arr = list(map(int, input().split()))
while cases:
cases -= 1
a, b = map(int, input().split())
minus = 0
plus = 0
for n in arr:
if n > 0:
plus += 1
else:
minus += 1
if (b-a+1) % 2 != 0:
... | 0 | |
386 | B | Fly, freebies, fly! | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" — then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis *n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100), where *n* — the number of students shouted "Fly, freebie, fly!" The second line contains *n* positive integers *t**i* (1<=≤<=*t**i*<=≤<=1000).
The last line contains integer *T* (1<=≤<=*T*<=≤<=1000) — the time interval during which the freebie was n... | Print a single integer — the largest number of people who will pass exam tomorrow because of the freebie visit. | [
"6\n4 1 7 8 3 8\n1\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "6\n4 1 7 8 3 8\n1",
"output": "3"
},
{
"input": "4\n4 2 1 5\n2",
"output": "2"
},
{
"input": "10\n4 7 1 3 8 5 2 1 8 4\n3",
"output": "6"
},
{
"input": "8\n39 49 37 28 40 17 50 2\n10",
"output": "3"
},
{
"input": "2\n1 1\n1",
"output": "2"
},
{
... | 1,695,401,858 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | N = int(input())
lst = list(map(int,input().split()))
T = int(input())
lst.sort()
count = 0
for i in range(len(lst)):
l, r = 0, len(lst)-1
while l<r:
m = (l+r)//2
if lst[i] - lst[m] == 1:
count+=1
break
elif lst[i] - lst[m] > 1:
l+=1
... | Title: Fly, freebies, fly!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" — then flo... | ```python
N = int(input())
lst = list(map(int,input().split()))
T = int(input())
lst.sort()
count = 0
for i in range(len(lst)):
l, r = 0, len(lst)-1
while l<r:
m = (l+r)//2
if lst[i] - lst[m] == 1:
count+=1
break
elif lst[i] - lst[m] > 1:
... | 0 | |
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full rev... | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
... | 1,547,694,224 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 248 | 1,228,800 | t = input()
#-+-++--+
stack = []
for i in t:
try:
if stack[-1] == i:
stack.pop()
else:
stack.append(i)
except:
stack.append(i)
if len(stack) == 0:
print("Yes")
else:
print("No") | Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it... | ```python
t = input()
#-+-++--+
stack = []
for i in t:
try:
if stack[-1] == i:
stack.pop()
else:
stack.append(i)
except:
stack.append(i)
if len(stack) == 0:
print("Yes")
else:
print("No")
``` | 3 | |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,438,423,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | def isPlaindrome(expression):
if(len(expression) <= 1):
return True
else:
if(expression[len(expression)-1] == expression[0]):
return isPlaindrome(expression[1:(len(expression)-1)])
else:
return False
s = input()
k = int(input())
l = len(s)//k
coun... | Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
def isPlaindrome(expression):
if(len(expression) <= 1):
return True
else:
if(expression[len(expression)-1] == expression[0]):
return isPlaindrome(expression[1:(len(expression)-1)])
else:
return False
s = input()
k = int(input())
l = len(s)/... | 0 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,667,767,418 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 265 | 13,824,000 | """
https://codeforces.com/problemset/problem/519/B
"""
_ = input()
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()]) + [-1]
c = sorted([int(x) for x in input().split()]) + [-1, -1]
for i, z in enumerate(b):
if z != a[i]:
print(a[i])
break
for i, z in enum... | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
"""
https://codeforces.com/problemset/problem/519/B
"""
_ = input()
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()]) + [-1]
c = sorted([int(x) for x in input().split()]) + [-1, -1]
for i, z in enumerate(b):
if z != a[i]:
print(a[i])
break
for i,... | 3 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,649,993,225 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | import sys
input = lambda : sys.stdin.readline().strip()
##############################################################################
n,k = map(int,input().split())
print('YES' if n % 2 == 1 else 'NO') | Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
import sys
input = lambda : sys.stdin.readline().strip()
##############################################################################
n,k = map(int,input().split())
print('YES' if n % 2 == 1 else 'NO')
``` | 0 | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,696,263,260 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 92 | 0 | n, k = map(int, input().split())
line = list(map(int, input().split()))
i = 0
while k:
if line[i] < 0:
line[i] *= -1
k -= 1
if k == 0:
break
elif line[i] >= 0:
if k % 2 == 1:
min_num = line.index(min(line))
line[min_nu... | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
n, k = map(int, input().split())
line = list(map(int, input().split()))
i = 0
while k:
if line[i] < 0:
line[i] *= -1
k -= 1
if k == 0:
break
elif line[i] >= 0:
if k % 2 == 1:
min_num = line.index(min(line))
l... | -1 | |
257 | B | Playing Cubes | PROGRAMMING | 1,300 | [
"games",
"greedy",
"implementation"
] | null | null | Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pa... | The only line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of red and blue cubes, correspondingly. | On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well. | [
"3 1\n",
"2 4\n"
] | [
"2 1\n",
"3 2\n"
] | In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point.
If Petya would choose the red cu... | 500 | [
{
"input": "3 1",
"output": "2 1"
},
{
"input": "2 4",
"output": "3 2"
},
{
"input": "1 1",
"output": "0 1"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "4 4",
"output": "3 4"
},
{
"input": "10 7",
"output": "9 7"
},
{
"input": "5 13"... | 1,540,128,711 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 156 | 0 | n=int(input().split())
m=int(input())
print(max(n,m)-1,min(n,m)) | Title: Playing Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (... | ```python
n=int(input().split())
m=int(input())
print(max(n,m)-1,min(n,m))
``` | -1 | |
60 | A | Where Are My Flakes? | PROGRAMMING | 1,300 | [
"implementation",
"two pointers"
] | A. Where Are My Flakes? | 2 | 256 | One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are numbered from 1 to *n* from the left to the right. The roommate left hints like "Hidden to the left o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*m*<=≤<=1000) which represent the number of boxes and the number of hints correspondingly. Next *m* lines contain hints like "To the left of *i*" and "To the right of *i*", where *i* is integer (1<=≤<=*i*<=≤<=*n*). The hints may coincide. | The answer should contain exactly one integer — the number of boxes that should necessarily be checked or "-1" if the hints are contradictory. | [
"2 1\nTo the left of 2\n",
"3 2\nTo the right of 1\nTo the right of 2\n",
"3 1\nTo the left of 3\n",
"3 2\nTo the left of 2\nTo the right of 1\n"
] | [
"1\n",
"1\n",
"2\n",
"-1\n"
] | none | 500 | [
{
"input": "2 1\nTo the left of 2",
"output": "1"
},
{
"input": "3 2\nTo the right of 1\nTo the right of 2",
"output": "1"
},
{
"input": "3 1\nTo the left of 3",
"output": "2"
},
{
"input": "3 2\nTo the left of 2\nTo the right of 1",
"output": "-1"
},
{
"input": "... | 1,581,214,198 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 374 | 1,433,600 | n, m = input().split(' ')
n = int(n)
m = int(m)
hints = {}
max_right = None
min_left = None
if m > 0:
for i in range(m):
do_nothing = False
line = input().split(' ')
hint_position = int(line[4])-1
if line[2] == 'left':
hint_box = hint_position - ... | Title: Where Are My Flakes?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are... | ```python
n, m = input().split(' ')
n = int(n)
m = int(m)
hints = {}
max_right = None
min_left = None
if m > 0:
for i in range(m):
do_nothing = False
line = input().split(' ')
hint_position = int(line[4])-1
if line[2] == 'left':
hint_box = hint_p... | 3.90383 |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,620,905,043 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 6,963,200 | def is_power_of_2(n):
return (n & (n - 1)) == 0
def solve(n):
sum_1_to_n = (n*(n+1))//2
sum_powers_of_2 = 0
i = 1
while i <= n:
if is_power_of_2(i):
sum_powers_of_2 += i
i *= 2
return sum_1_to_n - (2 * sum_powers_of_2)
if __name__ == '__main__':
t = int(input())
while t > 0:
n = int(input())
... | Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
def is_power_of_2(n):
return (n & (n - 1)) == 0
def solve(n):
sum_1_to_n = (n*(n+1))//2
sum_powers_of_2 = 0
i = 1
while i <= n:
if is_power_of_2(i):
sum_powers_of_2 += i
i *= 2
return sum_1_to_n - (2 * sum_powers_of_2)
if __name__ == '__main__':
t = int(input())
while t > 0:
n = int(i... | 3 | |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* deno... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1... | 1,397,838,477 | 1,077 | Python 3 | OK | TESTS | 34 | 62 | 0 | [n, k], speed = map(int, input().split()), sorted(map(int, input().split()), reverse = True)
print(speed[k - 1])
| Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a... | ```python
[n, k], speed = map(int, input().split()), sorted(map(int, input().split()), reverse = True)
print(speed[k - 1])
``` | 3 | |
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,693,371,864 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=input("")
b=input("")
c=a.length()
i=0
j=c-1
for i in range(c//2):
swap(a[i], a[j])
i++
j--
if (a==b):
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
a=input("")
b=input("")
c=a.length()
i=0
j=c-1
for i in range(c//2):
swap(a[i], a[j])
i++
j--
if (a==b):
print("YES")
else:
print("NO")
``` | -1 |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,660,243,380 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 155 | 27,545,600 | t=int(input())
l=list(map(int,input().split()))
maxi=max(l)
mini=min(l)
count1=l.count(maxi)
count2=l.count(mini)
if mini==maxi:
print(maxi-mini,count1*(count1-1)//2)
else:
print(maxi-mini,count1*count2) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
t=int(input())
l=list(map(int,input().split()))
maxi=max(l)
mini=min(l)
count1=l.count(maxi)
count2=l.count(mini)
if mini==maxi:
print(maxi-mini,count1*(count1-1)//2)
else:
print(maxi-mini,count1*count2)
``` | 3 |
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.