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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,632,379,465 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 154 | 6,963,200 | #!/usr/bin/env python
# Heders
import os
# Input
n = int(input())
k = [int(x) for x in input().split()]
e,o =[],[]
even,odd = 0,0
# Finding the odd one in list
for i in k:
if i%2 == 0:
e.append(str(k.index(i)))
elif i%2 == 1:
o.append(str(k.index(i)))
if len(o) <= 1:
val = int(''.join(o))+1
print(val)
elif ... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
#!/usr/bin/env python
# Heders
import os
# Input
n = int(input())
k = [int(x) for x in input().split()]
e,o =[],[]
even,odd = 0,0
# Finding the odd one in list
for i in k:
if i%2 == 0:
e.append(str(k.index(i)))
elif i%2 == 1:
o.append(str(k.index(i)))
if len(o) <= 1:
val = int(''.join(o))+1
print(... | 3.94853 |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,655,306,584 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 77 | 0 | n,c=map(int,input().split())
p=list(map(int,input().split()))
t=list(map(int,input().split()))
Tl=0
Tr=0
Sl=0
Sr=0
for i in range(n):
Tl+=t[i]
Tr+=t[-i-1]
Sl+=max(0,p[i]-(c*Tl))
Sr+=max(0,p[-i-1]-(c*Tr))
if Sl>Sr:
print("Limak")
elif Sr>Sl:
print("Radewoosh")
else:
print("Ti... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
n,c=map(int,input().split())
p=list(map(int,input().split()))
t=list(map(int,input().split()))
Tl=0
Tr=0
Sl=0
Sr=0
for i in range(n):
Tl+=t[i]
Tr+=t[-i-1]
Sl+=max(0,p[i]-(c*Tl))
Sr+=max(0,p[-i-1]-(c*Tr))
if Sl>Sr:
print("Limak")
elif Sr>Sl:
print("Radewoosh")
else:
... | 3 | |
450 | B | Jzzhu and Sequences | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). | Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). | [
"2 3\n3\n",
"0 -1\n2\n"
] | [
"1\n",
"1000000006\n"
] | In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-... | 1,000 | [
{
"input": "2 3\n3",
"output": "1"
},
{
"input": "0 -1\n2",
"output": "1000000006"
},
{
"input": "-9 -11\n12345",
"output": "1000000005"
},
{
"input": "0 0\n1000000000",
"output": "0"
},
{
"input": "-1000000000 1000000000\n2000000000",
"output": "1000000000"
... | 1,685,945,735 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 19 | 92 | 2,764,800 | from collections import deque
import math
from random import randint as rand
from functools import lru_cache
import string
alph_l = string.ascii_lowercase
alph_u = string.ascii_uppercase
def binpoisk(a, x):
l, r = -1, len(a)
while l +1 < r:
m = (l + r) // 2
if a[m] <= x:
... | Title: Jzzhu and Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers... | ```python
from collections import deque
import math
from random import randint as rand
from functools import lru_cache
import string
alph_l = string.ascii_lowercase
alph_u = string.ascii_uppercase
def binpoisk(a, x):
l, r = -1, len(a)
while l +1 < r:
m = (l + r) // 2
if a[m] <= x:
... | 0 | |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,699,200,344 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | import math
n=float(input())
if int(n%10)!=9:
if (n*10)%10<5:
print(math.floor(n))
else:
print(math.ceil(n))
else:
print("GOTO Vasilisa.") | Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
import math
n=float(input())
if int(n%10)!=9:
if (n*10)%10<5:
print(math.floor(n))
else:
print(math.ceil(n))
else:
print("GOTO Vasilisa.")
``` | 0 |
803 | D | Magazine Ad | PROGRAMMING | 1,900 | [
"binary search",
"greedy"
] | null | null | The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th... | The first line contains number *k* (1<=≤<=*k*<=≤<=105).
The second line contains the text of the ad — non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters. | Output minimal width of the ad. | [
"4\ngarage for sa-le\n",
"4\nEdu-ca-tion-al Ro-unds are so fun\n"
] | [
"7\n",
"10\n"
] | Here all spaces are replaced with dots.
In the first example one of possible results after all word wraps looks like this:
The second example: | 0 | [
{
"input": "4\ngarage for sa-le",
"output": "7"
},
{
"input": "4\nEdu-ca-tion-al Ro-unds are so fun",
"output": "10"
},
{
"input": "1\nj",
"output": "1"
},
{
"input": "10\nb",
"output": "1"
},
{
"input": "1\nQGVsfZevMD",
"output": "10"
},
{
"input": "1... | 1,495,902,362 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 61 | 0 | import math
k = int(input()) # 10^5
words = input() # 10^6
#k = 10**5
#words = 'garage for sa-le '*100
#words = 'Edu-ca-tion-al Ro-unds are so fun'
lens = []
pos = -1
for i in range(len(words)):
if (words[i]==' ')|(words[i]=='-'):
lens.append(i-pos)
pos = i
lens.append(i-pos)
m = max(math.ceil(sum(l... | Title: Magazine Ad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen... | ```python
import math
k = int(input()) # 10^5
words = input() # 10^6
#k = 10**5
#words = 'garage for sa-le '*100
#words = 'Edu-ca-tion-al Ro-unds are so fun'
lens = []
pos = -1
for i in range(len(words)):
if (words[i]==' ')|(words[i]=='-'):
lens.append(i-pos)
pos = i
lens.append(i-pos)
m = max(math.... | 0 | |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,691,504,911 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | s = input()
n = len(s)
ans = s.count("VK")
f = False
if n > 1:
if s[0] == s[1] and s[0] == "V":
f = True
if s[n-2] == s[n-1] and s[n-1] == "K":
f = True
if "VVV" in s or "KKK" in s:
f = True
if f:
ans += 1
print(ans) | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
s = input()
n = len(s)
ans = s.count("VK")
f = False
if n > 1:
if s[0] == s[1] and s[0] == "V":
f = True
if s[n-2] == s[n-1] and s[n-1] == "K":
f = True
if "VVV" in s or "KKK" in s:
f = True
if f:
ans += 1
print(ans)
``` | 0 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,633,556,986 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 77 | 6,963,200 | # https://codeforces.com/problemset/problem/749/A
integer = int( input() );
if integer % 2 == 0:
print(integer // 2); print( '2 ' * (integer // 2));
else:
print( (integer - 1) // 2); print( '2 ' * (integer // 2 - 1) + '3');
| Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
# https://codeforces.com/problemset/problem/749/A
integer = int( input() );
if integer % 2 == 0:
print(integer // 2); print( '2 ' * (integer // 2));
else:
print( (integer - 1) // 2); print( '2 ' * (integer // 2 - 1) + '3');
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index... | 0 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,594,718,142 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 233 | 32,460,800 | a,b = map(int,input().split())
z = list(map(int,input().split()))
if b ==1:print(min(z))
elif b==2:
q,v,w,r,t=z[0],[z[0]],[z[-1]],z[-1],-float("inf")
for i in range(1,a):
if z[i]<q:q =z[i]
v.append(q)
for j in range(a-2,-1,-1):
if z[j]<r:r=z[j]
w.append(r)
for i in range(a):
t = max(t,v[i],w[i... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ... | ```python
a,b = map(int,input().split())
z = list(map(int,input().split()))
if b ==1:print(min(z))
elif b==2:
q,v,w,r,t=z[0],[z[0]],[z[-1]],z[-1],-float("inf")
for i in range(1,a):
if z[i]<q:q =z[i]
v.append(q)
for j in range(a-2,-1,-1):
if z[j]<r:r=z[j]
w.append(r)
for i in range(a):
t = max(... | 3 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,508,916,936 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | n=input()
ans=[]
def c(s):
res=s
s=str(s)
for i in s:
res+=int(i)
return res
lb=int('1'+'0'*(len(n)-1))
ub=int('1'+'0'*len(n))
ans=0
d=[]
for i in range(lb,ub):
if c(i)==int(n):
d.append(i)
ans+=1
print(ans)
for i in d:
print(i)
... | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
n=input()
ans=[]
def c(s):
res=s
s=str(s)
for i in s:
res+=int(i)
return res
lb=int('1'+'0'*(len(n)-1))
ub=int('1'+'0'*len(n))
ans=0
d=[]
for i in range(lb,ub):
if c(i)==int(n):
d.append(i)
ans+=1
print(ans)
for i in d:
print(i)
... | 0 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,630,992,157 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 62 | 6,758,400 | S = input()
char = set(['a','e','i','o','u','1','3','5','7','9'])
flips = sum(X in char for X in S)
print(flips) | Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
S = input()
char = set(['a','e','i','o','u','1','3','5','7','9'])
flips = sum(X in char for X in S)
print(flips)
``` | 3 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,696,307,362 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 46 | 0 | # f(n) = -1 +2 -3 ... + (-n)^n * n
# f(1) = -1 -- f(2) = 1
# f(3) = -2 -- f(4) = 2
# f(5) = -3 -- f(6) = 3
# f(7) = -4 -- f(8) = 4
# f(9) = -5 -- f(10) = 5
# if n is odd it's ((n+1)/2) * -1
# if n is 1 it's -1.
# if n is even it's n/2.
# I've been thinking about this problem for a few days and now I see th... | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
# f(n) = -1 +2 -3 ... + (-n)^n * n
# f(1) = -1 -- f(2) = 1
# f(3) = -2 -- f(4) = 2
# f(5) = -3 -- f(6) = 3
# f(7) = -4 -- f(8) = 4
# f(9) = -5 -- f(10) = 5
# if n is odd it's ((n+1)/2) * -1
# if n is 1 it's -1.
# if n is even it's n/2.
# I've been thinking about this problem for a few days and no... | 3 | |
962 | D | Merge Equals | PROGRAMMING | 1,600 | [
"data structures",
"implementation"
] | null | null | You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two... | The first line contains a single integer $n$ ($2 \le n \le 150\,000$) — the number of elements in the array.
The second line contains a sequence from $n$ elements $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{9}$) — the elements of the array. | In the first line print an integer $k$ — the number of elements in the array after all the performed operations. In the second line print $k$ integers — the elements of the array after all the performed operations. | [
"7\n3 4 1 2 2 1 1\n",
"5\n1 1 3 1 1\n",
"5\n10 40 20 50 30\n"
] | [
"4\n3 8 2 1 \n",
"2\n3 4 \n",
"5\n10 40 20 50 30 \n"
] | The first two examples were considered in the statement.
In the third example all integers in the given array are distinct, so it will not change. | 0 | [
{
"input": "7\n3 4 1 2 2 1 1",
"output": "4\n3 8 2 1 "
},
{
"input": "5\n1 1 3 1 1",
"output": "2\n3 4 "
},
{
"input": "5\n10 40 20 50 30",
"output": "5\n10 40 20 50 30 "
},
{
"input": "100\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 1... | 1,670,320,405 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 202 | 21,811,200 | import sys
input = sys.stdin.readline
from heapq import heappop, heappush
from collections import defaultdict
n = int(input())
d = defaultdict(list)
for i, j in enumerate(map(int, input().split())):
d[j].append(i)
q = sorted([i for i in d if len(d[i]) > 1])
x = -2
a = -1
while q:
a = heappop(q)
... | Title: Merge Equals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first... | ```python
import sys
input = sys.stdin.readline
from heapq import heappop, heappush
from collections import defaultdict
n = int(input())
d = defaultdict(list)
for i, j in enumerate(map(int, input().split())):
d[j].append(i)
q = sorted([i for i in d if len(d[i]) > 1])
x = -2
a = -1
while q:
a = hea... | 0 | |
899 | B | Months and Years | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of... | 1,000 | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 3... | 1,520,520,310 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 62 | 5,632,000 | a='31 28 31 30 31 30 31 31 30 31 30 31 '*3
b='31 28 31 30 31 30 31 31 30 31 30 31 '*2+'31 29 31 30 31 30 31 31 30 31 30 31 '+'31 28 31 30 31 30 31 31 30 31 30 31 '*2
input()
c=input()
if c in a or c in b:
print('Yes')
else:
print('No') | Title: Months and Years
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, ... | ```python
a='31 28 31 30 31 30 31 31 30 31 30 31 '*3
b='31 28 31 30 31 30 31 31 30 31 30 31 '*2+'31 29 31 30 31 30 31 31 30 31 30 31 '+'31 28 31 30 31 30 31 31 30 31 30 31 '*2
input()
c=input()
if c in a or c in b:
print('Yes')
else:
print('No')
``` | 3 | |
340 | C | Tourist Problem | PROGRAMMING | 1,600 | [
"combinatorics",
"implementation",
"math"
] | null | null | Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a*... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107). | Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible. | [
"3\n2 3 5\n"
] | [
"22 3"
] | Consider 6 possible routes:
- [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; - [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; - [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; - [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; - [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; - [5, 3, 2]: |5 – 0| + |3 – 5|... | 2,000 | [
{
"input": "3\n2 3 5",
"output": "22 3"
},
{
"input": "4\n1 5 77 2",
"output": "547 4"
},
{
"input": "5\n3 3842 288 199 334",
"output": "35918 5"
},
{
"input": "7\n1 2 3 40 52 33 86",
"output": "255 1"
},
{
"input": "7\n1 10 100 1000 10000 1000000 10000000",
"... | 1,578,313,499 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | from math import gcd
n = int(input())
a = list(map(int, input().split()))
a.append(0)
ans = sum(a)
a.sort()
x = []
for i in range(1, n):
x.append(abs(a[i] - a[i]))
s = 0
for i in range(len(x)):
s += 2 * (i + 1) * (n - 1) + x[i]
tmp = gcd(ans + s, n)
print((ans + s) // tmp, end =' ')
print(n // tmp)
... | Title: Tourist Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* d... | ```python
from math import gcd
n = int(input())
a = list(map(int, input().split()))
a.append(0)
ans = sum(a)
a.sort()
x = []
for i in range(1, n):
x.append(abs(a[i] - a[i]))
s = 0
for i in range(len(x)):
s += 2 * (i + 1) * (n - 1) + x[i]
tmp = gcd(ans + s, n)
print((ans + s) // tmp, end =' ')
print(n // tmp)
... | 0 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,530,826,816 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #http://codeforces.com/contest/1004/problem/A Sonya and Hotels
def common_elements(list1, list2):
return list(set(list1) & set(list2))
n,d = map(int,input().split())
x= list(map(int,input().split()))
b=[]
c=[]
e=[]
for i in x:
b.append(i-d)
b.append(i+d)
c.append(b)
b=[]
# print ('c ... | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
#http://codeforces.com/contest/1004/problem/A Sonya and Hotels
def common_elements(list1, list2):
return list(set(list1) & set(list2))
n,d = map(int,input().split())
x= list(map(int,input().split()))
b=[]
c=[]
e=[]
for i in x:
b.append(i-d)
b.append(i+d)
c.append(b)
b=[]
# ... | -1 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,677,416,357 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,m,a=map(int,input().split())
if((n*m)>=(a*a):
print(min(n,m,a))
else:
print(max(n,m,a)) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a=map(int,input().split())
if((n*m)>=(a*a):
print(min(n,m,a))
else:
print(max(n,m,a))
``` | -1 |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,666,530,855 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 202 | 2,252,800 | sList =list(input())
tList = list(input())
i=0
while i<len(sList) and i<len(tList):
if sList[len(sList)-i-1]==tList[len(tList)-i-1]:
i+=1
else:
break
print(len(sList)+len(tList)-(2*i)) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
sList =list(input())
tList = list(input())
i=0
while i<len(sList) and i<len(tList):
if sList[len(sList)-i-1]==tList[len(tList)-i-1]:
i+=1
else:
break
print(len(sList)+len(tList)-(2*i))
``` | 3 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,646,870,106 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n = int(input())
arr = list(map(int, input().split()[:n]))
arr = sorted(arr)
print(arr[len(arr)//2]) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n = int(input())
arr = list(map(int, input().split()[:n]))
arr = sorted(arr)
print(arr[len(arr)//2])
``` | 0 | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,626,753,188 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 154 | 6,963,200 | s = str(input())
yes = True
while len(s)>0:
if len(s)>2 and s[:3] == '144':
s = s[3:]
elif len(s)>1 and s[:2] == '14':
s = s[2:]
elif s[0] == '1':
s = s[1:]
else:
yes = False
break
if yes:
print("YES")
else:
print('NO') | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
s = str(input())
yes = True
while len(s)>0:
if len(s)>2 and s[:3] == '144':
s = s[3:]
elif len(s)>1 and s[:2] == '14':
s = s[2:]
elif s[0] == '1':
s = s[1:]
else:
yes = False
break
if yes:
print("YES")
else:
print('NO')
``` | 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,680,859,451 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 23 | 154 | 2,048,000 | import math
n = int(input())
k = [0]*(n+1)
primes = [True]*(n+1)
for i in range(n+1):
if i%2 == 0:
k[i] += 1
primes[i] = False
for i in range(3, n, 2):
if not primes[i]:
continue
for j in range(i+1, n+1):
if j % i == 0:
k[j] += 1
... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
import math
n = int(input())
k = [0]*(n+1)
primes = [True]*(n+1)
for i in range(n+1):
if i%2 == 0:
k[i] += 1
primes[i] = False
for i in range(3, n, 2):
if not primes[i]:
continue
for j in range(i+1, n+1):
if j % i == 0:
k[j] +=... | 3.957685 |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,609,946,015 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 171 | 0 | t = int(input())
lst = []
for i in range(t):
str = input()
if str in lst:
print("YES")
else:
lst.append(str)
print("NO") | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
t = int(input())
lst = []
for i in range(t):
str = input()
if str in lst:
print("YES")
else:
lst.append(str)
print("NO")
``` | 3 | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,689,470,953 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 16,896,000 | import bisect; from sys import stdin, stdout
input = stdin.readline
n = int(input()); x = sorted(list(map(int, input().split())))
for i in range(int(input())):
print(len(x[:bisect.bisect_right(x, int(input()))])) | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
import bisect; from sys import stdin, stdout
input = stdin.readline
n = int(input()); x = sorted(list(map(int, input().split())))
for i in range(int(input())):
print(len(x[:bisect.bisect_right(x, int(input()))]))
``` | 0 | |
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,624,894,556 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 77 | 0 | s = list(input())
a = ['h','e','l','l','o',0]
x = 0
if a[0] in s:
x = s.index(a[0])
s = s[x+1:]
else:
print("NO")
if a[1] in s:
x = s.index(a[1])
s = s[x+1:]
else:
print("NO")
if a[2] in s:
x = s.index(a[2])
s = s[x+1:]
else:
print("NO")
if a[3] in s:
x... | 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 = list(input())
a = ['h','e','l','l','o',0]
x = 0
if a[0] in s:
x = s.index(a[0])
s = s[x+1:]
else:
print("NO")
if a[1] in s:
x = s.index(a[1])
s = s[x+1:]
else:
print("NO")
if a[2] in s:
x = s.index(a[2])
s = s[x+1:]
else:
print("NO")
if a[3] in... | 0 |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,643,950,979 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | /*
Author:
█ █ ██\ /██ /███\ █████ /███\
█ █ █\█\/█/█ █ █ █ █ █
█ █ █ \██/ █ █████ █ ████/
█ █ █ █ █ █ █ █\█\
\████/ █ █ █ █ █████ █ \█\
*/
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int t;
cin>>t;
while (t--){
long long n;
c... | Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
/*
Author:
█ █ ██\ /██ /███\ █████ /███\
█ █ █\█\/█/█ █ █ █ █ █
█ █ █ \██/ █ █████ █ ████/
█ █ █ █ █ █ █ █\█\
\████/ █ █ █ █ █████ █ \█\
*/
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int t;
cin>>t;
while (t--){
long lo... | -1 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,689,520,863 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | s1 = input()
s2 = input()
s3 = list(input())
s4 = s1 + s2
v ="YES"
for i in s4 :
if i in s3 :
s3.remove(i)
else :
v = "NO"
break
if len(s3) != 0 :
v = "NO"
print(v)
| Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
s1 = input()
s2 = input()
s3 = list(input())
s4 = s1 + s2
v ="YES"
for i in s4 :
if i in s3 :
s3.remove(i)
else :
v = "NO"
break
if len(s3) != 0 :
v = "NO"
print(v)
``` | 3 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,680,562,142 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 124 | 8,499,200 | n = int(input())
line = input().split()
change_25 = 0
change_50 = 0
for i in range(n):
if line[i] == "25":
change_25 += 1
elif line[i] == "50":
if change_25 > 0:
change_25 -= 1
change_50 += 1
else:
print("NO")
exit()
eli... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
n = int(input())
line = input().split()
change_25 = 0
change_50 = 0
for i in range(n):
if line[i] == "25":
change_25 += 1
elif line[i] == "50":
if change_25 > 0:
change_25 -= 1
change_50 += 1
else:
print("NO")
exit(... | 3 | |
862 | B | Mahmoud and Ehab and the bipartiteness | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *... | The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree.
It's guaranteed that the given graph is a tree. | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | [
"3\n1 2\n1 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n"
] | [
"0\n",
"2\n"
] | Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that ... | 1,000 | [
{
"input": "3\n1 2\n1 3",
"output": "0"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6",
"output": "16"
},
{
"input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4",
"output": "16"
},
{
"in... | 1,612,864,012 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 514 | 13,619,200 | n=int(input())
color=[ -1 for i in range(n+1)]
graph={}
for _ in range(n-1):
a,b=list(map(int,input().split(" ")))
if a in graph:
graph[a].append(b)
else:
graph[a]=[b]
if b in graph:
graph[b].append(a)
else:
graph[b]=[a]
remaining=1
col=0
next=[1]
... | Title: Mahmoud and Ehab and the bipartiteness
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a gra... | ```python
n=int(input())
color=[ -1 for i in range(n+1)]
graph={}
for _ in range(n-1):
a,b=list(map(int,input().split(" ")))
if a in graph:
graph[a].append(b)
else:
graph[a]=[b]
if b in graph:
graph[b].append(a)
else:
graph[b]=[a]
remaining=1
col=0
... | 3 | |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,666,189,271 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 1,000 | 18,124,800 | n,M = map(int,input().split())
a =[0]+list(map(int,input().split()))+[M]
res = [sum(a[1:n+2:2])-sum(a[2:n+1:2])]
for i in range(1,n+1,2):
if a[i]-1 != a[i-1] or a[i]+1 != a[i+1]:
res.append(sum(a[1:i+2:2])+sum(a[i+1:n+2:2])-sum(a[i:n+1:2])-sum(a[2:i+1:2])-1)
print(max(res)) | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n,M = map(int,input().split())
a =[0]+list(map(int,input().split()))+[M]
res = [sum(a[1:n+2:2])-sum(a[2:n+1:2])]
for i in range(1,n+1,2):
if a[i]-1 != a[i-1] or a[i]+1 != a[i+1]:
res.append(sum(a[1:i+2:2])+sum(a[i+1:n+2:2])-sum(a[i:n+1:2])-sum(a[2:i+1:2])-1)
print(max(res))
``` | 0 | |
155 | B | Combination | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number *a**i*, and the botto... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards Ilya has.
Each of the next *n* lines contains two non-negative space-separated integers — *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=104) — the numbers, written at the top and the bottom of the *i*-th card correspondingly. | Print the single number — the maximum number of points you can score in one round by the described rules. | [
"2\n1 0\n2 0\n",
"3\n1 0\n2 0\n0 2\n"
] | [
"2\n",
"3\n"
] | In the first sample none of two cards brings extra moves, so you should play the one that will bring more points.
In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards. | 1,000 | [
{
"input": "2\n1 0\n2 0",
"output": "2"
},
{
"input": "3\n1 0\n2 0\n0 2",
"output": "3"
},
{
"input": "5\n0 0\n2 0\n2 0\n3 0\n5 1",
"output": "8"
},
{
"input": "7\n9 1\n8 1\n9 0\n9 1\n5 1\n1 1\n0 1",
"output": "41"
},
{
"input": "7\n5 0\n4 0\n3 0\n5 2\n3 0\n4 2\n0... | 1,696,321,993 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 218 | 1,740,800 | n,l,s= int(input()),[],[1,0]
for i in range(n):
a,b=map(int, input().split())
l.append([b,a])
l.sort(),l.reverse()
for e in l:
if s[0]==0: break
s=[s[0]+e[0]-1,s[1]+e[1]]
print(s[1])
| Title: Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player ... | ```python
n,l,s= int(input()),[],[1,0]
for i in range(n):
a,b=map(int, input().split())
l.append([b,a])
l.sort(),l.reverse()
for e in l:
if s[0]==0: break
s=[s[0]+e[0]-1,s[1]+e[1]]
print(s[1])
``` | 3 | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,681,122,892 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 2,560,000 | n=int(input())
print(pow(1378,n)%10)
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n=int(input())
print(pow(1378,n)%10)
``` | 0 | |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,670,621,656 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 607 | 6,656,000 | ans = 0
price = float('inf')
for i in range(int(input())):
a,b = list(map(int,input().split()))
price = min(price,b)
ans += price * a
print(ans) | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
ans = 0
price = float('inf')
for i in range(int(input())):
a,b = list(map(int,input().split()))
price = min(price,b)
ans += price * a
print(ans)
``` | 3 | |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,607,493,353 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 140 | 0 | n = int(input())
m = int(input())
a = []
k = 0
aps = 0
for _ in range(n):
a.append(int(input()))
a.sort(reverse=True)
for i in a:
k+=i
aps += 1
if k >= m:
break
print(aps)
| Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
n = int(input())
m = int(input())
a = []
k = 0
aps = 0
for _ in range(n):
a.append(int(input()))
a.sort(reverse=True)
for i in a:
k+=i
aps += 1
if k >= m:
break
print(aps)
``` | 3 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,696,332,041 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 122 | 2,867,200 | from string import digits
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return (int(input()))
def inlt():
return (list(map(int, input().split())))
def insr():
s = input()
return (list(s[:len(s) - 1]))
def invr():
re... | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
from string import digits
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return (int(input()))
def inlt():
return (list(map(int, input().split())))
def insr():
s = input()
return (list(s[:len(s) - 1]))
def invr(... | -1 | |
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1.... | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
}... | 1,642,692,892 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 0 |
n,k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
flag = 0
item = arr[k-1]
for i in reversed(range(k-1)):
if arr[i] != item:
flag = i
break
if arr[k-1:].count(item) == n-k+1:
print(flag+1)
else:
print(-1) | Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the cur... | ```python
n,k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
flag = 0
item = arr[k-1]
for i in reversed(range(k-1)):
if arr[i] != item:
flag = i
break
if arr[k-1:].count(item) == n-k+1:
print(flag+1)
else:
print(-1)
``` | 0 | |
964 | B | Messages | PROGRAMMING | 1,300 | [
"math"
] | null | null | There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any mome... | The first line contains five integers *n*, *A*, *B*, *C* and *T* (1<=≤<=*n*,<=*A*,<=*B*,<=*C*,<=*T*<=≤<=1000).
The second string contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=*T*). | Output one integer — the answer to the problem. | [
"4 5 5 3 5\n1 5 5 4\n",
"5 3 1 1 3\n2 2 2 1 1\n",
"5 5 3 4 5\n1 2 3 4 5\n"
] | [
"20\n",
"15\n",
"35\n"
] | In the first sample the messages must be read immediately after receiving, Vasya receives *A* points for each message, *n*·*A* = 20 in total.
In the second sample the messages can be read at any integer moment.
In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messa... | 1,000 | [
{
"input": "4 5 5 3 5\n1 5 5 4",
"output": "20"
},
{
"input": "5 3 1 1 3\n2 2 2 1 1",
"output": "15"
},
{
"input": "5 5 3 4 5\n1 2 3 4 5",
"output": "35"
},
{
"input": "1 6 4 3 9\n2",
"output": "6"
},
{
"input": "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3",
"output": "90... | 1,582,461,019 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 109 | 0 | #!/usr/bin/env python3
# -*- coding: UTF-8 -*-
def main() -> None:
n,a,b,c,t = (int(x)for x in input().split())
s = 0
for item in input().split():
s+=t-int(item)
if b<c :
print(n*a+s*(c-b))
else:
print(n*a)
if __name__ == "__main__":
main()
... | Title: Messages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* e... | ```python
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
def main() -> None:
n,a,b,c,t = (int(x)for x in input().split())
s = 0
for item in input().split():
s+=t-int(item)
if b<c :
print(n*a+s*(c-b))
else:
print(n*a)
if __name__ == "__main__":
main()
... | 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,595,327,633 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 108 | 6,963,200 | def selection_sort(n):
for i in range(len(n)-1):
min = i
for j in range(i+1,len(n)):
if n[j]<n[min]:
min = j
tem = n[min]
n[min] = n[i]
n[i] = tem
number_of_mug,volum = input().split()
number_of_mug = int(number_of_mug)
volum = int(volum)
ls ... | 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
def selection_sort(n):
for i in range(len(n)-1):
min = i
for j in range(i+1,len(n)):
if n[j]<n[min]:
min = j
tem = n[min]
n[min] = n[i]
n[i] = tem
number_of_mug,volum = input().split()
number_of_mug = int(number_of_mug)
volum = int(... | 3 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,590,152,654 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 204,800 | def to_list(s):
return list(map(lambda x: int(x)))
def solve(a):
max_count = 1
for i in range(len(a)):
j = i-1
k = i+1
l_count = 0
r_count = 0
while (j >= 0):
if (a[j] <= a[i]):
l_count += 1
j -= 1
... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
def to_list(s):
return list(map(lambda x: int(x)))
def solve(a):
max_count = 1
for i in range(len(a)):
j = i-1
k = i+1
l_count = 0
r_count = 0
while (j >= 0):
if (a[j] <= a[i]):
l_count += 1
j -= 1
... | -1 |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,576,512,989 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | #!/usr/bin/env python
# coding: utf-8
# In[10]:
a,b,n=map(int,input().split())
def gcd(x,y):
while y>0:
x,y=y,x%y
return x
i=0
temp=0
while n>temp:
n=n-temp
if i==0:
temp=gcd(a,n)
i=1
else:
temp=gcd(b,n)
i=0
if i==1:
print(0)
else:
print(1)
# In[... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
#!/usr/bin/env python
# coding: utf-8
# In[10]:
a,b,n=map(int,input().split())
def gcd(x,y):
while y>0:
x,y=y,x%y
return x
i=0
temp=0
while n>temp:
n=n-temp
if i==0:
temp=gcd(a,n)
i=1
else:
temp=gcd(b,n)
i=0
if i==1:
print(0)
else:
print(... | 3 | |
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,696,486,380 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 62 | 0 | s = input()
s1 = s.lower()
result = ""
for i in range(len(s1)):
if s1[i] in "aeiou":
continue
else:
result += "." + s1[i]
print(result)
| 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()
s1 = s.lower()
result = ""
for i in range(len(s1)):
if s1[i] in "aeiou":
continue
else:
result += "." + s1[i]
print(result)
``` | 0 | |
743 | C | Vladik and fractions | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form .
Help Vladik with that, i.e for a given *n* find three distinct positive integers *x*, *y* and *z* such that . Because ... | The single line contains single integer *n* (1<=≤<=*n*<=≤<=104). | If the answer exists, print 3 distinct numbers *x*, *y* and *z* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=109, *x*<=≠<=*y*, *x*<=≠<=*z*, *y*<=≠<=*z*). Otherwise print -1.
If there are multiple answers, print any of them. | [
"3\n",
"7\n"
] | [
"2 7 42\n",
"7 8 56\n"
] | none | 1,250 | [
{
"input": "3",
"output": "2 7 42"
},
{
"input": "7",
"output": "7 8 56"
},
{
"input": "2",
"output": "2 3 6"
},
{
"input": "5",
"output": "5 6 30"
},
{
"input": "4",
"output": "4 5 20"
},
{
"input": "7",
"output": "7 8 56"
},
{
"input": "8... | 1,481,990,332 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 62 | 0 | n=int(input())
print(n, n+1, n*(n+1), sep=' ') | Title: Vladik and fractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form .
Help Vladik ... | ```python
n=int(input())
print(n, n+1, n*(n+1), sep=' ')
``` | 0 | |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,638,267,589 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | a=float(input())
if a==123456789123456789.999:
print('GOTO Vasilisa.')
else:
print(round(c))
| Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
a=float(input())
if a==123456789123456789.999:
print('GOTO Vasilisa.')
else:
print(round(c))
``` | -1 |
290 | F | Greedy Petya | PROGRAMMING | 2,800 | [
"*special",
"dfs and similar",
"graphs",
"greedy"
] | null | null | Petya is an unexperienced programming contestant. Recently he has come across the following problem:
You are given a non-directed graph which consists of *n* nodes and *m* edges. Your task is to determine whether the graph contains a Hamiltonian path.
Petya wrote a quick bug-free code which he believes solves this pr... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=20; 0<=≤<=*m*<=≤<=400). Next *m* lines contain pairs of integers *v**i*,<=*u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*). | Follow the format of Petya's code output. | [
"2 3\n1 2\n2 1\n1 1\n",
"3 0\n",
"10 20\n3 10\n4 6\n4 9\n7 5\n8 8\n3 10\n9 7\n5 2\n9 2\n10 6\n10 4\n1 1\n7 2\n8 4\n7 2\n1 8\n5 4\n10 2\n8 5\n5 2\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | none | 0 | [] | 1,664,156,993 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import random as r
a=r.randint(0,1)
if(a==0):
print("Yes")
else:
print("No") | Title: Greedy Petya
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is an unexperienced programming contestant. Recently he has come across the following problem:
You are given a non-directed graph which consists of *n* nodes and *m* edges. Your task is to determine whether the grap... | ```python
import random as r
a=r.randint(0,1)
if(a==0):
print("Yes")
else:
print("No")
``` | 0 | |
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,382,716,971 | 1,971 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 204,800 | n = int(input())
points = list(map(int, input().split()))
yep = False
def func(ar, num):
global yep
for i in range(n - 1):
if (i != num) and i != (num + 1):
if ar[num] < ar[num + 1]:
if ar[i] > ar[num] and ar[i] < ar[num + 1]:
if ar[i + 1] < ar[... | Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
n = int(input())
points = list(map(int, input().split()))
yep = False
def func(ar, num):
global yep
for i in range(n - 1):
if (i != num) and i != (num + 1):
if ar[num] < ar[num + 1]:
if ar[i] > ar[num] and ar[i] < ar[num + 1]:
if ar[i ... | 0 | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,685,790,206 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | s = input()
n = int(input())
| Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
s = input()
n = int(input())
``` | -1 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,655,911,989 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | a, b = input(), input()
print(f"{int(a, base=2) ^ int(b, base=2):0{len(a)}b}")
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a, b = input(), input()
print(f"{int(a, base=2) ^ int(b, base=2):0{len(a)}b}")
``` | 3.9885 |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,671,539,553 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | def show(l):
for i in range(3):
row = ""
for j in range(3):
row+=str(l[i][j])
print(row)
def change(l,i,j):
if l[i][j] == 1:
l[i][j] = 0
else:
l[i][j] = 1
def all01(matrix):
for i in range(3):
for j in range(3):
if matrix[i][j]%2 == 0:
matrix[i][j] = 0
else:
... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
def show(l):
for i in range(3):
row = ""
for j in range(3):
row+=str(l[i][j])
print(row)
def change(l,i,j):
if l[i][j] == 1:
l[i][j] = 0
else:
l[i][j] = 1
def all01(matrix):
for i in range(3):
for j in range(3):
if matrix[i][j]%2 == 0:
matrix[i][j] = 0
... | 3 | |
543 | B | Destroying Roads | PROGRAMMING | 2,100 | [
"constructive algorithms",
"graphs",
"shortest paths"
] | null | null | In some country there are exactly *n* cities and *m* bidirectional roads connecting the cities. Cities are numbered with integers from 1 to *n*. If cities *a* and *b* are connected by a road, then in an hour you can go along this road either from city *a* to city *b*, or from city *b* to city *a*. The road network is s... | The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=3000, ) — the number of cities and roads in the country, respectively.
Next *m* lines contain the descriptions of the roads as pairs of integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). It is guaranteed that the roads that are give... | Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1. | [
"5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n",
"5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n",
"5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1\n"
] | [
"0\n",
"1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2",
"output": "0"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2",
"output": "1"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1",
"output": "-1"
},
{
"input": "9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\... | 1,457,030,685 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 2,560,000 | from queue import Queue
from itertools import combinations_with_replacement
from operator import add, sub, mul, floordiv
#sys.stdin = open("input_py.txt","r")
n, m = map(int, input().split())
G = [ [] for i in range(n)]
for i in range(m):
x, y = map(int, input().split())
x-=1; y-=1
G[x].appe... | Title: Destroying Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some country there are exactly *n* cities and *m* bidirectional roads connecting the cities. Cities are numbered with integers from 1 to *n*. If cities *a* and *b* are connected by a road, then in an hour you can go... | ```python
from queue import Queue
from itertools import combinations_with_replacement
from operator import add, sub, mul, floordiv
#sys.stdin = open("input_py.txt","r")
n, m = map(int, input().split())
G = [ [] for i in range(n)]
for i in range(m):
x, y = map(int, input().split())
x-=1; y-=1
... | 0 | |
554 | B | Ohana Cleans Up | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"strings"
] | null | null | Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square,... | The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100).
The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-t... | The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. | [
"4\n0101\n1000\n1111\n0101\n",
"3\n111\n111\n111\n"
] | [
"2\n",
"3\n"
] | In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything. | 500 | [
{
"input": "4\n0101\n1000\n1111\n0101",
"output": "2"
},
{
"input": "3\n111\n111\n111",
"output": "3"
},
{
"input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "9"
},
{
"input": "1\n1"... | 1,521,406,761 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 78 | 7,065,600 | IL = lambda: list(map(int, input().split()))
I = lambda: int(input())
n = I()
grid = [input() for i in range(n)]
print(max([grid.count(i) for i in set(grid)])) | Title: Ohana Cleans Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very str... | ```python
IL = lambda: list(map(int, input().split()))
I = lambda: int(input())
n = I()
grid = [input() for i in range(n)]
print(max([grid.count(i) for i in set(grid)]))
``` | 3 | |
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000... | 1,658,770,380 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 154 | 0 | for i in range(int(input())):
a = input().split(':')
for j in range(len(a)):
if len(a[j]) == 0:
while len(a) < 8:
a.insert(j, '')
for j in range(8):
a[j] = '0' * (4 - len(a[j])) + a[j]
print(*a, sep=':') | Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. He... | ```python
for i in range(int(input())):
a = input().split(':')
for j in range(len(a)):
if len(a[j]) == 0:
while len(a) < 8:
a.insert(j, '')
for j in range(8):
a[j] = '0' * (4 - len(a[j])) + a[j]
print(*a, sep=':')
``` | 0 | |
687 | B | Remainders Game | PROGRAMMING | 1,800 | [
"chinese remainder theorem",
"math",
"number theory"
] | null | null | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000). | Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. | [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" ... | 1,000 | [
{
"input": "4 5\n2 3 5 12",
"output": "Yes"
},
{
"input": "2 7\n2 3",
"output": "No"
},
{
"input": "1 6\n8",
"output": "No"
},
{
"input": "2 3\n9 4",
"output": "Yes"
},
{
"input": "4 16\n19 16 13 9",
"output": "Yes"
},
{
"input": "5 10\n5 16 19 9 17",
... | 1,621,648,254 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 139 | 7,884,800 | n,x = map(int,input().split())
cop = x
v = list(map(int,input().split()))
N = int(1e6+5)
m = [1] * N
for i in range(3,N,2):
if i*i>=N: break
if m[i]:
for j in range(i*i, N, i): m[j]=0
primes = [2]
for i in range(3,N,2):
if m[i]: primes.append(i)
ok = set()
for i in primes:
i... | Title: Remainders Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*... | ```python
n,x = map(int,input().split())
cop = x
v = list(map(int,input().split()))
N = int(1e6+5)
m = [1] * N
for i in range(3,N,2):
if i*i>=N: break
if m[i]:
for j in range(i*i, N, i): m[j]=0
primes = [2]
for i in range(3,N,2):
if m[i]: primes.append(i)
ok = set()
for i in prim... | 0 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,619,703,440 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 78 | 0 | num=int(input())
lst=list(map(int,input().split()))[:num]
a=set(lst)
if 0 in a:
print(len(a)-1)
else:
print(len(a))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
num=int(input())
lst=list(map(int,input().split()))[:num]
a=set(lst)
if 0 in a:
print(len(a)-1)
else:
print(len(a))
``` | 3 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,693,310,761 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 12,390,400 | n = int(input())
elements = list(map(int,input().split()))
m = int(input())
queries = list(map(int,input().split()))
vasya_count = 0
petya_count = 0
for element in queries:
for i in range(n):
if element != elements[i]:
vasya_count+=1
else:
vasya_count+=1
... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
elements = list(map(int,input().split()))
m = int(input())
queries = list(map(int,input().split()))
vasya_count = 0
petya_count = 0
for element in queries:
for i in range(n):
if element != elements[i]:
vasya_count+=1
else:
vasya_count+=1
... | 0 | |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,699,008,713 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,k=map(int,input().split())
scores=list(map(int,input().split())
c = 0
for it in scores:
if it >=scores[k-1]and it != 0:
c=c+1
print(c) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n,k=map(int,input().split())
scores=list(map(int,input().split())
c = 0
for it in scores:
if it >=scores[k-1]and it != 0:
c=c+1
print(c)
``` | -1 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,602,352,472 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 307,200 | from sys import stdin
def can_equilibrate(initial: str, remaining: str):
if (len(initial) - 1 + len(remaining)) % 2 != 0:
print("Impossible")
return
left, right = initial.split("|")
while len(left) < len(right):
if not remaining:
print("Impossible")
return
... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
from sys import stdin
def can_equilibrate(initial: str, remaining: str):
if (len(initial) - 1 + len(remaining)) % 2 != 0:
print("Impossible")
return
left, right = initial.split("|")
while len(left) < len(right):
if not remaining:
print("Impossible")
... | 3 | |
938 | B | Run For Your Prize | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. | Print one integer — the minimum number of seconds it will take to collect all prizes. | [
"3\n2 3 9\n",
"2\n2 999995\n"
] | [
"8\n",
"5\n"
] | In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | 0 | [
{
"input": "3\n2 3 9",
"output": "8"
},
{
"input": "2\n2 999995",
"output": "5"
},
{
"input": "1\n20",
"output": "19"
},
{
"input": "6\n2 3 500000 999997 999998 999999",
"output": "499999"
},
{
"input": "1\n999999",
"output": "1"
},
{
"input": "1\n5100... | 1,682,105,263 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 171 | 7,372,800 | n = int(input())
a = list(map(int, input().split()))
cA=1
cB=int(1e6)
mx=0
for i in range(n):
x = abs(cA-a[i])
y = abs(cB-a[i])
mx=max(mx, min(x, y))
print(mx)
| Title: Run For Your Prize
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di... | ```python
n = int(input())
a = list(map(int, input().split()))
cA=1
cB=int(1e6)
mx=0
for i in range(n):
x = abs(cA-a[i])
y = abs(cB-a[i])
mx=max(mx, min(x, y))
print(mx)
``` | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,675,855,140 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | a=int(input())
s1=0
for i in range(1,a):
s1+=a%i<1
print(s1)
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
a=int(input())
s1=0
for i in range(1,a):
s1+=a%i<1
print(s1)
``` | 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,606,627,857 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 218 | 0 | n = int(input())
n += 1
nf = list(map(int, input().split()))
summ = sum(nf)
if summ%n == 0:
print(2)
elif summ%n <= n-1:
print(1)
| 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())
n += 1
nf = list(map(int, input().split()))
summ = sum(nf)
if summ%n == 0:
print(2)
elif summ%n <= n-1:
print(1)
``` | 0 | |
218 | A | Mountain Scenery | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting th... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the gi... | Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. | [
"3 2\n0 5 3 5 1 5 2\n",
"1 1\n0 2 0\n"
] | [
"0 5 3 4 1 4 2 \n",
"0 1 0 \n"
] | none | 500 | [
{
"input": "3 2\n0 5 3 5 1 5 2",
"output": "0 5 3 4 1 4 2 "
},
{
"input": "1 1\n0 2 0",
"output": "0 1 0 "
},
{
"input": "1 1\n1 100 0",
"output": "1 99 0 "
},
{
"input": "3 1\n0 1 0 1 0 2 0",
"output": "0 1 0 1 0 1 0 "
},
{
"input": "3 1\n0 1 0 2 0 1 0",
"out... | 1,667,341,914 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n,k = [int(n) for n in input().split()]
r = [int(r) for r in input().split()]
i = 1
while k > 0:
r[i] = r[i]-1
i = i + 2
k = k - 1
print(*r,sep=" ") | Title: Mountain Scenery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordi... | ```python
n,k = [int(n) for n in input().split()]
r = [int(r) for r in input().split()]
i = 1
while k > 0:
r[i] = r[i]-1
i = i + 2
k = k - 1
print(*r,sep=" ")
``` | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,669,462,411 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | number = int(input())
lst = [int(i) for i in input().split()]
sereja = dima = 0
flip = True
for i in range(len(lst)):
if flip:
if len(lst) > 1 and lst[0] > lst[-1]:
sereja += lst[0]
lst.pop(0)
else:
sereja += lst[-1]
lst.pop(-1)
... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
number = int(input())
lst = [int(i) for i in input().split()]
sereja = dima = 0
flip = True
for i in range(len(lst)):
if flip:
if len(lst) > 1 and lst[0] > lst[-1]:
sereja += lst[0]
lst.pop(0)
else:
sereja += lst[-1]
lst.pop(-1... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,658,551,130 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | N , M=map(int,input().split())
print(( N*M ) // 2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
N , M=map(int,input().split())
print(( N*M ) // 2)
``` | 3.977 |
440 | B | Balancer | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired c... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50000). The second line contains *n* non-negative numbers that do not exceed 109, the *i*-th written number is the number of matches in the *i*-th matchbox. It is guaranteed that the total number of matches is divisible by *n*. | Print the total minimum number of moves. | [
"6\n1 6 2 5 3 7\n"
] | [
"12\n"
] | none | 1,000 | [
{
"input": "6\n1 6 2 5 3 7",
"output": "12"
},
{
"input": "6\n6 6 6 0 0 0",
"output": "27"
},
{
"input": "6\n0 0 0 6 6 6",
"output": "27"
},
{
"input": "6\n6 6 0 0 6 6",
"output": "12"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "10\n0 10... | 1,517,162,927 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 140 | 9,728,000 | #from dust i have come dust i will be
n=int(input())
a=list(map(int,input().split()))
t=0
for i in range(n):
t+=a[i]
t=t//n
cnt=0
for i in range(n):
if a[i]>t:
a[i+1]+=abs(a[i]-t)
cnt+=(abs(a[i]-t))
elif a[i]<t:
a[i+1]-=abs(a[i]-t)
cnt+=(abs(a[i]-t))
print(cnt)
... | Title: Balancer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its ... | ```python
#from dust i have come dust i will be
n=int(input())
a=list(map(int,input().split()))
t=0
for i in range(n):
t+=a[i]
t=t//n
cnt=0
for i in range(n):
if a[i]>t:
a[i+1]+=abs(a[i]-t)
cnt+=(abs(a[i]-t))
elif a[i]<t:
a[i+1]-=abs(a[i]-t)
cnt+=(abs(a[i]-t))
print(cnt... | 3 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,650,695,838 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 1,481 | 17,203,200 |
n=int(input())
arr1=list(map(int,input().split()))
arr2=arr1.copy()
arr2.sort()
pre1=[0 for i in range(n)]
pre2=[0 for i in range(n)]
sm1=0
sm2=0
for i in range(n):
sm1+=arr1[i]
sm2+=arr2[i]
pre1[i]=sm1
pre2[i]=sm2
Q=int(input())
for i in range(Q):
x,a,... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n=int(input())
arr1=list(map(int,input().split()))
arr2=arr1.copy()
arr2.sort()
pre1=[0 for i in range(n)]
pre2=[0 for i in range(n)]
sm1=0
sm2=0
for i in range(n):
sm1+=arr1[i]
sm2+=arr2[i]
pre1[i]=sm1
pre2[i]=sm2
Q=int(input())
for i in range(Q):
... | 3 | |
24 | C | Sequence of points | PROGRAMMING | 1,800 | [
"geometry",
"implementation",
"math"
] | C. Sequence of points | 2 | 256 | You are given the following points with integer coordinates on the plane: *M*0,<=*A*0,<=*A*1,<=...,<=*A**n*<=-<=1, where *n* is odd number. Now we define the following infinite sequence of points *M**i*: *M**i* is symmetric to *M**i*<=-<=1 according (for every natural number *i*). Here point *B* is symmetric to *A* ac... | On the first line you will be given an integer *n* (1<=≤<=*n*<=≤<=105), which will be odd, and *j* (1<=≤<=*j*<=≤<=1018), where *j* is the index of the desired point. The next line contains two space separated integers, the coordinates of *M*0. After that *n* lines follow, where the *i*-th line contain the space separat... | On a single line output the coordinates of *M**j*, space separated. | [
"3 4\n0 0\n1 1\n2 3\n-5 3\n",
"3 1\n5 5\n1000 1000\n-1000 1000\n3 100\n"
] | [
"14 0\n",
"1995 1995\n"
] | none | 0 | [
{
"input": "3 4\n0 0\n1 1\n2 3\n-5 3",
"output": "14 0"
},
{
"input": "3 1\n5 5\n1000 1000\n-1000 1000\n3 100",
"output": "1995 1995"
},
{
"input": "1 1\n-1000 -1000\n1000 1000",
"output": "3000 3000"
},
{
"input": "1 1000000000000000000\n-1000 1000\n1000 -1000",
"output"... | 1,688,810,146 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 23 | 310 | 14,643,200 | from sys import stdin
N, J = [int(w) for w in stdin.readline().split()]
J = J % (N + N)
points = []
x, y = [int(w) for w in stdin.readline().split()]
for _ in range(N):
points.append([int(w) for w in stdin.readline().split()])
for i in range(J):
i %= N
x += (points[i][0] - x) * 2
y += (points[i]... | Title: Sequence of points
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given the following points with integer coordinates on the plane: *M*0,<=*A*0,<=*A*1,<=...,<=*A**n*<=-<=1, where *n* is odd number. Now we define the following infinite sequence of points *M**i*: *M**i* is symmet... | ```python
from sys import stdin
N, J = [int(w) for w in stdin.readline().split()]
J = J % (N + N)
points = []
x, y = [int(w) for w in stdin.readline().split()]
for _ in range(N):
points.append([int(w) for w in stdin.readline().split()])
for i in range(J):
i %= N
x += (points[i][0] - x) * 2
y += ... | 3.895225 |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,659,443,094 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 1,000 | 0 | a,b=map(int,input().split())
c=list(map(int,input().split()))
i=1
count=0
while i<a:
while c[i]<=c[i-1]:
c[i]+=b
count+=1
i+=1
print(count)
| Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
a,b=map(int,input().split())
c=list(map(int,input().split()))
i=1
count=0
while i<a:
while c[i]<=c[i-1]:
c[i]+=b
count+=1
i+=1
print(count)
``` | 0 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,666,019,934 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | #!/usr/bin/env python
# coding: utf-8
# In[ ]:
N, M = input().split()
print(N * M // 2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
N, M = input().split()
print(N * M // 2)
``` | -1 |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,618,212,964 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 102,400 | from collections import Counter
from collections import Counter
import math
def solve():
n=int(input())
array=[int(i) for i in input().split()]
count=Counter(array)
return math.ceil(n/len(count))
print(solve()) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
from collections import Counter
from collections import Counter
import math
def solve():
n=int(input())
array=[int(i) for i in input().split()]
count=Counter(array)
return math.ceil(n/len(count))
print(solve())
``` | 0 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,696,927,203 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | input()
l=list(map(int,input().split()))
l.sort(reverse=True)
a=sum(l)
sum=0
for i in range(len(l)):
sum+=l[i]
if sum>(a/2):
print(i+1)
break | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
input()
l=list(map(int,input().split()))
l.sort(reverse=True)
a=sum(l)
sum=0
for i in range(len(l)):
sum+=l[i]
if sum>(a/2):
print(i+1)
break
``` | 3 | |
197 | A | Plate Game | PROGRAMMING | 1,600 | [
"constructive algorithms",
"games",
"math"
] | null | null | You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located with... | A single line contains three space-separated integers *a*, *b*, *r* (1<=≤<=*a*,<=*b*,<=*r*<=≤<=100) — the table sides and the plates' radius, correspondingly. | If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes). | [
"5 5 2\n",
"6 7 4\n"
] | [
"First\n",
"Second\n"
] | In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses.
In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move. | 1,000 | [
{
"input": "5 5 2",
"output": "First"
},
{
"input": "6 7 4",
"output": "Second"
},
{
"input": "100 100 1",
"output": "First"
},
{
"input": "1 1 100",
"output": "Second"
},
{
"input": "13 7 3",
"output": "First"
},
{
"input": "23 7 3",
"output": "Fi... | 1,649,841,421 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | a,b,c = map(int, input().split())
x,y = a * b, (c * 2) ** 2
for i in range(9999999999999999999999999999999999999999):
x -= y
if x < 0:
print("First" if i % 2 == 1 else "Second")
break | Title: Plate Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie o... | ```python
a,b,c = map(int, input().split())
x,y = a * b, (c * 2) ** 2
for i in range(9999999999999999999999999999999999999999):
x -= y
if x < 0:
print("First" if i % 2 == 1 else "Second")
break
``` | 0 | |
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,657,937,731 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 248 | 10,035,200 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
d1 = list(reversed(range(1, m//2 + 1)))
if m % 2 == 0:
d2 = list(range(m//2 + 1, m+1))
d = []
else:
d2 = list(range(m//2 + 2, m+1))
d = [m//2 + 1]
for i in range(m//2):
d.append(d1[i])
d.append(d2[i])
i = 0
... | 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
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
d1 = list(reversed(range(1, m//2 + 1)))
if m % 2 == 0:
d2 = list(range(m//2 + 1, m+1))
d = []
else:
d2 = list(range(m//2 + 2, m+1))
d = [m//2 + 1]
for i in range(m//2):
d.append(d1[i])
d.append(d2[i])
... | 3 | |
601 | D | Acyclic Organic Compounds | PROGRAMMING | 2,400 | [
"data structures",
"dfs and similar",
"dsu",
"hashing",
"strings",
"trees"
] | null | null | You are given a tree *T* with *n* vertices (numbered 1 through *n*) and a letter in each vertex. The tree is rooted at vertex 1.
Let's look at the subtree *T**v* of some vertex *v*. It is possible to read a string along each simple path starting at *v* and ending at some vertex in *T**v* (possibly *v* itself). Let's d... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=300<=000) — the number of vertices of the tree.
The second line contains *n* space-separated integers *c**i* (0<=≤<=*c**i*<=≤<=109).
The third line contains a string *s* consisting of *n* lowercase English letters — the *i*-th character of this strin... | Print two lines.
On the first line, print over all 1<=≤<=*i*<=≤<=*n*.
On the second line, print the number of vertices *v* for which . | [
"10\n1 2 7 20 20 30 40 50 50 50\ncacabbcddd\n1 2\n6 8\n7 2\n6 2\n5 4\n5 9\n3 10\n2 5\n2 3\n",
"6\n0 2 4 1 1 1\nraaaba\n1 2\n2 3\n2 4\n2 5\n3 6\n"
] | [
"51\n3\n",
"6\n2\n"
] | In the first sample, the tree looks like this:
The sets of strings that can be read from individual vertices are:
Finally, the values of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/14691bbbb07694ceb84c7c73aa24a29ecfcb9e6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> are:
In t... | 2,000 | [
{
"input": "10\n1 2 7 20 20 30 40 50 50 50\ncacabbcddd\n1 2\n6 8\n7 2\n6 2\n5 4\n5 9\n3 10\n2 5\n2 3",
"output": "51\n3"
},
{
"input": "6\n0 2 4 1 1 1\nraaaba\n1 2\n2 3\n2 4\n2 5\n3 6",
"output": "6\n2"
},
{
"input": "16\n186427765 186427335 186426882 186427151 186427355 186427547 186427... | 1,693,000,104 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1693000104.8434772")# 1693000104.8434937 | Title: Acyclic Organic Compounds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tree *T* with *n* vertices (numbered 1 through *n*) and a letter in each vertex. The tree is rooted at vertex 1.
Let's look at the subtree *T**v* of some vertex *v*. It is possible to read a s... | ```python
print("_RANDOM_GUESS_1693000104.8434772")# 1693000104.8434937
``` | 0 | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,639,137,523 | 2,147,483,647 | Python 3 | OK | TESTS | 8 | 46 | 0 | for _ in range(int(input())):
x = int(input())
c3 = 0
while c3 * 3 <= x:
c7 = 0
while c3 * 3 + c7 * 7 < x:
c7 += 1
if c3 * 3 + c7 * 7 == x:
print("YES")
break
c3 += 1
else:
print("NO") | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
for _ in range(int(input())):
x = int(input())
c3 = 0
while c3 * 3 <= x:
c7 = 0
while c3 * 3 + c7 * 7 < x:
c7 += 1
if c3 * 3 + c7 * 7 == x:
print("YES")
break
c3 += 1
else:
print("NO")
``` | 3 | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,638,303,681 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | chaine=input().split(" ")
x=int(chaine[0])
y=int(chaine[1])
chaine2=list(map(int,input().strip().split(" ")))[:x]
for i in range(0,y):
ind=chaine2.index(min(chaine2))
if chaine2[ind]>0:
break
else:
chaine2[ind]*=-1
print(sum(chaine2)) | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
chaine=input().split(" ")
x=int(chaine[0])
y=int(chaine[1])
chaine2=list(map(int,input().strip().split(" ")))[:x]
for i in range(0,y):
ind=chaine2.index(min(chaine2))
if chaine2[ind]>0:
break
else:
chaine2[ind]*=-1
print(sum(chaine2))
``` | 0 | |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,689,333,460 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 62 | 0 | import sys
input = sys.stdin.readline
n = int(input())
boys = sorted(map(int, input().split()))
m = int(input())
girls = sorted(map(int, input().split()))
i, j, pairs = 0, 0, 0
while i < n and j < m:
if abs(boys[i] - girls[j]) <= 1:
pairs += 1
i += 1
j += 1
elif boys[i] <... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
import sys
input = sys.stdin.readline
n = int(input())
boys = sorted(map(int, input().split()))
m = int(input())
girls = sorted(map(int, input().split()))
i, j, pairs = 0, 0, 0
while i < n and j < m:
if abs(boys[i] - girls[j]) <= 1:
pairs += 1
i += 1
j += 1
elif... | 3 | |
718 | A | Efim and Strange Grade | PROGRAMMING | 1,700 | [
"dp",
"implementation",
"math"
] | null | null | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | The first line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*t*<=≤<=109) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least on... | Print the maximum grade that Efim can get in *t* seconds. Do not print trailing zeroes. | [
"6 1\n10.245\n",
"6 2\n10.245\n",
"3 100\n9.2\n"
] | [
"10.25\n",
"10.3\n",
"9.2\n"
] | In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | 500 | [
{
"input": "6 1\n10.245",
"output": "10.25"
},
{
"input": "6 2\n10.245",
"output": "10.3"
},
{
"input": "3 100\n9.2",
"output": "9.2"
},
{
"input": "12 5\n872.04488525",
"output": "872.1"
},
{
"input": "35 8\n984227318.2031144444444444494637612",
"output": "98... | 1,509,940,479 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def main(n, t, g):
def round(g):
if g[-2] == '.':
return g
l = list(g)
if int(l[-1]) < 5:
down = l[:-1]
return ''.join(down)
else:
last_digit = g[-1]
up = l[:-1]
up[-1] = str(int(up[-1]) + 1)
return '... | Title: Efim and Strange Grade
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Th... | ```python
def main(n, t, g):
def round(g):
if g[-2] == '.':
return g
l = list(g)
if int(l[-1]) < 5:
down = l[:-1]
return ''.join(down)
else:
last_digit = g[-1]
up = l[:-1]
up[-1] = str(int(up[-1]) + 1)
... | -1 | |
127 | B | Canvas Frames | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | [
"5\n2 4 3 2 3\n",
"13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n",
"4\n3 3 3 5\n"
] | [
"1",
"3",
"0"
] | none | 1,000 | [
{
"input": "5\n2 4 3 2 3",
"output": "1"
},
{
"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9",
"output": "3"
},
{
"input": "4\n3 3 3 5",
"output": "0"
},
{
"input": "2\n3 5",
"output": "0"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "14\... | 1,587,736,833 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 109 | 307,200 | def merge(lst1, lst2):
i = 0
j = 0
arr = []
while i < len(lst1) and j < len(lst2):
if lst1[i] < lst2[j]:
arr.append(lst1[i])
i += 1
else:
arr.append(lst2[j])
j += 1
while i < len(lst1):
arr.append(lst1[i])
i... | Title: Canvas Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin w... | ```python
def merge(lst1, lst2):
i = 0
j = 0
arr = []
while i < len(lst1) and j < len(lst2):
if lst1[i] < lst2[j]:
arr.append(lst1[i])
i += 1
else:
arr.append(lst2[j])
j += 1
while i < len(lst1):
arr.append(lst1[i])
... | 3 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,651,940,339 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 92 | 0 | n=int(input())
c=[]
for i in range(n):
x,y=map(str,input().split())
a=x+y
c.append(a)
print(len(set(c)))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
n=int(input())
c=[]
for i in range(n):
x,y=map(str,input().split())
a=x+y
c.append(a)
print(len(set(c)))
``` | 0 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,613,995,249 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 186 | 0 | n = int(input())
d={}
for i in range(n):
s = input()
if d.get(s,False)==False:
d[s]=0
d[s]+=1
m=0
ans=""
for i in d:
if d[i]>m:
ans=i
m=d[i]
print(ans)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
d={}
for i in range(n):
s = input()
if d.get(s,False)==False:
d[s]=0
d[s]+=1
m=0
ans=""
for i in d:
if d[i]>m:
ans=i
m=d[i]
print(ans)
``` | 3.9535 |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,589,803,760 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 140 | 20,172,800 | n = input()
m = []
for i in range(len(n)):
if n[i] == '4':
m.append('0')
else:
m.append('1')
ans = 2*(2**(len(m)-1) - 1) + int(''.join(m), 2) + 1
print(ans) | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
n = input()
m = []
for i in range(len(n)):
if n[i] == '4':
m.append('0')
else:
m.append('1')
ans = 2*(2**(len(m)-1) - 1) + int(''.join(m), 2) + 1
print(ans)
``` | 3 | |
821 | E | Okabe and El Psy Kongroo | PROGRAMMING | 2,100 | [
"dp",
"matrices"
] | null | null | Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (*x*,<=*y*) such that *x* and *y* are non-negative. Okabe starts at the origin (point (0,<=0)), and n... | The first line of input contains the integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1018) — the number of segments and the destination *x* coordinate.
The next *n* lines contain three space-separated integers *a**i*, *b**i*, and *c**i* (0<=≤<=*a**i*<=<<=*b**i*<=≤<=1018, 0<=≤<=*c**i*<=≤<=15) — the left and r... | Print the number of walks satisfying the conditions, modulo 1000000007 (109<=+<=7). | [
"1 3\n0 3 3\n",
"2 6\n0 3 0\n3 10 2\n"
] | [
"4\n",
"4\n"
] | The graph above corresponds to sample 1. The possible walks are:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7fcce410dbd2cf4e427a6b50e0f159b7ce538901.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/... | 2,500 | [
{
"input": "1 3\n0 3 3",
"output": "4"
},
{
"input": "2 6\n0 3 0\n3 10 2",
"output": "4"
},
{
"input": "2 3\n0 2 13\n2 3 11",
"output": "4"
},
{
"input": "2 9\n0 8 0\n8 10 10",
"output": "1"
},
{
"input": "1 1\n0 3 9",
"output": "1"
},
{
"input": "3 8\... | 1,692,285,885 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692285885.6478148")# 1692285885.6478326 | Title: Okabe and El Psy Kongroo
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as al... | ```python
print("_RANDOM_GUESS_1692285885.6478148")# 1692285885.6478326
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,661,966,097 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n, m, a = [int(i) for i in input().split(" ")]
flag_stones_required = 0
while n > 0:
n = n - a
flag_stones_required += 1
while m > 0:
m = m - a
flag_stones_required += 1
print(flag_stones_required) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = [int(i) for i in input().split(" ")]
flag_stones_required = 0
while n > 0:
n = n - a
flag_stones_required += 1
while m > 0:
m = m - a
flag_stones_required += 1
print(flag_stones_required)
``` | 0 |
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per... | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n99... | 1,628,166,414 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 77 | 6,963,200 | k = int(input())
board = {"1": 0, "2": 0, "3": 0, "4": 0,
"5": 0, "6": 0, "7": 0, "8": 0, "9": 0}
for i in range(4):
row = input()
for j in range(4):
if row[j] != '.':
board[row[j]] = board[row[j]]+1
if max(board.values()) <= 2*k:
print("YES")
else:
print("NO")
| Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preff... | ```python
k = int(input())
board = {"1": 0, "2": 0, "3": 0, "4": 0,
"5": 0, "6": 0, "7": 0, "8": 0, "9": 0}
for i in range(4):
row = input()
for j in range(4):
if row[j] != '.':
board[row[j]] = board[row[j]]+1
if max(board.values()) <= 2*k:
print("YES")
else:
prin... | 3 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,679,212,572 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | n,m=list(map(int,input().split()))
s1='#'*m
s2='.'*(m-1)+'#'
s3='#'+'.'*(m-1)
for i in range(n):
k=i%4
if k==0 or k==2 :
print(s1)
elif k==1:
print(s2)
else:
print(s3)
| Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
n,m=list(map(int,input().split()))
s1='#'*m
s2='.'*(m-1)+'#'
s3='#'+'.'*(m-1)
for i in range(n):
k=i%4
if k==0 or k==2 :
print(s1)
elif k==1:
print(s2)
else:
print(s3)
``` | 3 | |
952 | B | A Map of the Cat | PROGRAMMING | 1,900 | [
"brute force",
"interactive"
] | null | null | If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal... | none | none | [] | [] | Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. | 0 | [
{
"input": "5 0 1 2 5 3 5 4 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 5 6 6 7 8 9 10 11",
"output": "Correct answer 'grumpy'"
},
{
"input": "10 6 5 7 5 6 11 5 8 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "7 10 8 9 6 5 5 11 5 6",
"output": "Co... | 1,573,218,367 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | import sys
print(1,flush=True)
t = sys.stdin.readline().split()
print('grumpy',flush=True) | Title: A Map of the Cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from ... | ```python
import sys
print(1,flush=True)
t = sys.stdin.readline().split()
print('grumpy',flush=True)
``` | 0 | |
730 | L | Expression Queries | PROGRAMMING | 3,200 | [
"data structures"
] | null | null | A simplified arithmetic expression (SAE) is an arithmetic expression defined by the following grammar:
- <SAE> ::= <Number> | <SAE>+<SAE> | <SAE>*<SAE> | (<SAE>) - <Number> ::= <Digit> | <Digit><Number> - <Digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 |... | The first line of the input contains non-empty string *s* (1<=≤<=|*s*|<=≤<=4·105) which represents a correct SAE. Each character of the string can be one of the following characters: '*', '+', '(', ')' or a digit ('0'-'9'). The expression might contain extra-huge numbers.
The second line contains an integer *m* (1<=≤<... | The *i*-th number of output should be the answer for the *i*-th query. If the *i*-th query corresponds to a valid sub-expression output the value of the sub-expression modulo 1000000007 (109<=+<=7). Otherwise output -1 as an answer for the query. Print numbers on separate lines. | [
"((1+2)*3+101*2)\n6\n8 14\n1 6\n2 10\n11 14\n5 5\n4 5\n",
"(01)\n1\n1 4\n"
] | [
"205\n-1\n10\n2\n2\n-1\n",
"1\n"
] | none | 0 | [] | 1,599,390,236 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 4,000 | 20,992,000 | sae = input()
revers = reversed
def Findind(exn):
index = 0
for number in exn:
if number not in ["*","+","-"]:
index += 1
else:
return index
return index
def ExecuteOP(exn, op_):
ind = exn.index(op_)
rP = exn[ind + 1:]
lP = exn[:ind]
indexRight =... | Title: Expression Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simplified arithmetic expression (SAE) is an arithmetic expression defined by the following grammar:
- <SAE> ::= <Number> | <SAE>+<SAE> | <SAE>*<SAE> | (<SAE>) - <Num... | ```python
sae = input()
revers = reversed
def Findind(exn):
index = 0
for number in exn:
if number not in ["*","+","-"]:
index += 1
else:
return index
return index
def ExecuteOP(exn, op_):
ind = exn.index(op_)
rP = exn[ind + 1:]
lP = exn[:ind]
in... | 0 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,678,574,540 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 77 | 5,324,800 | n = int(input())
crime = list(map(int, input().split()))
recruit = 0
untreated = 0
for i in range(n):
if crime[i] > 0:
recruit += crime[i]
else:
if recruit > 0:
recruit -= 1
else:
untreated += 1
print(untreated) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
n = int(input())
crime = list(map(int, input().split()))
recruit = 0
untreated = 0
for i in range(n):
if crime[i] > 0:
recruit += crime[i]
else:
if recruit > 0:
recruit -= 1
else:
untreated += 1
print(untreated)
``` | 3 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,617,471,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | x, y = input(), input()
print(1) | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
x, y = input(), input()
print(1)
``` | 0 | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,598,618,937 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 307,200 | s = input()
m = int(input())
ans = ''
current_time = (int(s[0]) * 10 + int(s[1])) * 60 + int(s[3]) * 10 + int(s[4]) + m
hours, mins = current_time // 60, current_time % 60
if hours >= 24:
hours -= 24
if hours == 0:
ans += '00:'
elif hours > 0 and hours < 10:
ans += '0' + str(hours) + ':'
elif hou... | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
s = input()
m = int(input())
ans = ''
current_time = (int(s[0]) * 10 + int(s[1])) * 60 + int(s[3]) * 10 + int(s[4]) + m
hours, mins = current_time // 60, current_time % 60
if hours >= 24:
hours -= 24
if hours == 0:
ans += '00:'
elif hours > 0 and hours < 10:
ans += '0' + str(hours) + ':'... | 0 | |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,598,460,234 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 0 | n=int(input())
i=1
s=0
l=[]
while(s<n):
s=s+i
l.append(i)
i=i+1
if(s==n):
break
elif(s>n):
s=s-i
l.pop()
break
else:
pass
print(len(l))
l.pop()
l.append(n-(sum(l)))
print(*l) | Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
n=int(input())
i=1
s=0
l=[]
while(s<n):
s=s+i
l.append(i)
i=i+1
if(s==n):
break
elif(s>n):
s=s-i
l.pop()
break
else:
pass
print(len(l))
l.pop()
l.append(n-(sum(l)))
print(*l)
``` | 3 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,590,157,728 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 248 | 307,200 | def inp():
ls=list(map(int,input().split()))
return ls
t=int(input())
ls=inp()
ans=[0]*len(set(ls))
all=list(set(ls))
for i in range(len(set(ls))):
for j in range(t):
if all[i]==ls[j]:
ans[i]+=1
#print(ans)
for i in ans:
if i>(t+1)//2:
print("NO")
exit(... | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
def inp():
ls=list(map(int,input().split()))
return ls
t=int(input())
ls=inp()
ans=[0]*len(set(ls))
all=list(set(ls))
for i in range(len(set(ls))):
for j in range(t):
if all[i]==ls[j]:
ans[i]+=1
#print(ans)
for i in ans:
if i>(t+1)//2:
print("NO")
... | 3 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,698,077,668 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | import math
def total_tiredness(a,b):
x = math.ceil((a+b)/2)
sum_of_tiredness = 0
for i in range(1,abs(a-x)+1):
sum_of_tiredness += i
for j in range(1,abs(b-x)+1):
sum_of_tiredness += j
return sum_of_tiredness
a = int(input())
b = int(input())
if 1<=a<=1000 and 1<=b<=1000 ... | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
import math
def total_tiredness(a,b):
x = math.ceil((a+b)/2)
sum_of_tiredness = 0
for i in range(1,abs(a-x)+1):
sum_of_tiredness += i
for j in range(1,abs(b-x)+1):
sum_of_tiredness += j
return sum_of_tiredness
a = int(input())
b = int(input())
if 1<=a<=1000 and 1... | 3 | |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,618,258,841 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 420 | 12,595,200 | import math
def main():
n, m = map(int,input().split())
arr = list(map(int,input().split()))
adj = [[] for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
visited = [False] * n
def dfs(s):
... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
import math
def main():
n, m = map(int,input().split())
arr = list(map(int,input().split()))
adj = [[] for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
visited = [False] * n
def dfs(s)... | 0 | |
234 | B | Reading | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very lig... | The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*k*<=≤<=*n*) — the number of hours on the train and the number of hours to read, correspondingly. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100), *a**i* is the light level at the *i*-th hour. | In the first output line print the minimum light level Vasya will read at. In the second line print *k* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**k*, — the indexes of hours Vasya will read at (1<=≤<=*b**i*<=≤<=*n*). The hours are indexed starting from 1. If there are multiple optimal solutions, print an... | [
"5 3\n20 10 30 40 10\n",
"6 5\n90 20 35 40 60 100\n"
] | [
"20\n1 3 4 \n",
"35\n1 3 4 5 6 \n"
] | In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20. | 0 | [
{
"input": "5 3\n20 10 30 40 10",
"output": "20\n1 3 4 "
},
{
"input": "6 5\n90 20 35 40 60 100",
"output": "35\n1 3 4 5 6 "
},
{
"input": "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 2... | 1,696,907,899 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | # python F.py <input.txt> output.txt
from sys import stdin
def solucion(luz:list , ind:list,n:int,k:int):
for x in range(n):
for y in range(n-x-1):
if (luz[y]>luz[y+1]):
temp = luz[y]
temp2 = ind[y]
luz[y] = luz[y+1]
ind[y] = i... | Title: Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every ho... | ```python
# python F.py <input.txt> output.txt
from sys import stdin
def solucion(luz:list , ind:list,n:int,k:int):
for x in range(n):
for y in range(n-x-1):
if (luz[y]>luz[y+1]):
temp = luz[y]
temp2 = ind[y]
luz[y] = luz[y+1]
... | -1 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,591,123,609 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 218 | 0 | s=input()
c=input()
ans=0
for i in c:
if i==s[ans]:
ans+=1
print(ans+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s=input()
c=input()
ans=0
for i in c:
if i==s[ans]:
ans+=1
print(ans+1)
``` | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,624,514,031 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 156 | 0 | g = input()
i = input().split()
print(max(map(i.count, i)), len(set(i))) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
g = input()
i = input().split()
print(max(map(i.count, i)), len(set(i)))
``` | 3.961 |
321 | C | Ciel the Commander | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer",
"greedy",
"trees"
] | null | null | Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Tree Land.
Each of the following *n*<=-<=1 lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*) — they mean that there will be an undirected road between *a* and *b*. Consider all the cities are numbered fro... | If there is a valid plane, output *n* space-separated characters in a line — *i*-th character is the rank of officer in the city with number *i*.
Otherwise output "Impossible!". | [
"4\n1 2\n1 3\n1 4\n",
"10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n"
] | [
"A B B B\n",
"D C B A D C B D C D\n"
] | In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution. | 1,500 | [
{
"input": "4\n1 2\n1 3\n1 4",
"output": "A B B B"
},
{
"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10",
"output": "D C B A D C B D C D"
},
{
"input": "6\n1 2\n2 4\n4 5\n6 4\n3 2",
"output": "B A B B C C"
},
{
"input": "2\n2 1",
"output": "A B"
},
{
"i... | 1,640,963,500 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 966 | 28,364,800 | def centroid_tree_decomposition(graph):
n = len(graph)
graph = [c[:] for c in graph] # copy
bfs = [0]
for node in bfs:
bfs += graph[node]
for nei in graph[node]:
graph[nei].remove(node)
size = [0] * n
for node in reversed(bfs):
size[node] = 1 + sum(s... | Title: Ciel the Commander
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to... | ```python
def centroid_tree_decomposition(graph):
n = len(graph)
graph = [c[:] for c in graph] # copy
bfs = [0]
for node in bfs:
bfs += graph[node]
for nei in graph[node]:
graph[nei].remove(node)
size = [0] * n
for node in reversed(bfs):
size[node] =... | 3 | |
479 | C | Exams | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.
According to the schedule, a st... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take.
Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=<<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i... | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | [
"3\n5 2\n3 1\n4 2\n",
"3\n6 1\n5 2\n4 3\n"
] | [
"2\n",
"6\n"
] | In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark ... | 1,500 | [
{
"input": "3\n5 2\n3 1\n4 2",
"output": "2"
},
{
"input": "3\n6 1\n5 2\n4 3",
"output": "6"
},
{
"input": "1\n1000000000 999999999",
"output": "999999999"
},
{
"input": "1\n2 1",
"output": "1"
},
{
"input": "2\n3 2\n3 2",
"output": "2"
},
{
"input": "... | 1,696,854,546 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 171 | 6,451,200 | n = int(input())
exams = []
for i in range(n):
exams.append(input().split())
# print(exams)
exams.sort(key=lambda item: item[0])
start = int(exams[0][1])
vals = []
vals.append(start)
for s,e in exams[1:]:
# print(vals)
s, e = int(s), int(e)
if e >= start:
vals.append(e)
... | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Beside... | ```python
n = int(input())
exams = []
for i in range(n):
exams.append(input().split())
# print(exams)
exams.sort(key=lambda item: item[0])
start = int(exams[0][1])
vals = []
vals.append(start)
for s,e in exams[1:]:
# print(vals)
s, e = int(s), int(e)
if e >= start:
vals.appe... | 0 | |
821 | B | Okabe and Banana Trees | PROGRAMMING | 1,300 | [
"brute force",
"math"
] | null | null | Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor ... | The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000). | Print the maximum number of bananas Okabe can get from the trees he cuts. | [
"1 5\n",
"2 3\n"
] | [
"30\n",
"25\n"
] | The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas. | 1,000 | [
{
"input": "1 5",
"output": "30"
},
{
"input": "2 3",
"output": "25"
},
{
"input": "4 6",
"output": "459"
},
{
"input": "6 3",
"output": "171"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "10 1",
"output": "55"
},
{
"input": "20 10",
... | 1,499,261,691 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 61 | 5,529,600 | m, b = map(int, input().split())
ans = 0
for y in range(0, b + 1):
x = m * (b - y)
ans = max(ans, (x + 1) * (y * (y + 1) / 2) + (y + 1) * (x * (x + 1) / 2))
print(int(ans))
| Title: Okabe and Banana Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers a... | ```python
m, b = map(int, input().split())
ans = 0
for y in range(0, b + 1):
x = m * (b - y)
ans = max(ans, (x + 1) * (y * (y + 1) / 2) + (y + 1) * (x * (x + 1) / 2))
print(int(ans))
``` | 0 | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,578,340,021 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 3,000 | 18,124,800 | from itertools import combinations
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
for c in combinations(range(n), 2):
if a[c[0]][0] == a[c[1]][0] or a[c[0]][1] == a[c[1]][1]:
ans -=- 1
print(ans) | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
from itertools import combinations
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
for c in combinations(range(n), 2):
if a[c[0]][0] == a[c[1]][0] or a[c[0]][1] == a[c[1]][1]:
ans -=- 1
print(ans)
``` | 0 | |
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co... | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
... | 1,576,527,131 | 2,147,483,647 | Python 3 | OK | TESTS1 | 24 | 840 | 0 | a=int(input())
b=a
countt=0
while(b>0):
l=[]
countt+=1
while(a>0):
l.append(a%10)
a=a//10
l=sorted(l)
b=b-l[-1]
a=b
print(countt) | Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i... | ```python
a=int(input())
b=a
countt=0
while(b>0):
l=[]
countt+=1
while(a>0):
l.append(a%10)
a=a//10
l=sorted(l)
b=b-l[-1]
a=b
print(countt)
``` | 3 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,684,172,493 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n = int(input())
colors = ['R', 'O', 'Y', 'G', 'B' 'I', 'V']
s = ""
k = 0
for i in range(n):
if(k == 6):
k = 0
currentColor = colors[k]
if not(i>=0 and i<=4):
if(currentColor in s[i-4::i]):
k = 0
currentColor = colors[k]
if(i == n-1) and n > ... | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
n = int(input())
colors = ['R', 'O', 'Y', 'G', 'B' 'I', 'V']
s = ""
k = 0
for i in range(n):
if(k == 6):
k = 0
currentColor = colors[k]
if not(i>=0 and i<=4):
if(currentColor in s[i-4::i]):
k = 0
currentColor = colors[k]
if(i == n-1... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.