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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,687,774,145 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 436 | 409,600 | from collections import defaultdict
n = int(input())
a = defaultdict(int)
ans = float("-inf")
for _ in range(n):
hi, mi = map(int, input().split())
val = hi*60 + mi
a[val] += 1
ans = max(ans, a[val])
print(ans)
| 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
from collections import defaultdict
n = int(input())
a = defaultdict(int)
ans = float("-inf")
for _ in range(n):
hi, mi = map(int, input().split())
val = hi*60 + mi
a[val] += 1
ans = max(ans, a[val])
print(ans)
``` | 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,680,766,019 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n = int(input())
for i in range(n):
i = input()
a = []
if len(i) > 10:
a.append(i[0] + str(len(i) - 2) + i[-1], sep='')
print(''.join(a))
else:
print(i) | 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())
for i in range(n):
i = input()
a = []
if len(i) > 10:
a.append(i[0] + str(len(i) - 2) + i[-1], sep='')
print(''.join(a))
else:
print(i)
``` | -1 |
92 | B | Binary Number | PROGRAMMING | 1,300 | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divide... | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide... | 1,000 | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "101010100100111100011111001111100001010101111110101... | 1,461,258,405 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 7,782,400 | n, v = int(input(), 2), 0
while n > 1:
if n % 2:
n += 1
v += 1
n >>= 1
v += 1
print(v) | Title: Binary Number
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to ... | ```python
n, v = int(input(), 2), 0
while n > 1:
if n % 2:
n += 1
v += 1
n >>= 1
v += 1
print(v)
``` | 0 |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,660,848,441 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 46 | 0 | S = input()
T = input()
R = list(S[:-1])
R.append(chr(ord(S[-1]) + 1))
i = len(R) - 1
while i > 0 and R[i] > 'z':
R[i] = 'a'
R[i - 1] = chr(ord(S[i -1]) + 1)
i -= 1
R = "".join(R)
if R == T: print("No such string")
else: print(R) | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
S = input()
T = input()
R = list(S[:-1])
R.append(chr(ord(S[-1]) + 1))
i = len(R) - 1
while i > 0 and R[i] > 'z':
R[i] = 'a'
R[i - 1] = chr(ord(S[i -1]) + 1)
i -= 1
R = "".join(R)
if R == T: print("No such string")
else: print(R)
``` | 3 | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,588,272,094 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 280 | 0 | n, m = map(int, input().split())
A = [0]*m
B = [0]*m
k = 0
for i in range(m):
A[i], B[i] = map(int, input().split())
for i in range(1, n+1):
c = A.count(i) + B.count(i)
if c == 0 or c > 2:
k += 1
print(k)
| Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
n, m = map(int, input().split())
A = [0]*m
B = [0]*m
k = 0
for i in range(m):
A[i], B[i] = map(int, input().split())
for i in range(1, n+1):
c = A.count(i) + B.count(i)
if c == 0 or c > 2:
k += 1
print(k)
``` | 0 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,544,720,595 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n = int(input())
O = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
while n>5:
n = n >> 1
n = n-2
print(O[n-3]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
O = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
while n>5:
n = n >> 1
n = n-2
print(O[n-3])
``` | 0 |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,699,632,962 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | s=input()
a=""
for i in s:
if i not in "aeiouy":
a=a+"."+i
print(a)
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
s=input()
a=""
for i in s:
if i not in "aeiouy":
a=a+"."+i
print(a)
``` | 0 | |
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy ... | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the inp... | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti... | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n... | 1,619,621,325 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 77 | 0 | n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y,=0,0
while(x!=n)and(y!=k):
if(a[x]<=b[y]):
y=y+1
x=x+1
print(y)
| Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y,=0,0
while(x!=n)and(y!=k):
if(a[x]<=b[y]):
y=y+1
x=x+1
print(y)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,650,308,046 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | string=input()
def unique(string):
new=""
for i in string:
if i not in new:
if new.count("l"):
new+="l"
new+=i
return new
if "hello" in unique(string).lower():
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
string=input()
def unique(string):
new=""
for i in string:
if i not in new:
if new.count("l"):
new+="l"
new+=i
return new
if "hello" in unique(string).lower():
print("YES")
else:
print("NO")
``` | 0 |
621 | E | Wet Shark and Blocks | PROGRAMMING | 2,000 | [
"dp",
"matrices"
] | null | null | There are *b* blocks of digits. Each one consisting of the same *n* digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the se... | The first line of the input contains four space-separated integers, *n*, *b*, *k* and *x* (2<=≤<=*n*<=≤<=50<=000,<=1<=≤<=*b*<=≤<=109,<=0<=≤<=*k*<=<<=*x*<=≤<=100,<=*x*<=≥<=2) — the number of digits in one block, the number of blocks, interesting remainder modulo *x* and modulo *x* itself.
The next line contains *n* ... | Print the number of ways to pick exactly one digit from each blocks, such that the resulting integer equals *k* modulo *x*. | [
"12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5\n",
"3 2 1 2\n6 2 2\n",
"3 2 1 2\n3 1 2\n"
] | [
"3\n",
"0\n",
"6\n"
] | In the second sample possible integers are 22, 26, 62 and 66. None of them gives the remainder 1 modulo 2.
In the third sample integers 11, 13, 21, 23, 31 and 33 have remainder 1 modulo 2. There is exactly one way to obtain each of these integers, so the total answer is 6. | 2,500 | [
{
"input": "12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5",
"output": "3"
},
{
"input": "3 2 1 2\n6 2 2",
"output": "0"
},
{
"input": "3 2 1 2\n3 1 2",
"output": "6"
},
{
"input": "3 2 1 2\n6 3 2",
"output": "3"
},
{
"input": "3 2 1 2\n3 6 3",
"output": "6"
},
{
... | 1,604,824,947 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 921,600 | n,b,k,x=map(int,input().split())
mod=10**9+7
nums=list(map(int,input().split()))
a=[[0]*x for _ in range(x)]
for j in range(x):
for l in range(n):
a[(10*j+nums[l])%x][j]+=1
res=[[0]*x for _ in range(x)]
for i in range(x):
res[i][i]=1
def mul(a,b):
ans=[[0]*x for _ in range(x)]
... | Title: Wet Shark and Blocks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *b* blocks of digits. Each one consisting of the same *n* digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together ... | ```python
n,b,k,x=map(int,input().split())
mod=10**9+7
nums=list(map(int,input().split()))
a=[[0]*x for _ in range(x)]
for j in range(x):
for l in range(n):
a[(10*j+nums[l])%x][j]+=1
res=[[0]*x for _ in range(x)]
for i in range(x):
res[i][i]=1
def mul(a,b):
ans=[[0]*x for _ in ran... | 0 | |
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
... | 1,528,979,972 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 78 | 0 | s=input()
cg={'.':3,'A':0,'B':1,'C':2}
def _(x) :
return cg[x]
a=list(map(_,s))
if len(a)<3 :
print('No')
exit()
cnt=[0,0,0,0]
for i in range(len(a)) :
cnt[a[i]]=cnt[a[i]]+1
if i-3>=0 :
cnt[a[i-3]]=cnt[a[i-3]]-1
if cnt[0] and cnt[1] and cnt[2] :
print('Yes')
... | Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti... | ```python
s=input()
cg={'.':3,'A':0,'B':1,'C':2}
def _(x) :
return cg[x]
a=list(map(_,s))
if len(a)<3 :
print('No')
exit()
cnt=[0,0,0,0]
for i in range(len(a)) :
cnt[a[i]]=cnt[a[i]]+1
if i-3>=0 :
cnt[a[i-3]]=cnt[a[i-3]]-1
if cnt[0] and cnt[1] and cnt[2] :
print('Yes... | 3 | |
171 | B | Star | PROGRAMMING | 1,300 | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). | Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). | [
"2\n"
] | [
"13"
] | none | 0 | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"... | 1,692,234,033 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 154 | 102,400 | import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
N = int(input())
if N==1:
exit(print(1))
ans = 1
cur = 12
for i in range(1,N):
ans+=cur
cur*=2
print(ans)
| Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
N = int(input())
if N==1:
exit(print(1))
ans = 1
cur = 12
for i in range(1,N):
ans+=cur
cur*=2
print(an... | 0 | ||
254 | B | Jury Size | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | In 2013, the writers of Berland State University should prepare problems for *n* Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to *n*. For each Olympiad we know how many members of the jury must be involved in its preparation, as well as the time required to prepare the prob... | The first line contains integer *n* — the number of Olympiads in 2013 (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains four integers *m**i*, *d**i*, *p**i* and *t**i* — the month and day of the Olympiad (given without leading zeroes), the needed number of the jury members and the time needed to prepare the... | Print a single number — the minimum jury size. | [
"2\n5 23 1 2\n3 13 2 3\n",
"3\n12 9 2 1\n12 8 1 3\n12 8 2 2\n",
"1\n1 10 1 13\n"
] | [
"2\n",
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "2\n5 23 1 2\n3 13 2 3",
"output": "2"
},
{
"input": "3\n12 9 2 1\n12 8 1 3\n12 8 2 2",
"output": "3"
},
{
"input": "1\n1 10 1 13",
"output": "1"
},
{
"input": "3\n3 16 25 1\n3 15 9 34\n3 14 90 87",
"output": "99"
},
{
"input": "4\n2 15 52 53\n2 15 35 8... | 1,579,077,969 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 409,600 | from datetime import date, timedelta
import math
w=open('output.txt', 'w')
r=open('input.txt', 'r')
oplympiads = []
min_date = date(2014,1,1)
max_date = date(2011,1,1)
n = int(r.readline())
for _ in range(n):
m, d, p, t = map(int, r.readline().split())
oplympiads.append((m,d,p,t))
if (d... | Title: Jury Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In 2013, the writers of Berland State University should prepare problems for *n* Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to *n*. For each Olympiad we know how many members of... | ```python
from datetime import date, timedelta
import math
w=open('output.txt', 'w')
r=open('input.txt', 'r')
oplympiads = []
min_date = date(2014,1,1)
max_date = date(2011,1,1)
n = int(r.readline())
for _ in range(n):
m, d, p, t = map(int, r.readline().split())
oplympiads.append((m,d,p,t))
... | 3 | |
426 | A | Sereja and Mugs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume th... | The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug. | In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise. | [
"3 4\n1 1 1\n",
"3 4\n3 1 3\n",
"3 4\n4 4 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3 4\n1 1 1",
"output": "YES"
},
{
"input": "3 4\n3 1 3",
"output": "YES"
},
{
"input": "3 4\n4 4 4",
"output": "NO"
},
{
"input": "2 1\n1 10",
"output": "YES"
},
{
"input": "3 12\n5 6 6",
"output": "YES"
},
{
"input": "4 10\n6 3 8 7",
"... | 1,651,299,616 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 0 | n,s=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
a.sort()
sum=0
flag=0
for i in range(0,n-1):
sum+=a[i]
if(sum>s):
flag=1
break
if(flag==1):
print("NO")
else:
print("YES")
| Title: Sereja and Mugs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non... | ```python
n,s=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
a.sort()
sum=0
flag=0
for i in range(0,n-1):
sum+=a[i]
if(sum>s):
flag=1
break
if(flag==1):
print("NO")
else:
print("YES")
``` | 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,678,097,044 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | n=int(input())
s=[]
s1=""
s2=""
for i in range(n):
s.append(input())
for i in range(n):
s1=s[i]
l=len(s1)
if l>10:
s2=s1[0]+str(l-2)+s1[l-1]
print(s2)
else:
print(s1) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n=int(input())
s=[]
s1=""
s2=""
for i in range(n):
s.append(input())
for i in range(n):
s1=s[i]
l=len(s1)
if l>10:
s2=s1[0]+str(l-2)+s1[l-1]
print(s2)
else:
print(s1)
``` | 3.969 |
120 | C | Winnie-the-Pooh and honey | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, separated by spaces (1<=≤<=*a**i*<=≤<=100). | Print a single number — how many kilos of honey gets Piglet. | [
"3 3\n15 8 10\n"
] | [
"9\n"
] | none | 0 | [
{
"input": "3 3\n15 8 10",
"output": "9"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "3 4\n3 8 2",
"output": "5"
},
{
"input": "3 2\n95 25 49",
"output": "151"
},
{
"input": "3 1\n8 3 2",
"output": "5"
},
{
"input": "5 1\n4 7 9 5 7",
"outpu... | 1,428,136,943 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | import sys
import math
f = open('input.txt', 'r')
n, k = [int(x) for x in (f.readline()).split()]
an = list(map(int, (f.readline()).split()))
f.close()
res = 0
for i in an:
if(i < k):
res += i
else:
res += i - min(int(i / k), k) * k
fr = open('output.txt', 'w')
fr.... | Title: Winnie-the-Pooh and honey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie an... | ```python
import sys
import math
f = open('input.txt', 'r')
n, k = [int(x) for x in (f.readline()).split()]
an = list(map(int, (f.readline()).split()))
f.close()
res = 0
for i in an:
if(i < k):
res += i
else:
res += i - min(int(i / k), k) * k
fr = open('output.txt',... | 0 | |
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,695,702,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | a = input()
if ord(a[0])<95:
print(a)
else:
string = ''
string = string + a[0].upper()
for i in range(1,len(a)):
string += a[i]
print(string)
| 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
a = input()
if ord(a[0])<95:
print(a)
else:
string = ''
string = string + a[0].upper()
for i in range(1,len(a)):
string += a[i]
print(string)
``` | 0 | |
66 | D | Petya and His Friends | PROGRAMMING | 1,700 | [
"constructive algorithms",
"math",
"number theory"
] | D. Petya and His Friends | 2 | 256 | Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*.
Let us remind you the definition of the greatest common divisor: *GCD*(*a*1,<=...,<=*a**k*)<==<=*d*, where *d* represents such a maximal positive number that each *... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=50). | If there is no answer, print "-1" without quotes. Otherwise print a set of *n* distinct positive numbers *a*1,<=*a*2,<=...,<=*a**n*. Each line must contain one number. Each number must consist of not more than 100 digits, and must not contain any leading zeros. If there are several solutions to that problem, print any ... | [
"3\n",
"4\n"
] | [
"99\n55\n11115\n",
"385\n360\n792\n8360\n"
] | none | 2,000 | [
{
"input": "3",
"output": "15\n10\n6"
},
{
"input": "4",
"output": "105\n70\n42\n30"
},
{
"input": "5",
"output": "1155\n770\n462\n330\n210"
},
{
"input": "6",
"output": "15015\n10010\n6006\n4290\n2730\n2310"
},
{
"input": "7",
"output": "255255\n170170\n10210... | 1,566,402,327 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=100
primes = [True] * (n+1)#范围0到n的列表
p = 2#这是最小的素数
while p * p <= n:#一直筛到sqrt(n)就行了
if primes[p]:#如果没被筛,一定是素数
for i in range(p * 2, n + 1, p):#筛掉它的倍数即可
primes[i] = False
p += 1
primes = [element for element in range(2, n) if primes[element]]#得到所有少于n的素数
a=[]
nn=int(input())
if ... | Title: Petya and His Friends
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*.
Let us remind you the definition of the greatest common divis... | ```python
n=100
primes = [True] * (n+1)#范围0到n的列表
p = 2#这是最小的素数
while p * p <= n:#一直筛到sqrt(n)就行了
if primes[p]:#如果没被筛,一定是素数
for i in range(p * 2, n + 1, p):#筛掉它的倍数即可
primes[i] = False
p += 1
primes = [element for element in range(2, n) if primes[element]]#得到所有少于n的素数
a=[]
nn=int(inp... | -1 |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,667,964,884 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 33,894,400 | n,m = map(int,input().split())
an = list(map(int,input().split()))
mat = [{an[n-1]} for _ in range(n)]
for i in range(1,n):
for j in range(n-i):
mat[j] = set(list(mat[j])+[an[n-i-1]])
for k in range(n-1,n):
mat[k] = mat[k]
for s in range(m):
print(len(mat[int(input())-1])) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n,m = map(int,input().split())
an = list(map(int,input().split()))
mat = [{an[n-1]} for _ in range(n)]
for i in range(1,n):
for j in range(n-i):
mat[j] = set(list(mat[j])+[an[n-i-1]])
for k in range(n-1,n):
mat[k] = mat[k]
for s in range(m):
print(len(mat[int(input())-1]))... | 0 | |
70 | A | Cookies | PROGRAMMING | 1,300 | [
"math"
] | A. Cookies | 1 | 256 | Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). | Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. | [
"3\n"
] | [
"9"
] | If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | 500 | [
{
"input": "3",
"output": "9"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "27"
},
{
"input": "6",
"output": "243"
},
{
"input": "11",
"output": "59049"
},
{
"input": "14",
"output": "59... | 1,474,979,787 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | #Name of Allah
n = int(input())
if n == 2:
print(6)
exit(0)
md = 10**6 + 3
a = 0
b = 3
ans = 0
A = []
B = []
cnt = 0
while True:
a,b = b,a+b
A.append(b)
l = len(A)
ans = sum(A) - A[l-1]
B.append(ans)
cnt += 1
if cnt>n:
break
# print(*A)
# print(*B)
print(B[n-1]%md)
# pr... | Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which li... | ```python
#Name of Allah
n = int(input())
if n == 2:
print(6)
exit(0)
md = 10**6 + 3
a = 0
b = 3
ans = 0
A = []
B = []
cnt = 0
while True:
a,b = b,a+b
A.append(b)
l = len(A)
ans = sum(A) - A[l-1]
B.append(ans)
cnt += 1
if cnt>n:
break
# print(*A)
# print(*B)
print(B[n-1]... | 0 |
449 | B | Jzzhu and Cities | PROGRAMMING | 2,000 | [
"graphs",
"greedy",
"shortest paths"
] | null | null | Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train route... | The first line contains three integers *n*,<=*m*,<=*k* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=3·105; 1<=≤<=*k*<=≤<=105).
Each of the next *m* lines contains three integers *u**i*,<=*v**i*,<=*x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*; 1<=≤<=*x**i*<=≤<=109).
Each of the next *k* lines contains two integers *s*... | Output a single integer representing the maximum number of the train routes which can be closed. | [
"5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n",
"2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n"
] | [
"2\n",
"2\n"
] | none | 1,000 | [
{
"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5",
"output": "2"
},
{
"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3",
"output": "2"
},
{
"input": "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000",
"output": ... | 1,594,701,949 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 155 | 20,275,200 | from collections import defaultdict
import heapq as heap
def djkstra(src):
d = {i:float('inf') for i in range(1,n+1)}
d[src] = 0
visited = set()
min_dist = [(0,src)]
while min_dist:
val , curr = heap.heappop(min_dist)
if curr in visited:
continue
... | Title: Jzzhu and Cities
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vi... | ```python
from collections import defaultdict
import heapq as heap
def djkstra(src):
d = {i:float('inf') for i in range(1,n+1)}
d[src] = 0
visited = set()
min_dist = [(0,src)]
while min_dist:
val , curr = heap.heappop(min_dist)
if curr in visited:
contin... | 0 | |
813 | B | The Golden Age | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as the... | The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). | Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0. | [
"2 3 1 10\n",
"3 5 10 22\n",
"2 3 3 5\n"
] | [
"1\n",
"8\n",
"0\n"
] | In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | 0 | [
{
"input": "2 3 1 10",
"output": "1"
},
{
"input": "3 5 10 22",
"output": "8"
},
{
"input": "2 3 3 5",
"output": "0"
},
{
"input": "2 2 1 10",
"output": "1"
},
{
"input": "2 2 1 1000000",
"output": "213568"
},
{
"input": "2 2 1 1000000000000000000",
... | 1,527,107,271 | 1,311 | Python 3 | OK | TESTS | 85 | 78 | 0 | #!/usr/bin/env python3
[x, y, l, r] = map(int, input().strip().split())
def pows(x, r):
ps = [1]
while ps[-1] * x < r:
ps.append(ps[-1] * x)
return ps
px = pows(x, r)
py = pows(y, r)
nothappy = [l - 1, r + 1]
for ppx in px:
for ppy in py:
if l <= ppx + ppy <= r:
nothappy.append(ppx + ppy)
nothappy.sort()... | Title: The Golden Age
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 a... | ```python
#!/usr/bin/env python3
[x, y, l, r] = map(int, input().strip().split())
def pows(x, r):
ps = [1]
while ps[-1] * x < r:
ps.append(ps[-1] * x)
return ps
px = pows(x, r)
py = pows(y, r)
nothappy = [l - 1, r + 1]
for ppx in px:
for ppy in py:
if l <= ppx + ppy <= r:
nothappy.append(ppx + ppy)
notha... | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,684,862,431 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x,y=map(int,input().split())
c=x
n=1
while True:
print(str(x),str(y))
if str(x)[-1]==str(y):
print(n)
break
else:
n+=1
x+=c | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
x,y=map(int,input().split())
c=x
n=1
while True:
print(str(x),str(y))
if str(x)[-1]==str(y):
print(n)
break
else:
n+=1
x+=c
``` | 0 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,697,173,580 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 61 | 102,400 | N = int(input())
s = str(input())
sum1 = 0;sum2=0;
for i in range(N):
if s[i] =='A':
sum1+=1
elif s[i] =='D':
sum2+=1
if sum1>sum2:
print('Anton')
elif(sum1<sum2):
print("Danik")
else:
print("Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
N = int(input())
s = str(input())
sum1 = 0;sum2=0;
for i in range(N):
if s[i] =='A':
sum1+=1
elif s[i] =='D':
sum2+=1
if sum1>sum2:
print('Anton')
elif(sum1<sum2):
print("Danik")
else:
print("Friendship")
``` | 3 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,690,897,952 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 248 | 0 | import math
n = int(input())
primes = [True] * (n + 1)
primes[0] = primes[1] = False
for k in range(2, int(math.sqrt(n)) + 1):
if primes[k]:
for m in range(2 * k, n + 1, k):
primes[m] = False
primesVector = [k for k in range(2, n + 1) if primes[k]]
almostPrimeCount = 0
for k in ran... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
import math
n = int(input())
primes = [True] * (n + 1)
primes[0] = primes[1] = False
for k in range(2, int(math.sqrt(n)) + 1):
if primes[k]:
for m in range(2 * k, n + 1, k):
primes[m] = False
primesVector = [k for k in range(2, n + 1) if primes[k]]
almostPrimeCount = 0
fo... | 3.938 |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,621,347,787 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 109 | 0 | x=[]
for i in range(4):
x.append(input())
for i in range(1,3):
for j in range(1,3):
if (x[i][j]==x[i][j-1]) and (x[i][j]== x[i-1][j] or x[i][j]==x[i+1][j] or x[i][j]==x[i-1][j-1] or x[i][j]==x[i+1][j-1]):
print('YES')
exit()
elif (x[i][j]==x[i][j+1]) and (x[i][j... | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
x=[]
for i in range(4):
x.append(input())
for i in range(1,3):
for j in range(1,3):
if (x[i][j]==x[i][j-1]) and (x[i][j]== x[i-1][j] or x[i][j]==x[i+1][j] or x[i][j]==x[i-1][j-1] or x[i][j]==x[i+1][j-1]):
print('YES')
exit()
elif (x[i][j]==x[i][j+1]) a... | 3 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,621,076,124 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 154 | 0 | n= int(input())
j=0
num =0
for i in range(1,n+1):
if i%2==0:
j+=1
# print(2)
if i%3==0:
j+=1
#print(3)
if i%7==0:
j+=1
#print(7)
if i%5==0:
j+=1
# print(5)
if j==2:
num+=1
j=0
print(num) | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
n= int(input())
j=0
num =0
for i in range(1,n+1):
if i%2==0:
j+=1
# print(2)
if i%3==0:
j+=1
#print(3)
if i%7==0:
j+=1
#print(7)
if i%5==0:
j+=1
# print(5)
if j==2:
num+=1
j=0
print(num... | 0 |
524 | B | Фото на память - 2 (round version) | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | Прошло много лет, и на вечеринке снова встретились *n* друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можн... | В первой строке следует целое число *n* (1<=≤<=*n*<=≤<=1000) — количество друзей.
В последующих *n* строках следуют по два целых числа *w**i*,<=*h**i* (1<=≤<=*w**i*,<=*h**i*<=≤<=1000), обозначающие размеры прямоугольника, соответствующего *i*-му из друзей. | Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей. | [
"3\n10 1\n20 2\n30 3\n",
"3\n3 1\n2 2\n4 3\n",
"1\n5 10\n"
] | [
"180\n",
"21\n",
"50\n"
] | none | 500 | [
{
"input": "3\n10 1\n20 2\n30 3",
"output": "180"
},
{
"input": "3\n3 1\n2 2\n4 3",
"output": "21"
},
{
"input": "1\n5 10",
"output": "50"
},
{
"input": "10\n168 538\n836 439\n190 873\n206 47\n891 591\n939 481\n399 898\n859 466\n701 777\n629 222",
"output": "3478056"
},... | 1,426,952,562 | 6,162 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 31 | 0 | n = int(input())
ar = []
for i in range(n):
a, b = map(int, input().split())
if b > a:
a, b = b, a
ar.append((a, b))
l = 0
hmin = 0
for i in ar:
hmin = max(hmin, min(i[0], i[1]))
s = 10000000000000
for h in range(hmin, 1001):
for i in ar:
if i[0] > h:
l += ... | Title: Фото на память - 2 (round version)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Прошло много лет, и на вечеринке снова встретились *n* друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из дру... | ```python
n = int(input())
ar = []
for i in range(n):
a, b = map(int, input().split())
if b > a:
a, b = b, a
ar.append((a, b))
l = 0
hmin = 0
for i in ar:
hmin = max(hmin, min(i[0], i[1]))
s = 10000000000000
for h in range(hmin, 1001):
for i in ar:
if i[0] > h:
... | 0 | |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,500,642,937 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 4,608,000 | n = input().strip()
if n[0]!= '-':
if len(n) > 1:
if int(n[-1]) < 8:
print(8 - int(n[-1]))
elif int(n[-2]) == 7:
print(10 - int(n[-1]))
else:
print(18 - int(n[-1]))
else:
if int(n) >= 8:
print(18 - int(n))
else:
... | Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
n = input().strip()
if n[0]!= '-':
if len(n) > 1:
if int(n[-1]) < 8:
print(8 - int(n[-1]))
elif int(n[-2]) == 7:
print(10 - int(n[-1]))
else:
print(18 - int(n[-1]))
else:
if int(n) >= 8:
print(18 - int(n))
... | 0 | |
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,760,540 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 124 | 0 | s=input()
if s[0].islower():
s=s[0].upper()+s[1:]
print(s)
| 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()
if s[0].islower():
s=s[0].upper()+s[1:]
print(s)
``` | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,693,326,712 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 62 | 0 | k, r = map(int, input().split())
i = 1
while 0 != i * k % 10 != r:
i += 1
print(i)
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k, r = map(int, input().split())
i = 1
while 0 != i * k % 10 != r:
i += 1
print(i)
``` | 3 | |
414 | A | Mashmokh and Numbers | PROGRAMMING | 1,500 | [
"constructive algorithms",
"number theory"
] | null | null | It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he r... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 0<=≤<=*k*<=≤<=108). | If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | [
"5 2\n",
"5 3",
"7 2\n"
] | [
"1 2 3 4 5\n",
"2 4 3 7 1",
"-1\n"
] | *gcd*(*x*, *y*) is greatest common divisor of *x* and *y*. | 500 | [
{
"input": "5 2",
"output": "1 2 3 4 5"
},
{
"input": "5 3",
"output": "2 4 5 6 7"
},
{
"input": "7 2",
"output": "-1"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "2 0",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input"... | 1,609,026,170 | 2,147,483,647 | PyPy 3 | OK | TESTS | 84 | 296 | 8,396,800 | t = input().split()
n = int(t[0])
k = int(t[1])
somas = n//2
if (k < somas or (n == 1 and k != 0)):
print(-1)
elif(n == 1 and k == 0):
print(1)
else:
t1 = k - (n-2)//2
t2 = 2*t1
print(t1, t2, end = ' ')
ini = t2
for i in range(n-2):
ini = ini+1
print(ini, end = ' ')
... | Title: Mashmokh and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. ... | ```python
t = input().split()
n = int(t[0])
k = int(t[1])
somas = n//2
if (k < somas or (n == 1 and k != 0)):
print(-1)
elif(n == 1 and k == 0):
print(1)
else:
t1 = k - (n-2)//2
t2 = 2*t1
print(t1, t2, end = ' ')
ini = t2
for i in range(n-2):
ini = ini+1
print(ini, end... | 3 | |
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,676,047,235 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 69 | 62 | 0 | n=int(input())
sm=0
sc=0
for i in range(1,n+1):
g=input().split()
if int(g[0])>int(g[1]):
sm+=1
if int(g[0])<int(g[1]):
sc+=1
if sm==sc:
print('Friendship is magic!^^')
if sm>sc:
print('Mishka')
if sm<sc:
print('Chris')
| 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())
sm=0
sc=0
for i in range(1,n+1):
g=input().split()
if int(g[0])>int(g[1]):
sm+=1
if int(g[0])<int(g[1]):
sc+=1
if sm==sc:
print('Friendship is magic!^^')
if sm>sc:
print('Mishka')
if sm<sc:
print('Chris')
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,569,644,658 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | s=input()
#print(s)
cn="hello"
c=""
n=0
for i in range(0,len(s)):
if s[i] in cn and s[i] not in c:
c=c+s[i]
if s[i]=='l':
n+=1
elif s[i]=='l' and n<2 :
n+=1
c=c+s[i]
if(c=="hello"):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
#print(s)
cn="hello"
c=""
n=0
for i in range(0,len(s)):
if s[i] in cn and s[i] not in c:
c=c+s[i]
if s[i]=='l':
n+=1
elif s[i]=='l' and n<2 :
n+=1
c=c+s[i]
if(c=="hello"):
print("YES")
else:
print("NO")
``` | 0 |
788 | A | Functions again | PROGRAMMING | 1,600 | [
"dp",
"two pointers"
] | null | null | Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (-109<=≤<=*a**i*<=≤<=109) — the array elements. | Print the only integer — the maximum value of *f*. | [
"5\n1 4 2 3 1\n",
"4\n1 5 4 7\n"
] | [
"3",
"6"
] | In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of *f* is reachable only on the whole array. | 500 | [
{
"input": "5\n1 4 2 3 1",
"output": "3"
},
{
"input": "4\n1 5 4 7",
"output": "6"
},
{
"input": "8\n16 14 12 10 8 100 50 0",
"output": "92"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -4... | 1,583,902,912 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 139 | 0 | n=int(input())
l=list(map(int,input().split()))
a=[0]*(n-1)
for i in range(n-1):
a[i]=abs(l[i]-l[i+1])*(-1)**i
ans=a[0]
cur=a[0]
for i in range(1,n-1):
cur=max(abs(cur+a[i]),abs(a[i]))
ans=max(ans,cur)
print(ans) | Title: Functions again
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found t... | ```python
n=int(input())
l=list(map(int,input().split()))
a=[0]*(n-1)
for i in range(n-1):
a[i]=abs(l[i]-l[i+1])*(-1)**i
ans=a[0]
cur=a[0]
for i in range(1,n-1):
cur=max(abs(cur+a[i]),abs(a[i]))
ans=max(ans,cur)
print(ans)
``` | 0 | |
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters e... | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "Y... | 1,672,821,980 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 312 | 1,024,000 | len_of_road, max_jump = (int(x) for x in input().split())
road = input()
i = 0
while i < len_of_road:
if road[i] == '.':
current_jump = 0
else:
if current_jump < max_jump - 1:
current_jump += 1
else:
print('NO')
break
i += 1
else:
print('YES') | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to t... | ```python
len_of_road, max_jump = (int(x) for x in input().split())
road = input()
i = 0
while i < len_of_road:
if road[i] == '.':
current_jump = 0
else:
if current_jump < max_jump - 1:
current_jump += 1
else:
print('NO')
break
i += 1
else:
print('YES')
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on.
During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. T... | The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018). | Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9.
Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if . | [
"3 2 6\n",
"4 2 20\n"
] | [
"6.5\n",
"20.0\n"
] | In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be coo... | 0 | [
{
"input": "3 2 6",
"output": "6.5"
},
{
"input": "4 2 20",
"output": "20.0"
},
{
"input": "8 10 9",
"output": "10.0"
},
{
"input": "43 50 140",
"output": "150.5"
},
{
"input": "251 79 76",
"output": "76.0"
},
{
"input": "892 67 1000",
"output": "1... | 1,522,060,232 | 6,932 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 21,401,600 | run,vis,cook = map(int,input().split())
cir=(run+vis-1)//vis;
print(cir)
cirt=int(cir)*vis;
circ=(run+cirt);
ans=(int(2)*int(cook))//int(circ)*int(cirt);
print(ans)
rest=(2*cook)%(run+cir*vis);
if(2*run>=rest):
dans=ans+rest/2.0;
else:
dans=ans+run+(rest-2*run);
print(dans)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on.
During cooking, Julia goes to the kitchen every *d* minutes an... | ```python
run,vis,cook = map(int,input().split())
cir=(run+vis-1)//vis;
print(cir)
cirt=int(cir)*vis;
circ=(run+cirt);
ans=(int(2)*int(cook))//int(circ)*int(cirt);
print(ans)
rest=(2*cook)%(run+cir*vis);
if(2*run>=rest):
dans=ans+rest/2.0;
else:
dans=ans+run+(rest-2*run);
print(dans)
``` | 0 | |
853 | B | Jury Meeting | PROGRAMMING | 1,800 | [
"greedy",
"sortings",
"two pointers"
] | null | null | Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are *n*<=+<=1 cities consecutively numbered from 0 to *n*. City 0 is Metropolis that is the meeting poi... | The first line of input contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*m*<=≤<=105, 1<=≤<=*k*<=≤<=106).
The *i*-th of the following *m* lines contains the description of the *i*-th flight defined by four integers *d**i*, *f**i*, *t**i* and *c**i* (1<=≤<=*d**i*<=≤<=106, 0<=≤<=*f**i*<=≤<=*n*, 0<=≤<=... | Output the only integer that is the minimum cost of gathering all jury members in city 0 for *k* days and then sending them back to their home cities.
If it is impossible to gather everybody in Metropolis for *k* days and then send them back to their home cities, output "-1" (without the quotes). | [
"2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n",
"2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n"
] | [
"24500\n",
"-1\n"
] | The optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days 1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day 15, that would cost 2500 more.
In the second sample it is impossible to send jury member from city 2 b... | 750 | [
{
"input": "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500",
"output": "24500"
},
{
"input": "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000",
"output": "-1"
},
{
"input": "2 5 5\n1 1 0 1\n2 2 0 100\n3 2 0 10\n9 0 1 1000\n10 0 2 10000",
"output"... | 1,590,307,302 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 19,148,800 | import sys
import math
from collections import defaultdict,deque
def find(arr,day):
#print(arr,'arr',day,'day')
low = 0
high = len(arr) - 1
ans = -1
#print(high,'high',low,'low')
while (low <= high):
mid = (low + high) // 2
#print(mid,'mid')
if arr[mid][0] <= day:
ans = arr[mid][1]
low =... | Title: Jury Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are *... | ```python
import sys
import math
from collections import defaultdict,deque
def find(arr,day):
#print(arr,'arr',day,'day')
low = 0
high = len(arr) - 1
ans = -1
#print(high,'high',low,'low')
while (low <= high):
mid = (low + high) // 2
#print(mid,'mid')
if arr[mid][0] <= day:
ans = arr[mid][1]... | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,668,857,033 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 19 16:46:38 2022
@author: calvinzhu
"""
n = int(input())
arr = [int(x) for x in input().split(" ")]
top = max(arr)
arr.sort()
distinct=[0]*(top+1)
dp = [0]*(top+1)
cnt=1
for i in range(1,n):
if arr[i-1]==arr[i]:
cnt+=1
else:
... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 19 16:46:38 2022
@author: calvinzhu
"""
n = int(input())
arr = [int(x) for x in input().split(" ")]
top = max(arr)
arr.sort()
distinct=[0]*(top+1)
dp = [0]*(top+1)
cnt=1
for i in range(1,n):
if arr[i-1]==arr[i]:
cnt+=1
... | 0 | |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,618,926,716 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 61 | 0 | n,k =map(int,input().split())
s = int(str(n))
c=0
v=0
while(n%5==0):
n=n//5
c+=1
while(n%2==0):
n=n//2
v+=1
d = min(v,c)
if(d>=k):
print(s)
else:
s = n*(10**(k-d))
print(s)
| Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000.... | ```python
n,k =map(int,input().split())
s = int(str(n))
c=0
v=0
while(n%5==0):
n=n//5
c+=1
while(n%2==0):
n=n//2
v+=1
d = min(v,c)
if(d>=k):
print(s)
else:
s = n*(10**(k-d))
print(s)
``` | 0 | |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,536,516,133 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 124 | 0 | s=input()
l=sorted(s)
print("YES" if( (s.count("a")>=1 and s.count("b")>=1) and (s.count("c")==s.count("a") or s.count("c")==s.count("b")) and (s==''.join(l))) else "NO")
| Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
s=input()
l=sorted(s)
print("YES" if( (s.count("a")>=1 and s.count("b")>=1) and (s.count("c")==s.count("a") or s.count("c")==s.count("b")) and (s==''.join(l))) else "NO")
``` | 3 | |
215 | B | Olympic Medal | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/... | The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta... | Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists. | [
"3 1 2 3\n1 2\n3 3 2 1\n1 2\n",
"4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n"
] | [
"2.683281573000\n",
"2.267786838055\n"
] | In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1. | 500 | [
{
"input": "3 1 2 3\n1 2\n3 3 2 1\n1 2",
"output": "2.683281573000"
},
{
"input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1",
"output": "2.267786838055"
},
{
"input": "1 5\n1 3\n1 7\n515 892",
"output": "3.263613058533"
},
{
"input": "2 3 2\n3 2 3 1\n2 2 1\n733 883",
"output": "2.... | 1,619,107,032 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 216 | 1,945,600 | import math
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = list(map(int, input().split()))
A, B = map(int, input().split())
calc = (B*max(y[1:])*(max(x[1:]))**2)/((A*min(z[1:]))+B*max(y[1:]))
print(math.sqrt(calc))
| Title: Olympic Medal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/... | ```python
import math
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = list(map(int, input().split()))
A, B = map(int, input().split())
calc = (B*max(y[1:])*(max(x[1:]))**2)/((A*min(z[1:]))+B*max(y[1:]))
print(math.sqrt(calc))
``` | 3 | |
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -... | 1,500,809,601 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | n = int(input())
string = input()
numbers = list(map(int, string.split()))
print(numbers[n // 2]) | Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=... | ```python
n = int(input())
string = input()
numbers = list(map(int, string.split()))
print(numbers[n // 2])
``` | 0 | |
612 | E | Square Root of Permutation | PROGRAMMING | 2,200 | [
"combinatorics",
"constructive algorithms",
"dfs and similar",
"graphs",
"math"
] | null | null | A permutation of length *n* is an array containing each integer from 1 to *n* exactly once. For example, *q*<==<=[4,<=5,<=1,<=2,<=3] is a permutation. For the permutation *q* the square of permutation is the permutation *p* that *p*[*i*]<==<=*q*[*q*[*i*]] for each *i*<==<=1... *n*. For example, the square of *q*<==<=[4... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in permutation *p*.
The second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of permutation *p*. | If there is no permutation *q* such that *q*2<==<=*p* print the number "-1".
If the answer exists print it. The only line should contain *n* different integers *q**i* (1<=≤<=*q**i*<=≤<=*n*) — the elements of the permutation *q*. If there are several solutions print any of them. | [
"4\n2 1 4 3\n",
"4\n2 1 3 4\n",
"5\n2 3 4 5 1\n"
] | [
"3 4 2 1\n",
"-1\n",
"4 5 1 2 3\n"
] | none | 0 | [
{
"input": "4\n2 1 4 3",
"output": "3 4 2 1"
},
{
"input": "4\n2 1 3 4",
"output": "-1"
},
{
"input": "5\n2 3 4 5 1",
"output": "4 5 1 2 3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5"... | 1,662,277,163 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 841 | 144,896,000 | import sys
from collections import defaultdict
readline=sys.stdin.readline
N=int(readline())
P=list(map(int,readline().split()))
for x in range(N):
P[x]-=1
perm=[]
seen=[False]*N
for x in range(N):
if seen[x]:
continue
perm.append([])
perm[-1].append(x)
seen[x]=True
whil... | Title: Square Root of Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an array containing each integer from 1 to *n* exactly once. For example, *q*<==<=[4,<=5,<=1,<=2,<=3] is a permutation. For the permutation *q* the square of permutation is the ... | ```python
import sys
from collections import defaultdict
readline=sys.stdin.readline
N=int(readline())
P=list(map(int,readline().split()))
for x in range(N):
P[x]-=1
perm=[]
seen=[False]*N
for x in range(N):
if seen[x]:
continue
perm.append([])
perm[-1].append(x)
seen[x]=True... | 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,606,190,263 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 186 | 307,200 | m, n, x, y = map(int,input().split())
indicate = list(map(int,input().split()))
vest = list(map(int,input().split()))
i = j = 0
count = 0
ans = []
while i < m and j < n:
if (vest[j] >= indicate[i] - x) and (vest[j] <= indicate[i] + y):
count += 1
ans.append([i+1,j+1])
j += 1
... | 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
m, n, x, y = map(int,input().split())
indicate = list(map(int,input().split()))
vest = list(map(int,input().split()))
i = j = 0
count = 0
ans = []
while i < m and j < n:
if (vest[j] >= indicate[i] - x) and (vest[j] <= indicate[i] + y):
count += 1
ans.append([i+1,j+1])
j +... | 0 | |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,643,550,987 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | s=input()
s1=s[::-1]
c=0
for i in range (len(s)):
if s[i]!=s1[i]:
c=c+1
if c>2:
print('NO')
elif c == 0:
# if len(s)%2 == 0:
print('NO')
# else:
# print('YES')
else:
print('YES') | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
s=input()
s1=s[::-1]
c=0
for i in range (len(s)):
if s[i]!=s1[i]:
c=c+1
if c>2:
print('NO')
elif c == 0:
# if len(s)%2 == 0:
print('NO')
# else:
# print('YES')
else:
print('YES')
``` | 0 | |
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str... | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"i... | 1,643,266,549 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | x=input()
while x[-1]=='0':
x=x[0:-1]
if x[::-1]==x:print('YES')
else:print('NO') | Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from righ... | ```python
x=input()
while x[-1]=='0':
x=x[0:-1]
if x[::-1]==x:print('YES')
else:print('NO')
``` | 3 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,591,278,530 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 9 | 436 | 2,252,800 | s=input()
i=s.index('0')
print(s[:i]+s[i+1:]) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s=input()
i=s.index('0')
print(s[:i]+s[i+1:])
``` | -1 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,698,849,748 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, k = map(int, input().split())
y = list(map(int, input().split()))
y1 = []
for i in y:
if i <= 5 - k:
y1.append(i)
print(len(y1)//3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
y = list(map(int, input().split()))
y1 = []
for i in y:
if i <= 5 - k:
y1.append(i)
print(len(y1)//3)
``` | 3 | |
686 | B | Little Robber Girl's Zoo | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
The robber girl was angry at first, but then she decided to arrange the animals herself. She ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — number of animals in the robber girl's zoo.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the height of the animal occupying the *i*-th place. | Print the sequence of operations that will rearrange the animals by non-decreasing height.
The output should contain several lines, *i*-th of the lines should contain two space-separated integers *l**i* and *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*) — descriptions of segments the robber girl should name. The segments... | [
"4\n2 1 4 3\n",
"7\n36 28 57 39 66 69 68\n",
"5\n1 2 1 2 1\n"
] | [
"1 4\n",
"1 4\n6 7\n",
"2 5\n3 4\n1 4\n1 4\n"
] | Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed. | 1,000 | [
{
"input": "4\n2 1 4 3",
"output": "1 2\n3 4"
},
{
"input": "7\n36 28 57 39 66 69 68",
"output": "1 2\n3 4\n6 7"
},
{
"input": "5\n1 2 1 2 1",
"output": "2 3\n4 5\n3 4"
},
{
"input": "78\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38... | 1,592,436,627 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 156 | 3,993,600 | if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
for i in range(1, n):
if arr[i] < arr[i - 1]:
j = i
while j > 0 and arr[j - 1] > arr[j]:
print(j, j + 1)
tmp = arr[j - 1]
arr[j - 1] = arr[j]
... | Title: Little Robber Girl's Zoo
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in th... | ```python
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
for i in range(1, n):
if arr[i] < arr[i - 1]:
j = i
while j > 0 and arr[j - 1] > arr[j]:
print(j, j + 1)
tmp = arr[j - 1]
arr[j - 1] = ... | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,653,065,481 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 31 | 0 | n=int(input())
arr=list(map(int,input().split()))
max1=max(arr)
res=0
for i in arr:
if i==max1:
arr.remove(i)
for i in arr:
res+=max1-i
print(res) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n=int(input())
arr=list(map(int,input().split()))
max1=max(arr)
res=0
for i in arr:
if i==max1:
arr.remove(i)
for i in arr:
res+=max1-i
print(res)
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,641,579,301 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 186 | 0 | n=int(input())
l=list(map(int,input().split()))
count=0
totalsum=sum(l)
j=n+1
for i in range(1,6):
if (totalsum+i)%j!=1:
count+=1
print(count) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n=int(input())
l=list(map(int,input().split()))
count=0
totalsum=sum(l)
j=n+1
for i in range(1,6):
if (totalsum+i)%j!=1:
count+=1
print(count)
``` | 3 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,691,694,548 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 109 | 13,619,200 | def maxPoints(n, a):
freq = [0] * (max(a) + 2)
for num in a:
freq[num] += 1
points = [0] * (max(a) + 2)
points[1] = freq[1]
for i in range(2, max(a) + 2):
points[i] = max(points[i - 1], points[i - 2] + i * freq[i])
return points[max(a) + 1]
# Read input
... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
def maxPoints(n, a):
freq = [0] * (max(a) + 2)
for num in a:
freq[num] += 1
points = [0] * (max(a) + 2)
points[1] = freq[1]
for i in range(2, max(a) + 2):
points[i] = max(points[i - 1], points[i - 2] + i * freq[i])
return points[max(a) + 1]
# Re... | 3 | |
81 | B | Sequence Formatting | PROGRAMMING | 1,700 | [
"implementation",
"strings"
] | B. Sequence Formatting | 2 | 256 | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string *s*. Its length is from 1 to 255 characters. The string *s* does not begin and end with a space. Its content matches the description given above. | Print the string *s* after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | [
"1,2 ,3,..., 10\n",
"1,,,4...5......6\n",
"...,1,2,3,...\n"
] | [
"1, 2, 3, ..., 10\n",
"1, , , 4 ...5 ... ...6\n",
"..., 1, 2, 3, ...\n"
] | none | 1,000 | [
{
"input": "1,2 ,3,..., 10",
"output": "1, 2, 3, ..., 10"
},
{
"input": "1,,,4...5......6",
"output": "1, , , 4 ...5 ... ...6"
},
{
"input": ",,,,,,,,,,,,,",
"output": ", , , , , , , , , , , , ,"
},
{
"input": "123456789",
"output": "123456789"
},
{
"input": "... | 1,653,784,026 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 124 | 512,000 | s = input()
lst = []
i = 0
while i < len(s):
if s[i].isdigit():
num = ''
while i < len(s) and s[i].isdigit():
num += s[i]
i += 1
lst.append(num)
continue
if s[i] == '.':
lst.append('...')
i += 2
elif s[i] != ' ':
... | Title: Sequence Formatting
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he ... | ```python
s = input()
lst = []
i = 0
while i < len(s):
if s[i].isdigit():
num = ''
while i < len(s) and s[i].isdigit():
num += s[i]
i += 1
lst.append(num)
continue
if s[i] == '.':
lst.append('...')
i += 2
elif s[i] != ' ':... | 3.968046 |
55 | B | Smallest number | PROGRAMMING | 1,600 | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced... | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | 1,000 | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3... | 1,598,014,332 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 310 | 20,172,800 | ar=list(map(int,input().split()))
br=input().split()
ans=float('inf')
def gen(ar,ind):
global ans
if(len(ar)==1):
ans=min(ans,ar[0])
return
for i in range(len(ar)):
for j in range(i):
nw=ar.copy()
vl=ar[i]+ar[j] if br[ind]=='+'else ar[i]*ar[j]
... | Title: Smallest number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the n... | ```python
ar=list(map(int,input().split()))
br=input().split()
ans=float('inf')
def gen(ar,ind):
global ans
if(len(ar)==1):
ans=min(ans,ar[0])
return
for i in range(len(ar)):
for j in range(i):
nw=ar.copy()
vl=ar[i]+ar[j] if br[ind]=='+'else ar[i]*a... | 3.884925 |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"... | 1,694,347,770 | 2,147,483,647 | Python 3 | OK | TESTS | 114 | 46 | 0 | n,k=map(int,input().split())
S=input()
a=list(map(str,str(S)))
c={}
for i in a:
c.setdefault(i,0)
if i in c:
c[i]+=1
count=0
for i in c:
if c[i]<=k:
pass
else:
count+=1
if count==0:
print("YES")
else:
print("NO") | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo... | ```python
n,k=map(int,input().split())
S=input()
a=list(map(str,str(S)))
c={}
for i in a:
c.setdefault(i,0)
if i in c:
c[i]+=1
count=0
for i in c:
if c[i]<=k:
pass
else:
count+=1
if count==0:
print("YES")
else:
print("NO")
``` | 3 | |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,695,537,686 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 78 | 0 | n,x = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
if x in a:
for i in range(x+1):
if i == x and i in a:
ans += 1
elif i not in a:
ans += 1
else:
for i in range(x):
if i not in a:
ans += 1
print(ans) | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
n,x = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
if x in a:
for i in range(x+1):
if i == x and i in a:
ans += 1
elif i not in a:
ans += 1
else:
for i in range(x):
if i not in a:
ans += 1
print(ans)
``` | 3 | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,676,905,203 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 51 | 154 | 0 | def check(numbers):
possibilities = list(range(1, 10))
for i in numbers:
if i in possibilities:
possibilities.remove(i)
else:
return False
return True
r1, r2 = [int(x) for x in input().split()]
c1, c2 = [int(x) for x in input().split()]
d1, d2 = [int(x) ... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
def check(numbers):
possibilities = list(range(1, 10))
for i in numbers:
if i in possibilities:
possibilities.remove(i)
else:
return False
return True
r1, r2 = [int(x) for x in input().split()]
c1, c2 = [int(x) for x in input().split()]
d1, d2 ... | 0 | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,627,569,192 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 171 | 21,094,400 | def fun(A,n,B):
for i in range(n):
if A[i]==i+1:
pass
elif A[i]<i+1:
if B[i-1]=='0':
return 'NO'
elif A[i]>i+1:
if B[i]=='0':
return 'NO'
return 'Yes'
n=int(input())
A=list(map(int,input().split()))
B=inpu... | Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
def fun(A,n,B):
for i in range(n):
if A[i]==i+1:
pass
elif A[i]<i+1:
if B[i-1]=='0':
return 'NO'
elif A[i]>i+1:
if B[i]=='0':
return 'NO'
return 'Yes'
n=int(input())
A=list(map(int,input().split()... | 0 | |
886 | C | Petya and Catacombs | PROGRAMMING | 1,300 | [
"dsu",
"greedy",
"implementation",
"trees"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 1,500 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 ... | 1,510,507,571 | 4,871 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 61 | 716,800 | n = int(input())
t = [int(x) for x in input().split()]
ans = 0
used = [-1] * (2 * 10 ** 5 + 13)
realtimes = [i for i in range(n)]
for i in range(n):
if t[i] < i - 1 and realtimes[t[i]] == t[i]:
realtimes[t[i]] = i
used[t[i]] = True
else:
ans += 1
print(ans) | Title: Petya and Catacombs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectiona... | ```python
n = int(input())
t = [int(x) for x in input().split()]
ans = 0
used = [-1] * (2 * 10 ** 5 + 13)
realtimes = [i for i in range(n)]
for i in range(n):
if t[i] < i - 1 and realtimes[t[i]] == t[i]:
realtimes[t[i]] = i
used[t[i]] = True
else:
ans += 1
print(ans)
``` | 0 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,577,355,245 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | a, b, c, d = sorted(map(int, input().split()))
x = min(d - b - c, c - a - b)
print(x)
if x>0:
print("TRIANGlE")
elif x<0:
print("IMPOSIBLE")
else:
print("SEGMENT") | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
a, b, c, d = sorted(map(int, input().split()))
x = min(d - b - c, c - a - b)
print(x)
if x>0:
print("TRIANGlE")
elif x<0:
print("IMPOSIBLE")
else:
print("SEGMENT")
``` | 0 |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,684,523,937 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | resp = 0
size, count = 0, 0
size = int(input())
array = [0] * (size + 9)
i = 1
while i <= size:
array[i] = int(input())
i += 1
for i in range(1, size + 1):
count = 0
atual = array[i]
while atual != -1:
atual = array[atual]
count += 1
resp += count
print(resp + 1)
... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
resp = 0
size, count = 0, 0
size = int(input())
array = [0] * (size + 9)
i = 1
while i <= size:
array[i] = int(input())
i += 1
for i in range(1, size + 1):
count = 0
atual = array[i]
while atual != -1:
atual = array[atual]
count += 1
resp += count
print(resp + 1)
... | 0 | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,596,804,980 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 6,656,000 | n,m=map(int,input().split(' '))
j=1
sum1=m
while j<7:
for i in range(1,n+1):
sum1=sum1-i
if sum1<0:
sum1=sum1+i
print(sum1)
j=7
break
elif sum1==0:
print(0)
j=7
break
else:
... | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n,m=map(int,input().split(' '))
j=1
sum1=m
while j<7:
for i in range(1,n+1):
sum1=sum1-i
if sum1<0:
sum1=sum1+i
print(sum1)
j=7
break
elif sum1==0:
print(0)
j=7
break
else:
... | 0 |
120 | E | Put Knight! | PROGRAMMING | 1,400 | [
"games",
"math"
] | null | null | Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (*r*,<=*c*) can threat squares (*r*<=-<=1,<=*c*<=+<=2), (*r*<=-<=1,<=... | The first line contains integer *T* (1<=≤<=*T*<=≤<=100) — the number of boards, for which you should determine the winning player. Next *T* lines contain *T* integers *n**i* (1<=≤<=*n**i*<=≤<=10000) — the sizes of the chessboards. | For each *n**i*<=×<=*n**i* board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1". | [
"2\n2\n1\n"
] | [
"1\n0\n"
] | none | 0 | [
{
"input": "2\n2\n1",
"output": "1\n0"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "0\n1\n0\n1\n0\n1\n0\n1\n0\n1"
},
{
"input": "15\n10\n4\n7\n8\n9\n6\n2\n1\n3\n1\n5\n2\n3\n4\n5",
"output": "1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0"
},
{
"input": "6\n10\n7... | 1,695,975,995 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | for i in range(int(input())):
print(0 if int(input())%2==1 else 1) | Title: Put Knight!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other.... | ```python
for i in range(int(input())):
print(0 if int(input())%2==1 else 1)
``` | -1 | |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,639,966,026 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | n = int(input())
m = int(input())
def expo(x):
ans = 1
res = 2
while x > 1:
if x%2 == 0:
x /= 2
res *= res
else:
x -= 1
ans *= 2
return ans*res
print(m%expo(n) if n< 27 else m) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
n = int(input())
m = int(input())
def expo(x):
ans = 1
res = 2
while x > 1:
if x%2 == 0:
x /= 2
res *= res
else:
x -= 1
ans *= 2
return ans*res
print(m%expo(n) if n< 27 else m)
``` | 0 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,679,108,187 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n = int(input())
s = input()
count = 0
i = 0
while i < n-2:
if s[i:i+3] == 'xxx':
count += 1
i += 2
else:
i += 1
print(count) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
n = int(input())
s = input()
count = 0
i = 0
while i < n-2:
if s[i:i+3] == 'xxx':
count += 1
i += 2
else:
i += 1
print(count)
``` | 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,674,121,794 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 62 | 0 | l=[int(x) for x in input().split()]
print(max(l)-min(l)) | 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
l=[int(x) for x in input().split()]
print(max(l)-min(l))
``` | 3 | |
985 | B | Switches and Lamps | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps.
The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise.
It is guar... | Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. | [
"4 5\n10101\n01000\n00111\n10000\n",
"4 5\n10100\n01000\n00110\n00101\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "4 5\n10101\n01000\n00111\n10000",
"output": "YES"
},
{
"input": "4 5\n10100\n01000\n00110\n00101",
"output": "NO"
},
{
"input": "1 5\n11111",
"output": "NO"
},
{
"input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1",
"output": "YES"
},
{
"input": "1 1\n1",
... | 1,527,592,217 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
int n,m,sum[2010],s[2010][2010];
char c;
int main()
{
cin>>n>>m;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
cin>>c;
s[i][j]=c-'0';
if(s[i][j]) sum[j]+=1;
}
int j;
for(int i=0; i<n... | Title: Switches and Lamps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th... | ```python
#include<bits/stdc++.h>
using namespace std;
int n,m,sum[2010],s[2010][2010];
char c;
int main()
{
cin>>n>>m;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
cin>>c;
s[i][j]=c-'0';
if(s[i][j]) sum[j]+=1;
}
int j;
for(in... | -1 | |
195 | B | After Training | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly... | The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly. | Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. | [
"4 3\n",
"3 1\n"
] | [
"2\n1\n3\n2\n",
"1\n1\n1\n"
] | none | 1,000 | [
{
"input": "4 3",
"output": "2\n1\n3\n2"
},
{
"input": "3 1",
"output": "1\n1\n1"
},
{
"input": "10 3",
"output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2"
},
{
"input": "6 5",
"output": "3\n2\n4\n1\n5\n3"
},
{
"input": "2 6",
"output": "3\n4"
},
{
"input": "5 2"... | 1,613,825,161 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 560 | 307,200 | n,m=list(map(int,input().split(" ")))
if m%2!=0:
mid=int((m+1)/2)
i = mid
j = mid
else:
mid=int((m/2))
i = mid
j = mid+1
detector=1
if m==1:
for x in range(n):
print(1)
else:
for _ in range(n):
if i==j:
print(mid)
i-=... | Title: After Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are posi... | ```python
n,m=list(map(int,input().split(" ")))
if m%2!=0:
mid=int((m+1)/2)
i = mid
j = mid
else:
mid=int((m/2))
i = mid
j = mid+1
detector=1
if m==1:
for x in range(n):
print(1)
else:
for _ in range(n):
if i==j:
print(mid)
... | 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,680,475,565 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | a=input()
b=input()
s=""
for i in range(len(a)-1,-1,-1):
s+=a[i]
if b==s:
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()
s=""
for i in range(len(a)-1,-1,-1):
s+=a[i]
if b==s:
print("YES")
else:
print("NO")
``` | 3.977 |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,691,090,471 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 500 | 5,324,800 | n=int(input())
print((5 ** n) % 100) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
n=int(input())
print((5 ** n) % 100)
``` | 0 | |
560 | B | Gerald is into Art | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rec... | The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000. | If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes). | [
"3 2\n1 3\n2 1\n",
"5 5\n3 3\n3 3\n",
"4 2\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | That's how we can place the pictures in the first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's how we can do it in the third one.
<img class="tex-graphics" src="https://espresso.codeforces... | 1,000 | [
{
"input": "3 2\n1 3\n2 1",
"output": "YES"
},
{
"input": "5 5\n3 3\n3 3",
"output": "NO"
},
{
"input": "4 2\n2 3\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 1",
"output": "YES"
},
{
"input": "1000 1000\n999 999\n1 1000",
"output": "YES"
},
{
"in... | 1,460,983,300 | 640 | Python 3 | WRONG_ANSWER | TESTS | 78 | 62 | 5,120,000 | from math import ceil
def mp(): return map(int,input().split())
def lt(): return list(map(int,input().split()))
def pt(x): print(x)
def ip(): return input()
def it(): return int(input())
def sl(x): return [t for t in x]
def spl(x): return x.split()
def aj(liste, item): liste.append(item)
def bin(x): ret... | Title: Gerald is into Art
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board ha... | ```python
from math import ceil
def mp(): return map(int,input().split())
def lt(): return list(map(int,input().split()))
def pt(x): print(x)
def ip(): return input()
def it(): return int(input())
def sl(x): return [t for t in x]
def spl(x): return x.split()
def aj(liste, item): liste.append(item)
def bi... | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,683,914,178 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | a = []
x = int(input())
y = input()
a = y.split()
a = [int(y) for y in a]
b = []
h, d = 0, 0
for j in range(len(a)):
d = 0
for i in a:
if a[j]+1 != i and a[j]-1 != i:
d += i
b.append(d)
h = b[0]
for i in b:
if h < i:
h = i
print(h)
| Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
a = []
x = int(input())
y = input()
a = y.split()
a = [int(y) for y in a]
b = []
h, d = 0, 0
for j in range(len(a)):
d = 0
for i in a:
if a[j]+1 != i and a[j]-1 != i:
d += i
b.append(d)
h = b[0]
for i in b:
if h < i:
h = i
print(h)
``` | 0 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,633,273,397 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 6,963,200 | #problem link : https://codeforces.com/contest/16/problem/B
#time : o(n)
a,b = map(int,input().split())
z={}
for i in range(b):
x,y = map(int,input().split())
z[x] = y
z = {k: v for k, v in sorted(z.items(), key=lambda item: item[1], reverse = True)}
m = 0
n= a
for i,j in z.items() :
m += min... | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
#problem link : https://codeforces.com/contest/16/problem/B
#time : o(n)
a,b = map(int,input().split())
z={}
for i in range(b):
x,y = map(int,input().split())
z[x] = y
z = {k: v for k, v in sorted(z.items(), key=lambda item: item[1], reverse = True)}
m = 0
n= a
for i,j in z.items() :
... | 0 |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,482,658,894 | 2,194 | Python 3 | OK | TESTS | 46 | 109 | 4,608,000 | n, m, k = map(int, input().split())
if k % 2 == 0:
p = k // 2
else:
p = k // 2 + 1
if p % m == 0:
r = p // m
else:
r = p // m + 1
p %= m
if p == 0:
p = m
if k % 2 != 0:
lr = 'L'
else:
lr = 'R'
print(r, p, lr) | Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work... | ```python
n, m, k = map(int, input().split())
if k % 2 == 0:
p = k // 2
else:
p = k // 2 + 1
if p % m == 0:
r = p // m
else:
r = p // m + 1
p %= m
if p == 0:
p = m
if k % 2 != 0:
lr = 'L'
else:
lr = 'R'
print(r, p, lr)
``` | 3 | |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,678,165,174 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 187 | 8,396,800 | n = int(input())
if n<10 :
print(n*11)
else:
h = str(n)
k = h[::-1]
print(h+k) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
n = int(input())
if n<10 :
print(n*11)
else:
h = str(n)
k = h[::-1]
print(h+k)
``` | 3 | |
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
... | 1,667,923,821 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
s = input()
res = [0] * n
for i in range(n):
res[i] = s[i:] + s[:i]
print(res)
for i in range(n):
u = ''
d = (10 - int(res[i][0]))
print(d)
for j in range(n):
u += str((int(res[i][j]) + d) % 10)
print(u)
res[i] = u
print(min(res)) | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ... | ```python
n = int(input())
s = input()
res = [0] * n
for i in range(n):
res[i] = s[i:] + s[:i]
print(res)
for i in range(n):
u = ''
d = (10 - int(res[i][0]))
print(d)
for j in range(n):
u += str((int(res[i][j]) + d) % 10)
print(u)
res[i] = u
print(min(res))
``` | 0 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,688,195,410 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n=int(input())
soldiers=list(map(int,input().split()))
positions=sum(soldiers[i]>soldiers[i+1] for i in range(n-1))
swaps_needed=(positions+1)//2
print(swaps_needed) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n=int(input())
soldiers=list(map(int,input().split()))
positions=sum(soldiers[i]>soldiers[i+1] for i in range(n-1))
swaps_needed=(positions+1)//2
print(swaps_needed)
``` | 0 | |
264 | B | Good Sequences | PROGRAMMING | 1,500 | [
"dp",
"number theory"
] | null | null | Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions:
- The sequence is strictly increas... | The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=<<=*a**i*<=+<=1). | Print a single integer — the length of the longest good sequence. | [
"5\n2 3 4 6 9\n",
"9\n1 2 3 5 6 7 8 9 10\n"
] | [
"4\n",
"4\n"
] | In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4. | 1,000 | [
{
"input": "5\n2 3 4 6 9",
"output": "4"
},
{
"input": "9\n1 2 3 5 6 7 8 9 10",
"output": "4"
},
{
"input": "4\n1 2 4 6",
"output": "3"
},
{
"input": "7\n1 2 3 4 7 9 10",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "8\n3 4 5 6 7 8 9... | 1,574,112,339 | 2,147,483,647 | PyPy 3 | OK | TESTS | 86 | 498 | 14,233,600 | n = int(input())
a = list(map(int, input().split()))
dp = [1] * (n + 5)
tmax = [0 for _ in range(100005)]
p = [[] for _ in range(100005)]
p[1] = [1]
for i in range(2, 100001):
if p[i]==[]:
for j in range(i, 100001, i):
p[j].append(i)
for i in range(len(a)):
dp[i] = max(tmax[j] f... | Title: Good Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k*... | ```python
n = int(input())
a = list(map(int, input().split()))
dp = [1] * (n + 5)
tmax = [0 for _ in range(100005)]
p = [[] for _ in range(100005)]
p[1] = [1]
for i in range(2, 100001):
if p[i]==[]:
for j in range(i, 100001, i):
p[j].append(i)
for i in range(len(a)):
dp[i] = max... | 3 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,693,929,138 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 102,400 | a = input()
if 'AB' in a and 'BA':
a1 = a.find('AB')
a2 = a.rfind('AB')
b1 = a.find('BA')
b2 = a.rfind('BA')
if abs(a1 - b1) > 1 or abs(a1 - b2) > 1 or abs(a2 - b1) > 1 or abs(a2 - b2) > 1:
print('YES')
else:
print('NO')
else:
print('NO') | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
a = input()
if 'AB' in a and 'BA':
a1 = a.find('AB')
a2 = a.rfind('AB')
b1 = a.find('BA')
b2 = a.rfind('BA')
if abs(a1 - b1) > 1 or abs(a1 - b2) > 1 or abs(a2 - b1) > 1 or abs(a2 - b2) > 1:
print('YES')
else:
print('NO')
else:
print('NO')
``` | 0 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,689,952,006 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | l=[]
s=""
s2=""
for i in range(3):
coins=input()
if coins[1]==">":
l.append(coins[0])
else:
l.append(coins[2])
for p in "ABC":
if p not in l:
s+=p+''
if len(set(l))==3:
print("Impossible")
else:
for o in set(l):
if l.count(o)<=1:
s+=o+... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
l=[]
s=""
s2=""
for i in range(3):
coins=input()
if coins[1]==">":
l.append(coins[0])
else:
l.append(coins[2])
for p in "ABC":
if p not in l:
s+=p+''
if len(set(l))==3:
print("Impossible")
else:
for o in set(l):
if l.count(o)<=1:
... | 3.977 |
773 | C | Prairie Partition | PROGRAMMING | 2,200 | [
"binary search",
"constructive algorithms",
"greedy",
"math"
] | null | null | It can be shown that any positive integer *x* can be uniquely represented as *x*<==<=1<=+<=2<=+<=4<=+<=...<=+<=2*k*<=-<=1<=+<=*r*, where *k* and *r* are integers, *k*<=≥<=0, 0<=<<=*r*<=≤<=2*k*. Let's call that representation prairie partition of *x*.
For example, the prairie partitions of 12, 17, 7 and 1 are:
17<... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of numbers given from Alice to Borys.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1012; *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*) — the numbers given from Alice to Borys. | Output, in increasing order, all possible values of *m* such that there exists a sequence of positive integers of length *m* such that if you replace every element with the summands in its prairie partition and arrange the resulting numbers in non-decreasing order, you will get the sequence given in the input.
If ther... | [
"8\n1 1 2 2 3 4 5 8\n",
"6\n1 1 1 2 2 2\n",
"5\n1 2 4 4 4\n"
] | [
"2 \n",
"2 3 \n",
"-1\n"
] | In the first example, Alice could get the input sequence from [6, 20] as the original sequence.
In the second example, Alice's original sequence could be either [4, 5] or [3, 3, 3]. | 1,750 | [
{
"input": "8\n1 1 2 2 3 4 5 8",
"output": "2 "
},
{
"input": "6\n1 1 1 2 2 2",
"output": "2 3 "
},
{
"input": "5\n1 2 4 4 4",
"output": "-1"
},
{
"input": "20\n1 1 1 1 2 2 2 2 4 4 4 4 8 8 8 8 8 10 10 11",
"output": "4 "
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,554,979,942 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 546 | 13,414,400 | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
def get(cnt):
c = Counter(a)
last = []
while c[1] and (cnt is None or len(last) < cnt):
x = 1
while c[x]:
c[x] -= 1
x *= 2
last.append(x >> 1)
rem = sorted(c... | Title: Prairie Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It can be shown that any positive integer *x* can be uniquely represented as *x*<==<=1<=+<=2<=+<=4<=+<=...<=+<=2*k*<=-<=1<=+<=*r*, where *k* and *r* are integers, *k*<=≥<=0, 0<=<<=*r*<=≤<=2*k*. Let's call that repr... | ```python
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
def get(cnt):
c = Counter(a)
last = []
while c[1] and (cnt is None or len(last) < cnt):
x = 1
while c[x]:
c[x] -= 1
x *= 2
last.append(x >> 1)
rem ... | 3 | |
847 | B | Preparing for Merge Sort | PROGRAMMING | 1,600 | [
"binary search",
"data structures"
] | null | null | Ivan has an array consisting of *n* different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.
Ivan represent his array with increasing sequences with... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of elements in Ivan's array.
The second line contains a sequence consisting of distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — Ivan's array. | Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line. | [
"5\n1 3 2 5 4\n",
"4\n4 3 2 1\n",
"4\n10 30 50 101\n"
] | [
"1 3 5 \n2 4 \n",
"4 \n3 \n2 \n1 \n",
"10 30 50 101 \n"
] | none | 0 | [
{
"input": "5\n1 3 2 5 4",
"output": "1 3 5 \n2 4 "
},
{
"input": "4\n4 3 2 1",
"output": "4 \n3 \n2 \n1 "
},
{
"input": "4\n10 30 50 101",
"output": "10 30 50 101 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "1\n200000",
"output": "200000 "
},
{
... | 1,505,742,258 | 2,357 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 2,000 | 42,291,200 | n = int(input())
xs = list(map(int, input().split()))
ll = list(range(1,n+1))
prev = list(range(-1, n-1))
def delete(point):
#print(prev, ll)
if prev[point] > -1:
ll[prev[point]] = ll[point]
prev[ll[point]] = prev[point]
#prev[point] = -1
#ll[point] = -1
prev[0] = -1
ll... | Title: Preparing for Merge Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has an array consisting of *n* different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequence... | ```python
n = int(input())
xs = list(map(int, input().split()))
ll = list(range(1,n+1))
prev = list(range(-1, n-1))
def delete(point):
#print(prev, ll)
if prev[point] > -1:
ll[prev[point]] = ll[point]
prev[ll[point]] = prev[point]
#prev[point] = -1
#ll[point] = -1
prev[0... | 0 | |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,553,283,330 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 19,251,200 | n, m, k = input().split()
k = int(k)
buraco = input().split()
bone = "1"
for i in range(k):
a, b = input().split()
if a == bone:
bone = b
elif b == bone:
bone = a
if bone in buraco:
break
print(bone)
| Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
n, m, k = input().split()
k = int(k)
buraco = input().split()
bone = "1"
for i in range(k):
a, b = input().split()
if a == bone:
bone = b
elif b == bone:
bone = a
if bone in buraco:
break
print(bone)
``` | 0 | |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,615,829,484 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | l, r, a = map(int, input().split())
players = 0
if r<l:
if a>=l-r:
players += 2*(l)
players += int((a-(l-r))/2)
# print('im here1')
else:
players += 2*(r+a)
# print('im here2')
elif l<r:
if a>=r-l:
players += 2*(r)
players += int((a-(r... | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
l, r, a = map(int, input().split())
players = 0
if r<l:
if a>=l-r:
players += 2*(l)
players += int((a-(l-r))/2)
# print('im here1')
else:
players += 2*(r+a)
# print('im here2')
elif l<r:
if a>=r-l:
players += 2*(r)
players +=... | 0 | |
216 | B | Forming Teams | PROGRAMMING | 1,700 | [
"dfs and similar",
"implementation"
] | null | null | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then stud... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | [
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] | [
"1",
"0",
"2"
] | none | 1,500 | [
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
... | 1,516,732,380 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 154 | 6,041,600 | from enum import Enum
vertexes, edges = map(int, input().split(' '))
graph = [[] for _ in range(vertexes + 1)]
class IS_CYCLE(Enum):
PATH = 0
CYCLE = 1
for _ in range(edges):
from_, to = map(int, input().split(' '))
graph[from_].append(to)
graph[to].append(from_)
Visited = (ver... | Title: Forming Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each stu... | ```python
from enum import Enum
vertexes, edges = map(int, input().split(' '))
graph = [[] for _ in range(vertexes + 1)]
class IS_CYCLE(Enum):
PATH = 0
CYCLE = 1
for _ in range(edges):
from_, to = map(int, input().split(' '))
graph[from_].append(to)
graph[to].append(from_)
Visi... | 0 | |
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,646,746,040 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | s = input()
opening = {'<','{','[','('}
closing = {'>','}',']',')'}
pair = [['<','>'],['{','}'],['[',']'],['(',')']]
count = 0
stack = []
c = list(s)
print(c)
def findmatch(target):
temp = []
temp.append(stack[len(stack)-1])
temp.append(target)
print(temp)
if(temp in pair):
print("false")... | 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
s = input()
opening = {'<','{','[','('}
closing = {'>','}',']',')'}
pair = [['<','>'],['{','}'],['[',']'],['(',')']]
count = 0
stack = []
c = list(s)
print(c)
def findmatch(target):
temp = []
temp.append(stack[len(stack)-1])
temp.append(target)
print(temp)
if(temp in pair):
prin... | 0 | |
770 | D | Draw Brackets! | PROGRAMMING | 1,400 | [
"*special",
"implementation"
] | null | null | A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular.
Draw the given sequence using a minimalistic pseud... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=100) — the length of the sequence of brackets.
The second line contains the sequence of brackets — these are *n* symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular. | Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces. | [
"8\n[[][]][]\n",
"6\n[[[]]]\n",
"6\n[[][]]\n",
"2\n[]\n",
"4\n[][]\n"
] | [
"+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+\n",
"+- -+\n|+- -+|\n||+- -+||\n||| |||\n||+- -+||\n|+- -+|\n+- -+\n",
"+- -+\n|+- -++- -+|\n|| || ||\n|+- -++- -+|\n+- -+\n",
"+- -+\n| |\n+- -+\n",
"+- -++- -+\n| || |\n+- -... | none | 1,500 | [
{
"input": "8\n[[][]][]",
"output": "+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+"
},
{
"input": "6\n[[[]]]",
"output": "+- -+\n|+- -+|\n||+- -+||\n||| |||\n||+- -+||\n|+- -+|\n+- -+"
},
{
"input": "6\n[[][]]",
"output": ... | 1,698,879,056 | 2,147,483,647 | Python 3 | OK | TESTS | 132 | 46 | 0 | input()
s = input()
h, y = [], 0
for q in s:
h.append(y)
y += 2 * (q == '[') - 1
m = 1 + 2 * max(h)
f = lambda y: '+'.join((' ' * y, '|' * (m - 2 * y - 2), ' ' * y))
g = lambda i, y: [f(y)] if s[i] == '[' else ([' ' * m] * 3 if s[i - 1] == '[' else []) + [f(y - 1)]
for t in zip(*sum((g(i, y) for ... | Title: Draw Brackets!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same... | ```python
input()
s = input()
h, y = [], 0
for q in s:
h.append(y)
y += 2 * (q == '[') - 1
m = 1 + 2 * max(h)
f = lambda y: '+'.join((' ' * y, '|' * (m - 2 * y - 2), ' ' * y))
g = lambda i, y: [f(y)] if s[i] == '[' else ([' ' * m] * 3 if s[i - 1] == '[' else []) + [f(y - 1)]
for t in zip(*sum((g(... | 3 | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,549,547,040 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 0 | l1=["a","e","i","o","u"]
k=0
s=input()
for x in s :
if x in l1 :
k+=1
if k!=5 :
print("NO")
exit()
k=0
s=input()
for x in s :
if x in l1 :
k+=1
if k!=7 :
print("NO")
exit()
k=0
s=input()
for x in s :
if x in l1 :
k+=1... | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
l1=["a","e","i","o","u"]
k=0
s=input()
for x in s :
if x in l1 :
k+=1
if k!=5 :
print("NO")
exit()
k=0
s=input()
for x in s :
if x in l1 :
k+=1
if k!=7 :
print("NO")
exit()
k=0
s=input()
for x in s :
if x in l1 :
... | 3.938 |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,699,076,140 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | m,n = map(int,input().split())
if m%n == 0:
maxi = ((m-n+1)*(m-n))//2
if n == 1:
mini = maxi
else:
mini = (((m//n)*(m//n-1))//2)*n
elif m > n and m%n != 0:
f = m%n
s = (m-f)//n
d = n-f
#print(f,s,d)
if s == 0:
mini = f
else:
mini = f*(((... | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
m,n = map(int,input().split())
if m%n == 0:
maxi = ((m-n+1)*(m-n))//2
if n == 1:
mini = maxi
else:
mini = (((m//n)*(m//n-1))//2)*n
elif m > n and m%n != 0:
f = m%n
s = (m-f)//n
d = n-f
#print(f,s,d)
if s == 0:
mini = f
else:
mi... | 3 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,477,412,875 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | if __name__ =="__main__":
n,m = map(int,input().split())
OK = n<=10 and m <=10
check =[]
for i in range(n):
if OK:
tmp = str(input())
QQ = tmp[0]
for i in tmp:
if i!=QQ:
OK = False
if QQ in check:
OK=False
if OK:
check.append(QQ)
if OK:
print("YES")
else:
p... | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
if __name__ =="__main__":
n,m = map(int,input().split())
OK = n<=10 and m <=10
check =[]
for i in range(n):
if OK:
tmp = str(input())
QQ = tmp[0]
for i in tmp:
if i!=QQ:
OK = False
if QQ in check:
OK=False
if OK:
check.append(QQ)
if OK:
print("YES")
... | 0 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,697,395,664 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import sys
numbers=[int(i) for i in sys.stdin.readline().split]
n=numbers[0]
h=numbers[1]
a=[int(i) for i in sys.stdin.readline().split]
width_total=0
for i in a:
if i>h:
width_total+=2
else:
width_total+=1
print(width_total)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
import sys
numbers=[int(i) for i in sys.stdin.readline().split]
n=numbers[0]
h=numbers[1]
a=[int(i) for i in sys.stdin.readline().split]
width_total=0
for i in a:
if i>h:
width_total+=2
else:
width_total+=1
print(width_total)
``` | -1 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,674,987,722 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | import bisect
n,m =map(int,input().split())
l = list(map(int,input().split()))
pre = [l[0]]
ans = 0
for i in range(1,n):
pre.append(l[i]+pre[-1])
for i in range(n-1,-1,-1):
c = bisect.bisect_left(pre,pre[i]-m)
ans=max(max(0,i-c),ans)
print(ans)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
import bisect
n,m =map(int,input().split())
l = list(map(int,input().split()))
pre = [l[0]]
ans = 0
for i in range(1,n):
pre.append(l[i]+pre[-1])
for i in range(n-1,-1,-1):
c = bisect.bisect_left(pre,pre[i]-m)
ans=max(max(0,i-c),ans)
print(ans)
``` | 0 | |
641 | A | Little Artem and Grasshopper | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Gr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip.
Next line contains a string of length *n* which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d*... | Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). | [
"2\n><\n1 2\n",
"3\n>><\n2 1 1\n"
] | [
"FINITE\n",
"INFINITE"
] | In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | 500 | [
{
"input": "2\n><\n1 2",
"output": "FINITE"
},
{
"input": "3\n>><\n2 1 1",
"output": "INFINITE"
},
{
"input": "1\n>\n1000000000",
"output": "FINITE"
},
{
"input": "1\n<\n1000000000",
"output": "FINITE"
},
{
"input": "2\n>>\n1 1",
"output": "FINITE"
},
{
... | 1,639,667,951 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 33 | 2,000 | 10,854,400 | n = int(input()) - 1
directions = input()
powers = list(map(int, input().split()))
pos_x = 0
memory = [0]
while True:
if directions[pos_x] == '>':
pos_x += powers[pos_x]
else:
pos_x -= powers[pos_x]
if pos_x in memory:
print("INFINITE")
break
elif pos... | Title: Little Artem and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and t... | ```python
n = int(input()) - 1
directions = input()
powers = list(map(int, input().split()))
pos_x = 0
memory = [0]
while True:
if directions[pos_x] == '>':
pos_x += powers[pos_x]
else:
pos_x -= powers[pos_x]
if pos_x in memory:
print("INFINITE")
break
... | 0 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,684,911,957 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 124 | 0 | n, m = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
best=999999
for i in range (m-n+1):
best=min(best, pieces[i+n-1]-pieces[i])
print(best)
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n, m = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
best=999999
for i in range (m-n+1):
best=min(best, pieces[i+n-1]-pieces[i])
print(best)
``` | 3 | |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,567,009,596 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 109 | 0 | s, k = input(), int(input())
print((k - len(set(s)), "impossible")[len(s) < k])
| Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
s, k = input(), int(input())
print((k - len(set(s)), "impossible")[len(s) < k])
``` | 0 | |
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table... | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0... | 1,592,569,133 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 155 | 2,867,200 | n, k = map(int, input().split())
l = []
for i in range(n):
if i == n - 1:
l.append(k-sum(l))
else:
l.append(i)
for j in range(n):
print(*(l[j:]+l[:j])) | Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortun... | ```python
n, k = map(int, input().split())
l = []
for i in range(n):
if i == n - 1:
l.append(k-sum(l))
else:
l.append(i)
for j in range(n):
print(*(l[j:]+l[:j]))
``` | 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,627,335,268 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 6,963,200 | whoops_forgot_this_thing_existed_until_after_i_almost_finished_so_i_wont_actually_use_it = int(input())
time = list(map(int, input().split()))
c = len(time)
answer = 0
for b in range(1, c):
for a in range(0, b-1):
if time[a] == time[b] and time[a] == min(time):
answer = 1
if answer == 0:... | 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
whoops_forgot_this_thing_existed_until_after_i_almost_finished_so_i_wont_actually_use_it = int(input())
time = list(map(int, input().split()))
c = len(time)
answer = 0
for b in range(1, c):
for a in range(0, b-1):
if time[a] == time[b] and time[a] == min(time):
answer = 1
if an... | 0 | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,694,775,915 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n,t = [int(i) for i in input().split()]
a = [i for i in input().strip()]
for i in range(t):
for j in range(n-1):
if a[i] == 'B' and a[i+1] == 'G':
a[i],a[i+1] = a[i+1],a[i]
print(''.join(a)) | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
n,t = [int(i) for i in input().split()]
a = [i for i in input().strip()]
for i in range(t):
for j in range(n-1):
if a[i] == 'B' and a[i+1] == 'G':
a[i],a[i+1] = a[i+1],a[i]
print(''.join(a))
``` | 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,698,000,150 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 62 | 0 | n = int(input())
s = [int(i) for i in input().split()]
dp = [[0 for j in range(3)] for i in range(n)]
for i in range(n):
dp[i][0] = max((dp[i-1][0], dp[i-1][1], dp[i-1][2]))
if s[i-1] == 1 or s[i-1] == 3:
dp[i][1] = max(dp[i-1][0] + 1, dp[i-1][2] + 1)
if s[i-1] == 2 or s[i-1] == 3:
d... | 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())
s = [int(i) for i in input().split()]
dp = [[0 for j in range(3)] for i in range(n)]
for i in range(n):
dp[i][0] = max((dp[i-1][0], dp[i-1][1], dp[i-1][2]))
if s[i-1] == 1 or s[i-1] == 3:
dp[i][1] = max(dp[i-1][0] + 1, dp[i-1][2] + 1)
if s[i-1] == 2 or s[i-1] == 3:
... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.