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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,558,012,455 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 436 | 8,089,600 | n, k = map(int, input().split())
a = list(reversed(sorted(list(map(int, input().split())))))
if len(a) == 1:
print(0)
else:
s = set(a)
for i in a:
if i in s:
if i / k in s:
s.remove(i // k)
print(len(s))
| Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, ... | ```python
n, k = map(int, input().split())
a = list(reversed(sorted(list(map(int, input().split())))))
if len(a) == 1:
print(0)
else:
s = set(a)
for i in a:
if i in s:
if i / k in s:
s.remove(i // k)
print(len(s))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 0 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,646,158,058 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 3,379,200 | import math
def nCr(n,r):
f = math.factorial
return f(n) / f(r) / f(n-r)
nk = input().split()
n = int(nk[0])
k = int(nk[1])
arr = list(map(int, input().rstrip().split()))
answer = 0
for i in range(n):
count = 0
for j in range(i+1,n):
if arr[j] - arr[i] > k:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of th... | ```python
import math
def nCr(n,r):
f = math.factorial
return f(n) / f(r) / f(n-r)
nk = input().split()
n = int(nk[0])
k = int(nk[1])
arr = list(map(int, input().rstrip().split()))
answer = 0
for i in range(n):
count = 0
for j in range(i+1,n):
if arr[j] - arr[i] >... | -1 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,693,713,210 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=int(inpuut())
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
n=int(inpuut())
``` | -1 |
749 | B | Parallelogram is Back | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms",
"geometry"
] | null | null | Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwis... | The input consists of three lines, each containing a pair of integer coordinates *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide. | First print integer *k* — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.
Then print *k* lines, each containing a pa... | [
"0 0\n1 0\n0 1\n"
] | [
"3\n1 -1\n-1 1\n1 1\n"
] | If you need clarification of what parallelogram is, please check Wikipedia page:
https://en.wikipedia.org/wiki/Parallelogram | 1,000 | [
{
"input": "0 0\n1 0\n0 1",
"output": "3\n1 -1\n-1 1\n1 1"
},
{
"input": "0 -1\n-1 0\n1 1",
"output": "3\n-2 -2\n2 0\n0 2"
},
{
"input": "-1 -1\n0 1\n1 1",
"output": "3\n-2 -1\n0 -1\n2 3"
},
{
"input": "1000 1000\n-1000 -1000\n-1000 1000",
"output": "3\n1000 -1000\n1000 3... | 1,698,973,987 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
//Fast and foriuos typing:
typedef long long ll;
//Constants:
const int MOD = 1000000007;
const ll INF = 1e18;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
map<int,int> a,b;
set<pair... | Title: Parallelogram is Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate ... | ```python
#include <bits/stdc++.h>
using namespace std;
//Fast and foriuos typing:
typedef long long ll;
//Constants:
const int MOD = 1000000007;
const ll INF = 1e18;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
map<int,int> a,b;
... | -1 | |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min... | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
... | 1,633,779,712 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 20,172,800 |
n = int(input())
a = list(map(int, input().split()))
print((sum(a) // (n - 1)) + 1)
"""
2 3 5 7 2
s p p p p
s p p p p
s p p p
p s p p
p s p p
p s p p
p s p p
""" | Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a... | ```python
n = int(input())
a = list(map(int, input().split()))
print((sum(a) // (n - 1)) + 1)
"""
2 3 5 7 2
s p p p p
s p p p p
s p p p
p s p p
p s p p
p s p p
p s p p
"""
``` | 0 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,671,371,012 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n = int(input())
a = [int(x) for x in input()]
b = [int(y) for y in input()]
count = 0
for i in range(n):
if a[i]!=b[i]:
if abs(a[i]-b[i])<=4:
count += abs(a[i]-b[i])
else:
count += 10- abs(a[i]-b[i])
print(count) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
a = [int(x) for x in input()]
b = [int(y) for y in input()]
count = 0
for i in range(n):
if a[i]!=b[i]:
if abs(a[i]-b[i])<=4:
count += abs(a[i]-b[i])
else:
count += 10- abs(a[i]-b[i])
print(count)
``` | 3 | |
298 | A | Snow Footprints | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000).
The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's gu... | Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | 500 | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 1,680,118,902 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n = int(input())
s = input()
fr = lr = fl = ll = -1
for i in range(n):
if s[i] == 'R':
if fr < 0:
fr = i
lr = i
if s[i] == 'L':
if fl < 0:
fl = i
ll = i
if fr == -1:
print(ll+1, fl+1)
elif fl == -1:
print(fr+1, lr+1)
else:
... | Title: Snow Footprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *... | ```python
n = int(input())
s = input()
fr = lr = fl = ll = -1
for i in range(n):
if s[i] == 'R':
if fr < 0:
fr = i
lr = i
if s[i] == 'L':
if fl < 0:
fl = i
ll = i
if fr == -1:
print(ll+1, fl+1)
elif fl == -1:
print(fr+1, lr+1)
... | 0 | |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number — answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,588,327,988 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 307,200 | n = 0
per = []
l = 0
while n != 100:
try:
enter = input()
except EOFError as e:
break
for i in range(len(enter)):
if enter[0] == '+':
per.append(enter[1:])
break
elif enter[0] == '-':
per.remove(enter[1:])
break
... | Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
n = 0
per = []
l = 0
while n != 100:
try:
enter = input()
except EOFError as e:
break
for i in range(len(enter)):
if enter[0] == '+':
per.append(enter[1:])
break
elif enter[0] == '-':
per.remove(enter[1:])
... | 3.888711 |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,593,698,025 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | n = int(input())
l = [int(i) for i in input().split()]
mi = min(l)
ma = max(l)
initial = abs(l.index(ma)-l.index(mi))
f = n - initial - min(l.index(mi), l.index(ma))
s = n - max(l.index(mi), l.index(ma))
print(initial+max(f, s)-1) | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
n = int(input())
l = [int(i) for i in input().split()]
mi = min(l)
ma = max(l)
initial = abs(l.index(ma)-l.index(mi))
f = n - initial - min(l.index(mi), l.index(ma))
s = n - max(l.index(mi), l.index(ma))
print(initial+max(f, s)-1)
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,661,730,848 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | s=input()
print(s.lower() if 3 <len(s) else s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
print(s.lower() if 3 <len(s) else s.upper())
``` | 0 |
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,666,542,457 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 |
st='ROYGBIV'
x=int(input())
print(st*(x//7)+st[:x%7])
| 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
st='ROYGBIV'
x=int(input())
print(st*(x//7)+st[:x%7])
``` | 0 |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,594,836,750 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 124 | 6,656,000 | n,a,b=list(map(int,input().split()))
res = (a+b-1)%n
print(res+1)
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n,a,b=list(map(int,input().split()))
res = (a+b-1)%n
print(res+1)
``` | 3 | |
177 | G2 | Fibonacci Strings | PROGRAMMING | 2,600 | [
"matrices",
"strings"
] | null | null | Fibonacci strings are defined as follows:
- *f*1 = «a» - *f*2 = «b» - *f**n* = *f**n*<=-<=1 *f**n*<=-<=2, *n*<=><=2
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a Fibonacci string and *m* strings *s**i*. For each string *s**i*, find the number of times it occurs in... | The first line contains two space-separated integers *k* and *m* — the number of a Fibonacci string and the number of queries, correspondingly.
Next *m* lines contain strings *s**i* that correspond to the queries. It is guaranteed that strings *s**i* aren't empty and consist only of characters "a" and "b".
The input ... | For each string *s**i* print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo 1000000007 (109<=+<=7). Print the answers for the strings in the order in which they are given in the input. | [
"6 5\na\nb\nab\nba\naba\n"
] | [
"3\n5\n3\n3\n1\n"
] | none | 70 | [
{
"input": "6 5\na\nb\nab\nba\naba",
"output": "3\n5\n3\n3\n1"
},
{
"input": "10 10\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab",
"output": "12\n21\n21\n0\n12\n21\n21\n0\n12\n21"
},
{
"input": "10 10\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb",
"output": "0\n12\n21\n0\n12\n8\n0\n0... | 1,567,347,148 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS2 | 0 | 218 | 0 | k,m = map(int,input().split())
s=[]
for i in range(m):
s.append(input())
f1, f2 = 'a', 'b'
if k == 1:
f = f1
elif k == 2:
f = f2
else:
while k>2:
f = f2 + f1
f1,f2 = f2,f
k -= 1
print(f)
for x in s:
if(x=='bab'):
print(21)
else:
print(f.count(x)) | Title: Fibonacci Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fibonacci strings are defined as follows:
- *f*1 = «a» - *f*2 = «b» - *f**n* = *f**n*<=-<=1 *f**n*<=-<=2, *n*<=><=2
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a... | ```python
k,m = map(int,input().split())
s=[]
for i in range(m):
s.append(input())
f1, f2 = 'a', 'b'
if k == 1:
f = f1
elif k == 2:
f = f2
else:
while k>2:
f = f2 + f1
f1,f2 = f2,f
k -= 1
print(f)
for x in s:
if(x=='bab'):
print(21)
else:
print(f.count(x))
``` | 0 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,538,227,975 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 14,233,600 | n = int(input())
gifts = input().split()
i=0
while i <= (n-2)-i+1:
for k in range(i,(n//2)+1):
save = gifts[(n-2)-k+1]
gifts[(n-2)-k+1] = gifts[k]
gifts[k] = save
i+=1
print(' '.join(gifts)) | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
n = int(input())
gifts = input().split()
i=0
while i <= (n-2)-i+1:
for k in range(i,(n//2)+1):
save = gifts[(n-2)-k+1]
gifts[(n-2)-k+1] = gifts[k]
gifts[k] = save
i+=1
print(' '.join(gifts))
``` | 0 | |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,558,436,548 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 0 | n,m=map(int,input().split())
d={}
for i in range(1,m+1):
d[i]=[]
arr=[]
for i in range(n):
a=list(map(int,input().split()))
a=a[1:]
arr.append(a)
for j in a:
d[j].append(i)
adj={}
for i in range(n):
adj[i]=[]
for i in range(n):
for j in arr[i]:
adj[i]+=d[j]
adj[i]=list(set(adj[i])-{i})
#print(adj)
vi... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
n,m=map(int,input().split())
d={}
for i in range(1,m+1):
d[i]=[]
arr=[]
for i in range(n):
a=list(map(int,input().split()))
a=a[1:]
arr.append(a)
for j in a:
d[j].append(i)
adj={}
for i in range(n):
adj[i]=[]
for i in range(n):
for j in arr[i]:
adj[i]+=d[j]
adj[i]=list(set(adj[i])-{i})
#prin... | 0 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,681,660,080 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 93 | 0 | n = int(input())
a = list(map(int, input().split()))
b = max(a, key=a.count)
c = a.count(b)
print(min(n,c)) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n = int(input())
a = list(map(int, input().split()))
b = max(a, key=a.count)
c = a.count(b)
print(min(n,c))
``` | 3 | |
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, ... | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro... | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{... | 1,448,984,550 | 450 | Python 3 | OK | TESTS | 57 | 61 | 0 | m = list(map(int, input().split()))
w = list(map(int, input().split()))
h = [500, 1000, 1500, 2000, 2500]
s, u = map(int, input().split())
su = 0.0
for i in range(5):
su += max(0.3*h[i], (1.0-m[i]/250.0)*h[i] - 50.0*w[i])
su += s*100.0
su -= u*50.0
print(int(su))
| Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin... | ```python
m = list(map(int, input().split()))
w = list(map(int, input().split()))
h = [500, 1000, 1500, 2000, 2500]
s, u = map(int, input().split())
su = 0.0
for i in range(5):
su += max(0.3*h[i], (1.0-m[i]/250.0)*h[i] - 50.0*w[i])
su += s*100.0
su -= u*50.0
print(int(su))
``` | 3 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,375,015,706 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 186 | 0 | n = int(input())
left = 1
right = n ** 2
for i in range(n):
for j in range(n // 2):
print(left, right, end=' ')
left, right = left + 1, right - 1
print() | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n = int(input())
left = 1
right = n ** 2
for i in range(n):
for j in range(n // 2):
print(left, right, end=' ')
left, right = left + 1, right - 1
print()
``` | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,692,868,877 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | #https://codeforces.com/problemset/problem/466/A
n,m,a,b=map(int,input().split())
d=b/m
if d<=a:
t=n//m
print(b*t+(n-t*m)*a)
else:
t=n//a
print(a*t+(n-t*a)*b) | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
#https://codeforces.com/problemset/problem/466/A
n,m,a,b=map(int,input().split())
d=b/m
if d<=a:
t=n//m
print(b*t+(n-t*m)*a)
else:
t=n//a
print(a*t+(n-t*a)*b)
``` | 0 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,601,662,124 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 109 | 0 | a = input()
m = 0
for i in range(len(a)):
for j in range(i,len(a)):
s = a[i:j+1]
if s!=s[::-1]:
if len(s)>m:
m = len(s)
print(m)
| Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
a = input()
m = 0
for i in range(len(a)):
for j in range(i,len(a)):
s = a[i:j+1]
if s!=s[::-1]:
if len(s)>m:
m = len(s)
print(m)
``` | 3 | |
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys a... | The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *... | Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 ... | 1,551,963,472 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 249 | 18,432,000 | n, w = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(min(w, min(a[0], a[n]*0.5)*3*n))
| Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ... | ```python
n, w = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(min(w, min(a[0], a[n]*0.5)*3*n))
``` | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,603,913,669 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 108 | 0 | import math
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
n=int(input())
L=[ "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
k=math.floor(math.log2(n/5+1))
... | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
import math
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
n=int(input())
L=[ "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
k=math.floor(math.log... | 3.946 |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,634,835,809 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 41 | 124 | 4,505,600 | import math
n,*m=input().split()
n=int(n)
m=int(*m)
a,b=0,0
if n==m:
print(2)
else:
solCount=0
bSols=[]
for i in range(n+1):
if m-b**2 == math.sqrt(n-b):
solCount+=1
bSols.append(b)
b+=1
print(solCount) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
import math
n,*m=input().split()
n=int(n)
m=int(*m)
a,b=0,0
if n==m:
print(2)
else:
solCount=0
bSols=[]
for i in range(n+1):
if m-b**2 == math.sqrt(n-b):
solCount+=1
bSols.append(b)
b+=1
print(solCount)
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,567,702,546 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | forces = int(input())
x = 0
y = 0
z = 0
for i in range(0,forces):
x1, y1, z1 = input().split()
x += int(x1)
y += int(y1)
z += int(z1)
if x == 0 and y == 0 and z == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
forces = int(input())
x = 0
y = 0
z = 0
for i in range(0,forces):
x1, y1, z1 = input().split()
x += int(x1)
y += int(y1)
z += int(z1)
if x == 0 and y == 0 and z == 0:
print("YES")
else:
print("NO")
``` | 3.938 |
774 | L | Bars | PROGRAMMING | 2,000 | [
"*special",
"binary search"
] | null | null | Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can eit... | The first line contains two integers $n$ and $k$ ($2 \le n \le 200\,000$, $2 \le k \le n$) — the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length $n$ consisting of zeros and ones. If the $i$-th symbol ... | Print the minimum possible break in minutes between eating chocolate bars. | [
"3 3\n010\n",
"8 3\n01010110\n"
] | [
"1\n",
"3\n"
] | In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes $1$ and $8$ anyway, also he needs to eat the chocolate bar in the minute $5$, so that the time of the maximum break will be equal ... | 0 | [
{
"input": "3 3\n010",
"output": "1"
},
{
"input": "8 3\n01010110",
"output": "3"
},
{
"input": "9 5\n001100110",
"output": "2"
},
{
"input": "2 2\n00",
"output": "0"
},
{
"input": "3 2\n010",
"output": "1"
},
{
"input": "3 2\n000",
"output": "1"
... | 1,589,654,236 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 139 | 20,172,800 | def ok(x, k, s, n):
i = 0
while i < len(s):
k -= 1
if(i + x + 1 >= len(s)):
break
j = n[i + x + 1]
if(j == i):
return 0
i = j
return k >= 0
n, k = map(int, input().split())
s = input()
n = [0]
for i in range(1, len(s)):
if ... | Title: Bars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to... | ```python
def ok(x, k, s, n):
i = 0
while i < len(s):
k -= 1
if(i + x + 1 >= len(s)):
break
j = n[i + x + 1]
if(j == i):
return 0
i = j
return k >= 0
n, k = map(int, input().split())
s = input()
n = [0]
for i in range(1, len(s))... | 0 | |
665 | E | Beautiful Subarrays | PROGRAMMING | 2,100 | [
"data structures",
"divide and conquer",
"strings",
"trees"
] | null | null | One day, ZS the Coder wrote down an array of integers *a*<=with elements *a*1,<=<=*a*2,<=<=...,<=<=*a**n*.
A subarray of the array *a* is a sequence *a**l*,<=<=*a**l*<=<=+<=<=1,<=<=...,<=<=*a**r* for some integers (*l*,<=<=*r*) such that 1<=<=≤<=<=*l*<=<=≤<=<=*r*<=<=≤<=<=*n*. ZS the Coder thinks that a subarray of *a*... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=109) — the number of elements in the array *a* and the value of the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print the only integer *c* — the number of beautiful subarrays of the array *a*. | [
"3 1\n1 2 3\n",
"3 2\n1 2 3\n",
"3 3\n1 2 3\n"
] | [
"5\n",
"3\n",
"2\n"
] | none | 0 | [
{
"input": "3 1\n1 2 3",
"output": "5"
},
{
"input": "3 2\n1 2 3",
"output": "3"
},
{
"input": "3 3\n1 2 3",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 1\n1 1 0 1 0 1 1 0 0 0",
"output": "28"
},
{
"input": "100 80\n85 16 22 8... | 1,689,435,241 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689435241.7912953")# 1689435241.7913144 | Title: Beautiful Subarrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, ZS the Coder wrote down an array of integers *a*<=with elements *a*1,<=<=*a*2,<=<=...,<=<=*a**n*.
A subarray of the array *a* is a sequence *a**l*,<=<=*a**l*<=<=+<=<=1,<=<=...,<=<=*a**r* for some integers ... | ```python
print("_RANDOM_GUESS_1689435241.7912953")# 1689435241.7913144
``` | 0 | |
570 | B | Simple Game | PROGRAMMING | 1,300 | [
"constructive algorithms",
"games",
"greedy",
"implementation",
"math"
] | null | null | One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*.
Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n*... | The first line contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the range of numbers in the game, and the number selected by Misha respectively. | Print a single number — such value *a*, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them. | [
"3 1\n",
"4 3\n"
] | [
"2",
"2"
] | In the first sample test: Andrew wins if *c* is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses *a* = 3, the probability of winning will be 1 / 3. If *a* = 1, the probability of winning is 0.
In the second sample test: Andrew wins if *c* is equal to 1 and 2. The probability that Andrew wi... | 1,000 | [
{
"input": "3 1",
"output": "2"
},
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "4"
},
{
"input": "10 5",
"output": "6"
},
{
"input": "20 13",
"output": "12"
},
{
"input": "51 1",
"output": "2"
},
{
"input": "100 50",
... | 1,581,432,671 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 139 | 0 | #!/usr/bin/env python3
def main():
n, m = map(int, input().split(' '))
if m < n/2:
print(m+1)
else:
print(m-1)
if __name__== "__main__":
main()
| Title: Simple Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*.
Then, by using a random gen... | ```python
#!/usr/bin/env python3
def main():
n, m = map(int, input().split(' '))
if m < n/2:
print(m+1)
else:
print(m-1)
if __name__== "__main__":
main()
``` | 0 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,656,349,622 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 46 | 4,300,800 | x=int(input())
if (x%2 == 0) :
print((x//4)-(x%4==0))
else :
print(0)
| Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
x=int(input())
if (x%2 == 0) :
print((x//4)-(x%4==0))
else :
print(0)
``` | 3 | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,674,216,038 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | t = int(input())
s = input()
count = 0
i = 0
while (i <t -1):
if [i] == 'u' and s[i+1] == 'r' :
count + count +1
i = i +2
elif s [1] == 'r' and s [i +1 ] == 'u' :
count = count +1
i = i +2
else:
count=count
i = i +1
print(1 -... | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
t = int(input())
s = input()
count = 0
i = 0
while (i <t -1):
if [i] == 'u' and s[i+1] == 'r' :
count + count +1
i = i +2
elif s [1] == 'r' and s [i +1 ] == 'u' :
count = count +1
i = i +2
else:
count=count
i = i +1
... | 0 | |
712 | B | Memory and Trident | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move... | The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. | If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. | [
"RRU\n",
"UDUR\n",
"RUUR\n"
] | [
"-1\n",
"1\n",
"2\n"
] | In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses ... | 1,000 | [
{
"input": "RRU",
"output": "-1"
},
{
"input": "UDUR",
"output": "1"
},
{
"input": "RUUR",
"output": "2"
},
{
"input": "DDDD",
"output": "2"
},
{
"input": "RRRR",
"output": "2"
},
{
"input": "RRRUUD",
"output": "2"
},
{
"input": "UDURLRDURL... | 1,632,644,980 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 61 | 20,172,800 | s = input()
if len(s) % 2 == 1:
print(-1)
else:
u = 0
r = 0
for i in range(len(s)):
if s[i] == 'U':
u += 1
if s[i] == 'D':
u -= 1
if s[i] == 'L':
r -= 1
else:
r += 1
print(u+r) | Title: Memory and Trident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he shou... | ```python
s = input()
if len(s) % 2 == 1:
print(-1)
else:
u = 0
r = 0
for i in range(len(s)):
if s[i] == 'U':
u += 1
if s[i] == 'D':
u -= 1
if s[i] == 'L':
r -= 1
else:
r += 1
print(u+r)
``` | 0 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,687,954,718 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n, t = list(map(int, input().split()))
nums = list(map(int, input().split()))
cur_sum = 0
max_len = 0
r = 0
for l in range(n):
while r < n and cur_sum + nums[r] < t: # пока r < n и отрезок хороший
cur_sum += nums[r] # добавляем элемент r в отрезок
r += 1
max_len = max(max_len,... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n, t = list(map(int, input().split()))
nums = list(map(int, input().split()))
cur_sum = 0
max_len = 0
r = 0
for l in range(n):
while r < n and cur_sum + nums[r] < t: # пока r < n и отрезок хороший
cur_sum += nums[r] # добавляем элемент r в отрезок
r += 1
max_len = ma... | 0 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,622,108,917 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 77 | 0 | import math
n = int(input())
h = int(n//2)
if(n&1):
print(h,h+1)
else:
for i in range(h,0,-1):
if(math.gcd(i,n-i)==1):
print(i,n-i)
break | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
import math
n = int(input())
h = int(n//2)
if(n&1):
print(h,h+1)
else:
for i in range(h,0,-1):
if(math.gcd(i,n-i)==1):
print(i,n-i)
break
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,596,949,163 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 6,656,000 | x = list(map(int, input()))
y = list(map(int, input()))
s = ''
for i in range(len(x)):
if x[i] == y[i]:
s = s + '0'
else:
s = s + '1'
print(s)
| 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
x = list(map(int, input()))
y = list(map(int, input()))
s = ''
for i in range(len(x)):
if x[i] == y[i]:
s = s + '0'
else:
s = s + '1'
print(s)
``` | 3.960352 |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,602,549,608 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 280 | 0 | t = int(input())
s = input()
if s.count('4') + s.count('7') != t:
print('NO')
else:
one = 0
two = 0
n = int(t / 2)
q = s[:n]
w = s[n:]
for i in q:
one += int(i)
for i in w:
two += int(i)
if one == two:
print('YES')
else:
prin... | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
t = int(input())
s = input()
if s.count('4') + s.count('7') != t:
print('NO')
else:
one = 0
two = 0
n = int(t / 2)
q = s[:n]
w = s[n:]
for i in q:
one += int(i)
for i in w:
two += int(i)
if one == two:
print('YES')
else:
... | 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,591,010,197 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n,s = map(int,input().split())
l = list(map(int,input().split()))
k = sum(l)
m = max(l)
if ((k-m) <= k):
print("YES")
else:
print("NO") | Title: Sereja and Mugs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non... | ```python
n,s = map(int,input().split())
l = list(map(int,input().split()))
k = sum(l)
m = max(l)
if ((k-m) <= k):
print("YES")
else:
print("NO")
``` | 0 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,695,438,596 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | n = input()
if n[0] != '-':
print(n)
elif len(n) == 3 and n[2] == '0':
print(0)
else:
remove = int(max(n[-1], n[-2]))
result = n[:-remove-1] + n[-remove:]
print(result)
| Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
n = input()
if n[0] != '-':
print(n)
elif len(n) == 3 and n[2] == '0':
print(0)
else:
remove = int(max(n[-1], n[-2]))
result = n[:-remove-1] + n[-remove:]
print(result)
``` | 0 | |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,670,702,795 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 0 | a = int(input())
x = list(map(int, input().split()))
largest = 0
second = 0
l = []
j = 0
while j<len(x):
if x[j]>largest:
largest = x[j]
l.append(j+1)
j += 1
k = 0
while k<len(x):
if x[k]>second:
if k!=(l[-1]-1):
second = x[k]
k += 1
print(l[-1],secon... | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
a = int(input())
x = list(map(int, input().split()))
largest = 0
second = 0
l = []
j = 0
while j<len(x):
if x[j]>largest:
largest = x[j]
l.append(j+1)
j += 1
k = 0
while k<len(x):
if x[k]>second:
if k!=(l[-1]-1):
second = x[k]
k += 1
print(l... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,597,573,378 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 0 | x,y,z=0,0,0
n=int(input())
for i in range (n):
a,b,c=input().split()
x+=int(a)
y+=int(b)
z+=int(c)
if (bool(x)| bool(y)|bool(z)):
print("NO")
else:
print("YES") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
x,y,z=0,0,0
n=int(input())
for i in range (n):
a,b,c=input().split()
x+=int(a)
y+=int(b)
z+=int(c)
if (bool(x)| bool(y)|bool(z)):
print("NO")
else:
print("YES")
``` | 3.9455 |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,525,200,450 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 904 | 7,372,800 | n = int(input())
mass = list(map(int, input().split()))
k = 0
for i in range(1, n + 1):
if i not in mass:
k += 1
print(k) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n = int(input())
mass = list(map(int, input().split()))
k = 0
for i in range(1, n + 1):
if i not in mass:
k += 1
print(k)
``` | 3 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,659,540,646 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 62 | 1,536,000 | import sys
a, b = (int(el) for el in input().split())
aa, bb = 1, 2
for i in range(1000_000_000):
if i % 2 == 0:
a -= aa
if a < 0:
print("Vladik")
sys.exit()
aa += 2
else:
b -= bb
if b < 0:
print("Valera")
sy... | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
import sys
a, b = (int(el) for el in input().split())
aa, bb = 1, 2
for i in range(1000_000_000):
if i % 2 == 0:
a -= aa
if a < 0:
print("Vladik")
sys.exit()
aa += 2
else:
b -= bb
if b < 0:
print("Valera")
... | 3 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,676,235,846 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
int main()
{
int x,y;
string results[6]={"1/6","1/3","1/2","2/3","5/6","1/1"};
cin>>x>>y;
x=max(x,y);
cout<<results[6-x];
return 0;
}
| Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
#include <iostream>
using namespace std;
int main()
{
int x,y;
string results[6]={"1/6","1/3","1/2","2/3","5/6","1/1"};
cin>>x>>y;
x=max(x,y);
cout<<results[6-x];
return 0;
}
``` | -1 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,699,343,185 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 5,222,400 | n=int(input())
l=list(map(int,input().split()))
ans,m=0,sum(l)//3
l1,l2=[],[]
ss=0
for i in range(1,n+1):
ss+=l[i-1]
if ss==m and i!=1 and i!=n:
l1.append(i)
if ss==2*m and i!=1 and i!=n:
l2.append(i)
x,y=0,0
while x<len(l1) and y<len(l2):
if l2[y]>=l1[x]:
ans+=len(... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
n=int(input())
l=list(map(int,input().split()))
ans,m=0,sum(l)//3
l1,l2=[],[]
ss=0
for i in range(1,n+1):
ss+=l[i-1]
if ss==m and i!=1 and i!=n:
l1.append(i)
if ss==2*m and i!=1 and i!=n:
l2.append(i)
x,y=0,0
while x<len(l1) and y<len(l2):
if l2[y]>=l1[x]:
... | 0 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,592,846,239 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 10,444,800 | n, m = map(int, input().split())
neg = sum(x < 0 for x in map(int, input().split()))
d = min(neg, n - neg) * 2
for i in range(m):
l, r = map(int, input().split())
print(int(0 < r - l < d and (r - l) & 1))
| Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
n, m = map(int, input().split())
neg = sum(x < 0 for x in map(int, input().split()))
d = min(neg, n - neg) * 2
for i in range(m):
l, r = map(int, input().split())
print(int(0 < r - l < d and (r - l) & 1))
``` | 0 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,698,077,565 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 60 | 0 | n = int(input())
stops = []
capacity = [0]
for i in range(n):
line = input().split(" ")
stops.append((int(line[0]), int(line[1])),)
for i in stops:
if stops.index(i) > 0:
capacity.append(capacity[stops.index(i)-1] - i[0] + i[1])
else:
capacity[0] = i[1]
print(max(capacity))
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n = int(input())
stops = []
capacity = [0]
for i in range(n):
line = input().split(" ")
stops.append((int(line[0]), int(line[1])),)
for i in stops:
if stops.index(i) > 0:
capacity.append(capacity[stops.index(i)-1] - i[0] + i[1])
else:
capacity[0] = i[1]
print(max(capa... | -1 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,584,700,868 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 171 | 7,372,800 | n = int(input())
sumEven = 0
total = 0
uneven = []
for i in input().split():
if int(i) % 2 == 0:
sumEven = sumEven + int(i)
else:
uneven.append(int(i))
if len(uneven) % 2 == 0:
total = sum(uneven) + sumEven
else:
sorted(uneven, reverse=True)
total = sum(uneven[:-1]) + su... | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
sumEven = 0
total = 0
uneven = []
for i in input().split():
if int(i) % 2 == 0:
sumEven = sumEven + int(i)
else:
uneven.append(int(i))
if len(uneven) % 2 == 0:
total = sum(uneven) + sumEven
else:
sorted(uneven, reverse=True)
total = sum(uneven[... | 0 | |
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"o... | 1,679,879,456 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | n = int(input())
l = list(map(int,input().split()))
ones = l.count(100)
if ones % 2 == 1 :
print("NO")
elif ones == 0:
twos = l.count(200)
if twos % 2 == 1:
print("NO")
else :
print("YES") | Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w... | ```python
n = int(input())
l = list(map(int,input().split()))
ones = l.count(100)
if ones % 2 == 1 :
print("NO")
elif ones == 0:
twos = l.count(200)
if twos % 2 == 1:
print("NO")
else :
print("YES")
``` | 0 | |
260 | D | Black and White Tree | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dsu",
"graphs",
"greedy",
"trees"
] | null | null | The board has got a painted tree graph, consisting of *n* nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.
Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each ed... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of nodes in the tree. Next *n* lines contain pairs of space-separated integers *c**i*, *s**i* (0<=≤<=*c**i*<=≤<=1, 0<=≤<=*s**i*<=≤<=109), where *c**i* stands for the color of the *i*-th vertex (0 is for white, 1 is for black), an... | Print the description of *n*<=-<=1 edges of the tree graph. Each description is a group of three integers *v**i*, *u**i*, *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*, *v**i*<=≠<=*u**i*, 0<=≤<=*w**i*<=≤<=109), where *v**i* and *u**i* — are the numbers of the nodes that are connected by the *i*-th edge, and *w**i* is its value... | [
"3\n1 3\n1 2\n0 5\n",
"6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0\n"
] | [
"3 1 3\n3 2 2\n",
"2 3 3\n5 3 3\n4 3 2\n1 6 0\n2 1 0\n"
] | none | 2,000 | [
{
"input": "3\n1 3\n1 2\n0 5",
"output": "3 1 3\n3 2 2"
},
{
"input": "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0",
"output": "2 3 3\n5 3 3\n4 3 2\n1 6 0\n2 1 0"
},
{
"input": "2\n0 0\n1 0",
"output": "1 2 0"
},
{
"input": "5\n1 11\n0 9\n1 4\n0 4\n0 2",
"output": "2 1 9\n4 3 4\n5 1 ... | 1,689,419,470 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689419470.8338447")# 1689419470.8338654 | Title: Black and White Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The board has got a painted tree graph, consisting of *n* nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.
Each node of the graph is painted bl... | ```python
print("_RANDOM_GUESS_1689419470.8338447")# 1689419470.8338654
``` | 0 | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,490,891,788 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 5,529,600 | n = int(input())
x = list(input())
st = x.count("X")
if st == n / 2:
print(0)
print("".join(x))
elif st > n / 2:
count = st - n / 2
while count > 0:
index = x.index("X")
x[index] = "x"
count -= 1
print(int(abs(st - n / 2)))
print("".join(x))
else:
count = abs(st - n / 2)
whil... | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
n = int(input())
x = list(input())
st = x.count("X")
if st == n / 2:
print(0)
print("".join(x))
elif st > n / 2:
count = st - n / 2
while count > 0:
index = x.index("X")
x[index] = "x"
count -= 1
print(int(abs(st - n / 2)))
print("".join(x))
else:
count = abs(st - n / ... | -1 | |
614 | B | Gena's Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en... | The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total leng... | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | 1,000 | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 ... | 1,595,008,686 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 6,963,200 | from sys import stdin
answer = '1'
other = 1
for line_num, line in enumerate(stdin):
if line_num == 0:
n = line.rstrip()
else:
for num in line.rstrip().split():
ones = num.count('1')
if int(num) == 0:
answer = 0
break
if num[-1... | Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from eac... | ```python
from sys import stdin
answer = '1'
other = 1
for line_num, line in enumerate(stdin):
if line_num == 0:
n = line.rstrip()
else:
for num in line.rstrip().split():
ones = num.count('1')
if int(num) == 0:
answer = 0
break
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1).
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe... | Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I... | [
"5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n",
"3\n1 2 3\n2\n1 1\n3 1\n",
"1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n"
] | [
"1\n3\n4\n6\n",
"1\n3\n",
"1\n3\n13\n23\n33\n"
] | The first sample are shown on the picture. | 0 | [
{
"input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3",
"output": "1\n3\n4\n6"
},
{
"input": "3\n1 2 3\n2\n1 1\n3 1",
"output": "1\n3"
},
{
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10",
"output": "1\n3\n13\n23\n33"
},
{
"input": "8\n6 10 18 23 30 31 31 33\n1\n5 3",
"output":... | 1,586,780,512 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long l... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he... | ```python
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef l... | -1 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,685,712,641 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 46 | 0 | n = list(map(int, list(input())))
print(max(n))
ans = []
maxn = max(n)
for i in range(maxn):
ans.append(['0' for i in range(len(n))])
for j in range(len(n)):
if n[j]>0:
n[j]-=1
ans[i][j]='1'
print(int(''.join(ans[i])),end=" ")
| Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
n = list(map(int, list(input())))
print(max(n))
ans = []
maxn = max(n)
for i in range(maxn):
ans.append(['0' for i in range(len(n))])
for j in range(len(n)):
if n[j]>0:
n[j]-=1
ans[i][j]='1'
print(int(''.join(ans[i])),end=" ")
``` | 3 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,585,656,749 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | n, t = map(int, input().split())
arr = [int(x) for x in input().split()]
if n == t:
print(-sum(arr))
else:
money = []
kam = []
for i in range(len(arr)):
if arr[i] < 0:
money.append(-arr[i])
else:
kam.append(arr[i])
ans = 0
money.sort... | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n, t = map(int, input().split())
arr = [int(x) for x in input().split()]
if n == t:
print(-sum(arr))
else:
money = []
kam = []
for i in range(len(arr)):
if arr[i] < 0:
money.append(-arr[i])
else:
kam.append(arr[i])
ans = 0
... | 0 |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,672,073,775 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n=int(input())
for i in range(n):
str1=input()
l=len(str1)
if l<=0:
print(str)
else:
print(str[0],l-2,str[l-1],sep=" ") | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n=int(input())
for i in range(n):
str1=input()
l=len(str1)
if l<=0:
print(str)
else:
print(str[0],l-2,str[l-1],sep=" ")
``` | -1 |
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,638,580,907 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n=int(input())
list=[int(x) for x in input().split()]
list1=[]
if n==3:
for i in range(3):
if list[0]==list[1]:
print('3')
elif list[0]==list[2]:
print('2')
else:
print('1')
else:
for i in range(1,n):
a=list[i]-list[i-1]
l... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
list=[int(x) for x in input().split()]
list1=[]
if n==3:
for i in range(3):
if list[0]==list[1]:
print('3')
elif list[0]==list[2]:
print('2')
else:
print('1')
else:
for i in range(1,n):
a=list[i]-list[i-1]
... | 0 |
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,646,231,109 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 2,150,400 | import numpy
a = int(input())
h = [int(po) for po in input().split()]
d = h.copy()
d.sort()
n = int(input())
res = []
for i in range(n):
b = [int(lo) for lo in input().split()]
if b[0] == 1:
res.append(numpy.sum([int(k) for k in h[b[1]-1:b[2]]]))
else:
res.append(numpy.sum([int(k) for k in d... | 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
import numpy
a = int(input())
h = [int(po) for po in input().split()]
d = h.copy()
d.sort()
n = int(input())
res = []
for i in range(n):
b = [int(lo) for lo in input().split()]
if b[0] == 1:
res.append(numpy.sum([int(k) for k in h[b[1]-1:b[2]]]))
else:
res.append(numpy.sum([int(k) ... | -1 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,529,429,137 | 337 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | n=int(input())
a=sorted(list(map(int,input().split())))
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if a[k]==(a[i]+a[j]):
exit(print(a[k],a[j],a[i]))
print(-1) | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
n=int(input())
a=sorted(list(map(int,input().split())))
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if a[k]==(a[i]+a[j]):
exit(print(a[k],a[j],a[i]))
print(-1)
``` | 0 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,646,552,872 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 156 | 0 | arr = input()
N = len(arr)
out = []
i = 0
while i < N:
if arr[i] == ".":
out.append("0")
i += 1
elif arr[i] == "-" and arr[i+1] == ".":
out.append("1")
i += 2
elif arr[i] == "-" and arr[i+1] == "-":
out.append("2")
i += 2
print("".join(out)) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
arr = input()
N = len(arr)
out = []
i = 0
while i < N:
if arr[i] == ".":
out.append("0")
i += 1
elif arr[i] == "-" and arr[i+1] == ".":
out.append("1")
i += 2
elif arr[i] == "-" and arr[i+1] == "-":
out.append("2")
i += 2
print("".joi... | 3.961 |
332 | B | Maximum Absurdity | PROGRAMMING | 1,500 | [
"data structures",
"dp",
"implementation"
] | null | null | Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109). | Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple soluti... | [
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] | [
"1 4\n",
"1 3\n"
] | In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | 1,000 | [
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"i... | 1,696,128,110 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n, k = map(int, input().split())
absurdities = list(map(int, input().split()))
# Calculate prefix sums
prefix_sums = [sum(absurdities[:k])]
for i in range(k,n):
prefix_sums.append(prefix_sums[-1] + absurdities[i] - absurdities[i-k])
max_total_absurdity = -1
max_prefix_sum = [prefix_sums[0]]
b = 0
for i... | Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on... | ```python
n, k = map(int, input().split())
absurdities = list(map(int, input().split()))
# Calculate prefix sums
prefix_sums = [sum(absurdities[:k])]
for i in range(k,n):
prefix_sums.append(prefix_sums[-1] + absurdities[i] - absurdities[i-k])
max_total_absurdity = -1
max_prefix_sum = [prefix_sums[0]]
b ... | 0 | |
588 | B | Duff in Love | PROGRAMMING | 1,300 | [
"math"
] | null | null | Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want... | The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012). | Print the answer in one line. | [
"10\n",
"12\n"
] | [
"10\n",
"6\n"
] | In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "12",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "3",
"output": "3"
},
... | 1,554,733,807 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 65,126,400 | import math
perfect_sq = [i**2 for i in range(2, 1000001)]
n = int(input())
for i in range(n, 0, -1):
if n % i != 0:
continue
eh_divisivel = False
for j in range(0, int(math.sqrt(i)) - 1):
sq = perfect_sq[j]
if i % sq == 0:
eh_divisivel = True
if not eh_divisivel:
... | Title: Duff in Love
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has... | ```python
import math
perfect_sq = [i**2 for i in range(2, 1000001)]
n = int(input())
for i in range(n, 0, -1):
if n % i != 0:
continue
eh_divisivel = False
for j in range(0, int(math.sqrt(i)) - 1):
sq = perfect_sq[j]
if i % sq == 0:
eh_divisivel = True
if not eh_d... | 0 | |
870 | C | Maximum splitting | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"math",
"number theory"
] | null | null | You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
An integer greater than 1 is composite, if it is not prim... | The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries.
*q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | [
"1\n12\n",
"2\n6\n8\n",
"3\n1\n2\n3\n"
] | [
"3\n",
"1\n2\n",
"-1\n-1\n-1\n"
] | 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.
8 = 4 + 4, 6 can't be split into several composite summands.
1, 2, 3 are less than any composite number, so they do not have valid splittings. | 1,500 | [
{
"input": "1\n12",
"output": "3"
},
{
"input": "2\n6\n8",
"output": "1\n2"
},
{
"input": "3\n1\n2\n3",
"output": "-1\n-1\n-1"
},
{
"input": "6\n1\n2\n3\n5\n7\n11",
"output": "-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "3\n4\n6\n9",
"output": "1\n1\n1"
},
{
... | 1,584,341,706 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | q=int(input())
while q:
n=int(input())
if(n==4):print(1)
elif(n==6):print(1)
elif(n==8):print(2)
elif(n==9):print(1)
elif(n==10):print(2)
elif(n==12):print(3)
elif(n==14):print(3)
elif(n<14):print(-1)
elif(n%2==0):
if(n%4==0):print(n//4)
else:print((n... | Title: Maximum splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, o... | ```python
q=int(input())
while q:
n=int(input())
if(n==4):print(1)
elif(n==6):print(1)
elif(n==8):print(2)
elif(n==9):print(1)
elif(n==10):print(2)
elif(n==12):print(3)
elif(n==14):print(3)
elif(n<14):print(-1)
elif(n%2==0):
if(n%4==0):print(n//4)
els... | 0 | |
332 | B | Maximum Absurdity | PROGRAMMING | 1,500 | [
"data structures",
"dp",
"implementation"
] | null | null | Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109). | Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple soluti... | [
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] | [
"1 4\n",
"1 3\n"
] | In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | 1,000 | [
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"i... | 1,610,652,068 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 15,769,600 | n, k = map(int, input().split())
values = [int(i) for i in input().split()]
psa, best, besta, bestb = [values[0]], -1, -1, -1
for i in range(n):
psa.append(psa[i] + values[i])
for i in range(n - k + 1):
for j in range(i + k, n - k + 1):
if (psa[i + k] - psa[i] + psa[j + k] - psa[j]) > best:
... | Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on... | ```python
n, k = map(int, input().split())
values = [int(i) for i in input().split()]
psa, best, besta, bestb = [values[0]], -1, -1, -1
for i in range(n):
psa.append(psa[i] + values[i])
for i in range(n - k + 1):
for j in range(i + k, n - k + 1):
if (psa[i + k] - psa[i] + psa[j + k] - psa[j]) > b... | 0 | |
283 | A | Cows and Sequence | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following:
1. Add the integer *x**i* to the first *a**i* elements of the sequence. 1. Append an integer *k**i* to the end of ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of operations. The next *n* lines describe the operations. Each line will start with an integer *t**i* (1<=≤<=*t**i*<=≤<=3), denoting the type of the operation (see above). If *t**i*<==<=1, it will be followed by two integers *a**i*,<=*x**i... | Output *n* lines each containing the average of the numbers in the sequence after the corresponding operation.
The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"5\n2 1\n3\n2 3\n2 1\n3\n",
"6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3\n"
] | [
"0.500000\n0.000000\n1.500000\n1.333333\n1.500000\n",
"0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000\n"
] | In the second sample, the sequence becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fb5aaaa5dc516fe540cef52fd153768bfdb941c8.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "5\n2 1\n3\n2 3\n2 1\n3",
"output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000"
},
{
"input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3",
"output": "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000"
},
{
"input": "1\n1 1 1",
"output": "1.000000"
},
{
... | 1,595,873,358 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 1,091 | 34,611,200 | n=int(input())
s=0
c=1
l=[0]
d=[0]
ans=[0]*n
for i in range(n):
x=list(map(int,input().split()))
if x[0]==1:
d[x[1]-1]+=x[2]
s=s+x[1]*x[2]
elif x[0]==2:
l.append(x[1])
d.append(0)
s=s+x[1]
c=c+1
else:
t=d[-1]
s=s-l[-1]-t
... | Title: Cows and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following:
1. Add the i... | ```python
n=int(input())
s=0
c=1
l=[0]
d=[0]
ans=[0]*n
for i in range(n):
x=list(map(int,input().split()))
if x[0]==1:
d[x[1]-1]+=x[2]
s=s+x[1]*x[2]
elif x[0]==2:
l.append(x[1])
d.append(0)
s=s+x[1]
c=c+1
else:
t=d[-1]
s=s... | 3 | |
998 | A | Balloons | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi... | The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons.
The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet. | If it's impossible to divide the balloons satisfying the conditions above, print $-1$.
Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons... | [
"3\n1 2 1\n",
"2\n5 5\n",
"1\n10\n"
] | [
"2\n1 2\n",
"-1\n",
"-1\n"
] | In the first test Grigory gets $3$ balloons in total while Andrey gets $1$.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | 500 | [
{
"input": "3\n1 2 1",
"output": "1\n1"
},
{
"input": "2\n5 5",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1\n1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 9",... | 1,602,828,152 | 332 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | from sys import *
from math import *
from bisect import *
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
m=min(a)
i=0
for i in range(n):
if a[i]==m:
break
if sum(a)-2*m==0 or n==1:
print(-1)
else:
print(1)
print(i) | Title: Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bou... | ```python
from sys import *
from math import *
from bisect import *
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
m=min(a)
i=0
for i in range(n):
if a[i]==m:
break
if sum(a)-2*m==0 or n==1:
print(-1)
else:
print(1)
print(i)
``` | 0 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,644,148,673 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | n,m= map(int,input().split())
a=list(map(int,input().split()))
a_idx=list( [a[i],i] for i in range(len(a)))
j=0
while len(a_idx)>1:
if a_idx[j][0]<=m:
a_idx.remove(a_idx[j])
elif a_idx[j][0]>m:
a_idx[j][0]-=m
a_idx.append(a_idx[j])
a_idx.pop(0)
print(a_idx[0][1]+1)
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
n,m= map(int,input().split())
a=list(map(int,input().split()))
a_idx=list( [a[i],i] for i in range(len(a)))
j=0
while len(a_idx)>1:
if a_idx[j][0]<=m:
a_idx.remove(a_idx[j])
elif a_idx[j][0]>m:
a_idx[j][0]-=m
a_idx.append(a_idx[j])
a_idx.pop(0)
print(a_idx[0]... | 3 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,697,699,270 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input())
ans=n/5
if(n%5!=0):
ans+=1
print(ans) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
n=int(input())
ans=n/5
if(n%5!=0):
ans+=1
print(ans)
``` | 0 | |
283 | A | Cows and Sequence | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following:
1. Add the integer *x**i* to the first *a**i* elements of the sequence. 1. Append an integer *k**i* to the end of ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of operations. The next *n* lines describe the operations. Each line will start with an integer *t**i* (1<=≤<=*t**i*<=≤<=3), denoting the type of the operation (see above). If *t**i*<==<=1, it will be followed by two integers *a**i*,<=*x**i... | Output *n* lines each containing the average of the numbers in the sequence after the corresponding operation.
The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"5\n2 1\n3\n2 3\n2 1\n3\n",
"6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3\n"
] | [
"0.500000\n0.000000\n1.500000\n1.333333\n1.500000\n",
"0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000\n"
] | In the second sample, the sequence becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fb5aaaa5dc516fe540cef52fd153768bfdb941c8.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "5\n2 1\n3\n2 3\n2 1\n3",
"output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000"
},
{
"input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3",
"output": "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000"
},
{
"input": "1\n1 1 1",
"output": "1.000000"
},
{
... | 1,616,654,203 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 872 | 19,968,000 | import sys,os,io
import math,bisect,operator
inf,mod = float('inf'),10**9+7
# sys.setrecursionlimit(10 ** 6)
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
... | Title: Cows and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following:
1. Add the i... | ```python
import sys,os,io
import math,bisect,operator
inf,mod = float('inf'),10**9+7
# sys.setrecursionlimit(10 ** 6)
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).... | 3 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,593,075,882 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 248 | 6,963,200 | # https://codeforces.com/problemset/problem/215/A
"""
A bicycle chain consists of two parts
n stars attached to the pedal axle
m stars attached to rear wheel axle
The ith star on the pedal axle has a_i teeth
The jth star on the rear wheel axle has b_j teeth
a and b are strictly increasing
Any pair (i, j... | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
# https://codeforces.com/problemset/problem/215/A
"""
A bicycle chain consists of two parts
n stars attached to the pedal axle
m stars attached to rear wheel axle
The ith star on the pedal axle has a_i teeth
The jth star on the rear wheel axle has b_j teeth
a and b are strictly increasing
Any ... | 3 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,691,893,904 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n = int(input())
for i in range(n):
magnets = int(input())
count = 0
if "10" in magents:
count += 1
print(count)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input())
for i in range(n):
magnets = int(input())
count = 0
if "10" in magents:
count += 1
print(count)
``` | -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,664,805,693 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | n,m,a = map(int,input().split())
if n % a == 0:
x1 = n//a
else:
x1 = n//a +1
if m % a == 0:
x2 = m//a
else:
x2 = m//a +1
x = x1*x2
print(x) | 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 % a == 0:
x1 = n//a
else:
x1 = n//a +1
if m % a == 0:
x2 = m//a
else:
x2 = m//a +1
x = x1*x2
print(x)
``` | 3.9845 |
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,648,049,043 | 243 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define int long long
#define double long double
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvvi = std::vector<vvi>;
using vvvvi = std::vector<vvvi>;
using vb = std::vector<bool>;
using vvb = std::vector<vb>;
using pii = std::pair<int, int>;
using vpii = std::ve... | 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
#include <bits/stdc++.h>
#define int long long
#define double long double
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvvi = std::vector<vvi>;
using vvvvi = std::vector<vvvi>;
using vb = std::vector<bool>;
using vvb = std::vector<vb>;
using pii = std::pair<int, int>;
using vpii... | -1 | |
691 | D | Swaps in Permutation | PROGRAMMING | 1,700 | [
"dfs and similar",
"dsu",
"math"
] | null | null | You are given a permutation of the numbers 1,<=2,<=...,<=*n* and *m* pairs of positions (*a**j*,<=*b**j*).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let *p* and *q* be two permutations of the numbe... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=106) — the length of the permutation *p* and the number of pairs of positions.
The second line contains *n* distinct integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation *p*.
Each of the last *m* lines contains two integers (*a*... | Print the only line with *n* distinct integers *p*'*i* (1<=≤<=*p*'*i*<=≤<=*n*) — the lexicographically maximal permutation one can get. | [
"9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n"
] | [
"7 8 9 4 5 6 1 2 3\n"
] | none | 0 | [
{
"input": "9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9",
"output": "7 8 9 4 5 6 1 2 3"
},
{
"input": "1 1\n1\n1 1",
"output": "1"
},
{
"input": "2 10\n2 1\n2 1\n1 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 1\n2 1\n2 1",
"output": "2 1"
},
{
"input": "3 10\n1 2 3\n2 2\n1 1\n2 2\n... | 1,473,205,440 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 17 | 93 | 819,200 | from collections import deque
def bfs(n):
q = deque()
q.append(n)
visited[n]=1
data = []
pos = []
while q:
top = q[0]
data.append(a[top-1])
pos.append(top-1)
q.popleft()
for x in v[top]:
if visited[x]==0:
q.append(... | Title: Swaps in Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation of the numbers 1,<=2,<=...,<=*n* and *m* pairs of positions (*a**j*,<=*b**j*).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What i... | ```python
from collections import deque
def bfs(n):
q = deque()
q.append(n)
visited[n]=1
data = []
pos = []
while q:
top = q[0]
data.append(a[top-1])
pos.append(top-1)
q.popleft()
for x in v[top]:
if visited[x]==0:
... | -1 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,695,319,490 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n,h =input().split()
n =int(n)
h =int(h)
a =[int(i)for i in input().split()]
x =0
for i in range(h):
if a[i]>h:
x=x+2
else:
x=x+1
print(x)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n,h =input().split()
n =int(n)
h =int(h)
a =[int(i)for i in input().split()]
x =0
for i in range(h):
if a[i]>h:
x=x+2
else:
x=x+1
print(x)
``` | -1 | |
381 | B | Sereja and Stairs | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sereja loves integer sequences very much. He especially likes stairs.
Sequence *a*1,<=*a*2,<=...,<=*a*|*a*| (|*a*| is the length of the sequence) is stairs if there is such index *i* (1<=≤<=*i*<=≤<=|*a*|), that the following condition is met:
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3,... | The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of Sereja's cards. The second line contains *m* integers *b**i* (1<=≤<=*b**i*<=≤<=5000) — the numbers on the Sereja's cards. | In the first line print the number of cards you can put on the table. In the second line print the resulting stairs. | [
"5\n1 2 3 4 5\n",
"6\n1 1 2 2 3 3\n"
] | [
"5\n5 4 3 2 1\n",
"5\n1 2 3 2 1\n"
] | none | 1,000 | [
{
"input": "5\n1 2 3 4 5",
"output": "5\n5 4 3 2 1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "5\n1 2 3 2 1"
},
{
"input": "47\n3 4 5 3 1 4 4 3 4 6 1 5 1 3 5 3 6 5 1 4 3 2 6 5 3 1 4 6 4 6 2 1 1 1 4 3 6 1 6 6 3 5 1 4 6 4 4",
"output": "11\n1 2 3 4 5 6 5 4 3 2 1"
},
{
"input": ... | 1,669,464,777 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n = int(input())
v = list(map(int, input().split()))
v.sort(reverse=True)
v = v[v.count(v[0])-1:]
l, r = [], []
for i in range(1,len(v)):
if i%2: l.append(v[i])
else: r.append(v[i])
x = list(set(l))+ [v[0]] + list(set(r))[::-1]
print(len(x))
print(*x, sep=" ") | Title: Sereja and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja loves integer sequences very much. He especially likes stairs.
Sequence *a*1,<=*a*2,<=...,<=*a*|*a*| (|*a*| is the length of the sequence) is stairs if there is such index *i* (1<=≤<=*i*<=≤<=|*a*|), that the f... | ```python
n = int(input())
v = list(map(int, input().split()))
v.sort(reverse=True)
v = v[v.count(v[0])-1:]
l, r = [], []
for i in range(1,len(v)):
if i%2: l.append(v[i])
else: r.append(v[i])
x = list(set(l))+ [v[0]] + list(set(r))[::-1]
print(len(x))
print(*x, sep=" ")
``` | 0 | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,694,944,996 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 310 | 2,867,200 | from copy import copy
def solve_max(n, m, data):
result = 0
data.sort(reverse=True)
for i in range(n):
if data[0] == 0:
break
result += data[0]
data[0] -= 1
data.sort(reverse=True)
return result
def solve_min(n, m, data):
result = 0
... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
from copy import copy
def solve_max(n, m, data):
result = 0
data.sort(reverse=True)
for i in range(n):
if data[0] == 0:
break
result += data[0]
data[0] -= 1
data.sort(reverse=True)
return result
def solve_min(n, m, data):
resu... | 3 | |
90 | A | Cableway | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | A. Cableway | 2 | 256 | A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=100). It is guaranteed that *r*<=+<=*g*<=+<=*b*<=><=0, it means that the group consists of at least one student. | Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain. | [
"1 3 2\n",
"3 2 1\n"
] | [
"34",
"33"
] | Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the *r* group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the *g* group get on it; they get to the top at the moment of time 31.
At t... | 500 | [
{
"input": "1 3 2",
"output": "34"
},
{
"input": "3 2 1",
"output": "33"
},
{
"input": "3 5 2",
"output": "37"
},
{
"input": "10 10 10",
"output": "44"
},
{
"input": "29 7 24",
"output": "72"
},
{
"input": "28 94 13",
"output": "169"
},
{
"... | 1,599,385,572 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 218 | 0 |
l = [int(s) + 1 for s in input().split()]
r = ((l[0]//2) - 1) * 3
g = ((l[1]//2)-1) * 3 + 1
b = ((l[2]//2)-1) * 3 + 2
print(max(r,g,b)+ 30) | Title: Cableway
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cabl... | ```python
l = [int(s) + 1 for s in input().split()]
r = ((l[0]//2) - 1) * 3
g = ((l[1]//2)-1) * 3 + 1
b = ((l[2]//2)-1) * 3 + 2
print(max(r,g,b)+ 30)
``` | 3.9455 |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,698,336,435 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 10,649,600 | # -*- coding: utf-8 -*-
"""
Created on Thu Oct 26 23:22:34 2023
@author: 陈亚偲2300011106
"""
m,n=map(int,input().split())
a=[int(i) for i in input().split()]
b=[1]
q=1
for i in range(m-1,-1,-1):
if a[i]:
for j in range(i):
if a[j] and a[j]==a[i]:
a[j]=0
a[i]... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 26 23:22:34 2023
@author: 陈亚偲2300011106
"""
m,n=map(int,input().split())
a=[int(i) for i in input().split()]
b=[1]
q=1
for i in range(m-1,-1,-1):
if a[i]:
for j in range(i):
if a[j] and a[j]==a[i]:
a[j]=0
... | 0 | |
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,489,308,824 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 4,608,000 | n = int(input())
arr = [int(x) for x in input().split()]
summ = sum(arr)
ans = 0
for i in range(1,6):
if (i + summ) % (n + 1) == 1:
continue
else:
ans += 1
print(ans) | 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())
arr = [int(x) for x in input().split()]
summ = sum(arr)
ans = 0
for i in range(1,6):
if (i + summ) % (n + 1) == 1:
continue
else:
ans += 1
print(ans)
``` | 3 | |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,618,953,368 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n1 = int(input("n1"))
n2 = int(input("n2"))
k1 = int(input("k1"))
k2 = int(input("k2"))
#print(n1, n2, k1, k2)
f = n1**k1
s = n2**k2
#print(f,s)
if f > s:
print("First")
if s > f:
print("Second") | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
n1 = int(input("n1"))
n2 = int(input("n2"))
k1 = int(input("k1"))
k2 = int(input("k2"))
#print(n1, n2, k1, k2)
f = n1**k1
s = n2**k2
#print(f,s)
if f > s:
print("First")
if s > f:
print("Second")
``` | -1 | |
626 | B | Cards | PROGRAMMING | 1,300 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adja... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. | Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. | [
"2\nRB\n",
"3\nGRG\n",
"5\nBBBBB\n"
] | [
"G\n",
"BR\n",
"B\n"
] | In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue car... | 750 | [
{
"input": "2\nRB",
"output": "G"
},
{
"input": "3\nGRG",
"output": "BR"
},
{
"input": "5\nBBBBB",
"output": "B"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBB... | 1,574,185,178 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 0 | n = int(input())
s = str(input())
num_R = 0
num_B = 0
num_G = 0
elements = set()
for char in s:
if char == 'R':
num_R += 1
elements.add('R')
if char == 'B':
num_B += 1
elements.add('B')
if char == 'G':
num_G += 1
elements.add('G')
if elements == {'B', 'G', 'R'}:
print("BGR")
exit... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors... | ```python
n = int(input())
s = str(input())
num_R = 0
num_B = 0
num_G = 0
elements = set()
for char in s:
if char == 'R':
num_R += 1
elements.add('R')
if char == 'B':
num_B += 1
elements.add('B')
if char == 'G':
num_G += 1
elements.add('G')
if elements == {'B', 'G', 'R'}:
print("BGR... | 3 | |
747 | C | Servers | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of se... | The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks.
Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000)... | Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. | [
"4 3\n1 3 2\n2 2 1\n3 4 3\n",
"3 2\n3 2 3\n5 1 2\n",
"8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n"
] | [
"6\n-1\n10\n",
"3\n3\n",
"6\n9\n30\n-1\n15\n36\n"
] | In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third t... | 1,500 | [
{
"input": "4 3\n1 3 2\n2 2 1\n3 4 3",
"output": "6\n-1\n10"
},
{
"input": "3 2\n3 2 3\n5 1 2",
"output": "3\n3"
},
{
"input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8",
"output": "6\n9\n30\n-1\n15\n36"
},
{
"input": "4 1\n6 1 1",
"output": "1"
},
{
"inp... | 1,482,579,297 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 4,608,000 | class main():
def __init__(self):
servers = input().split(" ")
orders = int(servers[1])
a = int(servers[0])
servers = []
for i in range(a):
servers.append(0)
bef = 0
while(orders > 0):
t = input().split(" ")
k... | Title: Servers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three in... | ```python
class main():
def __init__(self):
servers = input().split(" ")
orders = int(servers[1])
a = int(servers[0])
servers = []
for i in range(a):
servers.append(0)
bef = 0
while(orders > 0):
t = input().split(" ")
... | 0 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,591,534,091 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 124 | 0 | n, a, b = map(int, input().split(" "))
out = (a+b)%n
if out == 0:
print(n)
else:
print(out)
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n, a, b = map(int, input().split(" "))
out = (a+b)%n
if out == 0:
print(n)
else:
print(out)
``` | 3 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,697,333,856 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | n = str(input())
n_list = n.split()
n_list_int = [int(x) for x in n_list]
height = str(input())
height_list = height.split()
height_list_int = [int(x) for x in height_list]
sum = 0;
for x in height_list_int:
if x > n_list_int[1]:
sum = sum + 2
else:
sum = sum + 1
prin... | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n = str(input())
n_list = n.split()
n_list_int = [int(x) for x in n_list]
height = str(input())
height_list = height.split()
height_list_int = [int(x) for x in height_list]
sum = 0;
for x in height_list_int:
if x > n_list_int[1]:
sum = sum + 2
else:
sum = sum + 1
... | 3 | |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,542,274,458 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 218 | 12,288,000 | import math
import string
def main():
n = int(input())
b = list(map(int, input().split()))
a = [b[i+1] + b[i] for i in range(n - 1)] + [b[-1]]
print(' '.join(map(str, a)))
if __name__ == '__main__':
main() | Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
import math
import string
def main():
n = int(input())
b = list(map(int, input().split()))
a = [b[i+1] + b[i] for i in range(n - 1)] + [b[-1]]
print(' '.join(map(str, a)))
if __name__ == '__main__':
main()
``` | 3 | |
456 | B | Fedya and Maths | PROGRAMMING | 1,200 | [
"math",
"number theory"
] | null | null | Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g. it can exceed any integer type of your programming language). | The single line contains a single integer *n* (0<=≤<=*n*<=≤<=10105). The number doesn't contain any leading zeroes. | Print the value of the expression without leading zeros. | [
"4\n",
"124356983594583453458888889\n"
] | [
"4\n",
"0\n"
] | Operation *x* *mod* *y* means taking remainder after division *x* by *y*.
Note to the first sample:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/825f244180bb10323db01645118c3cfdb312fa89.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4",
"output": "4"
},
{
"input": "124356983594583453458888889",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "7854",
"output": "0"
},
{
"input": "584660",
"output": "4"
},
{
"input": "464",
"output": "4"
},
{
"inp... | 1,680,334,644 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 21 | 1,000 | 102,400 | def quick(a: int ,b:int )->int:
re=1
while b>0:
if b%2==1:
re=re*a%5
b=b//2
a=a*a%5
return re
n=int(input())
sum=quick(2,n)+quick(3,n)+quick(4,n)+1;
sum=sum%5;
print(sum)
| Title: Fedya and Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g... | ```python
def quick(a: int ,b:int )->int:
re=1
while b>0:
if b%2==1:
re=re*a%5
b=b//2
a=a*a%5
return re
n=int(input())
sum=quick(2,n)+quick(3,n)+quick(4,n)+1;
sum=sum%5;
print(sum)
``` | 0 | |
877 | C | Slava and tanks | PROGRAMMING | 1,600 | [
"constructive algorithms"
] | null | null | Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map. | In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*.
If there are multiple answers, you can print any of them. | [
"2\n",
"3\n"
] | [
"3\n2 1 2 ",
"4\n2 1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "3\n2 1 2 "
},
{
"input": "3",
"output": "4\n2 1 3 2 "
},
{
"input": "4",
"output": "6\n2 4 1 3 2 4 "
},
{
"input": "6",
"output": "9\n2 4 6 1 3 5 2 4 6 "
},
{
"input": "10",
"output": "15\n2 4 6 8 10 1 3 5 7 9 2 4 6 8 10 "
},
{
... | 1,624,366,986 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 1,325 | 9,932,800 | def f(n):
l=[]
for i in range(n//2*2,1,-2):
l.append(i)
mid=[]
l=l[::-1]
for i in range(1,n+1):
if i not in l:
mid.append(i)
ans=l+mid+l
print(len(ans))
return ans
print(*f(int(input()))) | Title: Slava and tanks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there... | ```python
def f(n):
l=[]
for i in range(n//2*2,1,-2):
l.append(i)
mid=[]
l=l[::-1]
for i in range(1,n+1):
if i not in l:
mid.append(i)
ans=l+mid+l
print(len(ans))
return ans
print(*f(int(input())))
``` | 3 | |
56 | A | Bar | PROGRAMMING | 1,000 | [
"implementation"
] | A. Bar | 2 | 256 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da... | Print a single number which is the number of people Vasya should check to guarantee the law enforcement. | [
"5\n18\nVODKA\nCOKE\n19\n17\n"
] | [
"2\n"
] | In the sample test the second and fifth clients should be checked. | 500 | [
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI... | 1,686,823,460 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
Faster ;
int n;
map<string,int>m;
m["ABSINTH"]=1;
m["BEER"]=1;
m["BRANDY"]=1;
m["CHAMPAGNE"]=1;
m["GIN"]=1;
m["RUM"]=1;
m["SAKE"]=1;
... | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h... | ```python
#include<bits/stdc++.h>
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
Faster ;
int n;
map<string,int>m;
m["ABSINTH"]=1;
m["BEER"]=1;
m["BRANDY"]=1;
m["CHAMPAGNE"]=1;
m["GIN"]=1;
m["RUM"]=1;
m["SAK... | -1 |
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,656,143,119 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 248 | 6,656,000 | d={
25:0,
50:0,
100:0
}
input();ans='YES'
for i in map(int,input().split()):
if i==25:d[25]+=1
if i==50:
if d[25]==0:ans='NO';break
d[50]+=1;d[25]-=1
if i==100:
if d[25]>0 and d[50]>0:d[100]+=1;d[25]-=1;d[50]-=1
elif d[25]>2:d[100]+=1;d[25]-=3
else:ans='NO';break
print(ans) | 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
d={
25:0,
50:0,
100:0
}
input();ans='YES'
for i in map(int,input().split()):
if i==25:d[25]+=1
if i==50:
if d[25]==0:ans='NO';break
d[50]+=1;d[25]-=1
if i==100:
if d[25]>0 and d[50]>0:d[100]+=1;d[25]-=1;d[50]-=1
elif d[25]>2:d[100]+=1;d[25]-=3
else:ans='NO';break
print(... | 3 | |
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algor... | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\nj... | 1,618,499,448 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 93 | 0 | def swap(x):
return x[-1::-1]
n = int(input())
s = input()
for i in range(1, n + 1):
if not n%i:
s = swap(s[:i]) + s[i:]
print(s)
| Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$... | ```python
def swap(x):
return x[-1::-1]
n = int(input())
s = input()
for i in range(1, n + 1):
if not n%i:
s = swap(s[:i]) + s[i:]
print(s)
``` | 3 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,682,076,677 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 124 | 0 | n = int(input())
b = 0
c = 0
ba = 0
mas = list(map(int,input().split()))
for i in range(n):
if i%3==0:
c += mas[i]
elif i%3==1:
b += mas[i]
else:
ba += mas[i]
if c>b and c>ba:
print("chest")
elif b>c and b>ba:
print("biceps")
else:
print("back")
| Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
b = 0
c = 0
ba = 0
mas = list(map(int,input().split()))
for i in range(n):
if i%3==0:
c += mas[i]
elif i%3==1:
b += mas[i]
else:
ba += mas[i]
if c>b and c>ba:
print("chest")
elif b>c and b>ba:
print("biceps")
else:
print("back")
``` | 3 | |
347 | A | Difference Row | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000). | Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. | [
"5\n100 -100 50 0 -50\n"
] | [
"100 -50 0 50 -100 \n"
] | In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.
Sequence *x*<sub class="lower-inde... | 500 | [
{
"input": "5\n100 -100 50 0 -50",
"output": "100 -50 0 50 -100 "
},
{
"input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282",
"output": "963 -795 -367 -282 -49 -26 0 764 948 -939 "
},
{
"input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 ... | 1,685,202,050 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 124 | 0 | n=int(input())
a=list(map(int,input().split()))
M=max(a)
m=min(a)
a.remove(M)
a.remove(m)
a.sort()
l=[M]+a+[m]
for x in l:
print(x,end=" ") | Title: Difference Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote ... | ```python
n=int(input())
a=list(map(int,input().split()))
M=max(a)
m=min(a)
a.remove(M)
a.remove(m)
a.sort()
l=[M]+a+[m]
for x in l:
print(x,end=" ")
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,679,942,915 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 0 | a, b = input(), input()
s = [1 if a[i] != b[i] else 0 for i in range(len(a))]
print(*s, sep='')
| 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()
s = [1 if a[i] != b[i] else 0 for i in range(len(a))]
print(*s, sep='')
``` | 3.9845 |
20 | B | Equation | PROGRAMMING | 2,000 | [
"math"
] | B. Equation | 1 | 256 | You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order. | The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0. | In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point. | [
"1 -5 6\n"
] | [
"2\n2.0000000000\n3.0000000000"
] | none | 1,000 | [
{
"input": "1 -5 6",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "1\n-1.0000000000"
},
{
"input": "0 0 0",
"output": "-1"
},
{
"input": "0 -2 1",
"output": "1\n0.5000000000"
},
{
"inpu... | 1,666,597,600 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | a, b, c = [int(i) for i in input().split()]
if a == b == 0:
print(-1)
else:
if a == 0:
print(1)
print(-c/b)
exit()
d = b**2-4*a*c
if d<0:
print(0)
elif d == 0:
print(1)
print(-b/(2*a))
else:
print(2)
print((-b-d**0... | Title: Equation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input Specification:
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=1... | ```python
a, b, c = [int(i) for i in input().split()]
if a == b == 0:
print(-1)
else:
if a == 0:
print(1)
print(-c/b)
exit()
d = b**2-4*a*c
if d<0:
print(0)
elif d == 0:
print(1)
print(-b/(2*a))
else:
print(2)
prin... | 0 |
777 | C | Alyona and Spreadsheet | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | null | null | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the tab... | The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the followi... | Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n"
] | [
"Yes\nNo\nYes\nYes\nYes\nNo\n"
] | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | 1,500 | [
{
"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5",
"output": "Yes\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "Yes"
},
{
"input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n38686565... | 1,626,201,516 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 29,491,200 | n, m = map(int, input().split())
def binsearch(target, nums):
left = 0
right = len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] == target:
return mid
elif nums[mid] > target:
right = mid - 1
elif nums[mid] < targe... | Title: Alyona and Spreadsheet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By ... | ```python
n, m = map(int, input().split())
def binsearch(target, nums):
left = 0
right = len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] == target:
return mid
elif nums[mid] > target:
right = mid - 1
elif nums[mi... | 0 | |
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109... | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated ... | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\... | 1,546,280,867 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 1,433,600 | a,b=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
for i in range(1,10000000):
if i not in l:
b-=i
if b<0:
break
else:
l1+=[i]
print(len(l1))
print(*l1) | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania h... | ```python
a,b=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
for i in range(1,10000000):
if i not in l:
b-=i
if b<0:
break
else:
l1+=[i]
print(len(l1))
print(*l1)
``` | 0 | |
794 | C | Naming Company | PROGRAMMING | 1,800 | [
"games",
"greedy",
"sortings"
] | null | null | Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of *n* letters. Oleg and Igor ... | The first line of input contains a string *s* of length *n* (1<=≤<=*n*<=≤<=3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string *t* of length *n*. All characters of the string are lowercase English lett... | The output should contain a string of *n* lowercase English letters, denoting the company name if Oleg and Igor plays optimally. | [
"tinkoff\nzscoder\n",
"xxxxxx\nxxxxxx\n",
"ioi\nimo\n"
] | [
"fzfsirk\n",
"xxxxxx\n",
"ioi\n"
] | One way to play optimally in the first sample is as follows :
- Initially, the company name is ???????.- Oleg replaces the first question mark with 'f'. The company name becomes f??????.- Igor replaces the second question mark with 'z'. The company name becomes fz?????.- Oleg replaces the third question mark with '... | 1,750 | [
{
"input": "tinkoff\nzscoder",
"output": "fzfsirk"
},
{
"input": "xxxxxx\nxxxxxx",
"output": "xxxxxx"
},
{
"input": "ioi\nimo",
"output": "ioi"
},
{
"input": "abc\naaa",
"output": "aab"
},
{
"input": "reddit\nabcdef",
"output": "dfdeed"
},
{
"input": "... | 1,682,522,309 | 2,009 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
s = list(input().rstrip())
t = list(input().rstrip())
n = len(s)
s.sort()
t.sort(reverse = True)
n1, n2 = (n + 1) // 2, n // 2
c1, c2 = [0] * 27, [0] * 27
c1[26], c2[26] = 1, 1
for i in s[:n1]:
c1[i - 97] += 1
for i in t[:... | Title: Naming Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this p... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
s = list(input().rstrip())
t = list(input().rstrip())
n = len(s)
s.sort()
t.sort(reverse = True)
n1, n2 = (n + 1) // 2, n // 2
c1, c2 = [0] * 27, [0] * 27
c1[26], c2[26] = 1, 1
for i in s[:n1]:
c1[i - 97] += 1
fo... | 0 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,684,490,340 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 92 | 0 | a= int(input())
count = 0
host = []
guest = []
total = 0
while a != count:
b = input()
host_team, guest_team = map(int, b.split(' '))
host.append(host_team)
guest.append(guest_team)
if host_team in guest:
total += 1
if guest_team in host:
total += 1
count += 1
print(total)... | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
a= int(input())
count = 0
host = []
guest = []
total = 0
while a != count:
b = input()
host_team, guest_team = map(int, b.split(' '))
host.append(host_team)
guest.append(guest_team)
if host_team in guest:
total += 1
if guest_team in host:
total += 1
count += 1
pr... | 0 | |
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,625,754,657 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | def main():
l1=[]
l2=[]
lo=[]
dl1=[]
dl2=[]
n=int(input())
for i in range(n-1):
u,v=tuple(map(int,input().split()))
print(u,v)
if l1==[] and l2==[]:
l1+=[u]
l2+=[v]
elif u in l1:
l2+=[v]
elif v in l1:
l2+=[u]
elif v in l2:
l1+=[u]
elif u in l2:
l1+=[v]
else:... | 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
def main():
l1=[]
l2=[]
lo=[]
dl1=[]
dl2=[]
n=int(input())
for i in range(n-1):
u,v=tuple(map(int,input().split()))
print(u,v)
if l1==[] and l2==[]:
l1+=[u]
l2+=[v]
elif u in l1:
l2+=[v]
elif v in l1:
l2+=[u]
elif v in l2:
l1+=[u]
elif u in l2:
l1+=[v... | 0 | |
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,616,594,629 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | n = int(input())
n -= 3
print("ROY", end="")
s = "GBIV"
i = 0
while n:
i %= 4
print(s[i], end="")
i += 1
n -= 1
print()
| 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())
n -= 3
print("ROY", end="")
s = "GBIV"
i = 0
while n:
i %= 4
print(s[i], end="")
i += 1
n -= 1
print()
``` | 3.969 |
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer — the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0"... | 1,516,077,921 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 5,632,000 | n = int(input())
L = [i for i in map(int, input().split())]
alive = [True for i in range(n)]
i = n - 1
j = n - 2
while i > 0:
if j > 0:
# old_j -> j
old_j = min(i, j)
j = min(j, i - a[i])
alive[j : old_j] == False
i -= 1
if j == 0:
break
print(su... | Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ... | ```python
n = int(input())
L = [i for i in map(int, input().split())]
alive = [True for i in range(n)]
i = n - 1
j = n - 2
while i > 0:
if j > 0:
# old_j -> j
old_j = min(i, j)
j = min(j, i - a[i])
alive[j : old_j] == False
i -= 1
if j == 0:
break... | -1 | |
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algor... | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\nj... | 1,645,758,301 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | l = int(input())
c = input()
divisors = []
for i in range(1, l//2 +1):
if l % i == 0:
divisors.append(i)
for i in divisors:
c2 = c[0:i][::-1]
c = c2 + c[i:]
print(c[::-1]) | Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$... | ```python
l = int(input())
c = input()
divisors = []
for i in range(1, l//2 +1):
if l % i == 0:
divisors.append(i)
for i in divisors:
c2 = c[0:i][::-1]
c = c2 + c[i:]
print(c[::-1])
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.