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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,687,007,608 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | w=int(input("weight="))
while not 1<=w<=100:
w=int(input("weight="))
if w%2==0 and w!=2:
print("YES")
else:
print("NO")
| 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
w=int(input("weight="))
while not 1<=w<=100:
w=int(input("weight="))
if w%2==0 and w!=2:
print("YES")
else:
print("NO")
``` | 0 |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,568,653,568 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 280 | 1,433,600 | __author__ = 'Esfandiar'
n = int(input())
print(n,*range(1,n)) | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
__author__ = 'Esfandiar'
n = int(input())
print(n,*range(1,n))
``` | 3 | |
85 | A | Domino | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | A. Domino | 1 | 256 | We all know the problem about the number of ways one can tile a 2<=×<=*n* field by 1<=×<=2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes.
You are given a 4<=×<=*n* recta... | The input contains one positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of the field's columns. | If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing *n* characters each — that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a... | [
"4\n"
] | [
"yyzz\nbccd\nbxxd\nyyaa\n"
] | none | 500 | [
{
"input": "4",
"output": "aacc\nbbdd\nzkkz\nzllz"
},
{
"input": "2",
"output": "aa\nbb\naa\nbb"
},
{
"input": "3",
"output": "aab\nccb\nbaa\nbcc"
},
{
"input": "5",
"output": "aaccz\nbbddz\nzkkmm\nzllnn"
},
{
"input": "1",
"output": "a\na\nb\nb"
},
{
... | 1,572,505,131 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 436 | 2,150,400 | n=int(input())
if n%3==2:
print("-1")
else:
ans=["."*n for i in range(4)]
for i in range(n):
if i%2==0:
ans[i][0]="a"
ans[i][1]="a"
ans[i][2]="b"
ans[i][3]="b"
else:
ans[i][0]="b"
ans[i][1]="b"
... | Title: Domino
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
We all know the problem about the number of ways one can tile a 2<=×<=*n* field by 1<=×<=2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going... | ```python
n=int(input())
if n%3==2:
print("-1")
else:
ans=["."*n for i in range(4)]
for i in range(n):
if i%2==0:
ans[i][0]="a"
ans[i][1]="a"
ans[i][2]="b"
ans[i][3]="b"
else:
ans[i][0]="b"
ans[i][1]="b"
... | -1 |
292 | B | Network Topology | PROGRAMMING | 1,200 | [
"graphs",
"implementation"
] | null | null | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them... | The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*... | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo... | [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n"
] | [
"bus topology\n",
"ring topology\n",
"star topology\n",
"unknown topology\n"
] | none | 1,000 | [
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "bus topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "star topology"
},
{
"input": "4 4\n1 2\n2 3\n3 1\n1 4",
"output": "unknown topology"
},
{
"i... | 1,670,264,087 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def f(nn):
x=1
for i in range(len(nn)):
x=nn[i]
return x
n,m = list(map(int, input().split()))
nn = [0]n
a=[]
for i in range(m):
b,c = (list(map(int, input().split())))
a.append(b)
a.append(c)
nn[c-1]+=1
nn[b-1]+=1
if max(nn)==m:
print("star topology")
elif n... | Title: Network Topology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in... | ```python
def f(nn):
x=1
for i in range(len(nn)):
x=nn[i]
return x
n,m = list(map(int, input().split()))
nn = [0]n
a=[]
for i in range(m):
b,c = (list(map(int, input().split())))
a.append(b)
a.append(c)
nn[c-1]+=1
nn[b-1]+=1
if max(nn)==m:
print("star topology... | -1 | |
426 | B | Sereja and Mirroring | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Let's assume that we are given a matrix *b* of size *x*<=×<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=×<=*y* matrix *c* which has the following properties:
- the upper half of matrix *c* (rows with numbers from 1 to *x*) exactly matches *b*; - the lower half o... | The first line contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains *m* integers — the elements of matrix *a*. The *i*-th line contains integers *a**i*1,<=*a**i*2,<=...,<=*a**im* (0<=≤<=*a**ij*<=≤<=1) — the *i*-th row of the matrix *a*. | In the single line, print the answer to the problem — the minimum number of rows of matrix *b*. | [
"4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1\n",
"3 3\n0 0 0\n0 0 0\n0 0 0\n",
"8 1\n0\n1\n1\n0\n0\n1\n1\n0\n"
] | [
"2\n",
"3\n",
"2\n"
] | In the first test sample the answer is a 2 × 3 matrix *b*:
If we perform a mirroring operation with this matrix, we get the matrix *a* that is given in the input: | 1,000 | [
{
"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 0",
"output": "3"
},
{
"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0",
"output": "2"
},
{
"input": "10 4\n0 0 1 0\n0 0 1 0\n1 1 0 1\n0 0 1 1\n1 0 1 0\n1 0 1 0\n0 0 1 1\n1 1 0 1\n0 0 1 0\... | 1,398,613,485 | 885 | Python 3 | OK | TESTS | 65 | 124 | 0 | n,m=map(int,input().split())
a=[]
for i in range(n):
a.append(''.join(input().split()))
while n%2==0:
k=0
for i in range(n//2):
if a[i]==a[n-i-1]:
k+=1
if k!=n//2:
break
n=n//2
print(n) | Title: Sereja and Mirroring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's assume that we are given a matrix *b* of size *x*<=×<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=×<=*y* matrix *c* which has the following properties:
... | ```python
n,m=map(int,input().split())
a=[]
for i in range(n):
a.append(''.join(input().split()))
while n%2==0:
k=0
for i in range(n//2):
if a[i]==a[n-i-1]:
k+=1
if k!=n//2:
break
n=n//2
print(n)
``` | 3 | |
688 | A | Opponents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar... | The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th op... | Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. | [
"2 2\n10\n00\n",
"4 1\n0100\n",
"4 5\n1101\n1111\n0110\n1011\n1111\n"
] | [
"2\n",
"1\n",
"2\n"
] | In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | 500 | [
{
"input": "2 2\n10\n00",
"output": "2"
},
{
"input": "4 1\n0100",
"output": "1"
},
{
"input": "4 5\n1101\n1111\n0110\n1011\n1111",
"output": "2"
},
{
"input": "3 2\n110\n110",
"output": "2"
},
{
"input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111... | 1,601,415,110 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 124 | 0 | n_opps, n_days = input().strip().split()
n_days = int(n_days)
n_opps = int(n_opps)
max_cons_wins = 0
curr_cons_wins = 0
for _ in range(n_days):
n_dayopps = sum(c == '1' for c in input())
if n_dayopps != n_opps:
curr_cons_wins += 1
else:
curr_cons_wins = 0
max_cons_wins = max(max_cons_wi... | Title: Opponents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of th... | ```python
n_opps, n_days = input().strip().split()
n_days = int(n_days)
n_opps = int(n_opps)
max_cons_wins = 0
curr_cons_wins = 0
for _ in range(n_days):
n_dayopps = sum(c == '1' for c in input())
if n_dayopps != n_opps:
curr_cons_wins += 1
else:
curr_cons_wins = 0
max_cons_wins = max(m... | 3 | |
1,006 | F | Xor-Paths | PROGRAMMING | 2,100 | [
"bitmasks",
"brute force",
"dp",
"meet-in-the-middle"
] | null | null | There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
- You can move to the right or to ... | The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) — the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$). | Print one integer — the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$. | [
"3 3 11\n2 1 5\n7 10 0\n12 6 4\n",
"3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1\n",
"3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1\n"
] | [
"3\n",
"5\n",
"0\n"
] | All the paths from the first example:
- $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the path... | 0 | [
{
"input": "3 3 11\n2 1 5\n7 10 0\n12 6 4",
"output": "3"
},
{
"input": "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "5"
},
{
"input": "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "0"
},
{
"input": "1 1 1000000000000000000\n1000000000000000000",
"outpu... | 1,686,917,365 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 92 | 2,867,200 | import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
# sys.stderr = open("error.txt", "w")
input = sys.stdin.readline
n,m,k = map(int, input().split(' '))
arr = [ list(map(int, input().split(' '))) for i in range(n) ]
def solve(arr,i, j, xor):
if(i == n-1 and j == m-1 and xor^arr[i... | Title: Xor-Paths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bot... | ```python
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
# sys.stderr = open("error.txt", "w")
input = sys.stdin.readline
n,m,k = map(int, input().split(' '))
arr = [ list(map(int, input().split(' '))) for i in range(n) ]
def solve(arr,i, j, xor):
if(i == n-1 and j == m-1 and... | -1 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,679,984,635 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
l2=set(l)
l3=list(l2)
l3.sort()
if len(l3)==1:
print("NO")
else:
print(l3[1]) | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n=int(input())
l=list(map(int,input().split()))
l2=set(l)
l3=list(l2)
l3.sort()
if len(l3)==1:
print("NO")
else:
print(l3[1])
``` | 3.977 |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,681,903,423 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 171 | 7,065,600 | n = int(input())
a = [int(ak) for ak in input().split()]
count_num = [0] * 100001
for ak in a:
count_num[ak] += 1
dp = [0] * 100001
dp[1] = count_num[1]
for ak in range(2,len(dp)):
dp[ak] = max(dp[ak-1], dp[ak-2]+count_num[ak]*ak)
print(dp[-1]) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
a = [int(ak) for ak in input().split()]
count_num = [0] * 100001
for ak in a:
count_num[ak] += 1
dp = [0] * 100001
dp[1] = count_num[1]
for ak in range(2,len(dp)):
dp[ak] = max(dp[ak-1], dp[ak-2]+count_num[ak]*ak)
print(dp[-1])
``` | 3 | |
660 | D | Number of Parallelograms | PROGRAMMING | 1,900 | [
"geometry"
] | null | null | You are given *n* points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of points.
Each of the next *n* lines contains two integers (*x**i*,<=*y**i*) (0<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th point. | Print the only integer *c* — the number of parallelograms with the vertices at the given points. | [
"4\n0 1\n1 0\n1 1\n2 0\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "4\n0 1\n1 0\n1 1\n2 0",
"output": "1"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n6 6",
"output": "0"
},
{
"input": "5\n1 5\n4 2\n4 4\n8 1\n8 2",
"output": "0"
},
{
"input": "10\n1 7\n2 14\n3 7\n3 13\n5 13\n13 10\n15 12\n17 1\n18 8\n19 0",
... | 1,698,774,060 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 21 | 1,606 | 268,390,400 | from sys import stdin
input = lambda: stdin.buffer.readline().decode().strip()
from collections import Counter
points = []
n = int(input())
for _ in range(n):
x, y = map(int, input().split())
points += [(x, y)]
midPoints = Counter()
for i in range(n):
x1, y1 = points[i]
for j in range... | Title: Number of Parallelograms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
Input Specification:
The fir... | ```python
from sys import stdin
input = lambda: stdin.buffer.readline().decode().strip()
from collections import Counter
points = []
n = int(input())
for _ in range(n):
x, y = map(int, input().split())
points += [(x, y)]
midPoints = Counter()
for i in range(n):
x1, y1 = points[i]
for ... | 0 | |
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,610,305,210 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | n, m = map(int, input().split())
prices = list(map(int, input().split()))
prices.sort()
money = 0
for t in range(m):
if prices[0] < 0:
money -= prices.pop(0)
else:
break
print(money) | 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, m = map(int, input().split())
prices = list(map(int, input().split()))
prices.sort()
money = 0
for t in range(m):
if prices[0] < 0:
money -= prices.pop(0)
else:
break
print(money)
``` | 3.969 |
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a d... | The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). | Output one number — the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
... | 1,657,604,061 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 47 | 92 | 5,017,600 | import sys
import math
import collections
import heapq
input=sys.stdin.readline
n,k=(int(i) for i in input().split())
if(k==1):
print(n)
else:
print(pow(2,int(math.log(n,2))+1)-1) | Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co... | ```python
import sys
import math
import collections
import heapq
input=sys.stdin.readline
n,k=(int(i) for i in input().split())
if(k==1):
print(n)
else:
print(pow(2,int(math.log(n,2))+1)-1)
``` | 0 | |
91 | A | Newspaper Headline | PROGRAMMING | 1,500 | [
"greedy",
"strings"
] | A. Newspaper Headline | 2 | 256 | A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a n... | The input data contain two lines. The first line contain the heading *s*1, the second line contains the word *s*2. The lines only consist of lowercase Latin letters (1<=≤<=|*s*1|<=≤<=104,<=1<=≤<=|*s*2|<=≤<=106). | If it is impossible to get the word *s*2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings *s*1, which Fangy will need to receive the word *s*2. | [
"abc\nxyz\n",
"abcd\ndabc\n"
] | [
"-1\n",
"2\n"
] | none | 500 | [
{
"input": "abc\nxyz",
"output": "-1"
},
{
"input": "abcd\ndabc",
"output": "2"
},
{
"input": "ab\nbabaaab",
"output": "5"
},
{
"input": "ab\nbaaabba",
"output": "6"
},
{
"input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\nhbghjgijijcdafcbgiedichdeebaddfddb",
"ou... | 1,626,174,662 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 340 | 6,758,400 | a,s1,s2=1,input(),input();s=s1
while s1.find(s2)==-1 and a-10001:
s1+=s
a+=1
print(a if a-10001 else -1) | Title: Newspaper Headline
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order... | ```python
a,s1,s2=1,input(),input();s=s1
while s1.find(s2)==-1 and a-10001:
s1+=s
a+=1
print(a if a-10001 else -1)
``` | 0 |
715 | B | Complete The Graph | PROGRAMMING | 2,300 | [
"binary search",
"constructive algorithms",
"graphs",
"shortest paths"
] | null | null | ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of... | The first line contains five integers *n*,<=*m*,<=*L*,<=*s*,<=*t* (2<=≤<=*n*<=≤<=1000,<=<=1<=≤<=*m*<=≤<=10<=000,<=<=1<=≤<=*L*<=≤<=109,<=<=0<=≤<=*s*,<=*t*<=≤<=*n*<=-<=1,<=<=*s*<=≠<=*t*) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
Then, ... | Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
Otherwise, print "YES" in the first line. Next *m* lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. *i*-th of them should contain three integers *u*... | [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n"
] | [
"YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n",
"YES\n0 1 123456789\n",
"NO\n"
] | Here's how the graph in the first sample case looks like :
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456... | 1,000 | [
{
"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4",
"output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4"
},
{
"input": "2 1 123456789 0 1\n0 1 0",
"output": "YES\n0 1 123456789"
},
{
"input": "2 1 999999999 1 0\n0 1 1000000000",
"output": "NO"
},
{
"input": "4 5 10 1 2\... | 1,611,332,199 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define en cin.close();return 0;
#define INF ((ll)(4e18))
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
const ll N = 1005;
vec... | Title: Complete The Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder r... | ```python
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define en cin.close();return 0;
#define INF ((ll)(4e18))
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
const ll N = ... | -1 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,560,014,069 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | n=int(input())
s=list(str(input()))
ans=0
for i in range(0,2*(n-1),2):
#print(i)
if s[i] != (s[i+1]).lower():
ans+=1
print(ans) | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
n=int(input())
s=list(str(input()))
ans=0
for i in range(0,2*(n-1),2):
#print(i)
if s[i] != (s[i+1]).lower():
ans+=1
print(ans)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок,... | В первой строке входных данных следует целое положительное число *n* (3<=≤<=*n*<=≤<=1000) — количество оценок, полученных Васей.
Во второй строке входных данных следует последовательность из *n* чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5) — оценки, полученные Васей. Оценки заданы в том порядке, в котором Вас... | Выведите одно целое число — количество подарков, полученных Васей. | [
"6\n4 5 4 5 4 4\n",
"14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5\n"
] | [
"2\n",
"3\n"
] | В первом примере Вася получит два подарка — за первые три положительные оценки и за следующую тройку положительных оценок соответственно. | 0 | [
{
"input": "6\n4 5 4 5 4 4",
"output": "2"
},
{
"input": "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5",
"output": "3"
},
{
"input": "3\n4 5 4",
"output": "1"
},
{
"input": "3\n4 5 1",
"output": "0"
},
{
"input": "4\n5 4 3 5",
"output": "0"
},
{
"input": "10\n4 4 5... | 1,458,813,035 | 6,635 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 4,608,000 | n = int(input())
a = []
r = 0
a = input().split()
for i in range(n) :
a[i] = int(a[i])
scane = 0
while scane < ( n - 3 ) :
plus = 0
if a[scane] > 3 :
plus+=1
if a[scane+1] > 3 and a[scane+2] > 3 :
r+=1
plus+=1
scane+=(plus)
else :
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи ... | ```python
n = int(input())
a = []
r = 0
a = input().split()
for i in range(n) :
a[i] = int(a[i])
scane = 0
while scane < ( n - 3 ) :
plus = 0
if a[scane] > 3 :
plus+=1
if a[scane+1] > 3 and a[scane+2] > 3 :
r+=1
plus+=1
scane+=(plus)
... | 0 | |
821 | A | Okabe and Future Gadget Laboratory | PROGRAMMING | 800 | [
"implementation"
] | null | null | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). | Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case. | [
"3\n1 1 2\n2 3 1\n6 4 1\n",
"3\n1 5 2\n1 1 1\n1 2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an inte... | 500 | [
{
"input": "3\n1 1 2\n2 3 1\n6 4 1",
"output": "Yes"
},
{
"input": "3\n1 5 2\n1 1 1\n1 2 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2... | 1,498,443,798 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 967 | 5,529,600 | # Time : 2017-6-26 10:30
# Auther : Anjone
# URL : http://codeforces.com/contest/821/problem/A
n = int(input())
arr = [ list(map(int,input().split())) for i in range(n)]
for i in range(n):
for j in range(n):
if( arr[i][j] != 1):
cnt = 0
for k in range(n):
for l in range(n):
if(arr[i][k] +... | Title: Okabe and Future Gadget Laboratory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in whi... | ```python
# Time : 2017-6-26 10:30
# Auther : Anjone
# URL : http://codeforces.com/contest/821/problem/A
n = int(input())
arr = [ list(map(int,input().split())) for i in range(n)]
for i in range(n):
for j in range(n):
if( arr[i][j] != 1):
cnt = 0
for k in range(n):
for l in range(n):
if(a... | 3 | |
387 | C | George and Number | PROGRAMMING | 1,700 | [
"greedy",
"implementation"
] | null | null | George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers *b*. During the game, George modifies the array by using special changes. Let's mark George's current array as *b*1,<=*b*2,<=...,<=*b*|*b*| (record |*b*| denotes the current length of the array). Then one chang... | The first line of the input contains a single integer *p* (1<=≤<=*p*<=<<=10100000). It is guaranteed that number *p* doesn't contain any leading zeroes. | Print an integer — the maximum number of elements array *b* could contain originally. | [
"9555\n",
"10000000005\n",
"800101\n",
"45\n",
"1000000000000001223300003342220044555\n",
"19992000\n",
"310200\n"
] | [
"4",
"2",
"3",
"1",
"17",
"1",
"2"
] | Let's consider the test examples:
- Originally array *b* can be equal to {5, 9, 5, 5}. The sequence of George's changes could have been: {5, 9, 5, 5} → {5, 5, 95} → {95, 55} → {9555}. - Originally array *b* could be equal to {1000000000, 5}. Please note that the array *b* cannot contain zeros. - Originally array *... | 1,500 | [
{
"input": "9555",
"output": "4"
},
{
"input": "10000000005",
"output": "2"
},
{
"input": "800101",
"output": "3"
},
{
"input": "45",
"output": "1"
},
{
"input": "1000000000000001223300003342220044555",
"output": "17"
},
{
"input": "19992000",
"out... | 1,545,669,963 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 171 | 204,800 | p = input().strip()
n = len(p)
j = n - 1
ans = 0
while(j >= 0):
k = j
while p[k] == '0':
k -= 1
ln = j - k + 1
if ln > k:
ans += 1
j = -1
elif ln == k:
if (p[0] >= p[k]):
j = k - 1
else:
j = -1
ans... | Title: George and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers *b*. During the game, George modifies the array by using special changes. Let's mark George's current array... | ```python
p = input().strip()
n = len(p)
j = n - 1
ans = 0
while(j >= 0):
k = j
while p[k] == '0':
k -= 1
ln = j - k + 1
if ln > k:
ans += 1
j = -1
elif ln == k:
if (p[0] >= p[k]):
j = k - 1
else:
j = -1
... | 3 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,662,043,138 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | a,b,c = map(int, input().split())
d,e,f = map(int, input().split())
g,h,i = map(int, input().split())
a1, b1, c1, d1, e1, f1, g1, h1, i1= 1,1,1,1,1,1,1,1,1
def lightControl(x):
if x == 1:
return x-1
else:
return x + 1
if a>0 and a%2 == 1:
a1 = lightControl(a1)
b1... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
a,b,c = map(int, input().split())
d,e,f = map(int, input().split())
g,h,i = map(int, input().split())
a1, b1, c1, d1, e1, f1, g1, h1, i1= 1,1,1,1,1,1,1,1,1
def lightControl(x):
if x == 1:
return x-1
else:
return x + 1
if a>0 and a%2 == 1:
a1 = lightControl(a... | 3 | |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1... | 1,576,586,385 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 186 | 0 | s = input()
l = 0
b = 0
fl = False
for i in s:
if i.islower():
fl = True
if fl:
if i.isupper():
b += 1
else:
l += 1
if b == 0:
print(0)
else:
lb = l > b
c = 0
fl = False
for i in s:
if lb:
if fl and i.isu... | Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them... | ```python
s = input()
l = 0
b = 0
fl = False
for i in s:
if i.islower():
fl = True
if fl:
if i.isupper():
b += 1
else:
l += 1
if b == 0:
print(0)
else:
lb = l > b
c = 0
fl = False
for i in s:
if lb:
if fl... | 0 | |
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"... | 1,618,504,029 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 2,867,200 | if __name__ == '__main__':
s, r = list(input()), []
for c in s:
if r and c == r[-1]:r.pop()
else:r.append(c)
print("".join(r)) | Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed... | ```python
if __name__ == '__main__':
s, r = list(input()), []
for c in s:
if r and c == r[-1]:r.pop()
else:r.append(c)
print("".join(r))
``` | 3.885659 |
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,678,422,815 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 154 | 0 | #******************************
#import os
#import sys
from math import *
#import re
#import random
#sys.set_int_max_str_digits(int(1e9))
def solve():
a=[]
b=[]
c=[]
for i in range(int(input())):
#for _ in range(1):
#n = int(input())
p, q, r= [int(x) for x i... | 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
#******************************
#import os
#import sys
from math import *
#import re
#import random
#sys.set_int_max_str_digits(int(1e9))
def solve():
a=[]
b=[]
c=[]
for i in range(int(input())):
#for _ in range(1):
#n = int(input())
p, q, r= [int(... | 3.9615 |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,627,889,859 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 20,172,800 | n = int(input())
p = int(input())
q = int(input())
print(n*max(p,q)/100) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
n = int(input())
p = int(input())
q = int(input())
print(n*max(p,q)/100)
``` | 0 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,698,604,076 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | N = int(input())
järjend = list(map(int,input().split()))
pikk = max(järjend)
lühike = min(järjend)
pikka_asukoht = 0
for i in range(N):
if järjend[i] == pikk:
pikka_asukoht = i
break
lühikese_asukoht = 0
for i in range(N):
if järjend[i] == lühike:
lühikese_asukoht = i
... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
N = int(input())
järjend = list(map(int,input().split()))
pikk = max(järjend)
lühike = min(järjend)
pikka_asukoht = 0
for i in range(N):
if järjend[i] == pikk:
pikka_asukoht = i
break
lühikese_asukoht = 0
for i in range(N):
if järjend[i] == lühike:
lühikese_asuk... | 3 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,696,700,817 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 31 | 0 | res = []
for number in range(1, 10000):
if sum([int(i) for i in str(number)]) == 10:
res.append(number)
print(res[int(input()) - 1]) | Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
res = []
for number in range(1, 10000):
if sum([int(i) for i in str(number)]) == 10:
res.append(number)
print(res[int(input()) - 1])
``` | -1 | |
784 | F | Crunching Numbers Just for You | PROGRAMMING | 1,900 | [
"*special",
"implementation"
] | null | null | You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order. | The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100). | Output space-separated elements of the sorted array. | [
"3 3 1 2\n"
] | [
"1 2 3 \n"
] | Remember, this is a very important feature, and you have to make sure the customers appreciate it! | 0 | [
{
"input": "3 3 1 2",
"output": "1 2 3 "
},
{
"input": "10 54 100 27 1 33 27 80 49 27 6",
"output": "1 6 27 27 27 33 49 54 80 100 "
}
] | 1,617,051,921 | 5,121 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | print('1 2 3') | Title: Crunching Numbers Just for You
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done.... | ```python
print('1 2 3')
``` | 0 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,694,045,151 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | numeros = str(input())
lista = []
spacePlace = numeros.find(" ")
iguales = []
for i in range(4):
if (spacePlace != -1):
lista.append(int(numeros[:spacePlace + 1]))
numeros = numeros[(spacePlace + 1):]
spacePlace = numeros.find(' ')
else:
lista.append(int(numeros))
for item in lis... | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
numeros = str(input())
lista = []
spacePlace = numeros.find(" ")
iguales = []
for i in range(4):
if (spacePlace != -1):
lista.append(int(numeros[:spacePlace + 1]))
numeros = numeros[(spacePlace + 1):]
spacePlace = numeros.find(' ')
else:
lista.append(int(numeros))
for i... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,617,396,074 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | M_str = input()
M = int(M_str)
N_str = input("How many columns on the rectangular board?:\n")
N = int(N_str)
if M < 1 or M > 1000000 and N < 1 or N > 1000000 :
print ('The number of columns and rows should be between 1 and 1000000.')
else:
number_of_squares = M * N
print (number_of_squares // 2)
... | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M_str = input()
M = int(M_str)
N_str = input("How many columns on the rectangular board?:\n")
N = int(N_str)
if M < 1 or M > 1000000 and N < 1 or N > 1000000 :
print ('The number of columns and rows should be between 1 and 1000000.')
else:
number_of_squares = M * N
print (number_of_squares // 2)... | -1 |
631 | C | Report | PROGRAMMING | 1,700 | [
"data structures",
"sortings"
] | null | null | Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of commodities in the report and the number of managers, respectively.
The second line contains *n* integers *a**i* (|*a**i*|<=≤<=109) — the initial report before it gets to the first manager.
Then follow *m* lin... | Print *n* integers — the final report, which will be passed to Blake by manager number *m*. | [
"3 1\n1 2 3\n2 2\n",
"4 2\n1 2 4 3\n2 3\n1 2\n"
] | [
"2 1 3 ",
"2 4 1 3 "
] | In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.
In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the r... | 1,500 | [
{
"input": "3 1\n1 2 3\n2 2",
"output": "2 1 3 "
},
{
"input": "4 2\n1 2 4 3\n2 3\n1 2",
"output": "2 4 1 3 "
},
{
"input": "4 1\n4 3 2 1\n1 4",
"output": "1 2 3 4 "
},
{
"input": "5 1\n1 2 3 4 5\n2 5",
"output": "5 4 3 2 1 "
},
{
"input": "6 2\n3 1 2 6 4 5\n1 6\n... | 1,459,428,670 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 30,924,800 | a, b = (int(i) for i in input().split())
f = []
t = input().split()
for i in range(a):
f.append(int(t[i]))
d = []
for i in range(b):
c, e = (int(t) for t in input().split())
d.append([c, e])
for i in range(b):
u = int(d[i][1])
if d[i][0] == 1:
g = sorted(f[:u])
f[:u] = g... | Title: Report
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that... | ```python
a, b = (int(i) for i in input().split())
f = []
t = input().split()
for i in range(a):
f.append(int(t[i]))
d = []
for i in range(b):
c, e = (int(t) for t in input().split())
d.append([c, e])
for i in range(b):
u = int(d[i][1])
if d[i][0] == 1:
g = sorted(f[:u])
... | 0 | |
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"... | 1,572,756,321 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 342 | 2,560,000 | def plugin(string):
stack = []
for i in string:
if len(stack) == 0:
stack.append(i)
else:
if stack[-1] == i:
stack.pop()
else:
stack.append(i)
return "".join(stack)
string = input()
print(plugin(strin... | Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed... | ```python
def plugin(string):
stack = []
for i in string:
if len(stack) == 0:
stack.append(i)
else:
if stack[-1] == i:
stack.pop()
else:
stack.append(i)
return "".join(stack)
string = input()
print(pl... | 3.824232 |
821 | A | Okabe and Future Gadget Laboratory | PROGRAMMING | 800 | [
"implementation"
] | null | null | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). | Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case. | [
"3\n1 1 2\n2 3 1\n6 4 1\n",
"3\n1 5 2\n1 1 1\n1 2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an inte... | 500 | [
{
"input": "3\n1 1 2\n2 3 1\n6 4 1",
"output": "Yes"
},
{
"input": "3\n1 5 2\n1 1 1\n1 2 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2... | 1,598,046,009 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 171 | 22,630,400 | n = int(input())
aij = [list(map(int,input().split())) for i in range(n)]
ans = "YES"
for i in range(n):
for j in range(n):
if aij[i][j] != 1:
flag = 0
for i2 in range(n):
for j2 in range(n):
if i2 != i and j2 != j and aij[i2][j] + aij[i][... | Title: Okabe and Future Gadget Laboratory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in whi... | ```python
n = int(input())
aij = [list(map(int,input().split())) for i in range(n)]
ans = "YES"
for i in range(n):
for j in range(n):
if aij[i][j] != 1:
flag = 0
for i2 in range(n):
for j2 in range(n):
if i2 != i and j2 != j and aij[i2][j]... | 3 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,588,939,295 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 248 | 7,065,600 | import copy
import math
n=int(input())
a=list(map(int,input().split()))
x=[]
for i in range(0,n-1):
c=int(math.fabs(a[i]-a[i+1]))
x.append(c)
c=int(math.fabs(a[0]-a[n-1]))
x.append(c)
d=min(x)
for i in range(0,n):
if d==x[i]:
if i==n-1:
print(1,n)
else:
... | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
import copy
import math
n=int(input())
a=list(map(int,input().split()))
x=[]
for i in range(0,n-1):
c=int(math.fabs(a[i]-a[i+1]))
x.append(c)
c=int(math.fabs(a[0]-a[n-1]))
x.append(c)
d=min(x)
for i in range(0,n):
if d==x[i]:
if i==n-1:
print(1,n)
else:... | 3.924839 |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,566,440,791 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | def main():
nk = list(map(int, input("").split()))
set1 = set(map(int, input("").split()))
set2 = set(map(int, input("").split()))
n = nk[0]
k = nk[1]
print(len(set1 - set2))
if __name__ == '__main__':
main() | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
def main():
nk = list(map(int, input("").split()))
set1 = set(map(int, input("").split()))
set2 = set(map(int, input("").split()))
n = nk[0]
k = nk[1]
print(len(set1 - set2))
if __name__ == '__main__':
main()
``` | 0 | |
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome ... | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The pictur... | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 ... | 1,653,742,428 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,m,x1,y=map(int,input().split());a=[]
for i in range(n):
s=list(map(str,str(input())))
a.append(s)
o=0;l=0;h=n-2;p=0
while h<n:
x=x1
for i in range(x,y+1):
if n==6:
l=1
for j in range(m):
if a[i][j]=='#':
p+=1
x+=1
if p==0:
... | Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulf... | ```python
n,m,x1,y=map(int,input().split());a=[]
for i in range(n):
s=list(map(str,str(input())))
a.append(s)
o=0;l=0;h=n-2;p=0
while h<n:
x=x1
for i in range(x,y+1):
if n==6:
l=1
for j in range(m):
if a[i][j]=='#':
p+=1
x+=1
if p==... | 0 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,658,337,878 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n=str(input())
z=n.count('0')
o=n.count('1')
if z>7 or o>7:
print("YES")
else:print("NO") | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n=str(input())
z=n.count('0')
o=n.count('1')
if z>7 or o>7:
print("YES")
else:print("NO")
``` | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,697,703,780 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
a = list(map(int,input().split()))
d = [0] * n
for i in range(n):
ind = a.index(a[i])
l = a[i]-1
d[l] = ind+1
print(d)
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n = int(input())
a = list(map(int,input().split()))
d = [0] * n
for i in range(n):
ind = a.index(a[i])
l = a[i]-1
d[l] = ind+1
print(d)
``` | 0 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,668,854,818 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 124 | 0 | s=input()
i=s.find('0')
if i==-1:print(s[:len(s)-1])
else:print(s[:i]+s[i+1:]) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s=input()
i=s.find('0')
if i==-1:print(s[:len(s)-1])
else:print(s[:i]+s[i+1:])
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,681,462,772 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n=int(input())
arr=list(map(int,input().split()))
a=[]
for i in range(n):
# k=arr.index(i)
a.insert(arr[i]-1,i)
for i in a:
print(i,end=' ') | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input())
arr=list(map(int,input().split()))
a=[]
for i in range(n):
# k=arr.index(i)
a.insert(arr[i]-1,i)
for i in a:
print(i,end=' ')
``` | 0 | |
637 | C | Promocodes with Mistakes | PROGRAMMING | 1,400 | [
"*special",
"brute force",
"constructive algorithms",
"implementation"
] | null | null | During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at a... | The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes.
Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0". | Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes. | [
"2\n000000\n999999\n",
"6\n211111\n212111\n222111\n111111\n112111\n121111\n"
] | [
"2\n",
"0\n"
] | In the first sample *k* < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it. | 1,500 | [
{
"input": "2\n000000\n999999",
"output": "2"
},
{
"input": "6\n211111\n212111\n222111\n111111\n112111\n121111",
"output": "0"
},
{
"input": "1\n123456",
"output": "6"
},
{
"input": "2\n000000\n099999",
"output": "2"
},
{
"input": "2\n000000\n009999",
"output"... | 1,457,907,266 | 36,866 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sun Mar 13 19:40:03 2016
@author: Kostya S.
"""
from math import ceil
def hem(s,t):
r = 0
for u,v in zip(s,t):
r += u != v
return r
n = int(input())
code = set()
for _ in range(n):
c = (input())
code.add(c)
dist = s... | Title: Promocodes with Mistakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all th... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 13 19:40:03 2016
@author: Kostya S.
"""
from math import ceil
def hem(s,t):
r = 0
for u,v in zip(s,t):
r += u != v
return r
n = int(input())
code = set()
for _ in range(n):
c = (input())
code.add(c)
... | 0 | |
660 | C | Hard Process | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | 0 | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"o... | 1,692,178,249 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n, k = map(int, input().split())
elements = list(map(int, input().split()))
left_pointer = 0 # Left pointer of the sliding window
max_length = 0 # Maximum length of the subsegment
zero_count = 0 # Count of zeroes in the current subsegment
for right_pointer in range(n):
if elements[right_pointer] == 0:
... | Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can ch... | ```python
n, k = map(int, input().split())
elements = list(map(int, input().split()))
left_pointer = 0 # Left pointer of the sliding window
max_length = 0 # Maximum length of the subsegment
zero_count = 0 # Count of zeroes in the current subsegment
for right_pointer in range(n):
if elements[right_pointer] == 0... | 0 | |
309 | A | Morning run | PROGRAMMING | 2,000 | [
"binary search",
"math",
"two pointers"
] | null | null | People like to be fit. That's why many of them are ready to wake up at dawn, go to the stadium and run. In this problem your task is to help a company design a new stadium.
The city of N has a shabby old stadium. Many people like it and every morning thousands of people come out to this stadium to run. The stadium ca... | The first line of the input contains three integers *n*, *l*, *t* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*l*<=≤<=109,<=1<=≤<=*t*<=≤<=109). The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=<<=*l*), here *a**i* is the clockwise distance from the start line t... | Print a single real number — the answer to the problem with absolute or relative error of at most 10<=-<=6. | [
"2 5 1\n0 2\n",
"3 7 3\n0 1 6\n"
] | [
"0.2500000000\n",
"1.5000000000\n"
] | There are two runners in the first example. If the first runner run clockwise direction, then in 1 time unit he will be 1m away from the start line. If the second runner run counter-clockwise direction then in 1 time unit he will be also 1m away from the start line. And it is the only possible way to meet. We assume th... | 500 | [] | 1,689,434,564 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689434564.5995135")# 1689434564.5995345 | Title: Morning run
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People like to be fit. That's why many of them are ready to wake up at dawn, go to the stadium and run. In this problem your task is to help a company design a new stadium.
The city of N has a shabby old stadium. Many peo... | ```python
print("_RANDOM_GUESS_1689434564.5995135")# 1689434564.5995345
``` | 0 | |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,584,870,861 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 15,667,200 | n,m = map(int,input().split())
stage_matrix = []
dp_row = [[0 for i in range(m+1)] for j in range(n+1)]
dp_col = [[0 for i in range(n+1)] for j in range(m+1)]
for i in range(n):
stage_matrix.append(list(map(int,input().split())))
for i in range(1,n+1):
for j in range(1,m+1):
if stage_matrix[i-1][j-1... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
n,m = map(int,input().split())
stage_matrix = []
dp_row = [[0 for i in range(m+1)] for j in range(n+1)]
dp_col = [[0 for i in range(n+1)] for j in range(m+1)]
for i in range(n):
stage_matrix.append(list(map(int,input().split())))
for i in range(1,n+1):
for j in range(1,m+1):
if stage_matri... | 0 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,697,466,376 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a=int(input())
b=list(map(int,input().split()))
b.sort()
d=sum(b)
c=[]
for n in range(len(b)):
if sum(c)<=d-sum(c):
c.append(b[n])
print(c)
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
a=int(input())
b=list(map(int,input().split()))
b.sort()
d=sum(b)
c=[]
for n in range(len(b)):
if sum(c)<=d-sum(c):
c.append(b[n])
print(c)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Levko has an array that consists of integers: *a*1,<=*a*2,<=... ,<=*a**n*. But he doesn’t like this array at all.
Levko thinks that the beauty of the array *a* directly depends on value *c*(*a*), which can be calculated by the formula:
It’s time to change the world and Levko is going to change his array for the bett... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2000). The second line contains space-separated integers *a*1,<=*a*2,<=... ,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | A single number — the minimum value of *c*(*a*) Levko can get. | [
"5 2\n4 7 4 7 4\n",
"3 1\n-100 0 100\n",
"6 3\n1 2 3 7 8 9\n"
] | [
"0\n",
"100\n",
"1\n"
] | In the first sample Levko can change the second and fourth elements and get array: 4, 4, 4, 4, 4.
In the third sample he can get array: 1, 2, 3, 4, 5, 6. | 0 | [
{
"input": "5 2\n4 7 4 7 4",
"output": "0"
},
{
"input": "3 1\n-100 0 100",
"output": "100"
},
{
"input": "6 3\n1 2 3 7 8 9",
"output": "1"
},
{
"input": "4 1\n-1000000000 -1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "10 1\n-6 5 -7 -7 -... | 1,608,157,631 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 3,276,800 | import sys
import math
MAX = int(1e9)
MIN = int(1e9)
N = 2000
def reset(dp):
for i in range(1, N):
# Can always change all preceding entries
dp[i] = i
def check(n, k, arr, c, dp):
# dp[i]: minimum # of changes to make cost <= c from 0..i and i is unchanged.
reset(dp)
for i in range(... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko has an array that consists of integers: *a*1,<=*a*2,<=... ,<=*a**n*. But he doesn’t like this array at all.
Levko thinks that the beauty of the array *a* directly depends on value *c*(*a*), which can be calculated by the fo... | ```python
import sys
import math
MAX = int(1e9)
MIN = int(1e9)
N = 2000
def reset(dp):
for i in range(1, N):
# Can always change all preceding entries
dp[i] = i
def check(n, k, arr, c, dp):
# dp[i]: minimum # of changes to make cost <= c from 0..i and i is unchanged.
reset(dp)
for i... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,617,603,418 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | M, N = input().split()
M, N = int(M), int(N)
A1= int(M*N/2)
if M <= N: print(A1)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M, N = input().split()
M, N = int(M), int(N)
A1= int(M*N/2)
if M <= N: print(A1)
``` | 3.969 |
0 | none | none | none | 0 | [
"none"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert... | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*... | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https... | 0 | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1... | 1,488,111,461 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 1,356 | 19,456,000 | a = input()
b = input()
p = list(map(int, input().split()))
for i in range(len(p)):
p[i] -= 1
def good(m):
pos = 0
a1 = list(a)
for i in range(m):
a1[p[i]] = "#"
for i in range(len(a1)):
if a1[i] == b[pos]:
pos += 1
if pos == len(b):
return Tr... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nas... | ```python
a = input()
b = input()
p = list(map(int, input().split()))
for i in range(len(p)):
p[i] -= 1
def good(m):
pos = 0
a1 = list(a)
for i in range(m):
a1[p[i]] = "#"
for i in range(len(a1)):
if a1[i] == b[pos]:
pos += 1
if pos == len(b):
... | 3 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,679,816,337 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def func(n,str):
c=0
m=0
q=list(str)
for i in range(len(q)-1):
if (q[i]+q[i+1])=="SF":
c=c+1
elif (q[i]+q[i+1])=="FS":
m=m+1
if c>m:
return "yes"
else:
return "no"
n=4
st="FSSF"
P=func(n,st)
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
def func(n,str):
c=0
m=0
q=list(str)
for i in range(len(q)-1):
if (q[i]+q[i+1])=="SF":
c=c+1
elif (q[i]+q[i+1])=="FS":
m=m+1
if c>m:
return "yes"
else:
return "no"
n=4
st="FSSF"
P=func(n,st)
``` | 0 | |
687 | D | Dividing Kingdom II | PROGRAMMING | 2,500 | [
"brute force",
"data structures",
"dsu",
"graphs",
"sortings"
] | null | null | Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves.
The great kingdom consisted of *n* cities numbered from 1 to *n* and *m* bidirectional roads bet... | The first line of the input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*q*<=≤<=1000, ) — the number of cities and roads in the great kingdom, and the number of guesses, respectively.
The *i*-th line of the following *m* lines contains three integers *u**i*,<=*v**i* and *w**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<... | For each guess print the minimum possible hardness of the division in described scenario. | [
"5 6 5\n5 4 86\n5 1 0\n1 3 38\n2 1 33\n2 4 28\n2 3 40\n3 5\n2 6\n1 3\n2 3\n1 6\n"
] | [
"-1\n33\n-1\n-1\n33\n"
] | none | 2,000 | [] | 1,664,984,855 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 6,000 | 116,838,400 | from collections import deque
class UnionFind():
def __init__(self,size):
self.table = [-1 for _ in range(size)]
self.member_num = [1 for _ in range(size)]
#representative
#O(a(N))
def find(self,x):
Q = deque()
while self.table[x] >= 0:
Q.append... | Title: Dividing Kingdom II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between them... | ```python
from collections import deque
class UnionFind():
def __init__(self,size):
self.table = [-1 for _ in range(size)]
self.member_num = [1 for _ in range(size)]
#representative
#O(a(N))
def find(self,x):
Q = deque()
while self.table[x] >= 0:
... | 0 | |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be... | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,646,972,552 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 31 | 0 | con=True
for _ in [0]*int(input()):
a=[*map(int,input().split()[1:])]
if a[0]>=2400 and a[1]>a[0] and con:print('YES');con=False
if con:print('NO') | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
con=True
for _ in [0]*int(input()):
a=[*map(int,input().split()[1:])]
if a[0]>=2400 and a[1]>a[0] and con:print('YES');con=False
if con:print('NO')
``` | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,603,986,543 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 140 | 0 | a,b=map(int,input().split())
c1,c2,c3=0,0,0
l=[]
for i in range(1,7):
l.append((abs(i-a),abs(i-b)))
for i in range(len(l)):
if(l[i][0]>l[i][1]):
c3+=1
elif(l[i][0]<l[i][1]):
c1+=1
else:
c2+=1
print(c1,c2,c3) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a,b=map(int,input().split())
c1,c2,c3=0,0,0
l=[]
for i in range(1,7):
l.append((abs(i-a),abs(i-b)))
for i in range(len(l)):
if(l[i][0]>l[i][1]):
c3+=1
elif(l[i][0]<l[i][1]):
c1+=1
else:
c2+=1
print(c1,c2,c3)
``` | 3 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,638,842,391 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import math
r,x0,y0,x1,y1=map(int,input().split())
print(x0,y0,x1,y1)
d = math.sqrt((x1-x0)**2+(y1-y0)**2)
s = d/(r<<1)
print(d,s)
print(math.ceil(s))
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import math
r,x0,y0,x1,y1=map(int,input().split())
print(x0,y0,x1,y1)
d = math.sqrt((x1-x0)**2+(y1-y0)**2)
s = d/(r<<1)
print(d,s)
print(math.ceil(s))
``` | 0 | |
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,589,718,399 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 218 | 20,172,800 | n = int(input())
num = list(map(int, input().split(" ")))
aux = map(lambda x: 1 if x > n else 1, num)
print(sum(aux))
| 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())
num = list(map(int, input().split(" ")))
aux = map(lambda x: 1 if x > n else 1, num)
print(sum(aux))
``` | 0 | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,638,623,807 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n, m = map(int, input().split())
day = 0
x = n + n // m
y = x // m + n
#while x > 0:
# x = x - 1
# day = day + 1
print(y) | Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n, m = map(int, input().split())
day = 0
x = n + n // m
y = x // m + n
#while x > 0:
# x = x - 1
# day = day + 1
print(y)
``` | 0 | |
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
}... | 1,580,230,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 248 | 512,000 | def solution(n,m):
print(m+n-1)
if n>=m:
t=1
for i in range(1,n+1):
while t<=m:
print(i,t)
t+=1
t=2
for i in range(1,m+1):
while t<=n:
print(t,i)
t+=1
else:
t=1
... | Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. B... | ```python
def solution(n,m):
print(m+n-1)
if n>=m:
t=1
for i in range(1,n+1):
while t<=m:
print(i,t)
t+=1
t=2
for i in range(1,m+1):
while t<=n:
print(t,i)
t+=1
else:
... | 0 | |
195 | A | Let's Watch Football | PROGRAMMING | 1,000 | [
"binary search",
"brute force",
"math"
] | null | null | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. T... | Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses. | [
"4 1 1\n",
"10 3 2\n",
"13 12 1\n"
] | [
"3\n",
"5\n",
"1\n"
] | In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watch... | 500 | [
{
"input": "4 1 1",
"output": "3"
},
{
"input": "10 3 2",
"output": "5"
},
{
"input": "13 12 1",
"output": "1"
},
{
"input": "2 1 3",
"output": "3"
},
{
"input": "6 2 4",
"output": "8"
},
{
"input": "5 2 1",
"output": "2"
},
{
"input": "2 1... | 1,650,508,043 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 92 | 0 | def round_up(x):
if x % 1 == 0:
return int(x)
else:
return int(x // 1 + 1)
a, b, c = [int(x) for x in input().split()]
latency = a * c / b - c
print(round_up(latency))
| Title: Let's Watch Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn ... | ```python
def round_up(x):
if x % 1 == 0:
return int(x)
else:
return int(x // 1 + 1)
a, b, c = [int(x) for x in input().split()]
latency = a * c / b - c
print(round_up(latency))
``` | 3 | |
859 | B | Lazy Security Guard | PROGRAMMING | 1,000 | [
"brute force",
"geometry",
"math"
] | null | null | Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ... | Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route. | Print the minimum perimeter that can be achieved. | [
"4\n",
"11\n",
"22\n"
] | [
"8\n",
"14\n",
"20\n"
] | Here are some possible shapes for the examples:
<img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 750 | [
{
"input": "4",
"output": "8"
},
{
"input": "11",
"output": "14"
},
{
"input": "22",
"output": "20"
},
{
"input": "3",
"output": "8"
},
{
"input": "1024",
"output": "128"
},
{
"input": "101",
"output": "42"
},
{
"input": "30",
"output":... | 1,505,584,912 | 1,612 | Python 3 | OK | TESTS | 35 | 62 | 0 | n = int(input())
temp = int(n**0.5)
n -= temp ** 2
if n // temp != n / temp:
print(temp * 4 + (n//temp+1) * 2)
else:
print(temp * 4 + (n//temp) * 2)
| Title: Lazy Security Guard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is... | ```python
n = int(input())
temp = int(n**0.5)
n -= temp ** 2
if n // temp != n / temp:
print(temp * 4 + (n//temp+1) * 2)
else:
print(temp * 4 + (n//temp) * 2)
``` | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,681,139,692 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | string = input()
string = string.strip("WUB")
string = string.replace("WUB", " ")
print(string) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
string = input()
string = string.strip("WUB")
string = string.replace("WUB", " ")
print(string)
``` | 0 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
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 %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,697,084,782 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | def main():
n, k = tuple(map(int, input().split()))
odd_count = (n+1)//2
if k <= odd_count:
print(2*k-1)
else:
k -= odd_count
print(2*k)
if __name__ == '__main__':
main() | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
def main():
n, k = tuple(map(int, input().split()))
odd_count = (n+1)//2
if k <= odd_count:
print(2*k-1)
else:
k -= odd_count
print(2*k)
if __name__ == '__main__':
main()
``` | 3 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,601,460,059 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 139 | 0 | def main():
n = int(input())
lines = []
for _ in range(n):
lines.append(input())
y = lines[0][1]
for i in range(n):
for j in range(n):
if i == j or i == n - j - 1:
continue
if lines[i][j] != y:
print("NO")
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
def main():
n = int(input())
lines = []
for _ in range(n):
lines.append(input())
y = lines[0][1]
for i in range(n):
for j in range(n):
if i == j or i == n - j - 1:
continue
if lines[i][j] != y:
print("NO")... | 0 | |
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output... | 1,436,888,452 | 1,852 | Python 3 | OK | TESTS | 49 | 327 | 15,257,600 | n=int(input())
mas=list(map(int,input().split(" ")))
dic={i:[0,-1,-1] for i in set(mas)}
ma=0
for i in range(n):
if dic[mas[i]][1]==-1:
dic[mas[i]][1]=i
dic[mas[i]][0]+=1
dic[mas[i]][2]=i
if dic[mas[i]][0]>ma:ma=dic[mas[i]][0]
mi=9999999999
a=0
b=0
for i in range(n):
if(dic[ma... | Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to... | ```python
n=int(input())
mas=list(map(int,input().split(" ")))
dic={i:[0,-1,-1] for i in set(mas)}
ma=0
for i in range(n):
if dic[mas[i]][1]==-1:
dic[mas[i]][1]=i
dic[mas[i]][0]+=1
dic[mas[i]][2]=i
if dic[mas[i]][0]>ma:ma=dic[mas[i]][0]
mi=9999999999
a=0
b=0
for i in range(n):
... | 3 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,697,011,278 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 | '''
2300015897
吴杰稀
光华管理学院
'''
cases = int(input())
for i in range(cases):
angle = int(input())
t = 180 - angle
if 360 % t == 0 and 360 // t >= 3:
print("YES")
else:
print("NO") | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
'''
2300015897
吴杰稀
光华管理学院
'''
cases = int(input())
for i in range(cases):
angle = int(input())
t = 180 - angle
if 360 % t == 0 and 360 // t >= 3:
print("YES")
else:
print("NO")
``` | 3 | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,625,485,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
p=input()
c_0=p.count('0')
c_1=p.count('1')
s=2*min(c_0,c_1)
print(s)
| Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
n=int(input())
p=input()
c_0=p.count('0')
c_1=p.count('1')
s=2*min(c_0,c_1)
print(s)
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,694,259,243 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 77 | 0 | import math
def main():
dms=[]
ins = input()
dms = ins.split()
d1 = int(dms[0])/int(dms[2]);
d2 = int(dms[1])/int(dms[2]);
print(math.ceil(d1)*math.ceil(d2))
main() | 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
import math
def main():
dms=[]
ins = input()
dms = ins.split()
d1 = int(dms[0])/int(dms[2]);
d2 = int(dms[1])/int(dms[2]);
print(math.ceil(d1)*math.ceil(d2))
main()
``` | 3.9615 |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,667,822,601 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 102,400 | import os,sys,io,math
from array import array
from math import *
from bisect import *
from heapq import *
from functools import *
from itertools import *
from collections import Counter,defaultdict
I=lambda:[*map(int,sys.stdin.readline().split())]
IS=lambda:input()
IN=lambda:int(input())
IF=lambda:float(inpu... | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
import os,sys,io,math
from array import array
from math import *
from bisect import *
from heapq import *
from functools import *
from itertools import *
from collections import Counter,defaultdict
I=lambda:[*map(int,sys.stdin.readline().split())]
IS=lambda:input()
IN=lambda:int(input())
IF=lambda:... | 3.976809 |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,656,851,163 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | import math
a,b,c,d=list(map(int,input().split()))
print((b/(math.factorial(b+d)/(math.factorial(b)*math.factorial(d))))*(b+d-(a+c))) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
import math
a,b,c,d=list(map(int,input().split()))
print((b/(math.factorial(b+d)/(math.factorial(b)*math.factorial(d))))*(b+d-(a+c)))
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,648,488,336 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 2,048,000 | import re
s = input()
if re.match(r'.*h.*e.*l,*l.*o.*', s):
print(True)
else:
print(False)
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
import re
s = input()
if re.match(r'.*h.*e.*l,*l.*o.*', s):
print(True)
else:
print(False)
``` | 0 |
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -... | 1,614,596,176 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n = int(input())
coo = [int(i) for i in input().split(" ")]
print(coo[(n - 1) // 2])
| Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=... | ```python
n = int(input())
coo = [int(i) for i in input().split(" ")]
print(coo[(n - 1) // 2])
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,642,423,558 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | mn=[int(i) for i in input().split()]
print(int(mn[0]*mn[1]/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
mn=[int(i) for i in input().split()]
print(int(mn[0]*mn[1]/2))
``` | 3.969 |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,612,135,004 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 202 | 4,505,600 | s=input()
t=input()
swaps=s.swapcase()
swapt=t.swapcase()
alp=[]
countalp=[]
salp=[]
scountalp=[]
yay=0
woops=0
for i,x in enumerate(s):
if x not in alp:
alp.append(x)
n=s.count(x)
countalp.append(n)
for i,x in enumerate(t):
if x not in salp:
salp.appen... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
s=input()
t=input()
swaps=s.swapcase()
swapt=t.swapcase()
alp=[]
countalp=[]
salp=[]
scountalp=[]
yay=0
woops=0
for i,x in enumerate(s):
if x not in alp:
alp.append(x)
n=s.count(x)
countalp.append(n)
for i,x in enumerate(t):
if x not in salp:
... | 0 | |
724 | D | Dense Subsequence | PROGRAMMING | 1,900 | [
"data structures",
"greedy",
"strings"
] | null | null | You are given a string *s*, consisting of lowercase English letters, and the integer *m*.
One should choose some symbols from the given string so that any contiguous subsegment of length *m* has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.
Then one uses the ... | The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000).
The second line contains the string *s* consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100<=000. It is also guaranteed that the number *m* doesn't exceed the length... | Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above. | [
"3\ncbabc\n",
"2\nabcab\n",
"3\nbcabcbaccba\n"
] | [
"a\n",
"aab\n",
"aaabb\n"
] | In the first sample, one can choose the subsequence {3} and form a string "a".
In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab". | 1,500 | [
{
"input": "3\ncbabc",
"output": "a"
},
{
"input": "2\nabcab",
"output": "aab"
},
{
"input": "3\nbcabcbaccba",
"output": "aaabb"
},
{
"input": "5\nimmaydobun",
"output": "ab"
},
{
"input": "5\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouv... | 1,698,883,444 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 155 | 4,096,000 | m = int(input())
s = input()
n = len(s)
t = []
u = [1] * n
d = 'a'
i = 0
while i <= n - m:
k = i
for j in range(m):
if s[i + j] <= s[k]: k = i + j
t += [s[k]]
d = max(d, s[k])
u[k] = 0
i = k + 1
t += [q for q, v in zip(s, u) if q < d and v]
print(''.join(sorted(t))) | Title: Dense Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s*, consisting of lowercase English letters, and the integer *m*.
One should choose some symbols from the given string so that any contiguous subsegment of length *m* has at least one selected... | ```python
m = int(input())
s = input()
n = len(s)
t = []
u = [1] * n
d = 'a'
i = 0
while i <= n - m:
k = i
for j in range(m):
if s[i + j] <= s[k]: k = i + j
t += [s[k]]
d = max(d, s[k])
u[k] = 0
i = k + 1
t += [q for q, v in zip(s, u) if q < d and v]
print(''.join(sorted(... | 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,587,559,502 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | s = [0, 0, 0]
for _ in range(int(input())):
x, y, z = map(int, input().split())
s[0] += x
s[1] += y
s[2] += z
if all(i == 0 for i in s):
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
s = [0, 0, 0]
for _ in range(int(input())):
x, y, z = map(int, input().split())
s[0] += x
s[1] += y
s[2] += z
if all(i == 0 for i in s):
print('YES')
else:
print('NO')
``` | 3.938 |
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,667,238,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n_ = int(input())
n = input().split()
total = 1
s = []
for i in range(n_):
n[i] = int(n[i])
if n[i] in s:
if total == s.count(n[i]):
total += 1
s.append(s)
else:
s.append(n[i])
print(total)
| 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())
n = input().split()
total = 1
s = []
for i in range(n_):
n[i] = int(n[i])
if n[i] in s:
if total == s.count(n[i]):
total += 1
s.append(s)
else:
s.append(n[i])
print(total)
``` | 0 | |
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,589,101,860 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 372 | 22,220,800 | t=int(input(""))
d=list(map(int,input("").split(" ")))
f=int(input(""))
a=list(map(int,input("").split(" ")))
v=[]
for i in d:
list=[]
for j in a:
if j%i==0:
list.append(j/i)
v.append(max(list))
g=max(v)
s=0
for o in range(len(v)):
if g==v[o]:
s+=1
print(s) | 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
t=int(input(""))
d=list(map(int,input("").split(" ")))
f=int(input(""))
a=list(map(int,input("").split(" ")))
v=[]
for i in d:
list=[]
for j in a:
if j%i==0:
list.append(j/i)
v.append(max(list))
g=max(v)
s=0
for o in range(len(v)):
if g==v[o]:
s+=1
... | -1 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,700,285,868 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 9,932,800 | Pri, coin = map(int, input().split())
R = 1
X = int(str(Pri)[-1])
while True:
if str(X)[-1] == str(coin) or str(X)[-1] == '0':
break
R += 1
X += X
print(R)
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
Pri, coin = map(int, input().split())
R = 1
X = int(str(Pri)[-1])
while True:
if str(X)[-1] == str(coin) or str(X)[-1] == '0':
break
R += 1
X += X
print(R)
``` | 0 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,698,288,992 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | a = int(input())
b = int(input())
c = int(input())
m = a+b+c
def ifm(res):
global m
if res > m: m = res
ifm(a*b*c)
ifm(a*b+c)
ifm(a*(b+c))
ifm(a+b*c)
ifm((a+b)*c)
print(m) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a = int(input())
b = int(input())
c = int(input())
m = a+b+c
def ifm(res):
global m
if res > m: m = res
ifm(a*b*c)
ifm(a*b+c)
ifm(a*(b+c))
ifm(a+b*c)
ifm((a+b)*c)
print(m)
``` | 3 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,580,298,045 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 310 | 0 | k = int(input())
l = int(input())
for x in range(32):
if l == k * pow(k,x):
print('YES')
print(x)
break
if l < k * pow(k,x):
print('NO')
break
| Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
k = int(input())
l = int(input())
for x in range(32):
if l == k * pow(k,x):
print('YES')
print(x)
break
if l < k * pow(k,x):
print('NO')
break
``` | 3 | |
715 | A | Plus and Square Root | PROGRAMMING | 1,600 | [
"constructive algorithms",
"math"
] | null | null | ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, '<=+<=' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are *n*<=+<=1 levels in the game and ZS the Coder start at the level 1.
When ZS the Coder is at level *k*, he can :
1. Pr... | The first and only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000), denoting that ZS the Coder wants to reach level *n*<=+<=1. | Print *n* non-negative integers, one per line. *i*-th of them should be equal to the number of times that ZS the Coder needs to press the '<=+<=' button before pressing the '' button at level *i*.
Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018.
It is guar... | [
"3\n",
"2\n",
"4\n"
] | [
"14\n16\n46\n",
"999999999999999998\n44500000000\n",
"2\n17\n46\n97\n"
] | In the first sample case:
On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14·1 = 16. Then, ZS the Coder pressed the '<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c77ded9b8209a8cb488cc2ec7b7fe1dae32a53... | 500 | [
{
"input": "3",
"output": "2\n17\n46"
},
{
"input": "2",
"output": "2\n17"
},
{
"input": "4",
"output": "2\n17\n46\n97"
},
{
"input": "1",
"output": "2"
},
{
"input": "100000",
"output": "2\n17\n46\n97\n176\n289\n442\n641\n892\n1201\n1574\n2017\n2536\n3137\n38... | 1,535,281,802 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 514 | 102,400 | x=2
for i in range(1, int(input())+1):
print(i*(i+1)**2-x)
x=i
# Made By Mostafa_Khaled | Title: Plus and Square Root
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, '<=+<=' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are *n*<=+<=1 leve... | ```python
x=2
for i in range(1, int(input())+1):
print(i*(i+1)**2-x)
x=i
# Made By Mostafa_Khaled
``` | 3 | |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,661,130,260 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | a = int(input())
chars = input()
newSeq = False
seqCount = 0
seqs = 0
toPrint = []
for i in range(len(chars)):
if (chars[i] == "B"):
seqCount += 1
if (newSeq == False):
newSeq = True
if(i == len(chars) - 1): # last loop
toPrint.append(seqCount ) ... | Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
a = int(input())
chars = input()
newSeq = False
seqCount = 0
seqs = 0
toPrint = []
for i in range(len(chars)):
if (chars[i] == "B"):
seqCount += 1
if (newSeq == False):
newSeq = True
if(i == len(chars) - 1): # last loop
toPrint.append(seqCount... | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,689,691,219 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input())
cards = list(map(int , input().split()))
sereja = 0
dima = 0
while len(cards) != 0:
sereja += max(cards[0], cards[len(cards)-1])
cards.remove(max(cards[0], cards[len(cards)-1]))
if len(cards) == 0:
break
dima += max(cards[0], cards[len(cards)-1])
cards.remove(max(c... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input())
cards = list(map(int , input().split()))
sereja = 0
dima = 0
while len(cards) != 0:
sereja += max(cards[0], cards[len(cards)-1])
cards.remove(max(cards[0], cards[len(cards)-1]))
if len(cards) == 0:
break
dima += max(cards[0], cards[len(cards)-1])
cards.re... | 3 | |
337 | B | Routine Problem | PROGRAMMING | 1,400 | [
"greedy",
"math",
"number theory"
] | null | null | Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio *a*:*b*. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio *c*:*d*. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on ... | A single line contains four space-separated integers *a*, *b*, *c*, *d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000). | Print the answer to the problem as "p/q", where *p* is a non-negative integer, *q* is a positive integer and numbers *p* and *q* don't have a common divisor larger than 1. | [
"1 1 3 2\n",
"4 3 2 2\n"
] | [
"1/3\n",
"1/4\n"
] | Sample 1. Manao's monitor has a square screen. The movie has 3:2 horizontal to vertical length ratio. Obviously, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. In this case, only 2/3 of the monitor will project the movie in the horizontal dimension: <img class=... | 1,000 | [
{
"input": "1 1 3 2",
"output": "1/3"
},
{
"input": "4 3 2 2",
"output": "1/4"
},
{
"input": "3 4 2 3",
"output": "1/9"
},
{
"input": "4 4 5 5",
"output": "0/1"
},
{
"input": "1 1 1 1",
"output": "0/1"
},
{
"input": "1000 1000 1000 1000",
"output":... | 1,687,978,220 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | from math import gcd
a, b, c, d = map(int, input().split())
if a*d > b * c: a, b, c, d = b, a, d, c
p, q = b * c - a * d, b * c
print(p // gcd(p, q), q // gcd(p, q)) | Title: Routine Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio *a*:*b*. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio *c*:*d*. Manao adjusts the view... | ```python
from math import gcd
a, b, c, d = map(int, input().split())
if a*d > b * c: a, b, c, d = b, a, d, c
p, q = b * c - a * d, b * c
print(p // gcd(p, q), q // gcd(p, q))
``` | 0 | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,646,050,745 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
for i in range(n):
a=int(input())
if a%7==0 or a%3==0 or a%10==0 or a%13==0 or a%17==0 or a%23==0 or a%37==0 or a %44==0 or (a-10)%3==0 or (a-13)%3==0 or (a-10)%7==0 or (a-13)%7==0
print('YES')
else:
print('NO')
| Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
n=int(input())
for i in range(n):
a=int(input())
if a%7==0 or a%3==0 or a%10==0 or a%13==0 or a%17==0 or a%23==0 or a%37==0 or a %44==0 or (a-10)%3==0 or (a-13)%3==0 or (a-10)%7==0 or (a-13)%7==0
print('YES')
else:
print('NO')
``` | -1 | |
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane... | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
... | 1,496,326,891 | 391 | Python 3 | CHALLENGED | CHALLENGES | 7 | 46 | 0 | ans = 'NO'
for i in range(4):
l, s, r, p = map(int, input().split())
if (p == 1) and ((l + s + r) >= 1):
ans = 'YES'
print(ans) | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l... | ```python
ans = 'NO'
for i in range(4):
l, s, r, p = map(int, input().split())
if (p == 1) and ((l + s + r) >= 1):
ans = 'YES'
print(ans)
``` | -1 | |
297 | B | Fish Weight | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | It is known that there are *k* fish species in the polar ocean, numbered from 1 to *k*. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the *i*-th type of fish be *w**i*, then 0<=<<=*w*1<=≤<=*w*2<=≤<=...<=≤<=*w**k* holds.
Polar bears Alice and Bob each have cau... | The first line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of fish caught by Alice and Bob respectively, and the number of fish species.
The second line contains *n* integers each from 1 to *k*, the list of fish type caught by Alice. The third line contains *m* in... | Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. | [
"3 3 3\n2 2 2\n1 1 3\n",
"4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, if *w*<sub class="lower-index">1</sub> = 1, *w*<sub class="lower-index">2</sub> = 2, *w*<sub class="lower-index">3</sub> = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5.
In the second sample, the fish that Alice caught is a subset of Bob's. Theref... | 500 | [
{
"input": "3 3 3\n2 2 2\n1 1 3",
"output": "YES"
},
{
"input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7",
"output": "NO"
},
{
"input": "5 5 10\n8 2 8 5 9\n9 1 7 5 1",
"output": "YES"
},
{
"input": "7 7 10\n8 2 8 10 6 9 10\n2 4 9 5 6 2 5",
"output": "YES"
},
{
"input": "15 ... | 1,658,737,556 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | def f(a,b):
if len(a)>len(b):return 'YES'
a.sort()
b.sort()
print(a,b)
if any(a[-i]-b[-i]>0 for i in range(1,len(a)+1)):
return 'YES'
return 'NO'
if __name__=='__main__':
n,m,k=(int(i) for i in input().split())
a=list(map(int,input().split()))
b=list(map(int,inpu... | Title: Fish Weight
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is known that there are *k* fish species in the polar ocean, numbered from 1 to *k*. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the *i*-th type of fish be *w**i... | ```python
def f(a,b):
if len(a)>len(b):return 'YES'
a.sort()
b.sort()
print(a,b)
if any(a[-i]-b[-i]>0 for i in range(1,len(a)+1)):
return 'YES'
return 'NO'
if __name__=='__main__':
n,m,k=(int(i) for i in input().split())
a=list(map(int,input().split()))
b=list(ma... | 0 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,589,834,582 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 218 | 2,150,400 | s = input()
s2 = ['h', 'e', 'i', 'd', 'i']
n = [-1 for i in range(5)]
id = 0
for i in range(len(s)):
if s[i] == s2[id] and n[id] == -1:
# print(s[i], s2[id])
n[id] = i
id+=1
for i in n:
if i == -1:
print("NO")
break
else:
print("YES")
# print(n)
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s = input()
s2 = ['h', 'e', 'i', 'd', 'i']
n = [-1 for i in range(5)]
id = 0
for i in range(len(s)):
if s[i] == s2[id] and n[id] == -1:
# print(s[i], s2[id])
n[id] = i
id+=1
for i in n:
if i == -1:
print("NO")
break
else:
print("YES")
# print(n)
``` | -1 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,586,706,690 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | from sys import stdin
inp = stdin.readline
n = int(inp().strip())
s = inp().strip()
stf = 0
fts = 0
prev = s[0]
for city in s:
if prev == 'S' and city == 'F':
stf += 1
elif prev == 'F' and city == 'S':
fts += 1
prev = city
print("YES" if stf > fts else "NO") | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
from sys import stdin
inp = stdin.readline
n = int(inp().strip())
s = inp().strip()
stf = 0
fts = 0
prev = s[0]
for city in s:
if prev == 'S' and city == 'F':
stf += 1
elif prev == 'F' and city == 'S':
fts += 1
prev = city
print("YES" if stf > fts else "NO")
``... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them.
There are *n* planets in their universe numbered from 1 to *n*. Rick is in planet number *s* (the earth) and he doesn't know where Morty is. As we all... | The first line of input contains three integers *n*, *q* and *s* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*s*<=≤<=*n*) — number of planets, number of plans and index of earth respectively.
The next *q* lines contain the plans. Each line starts with a number *t*, type of that plan (1<=≤<=*t*<=≤<=3). If *t*<==<=1 then it is foll... | In the first and only line of output print *n* integers separated by spaces. *i*-th of them should be minimum money to get from earth to *i*-th planet, or <=-<=1 if it's impossible to get to that planet. | [
"3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17\n",
"4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16\n"
] | [
"0 28 12 \n",
"0 -1 -1 12 \n"
] | In the first sample testcase, Rick can purchase 4th plan once and then 2nd plan in order to get to get to planet number 2. | 0 | [] | 1,691,073,719 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1691073718.949566")# 1691073718.9495845 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them.
There are *n* planets in their universe numbered from 1 to *... | ```python
print("_RANDOM_GUESS_1691073718.949566")# 1691073718.9495845
``` | 0 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,601,596,734 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | def main():
q1 = a = q2 = 0
for s in input():
if s == 'Q':
q1 += 1
q2 += a
else:
a += q1
return q2
for m in range(1, 2 + 1):
o = str(main())
e = input()
if o != e:
print(f'Test {m} failed.\nOut: {o}\nExp: {e}\n')
e... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
def main():
q1 = a = q2 = 0
for s in input():
if s == 'Q':
q1 += 1
q2 += a
else:
a += q1
return q2
for m in range(1, 2 + 1):
o = str(main())
e = input()
if o != e:
print(f'Test {m} failed.\nOut: {o}\nExp: {e}\... | -1 | |
975 | B | Mancala | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ... | The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole.
It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board. | Output one integer, the maximum possible score after one move. | [
"0 1 1 0 0 0 0 0 0 7 0 0 0 0\n",
"5 1 1 1 1 0 0 0 0 0 0 0 0 0\n"
] | [
"4\n",
"8\n"
] | In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$. | 1,000 | [
{
"input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0",
"output": "4"
},
{
"input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0",
"output": "8"
},
{
"input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1",
"output": "54294"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15",
... | 1,534,360,532 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n=list(map(int,input().split()))
top=[]
for item in n:
top.append(item)
f=[]
y=0
t=y
taa=[]
for x in range(14):
if n[y]!=0:
if n[y]>13:
ol=n[y]//13
for z in range(14):
if t!=13:
t+=1
n[t]+=ol
... | Title: Mancala
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. ... | ```python
n=list(map(int,input().split()))
top=[]
for item in n:
top.append(item)
f=[]
y=0
t=y
taa=[]
for x in range(14):
if n[y]!=0:
if n[y]>13:
ol=n[y]//13
for z in range(14):
if t!=13:
t+=1
n[t]+=ol
... | 0 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,661,421,757 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n = int(input())
k = 1
people = set()
for i in range(n):
man = tuple(map(int, input().split()))
if man in people:
k += 1
people.add(man)
print(k)
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
k = 1
people = set()
for i in range(n):
man = tuple(map(int, input().split()))
if man in people:
k += 1
people.add(man)
print(k)
``` | 0 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,596,949,055 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 342 | 7,987,200 | rolls = list(map(int, input().split()))
highest = max(rolls)
fraction = [0, 6]
fraction[0] = 6 - highest + 1
from fractions import Fraction
result = str(Fraction(fraction[0], fraction[1]))
if result == '1':
print("1/1")
else:
print(result)
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
rolls = list(map(int, input().split()))
highest = max(rolls)
fraction = [0, 6]
fraction[0] = 6 - highest + 1
from fractions import Fraction
result = str(Fraction(fraction[0], fraction[1]))
if result == '1':
print("1/1")
else:
print(result)
``` | 3.769491 |
272 | C | Dima and Staircase | PROGRAMMING | 1,500 | [
"data structures",
"implementation"
] | 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. | 1,500 | [
{
"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,509,390,277 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 8,089,600 | cin = lambda : map(int, input().split())
n = int(input())
a = list(cin())
m = int(input())
mx = 0
for i in range(m):
w, h = cin()
mx = max(a[0], a[w - 1])
print(mx)
a[0] = mx + h | Title: Dima and Staircase
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 st... | ```python
cin = lambda : map(int, input().split())
n = int(input())
a = list(cin())
m = int(input())
mx = 0
for i in range(m):
w, h = cin()
mx = max(a[0], a[w - 1])
print(mx)
a[0] = mx + h
``` | 0 | |
288 | A | Polo the Penguin and Strings | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo... | A single line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=26) — the string's length and the number of distinct letters. | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | [
"7 4\n",
"4 7\n"
] | [
"ababacd\n",
"-1\n"
] | none | 500 | [
{
"input": "7 4",
"output": "ababacd"
},
{
"input": "4 7",
"output": "-1"
},
{
"input": "10 5",
"output": "abababacde"
},
{
"input": "47 2",
"output": "abababababababababababababababababababababababa"
},
{
"input": "10 7",
"output": "ababacdefg"
},
{
"... | 1,645,107,285 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 1,808 | 307,200 | # Author: Riddhish V. Lichade
# username: root_rvl
from collections import Counter
from sys import stdin, stdout
from heapq import nlargest, nsmallest
def outnl(x): stdout.write(str(x) + '\n')
def outsl(x): stdout.write(str(x) + '')
def instr(): return stdin.readline().strip()
def inint(): return int(stdin.read... | Title: Polo the Penguin and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase Englis... | ```python
# Author: Riddhish V. Lichade
# username: root_rvl
from collections import Counter
from sys import stdin, stdout
from heapq import nlargest, nsmallest
def outnl(x): stdout.write(str(x) + '\n')
def outsl(x): stdout.write(str(x) + '')
def instr(): return stdin.readline().strip()
def inint(): return int(... | 0 | |
651 | B | Beautiful Paintings | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy ... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement. | [
"5\n20 30 10 50 40\n",
"4\n200 100 100 200\n"
] | [
"4\n",
"2\n"
] | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | 1,000 | [
{
"input": "5\n20 30 10 50 40",
"output": "4"
},
{
"input": "4\n200 100 100 200",
"output": "2"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n444 333",
"output": "1"
},
{
"input": "100\n... | 1,589,985,700 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 124 | 307,200 | def most_frequent(List):
return max(set(List), key = List.count)
n=int(input())
l=list(map(int,input().split()))
m=set(l)
h=[0]*len(m)
print((n-1)-(l.count(most_frequent(l))-1))
| Title: Beautiful Paintings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to a... | ```python
def most_frequent(List):
return max(set(List), key = List.count)
n=int(input())
l=list(map(int,input().split()))
m=set(l)
h=[0]*len(m)
print((n-1)-(l.count(most_frequent(l))-1))
``` | 3 | |
916 | A | Jamie and Alarm Snooze | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). | Print the minimum number of times he needs to press the button. | [
"3\n11 23\n",
"5\n01 07\n"
] | [
"2\n",
"0\n"
] | In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | 500 | [
{
"input": "3\n11 23",
"output": "2"
},
{
"input": "5\n01 07",
"output": "0"
},
{
"input": "34\n09 24",
"output": "3"
},
{
"input": "2\n14 37",
"output": "0"
},
{
"input": "14\n19 54",
"output": "9"
},
{
"input": "42\n15 44",
"output": "12"
},
... | 1,522,510,776 | 516 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 7,065,600 | x = int(input())
hhs, mms = input().split()
hh, mm = int(hhs), int(mms)
if '7' in hhs or '7' in mms:
print(0)
else:
if mm > 57:
if '7' in str(hh + 1):
q = 60 - mm
else:
q = 67 - mm
else:
if mm % 10 > 7:
q = 7 + (10 - (mm % 10))
else:
... | Title: Jamie and Alarm Snooze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will the... | ```python
x = int(input())
hhs, mms = input().split()
hh, mm = int(hhs), int(mms)
if '7' in hhs or '7' in mms:
print(0)
else:
if mm > 57:
if '7' in str(hh + 1):
q = 60 - mm
else:
q = 67 - mm
else:
if mm % 10 > 7:
q = 7 + (10 - (mm % 10))
e... | 0 | |
908 | C | New Year and Curling | PROGRAMMING | 1,500 | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | Carol is currently curling.
She has *n* disks each with radius *r* on the 2D plane.
Initially she has all these disks above the line *y*<==<=10100.
She then will slide the disks towards the line *y*<==<=0 one by one in order from 1 to *n*.
When she slides the *i*-th disk, she will place its center at the point (*... | The first line will contain two integers *n* and *r* (1<=≤<=*n*,<=*r*<=≤<=1<=000), the number of disks, and the radius of the disks, respectively.
The next line will contain *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=1<=000) — the *x*-coordinates of the disks. | Print a single line with *n* numbers. The *i*-th number denotes the *y*-coordinate of the center of the *i*-th disk. The output will be accepted if it has absolute or relative error at most 10<=-<=6.
Namely, let's assume that your answer for a particular value of a coordinate is *a* and the answer of the jury is *b*. ... | [
"6 2\n5 5 6 8 3 12\n"
] | [
"2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\n"
] | The final positions of the disks will look as follows:
In particular, note the position of the last disk. | 1,000 | [
{
"input": "6 2\n5 5 6 8 3 12",
"output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "5 300\n939 465 129 611 532",
"output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391"
},
{
"input": "5 ... | 1,514,574,895 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,529,600 | n,r=map(int,input().split())
a=list(map(int,input().split()))
b=[0 for i in range(n)]
b[0]=a[0]
for i in range(1,n+1):
w=r
for j in range(1,i):
if abs(a[j]-a[i]>2*r):continue
w=max(w,b[j]+math.sqrt(4*(r**2)-dx**2))
b[i]=w
print(*b) | Title: New Year and Curling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carol is currently curling.
She has *n* disks each with radius *r* on the 2D plane.
Initially she has all these disks above the line *y*<==<=10100.
She then will slide the disks towards the line *y*<==<=0 one b... | ```python
n,r=map(int,input().split())
a=list(map(int,input().split()))
b=[0 for i in range(n)]
b[0]=a[0]
for i in range(1,n+1):
w=r
for j in range(1,i):
if abs(a[j]-a[i]>2*r):continue
w=max(w,b[j]+math.sqrt(4*(r**2)-dx**2))
b[i]=w
print(*b)
``` | -1 | |
165 | C | Another Problem on Strings | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math",
"strings",
"two pointers"
] | null | null | A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if th... | The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters. | Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
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. | [
"1\n1010\n",
"2\n01010\n",
"100\n01010\n"
] | [
"6\n",
"4\n",
"0\n"
] | In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | 1,500 | [
{
"input": "1\n1010",
"output": "6"
},
{
"input": "2\n01010",
"output": "4"
},
{
"input": "100\n01010",
"output": "0"
},
{
"input": "0\n01010",
"output": "3"
},
{
"input": "0\n0010100011",
"output": "10"
},
{
"input": "0\n10000",
"output": "10"
}... | 1,691,534,866 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def count_substrings(s, k):
answer = 0
prefix_sums = [0]
for i in range(len(s)):
prefix_sums.append(prefix_sums[i] + int(s[i]))
for i in range(len(prefix_sums)):
left = lower_bound(prefix_sums, i + 1, len(prefix_sums), prefix_sums[i] + k)
right = upper_bound(prefix_sums, i... | Title: Another Problem on Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, ... | ```python
def count_substrings(s, k):
answer = 0
prefix_sums = [0]
for i in range(len(s)):
prefix_sums.append(prefix_sums[i] + int(s[i]))
for i in range(len(prefix_sums)):
left = lower_bound(prefix_sums, i + 1, len(prefix_sums), prefix_sums[i] + k)
right = upper_bound(pref... | 0 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,693,403,666 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 124 | 0 | remix = input()
ori_song = [word for word in remix.split("WUB") if word]
ori_song_str = " ".join(ori_song)
print(ori_song_str)
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
remix = input()
ori_song = [word for word in remix.split("WUB") if word]
ori_song_str = " ".join(ori_song)
print(ori_song_str)
``` | 3 | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,606,370,938 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | s=list(input())
n=len(s)
m=0
l=['A','E','I','O','U']
c=0
for i in range(n):
if(s[i] not in l):
c+=1
if(c>m):
m=c
else:
c=0
print(m+1)
| Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
s=list(input())
n=len(s)
m=0
l=['A','E','I','O','U']
c=0
for i in range(n):
if(s[i] not in l):
c+=1
if(c>m):
m=c
else:
c=0
print(m+1)
``` | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,693,251,876 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 62 | 0 | entrada = list(map(int, input().split()))
print(min(entrada), end=" ")
print(abs(entrada[0] - entrada[1]) // 2)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
entrada = list(map(int, input().split()))
print(min(entrada), end=" ")
print(abs(entrada[0] - entrada[1]) // 2)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is... | In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] | [
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] | First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | 0 | [
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes... | 1,641,313,006 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 8,908,800 | t = int(input())
for _ in range(t):
a, b = map(int, input().split())
c = a*b
cbrt = int(c**(1/3))
if (cbrt+1)**3 == c:
cbrt += 1
if (cbrt-1)**3 == c:
cbrt -= 1
if cbrt**3 == c and a%cbrt == 0 and b%cbrt == 0:
print('YES')
else:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who ... | ```python
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
c = a*b
cbrt = int(c**(1/3))
if (cbrt+1)**3 == c:
cbrt += 1
if (cbrt-1)**3 == c:
cbrt -= 1
if cbrt**3 == c and a%cbrt == 0 and b%cbrt == 0:
print('YES')
else:... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.